Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

673 lines
15 KiB

  1. //++
  2. //
  3. // Module name
  4. // miscs.s
  5. // Author
  6. // Allen Kay ([email protected]) Jun-12-95
  7. // Description
  8. // Misc. assembly functions.
  9. //
  10. //---
  11. #include "ksia64.h"
  12. .file "miscs.s"
  13. .global PalProcPhysical
  14. .global PalPhysicalBase
  15. .global PalTrPs
  16. .global IoPortPhysicalBase
  17. .global IoPortTrPs
  18. .global OsLoaderBase
  19. //
  20. // Setup CPU state to go from physical to virtual
  21. //
  22. LEAF_ENTRY(MempGoVirtual)
  23. rpT0 = t21
  24. rpT1 = t20
  25. rTrPs = t19
  26. rPPN = t18
  27. rPsr = t17
  28. rPsri = t22
  29. //
  30. // Save the state of psr.i before turning it off
  31. //
  32. mov rPsr = psr
  33. movl rpT0 = (1 << PSR_I)
  34. ;;
  35. and rPsri = rpT0, rPsr
  36. mov ar.rsc = r0
  37. ;;
  38. rsm (1 << PSR_I)
  39. ;;
  40. rsm (1 << PSR_IC)
  41. ;;
  42. srlz.i
  43. ;;
  44. movl t0 = FPSR_FOR_KERNEL
  45. ;;
  46. mov ar.fpsr = t0 // initialize fpsr
  47. ;;
  48. //
  49. // Initialize Region Registers
  50. //
  51. mov t1 = (START_GLOBAL_RID << RR_RID) | (PAGE_SHIFT << RR_PS) | RR_PS_VE
  52. movl t3 = KSEG0_BASE
  53. ;;
  54. mov rr[t3] = t1
  55. //
  56. // Invalidate all protection key registers
  57. //
  58. mov t1 = zero
  59. ;;
  60. Bl_PKRLoop:
  61. mov pkr[t1] = zero
  62. ;;
  63. add t1 = 1, t1
  64. ;;
  65. cmp.gtu pt0, pt1 = PKRNUM, t1
  66. ;;
  67. (pt0) br.cond.sptk.few.clr Bl_PKRLoop
  68. ;;
  69. //
  70. // Setup the 1-to-1 translation for the loader
  71. //
  72. movl rpT1 = OsLoaderBase
  73. ;;
  74. ld8 rpT0 = [rpT1]
  75. ;;
  76. dep rpT0 = 0, rpT0, 0, PS_4M
  77. movl rpT1 = PS_4M // Min page size.
  78. // Size should include Text/Data/Stack/BackStore/BdPcr.
  79. // SAL TLB Miss handlers provide TC 1:1 mapping.
  80. ;;
  81. mov cr.ifa = rpT0
  82. movl t4 = IITR_ATTRIBUTE_PPN_MASK // construct GR[r]
  83. movl t5 = TR_VALUE(1,0,3,0,1,1,0,1)
  84. ;;
  85. shl t2 = rpT1, ITIR_PS
  86. and t6 = rpT0, t4 // t6 is PPN in GR[r]
  87. ;;
  88. mov cr.itir = t2
  89. ;;
  90. mov t3 = DTR_LOADER_INDEX // pre-assigned index
  91. mov t4 = ITR_LOADER_INDEX // pre-assigned index
  92. or t2 = t5, t6 // t2 is now GR[r]
  93. ;;
  94. itr.d dtr[t3] = t2
  95. ;;
  96. itr.i itr[t4] = t2
  97. ;;
  98. //
  99. // Setup a 64MB translation for the drivers.
  100. //
  101. movl t0 = KSEG0_BASE + BL_64M
  102. ;;
  103. movl t2 = ITIR_VALUE(0,PS_64M)
  104. mov cr.ifa = t0
  105. ;;
  106. mov cr.itir = t2
  107. ;;
  108. mov t3 = DTR_DRIVER0_INDEX
  109. movl t2 = TR_VALUE(1,BL_64M,3,0,1,1,0,1)
  110. ;;
  111. itr.d dtr[t3] = t2
  112. ;;
  113. itr.i itr[t3] = t2
  114. //
  115. // Setup 16MB translation for kernel/hal binary.
  116. //
  117. movl t0 = KSEG0_BASE + BL_48M;
  118. ;;
  119. movl t2 = ITIR_VALUE(0,PS_16M)
  120. mov cr.ifa = t0
  121. ;;
  122. mov cr.itir = t2
  123. ;;
  124. mov t3 = DTR_KERNEL_INDEX
  125. movl t2 = TR_VALUE(1,BL_48M,3,0,1,1,0,1)
  126. ;;
  127. itr.d dtr[t3] = t2
  128. ;;
  129. itr.i itr[t3] = t2
  130. //
  131. // Setup 16MB translation for decompression buffer used by setupldr.
  132. //
  133. movl t0 = KSEG0_BASE + BL_32M;
  134. ;;
  135. movl t2 = ITIR_VALUE(0,PS_16M)
  136. mov cr.ifa = t0
  137. ;;
  138. mov cr.itir = t2
  139. ;;
  140. mov t3 = BL_DECOMPRESS_INDEX
  141. movl t2 = TR_VALUE(1,BL_32M,3,0,1,1,0,1)
  142. ;;
  143. itr.d dtr[t3] = t2
  144. ;;
  145. itr.i itr[t3] = t2
  146. //
  147. // Setup translation for I/O port space
  148. //
  149. movl rpT0 = IoPortPhysicalBase // IO Port base addr
  150. movl rpT1 = IoPortTrPs // IO Port page size
  151. movl t1 = VIRTUAL_IO_BASE
  152. ;;
  153. ld8 t0 = [rpT0]
  154. ld8 rTrPs = [rpT1]
  155. mov cr.ifa = t1
  156. movl t4 = IITR_ATTRIBUTE_PPN_MASK // construct GR[r]
  157. movl t5 = TR_VALUE(1,0,3,0,1,1,4,1)
  158. ;;
  159. shl t2 = rTrPs, ITIR_PS
  160. and t6 = t0, t4 // t6 is PPN in GR[r]
  161. ;;
  162. mov cr.itir = t2
  163. ;;
  164. mov t3 = DTR_IO_PORT_INDEX // pre-assigned index
  165. or t2 = t5, t6 // t2 is now GR[r]
  166. ;;
  167. itr.d dtr[t3] = t2
  168. //
  169. // Turn on address translation, interrupt, psr.ed, protection key.
  170. //
  171. movl t1 = MASK_IA64(PSR_BN,1) | MASK_IA64(PSR_RT,1) | MASK_IA64(PSR_DT,1) | MASK_IA64(PSR_IC,1) | MASK_IA64(PSR_AC,1) | MASK_IA64(PSR_DB,1)
  172. ;;
  173. or t1 = t1, rPsr
  174. ;;
  175. mov cr.ipsr = t1
  176. //
  177. // Initialize DCR to defer all speculation faults
  178. //
  179. mov t0 = DCR_DEFER_ALL
  180. ;;
  181. mov cr.dcr = t0
  182. //
  183. // Prepare to do RFI to return to the caller.
  184. //
  185. movl t0 = return_label
  186. ;;
  187. mov cr.iip = t0
  188. ;;
  189. mov cr.ifs = r0
  190. ;;
  191. rfi
  192. ;;
  193. return_label:
  194. mov v0 = zero
  195. ;;
  196. cmp.eq pt0, pt1 = zero, rPsri
  197. ;;
  198. (pt1) ssm 1 << PSR_I // set PSR.i bit if it was set originally
  199. srlz.i
  200. ;;
  201. LEAF_RETURN
  202. LEAF_EXIT(MempGoVirtual)
  203. //
  204. // Flip psr.it bit from virtual to physical addressing mode.
  205. //
  206. LEAF_ENTRY(FlipToPhysical)
  207. rPsr = t17
  208. rPsri = t18
  209. rPi = t19
  210. //
  211. // Save the state of psr.i before turning it off
  212. //
  213. mov rPsr = psr
  214. movl rPi = (1 << PSR_I)
  215. ;;
  216. and rPsri = rPi, rPsr
  217. rsm (1 << PSR_I)
  218. ;;
  219. rsm (1 << PSR_IC)
  220. ;;
  221. srlz.i
  222. ;;
  223. mov rPsr = psr
  224. movl t1 = ~ (MASK_IA64(PSR_RT,1) | MASK_IA64(PSR_DT,1))
  225. movl t2 = MASK_IA64(PSR_BN,1) | MASK_IA64(PSR_IC,1)
  226. ;;
  227. and t1 = t1, rPsr
  228. ;;
  229. or t1 = t1, t2
  230. ;;
  231. mov cr.ipsr = t1
  232. //
  233. // Prepare to do RFI to return to the caller.
  234. //
  235. movl t0 = FlipToPhysicalReturn
  236. ;;
  237. mov cr.iip = t0
  238. ;;
  239. mov cr.ifs = r0
  240. ;;
  241. rfi
  242. ;;
  243. FlipToPhysicalReturn:
  244. mov v0 = zero
  245. ;;
  246. cmp.eq pt0, pt1 = zero, rPsri
  247. ;;
  248. (pt1) ssm 1 << PSR_I // set PSR.i bit if it was set originally
  249. srlz.i
  250. ;;
  251. LEAF_RETURN
  252. LEAF_EXIT(FlipToPhysical)
  253. //
  254. // Flip psr.it bit from physical to virtual addressing mode.
  255. //
  256. LEAF_ENTRY(FlipToVirtual)
  257. rPsr = t17
  258. rPsri = t18
  259. rPi = t19
  260. //
  261. // Save the state of psr.i before turning it off
  262. //
  263. mov rPsr = psr
  264. movl rPi = (1 << PSR_I)
  265. ;;
  266. and rPsri = rPi, rPsr
  267. rsm (1 << PSR_I)
  268. ;;
  269. rsm (1 << PSR_IC)
  270. ;;
  271. srlz.i
  272. ;;
  273. mov rPsr = psr
  274. movl t1 = MASK_IA64(PSR_RT,1) | MASK_IA64(PSR_DT,1) | MASK_IA64(PSR_BN,1) | MASK_IA64(PSR_IC,1)
  275. ;;
  276. or t1 = t1, rPsr
  277. ;;
  278. mov cr.ipsr = t1
  279. //
  280. // Prepare to do RFI to return to the caller.
  281. //
  282. movl t0 = FlipToVirtualReturn
  283. ;;
  284. mov cr.iip = t0
  285. ;;
  286. mov cr.ifs = r0
  287. ;;
  288. rfi
  289. ;;
  290. FlipToVirtualReturn:
  291. mov v0 = zero
  292. ;;
  293. cmp.eq pt0, pt1 = zero, rPsri
  294. ;;
  295. (pt1) ssm 1 << PSR_I // set PSR.i bit if it was set originally
  296. srlz.i
  297. ;;
  298. LEAF_RETURN
  299. LEAF_EXIT(FlipToVirtual)
  300. //++
  301. //
  302. // BOOLEAN
  303. // IsPsrDtOn(VOID);
  304. //
  305. // Routine Description:
  306. //
  307. // This function returns the value of psr.dt for this cpu
  308. //
  309. // Arguements:
  310. //
  311. // Return Value:
  312. //
  313. // psr.dt
  314. //
  315. //--
  316. LEAF_ENTRY(IsPsrDtOn)
  317. mov t0 = psr
  318. movl t1 = 1 << PSR_DT
  319. ;;
  320. and t2 = t0, t1
  321. ;;
  322. shr.u v0 = t2, PSR_DT
  323. LEAF_RETURN
  324. LEAF_EXIT(IsPsrDtOn)
  325. //
  326. // Clean up TR mappings used only by NT loader.
  327. //
  328. LEAF_ENTRY(BlTrCleanUp)
  329. rpT0 = t22
  330. rPsr = t17
  331. //
  332. // purge BL_DECOMPRESS_INDEX
  333. //
  334. movl t0 = PS_16M << PS_SHIFT
  335. movl t1 = KSEG0_BASE + BL_32M
  336. ;;
  337. ptr.d t1, t0
  338. ;;
  339. //
  340. // Turn on address translation, interrupt, psr.ed, protection key.
  341. //
  342. rsm (1 << PSR_I)
  343. ;;
  344. rsm (1 << PSR_IC)
  345. ;;
  346. srlz.i
  347. ;;
  348. //
  349. // At this point, turn on psr.it so that we can pass control to
  350. // the kernel.
  351. //
  352. mov rPsr = psr
  353. movl t1 = MASK_IA64(PSR_BN,1) | MASK_IA64(PSR_IT,1) | MASK_IA64(PSR_RT,1) | MASK_IA64(PSR_DT,1) | MASK_IA64(PSR_IC,1) | MASK_IA64(PSR_AC,1) | MASK_IA64(PSR_DB,1)
  354. ;;
  355. or t1 = t1, rPsr
  356. ;;
  357. mov cr.ipsr = t1
  358. //
  359. // Prepare to do RFI to return to the caller.
  360. //
  361. movl t0 = BlTrCleanupReturn
  362. ;;
  363. mov cr.iip = t0
  364. ;;
  365. mov cr.ifs = r0
  366. ;;
  367. rfi
  368. ;;
  369. BlTrCleanupReturn:
  370. mov v0 = zero
  371. ;;
  372. LEAF_RETURN
  373. LEAF_EXIT (BlTrCleanUp)
  374. //++
  375. //
  376. // VOID
  377. // BlpPalProc(
  378. // LONGLONG a0, /* PAL function ID */
  379. // LONGLONG a1, /* PAL argument */
  380. // LONGLONG a2, /* PAL argument */
  381. // LONGLONG a3 /* PAL argument */
  382. // );
  383. //
  384. // Routine Description
  385. // This routine sets up the correct registers for input into PAL depending on
  386. // if the call uses static or stacked registers, turns off interrupts, ensures
  387. // the correct bank registers are being used and calls into the PAL.
  388. //
  389. // Return Values:
  390. // r8->r11 contain the 4 64-bit return values for PAL, r8 is the status
  391. //--
  392. NESTED_ENTRY(BlpPalProc)
  393. NESTED_SETUP(4,3,4,0)
  394. PROLOGUE_END
  395. // For both the static and stacked register conventions, load r28 with FunctionID
  396. mov r28 = a0
  397. // If static register calling convention (1-255, 512-767), copy arguments to r29->r31
  398. // Otherwise, copy to out0->out3 so they are in r32->r35 in PAL_PROC
  399. mov t0 = a0
  400. ;;
  401. shr t0 = t0, 8
  402. ;;
  403. tbit.z pt0, pt1 = t0, 0
  404. ;;
  405. //
  406. // Static proc: do br not call
  407. //
  408. (pt0) mov r29 = a1
  409. (pt0) mov r30 = a2
  410. (pt0) mov r31 = a3
  411. //
  412. // Stacked call
  413. //
  414. (pt1) mov out0 = a0
  415. (pt1) mov out1 = a1
  416. (pt1) mov out2 = a2
  417. (pt1) mov out3 = a3
  418. // Load up the address of PAL_PROC and call it
  419. addl t1 = @gprel(PalProcPhysical), gp
  420. ;;
  421. ld8 t0 = [t1]
  422. ;;
  423. mov bt0 = t0
  424. // Call into PAL_PROC
  425. (pt0) addl t1 = @ltoff(PalReturn), gp
  426. ;;
  427. (pt0) ld8 t0 = [t1]
  428. ;;
  429. (pt0) mov brp = t0
  430. ;;
  431. // Disable interrupts
  432. DISABLE_INTERRUPTS(loc2)
  433. ;;
  434. srlz.d
  435. ;;
  436. (pt0) br.sptk.many bt0
  437. ;;
  438. (pt1) br.call.sptk brp = bt0
  439. ;;
  440. PalReturn:
  441. // Restore the interrupt state
  442. RESTORE_INTERRUPTS(loc2)
  443. ;;
  444. NESTED_RETURN
  445. NESTED_EXIT(BlpPalProc)
  446. LEAF_ENTRY(BlpMapRamdiskPages)
  447. //
  448. // Setup a 1MB translation for the RAM disk pages. The starting physical
  449. // address of the translation is the input page number, which must be a
  450. // multiple of 1MB/8192. The starting virtual address is KSEG0 + 32MB.
  451. //
  452. // rsm to reset PSR.i bit
  453. //
  454. rsm 1 << PSR_I // reset PSR.i bit
  455. ;;
  456. rsm 1 << PSR_IC // reset PSR.ic bit
  457. ;;
  458. srlz.d // serialize
  459. ;;
  460. srlz.i
  461. ;;
  462. movl t0 = KSEG0_BASE
  463. movl t2 = ITIR_VALUE(0,PS_1M)
  464. ;;
  465. add t0 = t0, a0
  466. ;;
  467. mov cr.ifa = t0
  468. ;;
  469. mov cr.itir = t2
  470. ;;
  471. mov t3 = BL_LOADER_INDEX
  472. movl t2 = TR_VALUE(1,0,3,0,1,1,0,1)
  473. ;;
  474. or t2 = t2, a0
  475. mov v0 = t0
  476. ;;
  477. itr.d dtr[t3] = t2
  478. ;;
  479. itr.i itr[t3] = t2
  480. ;;
  481. srlz.d // serialize
  482. ;;
  483. srlz.i
  484. ;;
  485. ssm 1 << PSR_IC // set PSR.ic bit again
  486. ;;
  487. ssm 1 << PSR_I // set PSR.i bit again
  488. ;;
  489. srlz.d // serialize
  490. ;;
  491. srlz.i
  492. ;;
  493. LEAF_RETURN
  494. LEAF_EXIT(BlpMapRamdiskPages)
  495. LEAF_ENTRY(BlpUnmapRamdiskPages)
  496. //
  497. // rsm to reset PSR.i bit
  498. //
  499. rsm 1 << PSR_I // reset PSR.i bit
  500. ;;
  501. rsm 1 << PSR_IC // reset PSR.ic bit
  502. ;;
  503. srlz.d // serialize
  504. ;;
  505. srlz.i
  506. ;;
  507. movl t0 = KSEG0_BASE
  508. movl t2 = ITIR_VALUE(0,PS_1M)
  509. ;;
  510. add t0 = t0, a0
  511. ;;
  512. ptr.i t0, t2
  513. ;;
  514. ptr.d t0, t2
  515. ;;
  516. srlz.d // serialize
  517. ;;
  518. srlz.i
  519. ;;
  520. ssm 1 << PSR_IC // set PSR.ic bit again
  521. ;;
  522. ssm 1 << PSR_I // set PSR.i bit again
  523. ;;
  524. srlz.d // serialize
  525. ;;
  526. srlz.i
  527. ;;
  528. LEAF_RETURN
  529. LEAF_EXIT(BlpUnmapRamdiskPages)
  530. LEAF_ENTRY(BlpInitializeRamdiskMapping)
  531. LEAF_RETURN
  532. LEAF_EXIT(BlpInitializeRamdiskMapping)