intvec_64.S 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565
  1. /*
  2. * Copyright 2011 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. *
  14. * Linux interrupt vectors.
  15. */
  16. #include <linux/linkage.h>
  17. #include <linux/errno.h>
  18. #include <linux/unistd.h>
  19. #include <linux/init.h>
  20. #include <asm/ptrace.h>
  21. #include <asm/thread_info.h>
  22. #include <asm/irqflags.h>
  23. #include <asm/asm-offsets.h>
  24. #include <asm/types.h>
  25. #include <asm/traps.h>
  26. #include <asm/signal.h>
  27. #include <hv/hypervisor.h>
  28. #include <arch/abi.h>
  29. #include <arch/interrupts.h>
  30. #include <arch/spr_def.h>
  31. #define PTREGS_PTR(reg, ptreg) addli reg, sp, C_ABI_SAVE_AREA_SIZE + (ptreg)
  32. #define PTREGS_OFFSET_SYSCALL PTREGS_OFFSET_REG(TREG_SYSCALL_NR)
  33. #if CONFIG_KERNEL_PL == 1 || CONFIG_KERNEL_PL == 2
  34. /*
  35. * Set "result" non-zero if ex1 holds the PL of the kernel
  36. * (with or without ICS being set). Note this works only
  37. * because we never find the PL at level 3.
  38. */
  39. # define IS_KERNEL_EX1(result, ex1) andi result, ex1, CONFIG_KERNEL_PL
  40. #else
  41. # error Recode IS_KERNEL_EX1 for CONFIG_KERNEL_PL
  42. #endif
  43. .macro push_reg reg, ptr=sp, delta=-8
  44. {
  45. st \ptr, \reg
  46. addli \ptr, \ptr, \delta
  47. }
  48. .endm
  49. .macro pop_reg reg, ptr=sp, delta=8
  50. {
  51. ld \reg, \ptr
  52. addli \ptr, \ptr, \delta
  53. }
  54. .endm
  55. .macro pop_reg_zero reg, zreg, ptr=sp, delta=8
  56. {
  57. move \zreg, zero
  58. ld \reg, \ptr
  59. addi \ptr, \ptr, \delta
  60. }
  61. .endm
  62. .macro push_extra_callee_saves reg
  63. PTREGS_PTR(\reg, PTREGS_OFFSET_REG(51))
  64. push_reg r51, \reg
  65. push_reg r50, \reg
  66. push_reg r49, \reg
  67. push_reg r48, \reg
  68. push_reg r47, \reg
  69. push_reg r46, \reg
  70. push_reg r45, \reg
  71. push_reg r44, \reg
  72. push_reg r43, \reg
  73. push_reg r42, \reg
  74. push_reg r41, \reg
  75. push_reg r40, \reg
  76. push_reg r39, \reg
  77. push_reg r38, \reg
  78. push_reg r37, \reg
  79. push_reg r36, \reg
  80. push_reg r35, \reg
  81. push_reg r34, \reg, PTREGS_OFFSET_BASE - PTREGS_OFFSET_REG(34)
  82. .endm
  83. .macro panic str
  84. .pushsection .rodata, "a"
  85. 1:
  86. .asciz "\str"
  87. .popsection
  88. {
  89. moveli r0, hw2_last(1b)
  90. }
  91. {
  92. shl16insli r0, r0, hw1(1b)
  93. }
  94. {
  95. shl16insli r0, r0, hw0(1b)
  96. jal panic
  97. }
  98. .endm
  99. /*
  100. * Unalign data exception fast handling: In order to handle
  101. * unaligned data access, a fast JIT version is generated and stored
  102. * in a specific area in user space. We first need to do a quick poke
  103. * to see if the JIT is available. We use certain bits in the fault
  104. * PC (3 to 9 is used for 16KB page size) as index to address the JIT
  105. * code area. The first 64bit word is the fault PC, and the 2nd one is
  106. * the fault bundle itself. If these 2 words both match, then we
  107. * directly "iret" to JIT code. If not, a slow path is invoked to
  108. * generate new JIT code. Note: the current JIT code WILL be
  109. * overwritten if it existed. So, ideally we can handle 128 unalign
  110. * fixups via JIT. For lookup efficiency and to effectively support
  111. * tight loops with multiple unaligned reference, a simple
  112. * direct-mapped cache is used.
  113. *
  114. * SPR_EX_CONTEXT_K_0 is modified to return to JIT code.
  115. * SPR_EX_CONTEXT_K_1 has ICS set.
  116. * SPR_EX_CONTEXT_0_0 is setup to user program's next PC.
  117. * SPR_EX_CONTEXT_0_1 = 0.
  118. */
  119. .macro int_hand_unalign_fast vecnum, vecname
  120. .org (\vecnum << 8)
  121. intvec_\vecname:
  122. /* Put r3 in SPR_SYSTEM_SAVE_K_1. */
  123. mtspr SPR_SYSTEM_SAVE_K_1, r3
  124. mfspr r3, SPR_EX_CONTEXT_K_1
  125. /*
  126. * Examine if exception comes from user without ICS set.
  127. * If not, just go directly to the slow path.
  128. */
  129. bnez r3, hand_unalign_slow_nonuser
  130. mfspr r3, SPR_SYSTEM_SAVE_K_0
  131. /* Get &thread_info->unalign_jit_tmp[0] in r3. */
  132. bfexts r3, r3, 0, CPU_SHIFT-1
  133. mm r3, zero, LOG2_THREAD_SIZE, 63
  134. addli r3, r3, THREAD_INFO_UNALIGN_JIT_TMP_OFFSET
  135. /*
  136. * Save r0, r1, r2 into thread_info array r3 points to
  137. * from low to high memory in order.
  138. */
  139. st_add r3, r0, 8
  140. st_add r3, r1, 8
  141. {
  142. st_add r3, r2, 8
  143. andi r2, sp, 7
  144. }
  145. /* Save stored r3 value so we can revert it on a page fault. */
  146. mfspr r1, SPR_SYSTEM_SAVE_K_1
  147. st r3, r1
  148. {
  149. /* Generate a SIGBUS if sp is not 8-byte aligned. */
  150. bnez r2, hand_unalign_slow_badsp
  151. }
  152. /*
  153. * Get the thread_info in r0; load r1 with pc. Set the low bit of sp
  154. * as an indicator to the page fault code in case we fault.
  155. */
  156. {
  157. ori sp, sp, 1
  158. mfspr r1, SPR_EX_CONTEXT_K_0
  159. }
  160. /* Add the jit_info offset in thread_info; extract r1 [3:9] into r2. */
  161. {
  162. addli r0, r3, THREAD_INFO_UNALIGN_JIT_BASE_OFFSET - \
  163. (THREAD_INFO_UNALIGN_JIT_TMP_OFFSET + (3 * 8))
  164. bfextu r2, r1, 3, (2 + PAGE_SHIFT - UNALIGN_JIT_SHIFT)
  165. }
  166. /* Load the jit_info; multiply r2 by 128. */
  167. {
  168. ld r0, r0
  169. shli r2, r2, UNALIGN_JIT_SHIFT
  170. }
  171. /*
  172. * If r0 is NULL, the JIT page is not mapped, so go to slow path;
  173. * add offset r2 to r0 at the same time.
  174. */
  175. {
  176. beqz r0, hand_unalign_slow
  177. add r2, r0, r2
  178. }
  179. /*
  180. * We are loading from userspace (both the JIT info PC and
  181. * instruction word, and the instruction word we executed)
  182. * and since either could fault while holding the interrupt
  183. * critical section, we must tag this region and check it in
  184. * do_page_fault() to handle it properly.
  185. */
  186. ENTRY(__start_unalign_asm_code)
  187. /* Load first word of JIT in r0 and increment r2 by 8. */
  188. ld_add r0, r2, 8
  189. /*
  190. * Compare the PC with the 1st word in JIT; load the fault bundle
  191. * into r1.
  192. */
  193. {
  194. cmpeq r0, r0, r1
  195. ld r1, r1
  196. }
  197. /* Go to slow path if PC doesn't match. */
  198. beqz r0, hand_unalign_slow
  199. /*
  200. * Load the 2nd word of JIT, which is supposed to be the fault
  201. * bundle for a cache hit. Increment r2; after this bundle r2 will
  202. * point to the potential start of the JIT code we want to run.
  203. */
  204. ld_add r0, r2, 8
  205. /* No further accesses to userspace are done after this point. */
  206. ENTRY(__end_unalign_asm_code)
  207. /* Compare the real bundle with what is saved in the JIT area. */
  208. {
  209. cmpeq r0, r1, r0
  210. mtspr SPR_EX_CONTEXT_0_1, zero
  211. }
  212. /* Go to slow path if the fault bundle does not match. */
  213. beqz r0, hand_unalign_slow
  214. /*
  215. * A cache hit is found.
  216. * r2 points to start of JIT code (3rd word).
  217. * r0 is the fault pc.
  218. * r1 is the fault bundle.
  219. * Reset the low bit of sp.
  220. */
  221. {
  222. mfspr r0, SPR_EX_CONTEXT_K_0
  223. andi sp, sp, ~1
  224. }
  225. /* Write r2 into EX_CONTEXT_K_0 and increment PC. */
  226. {
  227. mtspr SPR_EX_CONTEXT_K_0, r2
  228. addi r0, r0, 8
  229. }
  230. /*
  231. * Set ICS on kernel EX_CONTEXT_K_1 in order to "iret" to
  232. * user with ICS set. This way, if the JIT fixup causes another
  233. * unalign exception (which shouldn't be possible) the user
  234. * process will be terminated with SIGBUS. Also, our fixup will
  235. * run without interleaving with external interrupts.
  236. * Each fixup is at most 14 bundles, so it won't hold ICS for long.
  237. */
  238. {
  239. movei r1, PL_ICS_EX1(USER_PL, 1)
  240. mtspr SPR_EX_CONTEXT_0_0, r0
  241. }
  242. {
  243. mtspr SPR_EX_CONTEXT_K_1, r1
  244. addi r3, r3, -(3 * 8)
  245. }
  246. /* Restore r0..r3. */
  247. ld_add r0, r3, 8
  248. ld_add r1, r3, 8
  249. ld_add r2, r3, 8
  250. ld r3, r3
  251. iret
  252. ENDPROC(intvec_\vecname)
  253. .endm
  254. #ifdef __COLLECT_LINKER_FEEDBACK__
  255. .pushsection .text.intvec_feedback,"ax"
  256. intvec_feedback:
  257. .popsection
  258. #endif
  259. /*
  260. * Default interrupt handler.
  261. *
  262. * vecnum is where we'll put this code.
  263. * c_routine is the C routine we'll call.
  264. *
  265. * The C routine is passed two arguments:
  266. * - A pointer to the pt_regs state.
  267. * - The interrupt vector number.
  268. *
  269. * The "processing" argument specifies the code for processing
  270. * the interrupt. Defaults to "handle_interrupt".
  271. */
  272. .macro __int_hand vecnum, vecname, c_routine,processing=handle_interrupt
  273. intvec_\vecname:
  274. /* Temporarily save a register so we have somewhere to work. */
  275. mtspr SPR_SYSTEM_SAVE_K_1, r0
  276. mfspr r0, SPR_EX_CONTEXT_K_1
  277. /*
  278. * The unalign data fastpath code sets the low bit in sp to
  279. * force us to reset it here on fault.
  280. */
  281. {
  282. blbs sp, 2f
  283. IS_KERNEL_EX1(r0, r0)
  284. }
  285. .ifc \vecnum, INT_DOUBLE_FAULT
  286. /*
  287. * For double-faults from user-space, fall through to the normal
  288. * register save and stack setup path. Otherwise, it's the
  289. * hypervisor giving us one last chance to dump diagnostics, and we
  290. * branch to the kernel_double_fault routine to do so.
  291. */
  292. beqz r0, 1f
  293. j _kernel_double_fault
  294. 1:
  295. .else
  296. /*
  297. * If we're coming from user-space, then set sp to the top of
  298. * the kernel stack. Otherwise, assume sp is already valid.
  299. */
  300. {
  301. bnez r0, 0f
  302. move r0, sp
  303. }
  304. .endif
  305. .ifc \c_routine, do_page_fault
  306. /*
  307. * The page_fault handler may be downcalled directly by the
  308. * hypervisor even when Linux is running and has ICS set.
  309. *
  310. * In this case the contents of EX_CONTEXT_K_1 reflect the
  311. * previous fault and can't be relied on to choose whether or
  312. * not to reinitialize the stack pointer. So we add a test
  313. * to see whether SYSTEM_SAVE_K_2 has the high bit set,
  314. * and if so we don't reinitialize sp, since we must be coming
  315. * from Linux. (In fact the precise case is !(val & ~1),
  316. * but any Linux PC has to have the high bit set.)
  317. *
  318. * Note that the hypervisor *always* sets SYSTEM_SAVE_K_2 for
  319. * any path that turns into a downcall to one of our TLB handlers.
  320. *
  321. * FIXME: if we end up never using this path, perhaps we should
  322. * prevent the hypervisor from generating downcalls in this case.
  323. * The advantage of getting a downcall is we can panic in Linux.
  324. */
  325. mfspr r0, SPR_SYSTEM_SAVE_K_2
  326. {
  327. bltz r0, 0f /* high bit in S_S_1_2 is for a PC to use */
  328. move r0, sp
  329. }
  330. .endif
  331. 2:
  332. /*
  333. * SYSTEM_SAVE_K_0 holds the cpu number in the high bits, and
  334. * the current stack top in the lower bits. So we recover
  335. * our starting stack value by sign-extending the low bits, then
  336. * point sp at the top aligned address on the actual stack page.
  337. */
  338. mfspr r0, SPR_SYSTEM_SAVE_K_0
  339. bfexts r0, r0, 0, CPU_SHIFT-1
  340. 0:
  341. /*
  342. * Align the stack mod 64 so we can properly predict what
  343. * cache lines we need to write-hint to reduce memory fetch
  344. * latency as we enter the kernel. The layout of memory is
  345. * as follows, with cache line 0 at the lowest VA, and cache
  346. * line 8 just below the r0 value this "andi" computes.
  347. * Note that we never write to cache line 8, and we skip
  348. * cache lines 1-3 for syscalls.
  349. *
  350. * cache line 8: ptregs padding (two words)
  351. * cache line 7: sp, lr, pc, ex1, faultnum, orig_r0, flags, cmpexch
  352. * cache line 6: r46...r53 (tp)
  353. * cache line 5: r38...r45
  354. * cache line 4: r30...r37
  355. * cache line 3: r22...r29
  356. * cache line 2: r14...r21
  357. * cache line 1: r6...r13
  358. * cache line 0: 2 x frame, r0..r5
  359. */
  360. #if STACK_TOP_DELTA != 64
  361. #error STACK_TOP_DELTA must be 64 for assumptions here and in task_pt_regs()
  362. #endif
  363. andi r0, r0, -64
  364. /*
  365. * Push the first four registers on the stack, so that we can set
  366. * them to vector-unique values before we jump to the common code.
  367. *
  368. * Registers are pushed on the stack as a struct pt_regs,
  369. * with the sp initially just above the struct, and when we're
  370. * done, sp points to the base of the struct, minus
  371. * C_ABI_SAVE_AREA_SIZE, so we can directly jal to C code.
  372. *
  373. * This routine saves just the first four registers, plus the
  374. * stack context so we can do proper backtracing right away,
  375. * and defers to handle_interrupt to save the rest.
  376. * The backtracer needs pc, ex1, lr, sp, r52, and faultnum,
  377. * and needs sp set to its final location at the bottom of
  378. * the stack frame.
  379. */
  380. addli r0, r0, PTREGS_OFFSET_LR - (PTREGS_SIZE + KSTK_PTREGS_GAP)
  381. wh64 r0 /* cache line 7 */
  382. {
  383. st r0, lr
  384. addli r0, r0, PTREGS_OFFSET_SP - PTREGS_OFFSET_LR
  385. }
  386. {
  387. st r0, sp
  388. addli sp, r0, PTREGS_OFFSET_REG(52) - PTREGS_OFFSET_SP
  389. }
  390. wh64 sp /* cache line 6 */
  391. {
  392. st sp, r52
  393. addli sp, sp, PTREGS_OFFSET_REG(1) - PTREGS_OFFSET_REG(52)
  394. }
  395. wh64 sp /* cache line 0 */
  396. {
  397. st sp, r1
  398. addli sp, sp, PTREGS_OFFSET_REG(2) - PTREGS_OFFSET_REG(1)
  399. }
  400. {
  401. st sp, r2
  402. addli sp, sp, PTREGS_OFFSET_REG(3) - PTREGS_OFFSET_REG(2)
  403. }
  404. {
  405. st sp, r3
  406. addli sp, sp, PTREGS_OFFSET_PC - PTREGS_OFFSET_REG(3)
  407. }
  408. mfspr r0, SPR_EX_CONTEXT_K_0
  409. .ifc \processing,handle_syscall
  410. /*
  411. * Bump the saved PC by one bundle so that when we return, we won't
  412. * execute the same swint instruction again. We need to do this while
  413. * we're in the critical section.
  414. */
  415. addi r0, r0, 8
  416. .endif
  417. {
  418. st sp, r0
  419. addli sp, sp, PTREGS_OFFSET_EX1 - PTREGS_OFFSET_PC
  420. }
  421. mfspr r0, SPR_EX_CONTEXT_K_1
  422. {
  423. st sp, r0
  424. addi sp, sp, PTREGS_OFFSET_FAULTNUM - PTREGS_OFFSET_EX1
  425. /*
  426. * Use r0 for syscalls so it's a temporary; use r1 for interrupts
  427. * so that it gets passed through unchanged to the handler routine.
  428. * Note that the .if conditional confusingly spans bundles.
  429. */
  430. .ifc \processing,handle_syscall
  431. movei r0, \vecnum
  432. }
  433. {
  434. st sp, r0
  435. .else
  436. movei r1, \vecnum
  437. }
  438. {
  439. st sp, r1
  440. .endif
  441. addli sp, sp, PTREGS_OFFSET_REG(0) - PTREGS_OFFSET_FAULTNUM
  442. }
  443. mfspr r0, SPR_SYSTEM_SAVE_K_1 /* Original r0 */
  444. {
  445. st sp, r0
  446. addi sp, sp, -PTREGS_OFFSET_REG(0) - 8
  447. }
  448. {
  449. st sp, zero /* write zero into "Next SP" frame pointer */
  450. addi sp, sp, -8 /* leave SP pointing at bottom of frame */
  451. }
  452. .ifc \processing,handle_syscall
  453. j handle_syscall
  454. .else
  455. /* Capture per-interrupt SPR context to registers. */
  456. .ifc \c_routine, do_page_fault
  457. mfspr r2, SPR_SYSTEM_SAVE_K_3 /* address of page fault */
  458. mfspr r3, SPR_SYSTEM_SAVE_K_2 /* info about page fault */
  459. .else
  460. .ifc \vecnum, INT_ILL_TRANS
  461. mfspr r2, ILL_VA_PC
  462. .else
  463. .ifc \vecnum, INT_DOUBLE_FAULT
  464. mfspr r2, SPR_SYSTEM_SAVE_K_2 /* double fault info from HV */
  465. .else
  466. .ifc \c_routine, do_trap
  467. mfspr r2, GPV_REASON
  468. .else
  469. .ifc \c_routine, handle_perf_interrupt
  470. mfspr r2, PERF_COUNT_STS
  471. .else
  472. .ifc \c_routine, handle_perf_interrupt
  473. mfspr r2, AUX_PERF_COUNT_STS
  474. .endif
  475. .ifc \c_routine, do_nmi
  476. mfspr r2, SPR_SYSTEM_SAVE_K_2 /* nmi type */
  477. .else
  478. .endif
  479. .endif
  480. .endif
  481. .endif
  482. .endif
  483. .endif
  484. /* Put function pointer in r0 */
  485. moveli r0, hw2_last(\c_routine)
  486. shl16insli r0, r0, hw1(\c_routine)
  487. {
  488. shl16insli r0, r0, hw0(\c_routine)
  489. j \processing
  490. }
  491. .endif
  492. ENDPROC(intvec_\vecname)
  493. #ifdef __COLLECT_LINKER_FEEDBACK__
  494. .pushsection .text.intvec_feedback,"ax"
  495. .org (\vecnum << 5)
  496. FEEDBACK_ENTER_EXPLICIT(intvec_\vecname, .intrpt, 1 << 8)
  497. jrp lr
  498. .popsection
  499. #endif
  500. .endm
  501. /*
  502. * Save the rest of the registers that we didn't save in the actual
  503. * vector itself. We can't use r0-r10 inclusive here.
  504. */
  505. .macro finish_interrupt_save, function
  506. /* If it's a syscall, save a proper orig_r0, otherwise just zero. */
  507. PTREGS_PTR(r52, PTREGS_OFFSET_ORIG_R0)
  508. {
  509. .ifc \function,handle_syscall
  510. st r52, r0
  511. .else
  512. st r52, zero
  513. .endif
  514. PTREGS_PTR(r52, PTREGS_OFFSET_TP)
  515. }
  516. st r52, tp
  517. {
  518. mfspr tp, CMPEXCH_VALUE
  519. PTREGS_PTR(r52, PTREGS_OFFSET_CMPEXCH)
  520. }
  521. /*
  522. * For ordinary syscalls, we save neither caller- nor callee-
  523. * save registers, since the syscall invoker doesn't expect the
  524. * caller-saves to be saved, and the called kernel functions will
  525. * take care of saving the callee-saves for us.
  526. *
  527. * For interrupts we save just the caller-save registers. Saving
  528. * them is required (since the "caller" can't save them). Again,
  529. * the called kernel functions will restore the callee-save
  530. * registers for us appropriately.
  531. *
  532. * On return, we normally restore nothing special for syscalls,
  533. * and just the caller-save registers for interrupts.
  534. *
  535. * However, there are some important caveats to all this:
  536. *
  537. * - We always save a few callee-save registers to give us
  538. * some scratchpad registers to carry across function calls.
  539. *
  540. * - fork/vfork/etc require us to save all the callee-save
  541. * registers, which we do in PTREGS_SYSCALL_ALL_REGS, below.
  542. *
  543. * - We always save r0..r5 and r10 for syscalls, since we need
  544. * to reload them a bit later for the actual kernel call, and
  545. * since we might need them for -ERESTARTNOINTR, etc.
  546. *
  547. * - Before invoking a signal handler, we save the unsaved
  548. * callee-save registers so they are visible to the
  549. * signal handler or any ptracer.
  550. *
  551. * - If the unsaved callee-save registers are modified, we set
  552. * a bit in pt_regs so we know to reload them from pt_regs
  553. * and not just rely on the kernel function unwinding.
  554. * (Done for ptrace register writes and SA_SIGINFO handler.)
  555. */
  556. {
  557. st r52, tp
  558. PTREGS_PTR(r52, PTREGS_OFFSET_REG(33))
  559. }
  560. wh64 r52 /* cache line 4 */
  561. push_reg r33, r52
  562. push_reg r32, r52
  563. push_reg r31, r52
  564. .ifc \function,handle_syscall
  565. push_reg r30, r52, PTREGS_OFFSET_SYSCALL - PTREGS_OFFSET_REG(30)
  566. push_reg TREG_SYSCALL_NR_NAME, r52, \
  567. PTREGS_OFFSET_REG(5) - PTREGS_OFFSET_SYSCALL
  568. .else
  569. push_reg r30, r52, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(30)
  570. wh64 r52 /* cache line 3 */
  571. push_reg r29, r52
  572. push_reg r28, r52
  573. push_reg r27, r52
  574. push_reg r26, r52
  575. push_reg r25, r52
  576. push_reg r24, r52
  577. push_reg r23, r52
  578. push_reg r22, r52
  579. wh64 r52 /* cache line 2 */
  580. push_reg r21, r52
  581. push_reg r20, r52
  582. push_reg r19, r52
  583. push_reg r18, r52
  584. push_reg r17, r52
  585. push_reg r16, r52
  586. push_reg r15, r52
  587. push_reg r14, r52
  588. wh64 r52 /* cache line 1 */
  589. push_reg r13, r52
  590. push_reg r12, r52
  591. push_reg r11, r52
  592. push_reg r10, r52
  593. push_reg r9, r52
  594. push_reg r8, r52
  595. push_reg r7, r52
  596. push_reg r6, r52
  597. .endif
  598. push_reg r5, r52
  599. st r52, r4
  600. /*
  601. * If we will be returning to the kernel, we will need to
  602. * reset the interrupt masks to the state they had before.
  603. * Set DISABLE_IRQ in flags iff we came from kernel pl with
  604. * irqs disabled.
  605. */
  606. mfspr r32, SPR_EX_CONTEXT_K_1
  607. {
  608. IS_KERNEL_EX1(r32, r32)
  609. PTREGS_PTR(r21, PTREGS_OFFSET_FLAGS)
  610. }
  611. beqzt r32, 1f /* zero if from user space */
  612. IRQS_DISABLED(r32) /* zero if irqs enabled */
  613. #if PT_FLAGS_DISABLE_IRQ != 1
  614. # error Value of IRQS_DISABLED used to set PT_FLAGS_DISABLE_IRQ; fix
  615. #endif
  616. 1:
  617. .ifnc \function,handle_syscall
  618. /* Record the fact that we saved the caller-save registers above. */
  619. ori r32, r32, PT_FLAGS_CALLER_SAVES
  620. .endif
  621. st r21, r32
  622. /*
  623. * we've captured enough state to the stack (including in
  624. * particular our EX_CONTEXT state) that we can now release
  625. * the interrupt critical section and replace it with our
  626. * standard "interrupts disabled" mask value. This allows
  627. * synchronous interrupts (and profile interrupts) to punch
  628. * through from this point onwards.
  629. *
  630. * It's important that no code before this point touch memory
  631. * other than our own stack (to keep the invariant that this
  632. * is all that gets touched under ICS), and that no code after
  633. * this point reference any interrupt-specific SPR, in particular
  634. * the EX_CONTEXT_K_ values.
  635. */
  636. .ifc \function,handle_nmi
  637. IRQ_DISABLE_ALL(r20)
  638. .else
  639. IRQ_DISABLE(r20, r21)
  640. .endif
  641. mtspr INTERRUPT_CRITICAL_SECTION, zero
  642. /* Load tp with our per-cpu offset. */
  643. #ifdef CONFIG_SMP
  644. {
  645. mfspr r20, SPR_SYSTEM_SAVE_K_0
  646. moveli r21, hw2_last(__per_cpu_offset)
  647. }
  648. {
  649. shl16insli r21, r21, hw1(__per_cpu_offset)
  650. bfextu r20, r20, CPU_SHIFT, 63
  651. }
  652. shl16insli r21, r21, hw0(__per_cpu_offset)
  653. shl3add r20, r20, r21
  654. ld tp, r20
  655. #else
  656. move tp, zero
  657. #endif
  658. #ifdef __COLLECT_LINKER_FEEDBACK__
  659. /*
  660. * Notify the feedback routines that we were in the
  661. * appropriate fixed interrupt vector area. Note that we
  662. * still have ICS set at this point, so we can't invoke any
  663. * atomic operations or we will panic. The feedback
  664. * routines internally preserve r0..r10 and r30 up.
  665. */
  666. .ifnc \function,handle_syscall
  667. shli r20, r1, 5
  668. .else
  669. moveli r20, INT_SWINT_1 << 5
  670. .endif
  671. moveli r21, hw2_last(intvec_feedback)
  672. shl16insli r21, r21, hw1(intvec_feedback)
  673. shl16insli r21, r21, hw0(intvec_feedback)
  674. add r20, r20, r21
  675. jalr r20
  676. /* And now notify the feedback routines that we are here. */
  677. FEEDBACK_ENTER(\function)
  678. #endif
  679. /*
  680. * Prepare the first 256 stack bytes to be rapidly accessible
  681. * without having to fetch the background data.
  682. */
  683. addi r52, sp, -64
  684. {
  685. wh64 r52
  686. addi r52, r52, -64
  687. }
  688. {
  689. wh64 r52
  690. addi r52, r52, -64
  691. }
  692. {
  693. wh64 r52
  694. addi r52, r52, -64
  695. }
  696. wh64 r52
  697. #if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING)
  698. .ifnc \function,handle_nmi
  699. /*
  700. * We finally have enough state set up to notify the irq
  701. * tracing code that irqs were disabled on entry to the handler.
  702. * The TRACE_IRQS_OFF call clobbers registers r0-r29.
  703. * For syscalls, we already have the register state saved away
  704. * on the stack, so we don't bother to do any register saves here,
  705. * and later we pop the registers back off the kernel stack.
  706. * For interrupt handlers, save r0-r3 in callee-saved registers.
  707. */
  708. .ifnc \function,handle_syscall
  709. { move r30, r0; move r31, r1 }
  710. { move r32, r2; move r33, r3 }
  711. .endif
  712. TRACE_IRQS_OFF
  713. #ifdef CONFIG_CONTEXT_TRACKING
  714. jal context_tracking_user_exit
  715. #endif
  716. .ifnc \function,handle_syscall
  717. { move r0, r30; move r1, r31 }
  718. { move r2, r32; move r3, r33 }
  719. .endif
  720. .endif
  721. #endif
  722. .endm
  723. /*
  724. * Redispatch a downcall.
  725. */
  726. .macro dc_dispatch vecnum, vecname
  727. .org (\vecnum << 8)
  728. intvec_\vecname:
  729. j _hv_downcall_dispatch
  730. ENDPROC(intvec_\vecname)
  731. .endm
  732. /*
  733. * Common code for most interrupts. The C function we're eventually
  734. * going to is in r0, and the faultnum is in r1; the original
  735. * values for those registers are on the stack.
  736. */
  737. .pushsection .text.handle_interrupt,"ax"
  738. handle_interrupt:
  739. finish_interrupt_save handle_interrupt
  740. /* Jump to the C routine; it should enable irqs as soon as possible. */
  741. {
  742. jalr r0
  743. PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
  744. }
  745. FEEDBACK_REENTER(handle_interrupt)
  746. {
  747. movei r30, 0 /* not an NMI */
  748. j interrupt_return
  749. }
  750. STD_ENDPROC(handle_interrupt)
  751. /*
  752. * This routine takes a boolean in r30 indicating if this is an NMI.
  753. * If so, we also expect a boolean in r31 indicating whether to
  754. * re-enable the oprofile interrupts.
  755. *
  756. * Note that .Lresume_userspace is jumped to directly in several
  757. * places, and we need to make sure r30 is set correctly in those
  758. * callers as well.
  759. */
  760. STD_ENTRY(interrupt_return)
  761. /* If we're resuming to kernel space, don't check thread flags. */
  762. {
  763. bnez r30, .Lrestore_all /* NMIs don't special-case user-space */
  764. PTREGS_PTR(r29, PTREGS_OFFSET_EX1)
  765. }
  766. ld r29, r29
  767. IS_KERNEL_EX1(r29, r29)
  768. {
  769. beqzt r29, .Lresume_userspace
  770. move r29, sp
  771. }
  772. #ifdef CONFIG_PREEMPT
  773. /* Returning to kernel space. Check if we need preemption. */
  774. EXTRACT_THREAD_INFO(r29)
  775. addli r28, r29, THREAD_INFO_FLAGS_OFFSET
  776. {
  777. ld r28, r28
  778. addli r29, r29, THREAD_INFO_PREEMPT_COUNT_OFFSET
  779. }
  780. {
  781. andi r28, r28, _TIF_NEED_RESCHED
  782. ld4s r29, r29
  783. }
  784. beqzt r28, 1f
  785. bnez r29, 1f
  786. /* Disable interrupts explicitly for preemption. */
  787. IRQ_DISABLE(r20,r21)
  788. TRACE_IRQS_OFF
  789. jal preempt_schedule_irq
  790. FEEDBACK_REENTER(interrupt_return)
  791. 1:
  792. #endif
  793. /* If we're resuming to _cpu_idle_nap, bump PC forward by 8. */
  794. {
  795. moveli r27, hw2_last(_cpu_idle_nap)
  796. PTREGS_PTR(r29, PTREGS_OFFSET_PC)
  797. }
  798. {
  799. ld r28, r29
  800. shl16insli r27, r27, hw1(_cpu_idle_nap)
  801. }
  802. {
  803. shl16insli r27, r27, hw0(_cpu_idle_nap)
  804. }
  805. {
  806. cmpeq r27, r27, r28
  807. }
  808. {
  809. blbc r27, .Lrestore_all
  810. addi r28, r28, 8
  811. }
  812. st r29, r28
  813. j .Lrestore_all
  814. .Lresume_userspace:
  815. FEEDBACK_REENTER(interrupt_return)
  816. /*
  817. * Disable interrupts so as to make sure we don't
  818. * miss an interrupt that sets any of the thread flags (like
  819. * need_resched or sigpending) between sampling and the iret.
  820. * Routines like schedule() or do_signal() may re-enable
  821. * interrupts before returning.
  822. */
  823. IRQ_DISABLE(r20, r21)
  824. TRACE_IRQS_OFF /* Note: clobbers registers r0-r29 */
  825. /*
  826. * See if there are any work items (including single-shot items)
  827. * to do. If so, save the callee-save registers to pt_regs
  828. * and then dispatch to C code.
  829. */
  830. move r21, sp
  831. EXTRACT_THREAD_INFO(r21)
  832. {
  833. addi r22, r21, THREAD_INFO_FLAGS_OFFSET
  834. moveli r20, hw1_last(_TIF_ALLWORK_MASK)
  835. }
  836. {
  837. ld r22, r22
  838. shl16insli r20, r20, hw0(_TIF_ALLWORK_MASK)
  839. }
  840. and r1, r22, r20
  841. {
  842. PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
  843. beqzt r1, .Lrestore_all
  844. }
  845. push_extra_callee_saves r0
  846. jal prepare_exit_to_usermode
  847. /*
  848. * In the NMI case we
  849. * omit the call to single_process_check_nohz, which normally checks
  850. * to see if we should start or stop the scheduler tick, because
  851. * we can't call arbitrary Linux code from an NMI context.
  852. * We always call the homecache TLB deferral code to re-trigger
  853. * the deferral mechanism.
  854. *
  855. * The other chunk of responsibility this code has is to reset the
  856. * interrupt masks appropriately to reset irqs and NMIs. We have
  857. * to call TRACE_IRQS_OFF and TRACE_IRQS_ON to support all the
  858. * lockdep-type stuff, but we can't set ICS until afterwards, since
  859. * ICS can only be used in very tight chunks of code to avoid
  860. * tripping over various assertions that it is off.
  861. */
  862. .Lrestore_all:
  863. PTREGS_PTR(r0, PTREGS_OFFSET_EX1)
  864. {
  865. ld r0, r0
  866. PTREGS_PTR(r32, PTREGS_OFFSET_FLAGS)
  867. }
  868. {
  869. IS_KERNEL_EX1(r0, r0)
  870. ld r32, r32
  871. }
  872. bnez r0, 1f
  873. j 2f
  874. #if PT_FLAGS_DISABLE_IRQ != 1
  875. # error Assuming PT_FLAGS_DISABLE_IRQ == 1 so we can use blbct below
  876. #endif
  877. 1: blbct r32, 2f
  878. IRQ_DISABLE(r20,r21)
  879. TRACE_IRQS_OFF
  880. movei r0, 1
  881. mtspr INTERRUPT_CRITICAL_SECTION, r0
  882. beqzt r30, .Lrestore_regs
  883. j 3f
  884. 2: TRACE_IRQS_ON
  885. IRQ_ENABLE_LOAD(r20, r21)
  886. movei r0, 1
  887. mtspr INTERRUPT_CRITICAL_SECTION, r0
  888. IRQ_ENABLE_APPLY(r20, r21)
  889. beqzt r30, .Lrestore_regs
  890. 3:
  891. #if INT_PERF_COUNT + 1 != INT_AUX_PERF_COUNT
  892. # error Bad interrupt assumption
  893. #endif
  894. {
  895. movei r0, 3 /* two adjacent bits for the PERF_COUNT mask */
  896. beqz r31, .Lrestore_regs
  897. }
  898. shli r0, r0, INT_PERF_COUNT
  899. mtspr SPR_INTERRUPT_MASK_RESET_K, r0
  900. /*
  901. * We now commit to returning from this interrupt, since we will be
  902. * doing things like setting EX_CONTEXT SPRs and unwinding the stack
  903. * frame. No calls should be made to any other code after this point.
  904. * This code should only be entered with ICS set.
  905. * r32 must still be set to ptregs.flags.
  906. * We launch loads to each cache line separately first, so we can
  907. * get some parallelism out of the memory subsystem.
  908. * We start zeroing caller-saved registers throughout, since
  909. * that will save some cycles if this turns out to be a syscall.
  910. */
  911. .Lrestore_regs:
  912. /*
  913. * Rotate so we have one high bit and one low bit to test.
  914. * - low bit says whether to restore all the callee-saved registers,
  915. * or just r30-r33, and r52 up.
  916. * - high bit (i.e. sign bit) says whether to restore all the
  917. * caller-saved registers, or just r0.
  918. */
  919. #if PT_FLAGS_CALLER_SAVES != 2 || PT_FLAGS_RESTORE_REGS != 4
  920. # error Rotate trick does not work :-)
  921. #endif
  922. {
  923. rotli r20, r32, 62
  924. PTREGS_PTR(sp, PTREGS_OFFSET_REG(0))
  925. }
  926. /*
  927. * Load cache lines 0, 4, 6 and 7, in that order, then use
  928. * the last loaded value, which makes it likely that the other
  929. * cache lines have also loaded, at which point we should be
  930. * able to safely read all the remaining words on those cache
  931. * lines without waiting for the memory subsystem.
  932. */
  933. pop_reg r0, sp, PTREGS_OFFSET_REG(30) - PTREGS_OFFSET_REG(0)
  934. pop_reg r30, sp, PTREGS_OFFSET_REG(52) - PTREGS_OFFSET_REG(30)
  935. pop_reg_zero r52, r3, sp, PTREGS_OFFSET_CMPEXCH - PTREGS_OFFSET_REG(52)
  936. pop_reg_zero r21, r27, sp, PTREGS_OFFSET_EX1 - PTREGS_OFFSET_CMPEXCH
  937. pop_reg_zero lr, r2, sp, PTREGS_OFFSET_PC - PTREGS_OFFSET_EX1
  938. {
  939. mtspr CMPEXCH_VALUE, r21
  940. move r4, zero
  941. }
  942. pop_reg r21, sp, PTREGS_OFFSET_REG(31) - PTREGS_OFFSET_PC
  943. {
  944. mtspr SPR_EX_CONTEXT_K_1, lr
  945. IS_KERNEL_EX1(lr, lr)
  946. }
  947. {
  948. mtspr SPR_EX_CONTEXT_K_0, r21
  949. move r5, zero
  950. }
  951. /* Restore callee-saveds that we actually use. */
  952. pop_reg_zero r31, r6
  953. pop_reg_zero r32, r7
  954. pop_reg_zero r33, r8, sp, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(33)
  955. /*
  956. * If we modified other callee-saveds, restore them now.
  957. * This is rare, but could be via ptrace or signal handler.
  958. */
  959. {
  960. move r9, zero
  961. blbs r20, .Lrestore_callees
  962. }
  963. .Lcontinue_restore_regs:
  964. /* Check if we're returning from a syscall. */
  965. {
  966. move r10, zero
  967. bltzt r20, 1f /* no, so go restore callee-save registers */
  968. }
  969. /*
  970. * Check if we're returning to userspace.
  971. * Note that if we're not, we don't worry about zeroing everything.
  972. */
  973. {
  974. addli sp, sp, PTREGS_OFFSET_LR - PTREGS_OFFSET_REG(29)
  975. bnez lr, .Lkernel_return
  976. }
  977. /*
  978. * On return from syscall, we've restored r0 from pt_regs, but we
  979. * clear the remainder of the caller-saved registers. We could
  980. * restore the syscall arguments, but there's not much point,
  981. * and it ensures user programs aren't trying to use the
  982. * caller-saves if we clear them, as well as avoiding leaking
  983. * kernel pointers into userspace.
  984. */
  985. pop_reg_zero lr, r11, sp, PTREGS_OFFSET_TP - PTREGS_OFFSET_LR
  986. pop_reg_zero tp, r12, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_TP
  987. {
  988. ld sp, sp
  989. move r13, zero
  990. move r14, zero
  991. }
  992. { move r15, zero; move r16, zero }
  993. { move r17, zero; move r18, zero }
  994. { move r19, zero; move r20, zero }
  995. { move r21, zero; move r22, zero }
  996. { move r23, zero; move r24, zero }
  997. { move r25, zero; move r26, zero }
  998. /* Set r1 to errno if we are returning an error, otherwise zero. */
  999. {
  1000. moveli r29, 4096
  1001. sub r1, zero, r0
  1002. }
  1003. {
  1004. move r28, zero
  1005. cmpltu r29, r1, r29
  1006. }
  1007. {
  1008. mnz r1, r29, r1
  1009. move r29, zero
  1010. }
  1011. iret
  1012. /*
  1013. * Not a syscall, so restore caller-saved registers.
  1014. * First kick off loads for cache lines 1-3, which we're touching
  1015. * for the first time here.
  1016. */
  1017. .align 64
  1018. 1: pop_reg r29, sp, PTREGS_OFFSET_REG(21) - PTREGS_OFFSET_REG(29)
  1019. pop_reg r21, sp, PTREGS_OFFSET_REG(13) - PTREGS_OFFSET_REG(21)
  1020. pop_reg r13, sp, PTREGS_OFFSET_REG(1) - PTREGS_OFFSET_REG(13)
  1021. pop_reg r1
  1022. pop_reg r2
  1023. pop_reg r3
  1024. pop_reg r4
  1025. pop_reg r5
  1026. pop_reg r6
  1027. pop_reg r7
  1028. pop_reg r8
  1029. pop_reg r9
  1030. pop_reg r10
  1031. pop_reg r11
  1032. pop_reg r12, sp, 16
  1033. /* r13 already restored above */
  1034. pop_reg r14
  1035. pop_reg r15
  1036. pop_reg r16
  1037. pop_reg r17
  1038. pop_reg r18
  1039. pop_reg r19
  1040. pop_reg r20, sp, 16
  1041. /* r21 already restored above */
  1042. pop_reg r22
  1043. pop_reg r23
  1044. pop_reg r24
  1045. pop_reg r25
  1046. pop_reg r26
  1047. pop_reg r27
  1048. pop_reg r28, sp, PTREGS_OFFSET_LR - PTREGS_OFFSET_REG(28)
  1049. /* r29 already restored above */
  1050. bnez lr, .Lkernel_return
  1051. pop_reg lr, sp, PTREGS_OFFSET_TP - PTREGS_OFFSET_LR
  1052. pop_reg tp, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_TP
  1053. ld sp, sp
  1054. iret
  1055. /*
  1056. * We can't restore tp when in kernel mode, since a thread might
  1057. * have migrated from another cpu and brought a stale tp value.
  1058. */
  1059. .Lkernel_return:
  1060. pop_reg lr, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_LR
  1061. ld sp, sp
  1062. iret
  1063. /* Restore callee-saved registers from r34 to r51. */
  1064. .Lrestore_callees:
  1065. addli sp, sp, PTREGS_OFFSET_REG(34) - PTREGS_OFFSET_REG(29)
  1066. pop_reg r34
  1067. pop_reg r35
  1068. pop_reg r36
  1069. pop_reg r37
  1070. pop_reg r38
  1071. pop_reg r39
  1072. pop_reg r40
  1073. pop_reg r41
  1074. pop_reg r42
  1075. pop_reg r43
  1076. pop_reg r44
  1077. pop_reg r45
  1078. pop_reg r46
  1079. pop_reg r47
  1080. pop_reg r48
  1081. pop_reg r49
  1082. pop_reg r50
  1083. pop_reg r51, sp, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(51)
  1084. j .Lcontinue_restore_regs
  1085. STD_ENDPROC(interrupt_return)
  1086. /*
  1087. * "NMI" interrupts mask ALL interrupts before calling the
  1088. * handler, and don't check thread flags, etc., on the way
  1089. * back out. In general, the only things we do here for NMIs
  1090. * are register save/restore and dataplane kernel-TLB management.
  1091. * We don't (for example) deal with start/stop of the sched tick.
  1092. */
  1093. .pushsection .text.handle_nmi,"ax"
  1094. handle_nmi:
  1095. finish_interrupt_save handle_nmi
  1096. {
  1097. jalr r0
  1098. PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
  1099. }
  1100. FEEDBACK_REENTER(handle_nmi)
  1101. {
  1102. movei r30, 1
  1103. cmpeq r31, r0, zero
  1104. }
  1105. j interrupt_return
  1106. STD_ENDPROC(handle_nmi)
  1107. /*
  1108. * Parallel code for syscalls to handle_interrupt.
  1109. */
  1110. .pushsection .text.handle_syscall,"ax"
  1111. handle_syscall:
  1112. finish_interrupt_save handle_syscall
  1113. /* Enable irqs. */
  1114. TRACE_IRQS_ON
  1115. IRQ_ENABLE(r20, r21)
  1116. /* Bump the counter for syscalls made on this tile. */
  1117. moveli r20, hw2_last(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
  1118. shl16insli r20, r20, hw1(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
  1119. shl16insli r20, r20, hw0(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
  1120. add r20, r20, tp
  1121. ld4s r21, r20
  1122. {
  1123. addi r21, r21, 1
  1124. move r31, sp
  1125. }
  1126. {
  1127. st4 r20, r21
  1128. EXTRACT_THREAD_INFO(r31)
  1129. }
  1130. /* Trace syscalls, if requested. */
  1131. addi r31, r31, THREAD_INFO_FLAGS_OFFSET
  1132. {
  1133. ld r30, r31
  1134. moveli r32, _TIF_SYSCALL_ENTRY_WORK
  1135. }
  1136. and r30, r30, r32
  1137. {
  1138. addi r30, r31, THREAD_INFO_STATUS_OFFSET - THREAD_INFO_FLAGS_OFFSET
  1139. beqzt r30, .Lrestore_syscall_regs
  1140. }
  1141. {
  1142. PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
  1143. jal do_syscall_trace_enter
  1144. }
  1145. FEEDBACK_REENTER(handle_syscall)
  1146. bltz r0, .Lsyscall_sigreturn_skip
  1147. /*
  1148. * We always reload our registers from the stack at this
  1149. * point. They might be valid, if we didn't build with
  1150. * TRACE_IRQFLAGS, and this isn't a dataplane tile, and we're not
  1151. * doing syscall tracing, but there are enough cases now that it
  1152. * seems simplest just to do the reload unconditionally.
  1153. */
  1154. .Lrestore_syscall_regs:
  1155. {
  1156. ld r30, r30
  1157. PTREGS_PTR(r11, PTREGS_OFFSET_REG(0))
  1158. }
  1159. pop_reg r0, r11
  1160. pop_reg r1, r11
  1161. pop_reg r2, r11
  1162. pop_reg r3, r11
  1163. pop_reg r4, r11
  1164. pop_reg r5, r11, PTREGS_OFFSET_SYSCALL - PTREGS_OFFSET_REG(5)
  1165. {
  1166. ld TREG_SYSCALL_NR_NAME, r11
  1167. moveli r21, __NR_syscalls
  1168. }
  1169. /* Ensure that the syscall number is within the legal range. */
  1170. {
  1171. moveli r20, hw2(sys_call_table)
  1172. #ifdef CONFIG_COMPAT
  1173. blbs r30, .Lcompat_syscall
  1174. #endif
  1175. }
  1176. {
  1177. cmpltu r21, TREG_SYSCALL_NR_NAME, r21
  1178. shl16insli r20, r20, hw1(sys_call_table)
  1179. }
  1180. {
  1181. blbc r21, .Linvalid_syscall
  1182. shl16insli r20, r20, hw0(sys_call_table)
  1183. }
  1184. .Lload_syscall_pointer:
  1185. shl3add r20, TREG_SYSCALL_NR_NAME, r20
  1186. ld r20, r20
  1187. /* Jump to syscall handler. */
  1188. jalr r20
  1189. .Lhandle_syscall_link: /* value of "lr" after "jalr r20" above */
  1190. /*
  1191. * Write our r0 onto the stack so it gets restored instead
  1192. * of whatever the user had there before.
  1193. * In compat mode, sign-extend r0 before storing it.
  1194. */
  1195. {
  1196. PTREGS_PTR(r29, PTREGS_OFFSET_REG(0))
  1197. blbct r30, 1f
  1198. }
  1199. addxi r0, r0, 0
  1200. 1: st r29, r0
  1201. .Lsyscall_sigreturn_skip:
  1202. FEEDBACK_REENTER(handle_syscall)
  1203. /* Do syscall trace again, if requested. */
  1204. {
  1205. ld r30, r31
  1206. moveli r32, _TIF_SYSCALL_EXIT_WORK
  1207. }
  1208. and r0, r30, r32
  1209. {
  1210. andi r0, r30, _TIF_SINGLESTEP
  1211. beqzt r0, 1f
  1212. }
  1213. {
  1214. PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
  1215. jal do_syscall_trace_exit
  1216. }
  1217. FEEDBACK_REENTER(handle_syscall)
  1218. andi r0, r30, _TIF_SINGLESTEP
  1219. 1: beqzt r0, 2f
  1220. /* Single stepping -- notify ptrace. */
  1221. {
  1222. movei r0, SIGTRAP
  1223. jal ptrace_notify
  1224. }
  1225. FEEDBACK_REENTER(handle_syscall)
  1226. 2: {
  1227. movei r30, 0 /* not an NMI */
  1228. j .Lresume_userspace /* jump into middle of interrupt_return */
  1229. }
  1230. #ifdef CONFIG_COMPAT
  1231. .Lcompat_syscall:
  1232. /*
  1233. * Load the base of the compat syscall table in r20, and
  1234. * range-check the syscall number (duplicated from 64-bit path).
  1235. * Sign-extend all the user's passed arguments to make them consistent.
  1236. * Also save the original "r(n)" values away in "r(11+n)" in
  1237. * case the syscall table entry wants to validate them.
  1238. */
  1239. moveli r20, hw2(compat_sys_call_table)
  1240. {
  1241. cmpltu r21, TREG_SYSCALL_NR_NAME, r21
  1242. shl16insli r20, r20, hw1(compat_sys_call_table)
  1243. }
  1244. {
  1245. blbc r21, .Linvalid_syscall
  1246. shl16insli r20, r20, hw0(compat_sys_call_table)
  1247. }
  1248. { move r11, r0; addxi r0, r0, 0 }
  1249. { move r12, r1; addxi r1, r1, 0 }
  1250. { move r13, r2; addxi r2, r2, 0 }
  1251. { move r14, r3; addxi r3, r3, 0 }
  1252. { move r15, r4; addxi r4, r4, 0 }
  1253. { move r16, r5; addxi r5, r5, 0 }
  1254. j .Lload_syscall_pointer
  1255. #endif
  1256. .Linvalid_syscall:
  1257. /* Report an invalid syscall back to the user program */
  1258. {
  1259. PTREGS_PTR(r29, PTREGS_OFFSET_REG(0))
  1260. movei r28, -ENOSYS
  1261. }
  1262. st r29, r28
  1263. {
  1264. movei r30, 0 /* not an NMI */
  1265. j .Lresume_userspace /* jump into middle of interrupt_return */
  1266. }
  1267. STD_ENDPROC(handle_syscall)
  1268. /* Return the address for oprofile to suppress in backtraces. */
  1269. STD_ENTRY_SECTION(handle_syscall_link_address, .text.handle_syscall)
  1270. lnk r0
  1271. {
  1272. addli r0, r0, .Lhandle_syscall_link - .
  1273. jrp lr
  1274. }
  1275. STD_ENDPROC(handle_syscall_link_address)
  1276. STD_ENTRY(ret_from_fork)
  1277. jal sim_notify_fork
  1278. jal schedule_tail
  1279. FEEDBACK_REENTER(ret_from_fork)
  1280. {
  1281. movei r30, 0 /* not an NMI */
  1282. j .Lresume_userspace /* jump into middle of interrupt_return */
  1283. }
  1284. STD_ENDPROC(ret_from_fork)
  1285. STD_ENTRY(ret_from_kernel_thread)
  1286. jal sim_notify_fork
  1287. jal schedule_tail
  1288. FEEDBACK_REENTER(ret_from_fork)
  1289. {
  1290. move r0, r31
  1291. jalr r30
  1292. }
  1293. FEEDBACK_REENTER(ret_from_kernel_thread)
  1294. {
  1295. movei r30, 0 /* not an NMI */
  1296. j interrupt_return
  1297. }
  1298. STD_ENDPROC(ret_from_kernel_thread)
  1299. /* Various stub interrupt handlers and syscall handlers */
  1300. STD_ENTRY_LOCAL(_kernel_double_fault)
  1301. mfspr r1, SPR_EX_CONTEXT_K_0
  1302. move r2, lr
  1303. move r3, sp
  1304. move r4, r52
  1305. addi sp, sp, -C_ABI_SAVE_AREA_SIZE
  1306. j kernel_double_fault
  1307. STD_ENDPROC(_kernel_double_fault)
  1308. STD_ENTRY_LOCAL(bad_intr)
  1309. mfspr r2, SPR_EX_CONTEXT_K_0
  1310. panic "Unhandled interrupt %#x: PC %#lx"
  1311. STD_ENDPROC(bad_intr)
  1312. /*
  1313. * Special-case sigreturn to not write r0 to the stack on return.
  1314. * This is technically more efficient, but it also avoids difficulties
  1315. * in the 64-bit OS when handling 32-bit compat code, since we must not
  1316. * sign-extend r0 for the sigreturn return-value case.
  1317. */
  1318. #define PTREGS_SYSCALL_SIGRETURN(x, reg) \
  1319. STD_ENTRY(_##x); \
  1320. addli lr, lr, .Lsyscall_sigreturn_skip - .Lhandle_syscall_link; \
  1321. { \
  1322. PTREGS_PTR(reg, PTREGS_OFFSET_BASE); \
  1323. j x \
  1324. }; \
  1325. STD_ENDPROC(_##x)
  1326. PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0)
  1327. #ifdef CONFIG_COMPAT
  1328. PTREGS_SYSCALL_SIGRETURN(compat_sys_rt_sigreturn, r0)
  1329. #endif
  1330. /* Save additional callee-saves to pt_regs and jump to standard function. */
  1331. STD_ENTRY(_sys_clone)
  1332. push_extra_callee_saves r4
  1333. j sys_clone
  1334. STD_ENDPROC(_sys_clone)
  1335. /*
  1336. * Recover r3, r2, r1 and r0 here saved by unalign fast vector.
  1337. * The vector area limit is 32 bundles, so we handle the reload here.
  1338. * r0, r1, r2 are in thread_info from low to high memory in order.
  1339. * r3 points to location the original r3 was saved.
  1340. * We put this code in the __HEAD section so it can be reached
  1341. * via a conditional branch from the fast path.
  1342. */
  1343. __HEAD
  1344. hand_unalign_slow:
  1345. andi sp, sp, ~1
  1346. hand_unalign_slow_badsp:
  1347. addi r3, r3, -(3 * 8)
  1348. ld_add r0, r3, 8
  1349. ld_add r1, r3, 8
  1350. ld r2, r3
  1351. hand_unalign_slow_nonuser:
  1352. mfspr r3, SPR_SYSTEM_SAVE_K_1
  1353. __int_hand INT_UNALIGN_DATA, UNALIGN_DATA_SLOW, int_unalign
  1354. /* The unaligned data support needs to read all the registers. */
  1355. int_unalign:
  1356. push_extra_callee_saves r0
  1357. j do_unaligned
  1358. ENDPROC(hand_unalign_slow)
  1359. /* Fill the return address stack with nonzero entries. */
  1360. STD_ENTRY(fill_ra_stack)
  1361. {
  1362. move r0, lr
  1363. jal 1f
  1364. }
  1365. 1: jal 2f
  1366. 2: jal 3f
  1367. 3: jal 4f
  1368. 4: jrp r0
  1369. STD_ENDPROC(fill_ra_stack)
  1370. .macro int_hand vecnum, vecname, c_routine, processing=handle_interrupt
  1371. .org (\vecnum << 8)
  1372. __int_hand \vecnum, \vecname, \c_routine, \processing
  1373. .endm
  1374. /* Include .intrpt array of interrupt vectors */
  1375. .section ".intrpt", "ax"
  1376. .global intrpt_start
  1377. intrpt_start:
  1378. #ifndef CONFIG_USE_PMC
  1379. #define handle_perf_interrupt bad_intr
  1380. #endif
  1381. #ifndef CONFIG_HARDWALL
  1382. #define do_hardwall_trap bad_intr
  1383. #endif
  1384. int_hand INT_MEM_ERROR, MEM_ERROR, do_trap
  1385. int_hand INT_SINGLE_STEP_3, SINGLE_STEP_3, bad_intr
  1386. #if CONFIG_KERNEL_PL == 2
  1387. int_hand INT_SINGLE_STEP_2, SINGLE_STEP_2, gx_singlestep_handle
  1388. int_hand INT_SINGLE_STEP_1, SINGLE_STEP_1, bad_intr
  1389. #else
  1390. int_hand INT_SINGLE_STEP_2, SINGLE_STEP_2, bad_intr
  1391. int_hand INT_SINGLE_STEP_1, SINGLE_STEP_1, gx_singlestep_handle
  1392. #endif
  1393. int_hand INT_SINGLE_STEP_0, SINGLE_STEP_0, bad_intr
  1394. int_hand INT_IDN_COMPLETE, IDN_COMPLETE, bad_intr
  1395. int_hand INT_UDN_COMPLETE, UDN_COMPLETE, bad_intr
  1396. int_hand INT_ITLB_MISS, ITLB_MISS, do_page_fault
  1397. int_hand INT_ILL, ILL, do_trap
  1398. int_hand INT_GPV, GPV, do_trap
  1399. int_hand INT_IDN_ACCESS, IDN_ACCESS, do_trap
  1400. int_hand INT_UDN_ACCESS, UDN_ACCESS, do_trap
  1401. int_hand INT_SWINT_3, SWINT_3, do_trap
  1402. int_hand INT_SWINT_2, SWINT_2, do_trap
  1403. int_hand INT_SWINT_1, SWINT_1, SYSCALL, handle_syscall
  1404. int_hand INT_SWINT_0, SWINT_0, do_trap
  1405. int_hand INT_ILL_TRANS, ILL_TRANS, do_trap
  1406. int_hand_unalign_fast INT_UNALIGN_DATA, UNALIGN_DATA
  1407. int_hand INT_DTLB_MISS, DTLB_MISS, do_page_fault
  1408. int_hand INT_DTLB_ACCESS, DTLB_ACCESS, do_page_fault
  1409. int_hand INT_IDN_FIREWALL, IDN_FIREWALL, do_hardwall_trap
  1410. int_hand INT_UDN_FIREWALL, UDN_FIREWALL, do_hardwall_trap
  1411. int_hand INT_TILE_TIMER, TILE_TIMER, do_timer_interrupt
  1412. int_hand INT_IDN_TIMER, IDN_TIMER, bad_intr
  1413. int_hand INT_UDN_TIMER, UDN_TIMER, bad_intr
  1414. int_hand INT_IDN_AVAIL, IDN_AVAIL, bad_intr
  1415. int_hand INT_UDN_AVAIL, UDN_AVAIL, bad_intr
  1416. int_hand INT_IPI_3, IPI_3, bad_intr
  1417. #if CONFIG_KERNEL_PL == 2
  1418. int_hand INT_IPI_2, IPI_2, tile_dev_intr
  1419. int_hand INT_IPI_1, IPI_1, bad_intr
  1420. #else
  1421. int_hand INT_IPI_2, IPI_2, bad_intr
  1422. int_hand INT_IPI_1, IPI_1, tile_dev_intr
  1423. #endif
  1424. int_hand INT_IPI_0, IPI_0, bad_intr
  1425. int_hand INT_PERF_COUNT, PERF_COUNT, \
  1426. handle_perf_interrupt, handle_nmi
  1427. int_hand INT_AUX_PERF_COUNT, AUX_PERF_COUNT, \
  1428. handle_perf_interrupt, handle_nmi
  1429. int_hand INT_INTCTRL_3, INTCTRL_3, bad_intr
  1430. #if CONFIG_KERNEL_PL == 2
  1431. dc_dispatch INT_INTCTRL_2, INTCTRL_2
  1432. int_hand INT_INTCTRL_1, INTCTRL_1, bad_intr
  1433. #else
  1434. int_hand INT_INTCTRL_2, INTCTRL_2, bad_intr
  1435. dc_dispatch INT_INTCTRL_1, INTCTRL_1
  1436. #endif
  1437. int_hand INT_INTCTRL_0, INTCTRL_0, bad_intr
  1438. int_hand INT_MESSAGE_RCV_DWNCL, MESSAGE_RCV_DWNCL, \
  1439. hv_message_intr
  1440. int_hand INT_DEV_INTR_DWNCL, DEV_INTR_DWNCL, bad_intr
  1441. int_hand INT_I_ASID, I_ASID, bad_intr
  1442. int_hand INT_D_ASID, D_ASID, bad_intr
  1443. int_hand INT_DOUBLE_FAULT, DOUBLE_FAULT, do_trap
  1444. /* Synthetic interrupt delivered only by the simulator */
  1445. int_hand INT_BREAKPOINT, BREAKPOINT, do_breakpoint
  1446. /* Synthetic interrupt delivered by hv */
  1447. int_hand INT_NMI_DWNCL, NMI_DWNCL, do_nmi, handle_nmi