exceptions-64s.S 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * This file contains the 64-bit "server" PowerPC variant
  4. * of the low level exception handling including exception
  5. * vectors, exception return, part of the slb and stab
  6. * handling and other fixed offset specific things.
  7. *
  8. * This file is meant to be #included from head_64.S due to
  9. * position dependent assembly.
  10. *
  11. * Most of this originates from head_64.S and thus has the same
  12. * copyright history.
  13. *
  14. */
  15. #include <asm/hw_irq.h>
  16. #include <asm/exception-64s.h>
  17. #include <asm/ptrace.h>
  18. #include <asm/cpuidle.h>
  19. #include <asm/head-64.h>
  20. #include <asm/feature-fixups.h>
  21. /*
  22. * There are a few constraints to be concerned with.
  23. * - Real mode exceptions code/data must be located at their physical location.
  24. * - Virtual mode exceptions must be mapped at their 0xc000... location.
  25. * - Fixed location code must not call directly beyond the __end_interrupts
  26. * area when built with CONFIG_RELOCATABLE. LOAD_HANDLER / bctr sequence
  27. * must be used.
  28. * - LOAD_HANDLER targets must be within first 64K of physical 0 /
  29. * virtual 0xc00...
  30. * - Conditional branch targets must be within +/-32K of caller.
  31. *
  32. * "Virtual exceptions" run with relocation on (MSR_IR=1, MSR_DR=1), and
  33. * therefore don't have to run in physically located code or rfid to
  34. * virtual mode kernel code. However on relocatable kernels they do have
  35. * to branch to KERNELBASE offset because the rest of the kernel (outside
  36. * the exception vectors) may be located elsewhere.
  37. *
  38. * Virtual exceptions correspond with physical, except their entry points
  39. * are offset by 0xc000000000000000 and also tend to get an added 0x4000
  40. * offset applied. Virtual exceptions are enabled with the Alternate
  41. * Interrupt Location (AIL) bit set in the LPCR. However this does not
  42. * guarantee they will be delivered virtually. Some conditions (see the ISA)
  43. * cause exceptions to be delivered in real mode.
  44. *
  45. * It's impossible to receive interrupts below 0x300 via AIL.
  46. *
  47. * KVM: None of the virtual exceptions are from the guest. Anything that
  48. * escalated to HV=1 from HV=0 is delivered via real mode handlers.
  49. *
  50. *
  51. * We layout physical memory as follows:
  52. * 0x0000 - 0x00ff : Secondary processor spin code
  53. * 0x0100 - 0x18ff : Real mode pSeries interrupt vectors
  54. * 0x1900 - 0x3fff : Real mode trampolines
  55. * 0x4000 - 0x58ff : Relon (IR=1,DR=1) mode pSeries interrupt vectors
  56. * 0x5900 - 0x6fff : Relon mode trampolines
  57. * 0x7000 - 0x7fff : FWNMI data area
  58. * 0x8000 - .... : Common interrupt handlers, remaining early
  59. * setup code, rest of kernel.
  60. *
  61. * We could reclaim 0x4000-0x42ff for real mode trampolines if the space
  62. * is necessary. Until then it's more consistent to explicitly put VIRT_NONE
  63. * vectors there.
  64. */
  65. OPEN_FIXED_SECTION(real_vectors, 0x0100, 0x1900)
  66. OPEN_FIXED_SECTION(real_trampolines, 0x1900, 0x4000)
  67. OPEN_FIXED_SECTION(virt_vectors, 0x4000, 0x5900)
  68. OPEN_FIXED_SECTION(virt_trampolines, 0x5900, 0x7000)
  69. #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
  70. /*
  71. * Data area reserved for FWNMI option.
  72. * This address (0x7000) is fixed by the RPA.
  73. * pseries and powernv need to keep the whole page from
  74. * 0x7000 to 0x8000 free for use by the firmware
  75. */
  76. ZERO_FIXED_SECTION(fwnmi_page, 0x7000, 0x8000)
  77. OPEN_TEXT_SECTION(0x8000)
  78. #else
  79. OPEN_TEXT_SECTION(0x7000)
  80. #endif
  81. USE_FIXED_SECTION(real_vectors)
  82. /*
  83. * This is the start of the interrupt handlers for pSeries
  84. * This code runs with relocation off.
  85. * Code from here to __end_interrupts gets copied down to real
  86. * address 0x100 when we are running a relocatable kernel.
  87. * Therefore any relative branches in this section must only
  88. * branch to labels in this section.
  89. */
  90. .globl __start_interrupts
  91. __start_interrupts:
  92. /* No virt vectors corresponding with 0x0..0x100 */
  93. EXC_VIRT_NONE(0x4000, 0x100)
  94. #ifdef CONFIG_PPC_P7_NAP
  95. /*
  96. * If running native on arch 2.06 or later, check if we are waking up
  97. * from nap/sleep/winkle, and branch to idle handler. This tests SRR1
  98. * bits 46:47. A non-0 value indicates that we are coming from a power
  99. * saving state. The idle wakeup handler initially runs in real mode,
  100. * but we branch to the 0xc000... address so we can turn on relocation
  101. * with mtmsr.
  102. */
  103. #define IDLETEST(n) \
  104. BEGIN_FTR_SECTION ; \
  105. mfspr r10,SPRN_SRR1 ; \
  106. rlwinm. r10,r10,47-31,30,31 ; \
  107. beq- 1f ; \
  108. cmpwi cr3,r10,2 ; \
  109. BRANCH_TO_C000(r10, system_reset_idle_common) ; \
  110. 1: \
  111. KVMTEST_PR(n) ; \
  112. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  113. #else
  114. #define IDLETEST NOTEST
  115. #endif
  116. EXC_REAL_BEGIN(system_reset, 0x100, 0x100)
  117. SET_SCRATCH0(r13)
  118. /*
  119. * MSR_RI is not enabled, because PACA_EXNMI and nmi stack is
  120. * being used, so a nested NMI exception would corrupt it.
  121. */
  122. EXCEPTION_PROLOG_NORI(PACA_EXNMI, system_reset_common, EXC_STD,
  123. IDLETEST, 0x100)
  124. EXC_REAL_END(system_reset, 0x100, 0x100)
  125. EXC_VIRT_NONE(0x4100, 0x100)
  126. TRAMP_KVM(PACA_EXNMI, 0x100)
  127. #ifdef CONFIG_PPC_P7_NAP
  128. EXC_COMMON_BEGIN(system_reset_idle_common)
  129. mfspr r12,SPRN_SRR1
  130. b pnv_powersave_wakeup
  131. #endif
  132. /*
  133. * Set IRQS_ALL_DISABLED unconditionally so arch_irqs_disabled does
  134. * the right thing. We do not want to reconcile because that goes
  135. * through irq tracing which we don't want in NMI.
  136. *
  137. * Save PACAIRQHAPPENED because some code will do a hard disable
  138. * (e.g., xmon). So we want to restore this back to where it was
  139. * when we return. DAR is unused in the stack, so save it there.
  140. */
  141. #define ADD_RECONCILE_NMI \
  142. li r10,IRQS_ALL_DISABLED; \
  143. stb r10,PACAIRQSOFTMASK(r13); \
  144. lbz r10,PACAIRQHAPPENED(r13); \
  145. std r10,_DAR(r1)
  146. EXC_COMMON_BEGIN(system_reset_common)
  147. /*
  148. * Increment paca->in_nmi then enable MSR_RI. SLB or MCE will be able
  149. * to recover, but nested NMI will notice in_nmi and not recover
  150. * because of the use of the NMI stack. in_nmi reentrancy is tested in
  151. * system_reset_exception.
  152. */
  153. lhz r10,PACA_IN_NMI(r13)
  154. addi r10,r10,1
  155. sth r10,PACA_IN_NMI(r13)
  156. li r10,MSR_RI
  157. mtmsrd r10,1
  158. mr r10,r1
  159. ld r1,PACA_NMI_EMERG_SP(r13)
  160. subi r1,r1,INT_FRAME_SIZE
  161. EXCEPTION_COMMON_NORET_STACK(PACA_EXNMI, 0x100,
  162. system_reset, system_reset_exception,
  163. ADD_NVGPRS;ADD_RECONCILE_NMI)
  164. /* This (and MCE) can be simplified with mtmsrd L=1 */
  165. /* Clear MSR_RI before setting SRR0 and SRR1. */
  166. li r0,MSR_RI
  167. mfmsr r9
  168. andc r9,r9,r0
  169. mtmsrd r9,1
  170. /*
  171. * MSR_RI is clear, now we can decrement paca->in_nmi.
  172. */
  173. lhz r10,PACA_IN_NMI(r13)
  174. subi r10,r10,1
  175. sth r10,PACA_IN_NMI(r13)
  176. /*
  177. * Restore soft mask settings.
  178. */
  179. ld r10,_DAR(r1)
  180. stb r10,PACAIRQHAPPENED(r13)
  181. ld r10,SOFTE(r1)
  182. stb r10,PACAIRQSOFTMASK(r13)
  183. /*
  184. * Keep below code in synch with MACHINE_CHECK_HANDLER_WINDUP.
  185. * Should share common bits...
  186. */
  187. /* Move original SRR0 and SRR1 into the respective regs */
  188. ld r9,_MSR(r1)
  189. mtspr SPRN_SRR1,r9
  190. ld r3,_NIP(r1)
  191. mtspr SPRN_SRR0,r3
  192. ld r9,_CTR(r1)
  193. mtctr r9
  194. ld r9,_XER(r1)
  195. mtxer r9
  196. ld r9,_LINK(r1)
  197. mtlr r9
  198. REST_GPR(0, r1)
  199. REST_8GPRS(2, r1)
  200. REST_GPR(10, r1)
  201. ld r11,_CCR(r1)
  202. mtcr r11
  203. REST_GPR(11, r1)
  204. REST_2GPRS(12, r1)
  205. /* restore original r1. */
  206. ld r1,GPR1(r1)
  207. RFI_TO_USER_OR_KERNEL
  208. #ifdef CONFIG_PPC_PSERIES
  209. /*
  210. * Vectors for the FWNMI option. Share common code.
  211. */
  212. TRAMP_REAL_BEGIN(system_reset_fwnmi)
  213. SET_SCRATCH0(r13) /* save r13 */
  214. /* See comment at system_reset exception */
  215. EXCEPTION_PROLOG_NORI(PACA_EXNMI, system_reset_common, EXC_STD,
  216. NOTEST, 0x100)
  217. #endif /* CONFIG_PPC_PSERIES */
  218. EXC_REAL_BEGIN(machine_check, 0x200, 0x100)
  219. /* This is moved out of line as it can be patched by FW, but
  220. * some code path might still want to branch into the original
  221. * vector
  222. */
  223. SET_SCRATCH0(r13) /* save r13 */
  224. EXCEPTION_PROLOG_0(PACA_EXMC)
  225. BEGIN_FTR_SECTION
  226. b machine_check_powernv_early
  227. FTR_SECTION_ELSE
  228. b machine_check_pSeries_0
  229. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  230. EXC_REAL_END(machine_check, 0x200, 0x100)
  231. EXC_VIRT_NONE(0x4200, 0x100)
  232. TRAMP_REAL_BEGIN(machine_check_powernv_early)
  233. BEGIN_FTR_SECTION
  234. EXCEPTION_PROLOG_1(PACA_EXMC, NOTEST, 0x200)
  235. /*
  236. * Register contents:
  237. * R13 = PACA
  238. * R9 = CR
  239. * Original R9 to R13 is saved on PACA_EXMC
  240. *
  241. * Switch to mc_emergency stack and handle re-entrancy (we limit
  242. * the nested MCE upto level 4 to avoid stack overflow).
  243. * Save MCE registers srr1, srr0, dar and dsisr and then set ME=1
  244. *
  245. * We use paca->in_mce to check whether this is the first entry or
  246. * nested machine check. We increment paca->in_mce to track nested
  247. * machine checks.
  248. *
  249. * If this is the first entry then set stack pointer to
  250. * paca->mc_emergency_sp, otherwise r1 is already pointing to
  251. * stack frame on mc_emergency stack.
  252. *
  253. * NOTE: We are here with MSR_ME=0 (off), which means we risk a
  254. * checkstop if we get another machine check exception before we do
  255. * rfid with MSR_ME=1.
  256. *
  257. * This interrupt can wake directly from idle. If that is the case,
  258. * the machine check is handled then the idle wakeup code is called
  259. * to restore state.
  260. */
  261. mr r11,r1 /* Save r1 */
  262. lhz r10,PACA_IN_MCE(r13)
  263. cmpwi r10,0 /* Are we in nested machine check */
  264. bne 0f /* Yes, we are. */
  265. /* First machine check entry */
  266. ld r1,PACAMCEMERGSP(r13) /* Use MC emergency stack */
  267. 0: subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  268. addi r10,r10,1 /* increment paca->in_mce */
  269. sth r10,PACA_IN_MCE(r13)
  270. /* Limit nested MCE to level 4 to avoid stack overflow */
  271. cmpwi r10,MAX_MCE_DEPTH
  272. bgt 2f /* Check if we hit limit of 4 */
  273. std r11,GPR1(r1) /* Save r1 on the stack. */
  274. std r11,0(r1) /* make stack chain pointer */
  275. mfspr r11,SPRN_SRR0 /* Save SRR0 */
  276. std r11,_NIP(r1)
  277. mfspr r11,SPRN_SRR1 /* Save SRR1 */
  278. std r11,_MSR(r1)
  279. mfspr r11,SPRN_DAR /* Save DAR */
  280. std r11,_DAR(r1)
  281. mfspr r11,SPRN_DSISR /* Save DSISR */
  282. std r11,_DSISR(r1)
  283. std r9,_CCR(r1) /* Save CR in stackframe */
  284. /* Save r9 through r13 from EXMC save area to stack frame. */
  285. EXCEPTION_PROLOG_COMMON_2(PACA_EXMC)
  286. mfmsr r11 /* get MSR value */
  287. ori r11,r11,MSR_ME /* turn on ME bit */
  288. ori r11,r11,MSR_RI /* turn on RI bit */
  289. LOAD_HANDLER(r12, machine_check_handle_early)
  290. 1: mtspr SPRN_SRR0,r12
  291. mtspr SPRN_SRR1,r11
  292. RFI_TO_KERNEL
  293. b . /* prevent speculative execution */
  294. 2:
  295. /* Stack overflow. Stay on emergency stack and panic.
  296. * Keep the ME bit off while panic-ing, so that if we hit
  297. * another machine check we checkstop.
  298. */
  299. addi r1,r1,INT_FRAME_SIZE /* go back to previous stack frame */
  300. ld r11,PACAKMSR(r13)
  301. LOAD_HANDLER(r12, unrecover_mce)
  302. li r10,MSR_ME
  303. andc r11,r11,r10 /* Turn off MSR_ME */
  304. b 1b
  305. b . /* prevent speculative execution */
  306. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
  307. TRAMP_REAL_BEGIN(machine_check_pSeries)
  308. .globl machine_check_fwnmi
  309. machine_check_fwnmi:
  310. SET_SCRATCH0(r13) /* save r13 */
  311. EXCEPTION_PROLOG_0(PACA_EXMC)
  312. machine_check_pSeries_0:
  313. EXCEPTION_PROLOG_1(PACA_EXMC, KVMTEST_PR, 0x200)
  314. /*
  315. * MSR_RI is not enabled, because PACA_EXMC is being used, so a
  316. * nested machine check corrupts it. machine_check_common enables
  317. * MSR_RI.
  318. */
  319. EXCEPTION_PROLOG_2_NORI(machine_check_common, EXC_STD)
  320. TRAMP_KVM_SKIP(PACA_EXMC, 0x200)
  321. EXC_COMMON_BEGIN(machine_check_common)
  322. /*
  323. * Machine check is different because we use a different
  324. * save area: PACA_EXMC instead of PACA_EXGEN.
  325. */
  326. mfspr r10,SPRN_DAR
  327. std r10,PACA_EXMC+EX_DAR(r13)
  328. mfspr r10,SPRN_DSISR
  329. stw r10,PACA_EXMC+EX_DSISR(r13)
  330. EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
  331. FINISH_NAP
  332. RECONCILE_IRQ_STATE(r10, r11)
  333. ld r3,PACA_EXMC+EX_DAR(r13)
  334. lwz r4,PACA_EXMC+EX_DSISR(r13)
  335. /* Enable MSR_RI when finished with PACA_EXMC */
  336. li r10,MSR_RI
  337. mtmsrd r10,1
  338. std r3,_DAR(r1)
  339. std r4,_DSISR(r1)
  340. bl save_nvgprs
  341. addi r3,r1,STACK_FRAME_OVERHEAD
  342. bl machine_check_exception
  343. b ret_from_except
  344. #define MACHINE_CHECK_HANDLER_WINDUP \
  345. /* Clear MSR_RI before setting SRR0 and SRR1. */\
  346. li r0,MSR_RI; \
  347. mfmsr r9; /* get MSR value */ \
  348. andc r9,r9,r0; \
  349. mtmsrd r9,1; /* Clear MSR_RI */ \
  350. /* Move original SRR0 and SRR1 into the respective regs */ \
  351. ld r9,_MSR(r1); \
  352. mtspr SPRN_SRR1,r9; \
  353. ld r3,_NIP(r1); \
  354. mtspr SPRN_SRR0,r3; \
  355. ld r9,_CTR(r1); \
  356. mtctr r9; \
  357. ld r9,_XER(r1); \
  358. mtxer r9; \
  359. ld r9,_LINK(r1); \
  360. mtlr r9; \
  361. REST_GPR(0, r1); \
  362. REST_8GPRS(2, r1); \
  363. REST_GPR(10, r1); \
  364. ld r11,_CCR(r1); \
  365. mtcr r11; \
  366. /* Decrement paca->in_mce. */ \
  367. lhz r12,PACA_IN_MCE(r13); \
  368. subi r12,r12,1; \
  369. sth r12,PACA_IN_MCE(r13); \
  370. REST_GPR(11, r1); \
  371. REST_2GPRS(12, r1); \
  372. /* restore original r1. */ \
  373. ld r1,GPR1(r1)
  374. #ifdef CONFIG_PPC_P7_NAP
  375. /*
  376. * This is an idle wakeup. Low level machine check has already been
  377. * done. Queue the event then call the idle code to do the wake up.
  378. */
  379. EXC_COMMON_BEGIN(machine_check_idle_common)
  380. bl machine_check_queue_event
  381. /*
  382. * We have not used any non-volatile GPRs here, and as a rule
  383. * most exception code including machine check does not.
  384. * Therefore PACA_NAPSTATELOST does not need to be set. Idle
  385. * wakeup will restore volatile registers.
  386. *
  387. * Load the original SRR1 into r3 for pnv_powersave_wakeup_mce.
  388. *
  389. * Then decrement MCE nesting after finishing with the stack.
  390. */
  391. ld r3,_MSR(r1)
  392. lhz r11,PACA_IN_MCE(r13)
  393. subi r11,r11,1
  394. sth r11,PACA_IN_MCE(r13)
  395. /* Turn off the RI bit because SRR1 is used by idle wakeup code. */
  396. /* Recoverability could be improved by reducing the use of SRR1. */
  397. li r11,0
  398. mtmsrd r11,1
  399. b pnv_powersave_wakeup_mce
  400. #endif
  401. /*
  402. * Handle machine check early in real mode. We come here with
  403. * ME=1, MMU (IR=0 and DR=0) off and using MC emergency stack.
  404. */
  405. EXC_COMMON_BEGIN(machine_check_handle_early)
  406. std r0,GPR0(r1) /* Save r0 */
  407. EXCEPTION_PROLOG_COMMON_3(0x200)
  408. bl save_nvgprs
  409. addi r3,r1,STACK_FRAME_OVERHEAD
  410. bl machine_check_early
  411. std r3,RESULT(r1) /* Save result */
  412. ld r12,_MSR(r1)
  413. #ifdef CONFIG_PPC_P7_NAP
  414. /*
  415. * Check if thread was in power saving mode. We come here when any
  416. * of the following is true:
  417. * a. thread wasn't in power saving mode
  418. * b. thread was in power saving mode with no state loss,
  419. * supervisor state loss or hypervisor state loss.
  420. *
  421. * Go back to nap/sleep/winkle mode again if (b) is true.
  422. */
  423. BEGIN_FTR_SECTION
  424. rlwinm. r11,r12,47-31,30,31
  425. bne machine_check_idle_common
  426. END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  427. #endif
  428. /*
  429. * Check if we are coming from hypervisor userspace. If yes then we
  430. * continue in host kernel in V mode to deliver the MC event.
  431. */
  432. rldicl. r11,r12,4,63 /* See if MC hit while in HV mode. */
  433. beq 5f
  434. andi. r11,r12,MSR_PR /* See if coming from user. */
  435. bne 9f /* continue in V mode if we are. */
  436. 5:
  437. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  438. /*
  439. * We are coming from kernel context. Check if we are coming from
  440. * guest. if yes, then we can continue. We will fall through
  441. * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
  442. */
  443. lbz r11,HSTATE_IN_GUEST(r13)
  444. cmpwi r11,0 /* Check if coming from guest */
  445. bne 9f /* continue if we are. */
  446. #endif
  447. /*
  448. * At this point we are not sure about what context we come from.
  449. * Queue up the MCE event and return from the interrupt.
  450. * But before that, check if this is an un-recoverable exception.
  451. * If yes, then stay on emergency stack and panic.
  452. */
  453. andi. r11,r12,MSR_RI
  454. bne 2f
  455. 1: mfspr r11,SPRN_SRR0
  456. LOAD_HANDLER(r10,unrecover_mce)
  457. mtspr SPRN_SRR0,r10
  458. ld r10,PACAKMSR(r13)
  459. /*
  460. * We are going down. But there are chances that we might get hit by
  461. * another MCE during panic path and we may run into unstable state
  462. * with no way out. Hence, turn ME bit off while going down, so that
  463. * when another MCE is hit during panic path, system will checkstop
  464. * and hypervisor will get restarted cleanly by SP.
  465. */
  466. li r3,MSR_ME
  467. andc r10,r10,r3 /* Turn off MSR_ME */
  468. mtspr SPRN_SRR1,r10
  469. RFI_TO_KERNEL
  470. b .
  471. 2:
  472. /*
  473. * Check if we have successfully handled/recovered from error, if not
  474. * then stay on emergency stack and panic.
  475. */
  476. ld r3,RESULT(r1) /* Load result */
  477. cmpdi r3,0 /* see if we handled MCE successfully */
  478. beq 1b /* if !handled then panic */
  479. /*
  480. * Return from MC interrupt.
  481. * Queue up the MCE event so that we can log it later, while
  482. * returning from kernel or opal call.
  483. */
  484. bl machine_check_queue_event
  485. MACHINE_CHECK_HANDLER_WINDUP
  486. RFI_TO_USER_OR_KERNEL
  487. 9:
  488. /* Deliver the machine check to host kernel in V mode. */
  489. BEGIN_FTR_SECTION
  490. ld r10,ORIG_GPR3(r1)
  491. mtspr SPRN_CFAR,r10
  492. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  493. MACHINE_CHECK_HANDLER_WINDUP
  494. b machine_check_pSeries
  495. EXC_COMMON_BEGIN(unrecover_mce)
  496. /* Invoke machine_check_exception to print MCE event and panic. */
  497. addi r3,r1,STACK_FRAME_OVERHEAD
  498. bl machine_check_exception
  499. /*
  500. * We will not reach here. Even if we did, there is no way out. Call
  501. * unrecoverable_exception and die.
  502. */
  503. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  504. bl unrecoverable_exception
  505. b 1b
  506. EXC_REAL_OOL(data_access, 0x300, 0x80)
  507. EXC_VIRT(data_access, 0x4300, 0x80, 0x300)
  508. TRAMP_KVM_SKIP(PACA_EXGEN, 0x300)
  509. EXC_COMMON_BEGIN(data_access_common)
  510. /*
  511. * Here r13 points to the paca, r9 contains the saved CR,
  512. * SRR0 and SRR1 are saved in r11 and r12,
  513. * r9 - r13 are saved in paca->exgen.
  514. */
  515. mfspr r10,SPRN_DAR
  516. std r10,PACA_EXGEN+EX_DAR(r13)
  517. mfspr r10,SPRN_DSISR
  518. stw r10,PACA_EXGEN+EX_DSISR(r13)
  519. EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
  520. RECONCILE_IRQ_STATE(r10, r11)
  521. ld r12,_MSR(r1)
  522. ld r3,PACA_EXGEN+EX_DAR(r13)
  523. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  524. li r5,0x300
  525. std r3,_DAR(r1)
  526. std r4,_DSISR(r1)
  527. BEGIN_MMU_FTR_SECTION
  528. b do_hash_page /* Try to handle as hpte fault */
  529. MMU_FTR_SECTION_ELSE
  530. b handle_page_fault
  531. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
  532. EXC_REAL_BEGIN(data_access_slb, 0x380, 0x80)
  533. SET_SCRATCH0(r13)
  534. EXCEPTION_PROLOG_0(PACA_EXSLB)
  535. b tramp_data_access_slb
  536. EXC_REAL_END(data_access_slb, 0x380, 0x80)
  537. TRAMP_REAL_BEGIN(tramp_data_access_slb)
  538. EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x380)
  539. mr r12,r3 /* save r3 */
  540. mfspr r3,SPRN_DAR
  541. mfspr r11,SPRN_SRR1
  542. crset 4*cr6+eq
  543. BRANCH_TO_COMMON(r10, slb_miss_common)
  544. EXC_VIRT_BEGIN(data_access_slb, 0x4380, 0x80)
  545. SET_SCRATCH0(r13)
  546. EXCEPTION_PROLOG_0(PACA_EXSLB)
  547. EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x380)
  548. mr r12,r3 /* save r3 */
  549. mfspr r3,SPRN_DAR
  550. mfspr r11,SPRN_SRR1
  551. crset 4*cr6+eq
  552. BRANCH_TO_COMMON(r10, slb_miss_common)
  553. EXC_VIRT_END(data_access_slb, 0x4380, 0x80)
  554. TRAMP_KVM_SKIP(PACA_EXSLB, 0x380)
  555. EXC_REAL_OOL(instruction_access, 0x400, 0x80)
  556. EXC_VIRT(instruction_access, 0x4400, 0x80, 0x400)
  557. TRAMP_KVM(PACA_EXGEN, 0x400)
  558. EXC_COMMON_BEGIN(instruction_access_common)
  559. EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
  560. RECONCILE_IRQ_STATE(r10, r11)
  561. ld r12,_MSR(r1)
  562. ld r3,_NIP(r1)
  563. andis. r4,r12,DSISR_SRR1_MATCH_64S@h
  564. li r5,0x400
  565. std r3,_DAR(r1)
  566. std r4,_DSISR(r1)
  567. BEGIN_MMU_FTR_SECTION
  568. b do_hash_page /* Try to handle as hpte fault */
  569. MMU_FTR_SECTION_ELSE
  570. b handle_page_fault
  571. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_TYPE_RADIX)
  572. EXC_REAL_BEGIN(instruction_access_slb, 0x480, 0x80)
  573. SET_SCRATCH0(r13)
  574. EXCEPTION_PROLOG_0(PACA_EXSLB)
  575. b tramp_instruction_access_slb
  576. EXC_REAL_END(instruction_access_slb, 0x480, 0x80)
  577. TRAMP_REAL_BEGIN(tramp_instruction_access_slb)
  578. EXCEPTION_PROLOG_1(PACA_EXSLB, KVMTEST_PR, 0x480)
  579. mr r12,r3 /* save r3 */
  580. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  581. mfspr r11,SPRN_SRR1
  582. crclr 4*cr6+eq
  583. BRANCH_TO_COMMON(r10, slb_miss_common)
  584. EXC_VIRT_BEGIN(instruction_access_slb, 0x4480, 0x80)
  585. SET_SCRATCH0(r13)
  586. EXCEPTION_PROLOG_0(PACA_EXSLB)
  587. EXCEPTION_PROLOG_1(PACA_EXSLB, NOTEST, 0x480)
  588. mr r12,r3 /* save r3 */
  589. mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
  590. mfspr r11,SPRN_SRR1
  591. crclr 4*cr6+eq
  592. BRANCH_TO_COMMON(r10, slb_miss_common)
  593. EXC_VIRT_END(instruction_access_slb, 0x4480, 0x80)
  594. TRAMP_KVM(PACA_EXSLB, 0x480)
  595. /*
  596. * This handler is used by the 0x380 and 0x480 SLB miss interrupts, as well as
  597. * the virtual mode 0x4380 and 0x4480 interrupts if AIL is enabled.
  598. */
  599. EXC_COMMON_BEGIN(slb_miss_common)
  600. /*
  601. * r13 points to the PACA, r9 contains the saved CR,
  602. * r12 contains the saved r3,
  603. * r11 contain the saved SRR1, SRR0 is still ready for return
  604. * r3 has the faulting address
  605. * r9 - r13 are saved in paca->exslb.
  606. * cr6.eq is set for a D-SLB miss, clear for a I-SLB miss
  607. * We assume we aren't going to take any exceptions during this
  608. * procedure.
  609. */
  610. mflr r10
  611. stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
  612. std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
  613. andi. r9,r11,MSR_PR // Check for exception from userspace
  614. cmpdi cr4,r9,MSR_PR // And save the result in CR4 for later
  615. /*
  616. * Test MSR_RI before calling slb_allocate_realmode, because the
  617. * MSR in r11 gets clobbered. However we still want to allocate
  618. * SLB in case MSR_RI=0, to minimise the risk of getting stuck in
  619. * recursive SLB faults. So use cr5 for this, which is preserved.
  620. */
  621. andi. r11,r11,MSR_RI /* check for unrecoverable exception */
  622. cmpdi cr5,r11,MSR_RI
  623. crset 4*cr0+eq
  624. #ifdef CONFIG_PPC_BOOK3S_64
  625. BEGIN_MMU_FTR_SECTION
  626. bl slb_allocate
  627. END_MMU_FTR_SECTION_IFCLR(MMU_FTR_TYPE_RADIX)
  628. #endif
  629. ld r10,PACA_EXSLB+EX_LR(r13)
  630. lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
  631. mtlr r10
  632. /*
  633. * Large address, check whether we have to allocate new contexts.
  634. */
  635. beq- 8f
  636. bne- cr5,2f /* if unrecoverable exception, oops */
  637. /* All done -- return from exception. */
  638. bne cr4,1f /* returning to kernel */
  639. mtcrf 0x80,r9
  640. mtcrf 0x08,r9 /* MSR[PR] indication is in cr4 */
  641. mtcrf 0x04,r9 /* MSR[RI] indication is in cr5 */
  642. mtcrf 0x02,r9 /* I/D indication is in cr6 */
  643. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  644. RESTORE_CTR(r9, PACA_EXSLB)
  645. RESTORE_PPR_PACA(PACA_EXSLB, r9)
  646. mr r3,r12
  647. ld r9,PACA_EXSLB+EX_R9(r13)
  648. ld r10,PACA_EXSLB+EX_R10(r13)
  649. ld r11,PACA_EXSLB+EX_R11(r13)
  650. ld r12,PACA_EXSLB+EX_R12(r13)
  651. ld r13,PACA_EXSLB+EX_R13(r13)
  652. RFI_TO_USER
  653. b . /* prevent speculative execution */
  654. 1:
  655. mtcrf 0x80,r9
  656. mtcrf 0x08,r9 /* MSR[PR] indication is in cr4 */
  657. mtcrf 0x04,r9 /* MSR[RI] indication is in cr5 */
  658. mtcrf 0x02,r9 /* I/D indication is in cr6 */
  659. mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
  660. RESTORE_CTR(r9, PACA_EXSLB)
  661. RESTORE_PPR_PACA(PACA_EXSLB, r9)
  662. mr r3,r12
  663. ld r9,PACA_EXSLB+EX_R9(r13)
  664. ld r10,PACA_EXSLB+EX_R10(r13)
  665. ld r11,PACA_EXSLB+EX_R11(r13)
  666. ld r12,PACA_EXSLB+EX_R12(r13)
  667. ld r13,PACA_EXSLB+EX_R13(r13)
  668. RFI_TO_KERNEL
  669. b . /* prevent speculative execution */
  670. 2: std r3,PACA_EXSLB+EX_DAR(r13)
  671. mr r3,r12
  672. mfspr r11,SPRN_SRR0
  673. mfspr r12,SPRN_SRR1
  674. LOAD_HANDLER(r10,unrecov_slb)
  675. mtspr SPRN_SRR0,r10
  676. ld r10,PACAKMSR(r13)
  677. mtspr SPRN_SRR1,r10
  678. RFI_TO_KERNEL
  679. b .
  680. 8: std r3,PACA_EXSLB+EX_DAR(r13)
  681. mr r3,r12
  682. mfspr r11,SPRN_SRR0
  683. mfspr r12,SPRN_SRR1
  684. LOAD_HANDLER(r10, large_addr_slb)
  685. mtspr SPRN_SRR0,r10
  686. ld r10,PACAKMSR(r13)
  687. mtspr SPRN_SRR1,r10
  688. RFI_TO_KERNEL
  689. b .
  690. EXC_COMMON_BEGIN(unrecov_slb)
  691. EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
  692. RECONCILE_IRQ_STATE(r10, r11)
  693. bl save_nvgprs
  694. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  695. bl unrecoverable_exception
  696. b 1b
  697. EXC_COMMON_BEGIN(large_addr_slb)
  698. EXCEPTION_PROLOG_COMMON(0x380, PACA_EXSLB)
  699. RECONCILE_IRQ_STATE(r10, r11)
  700. ld r3, PACA_EXSLB+EX_DAR(r13)
  701. std r3, _DAR(r1)
  702. beq cr6, 2f
  703. li r10, 0x481 /* fix trap number for I-SLB miss */
  704. std r10, _TRAP(r1)
  705. 2: bl save_nvgprs
  706. addi r3, r1, STACK_FRAME_OVERHEAD
  707. bl slb_miss_large_addr
  708. b ret_from_except
  709. EXC_REAL_BEGIN(hardware_interrupt, 0x500, 0x100)
  710. .globl hardware_interrupt_hv;
  711. hardware_interrupt_hv:
  712. BEGIN_FTR_SECTION
  713. MASKABLE_EXCEPTION_HV(0x500, hardware_interrupt_common, IRQS_DISABLED)
  714. FTR_SECTION_ELSE
  715. MASKABLE_EXCEPTION(0x500, hardware_interrupt_common, IRQS_DISABLED)
  716. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
  717. EXC_REAL_END(hardware_interrupt, 0x500, 0x100)
  718. EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100)
  719. .globl hardware_interrupt_relon_hv;
  720. hardware_interrupt_relon_hv:
  721. BEGIN_FTR_SECTION
  722. MASKABLE_RELON_EXCEPTION_HV(0x500, hardware_interrupt_common,
  723. IRQS_DISABLED)
  724. FTR_SECTION_ELSE
  725. __MASKABLE_RELON_EXCEPTION(0x500, hardware_interrupt_common,
  726. EXC_STD, SOFTEN_TEST_PR, IRQS_DISABLED)
  727. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  728. EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100)
  729. TRAMP_KVM(PACA_EXGEN, 0x500)
  730. TRAMP_KVM_HV(PACA_EXGEN, 0x500)
  731. EXC_COMMON_ASYNC(hardware_interrupt_common, 0x500, do_IRQ)
  732. EXC_REAL(alignment, 0x600, 0x100)
  733. EXC_VIRT(alignment, 0x4600, 0x100, 0x600)
  734. TRAMP_KVM(PACA_EXGEN, 0x600)
  735. EXC_COMMON_BEGIN(alignment_common)
  736. mfspr r10,SPRN_DAR
  737. std r10,PACA_EXGEN+EX_DAR(r13)
  738. mfspr r10,SPRN_DSISR
  739. stw r10,PACA_EXGEN+EX_DSISR(r13)
  740. EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
  741. ld r3,PACA_EXGEN+EX_DAR(r13)
  742. lwz r4,PACA_EXGEN+EX_DSISR(r13)
  743. std r3,_DAR(r1)
  744. std r4,_DSISR(r1)
  745. bl save_nvgprs
  746. RECONCILE_IRQ_STATE(r10, r11)
  747. addi r3,r1,STACK_FRAME_OVERHEAD
  748. bl alignment_exception
  749. b ret_from_except
  750. EXC_REAL(program_check, 0x700, 0x100)
  751. EXC_VIRT(program_check, 0x4700, 0x100, 0x700)
  752. TRAMP_KVM(PACA_EXGEN, 0x700)
  753. EXC_COMMON_BEGIN(program_check_common)
  754. /*
  755. * It's possible to receive a TM Bad Thing type program check with
  756. * userspace register values (in particular r1), but with SRR1 reporting
  757. * that we came from the kernel. Normally that would confuse the bad
  758. * stack logic, and we would report a bad kernel stack pointer. Instead
  759. * we switch to the emergency stack if we're taking a TM Bad Thing from
  760. * the kernel.
  761. */
  762. li r10,MSR_PR /* Build a mask of MSR_PR .. */
  763. oris r10,r10,0x200000@h /* .. and SRR1_PROGTM */
  764. and r10,r10,r12 /* Mask SRR1 with that. */
  765. srdi r10,r10,8 /* Shift it so we can compare */
  766. cmpldi r10,(0x200000 >> 8) /* .. with an immediate. */
  767. bne 1f /* If != go to normal path. */
  768. /* SRR1 had PR=0 and SRR1_PROGTM=1, so use the emergency stack */
  769. andi. r10,r12,MSR_PR; /* Set CR0 correctly for label */
  770. /* 3 in EXCEPTION_PROLOG_COMMON */
  771. mr r10,r1 /* Save r1 */
  772. ld r1,PACAEMERGSP(r13) /* Use emergency stack */
  773. subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  774. b 3f /* Jump into the macro !! */
  775. 1: EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
  776. bl save_nvgprs
  777. RECONCILE_IRQ_STATE(r10, r11)
  778. addi r3,r1,STACK_FRAME_OVERHEAD
  779. bl program_check_exception
  780. b ret_from_except
  781. EXC_REAL(fp_unavailable, 0x800, 0x100)
  782. EXC_VIRT(fp_unavailable, 0x4800, 0x100, 0x800)
  783. TRAMP_KVM(PACA_EXGEN, 0x800)
  784. EXC_COMMON_BEGIN(fp_unavailable_common)
  785. EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
  786. bne 1f /* if from user, just load it up */
  787. bl save_nvgprs
  788. RECONCILE_IRQ_STATE(r10, r11)
  789. addi r3,r1,STACK_FRAME_OVERHEAD
  790. bl kernel_fp_unavailable_exception
  791. BUG_OPCODE
  792. 1:
  793. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  794. BEGIN_FTR_SECTION
  795. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  796. * transaction), go do TM stuff
  797. */
  798. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  799. bne- 2f
  800. END_FTR_SECTION_IFSET(CPU_FTR_TM)
  801. #endif
  802. bl load_up_fpu
  803. b fast_exception_return
  804. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  805. 2: /* User process was in a transaction */
  806. bl save_nvgprs
  807. RECONCILE_IRQ_STATE(r10, r11)
  808. addi r3,r1,STACK_FRAME_OVERHEAD
  809. bl fp_unavailable_tm
  810. b ret_from_except
  811. #endif
  812. EXC_REAL_OOL_MASKABLE(decrementer, 0x900, 0x80, IRQS_DISABLED)
  813. EXC_VIRT_OOL_MASKABLE(decrementer, 0x4900, 0x80, 0x900, IRQS_DISABLED)
  814. TRAMP_KVM(PACA_EXGEN, 0x900)
  815. EXC_COMMON_ASYNC(decrementer_common, 0x900, timer_interrupt)
  816. EXC_REAL_OOL_HV(hdecrementer, 0x980, 0x80)
  817. EXC_VIRT_OOL_HV(hdecrementer, 0x4980, 0x80, 0x980)
  818. TRAMP_KVM_HV(PACA_EXGEN, 0x980)
  819. EXC_COMMON(hdecrementer_common, 0x980, hdec_interrupt)
  820. EXC_REAL_MASKABLE(doorbell_super, 0xa00, 0x100, IRQS_DISABLED)
  821. EXC_VIRT_MASKABLE(doorbell_super, 0x4a00, 0x100, 0xa00, IRQS_DISABLED)
  822. TRAMP_KVM(PACA_EXGEN, 0xa00)
  823. #ifdef CONFIG_PPC_DOORBELL
  824. EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, doorbell_exception)
  825. #else
  826. EXC_COMMON_ASYNC(doorbell_super_common, 0xa00, unknown_exception)
  827. #endif
  828. EXC_REAL(trap_0b, 0xb00, 0x100)
  829. EXC_VIRT(trap_0b, 0x4b00, 0x100, 0xb00)
  830. TRAMP_KVM(PACA_EXGEN, 0xb00)
  831. EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
  832. /*
  833. * system call / hypercall (0xc00, 0x4c00)
  834. *
  835. * The system call exception is invoked with "sc 0" and does not alter HV bit.
  836. * There is support for kernel code to invoke system calls but there are no
  837. * in-tree users.
  838. *
  839. * The hypercall is invoked with "sc 1" and sets HV=1.
  840. *
  841. * In HPT, sc 1 always goes to 0xc00 real mode. In RADIX, sc 1 can go to
  842. * 0x4c00 virtual mode.
  843. *
  844. * Call convention:
  845. *
  846. * syscall register convention is in Documentation/powerpc/syscall64-abi.txt
  847. *
  848. * For hypercalls, the register convention is as follows:
  849. * r0 volatile
  850. * r1-2 nonvolatile
  851. * r3 volatile parameter and return value for status
  852. * r4-r10 volatile input and output value
  853. * r11 volatile hypercall number and output value
  854. * r12 volatile input and output value
  855. * r13-r31 nonvolatile
  856. * LR nonvolatile
  857. * CTR volatile
  858. * XER volatile
  859. * CR0-1 CR5-7 volatile
  860. * CR2-4 nonvolatile
  861. * Other registers nonvolatile
  862. *
  863. * The intersection of volatile registers that don't contain possible
  864. * inputs is: cr0, xer, ctr. We may use these as scratch regs upon entry
  865. * without saving, though xer is not a good idea to use, as hardware may
  866. * interpret some bits so it may be costly to change them.
  867. */
  868. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  869. /*
  870. * There is a little bit of juggling to get syscall and hcall
  871. * working well. Save r13 in ctr to avoid using SPRG scratch
  872. * register.
  873. *
  874. * Userspace syscalls have already saved the PPR, hcalls must save
  875. * it before setting HMT_MEDIUM.
  876. */
  877. #define SYSCALL_KVMTEST \
  878. mtctr r13; \
  879. GET_PACA(r13); \
  880. std r10,PACA_EXGEN+EX_R10(r13); \
  881. INTERRUPT_TO_KERNEL; \
  882. KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \
  883. HMT_MEDIUM; \
  884. mfctr r9;
  885. #else
  886. #define SYSCALL_KVMTEST \
  887. HMT_MEDIUM; \
  888. mr r9,r13; \
  889. GET_PACA(r13); \
  890. INTERRUPT_TO_KERNEL;
  891. #endif
  892. #define LOAD_SYSCALL_HANDLER(reg) \
  893. __LOAD_HANDLER(reg, system_call_common)
  894. /*
  895. * After SYSCALL_KVMTEST, we reach here with PACA in r13, r13 in r9,
  896. * and HMT_MEDIUM.
  897. */
  898. #define SYSCALL_REAL \
  899. mfspr r11,SPRN_SRR0 ; \
  900. mfspr r12,SPRN_SRR1 ; \
  901. LOAD_SYSCALL_HANDLER(r10) ; \
  902. mtspr SPRN_SRR0,r10 ; \
  903. ld r10,PACAKMSR(r13) ; \
  904. mtspr SPRN_SRR1,r10 ; \
  905. RFI_TO_KERNEL ; \
  906. b . ; /* prevent speculative execution */
  907. #ifdef CONFIG_PPC_FAST_ENDIAN_SWITCH
  908. #define SYSCALL_FASTENDIAN_TEST \
  909. BEGIN_FTR_SECTION \
  910. cmpdi r0,0x1ebe ; \
  911. beq- 1f ; \
  912. END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE) \
  913. #define SYSCALL_FASTENDIAN \
  914. /* Fast LE/BE switch system call */ \
  915. 1: mfspr r12,SPRN_SRR1 ; \
  916. xori r12,r12,MSR_LE ; \
  917. mtspr SPRN_SRR1,r12 ; \
  918. mr r13,r9 ; \
  919. RFI_TO_USER ; /* return to userspace */ \
  920. b . ; /* prevent speculative execution */
  921. #else
  922. #define SYSCALL_FASTENDIAN_TEST
  923. #define SYSCALL_FASTENDIAN
  924. #endif /* CONFIG_PPC_FAST_ENDIAN_SWITCH */
  925. #if defined(CONFIG_RELOCATABLE)
  926. /*
  927. * We can't branch directly so we do it via the CTR which
  928. * is volatile across system calls.
  929. */
  930. #define SYSCALL_VIRT \
  931. LOAD_SYSCALL_HANDLER(r10) ; \
  932. mtctr r10 ; \
  933. mfspr r11,SPRN_SRR0 ; \
  934. mfspr r12,SPRN_SRR1 ; \
  935. li r10,MSR_RI ; \
  936. mtmsrd r10,1 ; \
  937. bctr ;
  938. #else
  939. /* We can branch directly */
  940. #define SYSCALL_VIRT \
  941. mfspr r11,SPRN_SRR0 ; \
  942. mfspr r12,SPRN_SRR1 ; \
  943. li r10,MSR_RI ; \
  944. mtmsrd r10,1 ; /* Set RI (EE=0) */ \
  945. b system_call_common ;
  946. #endif
  947. EXC_REAL_BEGIN(system_call, 0xc00, 0x100)
  948. SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
  949. SYSCALL_FASTENDIAN_TEST
  950. SYSCALL_REAL
  951. SYSCALL_FASTENDIAN
  952. EXC_REAL_END(system_call, 0xc00, 0x100)
  953. EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100)
  954. SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */
  955. SYSCALL_FASTENDIAN_TEST
  956. SYSCALL_VIRT
  957. SYSCALL_FASTENDIAN
  958. EXC_VIRT_END(system_call, 0x4c00, 0x100)
  959. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  960. /*
  961. * This is a hcall, so register convention is as above, with these
  962. * differences:
  963. * r13 = PACA
  964. * ctr = orig r13
  965. * orig r10 saved in PACA
  966. */
  967. TRAMP_KVM_BEGIN(do_kvm_0xc00)
  968. /*
  969. * Save the PPR (on systems that support it) before changing to
  970. * HMT_MEDIUM. That allows the KVM code to save that value into the
  971. * guest state (it is the guest's PPR value).
  972. */
  973. OPT_GET_SPR(r10, SPRN_PPR, CPU_FTR_HAS_PPR)
  974. HMT_MEDIUM
  975. OPT_SAVE_REG_TO_PACA(PACA_EXGEN+EX_PPR, r10, CPU_FTR_HAS_PPR)
  976. mfctr r10
  977. SET_SCRATCH0(r10)
  978. std r9,PACA_EXGEN+EX_R9(r13)
  979. mfcr r9
  980. KVM_HANDLER(PACA_EXGEN, EXC_STD, 0xc00)
  981. #endif
  982. EXC_REAL(single_step, 0xd00, 0x100)
  983. EXC_VIRT(single_step, 0x4d00, 0x100, 0xd00)
  984. TRAMP_KVM(PACA_EXGEN, 0xd00)
  985. EXC_COMMON(single_step_common, 0xd00, single_step_exception)
  986. EXC_REAL_OOL_HV(h_data_storage, 0xe00, 0x20)
  987. EXC_VIRT_OOL_HV(h_data_storage, 0x4e00, 0x20, 0xe00)
  988. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0xe00)
  989. EXC_COMMON_BEGIN(h_data_storage_common)
  990. mfspr r10,SPRN_HDAR
  991. std r10,PACA_EXGEN+EX_DAR(r13)
  992. mfspr r10,SPRN_HDSISR
  993. stw r10,PACA_EXGEN+EX_DSISR(r13)
  994. EXCEPTION_PROLOG_COMMON(0xe00, PACA_EXGEN)
  995. bl save_nvgprs
  996. RECONCILE_IRQ_STATE(r10, r11)
  997. addi r3,r1,STACK_FRAME_OVERHEAD
  998. bl unknown_exception
  999. b ret_from_except
  1000. EXC_REAL_OOL_HV(h_instr_storage, 0xe20, 0x20)
  1001. EXC_VIRT_OOL_HV(h_instr_storage, 0x4e20, 0x20, 0xe20)
  1002. TRAMP_KVM_HV(PACA_EXGEN, 0xe20)
  1003. EXC_COMMON(h_instr_storage_common, 0xe20, unknown_exception)
  1004. EXC_REAL_OOL_HV(emulation_assist, 0xe40, 0x20)
  1005. EXC_VIRT_OOL_HV(emulation_assist, 0x4e40, 0x20, 0xe40)
  1006. TRAMP_KVM_HV(PACA_EXGEN, 0xe40)
  1007. EXC_COMMON(emulation_assist_common, 0xe40, emulation_assist_interrupt)
  1008. /*
  1009. * hmi_exception trampoline is a special case. It jumps to hmi_exception_early
  1010. * first, and then eventaully from there to the trampoline to get into virtual
  1011. * mode.
  1012. */
  1013. __EXC_REAL_OOL_HV_DIRECT(hmi_exception, 0xe60, 0x20, hmi_exception_early)
  1014. __TRAMP_REAL_OOL_MASKABLE_HV(hmi_exception, 0xe60, IRQS_DISABLED)
  1015. EXC_VIRT_NONE(0x4e60, 0x20)
  1016. TRAMP_KVM_HV(PACA_EXGEN, 0xe60)
  1017. TRAMP_REAL_BEGIN(hmi_exception_early)
  1018. EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, 0xe60)
  1019. mr r10,r1 /* Save r1 */
  1020. ld r1,PACAEMERGSP(r13) /* Use emergency stack for realmode */
  1021. subi r1,r1,INT_FRAME_SIZE /* alloc stack frame */
  1022. mfspr r11,SPRN_HSRR0 /* Save HSRR0 */
  1023. mfspr r12,SPRN_HSRR1 /* Save HSRR1 */
  1024. EXCEPTION_PROLOG_COMMON_1()
  1025. EXCEPTION_PROLOG_COMMON_2(PACA_EXGEN)
  1026. EXCEPTION_PROLOG_COMMON_3(0xe60)
  1027. addi r3,r1,STACK_FRAME_OVERHEAD
  1028. BRANCH_LINK_TO_FAR(DOTSYM(hmi_exception_realmode)) /* Function call ABI */
  1029. cmpdi cr0,r3,0
  1030. /* Windup the stack. */
  1031. /* Move original HSRR0 and HSRR1 into the respective regs */
  1032. ld r9,_MSR(r1)
  1033. mtspr SPRN_HSRR1,r9
  1034. ld r3,_NIP(r1)
  1035. mtspr SPRN_HSRR0,r3
  1036. ld r9,_CTR(r1)
  1037. mtctr r9
  1038. ld r9,_XER(r1)
  1039. mtxer r9
  1040. ld r9,_LINK(r1)
  1041. mtlr r9
  1042. REST_GPR(0, r1)
  1043. REST_8GPRS(2, r1)
  1044. REST_GPR(10, r1)
  1045. ld r11,_CCR(r1)
  1046. REST_2GPRS(12, r1)
  1047. bne 1f
  1048. mtcr r11
  1049. REST_GPR(11, r1)
  1050. ld r1,GPR1(r1)
  1051. HRFI_TO_USER_OR_KERNEL
  1052. 1: mtcr r11
  1053. REST_GPR(11, r1)
  1054. ld r1,GPR1(r1)
  1055. /*
  1056. * Go to virtual mode and pull the HMI event information from
  1057. * firmware.
  1058. */
  1059. .globl hmi_exception_after_realmode
  1060. hmi_exception_after_realmode:
  1061. SET_SCRATCH0(r13)
  1062. EXCEPTION_PROLOG_0(PACA_EXGEN)
  1063. b tramp_real_hmi_exception
  1064. EXC_COMMON_BEGIN(hmi_exception_common)
  1065. EXCEPTION_COMMON(PACA_EXGEN, 0xe60, hmi_exception_common, handle_hmi_exception,
  1066. ret_from_except, FINISH_NAP;ADD_NVGPRS;ADD_RECONCILE;RUNLATCH_ON)
  1067. EXC_REAL_OOL_MASKABLE_HV(h_doorbell, 0xe80, 0x20, IRQS_DISABLED)
  1068. EXC_VIRT_OOL_MASKABLE_HV(h_doorbell, 0x4e80, 0x20, 0xe80, IRQS_DISABLED)
  1069. TRAMP_KVM_HV(PACA_EXGEN, 0xe80)
  1070. #ifdef CONFIG_PPC_DOORBELL
  1071. EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, doorbell_exception)
  1072. #else
  1073. EXC_COMMON_ASYNC(h_doorbell_common, 0xe80, unknown_exception)
  1074. #endif
  1075. EXC_REAL_OOL_MASKABLE_HV(h_virt_irq, 0xea0, 0x20, IRQS_DISABLED)
  1076. EXC_VIRT_OOL_MASKABLE_HV(h_virt_irq, 0x4ea0, 0x20, 0xea0, IRQS_DISABLED)
  1077. TRAMP_KVM_HV(PACA_EXGEN, 0xea0)
  1078. EXC_COMMON_ASYNC(h_virt_irq_common, 0xea0, do_IRQ)
  1079. EXC_REAL_NONE(0xec0, 0x20)
  1080. EXC_VIRT_NONE(0x4ec0, 0x20)
  1081. EXC_REAL_NONE(0xee0, 0x20)
  1082. EXC_VIRT_NONE(0x4ee0, 0x20)
  1083. EXC_REAL_OOL_MASKABLE(performance_monitor, 0xf00, 0x20, IRQS_PMI_DISABLED)
  1084. EXC_VIRT_OOL_MASKABLE(performance_monitor, 0x4f00, 0x20, 0xf00, IRQS_PMI_DISABLED)
  1085. TRAMP_KVM(PACA_EXGEN, 0xf00)
  1086. EXC_COMMON_ASYNC(performance_monitor_common, 0xf00, performance_monitor_exception)
  1087. EXC_REAL_OOL(altivec_unavailable, 0xf20, 0x20)
  1088. EXC_VIRT_OOL(altivec_unavailable, 0x4f20, 0x20, 0xf20)
  1089. TRAMP_KVM(PACA_EXGEN, 0xf20)
  1090. EXC_COMMON_BEGIN(altivec_unavailable_common)
  1091. EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
  1092. #ifdef CONFIG_ALTIVEC
  1093. BEGIN_FTR_SECTION
  1094. beq 1f
  1095. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1096. BEGIN_FTR_SECTION_NESTED(69)
  1097. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  1098. * transaction), go do TM stuff
  1099. */
  1100. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1101. bne- 2f
  1102. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  1103. #endif
  1104. bl load_up_altivec
  1105. b fast_exception_return
  1106. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1107. 2: /* User process was in a transaction */
  1108. bl save_nvgprs
  1109. RECONCILE_IRQ_STATE(r10, r11)
  1110. addi r3,r1,STACK_FRAME_OVERHEAD
  1111. bl altivec_unavailable_tm
  1112. b ret_from_except
  1113. #endif
  1114. 1:
  1115. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  1116. #endif
  1117. bl save_nvgprs
  1118. RECONCILE_IRQ_STATE(r10, r11)
  1119. addi r3,r1,STACK_FRAME_OVERHEAD
  1120. bl altivec_unavailable_exception
  1121. b ret_from_except
  1122. EXC_REAL_OOL(vsx_unavailable, 0xf40, 0x20)
  1123. EXC_VIRT_OOL(vsx_unavailable, 0x4f40, 0x20, 0xf40)
  1124. TRAMP_KVM(PACA_EXGEN, 0xf40)
  1125. EXC_COMMON_BEGIN(vsx_unavailable_common)
  1126. EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
  1127. #ifdef CONFIG_VSX
  1128. BEGIN_FTR_SECTION
  1129. beq 1f
  1130. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1131. BEGIN_FTR_SECTION_NESTED(69)
  1132. /* Test if 2 TM state bits are zero. If non-zero (ie. userspace was in
  1133. * transaction), go do TM stuff
  1134. */
  1135. rldicl. r0, r12, (64-MSR_TS_LG), (64-2)
  1136. bne- 2f
  1137. END_FTR_SECTION_NESTED(CPU_FTR_TM, CPU_FTR_TM, 69)
  1138. #endif
  1139. b load_up_vsx
  1140. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  1141. 2: /* User process was in a transaction */
  1142. bl save_nvgprs
  1143. RECONCILE_IRQ_STATE(r10, r11)
  1144. addi r3,r1,STACK_FRAME_OVERHEAD
  1145. bl vsx_unavailable_tm
  1146. b ret_from_except
  1147. #endif
  1148. 1:
  1149. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  1150. #endif
  1151. bl save_nvgprs
  1152. RECONCILE_IRQ_STATE(r10, r11)
  1153. addi r3,r1,STACK_FRAME_OVERHEAD
  1154. bl vsx_unavailable_exception
  1155. b ret_from_except
  1156. EXC_REAL_OOL(facility_unavailable, 0xf60, 0x20)
  1157. EXC_VIRT_OOL(facility_unavailable, 0x4f60, 0x20, 0xf60)
  1158. TRAMP_KVM(PACA_EXGEN, 0xf60)
  1159. EXC_COMMON(facility_unavailable_common, 0xf60, facility_unavailable_exception)
  1160. EXC_REAL_OOL_HV(h_facility_unavailable, 0xf80, 0x20)
  1161. EXC_VIRT_OOL_HV(h_facility_unavailable, 0x4f80, 0x20, 0xf80)
  1162. TRAMP_KVM_HV(PACA_EXGEN, 0xf80)
  1163. EXC_COMMON(h_facility_unavailable_common, 0xf80, facility_unavailable_exception)
  1164. EXC_REAL_NONE(0xfa0, 0x20)
  1165. EXC_VIRT_NONE(0x4fa0, 0x20)
  1166. EXC_REAL_NONE(0xfc0, 0x20)
  1167. EXC_VIRT_NONE(0x4fc0, 0x20)
  1168. EXC_REAL_NONE(0xfe0, 0x20)
  1169. EXC_VIRT_NONE(0x4fe0, 0x20)
  1170. EXC_REAL_NONE(0x1000, 0x100)
  1171. EXC_VIRT_NONE(0x5000, 0x100)
  1172. EXC_REAL_NONE(0x1100, 0x100)
  1173. EXC_VIRT_NONE(0x5100, 0x100)
  1174. #ifdef CONFIG_CBE_RAS
  1175. EXC_REAL_HV(cbe_system_error, 0x1200, 0x100)
  1176. EXC_VIRT_NONE(0x5200, 0x100)
  1177. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1200)
  1178. EXC_COMMON(cbe_system_error_common, 0x1200, cbe_system_error_exception)
  1179. #else /* CONFIG_CBE_RAS */
  1180. EXC_REAL_NONE(0x1200, 0x100)
  1181. EXC_VIRT_NONE(0x5200, 0x100)
  1182. #endif
  1183. EXC_REAL(instruction_breakpoint, 0x1300, 0x100)
  1184. EXC_VIRT(instruction_breakpoint, 0x5300, 0x100, 0x1300)
  1185. TRAMP_KVM_SKIP(PACA_EXGEN, 0x1300)
  1186. EXC_COMMON(instruction_breakpoint_common, 0x1300, instruction_breakpoint_exception)
  1187. EXC_REAL_NONE(0x1400, 0x100)
  1188. EXC_VIRT_NONE(0x5400, 0x100)
  1189. EXC_REAL_BEGIN(denorm_exception_hv, 0x1500, 0x100)
  1190. mtspr SPRN_SPRG_HSCRATCH0,r13
  1191. EXCEPTION_PROLOG_0(PACA_EXGEN)
  1192. EXCEPTION_PROLOG_1(PACA_EXGEN, NOTEST, 0x1500)
  1193. #ifdef CONFIG_PPC_DENORMALISATION
  1194. mfspr r10,SPRN_HSRR1
  1195. andis. r10,r10,(HSRR1_DENORM)@h /* denorm? */
  1196. bne+ denorm_assist
  1197. #endif
  1198. KVMTEST_HV(0x1500)
  1199. EXCEPTION_PROLOG_2(denorm_common, EXC_HV)
  1200. EXC_REAL_END(denorm_exception_hv, 0x1500, 0x100)
  1201. #ifdef CONFIG_PPC_DENORMALISATION
  1202. EXC_VIRT_BEGIN(denorm_exception, 0x5500, 0x100)
  1203. b exc_real_0x1500_denorm_exception_hv
  1204. EXC_VIRT_END(denorm_exception, 0x5500, 0x100)
  1205. #else
  1206. EXC_VIRT_NONE(0x5500, 0x100)
  1207. #endif
  1208. TRAMP_KVM_HV(PACA_EXGEN, 0x1500)
  1209. #ifdef CONFIG_PPC_DENORMALISATION
  1210. TRAMP_REAL_BEGIN(denorm_assist)
  1211. BEGIN_FTR_SECTION
  1212. /*
  1213. * To denormalise we need to move a copy of the register to itself.
  1214. * For POWER6 do that here for all FP regs.
  1215. */
  1216. mfmsr r10
  1217. ori r10,r10,(MSR_FP|MSR_FE0|MSR_FE1)
  1218. xori r10,r10,(MSR_FE0|MSR_FE1)
  1219. mtmsrd r10
  1220. sync
  1221. #define FMR2(n) fmr (n), (n) ; fmr n+1, n+1
  1222. #define FMR4(n) FMR2(n) ; FMR2(n+2)
  1223. #define FMR8(n) FMR4(n) ; FMR4(n+4)
  1224. #define FMR16(n) FMR8(n) ; FMR8(n+8)
  1225. #define FMR32(n) FMR16(n) ; FMR16(n+16)
  1226. FMR32(0)
  1227. FTR_SECTION_ELSE
  1228. /*
  1229. * To denormalise we need to move a copy of the register to itself.
  1230. * For POWER7 do that here for the first 32 VSX registers only.
  1231. */
  1232. mfmsr r10
  1233. oris r10,r10,MSR_VSX@h
  1234. mtmsrd r10
  1235. sync
  1236. #define XVCPSGNDP2(n) XVCPSGNDP(n,n,n) ; XVCPSGNDP(n+1,n+1,n+1)
  1237. #define XVCPSGNDP4(n) XVCPSGNDP2(n) ; XVCPSGNDP2(n+2)
  1238. #define XVCPSGNDP8(n) XVCPSGNDP4(n) ; XVCPSGNDP4(n+4)
  1239. #define XVCPSGNDP16(n) XVCPSGNDP8(n) ; XVCPSGNDP8(n+8)
  1240. #define XVCPSGNDP32(n) XVCPSGNDP16(n) ; XVCPSGNDP16(n+16)
  1241. XVCPSGNDP32(0)
  1242. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_206)
  1243. BEGIN_FTR_SECTION
  1244. b denorm_done
  1245. END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
  1246. /*
  1247. * To denormalise we need to move a copy of the register to itself.
  1248. * For POWER8 we need to do that for all 64 VSX registers
  1249. */
  1250. XVCPSGNDP32(32)
  1251. denorm_done:
  1252. mfspr r11,SPRN_HSRR0
  1253. subi r11,r11,4
  1254. mtspr SPRN_HSRR0,r11
  1255. mtcrf 0x80,r9
  1256. ld r9,PACA_EXGEN+EX_R9(r13)
  1257. RESTORE_PPR_PACA(PACA_EXGEN, r10)
  1258. BEGIN_FTR_SECTION
  1259. ld r10,PACA_EXGEN+EX_CFAR(r13)
  1260. mtspr SPRN_CFAR,r10
  1261. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  1262. ld r10,PACA_EXGEN+EX_R10(r13)
  1263. ld r11,PACA_EXGEN+EX_R11(r13)
  1264. ld r12,PACA_EXGEN+EX_R12(r13)
  1265. ld r13,PACA_EXGEN+EX_R13(r13)
  1266. HRFI_TO_UNKNOWN
  1267. b .
  1268. #endif
  1269. EXC_COMMON(denorm_common, 0x1500, unknown_exception)
  1270. #ifdef CONFIG_CBE_RAS
  1271. EXC_REAL_HV(cbe_maintenance, 0x1600, 0x100)
  1272. EXC_VIRT_NONE(0x5600, 0x100)
  1273. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1600)
  1274. EXC_COMMON(cbe_maintenance_common, 0x1600, cbe_maintenance_exception)
  1275. #else /* CONFIG_CBE_RAS */
  1276. EXC_REAL_NONE(0x1600, 0x100)
  1277. EXC_VIRT_NONE(0x5600, 0x100)
  1278. #endif
  1279. EXC_REAL(altivec_assist, 0x1700, 0x100)
  1280. EXC_VIRT(altivec_assist, 0x5700, 0x100, 0x1700)
  1281. TRAMP_KVM(PACA_EXGEN, 0x1700)
  1282. #ifdef CONFIG_ALTIVEC
  1283. EXC_COMMON(altivec_assist_common, 0x1700, altivec_assist_exception)
  1284. #else
  1285. EXC_COMMON(altivec_assist_common, 0x1700, unknown_exception)
  1286. #endif
  1287. #ifdef CONFIG_CBE_RAS
  1288. EXC_REAL_HV(cbe_thermal, 0x1800, 0x100)
  1289. EXC_VIRT_NONE(0x5800, 0x100)
  1290. TRAMP_KVM_HV_SKIP(PACA_EXGEN, 0x1800)
  1291. EXC_COMMON(cbe_thermal_common, 0x1800, cbe_thermal_exception)
  1292. #else /* CONFIG_CBE_RAS */
  1293. EXC_REAL_NONE(0x1800, 0x100)
  1294. EXC_VIRT_NONE(0x5800, 0x100)
  1295. #endif
  1296. #ifdef CONFIG_PPC_WATCHDOG
  1297. #define MASKED_DEC_HANDLER_LABEL 3f
  1298. #define MASKED_DEC_HANDLER(_H) \
  1299. 3: /* soft-nmi */ \
  1300. std r12,PACA_EXGEN+EX_R12(r13); \
  1301. GET_SCRATCH0(r10); \
  1302. std r10,PACA_EXGEN+EX_R13(r13); \
  1303. EXCEPTION_PROLOG_2(soft_nmi_common, _H)
  1304. /*
  1305. * Branch to soft_nmi_interrupt using the emergency stack. The emergency
  1306. * stack is one that is usable by maskable interrupts so long as MSR_EE
  1307. * remains off. It is used for recovery when something has corrupted the
  1308. * normal kernel stack, for example. The "soft NMI" must not use the process
  1309. * stack because we want irq disabled sections to avoid touching the stack
  1310. * at all (other than PMU interrupts), so use the emergency stack for this,
  1311. * and run it entirely with interrupts hard disabled.
  1312. */
  1313. EXC_COMMON_BEGIN(soft_nmi_common)
  1314. mr r10,r1
  1315. ld r1,PACAEMERGSP(r13)
  1316. subi r1,r1,INT_FRAME_SIZE
  1317. EXCEPTION_COMMON_NORET_STACK(PACA_EXGEN, 0x900,
  1318. system_reset, soft_nmi_interrupt,
  1319. ADD_NVGPRS;ADD_RECONCILE)
  1320. b ret_from_except
  1321. #else /* CONFIG_PPC_WATCHDOG */
  1322. #define MASKED_DEC_HANDLER_LABEL 2f /* normal return */
  1323. #define MASKED_DEC_HANDLER(_H)
  1324. #endif /* CONFIG_PPC_WATCHDOG */
  1325. /*
  1326. * An interrupt came in while soft-disabled. We set paca->irq_happened, then:
  1327. * - If it was a decrementer interrupt, we bump the dec to max and and return.
  1328. * - If it was a doorbell we return immediately since doorbells are edge
  1329. * triggered and won't automatically refire.
  1330. * - If it was a HMI we return immediately since we handled it in realmode
  1331. * and it won't refire.
  1332. * - Else it is one of PACA_IRQ_MUST_HARD_MASK, so hard disable and return.
  1333. * This is called with r10 containing the value to OR to the paca field.
  1334. */
  1335. #define MASKED_INTERRUPT(_H) \
  1336. masked_##_H##interrupt: \
  1337. std r11,PACA_EXGEN+EX_R11(r13); \
  1338. lbz r11,PACAIRQHAPPENED(r13); \
  1339. or r11,r11,r10; \
  1340. stb r11,PACAIRQHAPPENED(r13); \
  1341. cmpwi r10,PACA_IRQ_DEC; \
  1342. bne 1f; \
  1343. lis r10,0x7fff; \
  1344. ori r10,r10,0xffff; \
  1345. mtspr SPRN_DEC,r10; \
  1346. b MASKED_DEC_HANDLER_LABEL; \
  1347. 1: andi. r10,r10,PACA_IRQ_MUST_HARD_MASK; \
  1348. beq 2f; \
  1349. mfspr r10,SPRN_##_H##SRR1; \
  1350. xori r10,r10,MSR_EE; /* clear MSR_EE */ \
  1351. mtspr SPRN_##_H##SRR1,r10; \
  1352. ori r11,r11,PACA_IRQ_HARD_DIS; \
  1353. stb r11,PACAIRQHAPPENED(r13); \
  1354. 2: /* done */ \
  1355. mtcrf 0x80,r9; \
  1356. std r1,PACAR1(r13); \
  1357. ld r9,PACA_EXGEN+EX_R9(r13); \
  1358. ld r10,PACA_EXGEN+EX_R10(r13); \
  1359. ld r11,PACA_EXGEN+EX_R11(r13); \
  1360. /* returns to kernel where r13 must be set up, so don't restore it */ \
  1361. ##_H##RFI_TO_KERNEL; \
  1362. b .; \
  1363. MASKED_DEC_HANDLER(_H)
  1364. TRAMP_REAL_BEGIN(stf_barrier_fallback)
  1365. std r9,PACA_EXRFI+EX_R9(r13)
  1366. std r10,PACA_EXRFI+EX_R10(r13)
  1367. sync
  1368. ld r9,PACA_EXRFI+EX_R9(r13)
  1369. ld r10,PACA_EXRFI+EX_R10(r13)
  1370. ori 31,31,0
  1371. .rept 14
  1372. b 1f
  1373. 1:
  1374. .endr
  1375. blr
  1376. /* Clobbers r10, r11, ctr */
  1377. .macro L1D_DISPLACEMENT_FLUSH
  1378. ld r10,PACA_RFI_FLUSH_FALLBACK_AREA(r13)
  1379. ld r11,PACA_L1D_FLUSH_SIZE(r13)
  1380. srdi r11,r11,(7 + 3) /* 128 byte lines, unrolled 8x */
  1381. mtctr r11
  1382. DCBT_BOOK3S_STOP_ALL_STREAM_IDS(r11) /* Stop prefetch streams */
  1383. /* order ld/st prior to dcbt stop all streams with flushing */
  1384. sync
  1385. /*
  1386. * The load addresses are at staggered offsets within cachelines,
  1387. * which suits some pipelines better (on others it should not
  1388. * hurt).
  1389. */
  1390. 1:
  1391. ld r11,(0x80 + 8)*0(r10)
  1392. ld r11,(0x80 + 8)*1(r10)
  1393. ld r11,(0x80 + 8)*2(r10)
  1394. ld r11,(0x80 + 8)*3(r10)
  1395. ld r11,(0x80 + 8)*4(r10)
  1396. ld r11,(0x80 + 8)*5(r10)
  1397. ld r11,(0x80 + 8)*6(r10)
  1398. ld r11,(0x80 + 8)*7(r10)
  1399. addi r10,r10,0x80*8
  1400. bdnz 1b
  1401. .endm
  1402. TRAMP_REAL_BEGIN(entry_flush_fallback)
  1403. std r9,PACA_EXRFI+EX_R9(r13)
  1404. std r10,PACA_EXRFI+EX_R10(r13)
  1405. std r11,PACA_EXRFI+EX_R11(r13)
  1406. mfctr r9
  1407. L1D_DISPLACEMENT_FLUSH
  1408. mtctr r9
  1409. ld r9,PACA_EXRFI+EX_R9(r13)
  1410. ld r10,PACA_EXRFI+EX_R10(r13)
  1411. ld r11,PACA_EXRFI+EX_R11(r13)
  1412. blr
  1413. TRAMP_REAL_BEGIN(rfi_flush_fallback)
  1414. SET_SCRATCH0(r13);
  1415. GET_PACA(r13);
  1416. std r1,PACA_EXRFI+EX_R12(r13)
  1417. ld r1,PACAKSAVE(r13)
  1418. std r9,PACA_EXRFI+EX_R9(r13)
  1419. std r10,PACA_EXRFI+EX_R10(r13)
  1420. std r11,PACA_EXRFI+EX_R11(r13)
  1421. mfctr r9
  1422. L1D_DISPLACEMENT_FLUSH
  1423. mtctr r9
  1424. ld r9,PACA_EXRFI+EX_R9(r13)
  1425. ld r10,PACA_EXRFI+EX_R10(r13)
  1426. ld r11,PACA_EXRFI+EX_R11(r13)
  1427. ld r1,PACA_EXRFI+EX_R12(r13)
  1428. GET_SCRATCH0(r13);
  1429. rfid
  1430. TRAMP_REAL_BEGIN(hrfi_flush_fallback)
  1431. SET_SCRATCH0(r13);
  1432. GET_PACA(r13);
  1433. std r1,PACA_EXRFI+EX_R12(r13)
  1434. ld r1,PACAKSAVE(r13)
  1435. std r9,PACA_EXRFI+EX_R9(r13)
  1436. std r10,PACA_EXRFI+EX_R10(r13)
  1437. std r11,PACA_EXRFI+EX_R11(r13)
  1438. mfctr r9
  1439. L1D_DISPLACEMENT_FLUSH
  1440. mtctr r9
  1441. ld r9,PACA_EXRFI+EX_R9(r13)
  1442. ld r10,PACA_EXRFI+EX_R10(r13)
  1443. ld r11,PACA_EXRFI+EX_R11(r13)
  1444. ld r1,PACA_EXRFI+EX_R12(r13)
  1445. GET_SCRATCH0(r13);
  1446. hrfid
  1447. USE_TEXT_SECTION()
  1448. _GLOBAL(do_uaccess_flush)
  1449. UACCESS_FLUSH_FIXUP_SECTION
  1450. nop
  1451. nop
  1452. nop
  1453. blr
  1454. L1D_DISPLACEMENT_FLUSH
  1455. blr
  1456. _ASM_NOKPROBE_SYMBOL(do_uaccess_flush)
  1457. EXPORT_SYMBOL(do_uaccess_flush)
  1458. /*
  1459. * Real mode exceptions actually use this too, but alternate
  1460. * instruction code patches (which end up in the common .text area)
  1461. * cannot reach these if they are put there.
  1462. */
  1463. USE_FIXED_SECTION(virt_trampolines)
  1464. MASKED_INTERRUPT()
  1465. MASKED_INTERRUPT(H)
  1466. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  1467. TRAMP_REAL_BEGIN(kvmppc_skip_interrupt)
  1468. /*
  1469. * Here all GPRs are unchanged from when the interrupt happened
  1470. * except for r13, which is saved in SPRG_SCRATCH0.
  1471. */
  1472. mfspr r13, SPRN_SRR0
  1473. addi r13, r13, 4
  1474. mtspr SPRN_SRR0, r13
  1475. GET_SCRATCH0(r13)
  1476. RFI_TO_KERNEL
  1477. b .
  1478. TRAMP_REAL_BEGIN(kvmppc_skip_Hinterrupt)
  1479. /*
  1480. * Here all GPRs are unchanged from when the interrupt happened
  1481. * except for r13, which is saved in SPRG_SCRATCH0.
  1482. */
  1483. mfspr r13, SPRN_HSRR0
  1484. addi r13, r13, 4
  1485. mtspr SPRN_HSRR0, r13
  1486. GET_SCRATCH0(r13)
  1487. HRFI_TO_KERNEL
  1488. b .
  1489. #endif
  1490. /*
  1491. * Ensure that any handlers that get invoked from the exception prologs
  1492. * above are below the first 64KB (0x10000) of the kernel image because
  1493. * the prologs assemble the addresses of these handlers using the
  1494. * LOAD_HANDLER macro, which uses an ori instruction.
  1495. */
  1496. /*** Common interrupt handlers ***/
  1497. /*
  1498. * Relocation-on interrupts: A subset of the interrupts can be delivered
  1499. * with IR=1/DR=1, if AIL==2 and MSR.HV won't be changed by delivering
  1500. * it. Addresses are the same as the original interrupt addresses, but
  1501. * offset by 0xc000000000004000.
  1502. * It's impossible to receive interrupts below 0x300 via this mechanism.
  1503. * KVM: None of these traps are from the guest ; anything that escalated
  1504. * to HV=1 from HV=0 is delivered via real mode handlers.
  1505. */
  1506. /*
  1507. * This uses the standard macro, since the original 0x300 vector
  1508. * only has extra guff for STAB-based processors -- which never
  1509. * come here.
  1510. */
  1511. EXC_COMMON_BEGIN(ppc64_runlatch_on_trampoline)
  1512. b __ppc64_runlatch_on
  1513. USE_FIXED_SECTION(virt_trampolines)
  1514. /*
  1515. * The __end_interrupts marker must be past the out-of-line (OOL)
  1516. * handlers, so that they are copied to real address 0x100 when running
  1517. * a relocatable kernel. This ensures they can be reached from the short
  1518. * trampoline handlers (like 0x4f00, 0x4f20, etc.) which branch
  1519. * directly, without using LOAD_HANDLER().
  1520. */
  1521. .align 7
  1522. .globl __end_interrupts
  1523. __end_interrupts:
  1524. DEFINE_FIXED_SYMBOL(__end_interrupts)
  1525. #ifdef CONFIG_PPC_970_NAP
  1526. EXC_COMMON_BEGIN(power4_fixup_nap)
  1527. andc r9,r9,r10
  1528. std r9,TI_LOCAL_FLAGS(r11)
  1529. ld r10,_LINK(r1) /* make idle task do the */
  1530. std r10,_NIP(r1) /* equivalent of a blr */
  1531. blr
  1532. #endif
  1533. CLOSE_FIXED_SECTION(real_vectors);
  1534. CLOSE_FIXED_SECTION(real_trampolines);
  1535. CLOSE_FIXED_SECTION(virt_vectors);
  1536. CLOSE_FIXED_SECTION(virt_trampolines);
  1537. USE_TEXT_SECTION()
  1538. /*
  1539. * Hash table stuff
  1540. */
  1541. .balign IFETCH_ALIGN_BYTES
  1542. do_hash_page:
  1543. #ifdef CONFIG_PPC_BOOK3S_64
  1544. lis r0,(DSISR_BAD_FAULT_64S | DSISR_DABRMATCH | DSISR_KEYFAULT)@h
  1545. ori r0,r0,DSISR_BAD_FAULT_64S@l
  1546. and. r0,r4,r0 /* weird error? */
  1547. bne- handle_page_fault /* if not, try to insert a HPTE */
  1548. CURRENT_THREAD_INFO(r11, r1)
  1549. lwz r0,TI_PREEMPT(r11) /* If we're in an "NMI" */
  1550. andis. r0,r0,NMI_MASK@h /* (i.e. an irq when soft-disabled) */
  1551. bne 77f /* then don't call hash_page now */
  1552. /*
  1553. * r3 contains the faulting address
  1554. * r4 msr
  1555. * r5 contains the trap number
  1556. * r6 contains dsisr
  1557. *
  1558. * at return r3 = 0 for success, 1 for page fault, negative for error
  1559. */
  1560. mr r4,r12
  1561. ld r6,_DSISR(r1)
  1562. bl __hash_page /* build HPTE if possible */
  1563. cmpdi r3,0 /* see if __hash_page succeeded */
  1564. /* Success */
  1565. beq fast_exc_return_irq /* Return from exception on success */
  1566. /* Error */
  1567. blt- 13f
  1568. /* Reload DSISR into r4 for the DABR check below */
  1569. ld r4,_DSISR(r1)
  1570. #endif /* CONFIG_PPC_BOOK3S_64 */
  1571. /* Here we have a page fault that hash_page can't handle. */
  1572. handle_page_fault:
  1573. 11: andis. r0,r4,DSISR_DABRMATCH@h
  1574. bne- handle_dabr_fault
  1575. ld r4,_DAR(r1)
  1576. ld r5,_DSISR(r1)
  1577. addi r3,r1,STACK_FRAME_OVERHEAD
  1578. bl do_page_fault
  1579. cmpdi r3,0
  1580. beq+ ret_from_except_lite
  1581. bl save_nvgprs
  1582. mr r5,r3
  1583. addi r3,r1,STACK_FRAME_OVERHEAD
  1584. lwz r4,_DAR(r1)
  1585. bl bad_page_fault
  1586. b ret_from_except
  1587. /* We have a data breakpoint exception - handle it */
  1588. handle_dabr_fault:
  1589. bl save_nvgprs
  1590. ld r4,_DAR(r1)
  1591. ld r5,_DSISR(r1)
  1592. addi r3,r1,STACK_FRAME_OVERHEAD
  1593. bl do_break
  1594. /*
  1595. * do_break() may have changed the NV GPRS while handling a breakpoint.
  1596. * If so, we need to restore them with their updated values. Don't use
  1597. * ret_from_except_lite here.
  1598. */
  1599. b ret_from_except
  1600. #ifdef CONFIG_PPC_BOOK3S_64
  1601. /* We have a page fault that hash_page could handle but HV refused
  1602. * the PTE insertion
  1603. */
  1604. 13: bl save_nvgprs
  1605. mr r5,r3
  1606. addi r3,r1,STACK_FRAME_OVERHEAD
  1607. ld r4,_DAR(r1)
  1608. bl low_hash_fault
  1609. b ret_from_except
  1610. #endif
  1611. /*
  1612. * We come here as a result of a DSI at a point where we don't want
  1613. * to call hash_page, such as when we are accessing memory (possibly
  1614. * user memory) inside a PMU interrupt that occurred while interrupts
  1615. * were soft-disabled. We want to invoke the exception handler for
  1616. * the access, or panic if there isn't a handler.
  1617. */
  1618. 77: bl save_nvgprs
  1619. mr r4,r3
  1620. addi r3,r1,STACK_FRAME_OVERHEAD
  1621. li r5,SIGSEGV
  1622. bl bad_page_fault
  1623. b ret_from_except
  1624. /*
  1625. * Here we have detected that the kernel stack pointer is bad.
  1626. * R9 contains the saved CR, r13 points to the paca,
  1627. * r10 contains the (bad) kernel stack pointer,
  1628. * r11 and r12 contain the saved SRR0 and SRR1.
  1629. * We switch to using an emergency stack, save the registers there,
  1630. * and call kernel_bad_stack(), which panics.
  1631. */
  1632. bad_stack:
  1633. ld r1,PACAEMERGSP(r13)
  1634. subi r1,r1,64+INT_FRAME_SIZE
  1635. std r9,_CCR(r1)
  1636. std r10,GPR1(r1)
  1637. std r11,_NIP(r1)
  1638. std r12,_MSR(r1)
  1639. mfspr r11,SPRN_DAR
  1640. mfspr r12,SPRN_DSISR
  1641. std r11,_DAR(r1)
  1642. std r12,_DSISR(r1)
  1643. mflr r10
  1644. mfctr r11
  1645. mfxer r12
  1646. std r10,_LINK(r1)
  1647. std r11,_CTR(r1)
  1648. std r12,_XER(r1)
  1649. SAVE_GPR(0,r1)
  1650. SAVE_GPR(2,r1)
  1651. ld r10,EX_R3(r3)
  1652. std r10,GPR3(r1)
  1653. SAVE_GPR(4,r1)
  1654. SAVE_4GPRS(5,r1)
  1655. ld r9,EX_R9(r3)
  1656. ld r10,EX_R10(r3)
  1657. SAVE_2GPRS(9,r1)
  1658. ld r9,EX_R11(r3)
  1659. ld r10,EX_R12(r3)
  1660. ld r11,EX_R13(r3)
  1661. std r9,GPR11(r1)
  1662. std r10,GPR12(r1)
  1663. std r11,GPR13(r1)
  1664. BEGIN_FTR_SECTION
  1665. ld r10,EX_CFAR(r3)
  1666. std r10,ORIG_GPR3(r1)
  1667. END_FTR_SECTION_IFSET(CPU_FTR_CFAR)
  1668. SAVE_8GPRS(14,r1)
  1669. SAVE_10GPRS(22,r1)
  1670. lhz r12,PACA_TRAP_SAVE(r13)
  1671. std r12,_TRAP(r1)
  1672. addi r11,r1,INT_FRAME_SIZE
  1673. std r11,0(r1)
  1674. li r12,0
  1675. std r12,0(r11)
  1676. ld r2,PACATOC(r13)
  1677. ld r11,exception_marker@toc(r2)
  1678. std r12,RESULT(r1)
  1679. std r11,STACK_FRAME_OVERHEAD-16(r1)
  1680. 1: addi r3,r1,STACK_FRAME_OVERHEAD
  1681. bl kernel_bad_stack
  1682. b 1b
  1683. _ASM_NOKPROBE_SYMBOL(bad_stack);
  1684. /*
  1685. * When doorbell is triggered from system reset wakeup, the message is
  1686. * not cleared, so it would fire again when EE is enabled.
  1687. *
  1688. * When coming from local_irq_enable, there may be the same problem if
  1689. * we were hard disabled.
  1690. *
  1691. * Execute msgclr to clear pending exceptions before handling it.
  1692. */
  1693. h_doorbell_common_msgclr:
  1694. LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
  1695. PPC_MSGCLR(3)
  1696. b h_doorbell_common
  1697. doorbell_super_common_msgclr:
  1698. LOAD_REG_IMMEDIATE(r3, PPC_DBELL_MSGTYPE << (63-36))
  1699. PPC_MSGCLRP(3)
  1700. b doorbell_super_common
  1701. /*
  1702. * Called from arch_local_irq_enable when an interrupt needs
  1703. * to be resent. r3 contains 0x500, 0x900, 0xa00 or 0xe80 to indicate
  1704. * which kind of interrupt. MSR:EE is already off. We generate a
  1705. * stackframe like if a real interrupt had happened.
  1706. *
  1707. * Note: While MSR:EE is off, we need to make sure that _MSR
  1708. * in the generated frame has EE set to 1 or the exception
  1709. * handler will not properly re-enable them.
  1710. *
  1711. * Note that we don't specify LR as the NIP (return address) for
  1712. * the interrupt because that would unbalance the return branch
  1713. * predictor.
  1714. */
  1715. _GLOBAL(__replay_interrupt)
  1716. /* We are going to jump to the exception common code which
  1717. * will retrieve various register values from the PACA which
  1718. * we don't give a damn about, so we don't bother storing them.
  1719. */
  1720. mfmsr r12
  1721. LOAD_REG_ADDR(r11, replay_interrupt_return)
  1722. mfcr r9
  1723. ori r12,r12,MSR_EE
  1724. cmpwi r3,0x900
  1725. beq decrementer_common
  1726. cmpwi r3,0x500
  1727. BEGIN_FTR_SECTION
  1728. beq h_virt_irq_common
  1729. FTR_SECTION_ELSE
  1730. beq hardware_interrupt_common
  1731. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_300)
  1732. cmpwi r3,0xf00
  1733. beq performance_monitor_common
  1734. BEGIN_FTR_SECTION
  1735. cmpwi r3,0xa00
  1736. beq h_doorbell_common_msgclr
  1737. cmpwi r3,0xe60
  1738. beq hmi_exception_common
  1739. FTR_SECTION_ELSE
  1740. cmpwi r3,0xa00
  1741. beq doorbell_super_common_msgclr
  1742. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  1743. replay_interrupt_return:
  1744. blr
  1745. _ASM_NOKPROBE_SYMBOL(__replay_interrupt)