intvec_64.S 35 KB

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