mca_asm.S 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  1. /*
  2. * File: mca_asm.S
  3. * Purpose: assembly portion of the IA64 MCA handling
  4. *
  5. * Mods by cfleck to integrate into kernel build
  6. *
  7. * 2000-03-15 David Mosberger-Tang <davidm@hpl.hp.com>
  8. * Added various stop bits to get a clean compile
  9. *
  10. * 2000-03-29 Chuck Fleckenstein <cfleck@co.intel.com>
  11. * Added code to save INIT handoff state in pt_regs format,
  12. * switch to temp kstack, switch modes, jump to C INIT handler
  13. *
  14. * 2002-01-04 J.Hall <jenna.s.hall@intel.com>
  15. * Before entering virtual mode code:
  16. * 1. Check for TLB CPU error
  17. * 2. Restore current thread pointer to kr6
  18. * 3. Move stack ptr 16 bytes to conform to C calling convention
  19. *
  20. * 2004-11-12 Russ Anderson <rja@sgi.com>
  21. * Added per cpu MCA/INIT stack save areas.
  22. *
  23. * 2005-12-08 Keith Owens <kaos@sgi.com>
  24. * Use per cpu MCA/INIT stacks for all data.
  25. */
  26. #include <linux/threads.h>
  27. #include <asm/asmmacro.h>
  28. #include <asm/pgtable.h>
  29. #include <asm/processor.h>
  30. #include <asm/mca_asm.h>
  31. #include <asm/mca.h>
  32. #include "entry.h"
  33. #define GET_IA64_MCA_DATA(reg) \
  34. GET_THIS_PADDR(reg, ia64_mca_data) \
  35. ;; \
  36. ld8 reg=[reg]
  37. .global ia64_do_tlb_purge
  38. .global ia64_os_mca_dispatch
  39. .global ia64_os_init_on_kdump
  40. .global ia64_os_init_dispatch_monarch
  41. .global ia64_os_init_dispatch_slave
  42. .text
  43. .align 16
  44. //StartMain////////////////////////////////////////////////////////////////////
  45. /*
  46. * Just the TLB purge part is moved to a separate function
  47. * so we can re-use the code for cpu hotplug code as well
  48. * Caller should now setup b1, so we can branch once the
  49. * tlb flush is complete.
  50. */
  51. ia64_do_tlb_purge:
  52. #define O(member) IA64_CPUINFO_##member##_OFFSET
  53. GET_THIS_PADDR(r2, ia64_cpu_info) // load phys addr of cpu_info into r2
  54. ;;
  55. addl r17=O(PTCE_STRIDE),r2
  56. addl r2=O(PTCE_BASE),r2
  57. ;;
  58. ld8 r18=[r2],(O(PTCE_COUNT)-O(PTCE_BASE));; // r18=ptce_base
  59. ld4 r19=[r2],4 // r19=ptce_count[0]
  60. ld4 r21=[r17],4 // r21=ptce_stride[0]
  61. ;;
  62. ld4 r20=[r2] // r20=ptce_count[1]
  63. ld4 r22=[r17] // r22=ptce_stride[1]
  64. mov r24=0
  65. ;;
  66. adds r20=-1,r20
  67. ;;
  68. #undef O
  69. 2:
  70. cmp.ltu p6,p7=r24,r19
  71. (p7) br.cond.dpnt.few 4f
  72. mov ar.lc=r20
  73. 3:
  74. ptc.e r18
  75. ;;
  76. add r18=r22,r18
  77. br.cloop.sptk.few 3b
  78. ;;
  79. add r18=r21,r18
  80. add r24=1,r24
  81. ;;
  82. br.sptk.few 2b
  83. 4:
  84. srlz.i // srlz.i implies srlz.d
  85. ;;
  86. // Now purge addresses formerly mapped by TR registers
  87. // 1. Purge ITR&DTR for kernel.
  88. movl r16=KERNEL_START
  89. mov r18=KERNEL_TR_PAGE_SHIFT<<2
  90. ;;
  91. ptr.i r16, r18
  92. ptr.d r16, r18
  93. ;;
  94. srlz.i
  95. ;;
  96. srlz.d
  97. ;;
  98. // 3. Purge ITR for PAL code.
  99. GET_THIS_PADDR(r2, ia64_mca_pal_base)
  100. ;;
  101. ld8 r16=[r2]
  102. mov r18=IA64_GRANULE_SHIFT<<2
  103. ;;
  104. ptr.i r16,r18
  105. ;;
  106. srlz.i
  107. ;;
  108. // 4. Purge DTR for stack.
  109. mov r16=IA64_KR(CURRENT_STACK)
  110. ;;
  111. shl r16=r16,IA64_GRANULE_SHIFT
  112. movl r19=PAGE_OFFSET
  113. ;;
  114. add r16=r19,r16
  115. mov r18=IA64_GRANULE_SHIFT<<2
  116. ;;
  117. ptr.d r16,r18
  118. ;;
  119. srlz.i
  120. ;;
  121. // Now branch away to caller.
  122. br.sptk.many b1
  123. ;;
  124. //EndMain//////////////////////////////////////////////////////////////////////
  125. //StartMain////////////////////////////////////////////////////////////////////
  126. ia64_os_mca_dispatch:
  127. mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
  128. LOAD_PHYSICAL(p0,r2,1f) // return address
  129. mov r19=1 // All MCA events are treated as monarch (for now)
  130. br.sptk ia64_state_save // save the state that is not in minstate
  131. 1:
  132. GET_IA64_MCA_DATA(r2)
  133. // Using MCA stack, struct ia64_sal_os_state, variable proc_state_param
  134. ;;
  135. add r3=IA64_MCA_CPU_MCA_STACK_OFFSET+MCA_SOS_OFFSET+SOS(PROC_STATE_PARAM), r2
  136. ;;
  137. ld8 r18=[r3] // Get processor state parameter on existing PALE_CHECK.
  138. ;;
  139. tbit.nz p6,p7=r18,60
  140. (p7) br.spnt done_tlb_purge_and_reload
  141. // The following code purges TC and TR entries. Then reload all TC entries.
  142. // Purge percpu data TC entries.
  143. begin_tlb_purge_and_reload:
  144. movl r18=ia64_reload_tr;;
  145. LOAD_PHYSICAL(p0,r18,ia64_reload_tr);;
  146. mov b1=r18;;
  147. br.sptk.many ia64_do_tlb_purge;;
  148. ia64_reload_tr:
  149. // Finally reload the TR registers.
  150. // 1. Reload DTR/ITR registers for kernel.
  151. mov r18=KERNEL_TR_PAGE_SHIFT<<2
  152. movl r17=KERNEL_START
  153. ;;
  154. mov cr.itir=r18
  155. mov cr.ifa=r17
  156. mov r16=IA64_TR_KERNEL
  157. mov r19=ip
  158. movl r18=PAGE_KERNEL
  159. ;;
  160. dep r17=0,r19,0, KERNEL_TR_PAGE_SHIFT
  161. ;;
  162. or r18=r17,r18
  163. ;;
  164. itr.i itr[r16]=r18
  165. ;;
  166. itr.d dtr[r16]=r18
  167. ;;
  168. srlz.i
  169. srlz.d
  170. ;;
  171. // 3. Reload ITR for PAL code.
  172. GET_THIS_PADDR(r2, ia64_mca_pal_pte)
  173. ;;
  174. ld8 r18=[r2] // load PAL PTE
  175. ;;
  176. GET_THIS_PADDR(r2, ia64_mca_pal_base)
  177. ;;
  178. ld8 r16=[r2] // load PAL vaddr
  179. mov r19=IA64_GRANULE_SHIFT<<2
  180. ;;
  181. mov cr.itir=r19
  182. mov cr.ifa=r16
  183. mov r20=IA64_TR_PALCODE
  184. ;;
  185. itr.i itr[r20]=r18
  186. ;;
  187. srlz.i
  188. ;;
  189. // 4. Reload DTR for stack.
  190. mov r16=IA64_KR(CURRENT_STACK)
  191. ;;
  192. shl r16=r16,IA64_GRANULE_SHIFT
  193. movl r19=PAGE_OFFSET
  194. ;;
  195. add r18=r19,r16
  196. movl r20=PAGE_KERNEL
  197. ;;
  198. add r16=r20,r16
  199. mov r19=IA64_GRANULE_SHIFT<<2
  200. ;;
  201. mov cr.itir=r19
  202. mov cr.ifa=r18
  203. mov r20=IA64_TR_CURRENT_STACK
  204. ;;
  205. itr.d dtr[r20]=r16
  206. GET_THIS_PADDR(r2, ia64_mca_tr_reload)
  207. mov r18 = 1
  208. ;;
  209. srlz.d
  210. ;;
  211. st8 [r2] =r18
  212. ;;
  213. done_tlb_purge_and_reload:
  214. // switch to per cpu MCA stack
  215. mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
  216. LOAD_PHYSICAL(p0,r2,1f) // return address
  217. br.sptk ia64_new_stack
  218. 1:
  219. // everything saved, now we can set the kernel registers
  220. mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
  221. LOAD_PHYSICAL(p0,r2,1f) // return address
  222. br.sptk ia64_set_kernel_registers
  223. 1:
  224. // This must be done in physical mode
  225. GET_IA64_MCA_DATA(r2)
  226. ;;
  227. mov r7=r2
  228. // Enter virtual mode from physical mode
  229. VIRTUAL_MODE_ENTER(r2, r3, ia64_os_mca_virtual_begin, r4)
  230. // This code returns to SAL via SOS r2, in general SAL has no unwind
  231. // data. To get a clean termination when backtracing the C MCA/INIT
  232. // handler, set a dummy return address of 0 in this routine. That
  233. // requires that ia64_os_mca_virtual_begin be a global function.
  234. ENTRY(ia64_os_mca_virtual_begin)
  235. .prologue
  236. .save rp,r0
  237. .body
  238. mov ar.rsc=3 // set eager mode for C handler
  239. mov r2=r7 // see GET_IA64_MCA_DATA above
  240. ;;
  241. // Call virtual mode handler
  242. alloc r14=ar.pfs,0,0,3,0
  243. ;;
  244. DATA_PA_TO_VA(r2,r7)
  245. ;;
  246. add out0=IA64_MCA_CPU_MCA_STACK_OFFSET+MCA_PT_REGS_OFFSET, r2
  247. add out1=IA64_MCA_CPU_MCA_STACK_OFFSET+MCA_SWITCH_STACK_OFFSET, r2
  248. add out2=IA64_MCA_CPU_MCA_STACK_OFFSET+MCA_SOS_OFFSET, r2
  249. br.call.sptk.many b0=ia64_mca_handler
  250. // Revert back to physical mode before going back to SAL
  251. PHYSICAL_MODE_ENTER(r2, r3, ia64_os_mca_virtual_end, r4)
  252. ia64_os_mca_virtual_end:
  253. END(ia64_os_mca_virtual_begin)
  254. // switch back to previous stack
  255. alloc r14=ar.pfs,0,0,0,0 // remove the MCA handler frame
  256. mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
  257. LOAD_PHYSICAL(p0,r2,1f) // return address
  258. br.sptk ia64_old_stack
  259. 1:
  260. mov r3=IA64_MCA_CPU_MCA_STACK_OFFSET // use the MCA stack
  261. LOAD_PHYSICAL(p0,r2,1f) // return address
  262. br.sptk ia64_state_restore // restore the SAL state
  263. 1:
  264. mov b0=r12 // SAL_CHECK return address
  265. br b0
  266. //EndMain//////////////////////////////////////////////////////////////////////
  267. //StartMain////////////////////////////////////////////////////////////////////
  268. //
  269. // NOP init handler for kdump. In panic situation, we may receive INIT
  270. // while kernel transition. Since we initialize registers on leave from
  271. // current kernel, no longer monarch/slave handlers of current kernel in
  272. // virtual mode are called safely.
  273. // We can unregister these init handlers from SAL, however then the INIT
  274. // will result in warmboot by SAL and we cannot retrieve the crashdump.
  275. // Therefore register this NOP function to SAL, to prevent entering virtual
  276. // mode and resulting warmboot by SAL.
  277. //
  278. ia64_os_init_on_kdump:
  279. mov r8=r0 // IA64_INIT_RESUME
  280. mov r9=r10 // SAL_GP
  281. mov r22=r17 // *minstate
  282. ;;
  283. mov r10=r0 // return to same context
  284. mov b0=r12 // SAL_CHECK return address
  285. br b0
  286. //
  287. // SAL to OS entry point for INIT on all processors. This has been defined for
  288. // registration purposes with SAL as a part of ia64_mca_init. Monarch and
  289. // slave INIT have identical processing, except for the value of the
  290. // sos->monarch flag in r19.
  291. //
  292. ia64_os_init_dispatch_monarch:
  293. mov r19=1 // Bow, bow, ye lower middle classes!
  294. br.sptk ia64_os_init_dispatch
  295. ia64_os_init_dispatch_slave:
  296. mov r19=0 // <igor>yeth, mathter</igor>
  297. ia64_os_init_dispatch:
  298. mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
  299. LOAD_PHYSICAL(p0,r2,1f) // return address
  300. br.sptk ia64_state_save // save the state that is not in minstate
  301. 1:
  302. // switch to per cpu INIT stack
  303. mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
  304. LOAD_PHYSICAL(p0,r2,1f) // return address
  305. br.sptk ia64_new_stack
  306. 1:
  307. // everything saved, now we can set the kernel registers
  308. mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
  309. LOAD_PHYSICAL(p0,r2,1f) // return address
  310. br.sptk ia64_set_kernel_registers
  311. 1:
  312. // This must be done in physical mode
  313. GET_IA64_MCA_DATA(r2)
  314. ;;
  315. mov r7=r2
  316. // Enter virtual mode from physical mode
  317. VIRTUAL_MODE_ENTER(r2, r3, ia64_os_init_virtual_begin, r4)
  318. // This code returns to SAL via SOS r2, in general SAL has no unwind
  319. // data. To get a clean termination when backtracing the C MCA/INIT
  320. // handler, set a dummy return address of 0 in this routine. That
  321. // requires that ia64_os_init_virtual_begin be a global function.
  322. ENTRY(ia64_os_init_virtual_begin)
  323. .prologue
  324. .save rp,r0
  325. .body
  326. mov ar.rsc=3 // set eager mode for C handler
  327. mov r2=r7 // see GET_IA64_MCA_DATA above
  328. ;;
  329. // Call virtual mode handler
  330. alloc r14=ar.pfs,0,0,3,0
  331. ;;
  332. DATA_PA_TO_VA(r2,r7)
  333. ;;
  334. add out0=IA64_MCA_CPU_INIT_STACK_OFFSET+MCA_PT_REGS_OFFSET, r2
  335. add out1=IA64_MCA_CPU_INIT_STACK_OFFSET+MCA_SWITCH_STACK_OFFSET, r2
  336. add out2=IA64_MCA_CPU_INIT_STACK_OFFSET+MCA_SOS_OFFSET, r2
  337. br.call.sptk.many b0=ia64_init_handler
  338. // Revert back to physical mode before going back to SAL
  339. PHYSICAL_MODE_ENTER(r2, r3, ia64_os_init_virtual_end, r4)
  340. ia64_os_init_virtual_end:
  341. END(ia64_os_init_virtual_begin)
  342. mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
  343. LOAD_PHYSICAL(p0,r2,1f) // return address
  344. br.sptk ia64_state_restore // restore the SAL state
  345. 1:
  346. // switch back to previous stack
  347. alloc r14=ar.pfs,0,0,0,0 // remove the INIT handler frame
  348. mov r3=IA64_MCA_CPU_INIT_STACK_OFFSET // use the INIT stack
  349. LOAD_PHYSICAL(p0,r2,1f) // return address
  350. br.sptk ia64_old_stack
  351. 1:
  352. mov b0=r12 // SAL_CHECK return address
  353. br b0
  354. //EndMain//////////////////////////////////////////////////////////////////////
  355. // common defines for the stubs
  356. #define ms r4
  357. #define regs r5
  358. #define temp1 r2 /* careful, it overlaps with input registers */
  359. #define temp2 r3 /* careful, it overlaps with input registers */
  360. #define temp3 r7
  361. #define temp4 r14
  362. //++
  363. // Name:
  364. // ia64_state_save()
  365. //
  366. // Stub Description:
  367. //
  368. // Save the state that is not in minstate. This is sensitive to the layout of
  369. // struct ia64_sal_os_state in mca.h.
  370. //
  371. // r2 contains the return address, r3 contains either
  372. // IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
  373. //
  374. // The OS to SAL section of struct ia64_sal_os_state is set to a default
  375. // value of cold boot (MCA) or warm boot (INIT) and return to the same
  376. // context. ia64_sal_os_state is also used to hold some registers that
  377. // need to be saved and restored across the stack switches.
  378. //
  379. // Most input registers to this stub come from PAL/SAL
  380. // r1 os gp, physical
  381. // r8 pal_proc entry point
  382. // r9 sal_proc entry point
  383. // r10 sal gp
  384. // r11 MCA - rendevzous state, INIT - reason code
  385. // r12 sal return address
  386. // r17 pal min_state
  387. // r18 processor state parameter
  388. // r19 monarch flag, set by the caller of this routine
  389. //
  390. // In addition to the SAL to OS state, this routine saves all the
  391. // registers that appear in struct pt_regs and struct switch_stack,
  392. // excluding those that are already in the PAL minstate area. This
  393. // results in a partial pt_regs and switch_stack, the C code copies the
  394. // remaining registers from PAL minstate to pt_regs and switch_stack. The
  395. // resulting structures contain all the state of the original process when
  396. // MCA/INIT occurred.
  397. //
  398. //--
  399. ia64_state_save:
  400. add regs=MCA_SOS_OFFSET, r3
  401. add ms=MCA_SOS_OFFSET+8, r3
  402. mov b0=r2 // save return address
  403. cmp.eq p1,p2=IA64_MCA_CPU_MCA_STACK_OFFSET, r3
  404. ;;
  405. GET_IA64_MCA_DATA(temp2)
  406. ;;
  407. add temp1=temp2, regs // struct ia64_sal_os_state on MCA or INIT stack
  408. add temp2=temp2, ms // struct ia64_sal_os_state+8 on MCA or INIT stack
  409. ;;
  410. mov regs=temp1 // save the start of sos
  411. st8 [temp1]=r1,16 // os_gp
  412. st8 [temp2]=r8,16 // pal_proc
  413. ;;
  414. st8 [temp1]=r9,16 // sal_proc
  415. st8 [temp2]=r11,16 // rv_rc
  416. mov r11=cr.iipa
  417. ;;
  418. st8 [temp1]=r18 // proc_state_param
  419. st8 [temp2]=r19 // monarch
  420. mov r6=IA64_KR(CURRENT)
  421. add temp1=SOS(SAL_RA), regs
  422. add temp2=SOS(SAL_GP), regs
  423. ;;
  424. st8 [temp1]=r12,16 // sal_ra
  425. st8 [temp2]=r10,16 // sal_gp
  426. mov r12=cr.isr
  427. ;;
  428. st8 [temp1]=r17,16 // pal_min_state
  429. st8 [temp2]=r6,16 // prev_IA64_KR_CURRENT
  430. mov r6=IA64_KR(CURRENT_STACK)
  431. ;;
  432. st8 [temp1]=r6,16 // prev_IA64_KR_CURRENT_STACK
  433. st8 [temp2]=r0,16 // prev_task, starts off as NULL
  434. mov r6=cr.ifa
  435. ;;
  436. st8 [temp1]=r12,16 // cr.isr
  437. st8 [temp2]=r6,16 // cr.ifa
  438. mov r12=cr.itir
  439. ;;
  440. st8 [temp1]=r12,16 // cr.itir
  441. st8 [temp2]=r11,16 // cr.iipa
  442. mov r12=cr.iim
  443. ;;
  444. st8 [temp1]=r12 // cr.iim
  445. (p1) mov r12=IA64_MCA_COLD_BOOT
  446. (p2) mov r12=IA64_INIT_WARM_BOOT
  447. mov r6=cr.iha
  448. add temp1=SOS(OS_STATUS), regs
  449. ;;
  450. st8 [temp2]=r6 // cr.iha
  451. add temp2=SOS(CONTEXT), regs
  452. st8 [temp1]=r12 // os_status, default is cold boot
  453. mov r6=IA64_MCA_SAME_CONTEXT
  454. ;;
  455. st8 [temp2]=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=SOS(SAL_RA), regs
  753. add temp2=SOS(SAL_GP), regs
  754. ;;
  755. ld8 r12=[temp1],16 // sal_ra
  756. ld8 r9=[temp2],16 // sal_gp
  757. ;;
  758. ld8 r22=[temp1],16 // pal_min_state, virtual
  759. ld8 r13=[temp2],16 // prev_IA64_KR_CURRENT
  760. ;;
  761. ld8 r16=[temp1],16 // prev_IA64_KR_CURRENT_STACK
  762. ld8 r20=[temp2],16 // prev_task
  763. ;;
  764. ld8 temp3=[temp1],16 // cr.isr
  765. ld8 temp4=[temp2],16 // cr.ifa
  766. ;;
  767. mov cr.isr=temp3
  768. mov cr.ifa=temp4
  769. ld8 temp3=[temp1],16 // cr.itir
  770. ld8 temp4=[temp2],16 // cr.iipa
  771. ;;
  772. mov cr.itir=temp3
  773. mov cr.iipa=temp4
  774. ld8 temp3=[temp1] // cr.iim
  775. ld8 temp4=[temp2] // cr.iha
  776. add temp1=SOS(OS_STATUS), regs
  777. add temp2=SOS(CONTEXT), regs
  778. ;;
  779. mov cr.iim=temp3
  780. mov cr.iha=temp4
  781. dep r22=0,r22,62,1 // pal_min_state, physical, uncached
  782. mov IA64_KR(CURRENT)=r13
  783. ld8 r8=[temp1] // os_status
  784. ld8 r10=[temp2] // context
  785. /* Wire IA64_TR_CURRENT_STACK to the stack that we are resuming to. To
  786. * avoid any dependencies on the algorithm in ia64_switch_to(), just
  787. * purge any existing CURRENT_STACK mapping and insert the new one.
  788. *
  789. * r16 contains prev_IA64_KR_CURRENT_STACK, r13 contains
  790. * prev_IA64_KR_CURRENT, these values may have been changed by the C
  791. * code. Do not use r8, r9, r10, r22, they contain values ready for
  792. * the return to SAL.
  793. */
  794. mov r15=IA64_KR(CURRENT_STACK) // physical granule mapped by IA64_TR_CURRENT_STACK
  795. ;;
  796. shl r15=r15,IA64_GRANULE_SHIFT
  797. ;;
  798. dep r15=-1,r15,61,3 // virtual granule
  799. mov r18=IA64_GRANULE_SHIFT<<2 // for cr.itir.ps
  800. ;;
  801. ptr.d r15,r18
  802. ;;
  803. srlz.d
  804. extr.u r19=r13,61,3 // r13 = prev_IA64_KR_CURRENT
  805. shl r20=r16,IA64_GRANULE_SHIFT // r16 = prev_IA64_KR_CURRENT_STACK
  806. movl r21=PAGE_KERNEL // page properties
  807. ;;
  808. mov IA64_KR(CURRENT_STACK)=r16
  809. cmp.ne p6,p0=RGN_KERNEL,r19 // new stack is in the kernel region?
  810. or r21=r20,r21 // construct PA | page properties
  811. (p6) br.spnt 1f // the dreaded cpu 0 idle task in region 5:(
  812. ;;
  813. mov cr.itir=r18
  814. mov cr.ifa=r13
  815. mov r20=IA64_TR_CURRENT_STACK
  816. ;;
  817. itr.d dtr[r20]=r21
  818. ;;
  819. srlz.d
  820. 1:
  821. br.sptk b0
  822. //EndStub//////////////////////////////////////////////////////////////////////
  823. //++
  824. // Name:
  825. // ia64_new_stack()
  826. //
  827. // Stub Description:
  828. //
  829. // Switch to the MCA/INIT stack.
  830. //
  831. // r2 contains the return address, r3 contains either
  832. // IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
  833. //
  834. // On entry RBS is still on the original stack, this routine switches RBS
  835. // to use the MCA/INIT stack.
  836. //
  837. // On entry, sos->pal_min_state is physical, on exit it is virtual.
  838. //
  839. //--
  840. ia64_new_stack:
  841. add regs=MCA_PT_REGS_OFFSET, r3
  842. add temp2=MCA_SOS_OFFSET+SOS(PAL_MIN_STATE), r3
  843. mov b0=r2 // save return address
  844. GET_IA64_MCA_DATA(temp1)
  845. invala
  846. ;;
  847. add temp2=temp2, temp1 // struct ia64_sal_os_state.pal_min_state on MCA or INIT stack
  848. add regs=regs, temp1 // struct pt_regs on MCA or INIT stack
  849. ;;
  850. // Address of minstate area provided by PAL is physical, uncacheable.
  851. // Convert to Linux virtual address in region 6 for C code.
  852. ld8 ms=[temp2] // pal_min_state, physical
  853. ;;
  854. dep temp1=-1,ms,62,2 // set region 6
  855. mov temp3=IA64_RBS_OFFSET-MCA_PT_REGS_OFFSET
  856. ;;
  857. st8 [temp2]=temp1 // pal_min_state, virtual
  858. add temp4=temp3, regs // start of bspstore on new stack
  859. ;;
  860. mov ar.bspstore=temp4 // switch RBS to MCA/INIT stack
  861. ;;
  862. flushrs // must be first in group
  863. br.sptk b0
  864. //EndStub//////////////////////////////////////////////////////////////////////
  865. //++
  866. // Name:
  867. // ia64_old_stack()
  868. //
  869. // Stub Description:
  870. //
  871. // Switch to the old stack.
  872. //
  873. // r2 contains the return address, r3 contains either
  874. // IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
  875. //
  876. // On entry, pal_min_state is virtual, on exit it is physical.
  877. //
  878. // On entry RBS is on the MCA/INIT stack, this routine switches RBS
  879. // back to the previous stack.
  880. //
  881. // The psr is set to all zeroes. SAL return requires either all zeroes or
  882. // just psr.mc set. Leaving psr.mc off allows INIT to be issued if this
  883. // code does not perform correctly.
  884. //
  885. // The dirty registers at the time of the event were flushed to the
  886. // MCA/INIT stack in ia64_pt_regs_save(). Restore the dirty registers
  887. // before reverting to the previous bspstore.
  888. //--
  889. ia64_old_stack:
  890. add regs=MCA_PT_REGS_OFFSET, r3
  891. mov b0=r2 // save return address
  892. GET_IA64_MCA_DATA(temp2)
  893. LOAD_PHYSICAL(p0,temp1,1f)
  894. ;;
  895. mov cr.ipsr=r0
  896. mov cr.ifs=r0
  897. mov cr.iip=temp1
  898. ;;
  899. invala
  900. rfi
  901. 1:
  902. add regs=regs, temp2 // struct pt_regs on MCA or INIT stack
  903. ;;
  904. add temp1=PT(LOADRS), regs
  905. ;;
  906. ld8 temp2=[temp1],PT(AR_BSPSTORE)-PT(LOADRS) // restore loadrs
  907. ;;
  908. ld8 temp3=[temp1],PT(AR_RNAT)-PT(AR_BSPSTORE) // restore ar.bspstore
  909. mov ar.rsc=temp2
  910. ;;
  911. loadrs
  912. ld8 temp4=[temp1] // restore ar.rnat
  913. ;;
  914. mov ar.bspstore=temp3 // back to old stack
  915. ;;
  916. mov ar.rnat=temp4
  917. ;;
  918. br.sptk b0
  919. //EndStub//////////////////////////////////////////////////////////////////////
  920. //++
  921. // Name:
  922. // ia64_set_kernel_registers()
  923. //
  924. // Stub Description:
  925. //
  926. // Set the registers that are required by the C code in order to run on an
  927. // MCA/INIT stack.
  928. //
  929. // r2 contains the return address, r3 contains either
  930. // IA64_MCA_CPU_MCA_STACK_OFFSET or IA64_MCA_CPU_INIT_STACK_OFFSET.
  931. //
  932. //--
  933. ia64_set_kernel_registers:
  934. add temp3=MCA_SP_OFFSET, r3
  935. mov b0=r2 // save return address
  936. GET_IA64_MCA_DATA(temp1)
  937. ;;
  938. add r12=temp1, temp3 // kernel stack pointer on MCA/INIT stack
  939. add r13=temp1, r3 // set current to start of MCA/INIT stack
  940. add r20=temp1, r3 // physical start of MCA/INIT stack
  941. ;;
  942. DATA_PA_TO_VA(r12,temp2)
  943. DATA_PA_TO_VA(r13,temp3)
  944. ;;
  945. mov IA64_KR(CURRENT)=r13
  946. /* Wire IA64_TR_CURRENT_STACK to the MCA/INIT handler stack. To avoid
  947. * any dependencies on the algorithm in ia64_switch_to(), just purge
  948. * any existing CURRENT_STACK mapping and insert the new one.
  949. */
  950. mov r16=IA64_KR(CURRENT_STACK) // physical granule mapped by IA64_TR_CURRENT_STACK
  951. ;;
  952. shl r16=r16,IA64_GRANULE_SHIFT
  953. ;;
  954. dep r16=-1,r16,61,3 // virtual granule
  955. mov r18=IA64_GRANULE_SHIFT<<2 // for cr.itir.ps
  956. ;;
  957. ptr.d r16,r18
  958. ;;
  959. srlz.d
  960. shr.u r16=r20,IA64_GRANULE_SHIFT // r20 = physical start of MCA/INIT stack
  961. movl r21=PAGE_KERNEL // page properties
  962. ;;
  963. mov IA64_KR(CURRENT_STACK)=r16
  964. or r21=r20,r21 // construct PA | page properties
  965. ;;
  966. mov cr.itir=r18
  967. mov cr.ifa=r13
  968. mov r20=IA64_TR_CURRENT_STACK
  969. movl r17=FPSR_DEFAULT
  970. ;;
  971. mov.m ar.fpsr=r17 // set ar.fpsr to kernel default value
  972. ;;
  973. itr.d dtr[r20]=r21
  974. ;;
  975. srlz.d
  976. br.sptk b0
  977. //EndStub//////////////////////////////////////////////////////////////////////
  978. #undef ms
  979. #undef regs
  980. #undef temp1
  981. #undef temp2
  982. #undef temp3
  983. #undef temp4
  984. // Support function for mca.c, it is here to avoid using inline asm. Given the
  985. // address of an rnat slot, if that address is below the current ar.bspstore
  986. // then return the contents of that slot, otherwise return the contents of
  987. // ar.rnat.
  988. GLOBAL_ENTRY(ia64_get_rnat)
  989. alloc r14=ar.pfs,1,0,0,0
  990. mov ar.rsc=0
  991. ;;
  992. mov r14=ar.bspstore
  993. ;;
  994. cmp.lt p6,p7=in0,r14
  995. ;;
  996. (p6) ld8 r8=[in0]
  997. (p7) mov r8=ar.rnat
  998. mov ar.rsc=3
  999. br.ret.sptk.many rp
  1000. END(ia64_get_rnat)
  1001. // void ia64_set_psr_mc(void)
  1002. //
  1003. // Set psr.mc bit to mask MCA/INIT.
  1004. GLOBAL_ENTRY(ia64_set_psr_mc)
  1005. rsm psr.i | psr.ic // disable interrupts
  1006. ;;
  1007. srlz.d
  1008. ;;
  1009. mov r14 = psr // get psr{36:35,31:0}
  1010. movl r15 = 1f
  1011. ;;
  1012. dep r14 = -1, r14, PSR_MC, 1 // set psr.mc
  1013. ;;
  1014. dep r14 = -1, r14, PSR_IC, 1 // set psr.ic
  1015. ;;
  1016. dep r14 = -1, r14, PSR_BN, 1 // keep bank1 in use
  1017. ;;
  1018. mov cr.ipsr = r14
  1019. mov cr.ifs = r0
  1020. mov cr.iip = r15
  1021. ;;
  1022. rfi
  1023. 1:
  1024. br.ret.sptk.many rp
  1025. END(ia64_set_psr_mc)