mca_asm.S 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. //
  2. // assembly portion of the IA64 MCA handling
  3. //
  4. // Mods by cfleck to integrate into kernel build
  5. // 00/03/15 davidm Added various stop bits to get a clean compile
  6. //
  7. // 00/03/29 cfleck Added code to save INIT handoff state in pt_regs format, switch to temp
  8. // kstack, switch modes, jump to C INIT handler
  9. //
  10. // 02/01/04 J.Hall <jenna.s.hall@intel.com>
  11. // Before entering virtual mode code:
  12. // 1. Check for TLB CPU error
  13. // 2. Restore current thread pointer to kr6
  14. // 3. Move stack ptr 16 bytes to conform to C calling convention
  15. //
  16. // 04/11/12 Russ Anderson <rja@sgi.com>
  17. // Added per cpu MCA/INIT stack save areas.
  18. //
  19. // 12/08/05 Keith Owens <kaos@sgi.com>
  20. // Use per cpu MCA/INIT stacks for all data.
  21. //
  22. #include <linux/config.h>
  23. #include <linux/threads.h>
  24. #include <asm/asmmacro.h>
  25. #include <asm/pgtable.h>
  26. #include <asm/processor.h>
  27. #include <asm/mca_asm.h>
  28. #include <asm/mca.h>
  29. #include "entry.h"
  30. #define GET_IA64_MCA_DATA(reg) \
  31. GET_THIS_PADDR(reg, ia64_mca_data) \
  32. ;; \
  33. ld8 reg=[reg]
  34. .global ia64_do_tlb_purge
  35. .global ia64_os_mca_dispatch
  36. .global ia64_os_init_dispatch_monarch
  37. .global ia64_os_init_dispatch_slave
  38. .text
  39. .align 16
  40. //StartMain////////////////////////////////////////////////////////////////////
  41. /*
  42. * Just the TLB purge part is moved to a separate function
  43. * so we can re-use the code for cpu hotplug code as well
  44. * Caller should now setup b1, so we can branch once the
  45. * tlb flush is complete.
  46. */
  47. ia64_do_tlb_purge:
  48. #define O(member) IA64_CPUINFO_##member##_OFFSET
  49. GET_THIS_PADDR(r2, cpu_info) // load phys addr of cpu_info into r2
  50. ;;
  51. addl r17=O(PTCE_STRIDE),r2
  52. addl r2=O(PTCE_BASE),r2
  53. ;;
  54. ld8 r18=[r2],(O(PTCE_COUNT)-O(PTCE_BASE));; // r18=ptce_base
  55. ld4 r19=[r2],4 // r19=ptce_count[0]
  56. ld4 r21=[r17],4 // r21=ptce_stride[0]
  57. ;;
  58. ld4 r20=[r2] // r20=ptce_count[1]
  59. ld4 r22=[r17] // r22=ptce_stride[1]
  60. mov r24=0
  61. ;;
  62. adds r20=-1,r20
  63. ;;
  64. #undef O
  65. 2:
  66. cmp.ltu p6,p7=r24,r19
  67. (p7) br.cond.dpnt.few 4f
  68. mov ar.lc=r20
  69. 3:
  70. ptc.e r18
  71. ;;
  72. add r18=r22,r18
  73. br.cloop.sptk.few 3b
  74. ;;
  75. add r18=r21,r18
  76. add r24=1,r24
  77. ;;
  78. br.sptk.few 2b
  79. 4:
  80. srlz.i // srlz.i implies srlz.d
  81. ;;
  82. // Now purge addresses formerly mapped by TR registers
  83. // 1. Purge ITR&DTR for kernel.
  84. movl r16=KERNEL_START
  85. mov r18=KERNEL_TR_PAGE_SHIFT<<2
  86. ;;
  87. ptr.i r16, r18
  88. ptr.d r16, r18
  89. ;;
  90. srlz.i
  91. ;;
  92. srlz.d
  93. ;;
  94. // 2. Purge DTR for PERCPU data.
  95. movl r16=PERCPU_ADDR
  96. mov r18=PERCPU_PAGE_SHIFT<<2
  97. ;;
  98. ptr.d r16,r18
  99. ;;
  100. srlz.d
  101. ;;
  102. // 3. Purge ITR for PAL code.
  103. GET_THIS_PADDR(r2, ia64_mca_pal_base)
  104. ;;
  105. ld8 r16=[r2]
  106. mov r18=IA64_GRANULE_SHIFT<<2
  107. ;;
  108. ptr.i r16,r18
  109. ;;
  110. srlz.i
  111. ;;
  112. // 4. Purge DTR for stack.
  113. mov r16=IA64_KR(CURRENT_STACK)
  114. ;;
  115. shl r16=r16,IA64_GRANULE_SHIFT
  116. movl r19=PAGE_OFFSET
  117. ;;
  118. add r16=r19,r16
  119. mov r18=IA64_GRANULE_SHIFT<<2
  120. ;;
  121. ptr.d r16,r18
  122. ;;
  123. srlz.i
  124. ;;
  125. // Now branch away to caller.
  126. br.sptk.many b1
  127. ;;
  128. //EndMain//////////////////////////////////////////////////////////////////////
  129. //StartMain////////////////////////////////////////////////////////////////////
  130. ia64_os_mca_dispatch:
  131. // Serialize all MCA processing
  132. mov r3=1;;
  133. LOAD_PHYSICAL(p0,r2,ia64_mca_serialize);;
  134. ia64_os_mca_spin:
  135. xchg4 r4=[r2],r3;;
  136. cmp.ne p6,p0=r4,r0
  137. (p6) br ia64_os_mca_spin
  138. mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
  139. LOAD_PHYSICAL(p0,r2,1f) // return address
  140. mov r19=1 // All MCA events are treated as monarch (for now)
  141. br.sptk ia64_state_save // save the state that is not in minstate
  142. 1:
  143. GET_IA64_MCA_DATA(r2)
  144. // Using MCA stack, struct ia64_sal_os_state, variable proc_state_param
  145. ;;
  146. add r3=IA64_MCA_CPU_MCA_STACK_OFFSET+MCA_SOS_OFFSET+IA64_SAL_OS_STATE_PROC_STATE_PARAM_OFFSET, r2
  147. ;;
  148. ld8 r18=[r3] // Get processor state parameter on existing PALE_CHECK.
  149. ;;
  150. tbit.nz p6,p7=r18,60
  151. (p7) br.spnt done_tlb_purge_and_reload
  152. // The following code purges TC and TR entries. Then reload all TC entries.
  153. // Purge percpu data TC entries.
  154. begin_tlb_purge_and_reload:
  155. movl r18=ia64_reload_tr;;
  156. LOAD_PHYSICAL(p0,r18,ia64_reload_tr);;
  157. mov b1=r18;;
  158. br.sptk.many ia64_do_tlb_purge;;
  159. ia64_reload_tr:
  160. // Finally reload the TR registers.
  161. // 1. Reload DTR/ITR registers for kernel.
  162. mov r18=KERNEL_TR_PAGE_SHIFT<<2
  163. movl r17=KERNEL_START
  164. ;;
  165. mov cr.itir=r18
  166. mov cr.ifa=r17
  167. mov r16=IA64_TR_KERNEL
  168. mov r19=ip
  169. movl r18=PAGE_KERNEL
  170. ;;
  171. dep r17=0,r19,0, KERNEL_TR_PAGE_SHIFT
  172. ;;
  173. or r18=r17,r18
  174. ;;
  175. itr.i itr[r16]=r18
  176. ;;
  177. itr.d dtr[r16]=r18
  178. ;;
  179. srlz.i
  180. srlz.d
  181. ;;
  182. // 2. Reload DTR register for PERCPU data.
  183. GET_THIS_PADDR(r2, ia64_mca_per_cpu_pte)
  184. ;;
  185. movl r16=PERCPU_ADDR // vaddr
  186. movl r18=PERCPU_PAGE_SHIFT<<2
  187. ;;
  188. mov cr.itir=r18
  189. mov cr.ifa=r16
  190. ;;
  191. ld8 r18=[r2] // load per-CPU PTE
  192. mov r16=IA64_TR_PERCPU_DATA;
  193. ;;
  194. itr.d dtr[r16]=r18
  195. ;;
  196. srlz.d
  197. ;;
  198. // 3. Reload ITR for PAL code.
  199. GET_THIS_PADDR(r2, ia64_mca_pal_pte)
  200. ;;
  201. ld8 r18=[r2] // load PAL PTE
  202. ;;
  203. GET_THIS_PADDR(r2, ia64_mca_pal_base)
  204. ;;
  205. ld8 r16=[r2] // load PAL vaddr
  206. mov r19=IA64_GRANULE_SHIFT<<2
  207. ;;
  208. mov cr.itir=r19
  209. mov cr.ifa=r16
  210. mov r20=IA64_TR_PALCODE
  211. ;;
  212. itr.i itr[r20]=r18
  213. ;;
  214. srlz.i
  215. ;;
  216. // 4. Reload DTR for stack.
  217. mov r16=IA64_KR(CURRENT_STACK)
  218. ;;
  219. shl r16=r16,IA64_GRANULE_SHIFT
  220. movl r19=PAGE_OFFSET
  221. ;;
  222. add r18=r19,r16
  223. movl r20=PAGE_KERNEL
  224. ;;
  225. add r16=r20,r16
  226. mov r19=IA64_GRANULE_SHIFT<<2
  227. ;;
  228. mov cr.itir=r19
  229. mov cr.ifa=r18
  230. mov r20=IA64_TR_CURRENT_STACK
  231. ;;
  232. itr.d dtr[r20]=r16
  233. ;;
  234. srlz.d
  235. done_tlb_purge_and_reload:
  236. // switch to per cpu MCA stack
  237. mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
  238. LOAD_PHYSICAL(p0,r2,1f) // return address
  239. br.sptk ia64_new_stack
  240. 1:
  241. // everything saved, now we can set the kernel registers
  242. mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
  243. LOAD_PHYSICAL(p0,r2,1f) // return address
  244. br.sptk ia64_set_kernel_registers
  245. 1:
  246. // This must be done in physical mode
  247. GET_IA64_MCA_DATA(r2)
  248. ;;
  249. mov r7=r2
  250. // Enter virtual mode from physical mode
  251. VIRTUAL_MODE_ENTER(r2, r3, ia64_os_mca_virtual_begin, r4)
  252. // This code returns to SAL via SOS r2, in general SAL has no unwind
  253. // data. To get a clean termination when backtracing the C MCA/INIT
  254. // handler, set a dummy return address of 0 in this routine. That
  255. // requires that ia64_os_mca_virtual_begin be a global function.
  256. ENTRY(ia64_os_mca_virtual_begin)
  257. .prologue
  258. .save rp,r0
  259. .body
  260. mov ar.rsc=3 // set eager mode for C handler
  261. mov r2=r7 // see GET_IA64_MCA_DATA above
  262. ;;
  263. // Call virtual mode handler
  264. alloc r14=ar.pfs,0,0,3,0
  265. ;;
  266. DATA_PA_TO_VA(r2,r7)
  267. ;;
  268. add out0=IA64_MCA_CPU_MCA_STACK_OFFSET+MCA_PT_REGS_OFFSET, r2
  269. add out1=IA64_MCA_CPU_MCA_STACK_OFFSET+MCA_SWITCH_STACK_OFFSET, r2
  270. add out2=IA64_MCA_CPU_MCA_STACK_OFFSET+MCA_SOS_OFFSET, r2
  271. br.call.sptk.many b0=ia64_mca_handler
  272. // Revert back to physical mode before going back to SAL
  273. PHYSICAL_MODE_ENTER(r2, r3, ia64_os_mca_virtual_end, r4)
  274. ia64_os_mca_virtual_end:
  275. END(ia64_os_mca_virtual_begin)
  276. // switch back to previous stack
  277. alloc r14=ar.pfs,0,0,0,0 // remove the MCA handler frame
  278. mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
  279. LOAD_PHYSICAL(p0,r2,1f) // return address
  280. br.sptk ia64_old_stack
  281. 1:
  282. mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
  283. LOAD_PHYSICAL(p0,r2,1f) // return address
  284. br.sptk ia64_state_restore // restore the SAL state
  285. 1:
  286. mov b0=r12 // SAL_CHECK return address
  287. // release lock
  288. LOAD_PHYSICAL(p0,r3,ia64_mca_serialize);;
  289. st4.rel [r3]=r0
  290. br b0
  291. //EndMain//////////////////////////////////////////////////////////////////////
  292. //StartMain////////////////////////////////////////////////////////////////////
  293. //
  294. // SAL to OS entry point for INIT on all processors. This has been defined for
  295. // registration purposes with SAL as a part of ia64_mca_init. Monarch and
  296. // slave INIT have identical processing, except for the value of the
  297. // sos->monarch flag in r19.
  298. //
  299. ia64_os_init_dispatch_monarch:
  300. mov r19=1 // Bow, bow, ye lower middle classes!
  301. br.sptk ia64_os_init_dispatch
  302. ia64_os_init_dispatch_slave:
  303. mov r19=0 // <igor>yeth, mathter</igor>
  304. ia64_os_init_dispatch:
  305. mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
  306. LOAD_PHYSICAL(p0,r2,1f) // return address
  307. br.sptk ia64_state_save // save the state that is not in minstate
  308. 1:
  309. // switch to per cpu INIT stack
  310. mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
  311. LOAD_PHYSICAL(p0,r2,1f) // return address
  312. br.sptk ia64_new_stack
  313. 1:
  314. // everything saved, now we can set the kernel registers
  315. mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
  316. LOAD_PHYSICAL(p0,r2,1f) // return address
  317. br.sptk ia64_set_kernel_registers
  318. 1:
  319. // This must be done in physical mode
  320. GET_IA64_MCA_DATA(r2)
  321. ;;
  322. mov r7=r2
  323. // Enter virtual mode from physical mode
  324. VIRTUAL_MODE_ENTER(r2, r3, ia64_os_init_virtual_begin, r4)
  325. // This code returns to SAL via SOS r2, in general SAL has no unwind
  326. // data. To get a clean termination when backtracing the C MCA/INIT
  327. // handler, set a dummy return address of 0 in this routine. That
  328. // requires that ia64_os_init_virtual_begin be a global function.
  329. ENTRY(ia64_os_init_virtual_begin)
  330. .prologue
  331. .save rp,r0
  332. .body
  333. mov ar.rsc=3 // set eager mode for C handler
  334. mov r2=r7 // see GET_IA64_MCA_DATA above
  335. ;;
  336. // Call virtual mode handler
  337. alloc r14=ar.pfs,0,0,3,0
  338. ;;
  339. DATA_PA_TO_VA(r2,r7)
  340. ;;
  341. add out0=IA64_MCA_CPU_INIT_STACK_OFFSET+MCA_PT_REGS_OFFSET, r2
  342. add out1=IA64_MCA_CPU_INIT_STACK_OFFSET+MCA_SWITCH_STACK_OFFSET, r2
  343. add out2=IA64_MCA_CPU_INIT_STACK_OFFSET+MCA_SOS_OFFSET, r2
  344. br.call.sptk.many b0=ia64_init_handler
  345. // Revert back to physical mode before going back to SAL
  346. PHYSICAL_MODE_ENTER(r2, r3, ia64_os_init_virtual_end, r4)
  347. ia64_os_init_virtual_end:
  348. END(ia64_os_init_virtual_begin)
  349. mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
  350. LOAD_PHYSICAL(p0,r2,1f) // return address
  351. br.sptk ia64_state_restore // restore the SAL state
  352. 1:
  353. // switch back to previous stack
  354. alloc r14=ar.pfs,0,0,0,0 // remove the INIT handler frame
  355. mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
  356. LOAD_PHYSICAL(p0,r2,1f) // return address
  357. br.sptk ia64_old_stack
  358. 1:
  359. mov b0=r12 // SAL_CHECK return address
  360. br b0
  361. //EndMain//////////////////////////////////////////////////////////////////////
  362. // common defines for the stubs
  363. #define ms r4
  364. #define regs r5
  365. #define temp1 r2 /* careful, it overlaps with input registers */
  366. #define temp2 r3 /* careful, it overlaps with input registers */
  367. #define temp3 r7
  368. #define temp4 r14
  369. //++
  370. // Name:
  371. // ia64_state_save()
  372. //
  373. // Stub Description:
  374. //
  375. // Save the state that is not in minstate. This is sensitive to the layout of
  376. // struct ia64_sal_os_state in mca.h.
  377. //
  378. // r2 contains the return address, r3 contains either
  379. // IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
  380. //
  381. // The OS to SAL section of struct ia64_sal_os_state is set to a default
  382. // value of cold boot (MCA) or warm boot (INIT) and return to the same
  383. // context. ia64_sal_os_state is also used to hold some registers that
  384. // need to be saved and restored across the stack switches.
  385. //
  386. // Most input registers to this stub come from PAL/SAL
  387. // r1 os gp, physical
  388. // r8 pal_proc entry point
  389. // r9 sal_proc entry point
  390. // r10 sal gp
  391. // r11 MCA - rendevzous state, INIT - reason code
  392. // r12 sal return address
  393. // r17 pal min_state
  394. // r18 processor state parameter
  395. // r19 monarch flag, set by the caller of this routine
  396. //
  397. // In addition to the SAL to OS state, this routine saves all the
  398. // registers that appear in struct pt_regs and struct switch_stack,
  399. // excluding those that are already in the PAL minstate area. This
  400. // results in a partial pt_regs and switch_stack, the C code copies the
  401. // remaining registers from PAL minstate to pt_regs and switch_stack. The
  402. // resulting structures contain all the state of the original process when
  403. // MCA/INIT occurred.
  404. //
  405. //--
  406. ia64_state_save:
  407. add regs=MCA_SOS_OFFSET, r3
  408. add ms=MCA_SOS_OFFSET+8, r3
  409. mov b0=r2 // save return address
  410. cmp.eq p1,p2=IA64_MCA_CPU_MCA_STACK_OFFSET, r3
  411. ;;
  412. GET_IA64_MCA_DATA(temp2)
  413. ;;
  414. add temp1=temp2, regs // struct ia64_sal_os_state on MCA or INIT stack
  415. add temp2=temp2, ms // struct ia64_sal_os_state+8 on MCA or INIT stack
  416. ;;
  417. mov regs=temp1 // save the start of sos
  418. st8 [temp1]=r1,16 // os_gp
  419. st8 [temp2]=r8,16 // pal_proc
  420. ;;
  421. st8 [temp1]=r9,16 // sal_proc
  422. st8 [temp2]=r11,16 // rv_rc
  423. mov r11=cr.iipa
  424. ;;
  425. st8 [temp1]=r18,16 // proc_state_param
  426. st8 [temp2]=r19,16 // monarch
  427. mov r6=IA64_KR(CURRENT)
  428. ;;
  429. st8 [temp1]=r12,16 // sal_ra
  430. st8 [temp2]=r10,16 // sal_gp
  431. mov r12=cr.isr
  432. ;;
  433. st8 [temp1]=r17,16 // pal_min_state
  434. st8 [temp2]=r6,16 // prev_IA64_KR_CURRENT
  435. mov r6=cr.ifa
  436. ;;
  437. st8 [temp1]=r0,16 // prev_task, starts off as NULL
  438. st8 [temp2]=r12,16 // cr.isr
  439. mov r12=cr.itir
  440. ;;
  441. st8 [temp1]=r6,16 // cr.ifa
  442. st8 [temp2]=r12,16 // cr.itir
  443. mov r12=cr.iim
  444. ;;
  445. st8 [temp1]=r11,16 // cr.iipa
  446. st8 [temp2]=r12,16 // cr.iim
  447. mov r6=cr.iha
  448. (p1) mov r12=IA64_MCA_COLD_BOOT
  449. (p2) mov r12=IA64_INIT_WARM_BOOT
  450. ;;
  451. st8 [temp1]=r6,16 // cr.iha
  452. st8 [temp2]=r12 // os_status, default is cold boot
  453. mov r6=IA64_MCA_SAME_CONTEXT
  454. ;;
  455. st8 [temp1]=r6 // context, default is same context
  456. // Save the pt_regs data that is not in minstate. The previous code
  457. // left regs at sos.
  458. add regs=MCA_PT_REGS_OFFSET-MCA_SOS_OFFSET, regs
  459. ;;
  460. add temp1=PT(B6), regs
  461. mov temp3=b6
  462. mov temp4=b7
  463. add temp2=PT(B7), regs
  464. ;;
  465. st8 [temp1]=temp3,PT(AR_CSD)-PT(B6) // save b6
  466. st8 [temp2]=temp4,PT(AR_SSD)-PT(B7) // save b7
  467. mov temp3=ar.csd
  468. mov temp4=ar.ssd
  469. cover // must be last in group
  470. ;;
  471. st8 [temp1]=temp3,PT(AR_UNAT)-PT(AR_CSD) // save ar.csd
  472. st8 [temp2]=temp4,PT(AR_PFS)-PT(AR_SSD) // save ar.ssd
  473. mov temp3=ar.unat
  474. mov temp4=ar.pfs
  475. ;;
  476. st8 [temp1]=temp3,PT(AR_RNAT)-PT(AR_UNAT) // save ar.unat
  477. st8 [temp2]=temp4,PT(AR_BSPSTORE)-PT(AR_PFS) // save ar.pfs
  478. mov temp3=ar.rnat
  479. mov temp4=ar.bspstore
  480. ;;
  481. st8 [temp1]=temp3,PT(LOADRS)-PT(AR_RNAT) // save ar.rnat
  482. st8 [temp2]=temp4,PT(AR_FPSR)-PT(AR_BSPSTORE) // save ar.bspstore
  483. mov temp3=ar.bsp
  484. ;;
  485. sub temp3=temp3, temp4 // ar.bsp - ar.bspstore
  486. mov temp4=ar.fpsr
  487. ;;
  488. shl temp3=temp3,16 // compute ar.rsc to be used for "loadrs"
  489. ;;
  490. st8 [temp1]=temp3,PT(AR_CCV)-PT(LOADRS) // save loadrs
  491. st8 [temp2]=temp4,PT(F6)-PT(AR_FPSR) // save ar.fpsr
  492. mov temp3=ar.ccv
  493. ;;
  494. st8 [temp1]=temp3,PT(F7)-PT(AR_CCV) // save ar.ccv
  495. stf.spill [temp2]=f6,PT(F8)-PT(F6)
  496. ;;
  497. stf.spill [temp1]=f7,PT(F9)-PT(F7)
  498. stf.spill [temp2]=f8,PT(F10)-PT(F8)
  499. ;;
  500. stf.spill [temp1]=f9,PT(F11)-PT(F9)
  501. stf.spill [temp2]=f10
  502. ;;
  503. stf.spill [temp1]=f11
  504. // Save the switch_stack data that is not in minstate nor pt_regs. The
  505. // previous code left regs at pt_regs.
  506. add regs=MCA_SWITCH_STACK_OFFSET-MCA_PT_REGS_OFFSET, regs
  507. ;;
  508. add temp1=SW(F2), regs
  509. add temp2=SW(F3), regs
  510. ;;
  511. stf.spill [temp1]=f2,32
  512. stf.spill [temp2]=f3,32
  513. ;;
  514. stf.spill [temp1]=f4,32
  515. stf.spill [temp2]=f5,32
  516. ;;
  517. stf.spill [temp1]=f12,32
  518. stf.spill [temp2]=f13,32
  519. ;;
  520. stf.spill [temp1]=f14,32
  521. stf.spill [temp2]=f15,32
  522. ;;
  523. stf.spill [temp1]=f16,32
  524. stf.spill [temp2]=f17,32
  525. ;;
  526. stf.spill [temp1]=f18,32
  527. stf.spill [temp2]=f19,32
  528. ;;
  529. stf.spill [temp1]=f20,32
  530. stf.spill [temp2]=f21,32
  531. ;;
  532. stf.spill [temp1]=f22,32
  533. stf.spill [temp2]=f23,32
  534. ;;
  535. stf.spill [temp1]=f24,32
  536. stf.spill [temp2]=f25,32
  537. ;;
  538. stf.spill [temp1]=f26,32
  539. stf.spill [temp2]=f27,32
  540. ;;
  541. stf.spill [temp1]=f28,32
  542. stf.spill [temp2]=f29,32
  543. ;;
  544. stf.spill [temp1]=f30,SW(B2)-SW(F30)
  545. stf.spill [temp2]=f31,SW(B3)-SW(F31)
  546. mov temp3=b2
  547. mov temp4=b3
  548. ;;
  549. st8 [temp1]=temp3,16 // save b2
  550. st8 [temp2]=temp4,16 // save b3
  551. mov temp3=b4
  552. mov temp4=b5
  553. ;;
  554. st8 [temp1]=temp3,SW(AR_LC)-SW(B4) // save b4
  555. st8 [temp2]=temp4 // save b5
  556. mov temp3=ar.lc
  557. ;;
  558. st8 [temp1]=temp3 // save ar.lc
  559. // FIXME: Some proms are incorrectly accessing the minstate area as
  560. // cached data. The C code uses region 6, uncached virtual. Ensure
  561. // that there is no cache data lying around for the first 1K of the
  562. // minstate area.
  563. // Remove this code in September 2006, that gives platforms a year to
  564. // fix their proms and get their customers updated.
  565. add r1=32*1,r17
  566. add r2=32*2,r17
  567. add r3=32*3,r17
  568. add r4=32*4,r17
  569. add r5=32*5,r17
  570. add r6=32*6,r17
  571. add r7=32*7,r17
  572. ;;
  573. fc r17
  574. fc r1
  575. fc r2
  576. fc r3
  577. fc r4
  578. fc r5
  579. fc r6
  580. fc r7
  581. add r17=32*8,r17
  582. add r1=32*8,r1
  583. add r2=32*8,r2
  584. add r3=32*8,r3
  585. add r4=32*8,r4
  586. add r5=32*8,r5
  587. add r6=32*8,r6
  588. add r7=32*8,r7
  589. ;;
  590. fc r17
  591. fc r1
  592. fc r2
  593. fc r3
  594. fc r4
  595. fc r5
  596. fc r6
  597. fc r7
  598. add r17=32*8,r17
  599. add r1=32*8,r1
  600. add r2=32*8,r2
  601. add r3=32*8,r3
  602. add r4=32*8,r4
  603. add r5=32*8,r5
  604. add r6=32*8,r6
  605. add r7=32*8,r7
  606. ;;
  607. fc r17
  608. fc r1
  609. fc r2
  610. fc r3
  611. fc r4
  612. fc r5
  613. fc r6
  614. fc r7
  615. add r17=32*8,r17
  616. add r1=32*8,r1
  617. add r2=32*8,r2
  618. add r3=32*8,r3
  619. add r4=32*8,r4
  620. add r5=32*8,r5
  621. add r6=32*8,r6
  622. add r7=32*8,r7
  623. ;;
  624. fc r17
  625. fc r1
  626. fc r2
  627. fc r3
  628. fc r4
  629. fc r5
  630. fc r6
  631. fc r7
  632. br.sptk b0
  633. //EndStub//////////////////////////////////////////////////////////////////////
  634. //++
  635. // Name:
  636. // ia64_state_restore()
  637. //
  638. // Stub Description:
  639. //
  640. // Restore the SAL/OS state. This is sensitive to the layout of struct
  641. // ia64_sal_os_state in mca.h.
  642. //
  643. // r2 contains the return address, r3 contains either
  644. // IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
  645. //
  646. // In addition to the SAL to OS state, this routine restores all the
  647. // registers that appear in struct pt_regs and struct switch_stack,
  648. // excluding those in the PAL minstate area.
  649. //
  650. //--
  651. ia64_state_restore:
  652. // Restore the switch_stack data that is not in minstate nor pt_regs.
  653. add regs=MCA_SWITCH_STACK_OFFSET, r3
  654. mov b0=r2 // save return address
  655. ;;
  656. GET_IA64_MCA_DATA(temp2)
  657. ;;
  658. add regs=temp2, regs
  659. ;;
  660. add temp1=SW(F2), regs
  661. add temp2=SW(F3), regs
  662. ;;
  663. ldf.fill f2=[temp1],32
  664. ldf.fill f3=[temp2],32
  665. ;;
  666. ldf.fill f4=[temp1],32
  667. ldf.fill f5=[temp2],32
  668. ;;
  669. ldf.fill f12=[temp1],32
  670. ldf.fill f13=[temp2],32
  671. ;;
  672. ldf.fill f14=[temp1],32
  673. ldf.fill f15=[temp2],32
  674. ;;
  675. ldf.fill f16=[temp1],32
  676. ldf.fill f17=[temp2],32
  677. ;;
  678. ldf.fill f18=[temp1],32
  679. ldf.fill f19=[temp2],32
  680. ;;
  681. ldf.fill f20=[temp1],32
  682. ldf.fill f21=[temp2],32
  683. ;;
  684. ldf.fill f22=[temp1],32
  685. ldf.fill f23=[temp2],32
  686. ;;
  687. ldf.fill f24=[temp1],32
  688. ldf.fill f25=[temp2],32
  689. ;;
  690. ldf.fill f26=[temp1],32
  691. ldf.fill f27=[temp2],32
  692. ;;
  693. ldf.fill f28=[temp1],32
  694. ldf.fill f29=[temp2],32
  695. ;;
  696. ldf.fill f30=[temp1],SW(B2)-SW(F30)
  697. ldf.fill f31=[temp2],SW(B3)-SW(F31)
  698. ;;
  699. ld8 temp3=[temp1],16 // restore b2
  700. ld8 temp4=[temp2],16 // restore b3
  701. ;;
  702. mov b2=temp3
  703. mov b3=temp4
  704. ld8 temp3=[temp1],SW(AR_LC)-SW(B4) // restore b4
  705. ld8 temp4=[temp2] // restore b5
  706. ;;
  707. mov b4=temp3
  708. mov b5=temp4
  709. ld8 temp3=[temp1] // restore ar.lc
  710. ;;
  711. mov ar.lc=temp3
  712. // Restore the pt_regs data that is not in minstate. The previous code
  713. // left regs at switch_stack.
  714. add regs=MCA_PT_REGS_OFFSET-MCA_SWITCH_STACK_OFFSET, regs
  715. ;;
  716. add temp1=PT(B6), regs
  717. add temp2=PT(B7), regs
  718. ;;
  719. ld8 temp3=[temp1],PT(AR_CSD)-PT(B6) // restore b6
  720. ld8 temp4=[temp2],PT(AR_SSD)-PT(B7) // restore b7
  721. ;;
  722. mov b6=temp3
  723. mov b7=temp4
  724. ld8 temp3=[temp1],PT(AR_UNAT)-PT(AR_CSD) // restore ar.csd
  725. ld8 temp4=[temp2],PT(AR_PFS)-PT(AR_SSD) // restore ar.ssd
  726. ;;
  727. mov ar.csd=temp3
  728. mov ar.ssd=temp4
  729. ld8 temp3=[temp1] // restore ar.unat
  730. add temp1=PT(AR_CCV)-PT(AR_UNAT), temp1
  731. ld8 temp4=[temp2],PT(AR_FPSR)-PT(AR_PFS) // restore ar.pfs
  732. ;;
  733. mov ar.unat=temp3
  734. mov ar.pfs=temp4
  735. // ar.rnat, ar.bspstore, loadrs are restore in ia64_old_stack.
  736. ld8 temp3=[temp1],PT(F6)-PT(AR_CCV) // restore ar.ccv
  737. ld8 temp4=[temp2],PT(F7)-PT(AR_FPSR) // restore ar.fpsr
  738. ;;
  739. mov ar.ccv=temp3
  740. mov ar.fpsr=temp4
  741. ldf.fill f6=[temp1],PT(F8)-PT(F6)
  742. ldf.fill f7=[temp2],PT(F9)-PT(F7)
  743. ;;
  744. ldf.fill f8=[temp1],PT(F10)-PT(F8)
  745. ldf.fill f9=[temp2],PT(F11)-PT(F9)
  746. ;;
  747. ldf.fill f10=[temp1]
  748. ldf.fill f11=[temp2]
  749. // Restore the SAL to OS state. The previous code left regs at pt_regs.
  750. add regs=MCA_SOS_OFFSET-MCA_PT_REGS_OFFSET, regs
  751. ;;
  752. add temp1=IA64_SAL_OS_STATE_COMMON_OFFSET, regs
  753. add temp2=IA64_SAL_OS_STATE_COMMON_OFFSET+8, regs
  754. ;;
  755. ld8 r12=[temp1],16 // sal_ra
  756. ld8 r9=[temp2],16 // sal_gp
  757. ;;
  758. ld8 r22=[temp1],24 // pal_min_state, virtual. skip prev_task
  759. ld8 r21=[temp2],16 // prev_IA64_KR_CURRENT
  760. ;;
  761. ld8 temp3=[temp1],16 // cr.isr
  762. ld8 temp4=[temp2],16 // cr.ifa
  763. ;;
  764. mov cr.isr=temp3
  765. mov cr.ifa=temp4
  766. ld8 temp3=[temp1],16 // cr.itir
  767. ld8 temp4=[temp2],16 // cr.iipa
  768. ;;
  769. mov cr.itir=temp3
  770. mov cr.iipa=temp4
  771. ld8 temp3=[temp1],16 // cr.iim
  772. ld8 temp4=[temp2],16 // cr.iha
  773. ;;
  774. mov cr.iim=temp3
  775. mov cr.iha=temp4
  776. dep r22=0,r22,62,2 // pal_min_state, physical, uncached
  777. mov IA64_KR(CURRENT)=r21
  778. ld8 r8=[temp1] // os_status
  779. ld8 r10=[temp2] // context
  780. br.sptk b0
  781. //EndStub//////////////////////////////////////////////////////////////////////
  782. //++
  783. // Name:
  784. // ia64_new_stack()
  785. //
  786. // Stub Description:
  787. //
  788. // Switch to the MCA/INIT stack.
  789. //
  790. // r2 contains the return address, r3 contains either
  791. // IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
  792. //
  793. // On entry RBS is still on the original stack, this routine switches RBS
  794. // to use the MCA/INIT stack.
  795. //
  796. // On entry, sos->pal_min_state is physical, on exit it is virtual.
  797. //
  798. //--
  799. ia64_new_stack:
  800. add regs=MCA_PT_REGS_OFFSET, r3
  801. add temp2=MCA_SOS_OFFSET+IA64_SAL_OS_STATE_PAL_MIN_STATE_OFFSET, r3
  802. mov b0=r2 // save return address
  803. GET_IA64_MCA_DATA(temp1)
  804. invala
  805. ;;
  806. add temp2=temp2, temp1 // struct ia64_sal_os_state.pal_min_state on MCA or INIT stack
  807. add regs=regs, temp1 // struct pt_regs on MCA or INIT stack
  808. ;;
  809. // Address of minstate area provided by PAL is physical, uncacheable.
  810. // Convert to Linux virtual address in region 6 for C code.
  811. ld8 ms=[temp2] // pal_min_state, physical
  812. ;;
  813. dep temp1=-1,ms,62,2 // set region 6
  814. mov temp3=IA64_RBS_OFFSET-MCA_PT_REGS_OFFSET
  815. ;;
  816. st8 [temp2]=temp1 // pal_min_state, virtual
  817. add temp4=temp3, regs // start of bspstore on new stack
  818. ;;
  819. mov ar.bspstore=temp4 // switch RBS to MCA/INIT stack
  820. ;;
  821. flushrs // must be first in group
  822. br.sptk b0
  823. //EndStub//////////////////////////////////////////////////////////////////////
  824. //++
  825. // Name:
  826. // ia64_old_stack()
  827. //
  828. // Stub Description:
  829. //
  830. // Switch to the old stack.
  831. //
  832. // r2 contains the return address, r3 contains either
  833. // IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
  834. //
  835. // On entry, pal_min_state is virtual, on exit it is physical.
  836. //
  837. // On entry RBS is on the MCA/INIT stack, this routine switches RBS
  838. // back to the previous stack.
  839. //
  840. // The psr is set to all zeroes. SAL return requires either all zeroes or
  841. // just psr.mc set. Leaving psr.mc off allows INIT to be issued if this
  842. // code does not perform correctly.
  843. //
  844. // The dirty registers at the time of the event were flushed to the
  845. // MCA/INIT stack in ia64_pt_regs_save(). Restore the dirty registers
  846. // before reverting to the previous bspstore.
  847. //--
  848. ia64_old_stack:
  849. add regs=MCA_PT_REGS_OFFSET, r3
  850. mov b0=r2 // save return address
  851. GET_IA64_MCA_DATA(temp2)
  852. LOAD_PHYSICAL(p0,temp1,1f)
  853. ;;
  854. mov cr.ipsr=r0
  855. mov cr.ifs=r0
  856. mov cr.iip=temp1
  857. ;;
  858. invala
  859. rfi
  860. 1:
  861. add regs=regs, temp2 // struct pt_regs on MCA or INIT stack
  862. ;;
  863. add temp1=PT(LOADRS), regs
  864. ;;
  865. ld8 temp2=[temp1],PT(AR_BSPSTORE)-PT(LOADRS) // restore loadrs
  866. ;;
  867. ld8 temp3=[temp1],PT(AR_RNAT)-PT(AR_BSPSTORE) // restore ar.bspstore
  868. mov ar.rsc=temp2
  869. ;;
  870. loadrs
  871. ld8 temp4=[temp1] // restore ar.rnat
  872. ;;
  873. mov ar.bspstore=temp3 // back to old stack
  874. ;;
  875. mov ar.rnat=temp4
  876. ;;
  877. br.sptk b0
  878. //EndStub//////////////////////////////////////////////////////////////////////
  879. //++
  880. // Name:
  881. // ia64_set_kernel_registers()
  882. //
  883. // Stub Description:
  884. //
  885. // Set the registers that are required by the C code in order to run on an
  886. // MCA/INIT stack.
  887. //
  888. // r2 contains the return address, r3 contains either
  889. // IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
  890. //
  891. //--
  892. ia64_set_kernel_registers:
  893. add temp3=MCA_SP_OFFSET, r3
  894. add temp4=MCA_SOS_OFFSET+IA64_SAL_OS_STATE_OS_GP_OFFSET, r3
  895. mov b0=r2 // save return address
  896. GET_IA64_MCA_DATA(temp1)
  897. ;;
  898. add temp4=temp4, temp1 // &struct ia64_sal_os_state.os_gp
  899. add r12=temp1, temp3 // kernel stack pointer on MCA/INIT stack
  900. add r13=temp1, r3 // set current to start of MCA/INIT stack
  901. ;;
  902. ld8 r1=[temp4] // OS GP from SAL OS state
  903. ;;
  904. DATA_PA_TO_VA(r1,temp1)
  905. DATA_PA_TO_VA(r12,temp2)
  906. DATA_PA_TO_VA(r13,temp3)
  907. ;;
  908. mov IA64_KR(CURRENT)=r13
  909. // FIXME: do I need to wire IA64_KR_CURRENT_STACK and IA64_TR_CURRENT_STACK?
  910. br.sptk b0
  911. //EndStub//////////////////////////////////////////////////////////////////////
  912. #undef ms
  913. #undef regs
  914. #undef temp1
  915. #undef temp2
  916. #undef temp3
  917. #undef temp4
  918. // Support function for mca.c, it is here to avoid using inline asm. Given the
  919. // address of an rnat slot, if that address is below the current ar.bspstore
  920. // then return the contents of that slot, otherwise return the contents of
  921. // ar.rnat.
  922. GLOBAL_ENTRY(ia64_get_rnat)
  923. alloc r14=ar.pfs,1,0,0,0
  924. mov ar.rsc=0
  925. ;;
  926. mov r14=ar.bspstore
  927. ;;
  928. cmp.lt p6,p7=in0,r14
  929. ;;
  930. (p6) ld8 r8=[in0]
  931. (p7) mov r8=ar.rnat
  932. mov ar.rsc=3
  933. br.ret.sptk.many rp
  934. END(ia64_get_rnat)