entry.S 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. /*
  2. * OpenRISC entry.S
  3. *
  4. * Linux architectural port borrowing liberally from similar works of
  5. * others. All original copyrights apply as per the original source
  6. * declaration.
  7. *
  8. * Modifications for the OpenRISC architecture:
  9. * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
  10. * Copyright (C) 2005 Gyorgy Jeney <nog@bsemi.com>
  11. * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License
  15. * as published by the Free Software Foundation; either version
  16. * 2 of the License, or (at your option) any later version.
  17. */
  18. #include <linux/linkage.h>
  19. #include <asm/processor.h>
  20. #include <asm/unistd.h>
  21. #include <asm/thread_info.h>
  22. #include <asm/errno.h>
  23. #include <asm/spr_defs.h>
  24. #include <asm/page.h>
  25. #include <asm/mmu.h>
  26. #include <asm/pgtable.h>
  27. #include <asm/asm-offsets.h>
  28. #define DISABLE_INTERRUPTS(t1,t2) \
  29. l.mfspr t2,r0,SPR_SR ;\
  30. l.movhi t1,hi(~(SPR_SR_IEE|SPR_SR_TEE)) ;\
  31. l.ori t1,t1,lo(~(SPR_SR_IEE|SPR_SR_TEE)) ;\
  32. l.and t2,t2,t1 ;\
  33. l.mtspr r0,t2,SPR_SR
  34. #define ENABLE_INTERRUPTS(t1) \
  35. l.mfspr t1,r0,SPR_SR ;\
  36. l.ori t1,t1,lo(SPR_SR_IEE|SPR_SR_TEE) ;\
  37. l.mtspr r0,t1,SPR_SR
  38. /* =========================================================[ macros ]=== */
  39. #ifdef CONFIG_TRACE_IRQFLAGS
  40. /*
  41. * Trace irq on/off creating a stack frame.
  42. */
  43. #define TRACE_IRQS_OP(trace_op) \
  44. l.sw -8(r1),r2 /* store frame pointer */ ;\
  45. l.sw -4(r1),r9 /* store return address */ ;\
  46. l.addi r2,r1,0 /* move sp to fp */ ;\
  47. l.jal trace_op ;\
  48. l.addi r1,r1,-8 ;\
  49. l.ori r1,r2,0 /* restore sp */ ;\
  50. l.lwz r9,-4(r1) /* restore return address */ ;\
  51. l.lwz r2,-8(r1) /* restore fp */ ;\
  52. /*
  53. * Trace irq on/off and save registers we need that would otherwise be
  54. * clobbered.
  55. */
  56. #define TRACE_IRQS_SAVE(t1,trace_op) \
  57. l.sw -12(r1),t1 /* save extra reg */ ;\
  58. l.sw -8(r1),r2 /* store frame pointer */ ;\
  59. l.sw -4(r1),r9 /* store return address */ ;\
  60. l.addi r2,r1,0 /* move sp to fp */ ;\
  61. l.jal trace_op ;\
  62. l.addi r1,r1,-12 ;\
  63. l.ori r1,r2,0 /* restore sp */ ;\
  64. l.lwz r9,-4(r1) /* restore return address */ ;\
  65. l.lwz r2,-8(r1) /* restore fp */ ;\
  66. l.lwz t1,-12(r1) /* restore extra reg */
  67. #define TRACE_IRQS_OFF TRACE_IRQS_OP(trace_hardirqs_off)
  68. #define TRACE_IRQS_ON TRACE_IRQS_OP(trace_hardirqs_on)
  69. #define TRACE_IRQS_ON_SYSCALL \
  70. TRACE_IRQS_SAVE(r10,trace_hardirqs_on) ;\
  71. l.lwz r3,PT_GPR3(r1) ;\
  72. l.lwz r4,PT_GPR4(r1) ;\
  73. l.lwz r5,PT_GPR5(r1) ;\
  74. l.lwz r6,PT_GPR6(r1) ;\
  75. l.lwz r7,PT_GPR7(r1) ;\
  76. l.lwz r8,PT_GPR8(r1) ;\
  77. l.lwz r11,PT_GPR11(r1)
  78. #define TRACE_IRQS_OFF_ENTRY \
  79. l.lwz r5,PT_SR(r1) ;\
  80. l.andi r3,r5,(SPR_SR_IEE|SPR_SR_TEE) ;\
  81. l.sfeq r5,r0 /* skip trace if irqs were already off */;\
  82. l.bf 1f ;\
  83. l.nop ;\
  84. TRACE_IRQS_SAVE(r4,trace_hardirqs_off) ;\
  85. 1:
  86. #else
  87. #define TRACE_IRQS_OFF
  88. #define TRACE_IRQS_ON
  89. #define TRACE_IRQS_OFF_ENTRY
  90. #define TRACE_IRQS_ON_SYSCALL
  91. #endif
  92. /*
  93. * We need to disable interrupts at beginning of RESTORE_ALL
  94. * since interrupt might come in after we've loaded EPC return address
  95. * and overwrite EPC with address somewhere in RESTORE_ALL
  96. * which is of course wrong!
  97. */
  98. #define RESTORE_ALL \
  99. DISABLE_INTERRUPTS(r3,r4) ;\
  100. l.lwz r3,PT_PC(r1) ;\
  101. l.mtspr r0,r3,SPR_EPCR_BASE ;\
  102. l.lwz r3,PT_SR(r1) ;\
  103. l.mtspr r0,r3,SPR_ESR_BASE ;\
  104. l.lwz r2,PT_GPR2(r1) ;\
  105. l.lwz r3,PT_GPR3(r1) ;\
  106. l.lwz r4,PT_GPR4(r1) ;\
  107. l.lwz r5,PT_GPR5(r1) ;\
  108. l.lwz r6,PT_GPR6(r1) ;\
  109. l.lwz r7,PT_GPR7(r1) ;\
  110. l.lwz r8,PT_GPR8(r1) ;\
  111. l.lwz r9,PT_GPR9(r1) ;\
  112. l.lwz r10,PT_GPR10(r1) ;\
  113. l.lwz r11,PT_GPR11(r1) ;\
  114. l.lwz r12,PT_GPR12(r1) ;\
  115. l.lwz r13,PT_GPR13(r1) ;\
  116. l.lwz r14,PT_GPR14(r1) ;\
  117. l.lwz r15,PT_GPR15(r1) ;\
  118. l.lwz r16,PT_GPR16(r1) ;\
  119. l.lwz r17,PT_GPR17(r1) ;\
  120. l.lwz r18,PT_GPR18(r1) ;\
  121. l.lwz r19,PT_GPR19(r1) ;\
  122. l.lwz r20,PT_GPR20(r1) ;\
  123. l.lwz r21,PT_GPR21(r1) ;\
  124. l.lwz r22,PT_GPR22(r1) ;\
  125. l.lwz r23,PT_GPR23(r1) ;\
  126. l.lwz r24,PT_GPR24(r1) ;\
  127. l.lwz r25,PT_GPR25(r1) ;\
  128. l.lwz r26,PT_GPR26(r1) ;\
  129. l.lwz r27,PT_GPR27(r1) ;\
  130. l.lwz r28,PT_GPR28(r1) ;\
  131. l.lwz r29,PT_GPR29(r1) ;\
  132. l.lwz r30,PT_GPR30(r1) ;\
  133. l.lwz r31,PT_GPR31(r1) ;\
  134. l.lwz r1,PT_SP(r1) ;\
  135. l.rfe
  136. #define EXCEPTION_ENTRY(handler) \
  137. .global handler ;\
  138. handler: ;\
  139. /* r1, EPCR, ESR a already saved */ ;\
  140. l.sw PT_GPR2(r1),r2 ;\
  141. l.sw PT_GPR3(r1),r3 ;\
  142. /* r4 already save */ ;\
  143. l.sw PT_GPR5(r1),r5 ;\
  144. l.sw PT_GPR6(r1),r6 ;\
  145. l.sw PT_GPR7(r1),r7 ;\
  146. l.sw PT_GPR8(r1),r8 ;\
  147. l.sw PT_GPR9(r1),r9 ;\
  148. /* r10 already saved */ ;\
  149. l.sw PT_GPR11(r1),r11 ;\
  150. /* r12 already saved */ ;\
  151. l.sw PT_GPR13(r1),r13 ;\
  152. l.sw PT_GPR14(r1),r14 ;\
  153. l.sw PT_GPR15(r1),r15 ;\
  154. l.sw PT_GPR16(r1),r16 ;\
  155. l.sw PT_GPR17(r1),r17 ;\
  156. l.sw PT_GPR18(r1),r18 ;\
  157. l.sw PT_GPR19(r1),r19 ;\
  158. l.sw PT_GPR20(r1),r20 ;\
  159. l.sw PT_GPR21(r1),r21 ;\
  160. l.sw PT_GPR22(r1),r22 ;\
  161. l.sw PT_GPR23(r1),r23 ;\
  162. l.sw PT_GPR24(r1),r24 ;\
  163. l.sw PT_GPR25(r1),r25 ;\
  164. l.sw PT_GPR26(r1),r26 ;\
  165. l.sw PT_GPR27(r1),r27 ;\
  166. l.sw PT_GPR28(r1),r28 ;\
  167. l.sw PT_GPR29(r1),r29 ;\
  168. /* r30 already save */ ;\
  169. /* l.sw PT_GPR30(r1),r30*/ ;\
  170. l.sw PT_GPR31(r1),r31 ;\
  171. TRACE_IRQS_OFF_ENTRY ;\
  172. /* Store -1 in orig_gpr11 for non-syscall exceptions */ ;\
  173. l.addi r30,r0,-1 ;\
  174. l.sw PT_ORIG_GPR11(r1),r30
  175. #define UNHANDLED_EXCEPTION(handler,vector) \
  176. .global handler ;\
  177. handler: ;\
  178. /* r1, EPCR, ESR already saved */ ;\
  179. l.sw PT_GPR2(r1),r2 ;\
  180. l.sw PT_GPR3(r1),r3 ;\
  181. l.sw PT_GPR5(r1),r5 ;\
  182. l.sw PT_GPR6(r1),r6 ;\
  183. l.sw PT_GPR7(r1),r7 ;\
  184. l.sw PT_GPR8(r1),r8 ;\
  185. l.sw PT_GPR9(r1),r9 ;\
  186. /* r10 already saved */ ;\
  187. l.sw PT_GPR11(r1),r11 ;\
  188. /* r12 already saved */ ;\
  189. l.sw PT_GPR13(r1),r13 ;\
  190. l.sw PT_GPR14(r1),r14 ;\
  191. l.sw PT_GPR15(r1),r15 ;\
  192. l.sw PT_GPR16(r1),r16 ;\
  193. l.sw PT_GPR17(r1),r17 ;\
  194. l.sw PT_GPR18(r1),r18 ;\
  195. l.sw PT_GPR19(r1),r19 ;\
  196. l.sw PT_GPR20(r1),r20 ;\
  197. l.sw PT_GPR21(r1),r21 ;\
  198. l.sw PT_GPR22(r1),r22 ;\
  199. l.sw PT_GPR23(r1),r23 ;\
  200. l.sw PT_GPR24(r1),r24 ;\
  201. l.sw PT_GPR25(r1),r25 ;\
  202. l.sw PT_GPR26(r1),r26 ;\
  203. l.sw PT_GPR27(r1),r27 ;\
  204. l.sw PT_GPR28(r1),r28 ;\
  205. l.sw PT_GPR29(r1),r29 ;\
  206. /* r31 already saved */ ;\
  207. l.sw PT_GPR30(r1),r30 ;\
  208. /* l.sw PT_GPR31(r1),r31 */ ;\
  209. /* Store -1 in orig_gpr11 for non-syscall exceptions */ ;\
  210. l.addi r30,r0,-1 ;\
  211. l.sw PT_ORIG_GPR11(r1),r30 ;\
  212. l.addi r3,r1,0 ;\
  213. /* r4 is exception EA */ ;\
  214. l.addi r5,r0,vector ;\
  215. l.jal unhandled_exception ;\
  216. l.nop ;\
  217. l.j _ret_from_exception ;\
  218. l.nop
  219. /* clobbers 'reg' */
  220. #define CLEAR_LWA_FLAG(reg) \
  221. l.movhi reg,hi(lwa_flag) ;\
  222. l.ori reg,reg,lo(lwa_flag) ;\
  223. l.sw 0(reg),r0
  224. /*
  225. * NOTE: one should never assume that SPR_EPC, SPR_ESR, SPR_EEAR
  226. * contain the same values as when exception we're handling
  227. * occured. in fact they never do. if you need them use
  228. * values saved on stack (for SPR_EPC, SPR_ESR) or content
  229. * of r4 (for SPR_EEAR). for details look at EXCEPTION_HANDLE()
  230. * in 'arch/openrisc/kernel/head.S'
  231. */
  232. /* =====================================================[ exceptions] === */
  233. /* ---[ 0x100: RESET exception ]----------------------------------------- */
  234. EXCEPTION_ENTRY(_tng_kernel_start)
  235. l.jal _start
  236. l.andi r0,r0,0
  237. /* ---[ 0x200: BUS exception ]------------------------------------------- */
  238. EXCEPTION_ENTRY(_bus_fault_handler)
  239. CLEAR_LWA_FLAG(r3)
  240. /* r4: EA of fault (set by EXCEPTION_HANDLE) */
  241. l.jal do_bus_fault
  242. l.addi r3,r1,0 /* pt_regs */
  243. l.j _ret_from_exception
  244. l.nop
  245. /* ---[ 0x300: Data Page Fault exception ]------------------------------- */
  246. EXCEPTION_ENTRY(_dtlb_miss_page_fault_handler)
  247. CLEAR_LWA_FLAG(r3)
  248. l.and r5,r5,r0
  249. l.j 1f
  250. l.nop
  251. EXCEPTION_ENTRY(_data_page_fault_handler)
  252. CLEAR_LWA_FLAG(r3)
  253. /* set up parameters for do_page_fault */
  254. l.ori r5,r0,0x300 // exception vector
  255. 1:
  256. l.addi r3,r1,0 // pt_regs
  257. /* r4 set be EXCEPTION_HANDLE */ // effective address of fault
  258. #ifdef CONFIG_OPENRISC_NO_SPR_SR_DSX
  259. l.lwz r6,PT_PC(r3) // address of an offending insn
  260. l.lwz r6,0(r6) // instruction that caused pf
  261. l.srli r6,r6,26 // check opcode for jump insn
  262. l.sfeqi r6,0 // l.j
  263. l.bf 8f
  264. l.sfeqi r6,1 // l.jal
  265. l.bf 8f
  266. l.sfeqi r6,3 // l.bnf
  267. l.bf 8f
  268. l.sfeqi r6,4 // l.bf
  269. l.bf 8f
  270. l.sfeqi r6,0x11 // l.jr
  271. l.bf 8f
  272. l.sfeqi r6,0x12 // l.jalr
  273. l.bf 8f
  274. l.nop
  275. l.j 9f
  276. l.nop
  277. 8: // offending insn is in delay slot
  278. l.lwz r6,PT_PC(r3) // address of an offending insn
  279. l.addi r6,r6,4
  280. l.lwz r6,0(r6) // instruction that caused pf
  281. l.srli r6,r6,26 // get opcode
  282. 9: // offending instruction opcode loaded in r6
  283. #else
  284. l.mfspr r6,r0,SPR_SR // SR
  285. l.andi r6,r6,SPR_SR_DSX // check for delay slot exception
  286. l.sfne r6,r0 // exception happened in delay slot
  287. l.bnf 7f
  288. l.lwz r6,PT_PC(r3) // address of an offending insn
  289. l.addi r6,r6,4 // offending insn is in delay slot
  290. 7:
  291. l.lwz r6,0(r6) // instruction that caused pf
  292. l.srli r6,r6,26 // check opcode for write access
  293. #endif
  294. l.sfgeui r6,0x33 // check opcode for write access
  295. l.bnf 1f
  296. l.sfleui r6,0x37
  297. l.bnf 1f
  298. l.ori r6,r0,0x1 // write access
  299. l.j 2f
  300. l.nop
  301. 1: l.ori r6,r0,0x0 // !write access
  302. 2:
  303. /* call fault.c handler in or32/mm/fault.c */
  304. l.jal do_page_fault
  305. l.nop
  306. l.j _ret_from_exception
  307. l.nop
  308. /* ---[ 0x400: Insn Page Fault exception ]------------------------------- */
  309. EXCEPTION_ENTRY(_itlb_miss_page_fault_handler)
  310. CLEAR_LWA_FLAG(r3)
  311. l.and r5,r5,r0
  312. l.j 1f
  313. l.nop
  314. EXCEPTION_ENTRY(_insn_page_fault_handler)
  315. CLEAR_LWA_FLAG(r3)
  316. /* set up parameters for do_page_fault */
  317. l.ori r5,r0,0x400 // exception vector
  318. 1:
  319. l.addi r3,r1,0 // pt_regs
  320. /* r4 set be EXCEPTION_HANDLE */ // effective address of fault
  321. l.ori r6,r0,0x0 // !write access
  322. /* call fault.c handler in or32/mm/fault.c */
  323. l.jal do_page_fault
  324. l.nop
  325. l.j _ret_from_exception
  326. l.nop
  327. /* ---[ 0x500: Timer exception ]----------------------------------------- */
  328. EXCEPTION_ENTRY(_timer_handler)
  329. CLEAR_LWA_FLAG(r3)
  330. l.jal timer_interrupt
  331. l.addi r3,r1,0 /* pt_regs */
  332. l.j _ret_from_intr
  333. l.nop
  334. /* ---[ 0x600: Alignment exception ]-------------------------------------- */
  335. EXCEPTION_ENTRY(_alignment_handler)
  336. CLEAR_LWA_FLAG(r3)
  337. /* r4: EA of fault (set by EXCEPTION_HANDLE) */
  338. l.jal do_unaligned_access
  339. l.addi r3,r1,0 /* pt_regs */
  340. l.j _ret_from_exception
  341. l.nop
  342. #if 0
  343. EXCEPTION_ENTRY(_alignment_handler)
  344. // l.mfspr r2,r0,SPR_EEAR_BASE /* Load the effective address */
  345. l.addi r2,r4,0
  346. // l.mfspr r5,r0,SPR_EPCR_BASE /* Load the insn address */
  347. l.lwz r5,PT_PC(r1)
  348. l.lwz r3,0(r5) /* Load insn */
  349. l.srli r4,r3,26 /* Shift left to get the insn opcode */
  350. l.sfeqi r4,0x00 /* Check if the load/store insn is in delay slot */
  351. l.bf jmp
  352. l.sfeqi r4,0x01
  353. l.bf jmp
  354. l.sfeqi r4,0x03
  355. l.bf jmp
  356. l.sfeqi r4,0x04
  357. l.bf jmp
  358. l.sfeqi r4,0x11
  359. l.bf jr
  360. l.sfeqi r4,0x12
  361. l.bf jr
  362. l.nop
  363. l.j 1f
  364. l.addi r5,r5,4 /* Increment PC to get return insn address */
  365. jmp:
  366. l.slli r4,r3,6 /* Get the signed extended jump length */
  367. l.srai r4,r4,4
  368. l.lwz r3,4(r5) /* Load the real load/store insn */
  369. l.add r5,r5,r4 /* Calculate jump target address */
  370. l.j 1f
  371. l.srli r4,r3,26 /* Shift left to get the insn opcode */
  372. jr:
  373. l.slli r4,r3,9 /* Shift to get the reg nb */
  374. l.andi r4,r4,0x7c
  375. l.lwz r3,4(r5) /* Load the real load/store insn */
  376. l.add r4,r4,r1 /* Load the jump register value from the stack */
  377. l.lwz r5,0(r4)
  378. l.srli r4,r3,26 /* Shift left to get the insn opcode */
  379. 1:
  380. // l.mtspr r0,r5,SPR_EPCR_BASE
  381. l.sw PT_PC(r1),r5
  382. l.sfeqi r4,0x26
  383. l.bf lhs
  384. l.sfeqi r4,0x25
  385. l.bf lhz
  386. l.sfeqi r4,0x22
  387. l.bf lws
  388. l.sfeqi r4,0x21
  389. l.bf lwz
  390. l.sfeqi r4,0x37
  391. l.bf sh
  392. l.sfeqi r4,0x35
  393. l.bf sw
  394. l.nop
  395. 1: l.j 1b /* I don't know what to do */
  396. l.nop
  397. lhs: l.lbs r5,0(r2)
  398. l.slli r5,r5,8
  399. l.lbz r6,1(r2)
  400. l.or r5,r5,r6
  401. l.srli r4,r3,19
  402. l.andi r4,r4,0x7c
  403. l.add r4,r4,r1
  404. l.j align_end
  405. l.sw 0(r4),r5
  406. lhz: l.lbz r5,0(r2)
  407. l.slli r5,r5,8
  408. l.lbz r6,1(r2)
  409. l.or r5,r5,r6
  410. l.srli r4,r3,19
  411. l.andi r4,r4,0x7c
  412. l.add r4,r4,r1
  413. l.j align_end
  414. l.sw 0(r4),r5
  415. lws: l.lbs r5,0(r2)
  416. l.slli r5,r5,24
  417. l.lbz r6,1(r2)
  418. l.slli r6,r6,16
  419. l.or r5,r5,r6
  420. l.lbz r6,2(r2)
  421. l.slli r6,r6,8
  422. l.or r5,r5,r6
  423. l.lbz r6,3(r2)
  424. l.or r5,r5,r6
  425. l.srli r4,r3,19
  426. l.andi r4,r4,0x7c
  427. l.add r4,r4,r1
  428. l.j align_end
  429. l.sw 0(r4),r5
  430. lwz: l.lbz r5,0(r2)
  431. l.slli r5,r5,24
  432. l.lbz r6,1(r2)
  433. l.slli r6,r6,16
  434. l.or r5,r5,r6
  435. l.lbz r6,2(r2)
  436. l.slli r6,r6,8
  437. l.or r5,r5,r6
  438. l.lbz r6,3(r2)
  439. l.or r5,r5,r6
  440. l.srli r4,r3,19
  441. l.andi r4,r4,0x7c
  442. l.add r4,r4,r1
  443. l.j align_end
  444. l.sw 0(r4),r5
  445. sh:
  446. l.srli r4,r3,9
  447. l.andi r4,r4,0x7c
  448. l.add r4,r4,r1
  449. l.lwz r5,0(r4)
  450. l.sb 1(r2),r5
  451. l.srli r5,r5,8
  452. l.j align_end
  453. l.sb 0(r2),r5
  454. sw:
  455. l.srli r4,r3,9
  456. l.andi r4,r4,0x7c
  457. l.add r4,r4,r1
  458. l.lwz r5,0(r4)
  459. l.sb 3(r2),r5
  460. l.srli r5,r5,8
  461. l.sb 2(r2),r5
  462. l.srli r5,r5,8
  463. l.sb 1(r2),r5
  464. l.srli r5,r5,8
  465. l.j align_end
  466. l.sb 0(r2),r5
  467. align_end:
  468. l.j _ret_from_intr
  469. l.nop
  470. #endif
  471. /* ---[ 0x700: Illegal insn exception ]---------------------------------- */
  472. EXCEPTION_ENTRY(_illegal_instruction_handler)
  473. /* r4: EA of fault (set by EXCEPTION_HANDLE) */
  474. l.jal do_illegal_instruction
  475. l.addi r3,r1,0 /* pt_regs */
  476. l.j _ret_from_exception
  477. l.nop
  478. /* ---[ 0x800: External interrupt exception ]---------------------------- */
  479. EXCEPTION_ENTRY(_external_irq_handler)
  480. #ifdef CONFIG_OPENRISC_ESR_EXCEPTION_BUG_CHECK
  481. l.lwz r4,PT_SR(r1) // were interrupts enabled ?
  482. l.andi r4,r4,SPR_SR_IEE
  483. l.sfeqi r4,0
  484. l.bnf 1f // ext irq enabled, all ok.
  485. l.nop
  486. l.addi r1,r1,-0x8
  487. l.movhi r3,hi(42f)
  488. l.ori r3,r3,lo(42f)
  489. l.sw 0x0(r1),r3
  490. l.jal printk
  491. l.sw 0x4(r1),r4
  492. l.addi r1,r1,0x8
  493. .section .rodata, "a"
  494. 42:
  495. .string "\n\rESR interrupt bug: in _external_irq_handler (ESR %x)\n\r"
  496. .align 4
  497. .previous
  498. l.ori r4,r4,SPR_SR_IEE // fix the bug
  499. // l.sw PT_SR(r1),r4
  500. 1:
  501. #endif
  502. CLEAR_LWA_FLAG(r3)
  503. l.addi r3,r1,0
  504. l.movhi r8,hi(do_IRQ)
  505. l.ori r8,r8,lo(do_IRQ)
  506. l.jalr r8
  507. l.nop
  508. l.j _ret_from_intr
  509. l.nop
  510. /* ---[ 0x900: DTLB miss exception ]------------------------------------- */
  511. /* ---[ 0xa00: ITLB miss exception ]------------------------------------- */
  512. /* ---[ 0xb00: Range exception ]----------------------------------------- */
  513. UNHANDLED_EXCEPTION(_vector_0xb00,0xb00)
  514. /* ---[ 0xc00: Syscall exception ]--------------------------------------- */
  515. /*
  516. * Syscalls are a special type of exception in that they are
  517. * _explicitly_ invoked by userspace and can therefore be
  518. * held to conform to the same ABI as normal functions with
  519. * respect to whether registers are preserved across the call
  520. * or not.
  521. */
  522. /* Upon syscall entry we just save the callee-saved registers
  523. * and not the call-clobbered ones.
  524. */
  525. _string_syscall_return:
  526. .string "syscall return %ld \n\r\0"
  527. .align 4
  528. ENTRY(_sys_call_handler)
  529. /* r1, EPCR, ESR a already saved */
  530. l.sw PT_GPR2(r1),r2
  531. /* r3-r8 must be saved because syscall restart relies
  532. * on us being able to restart the syscall args... technically
  533. * they should be clobbered, otherwise
  534. */
  535. l.sw PT_GPR3(r1),r3
  536. /*
  537. * r4 already saved
  538. * r4 holds the EEAR address of the fault, use it as screatch reg and
  539. * then load the original r4
  540. */
  541. CLEAR_LWA_FLAG(r4)
  542. l.lwz r4,PT_GPR4(r1)
  543. l.sw PT_GPR5(r1),r5
  544. l.sw PT_GPR6(r1),r6
  545. l.sw PT_GPR7(r1),r7
  546. l.sw PT_GPR8(r1),r8
  547. l.sw PT_GPR9(r1),r9
  548. /* r10 already saved */
  549. l.sw PT_GPR11(r1),r11
  550. /* orig_gpr11 must be set for syscalls */
  551. l.sw PT_ORIG_GPR11(r1),r11
  552. /* r12,r13 already saved */
  553. /* r14-r28 (even) aren't touched by the syscall fast path below
  554. * so we don't need to save them. However, the functions that return
  555. * to userspace via a call to switch() DO need to save these because
  556. * switch() effectively clobbers them... saving these registers for
  557. * such functions is handled in their syscall wrappers (see fork, vfork,
  558. * and clone, below).
  559. /* r30 is the only register we clobber in the fast path */
  560. /* r30 already saved */
  561. /* l.sw PT_GPR30(r1),r30 */
  562. _syscall_check_trace_enter:
  563. /* syscalls run with interrupts enabled */
  564. TRACE_IRQS_ON_SYSCALL
  565. ENABLE_INTERRUPTS(r29) // enable interrupts, r29 is temp
  566. /* If TIF_SYSCALL_TRACE is set, then we want to do syscall tracing */
  567. l.lwz r30,TI_FLAGS(r10)
  568. l.andi r30,r30,_TIF_SYSCALL_TRACE
  569. l.sfne r30,r0
  570. l.bf _syscall_trace_enter
  571. l.nop
  572. _syscall_check:
  573. /* Ensure that the syscall number is reasonable */
  574. l.sfgeui r11,__NR_syscalls
  575. l.bf _syscall_badsys
  576. l.nop
  577. _syscall_call:
  578. l.movhi r29,hi(sys_call_table)
  579. l.ori r29,r29,lo(sys_call_table)
  580. l.slli r11,r11,2
  581. l.add r29,r29,r11
  582. l.lwz r29,0(r29)
  583. l.jalr r29
  584. l.nop
  585. _syscall_return:
  586. /* All syscalls return here... just pay attention to ret_from_fork
  587. * which does it in a round-about way.
  588. */
  589. l.sw PT_GPR11(r1),r11 // save return value
  590. #if 0
  591. _syscall_debug:
  592. l.movhi r3,hi(_string_syscall_return)
  593. l.ori r3,r3,lo(_string_syscall_return)
  594. l.ori r27,r0,1
  595. l.sw -4(r1),r27
  596. l.sw -8(r1),r11
  597. l.addi r1,r1,-8
  598. l.movhi r27,hi(printk)
  599. l.ori r27,r27,lo(printk)
  600. l.jalr r27
  601. l.nop
  602. l.addi r1,r1,8
  603. #endif
  604. _syscall_check_trace_leave:
  605. /* r30 is a callee-saved register so this should still hold the
  606. * _TIF_SYSCALL_TRACE flag from _syscall_check_trace_enter above...
  607. * _syscall_trace_leave expects syscall result to be in pt_regs->r11.
  608. */
  609. l.sfne r30,r0
  610. l.bf _syscall_trace_leave
  611. l.nop
  612. /* This is where the exception-return code begins... interrupts need to be
  613. * disabled the rest of the way here because we can't afford to miss any
  614. * interrupts that set NEED_RESCHED or SIGNALPENDING... really true? */
  615. _syscall_check_work:
  616. /* Here we need to disable interrupts */
  617. DISABLE_INTERRUPTS(r27,r29)
  618. TRACE_IRQS_OFF
  619. l.lwz r30,TI_FLAGS(r10)
  620. l.andi r30,r30,_TIF_WORK_MASK
  621. l.sfne r30,r0
  622. l.bnf _syscall_resume_userspace
  623. l.nop
  624. /* Work pending follows a different return path, so we need to
  625. * make sure that all the call-saved registers get into pt_regs
  626. * before branching...
  627. */
  628. l.sw PT_GPR14(r1),r14
  629. l.sw PT_GPR16(r1),r16
  630. l.sw PT_GPR18(r1),r18
  631. l.sw PT_GPR20(r1),r20
  632. l.sw PT_GPR22(r1),r22
  633. l.sw PT_GPR24(r1),r24
  634. l.sw PT_GPR26(r1),r26
  635. l.sw PT_GPR28(r1),r28
  636. /* _work_pending needs to be called with interrupts disabled */
  637. l.j _work_pending
  638. l.nop
  639. _syscall_resume_userspace:
  640. // ENABLE_INTERRUPTS(r29)
  641. /* This is the hot path for returning to userspace from a syscall. If there's
  642. * work to be done and the branch to _work_pending was taken above, then the
  643. * return to userspace will be done via the normal exception return path...
  644. * that path restores _all_ registers and will overwrite the "clobbered"
  645. * registers with whatever garbage is in pt_regs -- that's OK because those
  646. * registers are clobbered anyway and because the extra work is insignificant
  647. * in the context of the extra work that _work_pending is doing.
  648. /* Once again, syscalls are special and only guarantee to preserve the
  649. * same registers as a normal function call */
  650. /* The assumption here is that the registers r14-r28 (even) are untouched and
  651. * don't need to be restored... be sure that that's really the case!
  652. */
  653. /* This is still too much... we should only be restoring what we actually
  654. * clobbered... we should even be using 'scratch' (odd) regs above so that
  655. * we don't need to restore anything, hardly...
  656. */
  657. l.lwz r2,PT_GPR2(r1)
  658. /* Restore args */
  659. /* r3-r8 are technically clobbered, but syscall restart needs these
  660. * to be restored...
  661. */
  662. l.lwz r3,PT_GPR3(r1)
  663. l.lwz r4,PT_GPR4(r1)
  664. l.lwz r5,PT_GPR5(r1)
  665. l.lwz r6,PT_GPR6(r1)
  666. l.lwz r7,PT_GPR7(r1)
  667. l.lwz r8,PT_GPR8(r1)
  668. l.lwz r9,PT_GPR9(r1)
  669. l.lwz r10,PT_GPR10(r1)
  670. l.lwz r11,PT_GPR11(r1)
  671. /* r30 is the only register we clobber in the fast path */
  672. l.lwz r30,PT_GPR30(r1)
  673. /* Here we use r13-r19 (odd) as scratch regs */
  674. l.lwz r13,PT_PC(r1)
  675. l.lwz r15,PT_SR(r1)
  676. l.lwz r1,PT_SP(r1)
  677. /* Interrupts need to be disabled for setting EPCR and ESR
  678. * so that another interrupt doesn't come in here and clobber
  679. * them before we can use them for our l.rfe */
  680. DISABLE_INTERRUPTS(r17,r19)
  681. l.mtspr r0,r13,SPR_EPCR_BASE
  682. l.mtspr r0,r15,SPR_ESR_BASE
  683. l.rfe
  684. /* End of hot path!
  685. * Keep the below tracing and error handling out of the hot path...
  686. */
  687. _syscall_trace_enter:
  688. /* Here we pass pt_regs to do_syscall_trace_enter. Make sure
  689. * that function is really getting all the info it needs as
  690. * pt_regs isn't a complete set of userspace regs, just the
  691. * ones relevant to the syscall...
  692. *
  693. * Note use of delay slot for setting argument.
  694. */
  695. l.jal do_syscall_trace_enter
  696. l.addi r3,r1,0
  697. /* Restore arguments (not preserved across do_syscall_trace_enter)
  698. * so that we can do the syscall for real and return to the syscall
  699. * hot path.
  700. */
  701. l.lwz r11,PT_GPR11(r1)
  702. l.lwz r3,PT_GPR3(r1)
  703. l.lwz r4,PT_GPR4(r1)
  704. l.lwz r5,PT_GPR5(r1)
  705. l.lwz r6,PT_GPR6(r1)
  706. l.lwz r7,PT_GPR7(r1)
  707. l.j _syscall_check
  708. l.lwz r8,PT_GPR8(r1)
  709. _syscall_trace_leave:
  710. l.jal do_syscall_trace_leave
  711. l.addi r3,r1,0
  712. l.j _syscall_check_work
  713. l.nop
  714. _syscall_badsys:
  715. /* Here we effectively pretend to have executed an imaginary
  716. * syscall that returns -ENOSYS and then return to the regular
  717. * syscall hot path.
  718. * Note that "return value" is set in the delay slot...
  719. */
  720. l.j _syscall_return
  721. l.addi r11,r0,-ENOSYS
  722. /******* END SYSCALL HANDLING *******/
  723. /* ---[ 0xd00: Trap exception ]------------------------------------------ */
  724. UNHANDLED_EXCEPTION(_vector_0xd00,0xd00)
  725. /* ---[ 0xe00: Trap exception ]------------------------------------------ */
  726. EXCEPTION_ENTRY(_trap_handler)
  727. CLEAR_LWA_FLAG(r3)
  728. /* r4: EA of fault (set by EXCEPTION_HANDLE) */
  729. l.jal do_trap
  730. l.addi r3,r1,0 /* pt_regs */
  731. l.j _ret_from_exception
  732. l.nop
  733. /* ---[ 0xf00: Reserved exception ]-------------------------------------- */
  734. UNHANDLED_EXCEPTION(_vector_0xf00,0xf00)
  735. /* ---[ 0x1000: Reserved exception ]------------------------------------- */
  736. UNHANDLED_EXCEPTION(_vector_0x1000,0x1000)
  737. /* ---[ 0x1100: Reserved exception ]------------------------------------- */
  738. UNHANDLED_EXCEPTION(_vector_0x1100,0x1100)
  739. /* ---[ 0x1200: Reserved exception ]------------------------------------- */
  740. UNHANDLED_EXCEPTION(_vector_0x1200,0x1200)
  741. /* ---[ 0x1300: Reserved exception ]------------------------------------- */
  742. UNHANDLED_EXCEPTION(_vector_0x1300,0x1300)
  743. /* ---[ 0x1400: Reserved exception ]------------------------------------- */
  744. UNHANDLED_EXCEPTION(_vector_0x1400,0x1400)
  745. /* ---[ 0x1500: Reserved exception ]------------------------------------- */
  746. UNHANDLED_EXCEPTION(_vector_0x1500,0x1500)
  747. /* ---[ 0x1600: Reserved exception ]------------------------------------- */
  748. UNHANDLED_EXCEPTION(_vector_0x1600,0x1600)
  749. /* ---[ 0x1700: Reserved exception ]------------------------------------- */
  750. UNHANDLED_EXCEPTION(_vector_0x1700,0x1700)
  751. /* ---[ 0x1800: Reserved exception ]------------------------------------- */
  752. UNHANDLED_EXCEPTION(_vector_0x1800,0x1800)
  753. /* ---[ 0x1900: Reserved exception ]------------------------------------- */
  754. UNHANDLED_EXCEPTION(_vector_0x1900,0x1900)
  755. /* ---[ 0x1a00: Reserved exception ]------------------------------------- */
  756. UNHANDLED_EXCEPTION(_vector_0x1a00,0x1a00)
  757. /* ---[ 0x1b00: Reserved exception ]------------------------------------- */
  758. UNHANDLED_EXCEPTION(_vector_0x1b00,0x1b00)
  759. /* ---[ 0x1c00: Reserved exception ]------------------------------------- */
  760. UNHANDLED_EXCEPTION(_vector_0x1c00,0x1c00)
  761. /* ---[ 0x1d00: Reserved exception ]------------------------------------- */
  762. UNHANDLED_EXCEPTION(_vector_0x1d00,0x1d00)
  763. /* ---[ 0x1e00: Reserved exception ]------------------------------------- */
  764. UNHANDLED_EXCEPTION(_vector_0x1e00,0x1e00)
  765. /* ---[ 0x1f00: Reserved exception ]------------------------------------- */
  766. UNHANDLED_EXCEPTION(_vector_0x1f00,0x1f00)
  767. /* ========================================================[ return ] === */
  768. _resume_userspace:
  769. DISABLE_INTERRUPTS(r3,r4)
  770. TRACE_IRQS_OFF
  771. l.lwz r4,TI_FLAGS(r10)
  772. l.andi r13,r4,_TIF_WORK_MASK
  773. l.sfeqi r13,0
  774. l.bf _restore_all
  775. l.nop
  776. _work_pending:
  777. l.lwz r5,PT_ORIG_GPR11(r1)
  778. l.sfltsi r5,0
  779. l.bnf 1f
  780. l.nop
  781. l.andi r5,r5,0
  782. 1:
  783. l.jal do_work_pending
  784. l.ori r3,r1,0 /* pt_regs */
  785. l.sfeqi r11,0
  786. l.bf _restore_all
  787. l.nop
  788. l.sfltsi r11,0
  789. l.bnf 1f
  790. l.nop
  791. l.and r11,r11,r0
  792. l.ori r11,r11,__NR_restart_syscall
  793. l.j _syscall_check_trace_enter
  794. l.nop
  795. 1:
  796. l.lwz r11,PT_ORIG_GPR11(r1)
  797. /* Restore arg registers */
  798. l.lwz r3,PT_GPR3(r1)
  799. l.lwz r4,PT_GPR4(r1)
  800. l.lwz r5,PT_GPR5(r1)
  801. l.lwz r6,PT_GPR6(r1)
  802. l.lwz r7,PT_GPR7(r1)
  803. l.j _syscall_check_trace_enter
  804. l.lwz r8,PT_GPR8(r1)
  805. _restore_all:
  806. #ifdef CONFIG_TRACE_IRQFLAGS
  807. l.lwz r4,PT_SR(r1)
  808. l.andi r3,r4,(SPR_SR_IEE|SPR_SR_TEE)
  809. l.sfeq r3,r0 /* skip trace if irqs were off */
  810. l.bf skip_hardirqs_on
  811. l.nop
  812. TRACE_IRQS_ON
  813. skip_hardirqs_on:
  814. #endif
  815. RESTORE_ALL
  816. /* This returns to userspace code */
  817. ENTRY(_ret_from_intr)
  818. ENTRY(_ret_from_exception)
  819. l.lwz r4,PT_SR(r1)
  820. l.andi r3,r4,SPR_SR_SM
  821. l.sfeqi r3,0
  822. l.bnf _restore_all
  823. l.nop
  824. l.j _resume_userspace
  825. l.nop
  826. ENTRY(ret_from_fork)
  827. l.jal schedule_tail
  828. l.nop
  829. /* Check if we are a kernel thread */
  830. l.sfeqi r20,0
  831. l.bf 1f
  832. l.nop
  833. /* ...we are a kernel thread so invoke the requested callback */
  834. l.jalr r20
  835. l.or r3,r22,r0
  836. 1:
  837. /* _syscall_returns expect r11 to contain return value */
  838. l.lwz r11,PT_GPR11(r1)
  839. /* The syscall fast path return expects call-saved registers
  840. * r12-r28 to be untouched, so we restore them here as they
  841. * will have been effectively clobbered when arriving here
  842. * via the call to switch()
  843. */
  844. l.lwz r12,PT_GPR12(r1)
  845. l.lwz r14,PT_GPR14(r1)
  846. l.lwz r16,PT_GPR16(r1)
  847. l.lwz r18,PT_GPR18(r1)
  848. l.lwz r20,PT_GPR20(r1)
  849. l.lwz r22,PT_GPR22(r1)
  850. l.lwz r24,PT_GPR24(r1)
  851. l.lwz r26,PT_GPR26(r1)
  852. l.lwz r28,PT_GPR28(r1)
  853. l.j _syscall_return
  854. l.nop
  855. /* ========================================================[ switch ] === */
  856. /*
  857. * This routine switches between two different tasks. The process
  858. * state of one is saved on its kernel stack. Then the state
  859. * of the other is restored from its kernel stack. The memory
  860. * management hardware is updated to the second process's state.
  861. * Finally, we can return to the second process, via the 'return'.
  862. *
  863. * Note: there are two ways to get to the "going out" portion
  864. * of this code; either by coming in via the entry (_switch)
  865. * or via "fork" which must set up an environment equivalent
  866. * to the "_switch" path. If you change this (or in particular, the
  867. * SAVE_REGS macro), you'll have to change the fork code also.
  868. */
  869. /* _switch MUST never lay on page boundry, cause it runs from
  870. * effective addresses and beeing interrupted by iTLB miss would kill it.
  871. * dTLB miss seams to never accour in the bad place since data accesses
  872. * are from task structures which are always page aligned.
  873. *
  874. * The problem happens in RESTORE_ALL_NO_R11 where we first set the EPCR
  875. * register, then load the previous register values and only at the end call
  876. * the l.rfe instruction. If get TLB miss in beetwen the EPCR register gets
  877. * garbled and we end up calling l.rfe with the wrong EPCR. (same probably
  878. * holds for ESR)
  879. *
  880. * To avoid this problems it is sufficient to align _switch to
  881. * some nice round number smaller than it's size...
  882. */
  883. /* ABI rules apply here... we either enter _switch via schedule() or via
  884. * an imaginary call to which we shall return at return_from_fork. Either
  885. * way, we are a function call and only need to preserve the callee-saved
  886. * registers when we return. As such, we don't need to save the registers
  887. * on the stack that we won't be returning as they were...
  888. */
  889. .align 0x400
  890. ENTRY(_switch)
  891. /* We don't store SR as _switch only gets called in a context where
  892. * the SR will be the same going in and coming out... */
  893. /* Set up new pt_regs struct for saving task state */
  894. l.addi r1,r1,-(INT_FRAME_SIZE)
  895. /* No need to store r1/PT_SP as it goes into KSP below */
  896. l.sw PT_GPR2(r1),r2
  897. l.sw PT_GPR9(r1),r9
  898. /* This is wrong, r12 shouldn't be here... but GCC is broken for the time being
  899. * and expects r12 to be callee-saved... */
  900. l.sw PT_GPR12(r1),r12
  901. l.sw PT_GPR14(r1),r14
  902. l.sw PT_GPR16(r1),r16
  903. l.sw PT_GPR18(r1),r18
  904. l.sw PT_GPR20(r1),r20
  905. l.sw PT_GPR22(r1),r22
  906. l.sw PT_GPR24(r1),r24
  907. l.sw PT_GPR26(r1),r26
  908. l.sw PT_GPR28(r1),r28
  909. l.sw PT_GPR30(r1),r30
  910. l.addi r11,r10,0 /* Save old 'current' to 'last' return value*/
  911. /* We use thread_info->ksp for storing the address of the above
  912. * structure so that we can get back to it later... we don't want
  913. * to lose the value of thread_info->ksp, though, so store it as
  914. * pt_regs->sp so that we can easily restore it when we are made
  915. * live again...
  916. */
  917. /* Save the old value of thread_info->ksp as pt_regs->sp */
  918. l.lwz r29,TI_KSP(r10)
  919. l.sw PT_SP(r1),r29
  920. /* Swap kernel stack pointers */
  921. l.sw TI_KSP(r10),r1 /* Save old stack pointer */
  922. l.or r10,r4,r0 /* Set up new current_thread_info */
  923. l.lwz r1,TI_KSP(r10) /* Load new stack pointer */
  924. /* Restore the old value of thread_info->ksp */
  925. l.lwz r29,PT_SP(r1)
  926. l.sw TI_KSP(r10),r29
  927. /* ...and restore the registers, except r11 because the return value
  928. * has already been set above.
  929. */
  930. l.lwz r2,PT_GPR2(r1)
  931. l.lwz r9,PT_GPR9(r1)
  932. /* No need to restore r10 */
  933. /* ...and do not restore r11 */
  934. /* This is wrong, r12 shouldn't be here... but GCC is broken for the time being
  935. * and expects r12 to be callee-saved... */
  936. l.lwz r12,PT_GPR12(r1)
  937. l.lwz r14,PT_GPR14(r1)
  938. l.lwz r16,PT_GPR16(r1)
  939. l.lwz r18,PT_GPR18(r1)
  940. l.lwz r20,PT_GPR20(r1)
  941. l.lwz r22,PT_GPR22(r1)
  942. l.lwz r24,PT_GPR24(r1)
  943. l.lwz r26,PT_GPR26(r1)
  944. l.lwz r28,PT_GPR28(r1)
  945. l.lwz r30,PT_GPR30(r1)
  946. /* Unwind stack to pre-switch state */
  947. l.addi r1,r1,(INT_FRAME_SIZE)
  948. /* Return via the link-register back to where we 'came from', where
  949. * that may be either schedule(), ret_from_fork(), or
  950. * ret_from_kernel_thread(). If we are returning to a new thread,
  951. * we are expected to have set up the arg to schedule_tail already,
  952. * hence we do so here unconditionally:
  953. */
  954. l.lwz r3,TI_TASK(r3) /* Load 'prev' as schedule_tail arg */
  955. l.jr r9
  956. l.nop
  957. /* ==================================================================== */
  958. /* These all use the delay slot for setting the argument register, so the
  959. * jump is always happening after the l.addi instruction.
  960. *
  961. * These are all just wrappers that don't touch the link-register r9, so the
  962. * return from the "real" syscall function will return back to the syscall
  963. * code that did the l.jal that brought us here.
  964. */
  965. /* fork requires that we save all the callee-saved registers because they
  966. * are all effectively clobbered by the call to _switch. Here we store
  967. * all the registers that aren't touched by the syscall fast path and thus
  968. * weren't saved there.
  969. */
  970. _fork_save_extra_regs_and_call:
  971. l.sw PT_GPR14(r1),r14
  972. l.sw PT_GPR16(r1),r16
  973. l.sw PT_GPR18(r1),r18
  974. l.sw PT_GPR20(r1),r20
  975. l.sw PT_GPR22(r1),r22
  976. l.sw PT_GPR24(r1),r24
  977. l.sw PT_GPR26(r1),r26
  978. l.jr r29
  979. l.sw PT_GPR28(r1),r28
  980. ENTRY(__sys_clone)
  981. l.movhi r29,hi(sys_clone)
  982. l.ori r29,r29,lo(sys_clone)
  983. l.j _fork_save_extra_regs_and_call
  984. l.addi r7,r1,0
  985. ENTRY(__sys_fork)
  986. l.movhi r29,hi(sys_fork)
  987. l.ori r29,r29,lo(sys_fork)
  988. l.j _fork_save_extra_regs_and_call
  989. l.addi r3,r1,0
  990. ENTRY(sys_rt_sigreturn)
  991. l.jal _sys_rt_sigreturn
  992. l.addi r3,r1,0
  993. l.sfne r30,r0
  994. l.bnf _no_syscall_trace
  995. l.nop
  996. l.jal do_syscall_trace_leave
  997. l.addi r3,r1,0
  998. _no_syscall_trace:
  999. l.j _resume_userspace
  1000. l.nop
  1001. /* This is a catch-all syscall for atomic instructions for the OpenRISC 1000.
  1002. * The functions takes a variable number of parameters depending on which
  1003. * particular flavour of atomic you want... parameter 1 is a flag identifying
  1004. * the atomic in question. Currently, this function implements the
  1005. * following variants:
  1006. *
  1007. * XCHG:
  1008. * @flag: 1
  1009. * @ptr1:
  1010. * @ptr2:
  1011. * Atomically exchange the values in pointers 1 and 2.
  1012. *
  1013. */
  1014. ENTRY(sys_or1k_atomic)
  1015. /* FIXME: This ignores r3 and always does an XCHG */
  1016. DISABLE_INTERRUPTS(r17,r19)
  1017. l.lwz r29,0(r4)
  1018. l.lwz r27,0(r5)
  1019. l.sw 0(r4),r27
  1020. l.sw 0(r5),r29
  1021. ENABLE_INTERRUPTS(r17)
  1022. l.jr r9
  1023. l.or r11,r0,r0
  1024. /* ============================================================[ EOF ]=== */