intvec_64.S 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580
  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(r22, r22)
  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. #ifdef CONFIG_TRACE_IRQFLAGS
  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. .ifnc \function,handle_syscall
  714. { move r0, r30; move r1, r31 }
  715. { move r2, r32; move r3, r33 }
  716. .endif
  717. .endif
  718. #endif
  719. .endm
  720. /*
  721. * Redispatch a downcall.
  722. */
  723. .macro dc_dispatch vecnum, vecname
  724. .org (\vecnum << 8)
  725. intvec_\vecname:
  726. j _hv_downcall_dispatch
  727. ENDPROC(intvec_\vecname)
  728. .endm
  729. /*
  730. * Common code for most interrupts. The C function we're eventually
  731. * going to is in r0, and the faultnum is in r1; the original
  732. * values for those registers are on the stack.
  733. */
  734. .pushsection .text.handle_interrupt,"ax"
  735. handle_interrupt:
  736. finish_interrupt_save handle_interrupt
  737. /* Jump to the C routine; it should enable irqs as soon as possible. */
  738. {
  739. jalr r0
  740. PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
  741. }
  742. FEEDBACK_REENTER(handle_interrupt)
  743. {
  744. movei r30, 0 /* not an NMI */
  745. j interrupt_return
  746. }
  747. STD_ENDPROC(handle_interrupt)
  748. /*
  749. * This routine takes a boolean in r30 indicating if this is an NMI.
  750. * If so, we also expect a boolean in r31 indicating whether to
  751. * re-enable the oprofile interrupts.
  752. *
  753. * Note that .Lresume_userspace is jumped to directly in several
  754. * places, and we need to make sure r30 is set correctly in those
  755. * callers as well.
  756. */
  757. STD_ENTRY(interrupt_return)
  758. /* If we're resuming to kernel space, don't check thread flags. */
  759. {
  760. bnez r30, .Lrestore_all /* NMIs don't special-case user-space */
  761. PTREGS_PTR(r29, PTREGS_OFFSET_EX1)
  762. }
  763. ld r29, r29
  764. IS_KERNEL_EX1(r29, r29)
  765. {
  766. beqzt r29, .Lresume_userspace
  767. move r29, sp
  768. }
  769. #ifdef CONFIG_PREEMPT
  770. /* Returning to kernel space. Check if we need preemption. */
  771. EXTRACT_THREAD_INFO(r29)
  772. addli r28, r29, THREAD_INFO_FLAGS_OFFSET
  773. {
  774. ld r28, r28
  775. addli r29, r29, THREAD_INFO_PREEMPT_COUNT_OFFSET
  776. }
  777. {
  778. andi r28, r28, _TIF_NEED_RESCHED
  779. ld4s r29, r29
  780. }
  781. beqzt r28, 1f
  782. bnez r29, 1f
  783. /* Disable interrupts explicitly for preemption. */
  784. IRQ_DISABLE(r20,r21)
  785. TRACE_IRQS_OFF
  786. jal preempt_schedule_irq
  787. FEEDBACK_REENTER(interrupt_return)
  788. 1:
  789. #endif
  790. /* If we're resuming to _cpu_idle_nap, bump PC forward by 8. */
  791. {
  792. moveli r27, hw2_last(_cpu_idle_nap)
  793. PTREGS_PTR(r29, PTREGS_OFFSET_PC)
  794. }
  795. {
  796. ld r28, r29
  797. shl16insli r27, r27, hw1(_cpu_idle_nap)
  798. }
  799. {
  800. shl16insli r27, r27, hw0(_cpu_idle_nap)
  801. }
  802. {
  803. cmpeq r27, r27, r28
  804. }
  805. {
  806. blbc r27, .Lrestore_all
  807. addi r28, r28, 8
  808. }
  809. st r29, r28
  810. j .Lrestore_all
  811. .Lresume_userspace:
  812. FEEDBACK_REENTER(interrupt_return)
  813. /*
  814. * Use r33 to hold whether we have already loaded the callee-saves
  815. * into ptregs. We don't want to do it twice in this loop, since
  816. * then we'd clobber whatever changes are made by ptrace, etc.
  817. */
  818. {
  819. movei r33, 0
  820. move r32, sp
  821. }
  822. /* Get base of stack in r32. */
  823. EXTRACT_THREAD_INFO(r32)
  824. .Lretry_work_pending:
  825. /*
  826. * Disable interrupts so as to make sure we don't
  827. * miss an interrupt that sets any of the thread flags (like
  828. * need_resched or sigpending) between sampling and the iret.
  829. * Routines like schedule() or do_signal() may re-enable
  830. * interrupts before returning.
  831. */
  832. IRQ_DISABLE(r20, r21)
  833. TRACE_IRQS_OFF /* Note: clobbers registers r0-r29 */
  834. /* Check to see if there is any work to do before returning to user. */
  835. {
  836. addi r29, r32, THREAD_INFO_FLAGS_OFFSET
  837. moveli r1, hw1_last(_TIF_ALLWORK_MASK)
  838. }
  839. {
  840. ld r29, r29
  841. shl16insli r1, r1, hw0(_TIF_ALLWORK_MASK)
  842. }
  843. and r1, r29, r1
  844. beqzt r1, .Lrestore_all
  845. /*
  846. * Make sure we have all the registers saved for signal
  847. * handling or notify-resume. Call out to C code to figure out
  848. * exactly what we need to do for each flag bit, then if
  849. * necessary, reload the flags and recheck.
  850. */
  851. {
  852. PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
  853. bnez r33, 1f
  854. }
  855. push_extra_callee_saves r0
  856. movei r33, 1
  857. 1: jal do_work_pending
  858. bnez r0, .Lretry_work_pending
  859. /*
  860. * In the NMI case we
  861. * omit the call to single_process_check_nohz, which normally checks
  862. * to see if we should start or stop the scheduler tick, because
  863. * we can't call arbitrary Linux code from an NMI context.
  864. * We always call the homecache TLB deferral code to re-trigger
  865. * the deferral mechanism.
  866. *
  867. * The other chunk of responsibility this code has is to reset the
  868. * interrupt masks appropriately to reset irqs and NMIs. We have
  869. * to call TRACE_IRQS_OFF and TRACE_IRQS_ON to support all the
  870. * lockdep-type stuff, but we can't set ICS until afterwards, since
  871. * ICS can only be used in very tight chunks of code to avoid
  872. * tripping over various assertions that it is off.
  873. */
  874. .Lrestore_all:
  875. PTREGS_PTR(r0, PTREGS_OFFSET_EX1)
  876. {
  877. ld r0, r0
  878. PTREGS_PTR(r32, PTREGS_OFFSET_FLAGS)
  879. }
  880. {
  881. IS_KERNEL_EX1(r0, r0)
  882. ld r32, r32
  883. }
  884. bnez r0, 1f
  885. j 2f
  886. #if PT_FLAGS_DISABLE_IRQ != 1
  887. # error Assuming PT_FLAGS_DISABLE_IRQ == 1 so we can use blbct below
  888. #endif
  889. 1: blbct r32, 2f
  890. IRQ_DISABLE(r20,r21)
  891. TRACE_IRQS_OFF
  892. movei r0, 1
  893. mtspr INTERRUPT_CRITICAL_SECTION, r0
  894. beqzt r30, .Lrestore_regs
  895. j 3f
  896. 2: TRACE_IRQS_ON
  897. IRQ_ENABLE_LOAD(r20, r21)
  898. movei r0, 1
  899. mtspr INTERRUPT_CRITICAL_SECTION, r0
  900. IRQ_ENABLE_APPLY(r20, r21)
  901. beqzt r30, .Lrestore_regs
  902. 3:
  903. #if INT_PERF_COUNT + 1 != INT_AUX_PERF_COUNT
  904. # error Bad interrupt assumption
  905. #endif
  906. {
  907. movei r0, 3 /* two adjacent bits for the PERF_COUNT mask */
  908. beqz r31, .Lrestore_regs
  909. }
  910. shli r0, r0, INT_PERF_COUNT
  911. mtspr SPR_INTERRUPT_MASK_RESET_K, r0
  912. /*
  913. * We now commit to returning from this interrupt, since we will be
  914. * doing things like setting EX_CONTEXT SPRs and unwinding the stack
  915. * frame. No calls should be made to any other code after this point.
  916. * This code should only be entered with ICS set.
  917. * r32 must still be set to ptregs.flags.
  918. * We launch loads to each cache line separately first, so we can
  919. * get some parallelism out of the memory subsystem.
  920. * We start zeroing caller-saved registers throughout, since
  921. * that will save some cycles if this turns out to be a syscall.
  922. */
  923. .Lrestore_regs:
  924. /*
  925. * Rotate so we have one high bit and one low bit to test.
  926. * - low bit says whether to restore all the callee-saved registers,
  927. * or just r30-r33, and r52 up.
  928. * - high bit (i.e. sign bit) says whether to restore all the
  929. * caller-saved registers, or just r0.
  930. */
  931. #if PT_FLAGS_CALLER_SAVES != 2 || PT_FLAGS_RESTORE_REGS != 4
  932. # error Rotate trick does not work :-)
  933. #endif
  934. {
  935. rotli r20, r32, 62
  936. PTREGS_PTR(sp, PTREGS_OFFSET_REG(0))
  937. }
  938. /*
  939. * Load cache lines 0, 4, 6 and 7, in that order, then use
  940. * the last loaded value, which makes it likely that the other
  941. * cache lines have also loaded, at which point we should be
  942. * able to safely read all the remaining words on those cache
  943. * lines without waiting for the memory subsystem.
  944. */
  945. pop_reg r0, sp, PTREGS_OFFSET_REG(30) - PTREGS_OFFSET_REG(0)
  946. pop_reg r30, sp, PTREGS_OFFSET_REG(52) - PTREGS_OFFSET_REG(30)
  947. pop_reg_zero r52, r3, sp, PTREGS_OFFSET_CMPEXCH - PTREGS_OFFSET_REG(52)
  948. pop_reg_zero r21, r27, sp, PTREGS_OFFSET_EX1 - PTREGS_OFFSET_CMPEXCH
  949. pop_reg_zero lr, r2, sp, PTREGS_OFFSET_PC - PTREGS_OFFSET_EX1
  950. {
  951. mtspr CMPEXCH_VALUE, r21
  952. move r4, zero
  953. }
  954. pop_reg r21, sp, PTREGS_OFFSET_REG(31) - PTREGS_OFFSET_PC
  955. {
  956. mtspr SPR_EX_CONTEXT_K_1, lr
  957. IS_KERNEL_EX1(lr, lr)
  958. }
  959. {
  960. mtspr SPR_EX_CONTEXT_K_0, r21
  961. move r5, zero
  962. }
  963. /* Restore callee-saveds that we actually use. */
  964. pop_reg_zero r31, r6
  965. pop_reg_zero r32, r7
  966. pop_reg_zero r33, r8, sp, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(33)
  967. /*
  968. * If we modified other callee-saveds, restore them now.
  969. * This is rare, but could be via ptrace or signal handler.
  970. */
  971. {
  972. move r9, zero
  973. blbs r20, .Lrestore_callees
  974. }
  975. .Lcontinue_restore_regs:
  976. /* Check if we're returning from a syscall. */
  977. {
  978. move r10, zero
  979. bltzt r20, 1f /* no, so go restore callee-save registers */
  980. }
  981. /*
  982. * Check if we're returning to userspace.
  983. * Note that if we're not, we don't worry about zeroing everything.
  984. */
  985. {
  986. addli sp, sp, PTREGS_OFFSET_LR - PTREGS_OFFSET_REG(29)
  987. bnez lr, .Lkernel_return
  988. }
  989. /*
  990. * On return from syscall, we've restored r0 from pt_regs, but we
  991. * clear the remainder of the caller-saved registers. We could
  992. * restore the syscall arguments, but there's not much point,
  993. * and it ensures user programs aren't trying to use the
  994. * caller-saves if we clear them, as well as avoiding leaking
  995. * kernel pointers into userspace.
  996. */
  997. pop_reg_zero lr, r11, sp, PTREGS_OFFSET_TP - PTREGS_OFFSET_LR
  998. pop_reg_zero tp, r12, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_TP
  999. {
  1000. ld sp, sp
  1001. move r13, zero
  1002. move r14, zero
  1003. }
  1004. { move r15, zero; move r16, zero }
  1005. { move r17, zero; move r18, zero }
  1006. { move r19, zero; move r20, zero }
  1007. { move r21, zero; move r22, zero }
  1008. { move r23, zero; move r24, zero }
  1009. { move r25, zero; move r26, zero }
  1010. /* Set r1 to errno if we are returning an error, otherwise zero. */
  1011. {
  1012. moveli r29, 4096
  1013. sub r1, zero, r0
  1014. }
  1015. {
  1016. move r28, zero
  1017. cmpltu r29, r1, r29
  1018. }
  1019. {
  1020. mnz r1, r29, r1
  1021. move r29, zero
  1022. }
  1023. iret
  1024. /*
  1025. * Not a syscall, so restore caller-saved registers.
  1026. * First kick off loads for cache lines 1-3, which we're touching
  1027. * for the first time here.
  1028. */
  1029. .align 64
  1030. 1: pop_reg r29, sp, PTREGS_OFFSET_REG(21) - PTREGS_OFFSET_REG(29)
  1031. pop_reg r21, sp, PTREGS_OFFSET_REG(13) - PTREGS_OFFSET_REG(21)
  1032. pop_reg r13, sp, PTREGS_OFFSET_REG(1) - PTREGS_OFFSET_REG(13)
  1033. pop_reg r1
  1034. pop_reg r2
  1035. pop_reg r3
  1036. pop_reg r4
  1037. pop_reg r5
  1038. pop_reg r6
  1039. pop_reg r7
  1040. pop_reg r8
  1041. pop_reg r9
  1042. pop_reg r10
  1043. pop_reg r11
  1044. pop_reg r12, sp, 16
  1045. /* r13 already restored above */
  1046. pop_reg r14
  1047. pop_reg r15
  1048. pop_reg r16
  1049. pop_reg r17
  1050. pop_reg r18
  1051. pop_reg r19
  1052. pop_reg r20, sp, 16
  1053. /* r21 already restored above */
  1054. pop_reg r22
  1055. pop_reg r23
  1056. pop_reg r24
  1057. pop_reg r25
  1058. pop_reg r26
  1059. pop_reg r27
  1060. pop_reg r28, sp, PTREGS_OFFSET_LR - PTREGS_OFFSET_REG(28)
  1061. /* r29 already restored above */
  1062. bnez lr, .Lkernel_return
  1063. pop_reg lr, sp, PTREGS_OFFSET_TP - PTREGS_OFFSET_LR
  1064. pop_reg tp, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_TP
  1065. ld sp, sp
  1066. iret
  1067. /*
  1068. * We can't restore tp when in kernel mode, since a thread might
  1069. * have migrated from another cpu and brought a stale tp value.
  1070. */
  1071. .Lkernel_return:
  1072. pop_reg lr, sp, PTREGS_OFFSET_SP - PTREGS_OFFSET_LR
  1073. ld sp, sp
  1074. iret
  1075. /* Restore callee-saved registers from r34 to r51. */
  1076. .Lrestore_callees:
  1077. addli sp, sp, PTREGS_OFFSET_REG(34) - PTREGS_OFFSET_REG(29)
  1078. pop_reg r34
  1079. pop_reg r35
  1080. pop_reg r36
  1081. pop_reg r37
  1082. pop_reg r38
  1083. pop_reg r39
  1084. pop_reg r40
  1085. pop_reg r41
  1086. pop_reg r42
  1087. pop_reg r43
  1088. pop_reg r44
  1089. pop_reg r45
  1090. pop_reg r46
  1091. pop_reg r47
  1092. pop_reg r48
  1093. pop_reg r49
  1094. pop_reg r50
  1095. pop_reg r51, sp, PTREGS_OFFSET_REG(29) - PTREGS_OFFSET_REG(51)
  1096. j .Lcontinue_restore_regs
  1097. STD_ENDPROC(interrupt_return)
  1098. /*
  1099. * "NMI" interrupts mask ALL interrupts before calling the
  1100. * handler, and don't check thread flags, etc., on the way
  1101. * back out. In general, the only things we do here for NMIs
  1102. * are register save/restore and dataplane kernel-TLB management.
  1103. * We don't (for example) deal with start/stop of the sched tick.
  1104. */
  1105. .pushsection .text.handle_nmi,"ax"
  1106. handle_nmi:
  1107. finish_interrupt_save handle_nmi
  1108. {
  1109. jalr r0
  1110. PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
  1111. }
  1112. FEEDBACK_REENTER(handle_nmi)
  1113. {
  1114. movei r30, 1
  1115. cmpeq r31, r0, zero
  1116. }
  1117. j interrupt_return
  1118. STD_ENDPROC(handle_nmi)
  1119. /*
  1120. * Parallel code for syscalls to handle_interrupt.
  1121. */
  1122. .pushsection .text.handle_syscall,"ax"
  1123. handle_syscall:
  1124. finish_interrupt_save handle_syscall
  1125. /* Enable irqs. */
  1126. TRACE_IRQS_ON
  1127. IRQ_ENABLE(r20, r21)
  1128. /* Bump the counter for syscalls made on this tile. */
  1129. moveli r20, hw2_last(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
  1130. shl16insli r20, r20, hw1(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
  1131. shl16insli r20, r20, hw0(irq_stat + IRQ_CPUSTAT_SYSCALL_COUNT_OFFSET)
  1132. add r20, r20, tp
  1133. ld4s r21, r20
  1134. {
  1135. addi r21, r21, 1
  1136. move r31, sp
  1137. }
  1138. {
  1139. st4 r20, r21
  1140. EXTRACT_THREAD_INFO(r31)
  1141. }
  1142. /* Trace syscalls, if requested. */
  1143. addi r31, r31, THREAD_INFO_FLAGS_OFFSET
  1144. {
  1145. ld r30, r31
  1146. moveli r32, _TIF_SYSCALL_ENTRY_WORK
  1147. }
  1148. and r30, r30, r32
  1149. {
  1150. addi r30, r31, THREAD_INFO_STATUS_OFFSET - THREAD_INFO_FLAGS_OFFSET
  1151. beqzt r30, .Lrestore_syscall_regs
  1152. }
  1153. {
  1154. PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
  1155. jal do_syscall_trace_enter
  1156. }
  1157. FEEDBACK_REENTER(handle_syscall)
  1158. bltz r0, .Lsyscall_sigreturn_skip
  1159. /*
  1160. * We always reload our registers from the stack at this
  1161. * point. They might be valid, if we didn't build with
  1162. * TRACE_IRQFLAGS, and this isn't a dataplane tile, and we're not
  1163. * doing syscall tracing, but there are enough cases now that it
  1164. * seems simplest just to do the reload unconditionally.
  1165. */
  1166. .Lrestore_syscall_regs:
  1167. {
  1168. ld r30, r30
  1169. PTREGS_PTR(r11, PTREGS_OFFSET_REG(0))
  1170. }
  1171. pop_reg r0, r11
  1172. pop_reg r1, r11
  1173. pop_reg r2, r11
  1174. pop_reg r3, r11
  1175. pop_reg r4, r11
  1176. pop_reg r5, r11, PTREGS_OFFSET_SYSCALL - PTREGS_OFFSET_REG(5)
  1177. {
  1178. ld TREG_SYSCALL_NR_NAME, r11
  1179. moveli r21, __NR_syscalls
  1180. }
  1181. /* Ensure that the syscall number is within the legal range. */
  1182. {
  1183. moveli r20, hw2(sys_call_table)
  1184. #ifdef CONFIG_COMPAT
  1185. blbs r30, .Lcompat_syscall
  1186. #endif
  1187. }
  1188. {
  1189. cmpltu r21, TREG_SYSCALL_NR_NAME, r21
  1190. shl16insli r20, r20, hw1(sys_call_table)
  1191. }
  1192. {
  1193. blbc r21, .Linvalid_syscall
  1194. shl16insli r20, r20, hw0(sys_call_table)
  1195. }
  1196. .Lload_syscall_pointer:
  1197. shl3add r20, TREG_SYSCALL_NR_NAME, r20
  1198. ld r20, r20
  1199. /* Jump to syscall handler. */
  1200. jalr r20
  1201. .Lhandle_syscall_link: /* value of "lr" after "jalr r20" above */
  1202. /*
  1203. * Write our r0 onto the stack so it gets restored instead
  1204. * of whatever the user had there before.
  1205. * In compat mode, sign-extend r0 before storing it.
  1206. */
  1207. {
  1208. PTREGS_PTR(r29, PTREGS_OFFSET_REG(0))
  1209. blbct r30, 1f
  1210. }
  1211. addxi r0, r0, 0
  1212. 1: st r29, r0
  1213. .Lsyscall_sigreturn_skip:
  1214. FEEDBACK_REENTER(handle_syscall)
  1215. /* Do syscall trace again, if requested. */
  1216. {
  1217. ld r30, r31
  1218. moveli r32, _TIF_SYSCALL_EXIT_WORK
  1219. }
  1220. and r0, r30, r32
  1221. {
  1222. andi r0, r30, _TIF_SINGLESTEP
  1223. beqzt r0, 1f
  1224. }
  1225. {
  1226. PTREGS_PTR(r0, PTREGS_OFFSET_BASE)
  1227. jal do_syscall_trace_exit
  1228. }
  1229. FEEDBACK_REENTER(handle_syscall)
  1230. andi r0, r30, _TIF_SINGLESTEP
  1231. 1: beqzt r0, 2f
  1232. /* Single stepping -- notify ptrace. */
  1233. {
  1234. movei r0, SIGTRAP
  1235. jal ptrace_notify
  1236. }
  1237. FEEDBACK_REENTER(handle_syscall)
  1238. 2: {
  1239. movei r30, 0 /* not an NMI */
  1240. j .Lresume_userspace /* jump into middle of interrupt_return */
  1241. }
  1242. #ifdef CONFIG_COMPAT
  1243. .Lcompat_syscall:
  1244. /*
  1245. * Load the base of the compat syscall table in r20, and
  1246. * range-check the syscall number (duplicated from 64-bit path).
  1247. * Sign-extend all the user's passed arguments to make them consistent.
  1248. * Also save the original "r(n)" values away in "r(11+n)" in
  1249. * case the syscall table entry wants to validate them.
  1250. */
  1251. moveli r20, hw2(compat_sys_call_table)
  1252. {
  1253. cmpltu r21, TREG_SYSCALL_NR_NAME, r21
  1254. shl16insli r20, r20, hw1(compat_sys_call_table)
  1255. }
  1256. {
  1257. blbc r21, .Linvalid_syscall
  1258. shl16insli r20, r20, hw0(compat_sys_call_table)
  1259. }
  1260. { move r11, r0; addxi r0, r0, 0 }
  1261. { move r12, r1; addxi r1, r1, 0 }
  1262. { move r13, r2; addxi r2, r2, 0 }
  1263. { move r14, r3; addxi r3, r3, 0 }
  1264. { move r15, r4; addxi r4, r4, 0 }
  1265. { move r16, r5; addxi r5, r5, 0 }
  1266. j .Lload_syscall_pointer
  1267. #endif
  1268. .Linvalid_syscall:
  1269. /* Report an invalid syscall back to the user program */
  1270. {
  1271. PTREGS_PTR(r29, PTREGS_OFFSET_REG(0))
  1272. movei r28, -ENOSYS
  1273. }
  1274. st r29, r28
  1275. {
  1276. movei r30, 0 /* not an NMI */
  1277. j .Lresume_userspace /* jump into middle of interrupt_return */
  1278. }
  1279. STD_ENDPROC(handle_syscall)
  1280. /* Return the address for oprofile to suppress in backtraces. */
  1281. STD_ENTRY_SECTION(handle_syscall_link_address, .text.handle_syscall)
  1282. lnk r0
  1283. {
  1284. addli r0, r0, .Lhandle_syscall_link - .
  1285. jrp lr
  1286. }
  1287. STD_ENDPROC(handle_syscall_link_address)
  1288. STD_ENTRY(ret_from_fork)
  1289. jal sim_notify_fork
  1290. jal schedule_tail
  1291. FEEDBACK_REENTER(ret_from_fork)
  1292. {
  1293. movei r30, 0 /* not an NMI */
  1294. j .Lresume_userspace /* jump into middle of interrupt_return */
  1295. }
  1296. STD_ENDPROC(ret_from_fork)
  1297. STD_ENTRY(ret_from_kernel_thread)
  1298. jal sim_notify_fork
  1299. jal schedule_tail
  1300. FEEDBACK_REENTER(ret_from_fork)
  1301. {
  1302. move r0, r31
  1303. jalr r30
  1304. }
  1305. FEEDBACK_REENTER(ret_from_kernel_thread)
  1306. {
  1307. movei r30, 0 /* not an NMI */
  1308. j .Lresume_userspace /* jump into middle of interrupt_return */
  1309. }
  1310. STD_ENDPROC(ret_from_kernel_thread)
  1311. /* Various stub interrupt handlers and syscall handlers */
  1312. STD_ENTRY_LOCAL(_kernel_double_fault)
  1313. mfspr r1, SPR_EX_CONTEXT_K_0
  1314. move r2, lr
  1315. move r3, sp
  1316. move r4, r52
  1317. addi sp, sp, -C_ABI_SAVE_AREA_SIZE
  1318. j kernel_double_fault
  1319. STD_ENDPROC(_kernel_double_fault)
  1320. STD_ENTRY_LOCAL(bad_intr)
  1321. mfspr r2, SPR_EX_CONTEXT_K_0
  1322. panic "Unhandled interrupt %#x: PC %#lx"
  1323. STD_ENDPROC(bad_intr)
  1324. /*
  1325. * Special-case sigreturn to not write r0 to the stack on return.
  1326. * This is technically more efficient, but it also avoids difficulties
  1327. * in the 64-bit OS when handling 32-bit compat code, since we must not
  1328. * sign-extend r0 for the sigreturn return-value case.
  1329. */
  1330. #define PTREGS_SYSCALL_SIGRETURN(x, reg) \
  1331. STD_ENTRY(_##x); \
  1332. addli lr, lr, .Lsyscall_sigreturn_skip - .Lhandle_syscall_link; \
  1333. { \
  1334. PTREGS_PTR(reg, PTREGS_OFFSET_BASE); \
  1335. j x \
  1336. }; \
  1337. STD_ENDPROC(_##x)
  1338. PTREGS_SYSCALL_SIGRETURN(sys_rt_sigreturn, r0)
  1339. #ifdef CONFIG_COMPAT
  1340. PTREGS_SYSCALL_SIGRETURN(compat_sys_rt_sigreturn, r0)
  1341. #endif
  1342. /* Save additional callee-saves to pt_regs and jump to standard function. */
  1343. STD_ENTRY(_sys_clone)
  1344. push_extra_callee_saves r4
  1345. j sys_clone
  1346. STD_ENDPROC(_sys_clone)
  1347. /*
  1348. * Recover r3, r2, r1 and r0 here saved by unalign fast vector.
  1349. * The vector area limit is 32 bundles, so we handle the reload here.
  1350. * r0, r1, r2 are in thread_info from low to high memory in order.
  1351. * r3 points to location the original r3 was saved.
  1352. * We put this code in the __HEAD section so it can be reached
  1353. * via a conditional branch from the fast path.
  1354. */
  1355. __HEAD
  1356. hand_unalign_slow:
  1357. andi sp, sp, ~1
  1358. hand_unalign_slow_badsp:
  1359. addi r3, r3, -(3 * 8)
  1360. ld_add r0, r3, 8
  1361. ld_add r1, r3, 8
  1362. ld r2, r3
  1363. hand_unalign_slow_nonuser:
  1364. mfspr r3, SPR_SYSTEM_SAVE_K_1
  1365. __int_hand INT_UNALIGN_DATA, UNALIGN_DATA_SLOW, int_unalign
  1366. /* The unaligned data support needs to read all the registers. */
  1367. int_unalign:
  1368. push_extra_callee_saves r0
  1369. j do_unaligned
  1370. ENDPROC(hand_unalign_slow)
  1371. /* Fill the return address stack with nonzero entries. */
  1372. STD_ENTRY(fill_ra_stack)
  1373. {
  1374. move r0, lr
  1375. jal 1f
  1376. }
  1377. 1: jal 2f
  1378. 2: jal 3f
  1379. 3: jal 4f
  1380. 4: jrp r0
  1381. STD_ENDPROC(fill_ra_stack)
  1382. .macro int_hand vecnum, vecname, c_routine, processing=handle_interrupt
  1383. .org (\vecnum << 8)
  1384. __int_hand \vecnum, \vecname, \c_routine, \processing
  1385. .endm
  1386. /* Include .intrpt array of interrupt vectors */
  1387. .section ".intrpt", "ax"
  1388. .global intrpt_start
  1389. intrpt_start:
  1390. #ifndef CONFIG_USE_PMC
  1391. #define handle_perf_interrupt bad_intr
  1392. #endif
  1393. #ifndef CONFIG_HARDWALL
  1394. #define do_hardwall_trap bad_intr
  1395. #endif
  1396. int_hand INT_MEM_ERROR, MEM_ERROR, do_trap
  1397. int_hand INT_SINGLE_STEP_3, SINGLE_STEP_3, bad_intr
  1398. #if CONFIG_KERNEL_PL == 2
  1399. int_hand INT_SINGLE_STEP_2, SINGLE_STEP_2, gx_singlestep_handle
  1400. int_hand INT_SINGLE_STEP_1, SINGLE_STEP_1, bad_intr
  1401. #else
  1402. int_hand INT_SINGLE_STEP_2, SINGLE_STEP_2, bad_intr
  1403. int_hand INT_SINGLE_STEP_1, SINGLE_STEP_1, gx_singlestep_handle
  1404. #endif
  1405. int_hand INT_SINGLE_STEP_0, SINGLE_STEP_0, bad_intr
  1406. int_hand INT_IDN_COMPLETE, IDN_COMPLETE, bad_intr
  1407. int_hand INT_UDN_COMPLETE, UDN_COMPLETE, bad_intr
  1408. int_hand INT_ITLB_MISS, ITLB_MISS, do_page_fault
  1409. int_hand INT_ILL, ILL, do_trap
  1410. int_hand INT_GPV, GPV, do_trap
  1411. int_hand INT_IDN_ACCESS, IDN_ACCESS, do_trap
  1412. int_hand INT_UDN_ACCESS, UDN_ACCESS, do_trap
  1413. int_hand INT_SWINT_3, SWINT_3, do_trap
  1414. int_hand INT_SWINT_2, SWINT_2, do_trap
  1415. int_hand INT_SWINT_1, SWINT_1, SYSCALL, handle_syscall
  1416. int_hand INT_SWINT_0, SWINT_0, do_trap
  1417. int_hand INT_ILL_TRANS, ILL_TRANS, do_trap
  1418. int_hand_unalign_fast INT_UNALIGN_DATA, UNALIGN_DATA
  1419. int_hand INT_DTLB_MISS, DTLB_MISS, do_page_fault
  1420. int_hand INT_DTLB_ACCESS, DTLB_ACCESS, do_page_fault
  1421. int_hand INT_IDN_FIREWALL, IDN_FIREWALL, do_hardwall_trap
  1422. int_hand INT_UDN_FIREWALL, UDN_FIREWALL, do_hardwall_trap
  1423. int_hand INT_TILE_TIMER, TILE_TIMER, do_timer_interrupt
  1424. int_hand INT_IDN_TIMER, IDN_TIMER, bad_intr
  1425. int_hand INT_UDN_TIMER, UDN_TIMER, bad_intr
  1426. int_hand INT_IDN_AVAIL, IDN_AVAIL, bad_intr
  1427. int_hand INT_UDN_AVAIL, UDN_AVAIL, bad_intr
  1428. int_hand INT_IPI_3, IPI_3, bad_intr
  1429. #if CONFIG_KERNEL_PL == 2
  1430. int_hand INT_IPI_2, IPI_2, tile_dev_intr
  1431. int_hand INT_IPI_1, IPI_1, bad_intr
  1432. #else
  1433. int_hand INT_IPI_2, IPI_2, bad_intr
  1434. int_hand INT_IPI_1, IPI_1, tile_dev_intr
  1435. #endif
  1436. int_hand INT_IPI_0, IPI_0, bad_intr
  1437. int_hand INT_PERF_COUNT, PERF_COUNT, \
  1438. handle_perf_interrupt, handle_nmi
  1439. int_hand INT_AUX_PERF_COUNT, AUX_PERF_COUNT, \
  1440. handle_perf_interrupt, handle_nmi
  1441. int_hand INT_INTCTRL_3, INTCTRL_3, bad_intr
  1442. #if CONFIG_KERNEL_PL == 2
  1443. dc_dispatch INT_INTCTRL_2, INTCTRL_2
  1444. int_hand INT_INTCTRL_1, INTCTRL_1, bad_intr
  1445. #else
  1446. int_hand INT_INTCTRL_2, INTCTRL_2, bad_intr
  1447. dc_dispatch INT_INTCTRL_1, INTCTRL_1
  1448. #endif
  1449. int_hand INT_INTCTRL_0, INTCTRL_0, bad_intr
  1450. int_hand INT_MESSAGE_RCV_DWNCL, MESSAGE_RCV_DWNCL, \
  1451. hv_message_intr
  1452. int_hand INT_DEV_INTR_DWNCL, DEV_INTR_DWNCL, bad_intr
  1453. int_hand INT_I_ASID, I_ASID, bad_intr
  1454. int_hand INT_D_ASID, D_ASID, bad_intr
  1455. int_hand INT_DOUBLE_FAULT, DOUBLE_FAULT, do_trap
  1456. /* Synthetic interrupt delivered only by the simulator */
  1457. int_hand INT_BREAKPOINT, BREAKPOINT, do_breakpoint
  1458. /* Synthetic interrupt delivered by hv */
  1459. int_hand INT_NMI_DWNCL, NMI_DWNCL, do_nmi, handle_nmi