entry.S 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  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/or32/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. /*
  259. * __PHX__: TODO
  260. *
  261. * all this can be written much simpler. look at
  262. * DTLB miss handler in the CONFIG_GUARD_PROTECTED_CORE part
  263. */
  264. #ifdef CONFIG_OPENRISC_NO_SPR_SR_DSX
  265. l.lwz r6,PT_PC(r3) // address of an offending insn
  266. l.lwz r6,0(r6) // instruction that caused pf
  267. l.srli r6,r6,26 // check opcode for jump insn
  268. l.sfeqi r6,0 // l.j
  269. l.bf 8f
  270. l.sfeqi r6,1 // l.jal
  271. l.bf 8f
  272. l.sfeqi r6,3 // l.bnf
  273. l.bf 8f
  274. l.sfeqi r6,4 // l.bf
  275. l.bf 8f
  276. l.sfeqi r6,0x11 // l.jr
  277. l.bf 8f
  278. l.sfeqi r6,0x12 // l.jalr
  279. l.bf 8f
  280. l.nop
  281. l.j 9f
  282. l.nop
  283. 8: // offending insn is in delay slot
  284. l.lwz r6,PT_PC(r3) // address of an offending insn
  285. l.addi r6,r6,4
  286. l.lwz r6,0(r6) // instruction that caused pf
  287. l.srli r6,r6,26 // get opcode
  288. 9: // offending instruction opcode loaded in r6
  289. #else
  290. l.lwz r6,PT_SR(r3) // SR
  291. l.andi r6,r6,SPR_SR_DSX // check for delay slot exception
  292. l.sfne r6,r0 // exception happened in delay slot
  293. l.bnf 7f
  294. l.lwz r6,PT_PC(r3) // address of an offending insn
  295. l.addi r6,r6,4 // offending insn is in delay slot
  296. 7:
  297. l.lwz r6,0(r6) // instruction that caused pf
  298. l.srli r6,r6,26 // check opcode for write access
  299. #endif
  300. l.sfgeui r6,0x33 // check opcode for write access
  301. l.bnf 1f
  302. l.sfleui r6,0x37
  303. l.bnf 1f
  304. l.ori r6,r0,0x1 // write access
  305. l.j 2f
  306. l.nop
  307. 1: l.ori r6,r0,0x0 // !write access
  308. 2:
  309. /* call fault.c handler in or32/mm/fault.c */
  310. l.jal do_page_fault
  311. l.nop
  312. l.j _ret_from_exception
  313. l.nop
  314. /* ---[ 0x400: Insn Page Fault exception ]------------------------------- */
  315. EXCEPTION_ENTRY(_itlb_miss_page_fault_handler)
  316. CLEAR_LWA_FLAG(r3)
  317. l.and r5,r5,r0
  318. l.j 1f
  319. l.nop
  320. EXCEPTION_ENTRY(_insn_page_fault_handler)
  321. CLEAR_LWA_FLAG(r3)
  322. /* set up parameters for do_page_fault */
  323. l.ori r5,r0,0x400 // exception vector
  324. 1:
  325. l.addi r3,r1,0 // pt_regs
  326. /* r4 set be EXCEPTION_HANDLE */ // effective address of fault
  327. l.ori r6,r0,0x0 // !write access
  328. /* call fault.c handler in or32/mm/fault.c */
  329. l.jal do_page_fault
  330. l.nop
  331. l.j _ret_from_exception
  332. l.nop
  333. /* ---[ 0x500: Timer exception ]----------------------------------------- */
  334. EXCEPTION_ENTRY(_timer_handler)
  335. CLEAR_LWA_FLAG(r3)
  336. l.jal timer_interrupt
  337. l.addi r3,r1,0 /* pt_regs */
  338. l.j _ret_from_intr
  339. l.nop
  340. /* ---[ 0x600: Alignment exception ]-------------------------------------- */
  341. EXCEPTION_ENTRY(_alignment_handler)
  342. CLEAR_LWA_FLAG(r3)
  343. /* r4: EA of fault (set by EXCEPTION_HANDLE) */
  344. l.jal do_unaligned_access
  345. l.addi r3,r1,0 /* pt_regs */
  346. l.j _ret_from_exception
  347. l.nop
  348. #if 0
  349. EXCEPTION_ENTRY(_alignment_handler)
  350. // l.mfspr r2,r0,SPR_EEAR_BASE /* Load the effective address */
  351. l.addi r2,r4,0
  352. // l.mfspr r5,r0,SPR_EPCR_BASE /* Load the insn address */
  353. l.lwz r5,PT_PC(r1)
  354. l.lwz r3,0(r5) /* Load insn */
  355. l.srli r4,r3,26 /* Shift left to get the insn opcode */
  356. l.sfeqi r4,0x00 /* Check if the load/store insn is in delay slot */
  357. l.bf jmp
  358. l.sfeqi r4,0x01
  359. l.bf jmp
  360. l.sfeqi r4,0x03
  361. l.bf jmp
  362. l.sfeqi r4,0x04
  363. l.bf jmp
  364. l.sfeqi r4,0x11
  365. l.bf jr
  366. l.sfeqi r4,0x12
  367. l.bf jr
  368. l.nop
  369. l.j 1f
  370. l.addi r5,r5,4 /* Increment PC to get return insn address */
  371. jmp:
  372. l.slli r4,r3,6 /* Get the signed extended jump length */
  373. l.srai r4,r4,4
  374. l.lwz r3,4(r5) /* Load the real load/store insn */
  375. l.add r5,r5,r4 /* Calculate jump target address */
  376. l.j 1f
  377. l.srli r4,r3,26 /* Shift left to get the insn opcode */
  378. jr:
  379. l.slli r4,r3,9 /* Shift to get the reg nb */
  380. l.andi r4,r4,0x7c
  381. l.lwz r3,4(r5) /* Load the real load/store insn */
  382. l.add r4,r4,r1 /* Load the jump register value from the stack */
  383. l.lwz r5,0(r4)
  384. l.srli r4,r3,26 /* Shift left to get the insn opcode */
  385. 1:
  386. // l.mtspr r0,r5,SPR_EPCR_BASE
  387. l.sw PT_PC(r1),r5
  388. l.sfeqi r4,0x26
  389. l.bf lhs
  390. l.sfeqi r4,0x25
  391. l.bf lhz
  392. l.sfeqi r4,0x22
  393. l.bf lws
  394. l.sfeqi r4,0x21
  395. l.bf lwz
  396. l.sfeqi r4,0x37
  397. l.bf sh
  398. l.sfeqi r4,0x35
  399. l.bf sw
  400. l.nop
  401. 1: l.j 1b /* I don't know what to do */
  402. l.nop
  403. lhs: l.lbs r5,0(r2)
  404. l.slli r5,r5,8
  405. l.lbz r6,1(r2)
  406. l.or r5,r5,r6
  407. l.srli r4,r3,19
  408. l.andi r4,r4,0x7c
  409. l.add r4,r4,r1
  410. l.j align_end
  411. l.sw 0(r4),r5
  412. lhz: l.lbz r5,0(r2)
  413. l.slli r5,r5,8
  414. l.lbz r6,1(r2)
  415. l.or r5,r5,r6
  416. l.srli r4,r3,19
  417. l.andi r4,r4,0x7c
  418. l.add r4,r4,r1
  419. l.j align_end
  420. l.sw 0(r4),r5
  421. lws: l.lbs r5,0(r2)
  422. l.slli r5,r5,24
  423. l.lbz r6,1(r2)
  424. l.slli r6,r6,16
  425. l.or r5,r5,r6
  426. l.lbz r6,2(r2)
  427. l.slli r6,r6,8
  428. l.or r5,r5,r6
  429. l.lbz r6,3(r2)
  430. l.or r5,r5,r6
  431. l.srli r4,r3,19
  432. l.andi r4,r4,0x7c
  433. l.add r4,r4,r1
  434. l.j align_end
  435. l.sw 0(r4),r5
  436. lwz: l.lbz r5,0(r2)
  437. l.slli r5,r5,24
  438. l.lbz r6,1(r2)
  439. l.slli r6,r6,16
  440. l.or r5,r5,r6
  441. l.lbz r6,2(r2)
  442. l.slli r6,r6,8
  443. l.or r5,r5,r6
  444. l.lbz r6,3(r2)
  445. l.or r5,r5,r6
  446. l.srli r4,r3,19
  447. l.andi r4,r4,0x7c
  448. l.add r4,r4,r1
  449. l.j align_end
  450. l.sw 0(r4),r5
  451. sh:
  452. l.srli r4,r3,9
  453. l.andi r4,r4,0x7c
  454. l.add r4,r4,r1
  455. l.lwz r5,0(r4)
  456. l.sb 1(r2),r5
  457. l.srli r5,r5,8
  458. l.j align_end
  459. l.sb 0(r2),r5
  460. sw:
  461. l.srli r4,r3,9
  462. l.andi r4,r4,0x7c
  463. l.add r4,r4,r1
  464. l.lwz r5,0(r4)
  465. l.sb 3(r2),r5
  466. l.srli r5,r5,8
  467. l.sb 2(r2),r5
  468. l.srli r5,r5,8
  469. l.sb 1(r2),r5
  470. l.srli r5,r5,8
  471. l.j align_end
  472. l.sb 0(r2),r5
  473. align_end:
  474. l.j _ret_from_intr
  475. l.nop
  476. #endif
  477. /* ---[ 0x700: Illegal insn exception ]---------------------------------- */
  478. EXCEPTION_ENTRY(_illegal_instruction_handler)
  479. /* r4: EA of fault (set by EXCEPTION_HANDLE) */
  480. l.jal do_illegal_instruction
  481. l.addi r3,r1,0 /* pt_regs */
  482. l.j _ret_from_exception
  483. l.nop
  484. /* ---[ 0x800: External interrupt exception ]---------------------------- */
  485. EXCEPTION_ENTRY(_external_irq_handler)
  486. #ifdef CONFIG_OPENRISC_ESR_EXCEPTION_BUG_CHECK
  487. l.lwz r4,PT_SR(r1) // were interrupts enabled ?
  488. l.andi r4,r4,SPR_SR_IEE
  489. l.sfeqi r4,0
  490. l.bnf 1f // ext irq enabled, all ok.
  491. l.nop
  492. l.addi r1,r1,-0x8
  493. l.movhi r3,hi(42f)
  494. l.ori r3,r3,lo(42f)
  495. l.sw 0x0(r1),r3
  496. l.jal printk
  497. l.sw 0x4(r1),r4
  498. l.addi r1,r1,0x8
  499. .section .rodata, "a"
  500. 42:
  501. .string "\n\rESR interrupt bug: in _external_irq_handler (ESR %x)\n\r"
  502. .align 4
  503. .previous
  504. l.ori r4,r4,SPR_SR_IEE // fix the bug
  505. // l.sw PT_SR(r1),r4
  506. 1:
  507. #endif
  508. CLEAR_LWA_FLAG(r3)
  509. l.addi r3,r1,0
  510. l.movhi r8,hi(do_IRQ)
  511. l.ori r8,r8,lo(do_IRQ)
  512. l.jalr r8
  513. l.nop
  514. l.j _ret_from_intr
  515. l.nop
  516. /* ---[ 0x900: DTLB miss exception ]------------------------------------- */
  517. /* ---[ 0xa00: ITLB miss exception ]------------------------------------- */
  518. /* ---[ 0xb00: Range exception ]----------------------------------------- */
  519. UNHANDLED_EXCEPTION(_vector_0xb00,0xb00)
  520. /* ---[ 0xc00: Syscall exception ]--------------------------------------- */
  521. /*
  522. * Syscalls are a special type of exception in that they are
  523. * _explicitly_ invoked by userspace and can therefore be
  524. * held to conform to the same ABI as normal functions with
  525. * respect to whether registers are preserved across the call
  526. * or not.
  527. */
  528. /* Upon syscall entry we just save the callee-saved registers
  529. * and not the call-clobbered ones.
  530. */
  531. _string_syscall_return:
  532. .string "syscall return %ld \n\r\0"
  533. .align 4
  534. ENTRY(_sys_call_handler)
  535. /* r1, EPCR, ESR a already saved */
  536. l.sw PT_GPR2(r1),r2
  537. /* r3-r8 must be saved because syscall restart relies
  538. * on us being able to restart the syscall args... technically
  539. * they should be clobbered, otherwise
  540. */
  541. l.sw PT_GPR3(r1),r3
  542. /*
  543. * r4 already saved
  544. * r4 holds the EEAR address of the fault, use it as screatch reg and
  545. * then load the original r4
  546. */
  547. CLEAR_LWA_FLAG(r4)
  548. l.lwz r4,PT_GPR4(r1)
  549. l.sw PT_GPR5(r1),r5
  550. l.sw PT_GPR6(r1),r6
  551. l.sw PT_GPR7(r1),r7
  552. l.sw PT_GPR8(r1),r8
  553. l.sw PT_GPR9(r1),r9
  554. /* r10 already saved */
  555. l.sw PT_GPR11(r1),r11
  556. /* orig_gpr11 must be set for syscalls */
  557. l.sw PT_ORIG_GPR11(r1),r11
  558. /* r12,r13 already saved */
  559. /* r14-r28 (even) aren't touched by the syscall fast path below
  560. * so we don't need to save them. However, the functions that return
  561. * to userspace via a call to switch() DO need to save these because
  562. * switch() effectively clobbers them... saving these registers for
  563. * such functions is handled in their syscall wrappers (see fork, vfork,
  564. * and clone, below).
  565. /* r30 is the only register we clobber in the fast path */
  566. /* r30 already saved */
  567. /* l.sw PT_GPR30(r1),r30 */
  568. _syscall_check_trace_enter:
  569. /* syscalls run with interrupts enabled */
  570. TRACE_IRQS_ON_SYSCALL
  571. ENABLE_INTERRUPTS(r29) // enable interrupts, r29 is temp
  572. /* If TIF_SYSCALL_TRACE is set, then we want to do syscall tracing */
  573. l.lwz r30,TI_FLAGS(r10)
  574. l.andi r30,r30,_TIF_SYSCALL_TRACE
  575. l.sfne r30,r0
  576. l.bf _syscall_trace_enter
  577. l.nop
  578. _syscall_check:
  579. /* Ensure that the syscall number is reasonable */
  580. l.sfgeui r11,__NR_syscalls
  581. l.bf _syscall_badsys
  582. l.nop
  583. _syscall_call:
  584. l.movhi r29,hi(sys_call_table)
  585. l.ori r29,r29,lo(sys_call_table)
  586. l.slli r11,r11,2
  587. l.add r29,r29,r11
  588. l.lwz r29,0(r29)
  589. l.jalr r29
  590. l.nop
  591. _syscall_return:
  592. /* All syscalls return here... just pay attention to ret_from_fork
  593. * which does it in a round-about way.
  594. */
  595. l.sw PT_GPR11(r1),r11 // save return value
  596. #if 0
  597. _syscall_debug:
  598. l.movhi r3,hi(_string_syscall_return)
  599. l.ori r3,r3,lo(_string_syscall_return)
  600. l.ori r27,r0,1
  601. l.sw -4(r1),r27
  602. l.sw -8(r1),r11
  603. l.addi r1,r1,-8
  604. l.movhi r27,hi(printk)
  605. l.ori r27,r27,lo(printk)
  606. l.jalr r27
  607. l.nop
  608. l.addi r1,r1,8
  609. #endif
  610. _syscall_check_trace_leave:
  611. /* r30 is a callee-saved register so this should still hold the
  612. * _TIF_SYSCALL_TRACE flag from _syscall_check_trace_enter above...
  613. * _syscall_trace_leave expects syscall result to be in pt_regs->r11.
  614. */
  615. l.sfne r30,r0
  616. l.bf _syscall_trace_leave
  617. l.nop
  618. /* This is where the exception-return code begins... interrupts need to be
  619. * disabled the rest of the way here because we can't afford to miss any
  620. * interrupts that set NEED_RESCHED or SIGNALPENDING... really true? */
  621. _syscall_check_work:
  622. /* Here we need to disable interrupts */
  623. DISABLE_INTERRUPTS(r27,r29)
  624. TRACE_IRQS_OFF
  625. l.lwz r30,TI_FLAGS(r10)
  626. l.andi r30,r30,_TIF_WORK_MASK
  627. l.sfne r30,r0
  628. l.bnf _syscall_resume_userspace
  629. l.nop
  630. /* Work pending follows a different return path, so we need to
  631. * make sure that all the call-saved registers get into pt_regs
  632. * before branching...
  633. */
  634. l.sw PT_GPR14(r1),r14
  635. l.sw PT_GPR16(r1),r16
  636. l.sw PT_GPR18(r1),r18
  637. l.sw PT_GPR20(r1),r20
  638. l.sw PT_GPR22(r1),r22
  639. l.sw PT_GPR24(r1),r24
  640. l.sw PT_GPR26(r1),r26
  641. l.sw PT_GPR28(r1),r28
  642. /* _work_pending needs to be called with interrupts disabled */
  643. l.j _work_pending
  644. l.nop
  645. _syscall_resume_userspace:
  646. // ENABLE_INTERRUPTS(r29)
  647. /* This is the hot path for returning to userspace from a syscall. If there's
  648. * work to be done and the branch to _work_pending was taken above, then the
  649. * return to userspace will be done via the normal exception return path...
  650. * that path restores _all_ registers and will overwrite the "clobbered"
  651. * registers with whatever garbage is in pt_regs -- that's OK because those
  652. * registers are clobbered anyway and because the extra work is insignificant
  653. * in the context of the extra work that _work_pending is doing.
  654. /* Once again, syscalls are special and only guarantee to preserve the
  655. * same registers as a normal function call */
  656. /* The assumption here is that the registers r14-r28 (even) are untouched and
  657. * don't need to be restored... be sure that that's really the case!
  658. */
  659. /* This is still too much... we should only be restoring what we actually
  660. * clobbered... we should even be using 'scratch' (odd) regs above so that
  661. * we don't need to restore anything, hardly...
  662. */
  663. l.lwz r2,PT_GPR2(r1)
  664. /* Restore args */
  665. /* r3-r8 are technically clobbered, but syscall restart needs these
  666. * to be restored...
  667. */
  668. l.lwz r3,PT_GPR3(r1)
  669. l.lwz r4,PT_GPR4(r1)
  670. l.lwz r5,PT_GPR5(r1)
  671. l.lwz r6,PT_GPR6(r1)
  672. l.lwz r7,PT_GPR7(r1)
  673. l.lwz r8,PT_GPR8(r1)
  674. l.lwz r9,PT_GPR9(r1)
  675. l.lwz r10,PT_GPR10(r1)
  676. l.lwz r11,PT_GPR11(r1)
  677. /* r30 is the only register we clobber in the fast path */
  678. l.lwz r30,PT_GPR30(r1)
  679. /* Here we use r13-r19 (odd) as scratch regs */
  680. l.lwz r13,PT_PC(r1)
  681. l.lwz r15,PT_SR(r1)
  682. l.lwz r1,PT_SP(r1)
  683. /* Interrupts need to be disabled for setting EPCR and ESR
  684. * so that another interrupt doesn't come in here and clobber
  685. * them before we can use them for our l.rfe */
  686. DISABLE_INTERRUPTS(r17,r19)
  687. l.mtspr r0,r13,SPR_EPCR_BASE
  688. l.mtspr r0,r15,SPR_ESR_BASE
  689. l.rfe
  690. /* End of hot path!
  691. * Keep the below tracing and error handling out of the hot path...
  692. */
  693. _syscall_trace_enter:
  694. /* Here we pass pt_regs to do_syscall_trace_enter. Make sure
  695. * that function is really getting all the info it needs as
  696. * pt_regs isn't a complete set of userspace regs, just the
  697. * ones relevant to the syscall...
  698. *
  699. * Note use of delay slot for setting argument.
  700. */
  701. l.jal do_syscall_trace_enter
  702. l.addi r3,r1,0
  703. /* Restore arguments (not preserved across do_syscall_trace_enter)
  704. * so that we can do the syscall for real and return to the syscall
  705. * hot path.
  706. */
  707. l.lwz r11,PT_GPR11(r1)
  708. l.lwz r3,PT_GPR3(r1)
  709. l.lwz r4,PT_GPR4(r1)
  710. l.lwz r5,PT_GPR5(r1)
  711. l.lwz r6,PT_GPR6(r1)
  712. l.lwz r7,PT_GPR7(r1)
  713. l.j _syscall_check
  714. l.lwz r8,PT_GPR8(r1)
  715. _syscall_trace_leave:
  716. l.jal do_syscall_trace_leave
  717. l.addi r3,r1,0
  718. l.j _syscall_check_work
  719. l.nop
  720. _syscall_badsys:
  721. /* Here we effectively pretend to have executed an imaginary
  722. * syscall that returns -ENOSYS and then return to the regular
  723. * syscall hot path.
  724. * Note that "return value" is set in the delay slot...
  725. */
  726. l.j _syscall_return
  727. l.addi r11,r0,-ENOSYS
  728. /******* END SYSCALL HANDLING *******/
  729. /* ---[ 0xd00: Trap exception ]------------------------------------------ */
  730. UNHANDLED_EXCEPTION(_vector_0xd00,0xd00)
  731. /* ---[ 0xe00: Trap exception ]------------------------------------------ */
  732. EXCEPTION_ENTRY(_trap_handler)
  733. CLEAR_LWA_FLAG(r3)
  734. /* r4: EA of fault (set by EXCEPTION_HANDLE) */
  735. l.jal do_trap
  736. l.addi r3,r1,0 /* pt_regs */
  737. l.j _ret_from_exception
  738. l.nop
  739. /* ---[ 0xf00: Reserved exception ]-------------------------------------- */
  740. UNHANDLED_EXCEPTION(_vector_0xf00,0xf00)
  741. /* ---[ 0x1000: Reserved exception ]------------------------------------- */
  742. UNHANDLED_EXCEPTION(_vector_0x1000,0x1000)
  743. /* ---[ 0x1100: Reserved exception ]------------------------------------- */
  744. UNHANDLED_EXCEPTION(_vector_0x1100,0x1100)
  745. /* ---[ 0x1200: Reserved exception ]------------------------------------- */
  746. UNHANDLED_EXCEPTION(_vector_0x1200,0x1200)
  747. /* ---[ 0x1300: Reserved exception ]------------------------------------- */
  748. UNHANDLED_EXCEPTION(_vector_0x1300,0x1300)
  749. /* ---[ 0x1400: Reserved exception ]------------------------------------- */
  750. UNHANDLED_EXCEPTION(_vector_0x1400,0x1400)
  751. /* ---[ 0x1500: Reserved exception ]------------------------------------- */
  752. UNHANDLED_EXCEPTION(_vector_0x1500,0x1500)
  753. /* ---[ 0x1600: Reserved exception ]------------------------------------- */
  754. UNHANDLED_EXCEPTION(_vector_0x1600,0x1600)
  755. /* ---[ 0x1700: Reserved exception ]------------------------------------- */
  756. UNHANDLED_EXCEPTION(_vector_0x1700,0x1700)
  757. /* ---[ 0x1800: Reserved exception ]------------------------------------- */
  758. UNHANDLED_EXCEPTION(_vector_0x1800,0x1800)
  759. /* ---[ 0x1900: Reserved exception ]------------------------------------- */
  760. UNHANDLED_EXCEPTION(_vector_0x1900,0x1900)
  761. /* ---[ 0x1a00: Reserved exception ]------------------------------------- */
  762. UNHANDLED_EXCEPTION(_vector_0x1a00,0x1a00)
  763. /* ---[ 0x1b00: Reserved exception ]------------------------------------- */
  764. UNHANDLED_EXCEPTION(_vector_0x1b00,0x1b00)
  765. /* ---[ 0x1c00: Reserved exception ]------------------------------------- */
  766. UNHANDLED_EXCEPTION(_vector_0x1c00,0x1c00)
  767. /* ---[ 0x1d00: Reserved exception ]------------------------------------- */
  768. UNHANDLED_EXCEPTION(_vector_0x1d00,0x1d00)
  769. /* ---[ 0x1e00: Reserved exception ]------------------------------------- */
  770. UNHANDLED_EXCEPTION(_vector_0x1e00,0x1e00)
  771. /* ---[ 0x1f00: Reserved exception ]------------------------------------- */
  772. UNHANDLED_EXCEPTION(_vector_0x1f00,0x1f00)
  773. /* ========================================================[ return ] === */
  774. _resume_userspace:
  775. DISABLE_INTERRUPTS(r3,r4)
  776. TRACE_IRQS_OFF
  777. l.lwz r4,TI_FLAGS(r10)
  778. l.andi r13,r4,_TIF_WORK_MASK
  779. l.sfeqi r13,0
  780. l.bf _restore_all
  781. l.nop
  782. _work_pending:
  783. l.lwz r5,PT_ORIG_GPR11(r1)
  784. l.sfltsi r5,0
  785. l.bnf 1f
  786. l.nop
  787. l.andi r5,r5,0
  788. 1:
  789. l.jal do_work_pending
  790. l.ori r3,r1,0 /* pt_regs */
  791. l.sfeqi r11,0
  792. l.bf _restore_all
  793. l.nop
  794. l.sfltsi r11,0
  795. l.bnf 1f
  796. l.nop
  797. l.and r11,r11,r0
  798. l.ori r11,r11,__NR_restart_syscall
  799. l.j _syscall_check_trace_enter
  800. l.nop
  801. 1:
  802. l.lwz r11,PT_ORIG_GPR11(r1)
  803. /* Restore arg registers */
  804. l.lwz r3,PT_GPR3(r1)
  805. l.lwz r4,PT_GPR4(r1)
  806. l.lwz r5,PT_GPR5(r1)
  807. l.lwz r6,PT_GPR6(r1)
  808. l.lwz r7,PT_GPR7(r1)
  809. l.j _syscall_check_trace_enter
  810. l.lwz r8,PT_GPR8(r1)
  811. _restore_all:
  812. #ifdef CONFIG_TRACE_IRQFLAGS
  813. l.lwz r4,PT_SR(r1)
  814. l.andi r3,r4,(SPR_SR_IEE|SPR_SR_TEE)
  815. l.sfeq r3,r0 /* skip trace if irqs were off */
  816. l.bf skip_hardirqs_on
  817. l.nop
  818. TRACE_IRQS_ON
  819. skip_hardirqs_on:
  820. #endif
  821. RESTORE_ALL
  822. /* This returns to userspace code */
  823. ENTRY(_ret_from_intr)
  824. ENTRY(_ret_from_exception)
  825. l.lwz r4,PT_SR(r1)
  826. l.andi r3,r4,SPR_SR_SM
  827. l.sfeqi r3,0
  828. l.bnf _restore_all
  829. l.nop
  830. l.j _resume_userspace
  831. l.nop
  832. ENTRY(ret_from_fork)
  833. l.jal schedule_tail
  834. l.nop
  835. /* Check if we are a kernel thread */
  836. l.sfeqi r20,0
  837. l.bf 1f
  838. l.nop
  839. /* ...we are a kernel thread so invoke the requested callback */
  840. l.jalr r20
  841. l.or r3,r22,r0
  842. 1:
  843. /* _syscall_returns expect r11 to contain return value */
  844. l.lwz r11,PT_GPR11(r1)
  845. /* The syscall fast path return expects call-saved registers
  846. * r12-r28 to be untouched, so we restore them here as they
  847. * will have been effectively clobbered when arriving here
  848. * via the call to switch()
  849. */
  850. l.lwz r12,PT_GPR12(r1)
  851. l.lwz r14,PT_GPR14(r1)
  852. l.lwz r16,PT_GPR16(r1)
  853. l.lwz r18,PT_GPR18(r1)
  854. l.lwz r20,PT_GPR20(r1)
  855. l.lwz r22,PT_GPR22(r1)
  856. l.lwz r24,PT_GPR24(r1)
  857. l.lwz r26,PT_GPR26(r1)
  858. l.lwz r28,PT_GPR28(r1)
  859. l.j _syscall_return
  860. l.nop
  861. /* ========================================================[ switch ] === */
  862. /*
  863. * This routine switches between two different tasks. The process
  864. * state of one is saved on its kernel stack. Then the state
  865. * of the other is restored from its kernel stack. The memory
  866. * management hardware is updated to the second process's state.
  867. * Finally, we can return to the second process, via the 'return'.
  868. *
  869. * Note: there are two ways to get to the "going out" portion
  870. * of this code; either by coming in via the entry (_switch)
  871. * or via "fork" which must set up an environment equivalent
  872. * to the "_switch" path. If you change this (or in particular, the
  873. * SAVE_REGS macro), you'll have to change the fork code also.
  874. */
  875. /* _switch MUST never lay on page boundry, cause it runs from
  876. * effective addresses and beeing interrupted by iTLB miss would kill it.
  877. * dTLB miss seams to never accour in the bad place since data accesses
  878. * are from task structures which are always page aligned.
  879. *
  880. * The problem happens in RESTORE_ALL_NO_R11 where we first set the EPCR
  881. * register, then load the previous register values and only at the end call
  882. * the l.rfe instruction. If get TLB miss in beetwen the EPCR register gets
  883. * garbled and we end up calling l.rfe with the wrong EPCR. (same probably
  884. * holds for ESR)
  885. *
  886. * To avoid this problems it is sufficient to align _switch to
  887. * some nice round number smaller than it's size...
  888. */
  889. /* ABI rules apply here... we either enter _switch via schedule() or via
  890. * an imaginary call to which we shall return at return_from_fork. Either
  891. * way, we are a function call and only need to preserve the callee-saved
  892. * registers when we return. As such, we don't need to save the registers
  893. * on the stack that we won't be returning as they were...
  894. */
  895. .align 0x400
  896. ENTRY(_switch)
  897. /* We don't store SR as _switch only gets called in a context where
  898. * the SR will be the same going in and coming out... */
  899. /* Set up new pt_regs struct for saving task state */
  900. l.addi r1,r1,-(INT_FRAME_SIZE)
  901. /* No need to store r1/PT_SP as it goes into KSP below */
  902. l.sw PT_GPR2(r1),r2
  903. l.sw PT_GPR9(r1),r9
  904. /* This is wrong, r12 shouldn't be here... but GCC is broken for the time being
  905. * and expects r12 to be callee-saved... */
  906. l.sw PT_GPR12(r1),r12
  907. l.sw PT_GPR14(r1),r14
  908. l.sw PT_GPR16(r1),r16
  909. l.sw PT_GPR18(r1),r18
  910. l.sw PT_GPR20(r1),r20
  911. l.sw PT_GPR22(r1),r22
  912. l.sw PT_GPR24(r1),r24
  913. l.sw PT_GPR26(r1),r26
  914. l.sw PT_GPR28(r1),r28
  915. l.sw PT_GPR30(r1),r30
  916. l.addi r11,r10,0 /* Save old 'current' to 'last' return value*/
  917. /* We use thread_info->ksp for storing the address of the above
  918. * structure so that we can get back to it later... we don't want
  919. * to lose the value of thread_info->ksp, though, so store it as
  920. * pt_regs->sp so that we can easily restore it when we are made
  921. * live again...
  922. */
  923. /* Save the old value of thread_info->ksp as pt_regs->sp */
  924. l.lwz r29,TI_KSP(r10)
  925. l.sw PT_SP(r1),r29
  926. /* Swap kernel stack pointers */
  927. l.sw TI_KSP(r10),r1 /* Save old stack pointer */
  928. l.or r10,r4,r0 /* Set up new current_thread_info */
  929. l.lwz r1,TI_KSP(r10) /* Load new stack pointer */
  930. /* Restore the old value of thread_info->ksp */
  931. l.lwz r29,PT_SP(r1)
  932. l.sw TI_KSP(r10),r29
  933. /* ...and restore the registers, except r11 because the return value
  934. * has already been set above.
  935. */
  936. l.lwz r2,PT_GPR2(r1)
  937. l.lwz r9,PT_GPR9(r1)
  938. /* No need to restore r10 */
  939. /* ...and do not restore r11 */
  940. /* This is wrong, r12 shouldn't be here... but GCC is broken for the time being
  941. * and expects r12 to be callee-saved... */
  942. l.lwz r12,PT_GPR12(r1)
  943. l.lwz r14,PT_GPR14(r1)
  944. l.lwz r16,PT_GPR16(r1)
  945. l.lwz r18,PT_GPR18(r1)
  946. l.lwz r20,PT_GPR20(r1)
  947. l.lwz r22,PT_GPR22(r1)
  948. l.lwz r24,PT_GPR24(r1)
  949. l.lwz r26,PT_GPR26(r1)
  950. l.lwz r28,PT_GPR28(r1)
  951. l.lwz r30,PT_GPR30(r1)
  952. /* Unwind stack to pre-switch state */
  953. l.addi r1,r1,(INT_FRAME_SIZE)
  954. /* Return via the link-register back to where we 'came from', where
  955. * that may be either schedule(), ret_from_fork(), or
  956. * ret_from_kernel_thread(). If we are returning to a new thread,
  957. * we are expected to have set up the arg to schedule_tail already,
  958. * hence we do so here unconditionally:
  959. */
  960. l.lwz r3,TI_TASK(r3) /* Load 'prev' as schedule_tail arg */
  961. l.jr r9
  962. l.nop
  963. /* ==================================================================== */
  964. /* These all use the delay slot for setting the argument register, so the
  965. * jump is always happening after the l.addi instruction.
  966. *
  967. * These are all just wrappers that don't touch the link-register r9, so the
  968. * return from the "real" syscall function will return back to the syscall
  969. * code that did the l.jal that brought us here.
  970. */
  971. /* fork requires that we save all the callee-saved registers because they
  972. * are all effectively clobbered by the call to _switch. Here we store
  973. * all the registers that aren't touched by the syscall fast path and thus
  974. * weren't saved there.
  975. */
  976. _fork_save_extra_regs_and_call:
  977. l.sw PT_GPR14(r1),r14
  978. l.sw PT_GPR16(r1),r16
  979. l.sw PT_GPR18(r1),r18
  980. l.sw PT_GPR20(r1),r20
  981. l.sw PT_GPR22(r1),r22
  982. l.sw PT_GPR24(r1),r24
  983. l.sw PT_GPR26(r1),r26
  984. l.jr r29
  985. l.sw PT_GPR28(r1),r28
  986. ENTRY(__sys_clone)
  987. l.movhi r29,hi(sys_clone)
  988. l.ori r29,r29,lo(sys_clone)
  989. l.j _fork_save_extra_regs_and_call
  990. l.addi r7,r1,0
  991. ENTRY(__sys_fork)
  992. l.movhi r29,hi(sys_fork)
  993. l.ori r29,r29,lo(sys_fork)
  994. l.j _fork_save_extra_regs_and_call
  995. l.addi r3,r1,0
  996. ENTRY(sys_rt_sigreturn)
  997. l.jal _sys_rt_sigreturn
  998. l.addi r3,r1,0
  999. l.sfne r30,r0
  1000. l.bnf _no_syscall_trace
  1001. l.nop
  1002. l.jal do_syscall_trace_leave
  1003. l.addi r3,r1,0
  1004. _no_syscall_trace:
  1005. l.j _resume_userspace
  1006. l.nop
  1007. /* This is a catch-all syscall for atomic instructions for the OpenRISC 1000.
  1008. * The functions takes a variable number of parameters depending on which
  1009. * particular flavour of atomic you want... parameter 1 is a flag identifying
  1010. * the atomic in question. Currently, this function implements the
  1011. * following variants:
  1012. *
  1013. * XCHG:
  1014. * @flag: 1
  1015. * @ptr1:
  1016. * @ptr2:
  1017. * Atomically exchange the values in pointers 1 and 2.
  1018. *
  1019. */
  1020. ENTRY(sys_or1k_atomic)
  1021. /* FIXME: This ignores r3 and always does an XCHG */
  1022. DISABLE_INTERRUPTS(r17,r19)
  1023. l.lwz r29,0(r4)
  1024. l.lwz r27,0(r5)
  1025. l.sw 0(r4),r27
  1026. l.sw 0(r5),r29
  1027. ENABLE_INTERRUPTS(r17)
  1028. l.jr r9
  1029. l.or r11,r0,r0
  1030. /* ============================================================[ EOF ]=== */