entry.S 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * OpenRISC entry.S
  4. *
  5. * Linux architectural port borrowing liberally from similar works of
  6. * others. All original copyrights apply as per the original source
  7. * declaration.
  8. *
  9. * Modifications for the OpenRISC architecture:
  10. * Copyright (C) 2003 Matjaz Breskvar <[email protected]>
  11. * Copyright (C) 2005 Gyorgy Jeney <[email protected]>
  12. * Copyright (C) 2010-2011 Jonas Bonn <[email protected]>
  13. */
  14. #include <linux/linkage.h>
  15. #include <linux/pgtable.h>
  16. #include <asm/processor.h>
  17. #include <asm/unistd.h>
  18. #include <asm/thread_info.h>
  19. #include <asm/errno.h>
  20. #include <asm/spr_defs.h>
  21. #include <asm/page.h>
  22. #include <asm/mmu.h>
  23. #include <asm/asm-offsets.h>
  24. #define DISABLE_INTERRUPTS(t1,t2) \
  25. l.mfspr t2,r0,SPR_SR ;\
  26. l.movhi t1,hi(~(SPR_SR_IEE|SPR_SR_TEE)) ;\
  27. l.ori t1,t1,lo(~(SPR_SR_IEE|SPR_SR_TEE)) ;\
  28. l.and t2,t2,t1 ;\
  29. l.mtspr r0,t2,SPR_SR
  30. #define ENABLE_INTERRUPTS(t1) \
  31. l.mfspr t1,r0,SPR_SR ;\
  32. l.ori t1,t1,lo(SPR_SR_IEE|SPR_SR_TEE) ;\
  33. l.mtspr r0,t1,SPR_SR
  34. /* =========================================================[ macros ]=== */
  35. #ifdef CONFIG_TRACE_IRQFLAGS
  36. /*
  37. * Trace irq on/off creating a stack frame.
  38. */
  39. #define TRACE_IRQS_OP(trace_op) \
  40. l.sw -8(r1),r2 /* store frame pointer */ ;\
  41. l.sw -4(r1),r9 /* store return address */ ;\
  42. l.addi r2,r1,0 /* move sp to fp */ ;\
  43. l.jal trace_op ;\
  44. l.addi r1,r1,-8 ;\
  45. l.ori r1,r2,0 /* restore sp */ ;\
  46. l.lwz r9,-4(r1) /* restore return address */ ;\
  47. l.lwz r2,-8(r1) /* restore fp */ ;\
  48. /*
  49. * Trace irq on/off and save registers we need that would otherwise be
  50. * clobbered.
  51. */
  52. #define TRACE_IRQS_SAVE(t1,trace_op) \
  53. l.sw -12(r1),t1 /* save extra reg */ ;\
  54. l.sw -8(r1),r2 /* store frame pointer */ ;\
  55. l.sw -4(r1),r9 /* store return address */ ;\
  56. l.addi r2,r1,0 /* move sp to fp */ ;\
  57. l.jal trace_op ;\
  58. l.addi r1,r1,-12 ;\
  59. l.ori r1,r2,0 /* restore sp */ ;\
  60. l.lwz r9,-4(r1) /* restore return address */ ;\
  61. l.lwz r2,-8(r1) /* restore fp */ ;\
  62. l.lwz t1,-12(r1) /* restore extra reg */
  63. #define TRACE_IRQS_OFF TRACE_IRQS_OP(trace_hardirqs_off)
  64. #define TRACE_IRQS_ON TRACE_IRQS_OP(trace_hardirqs_on)
  65. #define TRACE_IRQS_ON_SYSCALL \
  66. TRACE_IRQS_SAVE(r10,trace_hardirqs_on) ;\
  67. l.lwz r3,PT_GPR3(r1) ;\
  68. l.lwz r4,PT_GPR4(r1) ;\
  69. l.lwz r5,PT_GPR5(r1) ;\
  70. l.lwz r6,PT_GPR6(r1) ;\
  71. l.lwz r7,PT_GPR7(r1) ;\
  72. l.lwz r8,PT_GPR8(r1) ;\
  73. l.lwz r11,PT_GPR11(r1)
  74. #define TRACE_IRQS_OFF_ENTRY \
  75. l.lwz r5,PT_SR(r1) ;\
  76. l.andi r3,r5,(SPR_SR_IEE|SPR_SR_TEE) ;\
  77. l.sfeq r5,r0 /* skip trace if irqs were already off */;\
  78. l.bf 1f ;\
  79. l.nop ;\
  80. TRACE_IRQS_SAVE(r4,trace_hardirqs_off) ;\
  81. 1:
  82. #else
  83. #define TRACE_IRQS_OFF
  84. #define TRACE_IRQS_ON
  85. #define TRACE_IRQS_OFF_ENTRY
  86. #define TRACE_IRQS_ON_SYSCALL
  87. #endif
  88. /*
  89. * We need to disable interrupts at beginning of RESTORE_ALL
  90. * since interrupt might come in after we've loaded EPC return address
  91. * and overwrite EPC with address somewhere in RESTORE_ALL
  92. * which is of course wrong!
  93. */
  94. #define RESTORE_ALL \
  95. DISABLE_INTERRUPTS(r3,r4) ;\
  96. l.lwz r3,PT_PC(r1) ;\
  97. l.mtspr r0,r3,SPR_EPCR_BASE ;\
  98. l.lwz r3,PT_SR(r1) ;\
  99. l.mtspr r0,r3,SPR_ESR_BASE ;\
  100. l.lwz r2,PT_GPR2(r1) ;\
  101. l.lwz r3,PT_GPR3(r1) ;\
  102. l.lwz r4,PT_GPR4(r1) ;\
  103. l.lwz r5,PT_GPR5(r1) ;\
  104. l.lwz r6,PT_GPR6(r1) ;\
  105. l.lwz r7,PT_GPR7(r1) ;\
  106. l.lwz r8,PT_GPR8(r1) ;\
  107. l.lwz r9,PT_GPR9(r1) ;\
  108. l.lwz r10,PT_GPR10(r1) ;\
  109. l.lwz r11,PT_GPR11(r1) ;\
  110. l.lwz r12,PT_GPR12(r1) ;\
  111. l.lwz r13,PT_GPR13(r1) ;\
  112. l.lwz r14,PT_GPR14(r1) ;\
  113. l.lwz r15,PT_GPR15(r1) ;\
  114. l.lwz r16,PT_GPR16(r1) ;\
  115. l.lwz r17,PT_GPR17(r1) ;\
  116. l.lwz r18,PT_GPR18(r1) ;\
  117. l.lwz r19,PT_GPR19(r1) ;\
  118. l.lwz r20,PT_GPR20(r1) ;\
  119. l.lwz r21,PT_GPR21(r1) ;\
  120. l.lwz r22,PT_GPR22(r1) ;\
  121. l.lwz r23,PT_GPR23(r1) ;\
  122. l.lwz r24,PT_GPR24(r1) ;\
  123. l.lwz r25,PT_GPR25(r1) ;\
  124. l.lwz r26,PT_GPR26(r1) ;\
  125. l.lwz r27,PT_GPR27(r1) ;\
  126. l.lwz r28,PT_GPR28(r1) ;\
  127. l.lwz r29,PT_GPR29(r1) ;\
  128. l.lwz r30,PT_GPR30(r1) ;\
  129. l.lwz r31,PT_GPR31(r1) ;\
  130. l.lwz r1,PT_SP(r1) ;\
  131. l.rfe
  132. #define EXCEPTION_ENTRY(handler) \
  133. .global handler ;\
  134. handler: ;\
  135. /* r1, EPCR, ESR a already saved */ ;\
  136. l.sw PT_GPR2(r1),r2 ;\
  137. l.sw PT_GPR3(r1),r3 ;\
  138. /* r4 already save */ ;\
  139. l.sw PT_GPR5(r1),r5 ;\
  140. l.sw PT_GPR6(r1),r6 ;\
  141. l.sw PT_GPR7(r1),r7 ;\
  142. l.sw PT_GPR8(r1),r8 ;\
  143. l.sw PT_GPR9(r1),r9 ;\
  144. /* r10 already saved */ ;\
  145. l.sw PT_GPR11(r1),r11 ;\
  146. /* r12 already saved */ ;\
  147. l.sw PT_GPR13(r1),r13 ;\
  148. l.sw PT_GPR14(r1),r14 ;\
  149. l.sw PT_GPR15(r1),r15 ;\
  150. l.sw PT_GPR16(r1),r16 ;\
  151. l.sw PT_GPR17(r1),r17 ;\
  152. l.sw PT_GPR18(r1),r18 ;\
  153. l.sw PT_GPR19(r1),r19 ;\
  154. l.sw PT_GPR20(r1),r20 ;\
  155. l.sw PT_GPR21(r1),r21 ;\
  156. l.sw PT_GPR22(r1),r22 ;\
  157. l.sw PT_GPR23(r1),r23 ;\
  158. l.sw PT_GPR24(r1),r24 ;\
  159. l.sw PT_GPR25(r1),r25 ;\
  160. l.sw PT_GPR26(r1),r26 ;\
  161. l.sw PT_GPR27(r1),r27 ;\
  162. l.sw PT_GPR28(r1),r28 ;\
  163. l.sw PT_GPR29(r1),r29 ;\
  164. /* r30 already save */ ;\
  165. l.sw PT_GPR31(r1),r31 ;\
  166. TRACE_IRQS_OFF_ENTRY ;\
  167. /* Store -1 in orig_gpr11 for non-syscall exceptions */ ;\
  168. l.addi r30,r0,-1 ;\
  169. l.sw PT_ORIG_GPR11(r1),r30
  170. #define UNHANDLED_EXCEPTION(handler,vector) \
  171. .global handler ;\
  172. handler: ;\
  173. /* r1, EPCR, ESR already saved */ ;\
  174. l.sw PT_GPR2(r1),r2 ;\
  175. l.sw PT_GPR3(r1),r3 ;\
  176. l.sw PT_GPR5(r1),r5 ;\
  177. l.sw PT_GPR6(r1),r6 ;\
  178. l.sw PT_GPR7(r1),r7 ;\
  179. l.sw PT_GPR8(r1),r8 ;\
  180. l.sw PT_GPR9(r1),r9 ;\
  181. /* r10 already saved */ ;\
  182. l.sw PT_GPR11(r1),r11 ;\
  183. /* r12 already saved */ ;\
  184. l.sw PT_GPR13(r1),r13 ;\
  185. l.sw PT_GPR14(r1),r14 ;\
  186. l.sw PT_GPR15(r1),r15 ;\
  187. l.sw PT_GPR16(r1),r16 ;\
  188. l.sw PT_GPR17(r1),r17 ;\
  189. l.sw PT_GPR18(r1),r18 ;\
  190. l.sw PT_GPR19(r1),r19 ;\
  191. l.sw PT_GPR20(r1),r20 ;\
  192. l.sw PT_GPR21(r1),r21 ;\
  193. l.sw PT_GPR22(r1),r22 ;\
  194. l.sw PT_GPR23(r1),r23 ;\
  195. l.sw PT_GPR24(r1),r24 ;\
  196. l.sw PT_GPR25(r1),r25 ;\
  197. l.sw PT_GPR26(r1),r26 ;\
  198. l.sw PT_GPR27(r1),r27 ;\
  199. l.sw PT_GPR28(r1),r28 ;\
  200. l.sw PT_GPR29(r1),r29 ;\
  201. /* r30 already saved */ ;\
  202. l.sw PT_GPR31(r1),r31 ;\
  203. /* Store -1 in orig_gpr11 for non-syscall exceptions */ ;\
  204. l.addi r30,r0,-1 ;\
  205. l.sw PT_ORIG_GPR11(r1),r30 ;\
  206. l.addi r3,r1,0 ;\
  207. /* r4 is exception EA */ ;\
  208. l.addi r5,r0,vector ;\
  209. l.jal unhandled_exception ;\
  210. l.nop ;\
  211. l.j _ret_from_exception ;\
  212. l.nop
  213. /* clobbers 'reg' */
  214. #define CLEAR_LWA_FLAG(reg) \
  215. l.movhi reg,hi(lwa_flag) ;\
  216. l.ori reg,reg,lo(lwa_flag) ;\
  217. l.sw 0(reg),r0
  218. /*
  219. * NOTE: one should never assume that SPR_EPC, SPR_ESR, SPR_EEAR
  220. * contain the same values as when exception we're handling
  221. * occured. in fact they never do. if you need them use
  222. * values saved on stack (for SPR_EPC, SPR_ESR) or content
  223. * of r4 (for SPR_EEAR). for details look at EXCEPTION_HANDLE()
  224. * in 'arch/openrisc/kernel/head.S'
  225. */
  226. /* =====================================================[ exceptions] === */
  227. /* ---[ 0x100: RESET exception ]----------------------------------------- */
  228. EXCEPTION_ENTRY(_tng_kernel_start)
  229. l.jal _start
  230. l.andi r0,r0,0
  231. /* ---[ 0x200: BUS exception ]------------------------------------------- */
  232. EXCEPTION_ENTRY(_bus_fault_handler)
  233. CLEAR_LWA_FLAG(r3)
  234. /* r4: EA of fault (set by EXCEPTION_HANDLE) */
  235. l.jal do_bus_fault
  236. l.addi r3,r1,0 /* pt_regs */
  237. l.j _ret_from_exception
  238. l.nop
  239. /* ---[ 0x300: Data Page Fault exception ]------------------------------- */
  240. EXCEPTION_ENTRY(_dtlb_miss_page_fault_handler)
  241. CLEAR_LWA_FLAG(r3)
  242. l.and r5,r5,r0
  243. l.j 1f
  244. l.nop
  245. EXCEPTION_ENTRY(_data_page_fault_handler)
  246. CLEAR_LWA_FLAG(r3)
  247. /* set up parameters for do_page_fault */
  248. l.ori r5,r0,0x300 // exception vector
  249. 1:
  250. l.addi r3,r1,0 // pt_regs
  251. /* r4 set be EXCEPTION_HANDLE */ // effective address of fault
  252. #ifdef CONFIG_OPENRISC_NO_SPR_SR_DSX
  253. l.lwz r6,PT_PC(r3) // address of an offending insn
  254. l.lwz r6,0(r6) // instruction that caused pf
  255. l.srli r6,r6,26 // check opcode for jump insn
  256. l.sfeqi r6,0 // l.j
  257. l.bf 8f
  258. l.sfeqi r6,1 // l.jal
  259. l.bf 8f
  260. l.sfeqi r6,3 // l.bnf
  261. l.bf 8f
  262. l.sfeqi r6,4 // l.bf
  263. l.bf 8f
  264. l.sfeqi r6,0x11 // l.jr
  265. l.bf 8f
  266. l.sfeqi r6,0x12 // l.jalr
  267. l.bf 8f
  268. l.nop
  269. l.j 9f
  270. l.nop
  271. 8: // offending insn is in delay slot
  272. l.lwz r6,PT_PC(r3) // address of an offending insn
  273. l.addi r6,r6,4
  274. l.lwz r6,0(r6) // instruction that caused pf
  275. l.srli r6,r6,26 // get opcode
  276. 9: // offending instruction opcode loaded in r6
  277. #else
  278. l.mfspr r6,r0,SPR_SR // SR
  279. l.andi r6,r6,SPR_SR_DSX // check for delay slot exception
  280. l.sfne r6,r0 // exception happened in delay slot
  281. l.bnf 7f
  282. l.lwz r6,PT_PC(r3) // address of an offending insn
  283. l.addi r6,r6,4 // offending insn is in delay slot
  284. 7:
  285. l.lwz r6,0(r6) // instruction that caused pf
  286. l.srli r6,r6,26 // check opcode for write access
  287. #endif
  288. l.sfgeui r6,0x33 // check opcode for write access
  289. l.bnf 1f
  290. l.sfleui r6,0x37
  291. l.bnf 1f
  292. l.ori r6,r0,0x1 // write access
  293. l.j 2f
  294. l.nop
  295. 1: l.ori r6,r0,0x0 // !write access
  296. 2:
  297. /* call fault.c handler in openrisc/mm/fault.c */
  298. l.jal do_page_fault
  299. l.nop
  300. l.j _ret_from_exception
  301. l.nop
  302. /* ---[ 0x400: Insn Page Fault exception ]------------------------------- */
  303. EXCEPTION_ENTRY(_itlb_miss_page_fault_handler)
  304. CLEAR_LWA_FLAG(r3)
  305. l.and r5,r5,r0
  306. l.j 1f
  307. l.nop
  308. EXCEPTION_ENTRY(_insn_page_fault_handler)
  309. CLEAR_LWA_FLAG(r3)
  310. /* set up parameters for do_page_fault */
  311. l.ori r5,r0,0x400 // exception vector
  312. 1:
  313. l.addi r3,r1,0 // pt_regs
  314. /* r4 set be EXCEPTION_HANDLE */ // effective address of fault
  315. l.ori r6,r0,0x0 // !write access
  316. /* call fault.c handler in openrisc/mm/fault.c */
  317. l.jal do_page_fault
  318. l.nop
  319. l.j _ret_from_exception
  320. l.nop
  321. /* ---[ 0x500: Timer exception ]----------------------------------------- */
  322. EXCEPTION_ENTRY(_timer_handler)
  323. CLEAR_LWA_FLAG(r3)
  324. l.jal timer_interrupt
  325. l.addi r3,r1,0 /* pt_regs */
  326. l.j _ret_from_intr
  327. l.nop
  328. /* ---[ 0x600: Alignment exception ]-------------------------------------- */
  329. EXCEPTION_ENTRY(_alignment_handler)
  330. CLEAR_LWA_FLAG(r3)
  331. /* r4: EA of fault (set by EXCEPTION_HANDLE) */
  332. l.jal do_unaligned_access
  333. l.addi r3,r1,0 /* pt_regs */
  334. l.j _ret_from_exception
  335. l.nop
  336. #if 0
  337. EXCEPTION_ENTRY(_alignment_handler)
  338. // l.mfspr r2,r0,SPR_EEAR_BASE /* Load the effective address */
  339. l.addi r2,r4,0
  340. // l.mfspr r5,r0,SPR_EPCR_BASE /* Load the insn address */
  341. l.lwz r5,PT_PC(r1)
  342. l.lwz r3,0(r5) /* Load insn */
  343. l.srli r4,r3,26 /* Shift left to get the insn opcode */
  344. l.sfeqi r4,0x00 /* Check if the load/store insn is in delay slot */
  345. l.bf jmp
  346. l.sfeqi r4,0x01
  347. l.bf jmp
  348. l.sfeqi r4,0x03
  349. l.bf jmp
  350. l.sfeqi r4,0x04
  351. l.bf jmp
  352. l.sfeqi r4,0x11
  353. l.bf jr
  354. l.sfeqi r4,0x12
  355. l.bf jr
  356. l.nop
  357. l.j 1f
  358. l.addi r5,r5,4 /* Increment PC to get return insn address */
  359. jmp:
  360. l.slli r4,r3,6 /* Get the signed extended jump length */
  361. l.srai r4,r4,4
  362. l.lwz r3,4(r5) /* Load the real load/store insn */
  363. l.add r5,r5,r4 /* Calculate jump target address */
  364. l.j 1f
  365. l.srli r4,r3,26 /* Shift left to get the insn opcode */
  366. jr:
  367. l.slli r4,r3,9 /* Shift to get the reg nb */
  368. l.andi r4,r4,0x7c
  369. l.lwz r3,4(r5) /* Load the real load/store insn */
  370. l.add r4,r4,r1 /* Load the jump register value from the stack */
  371. l.lwz r5,0(r4)
  372. l.srli r4,r3,26 /* Shift left to get the insn opcode */
  373. 1:
  374. // l.mtspr r0,r5,SPR_EPCR_BASE
  375. l.sw PT_PC(r1),r5
  376. l.sfeqi r4,0x26
  377. l.bf lhs
  378. l.sfeqi r4,0x25
  379. l.bf lhz
  380. l.sfeqi r4,0x22
  381. l.bf lws
  382. l.sfeqi r4,0x21
  383. l.bf lwz
  384. l.sfeqi r4,0x37
  385. l.bf sh
  386. l.sfeqi r4,0x35
  387. l.bf sw
  388. l.nop
  389. 1: l.j 1b /* I don't know what to do */
  390. l.nop
  391. lhs: l.lbs r5,0(r2)
  392. l.slli r5,r5,8
  393. l.lbz r6,1(r2)
  394. l.or r5,r5,r6
  395. l.srli r4,r3,19
  396. l.andi r4,r4,0x7c
  397. l.add r4,r4,r1
  398. l.j align_end
  399. l.sw 0(r4),r5
  400. lhz: l.lbz r5,0(r2)
  401. l.slli r5,r5,8
  402. l.lbz r6,1(r2)
  403. l.or r5,r5,r6
  404. l.srli r4,r3,19
  405. l.andi r4,r4,0x7c
  406. l.add r4,r4,r1
  407. l.j align_end
  408. l.sw 0(r4),r5
  409. lws: l.lbs r5,0(r2)
  410. l.slli r5,r5,24
  411. l.lbz r6,1(r2)
  412. l.slli r6,r6,16
  413. l.or r5,r5,r6
  414. l.lbz r6,2(r2)
  415. l.slli r6,r6,8
  416. l.or r5,r5,r6
  417. l.lbz r6,3(r2)
  418. l.or r5,r5,r6
  419. l.srli r4,r3,19
  420. l.andi r4,r4,0x7c
  421. l.add r4,r4,r1
  422. l.j align_end
  423. l.sw 0(r4),r5
  424. lwz: l.lbz r5,0(r2)
  425. l.slli r5,r5,24
  426. l.lbz r6,1(r2)
  427. l.slli r6,r6,16
  428. l.or r5,r5,r6
  429. l.lbz r6,2(r2)
  430. l.slli r6,r6,8
  431. l.or r5,r5,r6
  432. l.lbz r6,3(r2)
  433. l.or r5,r5,r6
  434. l.srli r4,r3,19
  435. l.andi r4,r4,0x7c
  436. l.add r4,r4,r1
  437. l.j align_end
  438. l.sw 0(r4),r5
  439. sh:
  440. l.srli r4,r3,9
  441. l.andi r4,r4,0x7c
  442. l.add r4,r4,r1
  443. l.lwz r5,0(r4)
  444. l.sb 1(r2),r5
  445. l.srli r5,r5,8
  446. l.j align_end
  447. l.sb 0(r2),r5
  448. sw:
  449. l.srli r4,r3,9
  450. l.andi r4,r4,0x7c
  451. l.add r4,r4,r1
  452. l.lwz r5,0(r4)
  453. l.sb 3(r2),r5
  454. l.srli r5,r5,8
  455. l.sb 2(r2),r5
  456. l.srli r5,r5,8
  457. l.sb 1(r2),r5
  458. l.srli r5,r5,8
  459. l.j align_end
  460. l.sb 0(r2),r5
  461. align_end:
  462. l.j _ret_from_intr
  463. l.nop
  464. #endif
  465. /* ---[ 0x700: Illegal insn exception ]---------------------------------- */
  466. EXCEPTION_ENTRY(_illegal_instruction_handler)
  467. /* r4: EA of fault (set by EXCEPTION_HANDLE) */
  468. l.jal do_illegal_instruction
  469. l.addi r3,r1,0 /* pt_regs */
  470. l.j _ret_from_exception
  471. l.nop
  472. /* ---[ 0x800: External interrupt exception ]---------------------------- */
  473. EXCEPTION_ENTRY(_external_irq_handler)
  474. #ifdef CONFIG_OPENRISC_ESR_EXCEPTION_BUG_CHECK
  475. l.lwz r4,PT_SR(r1) // were interrupts enabled ?
  476. l.andi r4,r4,SPR_SR_IEE
  477. l.sfeqi r4,0
  478. l.bnf 1f // ext irq enabled, all ok.
  479. l.nop
  480. #ifdef CONFIG_PRINTK
  481. l.addi r1,r1,-0x8
  482. l.movhi r3,hi(42f)
  483. l.ori r3,r3,lo(42f)
  484. l.sw 0x0(r1),r3
  485. l.jal _printk
  486. l.sw 0x4(r1),r4
  487. l.addi r1,r1,0x8
  488. .section .rodata, "a"
  489. 42:
  490. .string "\n\rESR interrupt bug: in _external_irq_handler (ESR %x)\n\r"
  491. .align 4
  492. .previous
  493. #endif
  494. l.ori r4,r4,SPR_SR_IEE // fix the bug
  495. // l.sw PT_SR(r1),r4
  496. 1:
  497. #endif
  498. CLEAR_LWA_FLAG(r3)
  499. l.addi r3,r1,0
  500. l.movhi r8,hi(generic_handle_arch_irq)
  501. l.ori r8,r8,lo(generic_handle_arch_irq)
  502. l.jalr r8
  503. l.nop
  504. l.j _ret_from_intr
  505. l.nop
  506. /* ---[ 0x900: DTLB miss exception ]------------------------------------- */
  507. /* ---[ 0xa00: ITLB miss exception ]------------------------------------- */
  508. /* ---[ 0xb00: Range exception ]----------------------------------------- */
  509. UNHANDLED_EXCEPTION(_vector_0xb00,0xb00)
  510. /* ---[ 0xc00: Syscall exception ]--------------------------------------- */
  511. /*
  512. * Syscalls are a special type of exception in that they are
  513. * _explicitly_ invoked by userspace and can therefore be
  514. * held to conform to the same ABI as normal functions with
  515. * respect to whether registers are preserved across the call
  516. * or not.
  517. */
  518. /* Upon syscall entry we just save the callee-saved registers
  519. * and not the call-clobbered ones.
  520. */
  521. _string_syscall_return:
  522. .string "syscall r9:0x%08x -> syscall(%ld) return %ld\0"
  523. .align 4
  524. ENTRY(_sys_call_handler)
  525. /* r1, EPCR, ESR a already saved */
  526. l.sw PT_GPR2(r1),r2
  527. /* r3-r8 must be saved because syscall restart relies
  528. * on us being able to restart the syscall args... technically
  529. * they should be clobbered, otherwise
  530. */
  531. l.sw PT_GPR3(r1),r3
  532. /*
  533. * r4 already saved
  534. * r4 holds the EEAR address of the fault, use it as screatch reg and
  535. * then load the original r4
  536. */
  537. CLEAR_LWA_FLAG(r4)
  538. l.lwz r4,PT_GPR4(r1)
  539. l.sw PT_GPR5(r1),r5
  540. l.sw PT_GPR6(r1),r6
  541. l.sw PT_GPR7(r1),r7
  542. l.sw PT_GPR8(r1),r8
  543. l.sw PT_GPR9(r1),r9
  544. /* r10 already saved */
  545. l.sw PT_GPR11(r1),r11
  546. /* orig_gpr11 must be set for syscalls */
  547. l.sw PT_ORIG_GPR11(r1),r11
  548. /* r12,r13 already saved */
  549. /* r14-r28 (even) aren't touched by the syscall fast path below
  550. * so we don't need to save them. However, the functions that return
  551. * to userspace via a call to switch() DO need to save these because
  552. * switch() effectively clobbers them... saving these registers for
  553. * such functions is handled in their syscall wrappers (see fork, vfork,
  554. * and clone, below).
  555. /* r30 is the only register we clobber in the fast path */
  556. /* r30 already saved */
  557. /* l.sw PT_GPR30(r1),r30 */
  558. _syscall_check_trace_enter:
  559. /* syscalls run with interrupts enabled */
  560. TRACE_IRQS_ON_SYSCALL
  561. ENABLE_INTERRUPTS(r29) // enable interrupts, r29 is temp
  562. /* If TIF_SYSCALL_TRACE is set, then we want to do syscall tracing */
  563. l.lwz r30,TI_FLAGS(r10)
  564. l.andi r30,r30,_TIF_SYSCALL_TRACE
  565. l.sfne r30,r0
  566. l.bf _syscall_trace_enter
  567. l.nop
  568. _syscall_check:
  569. /* Ensure that the syscall number is reasonable */
  570. l.sfgeui r11,__NR_syscalls
  571. l.bf _syscall_badsys
  572. l.nop
  573. _syscall_call:
  574. l.movhi r29,hi(sys_call_table)
  575. l.ori r29,r29,lo(sys_call_table)
  576. l.slli r11,r11,2
  577. l.add r29,r29,r11
  578. l.lwz r29,0(r29)
  579. l.jalr r29
  580. l.nop
  581. _syscall_return:
  582. /* All syscalls return here... just pay attention to ret_from_fork
  583. * which does it in a round-about way.
  584. */
  585. l.sw PT_GPR11(r1),r11 // save return value
  586. #if 0
  587. _syscall_debug:
  588. l.movhi r3,hi(_string_syscall_return)
  589. l.ori r3,r3,lo(_string_syscall_return)
  590. l.ori r27,r0,2
  591. l.sw -4(r1),r27
  592. l.sw -8(r1),r11
  593. l.lwz r29,PT_ORIG_GPR11(r1)
  594. l.sw -12(r1),r29
  595. l.lwz r29,PT_GPR9(r1)
  596. l.sw -16(r1),r29
  597. l.movhi r27,hi(_printk)
  598. l.ori r27,r27,lo(_printk)
  599. l.jalr r27
  600. l.addi r1,r1,-16
  601. l.addi r1,r1,16
  602. #endif
  603. #if 0
  604. _syscall_show_regs:
  605. l.movhi r27,hi(show_registers)
  606. l.ori r27,r27,lo(show_registers)
  607. l.jalr r27
  608. l.or r3,r1,r1
  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. * r14-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 r14,PT_GPR14(r1)
  851. l.lwz r16,PT_GPR16(r1)
  852. l.lwz r18,PT_GPR18(r1)
  853. l.lwz r20,PT_GPR20(r1)
  854. l.lwz r22,PT_GPR22(r1)
  855. l.lwz r24,PT_GPR24(r1)
  856. l.lwz r26,PT_GPR26(r1)
  857. l.lwz r28,PT_GPR28(r1)
  858. l.j _syscall_return
  859. l.nop
  860. /* ========================================================[ switch ] === */
  861. /*
  862. * This routine switches between two different tasks. The process
  863. * state of one is saved on its kernel stack. Then the state
  864. * of the other is restored from its kernel stack. The memory
  865. * management hardware is updated to the second process's state.
  866. * Finally, we can return to the second process, via the 'return'.
  867. *
  868. * Note: there are two ways to get to the "going out" portion
  869. * of this code; either by coming in via the entry (_switch)
  870. * or via "fork" which must set up an environment equivalent
  871. * to the "_switch" path. If you change this (or in particular, the
  872. * SAVE_REGS macro), you'll have to change the fork code also.
  873. */
  874. /* _switch MUST never lay on page boundry, cause it runs from
  875. * effective addresses and beeing interrupted by iTLB miss would kill it.
  876. * dTLB miss seems to never accour in the bad place since data accesses
  877. * are from task structures which are always page aligned.
  878. *
  879. * The problem happens in RESTORE_ALL where we first set the EPCR
  880. * register, then load the previous register values and only at the end call
  881. * the l.rfe instruction. If get TLB miss in beetwen the EPCR register gets
  882. * garbled and we end up calling l.rfe with the wrong EPCR. (same probably
  883. * holds for ESR)
  884. *
  885. * To avoid this problems it is sufficient to align _switch to
  886. * some nice round number smaller than it's size...
  887. */
  888. /* ABI rules apply here... we either enter _switch via schedule() or via
  889. * an imaginary call to which we shall return at return_from_fork. Either
  890. * way, we are a function call and only need to preserve the callee-saved
  891. * registers when we return. As such, we don't need to save the registers
  892. * on the stack that we won't be returning as they were...
  893. */
  894. .align 0x400
  895. ENTRY(_switch)
  896. /* We don't store SR as _switch only gets called in a context where
  897. * the SR will be the same going in and coming out... */
  898. /* Set up new pt_regs struct for saving task state */
  899. l.addi r1,r1,-(INT_FRAME_SIZE)
  900. /* No need to store r1/PT_SP as it goes into KSP below */
  901. l.sw PT_GPR2(r1),r2
  902. l.sw PT_GPR9(r1),r9
  903. /* Save callee-saved registers to the new pt_regs */
  904. l.sw PT_GPR14(r1),r14
  905. l.sw PT_GPR16(r1),r16
  906. l.sw PT_GPR18(r1),r18
  907. l.sw PT_GPR20(r1),r20
  908. l.sw PT_GPR22(r1),r22
  909. l.sw PT_GPR24(r1),r24
  910. l.sw PT_GPR26(r1),r26
  911. l.sw PT_GPR28(r1),r28
  912. l.sw PT_GPR30(r1),r30
  913. l.addi r11,r10,0 /* Save old 'current' to 'last' return value*/
  914. /* We use thread_info->ksp for storing the address of the above
  915. * structure so that we can get back to it later... we don't want
  916. * to lose the value of thread_info->ksp, though, so store it as
  917. * pt_regs->sp so that we can easily restore it when we are made
  918. * live again...
  919. */
  920. /* Save the old value of thread_info->ksp as pt_regs->sp */
  921. l.lwz r29,TI_KSP(r10)
  922. l.sw PT_SP(r1),r29
  923. /* Swap kernel stack pointers */
  924. l.sw TI_KSP(r10),r1 /* Save old stack pointer */
  925. l.or r10,r4,r0 /* Set up new current_thread_info */
  926. l.lwz r1,TI_KSP(r10) /* Load new stack pointer */
  927. /* Restore the old value of thread_info->ksp */
  928. l.lwz r29,PT_SP(r1)
  929. l.sw TI_KSP(r10),r29
  930. /* ...and restore the registers, except r11 because the return value
  931. * has already been set above.
  932. */
  933. l.lwz r2,PT_GPR2(r1)
  934. l.lwz r9,PT_GPR9(r1)
  935. /* No need to restore r10 */
  936. /* ...and do not restore r11 */
  937. /* Restore callee-saved registers */
  938. l.lwz r14,PT_GPR14(r1)
  939. l.lwz r16,PT_GPR16(r1)
  940. l.lwz r18,PT_GPR18(r1)
  941. l.lwz r20,PT_GPR20(r1)
  942. l.lwz r22,PT_GPR22(r1)
  943. l.lwz r24,PT_GPR24(r1)
  944. l.lwz r26,PT_GPR26(r1)
  945. l.lwz r28,PT_GPR28(r1)
  946. l.lwz r30,PT_GPR30(r1)
  947. /* Unwind stack to pre-switch state */
  948. l.addi r1,r1,(INT_FRAME_SIZE)
  949. /* Return via the link-register back to where we 'came from', where
  950. * that may be either schedule(), ret_from_fork(), or
  951. * ret_from_kernel_thread(). If we are returning to a new thread,
  952. * we are expected to have set up the arg to schedule_tail already,
  953. * hence we do so here unconditionally:
  954. */
  955. l.lwz r3,TI_TASK(r3) /* Load 'prev' as schedule_tail arg */
  956. l.jr r9
  957. l.nop
  958. /* ==================================================================== */
  959. /* These all use the delay slot for setting the argument register, so the
  960. * jump is always happening after the l.addi instruction.
  961. *
  962. * These are all just wrappers that don't touch the link-register r9, so the
  963. * return from the "real" syscall function will return back to the syscall
  964. * code that did the l.jal that brought us here.
  965. */
  966. /* fork requires that we save all the callee-saved registers because they
  967. * are all effectively clobbered by the call to _switch. Here we store
  968. * all the registers that aren't touched by the syscall fast path and thus
  969. * weren't saved there.
  970. */
  971. _fork_save_extra_regs_and_call:
  972. l.sw PT_GPR14(r1),r14
  973. l.sw PT_GPR16(r1),r16
  974. l.sw PT_GPR18(r1),r18
  975. l.sw PT_GPR20(r1),r20
  976. l.sw PT_GPR22(r1),r22
  977. l.sw PT_GPR24(r1),r24
  978. l.sw PT_GPR26(r1),r26
  979. l.jr r29
  980. l.sw PT_GPR28(r1),r28
  981. ENTRY(__sys_clone)
  982. l.movhi r29,hi(sys_clone)
  983. l.j _fork_save_extra_regs_and_call
  984. l.ori r29,r29,lo(sys_clone)
  985. ENTRY(__sys_clone3)
  986. l.movhi r29,hi(sys_clone3)
  987. l.j _fork_save_extra_regs_and_call
  988. l.ori r29,r29,lo(sys_clone3)
  989. ENTRY(__sys_fork)
  990. l.movhi r29,hi(sys_fork)
  991. l.j _fork_save_extra_regs_and_call
  992. l.ori r29,r29,lo(sys_fork)
  993. ENTRY(sys_rt_sigreturn)
  994. l.jal _sys_rt_sigreturn
  995. l.addi r3,r1,0
  996. l.sfne r30,r0
  997. l.bnf _no_syscall_trace
  998. l.nop
  999. l.jal do_syscall_trace_leave
  1000. l.addi r3,r1,0
  1001. _no_syscall_trace:
  1002. l.j _resume_userspace
  1003. l.nop
  1004. /* This is a catch-all syscall for atomic instructions for the OpenRISC 1000.
  1005. * The functions takes a variable number of parameters depending on which
  1006. * particular flavour of atomic you want... parameter 1 is a flag identifying
  1007. * the atomic in question. Currently, this function implements the
  1008. * following variants:
  1009. *
  1010. * XCHG:
  1011. * @flag: 1
  1012. * @ptr1:
  1013. * @ptr2:
  1014. * Atomically exchange the values in pointers 1 and 2.
  1015. *
  1016. */
  1017. ENTRY(sys_or1k_atomic)
  1018. /* FIXME: This ignores r3 and always does an XCHG */
  1019. DISABLE_INTERRUPTS(r17,r19)
  1020. l.lwz r29,0(r4)
  1021. l.lwz r27,0(r5)
  1022. l.sw 0(r4),r27
  1023. l.sw 0(r5),r29
  1024. ENABLE_INTERRUPTS(r17)
  1025. l.jr r9
  1026. l.or r11,r0,r0
  1027. /* ============================================================[ EOF ]=== */