mca_asm.S 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  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+SOS(PROC_STATE_PARAM), 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 // proc_state_param
  426. st8 [temp2]=r19 // monarch
  427. mov r6=IA64_KR(CURRENT)
  428. add temp1=SOS(SAL_RA), regs
  429. add temp2=SOS(SAL_GP), regs
  430. ;;
  431. st8 [temp1]=r12,16 // sal_ra
  432. st8 [temp2]=r10,16 // sal_gp
  433. mov r12=cr.isr
  434. ;;
  435. st8 [temp1]=r17,16 // pal_min_state
  436. st8 [temp2]=r6,16 // prev_IA64_KR_CURRENT
  437. mov r6=IA64_KR(CURRENT_STACK)
  438. ;;
  439. st8 [temp1]=r6,16 // prev_IA64_KR_CURRENT_STACK
  440. st8 [temp2]=r0,16 // prev_task, starts off as NULL
  441. mov r6=cr.ifa
  442. ;;
  443. st8 [temp1]=r12,16 // cr.isr
  444. st8 [temp2]=r6,16 // cr.ifa
  445. mov r12=cr.itir
  446. ;;
  447. st8 [temp1]=r12,16 // cr.itir
  448. st8 [temp2]=r11,16 // cr.iipa
  449. mov r12=cr.iim
  450. ;;
  451. st8 [temp1]=r12 // cr.iim
  452. (p1) mov r12=IA64_MCA_COLD_BOOT
  453. (p2) mov r12=IA64_INIT_WARM_BOOT
  454. mov r6=cr.iha
  455. add temp1=SOS(OS_STATUS), regs
  456. ;;
  457. st8 [temp2]=r6 // cr.iha
  458. add temp2=SOS(CONTEXT), regs
  459. st8 [temp1]=r12 // os_status, default is cold boot
  460. mov r6=IA64_MCA_SAME_CONTEXT
  461. ;;
  462. st8 [temp2]=r6 // context, default is same context
  463. // Save the pt_regs data that is not in minstate. The previous code
  464. // left regs at sos.
  465. add regs=MCA_PT_REGS_OFFSET-MCA_SOS_OFFSET, regs
  466. ;;
  467. add temp1=PT(B6), regs
  468. mov temp3=b6
  469. mov temp4=b7
  470. add temp2=PT(B7), regs
  471. ;;
  472. st8 [temp1]=temp3,PT(AR_CSD)-PT(B6) // save b6
  473. st8 [temp2]=temp4,PT(AR_SSD)-PT(B7) // save b7
  474. mov temp3=ar.csd
  475. mov temp4=ar.ssd
  476. cover // must be last in group
  477. ;;
  478. st8 [temp1]=temp3,PT(AR_UNAT)-PT(AR_CSD) // save ar.csd
  479. st8 [temp2]=temp4,PT(AR_PFS)-PT(AR_SSD) // save ar.ssd
  480. mov temp3=ar.unat
  481. mov temp4=ar.pfs
  482. ;;
  483. st8 [temp1]=temp3,PT(AR_RNAT)-PT(AR_UNAT) // save ar.unat
  484. st8 [temp2]=temp4,PT(AR_BSPSTORE)-PT(AR_PFS) // save ar.pfs
  485. mov temp3=ar.rnat
  486. mov temp4=ar.bspstore
  487. ;;
  488. st8 [temp1]=temp3,PT(LOADRS)-PT(AR_RNAT) // save ar.rnat
  489. st8 [temp2]=temp4,PT(AR_FPSR)-PT(AR_BSPSTORE) // save ar.bspstore
  490. mov temp3=ar.bsp
  491. ;;
  492. sub temp3=temp3, temp4 // ar.bsp - ar.bspstore
  493. mov temp4=ar.fpsr
  494. ;;
  495. shl temp3=temp3,16 // compute ar.rsc to be used for "loadrs"
  496. ;;
  497. st8 [temp1]=temp3,PT(AR_CCV)-PT(LOADRS) // save loadrs
  498. st8 [temp2]=temp4,PT(F6)-PT(AR_FPSR) // save ar.fpsr
  499. mov temp3=ar.ccv
  500. ;;
  501. st8 [temp1]=temp3,PT(F7)-PT(AR_CCV) // save ar.ccv
  502. stf.spill [temp2]=f6,PT(F8)-PT(F6)
  503. ;;
  504. stf.spill [temp1]=f7,PT(F9)-PT(F7)
  505. stf.spill [temp2]=f8,PT(F10)-PT(F8)
  506. ;;
  507. stf.spill [temp1]=f9,PT(F11)-PT(F9)
  508. stf.spill [temp2]=f10
  509. ;;
  510. stf.spill [temp1]=f11
  511. // Save the switch_stack data that is not in minstate nor pt_regs. The
  512. // previous code left regs at pt_regs.
  513. add regs=MCA_SWITCH_STACK_OFFSET-MCA_PT_REGS_OFFSET, regs
  514. ;;
  515. add temp1=SW(F2), regs
  516. add temp2=SW(F3), regs
  517. ;;
  518. stf.spill [temp1]=f2,32
  519. stf.spill [temp2]=f3,32
  520. ;;
  521. stf.spill [temp1]=f4,32
  522. stf.spill [temp2]=f5,32
  523. ;;
  524. stf.spill [temp1]=f12,32
  525. stf.spill [temp2]=f13,32
  526. ;;
  527. stf.spill [temp1]=f14,32
  528. stf.spill [temp2]=f15,32
  529. ;;
  530. stf.spill [temp1]=f16,32
  531. stf.spill [temp2]=f17,32
  532. ;;
  533. stf.spill [temp1]=f18,32
  534. stf.spill [temp2]=f19,32
  535. ;;
  536. stf.spill [temp1]=f20,32
  537. stf.spill [temp2]=f21,32
  538. ;;
  539. stf.spill [temp1]=f22,32
  540. stf.spill [temp2]=f23,32
  541. ;;
  542. stf.spill [temp1]=f24,32
  543. stf.spill [temp2]=f25,32
  544. ;;
  545. stf.spill [temp1]=f26,32
  546. stf.spill [temp2]=f27,32
  547. ;;
  548. stf.spill [temp1]=f28,32
  549. stf.spill [temp2]=f29,32
  550. ;;
  551. stf.spill [temp1]=f30,SW(B2)-SW(F30)
  552. stf.spill [temp2]=f31,SW(B3)-SW(F31)
  553. mov temp3=b2
  554. mov temp4=b3
  555. ;;
  556. st8 [temp1]=temp3,16 // save b2
  557. st8 [temp2]=temp4,16 // save b3
  558. mov temp3=b4
  559. mov temp4=b5
  560. ;;
  561. st8 [temp1]=temp3,SW(AR_LC)-SW(B4) // save b4
  562. st8 [temp2]=temp4 // save b5
  563. mov temp3=ar.lc
  564. ;;
  565. st8 [temp1]=temp3 // save ar.lc
  566. // FIXME: Some proms are incorrectly accessing the minstate area as
  567. // cached data. The C code uses region 6, uncached virtual. Ensure
  568. // that there is no cache data lying around for the first 1K of the
  569. // minstate area.
  570. // Remove this code in September 2006, that gives platforms a year to
  571. // fix their proms and get their customers updated.
  572. add r1=32*1,r17
  573. add r2=32*2,r17
  574. add r3=32*3,r17
  575. add r4=32*4,r17
  576. add r5=32*5,r17
  577. add r6=32*6,r17
  578. add r7=32*7,r17
  579. ;;
  580. fc r17
  581. fc r1
  582. fc r2
  583. fc r3
  584. fc r4
  585. fc r5
  586. fc r6
  587. fc r7
  588. add r17=32*8,r17
  589. add r1=32*8,r1
  590. add r2=32*8,r2
  591. add r3=32*8,r3
  592. add r4=32*8,r4
  593. add r5=32*8,r5
  594. add r6=32*8,r6
  595. add r7=32*8,r7
  596. ;;
  597. fc r17
  598. fc r1
  599. fc r2
  600. fc r3
  601. fc r4
  602. fc r5
  603. fc r6
  604. fc r7
  605. add r17=32*8,r17
  606. add r1=32*8,r1
  607. add r2=32*8,r2
  608. add r3=32*8,r3
  609. add r4=32*8,r4
  610. add r5=32*8,r5
  611. add r6=32*8,r6
  612. add r7=32*8,r7
  613. ;;
  614. fc r17
  615. fc r1
  616. fc r2
  617. fc r3
  618. fc r4
  619. fc r5
  620. fc r6
  621. fc r7
  622. add r17=32*8,r17
  623. add r1=32*8,r1
  624. add r2=32*8,r2
  625. add r3=32*8,r3
  626. add r4=32*8,r4
  627. add r5=32*8,r5
  628. add r6=32*8,r6
  629. add r7=32*8,r7
  630. ;;
  631. fc r17
  632. fc r1
  633. fc r2
  634. fc r3
  635. fc r4
  636. fc r5
  637. fc r6
  638. fc r7
  639. br.sptk b0
  640. //EndStub//////////////////////////////////////////////////////////////////////
  641. //++
  642. // Name:
  643. // ia64_state_restore()
  644. //
  645. // Stub Description:
  646. //
  647. // Restore the SAL/OS state. This is sensitive to the layout of struct
  648. // ia64_sal_os_state in mca.h.
  649. //
  650. // r2 contains the return address, r3 contains either
  651. // IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
  652. //
  653. // In addition to the SAL to OS state, this routine restores all the
  654. // registers that appear in struct pt_regs and struct switch_stack,
  655. // excluding those in the PAL minstate area.
  656. //
  657. //--
  658. ia64_state_restore:
  659. // Restore the switch_stack data that is not in minstate nor pt_regs.
  660. add regs=MCA_SWITCH_STACK_OFFSET, r3
  661. mov b0=r2 // save return address
  662. ;;
  663. GET_IA64_MCA_DATA(temp2)
  664. ;;
  665. add regs=temp2, regs
  666. ;;
  667. add temp1=SW(F2), regs
  668. add temp2=SW(F3), regs
  669. ;;
  670. ldf.fill f2=[temp1],32
  671. ldf.fill f3=[temp2],32
  672. ;;
  673. ldf.fill f4=[temp1],32
  674. ldf.fill f5=[temp2],32
  675. ;;
  676. ldf.fill f12=[temp1],32
  677. ldf.fill f13=[temp2],32
  678. ;;
  679. ldf.fill f14=[temp1],32
  680. ldf.fill f15=[temp2],32
  681. ;;
  682. ldf.fill f16=[temp1],32
  683. ldf.fill f17=[temp2],32
  684. ;;
  685. ldf.fill f18=[temp1],32
  686. ldf.fill f19=[temp2],32
  687. ;;
  688. ldf.fill f20=[temp1],32
  689. ldf.fill f21=[temp2],32
  690. ;;
  691. ldf.fill f22=[temp1],32
  692. ldf.fill f23=[temp2],32
  693. ;;
  694. ldf.fill f24=[temp1],32
  695. ldf.fill f25=[temp2],32
  696. ;;
  697. ldf.fill f26=[temp1],32
  698. ldf.fill f27=[temp2],32
  699. ;;
  700. ldf.fill f28=[temp1],32
  701. ldf.fill f29=[temp2],32
  702. ;;
  703. ldf.fill f30=[temp1],SW(B2)-SW(F30)
  704. ldf.fill f31=[temp2],SW(B3)-SW(F31)
  705. ;;
  706. ld8 temp3=[temp1],16 // restore b2
  707. ld8 temp4=[temp2],16 // restore b3
  708. ;;
  709. mov b2=temp3
  710. mov b3=temp4
  711. ld8 temp3=[temp1],SW(AR_LC)-SW(B4) // restore b4
  712. ld8 temp4=[temp2] // restore b5
  713. ;;
  714. mov b4=temp3
  715. mov b5=temp4
  716. ld8 temp3=[temp1] // restore ar.lc
  717. ;;
  718. mov ar.lc=temp3
  719. // Restore the pt_regs data that is not in minstate. The previous code
  720. // left regs at switch_stack.
  721. add regs=MCA_PT_REGS_OFFSET-MCA_SWITCH_STACK_OFFSET, regs
  722. ;;
  723. add temp1=PT(B6), regs
  724. add temp2=PT(B7), regs
  725. ;;
  726. ld8 temp3=[temp1],PT(AR_CSD)-PT(B6) // restore b6
  727. ld8 temp4=[temp2],PT(AR_SSD)-PT(B7) // restore b7
  728. ;;
  729. mov b6=temp3
  730. mov b7=temp4
  731. ld8 temp3=[temp1],PT(AR_UNAT)-PT(AR_CSD) // restore ar.csd
  732. ld8 temp4=[temp2],PT(AR_PFS)-PT(AR_SSD) // restore ar.ssd
  733. ;;
  734. mov ar.csd=temp3
  735. mov ar.ssd=temp4
  736. ld8 temp3=[temp1] // restore ar.unat
  737. add temp1=PT(AR_CCV)-PT(AR_UNAT), temp1
  738. ld8 temp4=[temp2],PT(AR_FPSR)-PT(AR_PFS) // restore ar.pfs
  739. ;;
  740. mov ar.unat=temp3
  741. mov ar.pfs=temp4
  742. // ar.rnat, ar.bspstore, loadrs are restore in ia64_old_stack.
  743. ld8 temp3=[temp1],PT(F6)-PT(AR_CCV) // restore ar.ccv
  744. ld8 temp4=[temp2],PT(F7)-PT(AR_FPSR) // restore ar.fpsr
  745. ;;
  746. mov ar.ccv=temp3
  747. mov ar.fpsr=temp4
  748. ldf.fill f6=[temp1],PT(F8)-PT(F6)
  749. ldf.fill f7=[temp2],PT(F9)-PT(F7)
  750. ;;
  751. ldf.fill f8=[temp1],PT(F10)-PT(F8)
  752. ldf.fill f9=[temp2],PT(F11)-PT(F9)
  753. ;;
  754. ldf.fill f10=[temp1]
  755. ldf.fill f11=[temp2]
  756. // Restore the SAL to OS state. The previous code left regs at pt_regs.
  757. add regs=MCA_SOS_OFFSET-MCA_PT_REGS_OFFSET, regs
  758. ;;
  759. add temp1=SOS(SAL_RA), regs
  760. add temp2=SOS(SAL_GP), regs
  761. ;;
  762. ld8 r12=[temp1],16 // sal_ra
  763. ld8 r9=[temp2],16 // sal_gp
  764. ;;
  765. ld8 r22=[temp1],16 // pal_min_state, virtual
  766. ld8 r13=[temp2],16 // prev_IA64_KR_CURRENT
  767. ;;
  768. ld8 r16=[temp1],16 // prev_IA64_KR_CURRENT_STACK
  769. ld8 r20=[temp2],16 // prev_task
  770. ;;
  771. ld8 temp3=[temp1],16 // cr.isr
  772. ld8 temp4=[temp2],16 // cr.ifa
  773. ;;
  774. mov cr.isr=temp3
  775. mov cr.ifa=temp4
  776. ld8 temp3=[temp1],16 // cr.itir
  777. ld8 temp4=[temp2],16 // cr.iipa
  778. ;;
  779. mov cr.itir=temp3
  780. mov cr.iipa=temp4
  781. ld8 temp3=[temp1] // cr.iim
  782. ld8 temp4=[temp2] // cr.iha
  783. add temp1=SOS(OS_STATUS), regs
  784. add temp2=SOS(CONTEXT), regs
  785. ;;
  786. mov cr.iim=temp3
  787. mov cr.iha=temp4
  788. dep r22=0,r22,62,1 // pal_min_state, physical, uncached
  789. mov IA64_KR(CURRENT)=r13
  790. ld8 r8=[temp1] // os_status
  791. ld8 r10=[temp2] // context
  792. /* Wire IA64_TR_CURRENT_STACK to the stack that we are resuming to. To
  793. * avoid any dependencies on the algorithm in ia64_switch_to(), just
  794. * purge any existing CURRENT_STACK mapping and insert the new one.
  795. *
  796. * r16 contains prev_IA64_KR_CURRENT_STACK, r13 contains
  797. * prev_IA64_KR_CURRENT, these values may have been changed by the C
  798. * code. Do not use r8, r9, r10, r22, they contain values ready for
  799. * the return to SAL.
  800. */
  801. mov r15=IA64_KR(CURRENT_STACK) // physical granule mapped by IA64_TR_CURRENT_STACK
  802. ;;
  803. shl r15=r15,IA64_GRANULE_SHIFT
  804. ;;
  805. dep r15=-1,r15,61,3 // virtual granule
  806. mov r18=IA64_GRANULE_SHIFT<<2 // for cr.itir.ps
  807. ;;
  808. ptr.d r15,r18
  809. ;;
  810. srlz.d
  811. extr.u r19=r13,61,3 // r13 = prev_IA64_KR_CURRENT
  812. shl r20=r16,IA64_GRANULE_SHIFT // r16 = prev_IA64_KR_CURRENT_STACK
  813. movl r21=PAGE_KERNEL // page properties
  814. ;;
  815. mov IA64_KR(CURRENT_STACK)=r16
  816. cmp.ne p6,p0=RGN_KERNEL,r19 // new stack is in the kernel region?
  817. or r21=r20,r21 // construct PA | page properties
  818. (p6) br.spnt 1f // the dreaded cpu 0 idle task in region 5:(
  819. ;;
  820. mov cr.itir=r18
  821. mov cr.ifa=r13
  822. mov r20=IA64_TR_CURRENT_STACK
  823. ;;
  824. itr.d dtr[r20]=r21
  825. ;;
  826. srlz.d
  827. 1:
  828. br.sptk b0
  829. //EndStub//////////////////////////////////////////////////////////////////////
  830. //++
  831. // Name:
  832. // ia64_new_stack()
  833. //
  834. // Stub Description:
  835. //
  836. // Switch to the MCA/INIT stack.
  837. //
  838. // r2 contains the return address, r3 contains either
  839. // IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
  840. //
  841. // On entry RBS is still on the original stack, this routine switches RBS
  842. // to use the MCA/INIT stack.
  843. //
  844. // On entry, sos->pal_min_state is physical, on exit it is virtual.
  845. //
  846. //--
  847. ia64_new_stack:
  848. add regs=MCA_PT_REGS_OFFSET, r3
  849. add temp2=MCA_SOS_OFFSET+SOS(PAL_MIN_STATE), r3
  850. mov b0=r2 // save return address
  851. GET_IA64_MCA_DATA(temp1)
  852. invala
  853. ;;
  854. add temp2=temp2, temp1 // struct ia64_sal_os_state.pal_min_state on MCA or INIT stack
  855. add regs=regs, temp1 // struct pt_regs on MCA or INIT stack
  856. ;;
  857. // Address of minstate area provided by PAL is physical, uncacheable.
  858. // Convert to Linux virtual address in region 6 for C code.
  859. ld8 ms=[temp2] // pal_min_state, physical
  860. ;;
  861. dep temp1=-1,ms,62,2 // set region 6
  862. mov temp3=IA64_RBS_OFFSET-MCA_PT_REGS_OFFSET
  863. ;;
  864. st8 [temp2]=temp1 // pal_min_state, virtual
  865. add temp4=temp3, regs // start of bspstore on new stack
  866. ;;
  867. mov ar.bspstore=temp4 // switch RBS to MCA/INIT stack
  868. ;;
  869. flushrs // must be first in group
  870. br.sptk b0
  871. //EndStub//////////////////////////////////////////////////////////////////////
  872. //++
  873. // Name:
  874. // ia64_old_stack()
  875. //
  876. // Stub Description:
  877. //
  878. // Switch to the old stack.
  879. //
  880. // r2 contains the return address, r3 contains either
  881. // IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
  882. //
  883. // On entry, pal_min_state is virtual, on exit it is physical.
  884. //
  885. // On entry RBS is on the MCA/INIT stack, this routine switches RBS
  886. // back to the previous stack.
  887. //
  888. // The psr is set to all zeroes. SAL return requires either all zeroes or
  889. // just psr.mc set. Leaving psr.mc off allows INIT to be issued if this
  890. // code does not perform correctly.
  891. //
  892. // The dirty registers at the time of the event were flushed to the
  893. // MCA/INIT stack in ia64_pt_regs_save(). Restore the dirty registers
  894. // before reverting to the previous bspstore.
  895. //--
  896. ia64_old_stack:
  897. add regs=MCA_PT_REGS_OFFSET, r3
  898. mov b0=r2 // save return address
  899. GET_IA64_MCA_DATA(temp2)
  900. LOAD_PHYSICAL(p0,temp1,1f)
  901. ;;
  902. mov cr.ipsr=r0
  903. mov cr.ifs=r0
  904. mov cr.iip=temp1
  905. ;;
  906. invala
  907. rfi
  908. 1:
  909. add regs=regs, temp2 // struct pt_regs on MCA or INIT stack
  910. ;;
  911. add temp1=PT(LOADRS), regs
  912. ;;
  913. ld8 temp2=[temp1],PT(AR_BSPSTORE)-PT(LOADRS) // restore loadrs
  914. ;;
  915. ld8 temp3=[temp1],PT(AR_RNAT)-PT(AR_BSPSTORE) // restore ar.bspstore
  916. mov ar.rsc=temp2
  917. ;;
  918. loadrs
  919. ld8 temp4=[temp1] // restore ar.rnat
  920. ;;
  921. mov ar.bspstore=temp3 // back to old stack
  922. ;;
  923. mov ar.rnat=temp4
  924. ;;
  925. br.sptk b0
  926. //EndStub//////////////////////////////////////////////////////////////////////
  927. //++
  928. // Name:
  929. // ia64_set_kernel_registers()
  930. //
  931. // Stub Description:
  932. //
  933. // Set the registers that are required by the C code in order to run on an
  934. // MCA/INIT stack.
  935. //
  936. // r2 contains the return address, r3 contains either
  937. // IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
  938. //
  939. //--
  940. ia64_set_kernel_registers:
  941. add temp3=MCA_SP_OFFSET, r3
  942. add temp4=MCA_SOS_OFFSET+SOS(OS_GP), r3
  943. mov b0=r2 // save return address
  944. GET_IA64_MCA_DATA(temp1)
  945. ;;
  946. add temp4=temp4, temp1 // &struct ia64_sal_os_state.os_gp
  947. add r12=temp1, temp3 // kernel stack pointer on MCA/INIT stack
  948. add r13=temp1, r3 // set current to start of MCA/INIT stack
  949. add r20=temp1, r3 // physical start of MCA/INIT stack
  950. ;;
  951. ld8 r1=[temp4] // OS GP from SAL OS state
  952. ;;
  953. DATA_PA_TO_VA(r1,temp1)
  954. DATA_PA_TO_VA(r12,temp2)
  955. DATA_PA_TO_VA(r13,temp3)
  956. ;;
  957. mov IA64_KR(CURRENT)=r13
  958. /* Wire IA64_TR_CURRENT_STACK to the MCA/INIT handler stack. To avoid
  959. * any dependencies on the algorithm in ia64_switch_to(), just purge
  960. * any existing CURRENT_STACK mapping and insert the new one.
  961. */
  962. mov r16=IA64_KR(CURRENT_STACK) // physical granule mapped by IA64_TR_CURRENT_STACK
  963. ;;
  964. shl r16=r16,IA64_GRANULE_SHIFT
  965. ;;
  966. dep r16=-1,r16,61,3 // virtual granule
  967. mov r18=IA64_GRANULE_SHIFT<<2 // for cr.itir.ps
  968. ;;
  969. ptr.d r16,r18
  970. ;;
  971. srlz.d
  972. shr.u r16=r20,IA64_GRANULE_SHIFT // r20 = physical start of MCA/INIT stack
  973. movl r21=PAGE_KERNEL // page properties
  974. ;;
  975. mov IA64_KR(CURRENT_STACK)=r16
  976. or r21=r20,r21 // construct PA | page properties
  977. ;;
  978. mov cr.itir=r18
  979. mov cr.ifa=r13
  980. mov r20=IA64_TR_CURRENT_STACK
  981. ;;
  982. itr.d dtr[r20]=r21
  983. ;;
  984. srlz.d
  985. br.sptk b0
  986. //EndStub//////////////////////////////////////////////////////////////////////
  987. #undef ms
  988. #undef regs
  989. #undef temp1
  990. #undef temp2
  991. #undef temp3
  992. #undef temp4
  993. // Support function for mca.c, it is here to avoid using inline asm. Given the
  994. // address of an rnat slot, if that address is below the current ar.bspstore
  995. // then return the contents of that slot, otherwise return the contents of
  996. // ar.rnat.
  997. GLOBAL_ENTRY(ia64_get_rnat)
  998. alloc r14=ar.pfs,1,0,0,0
  999. mov ar.rsc=0
  1000. ;;
  1001. mov r14=ar.bspstore
  1002. ;;
  1003. cmp.lt p6,p7=in0,r14
  1004. ;;
  1005. (p6) ld8 r8=[in0]
  1006. (p7) mov r8=ar.rnat
  1007. mov ar.rsc=3
  1008. br.ret.sptk.many rp
  1009. END(ia64_get_rnat)