entry.S 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. /* arch/arm26/kernel/entry.S
  2. *
  3. * Assembled from chunks of code in arch/arm
  4. *
  5. * Copyright (C) 2003 Ian Molton
  6. * Based on the work of RMK.
  7. *
  8. */
  9. #include <linux/linkage.h>
  10. #include <asm/assembler.h>
  11. #include <asm/asm_offsets.h>
  12. #include <asm/errno.h>
  13. #include <asm/hardware.h>
  14. #include <asm/sysirq.h>
  15. #include <asm/thread_info.h>
  16. #include <asm/page.h>
  17. #include <asm/ptrace.h>
  18. .macro zero_fp
  19. #ifndef CONFIG_NO_FRAME_POINTER
  20. mov fp, #0
  21. #endif
  22. .endm
  23. .text
  24. @ Bad Abort numbers
  25. @ -----------------
  26. @
  27. #define BAD_PREFETCH 0
  28. #define BAD_DATA 1
  29. #define BAD_ADDREXCPTN 2
  30. #define BAD_IRQ 3
  31. #define BAD_UNDEFINSTR 4
  32. @ OS version number used in SWIs
  33. @ RISC OS is 0
  34. @ RISC iX is 8
  35. @
  36. #define OS_NUMBER 9
  37. #define ARMSWI_OFFSET 0x000f0000
  38. @
  39. @ Stack format (ensured by USER_* and SVC_*)
  40. @ PSR and PC are comined on arm26
  41. @
  42. #define S_OFF 8
  43. #define S_OLD_R0 64
  44. #define S_PC 60
  45. #define S_LR 56
  46. #define S_SP 52
  47. #define S_IP 48
  48. #define S_FP 44
  49. #define S_R10 40
  50. #define S_R9 36
  51. #define S_R8 32
  52. #define S_R7 28
  53. #define S_R6 24
  54. #define S_R5 20
  55. #define S_R4 16
  56. #define S_R3 12
  57. #define S_R2 8
  58. #define S_R1 4
  59. #define S_R0 0
  60. .macro save_user_regs
  61. str r0, [sp, #-4]! @ Store SVC r0
  62. str lr, [sp, #-4]! @ Store user mode PC
  63. sub sp, sp, #15*4
  64. stmia sp, {r0 - lr}^ @ Store the other user-mode regs
  65. mov r0, r0
  66. .endm
  67. .macro slow_restore_user_regs
  68. ldmia sp, {r0 - lr}^ @ restore the user regs not including PC
  69. mov r0, r0
  70. ldr lr, [sp, #15*4] @ get user PC
  71. add sp, sp, #15*4+8 @ free stack
  72. movs pc, lr @ return
  73. .endm
  74. .macro fast_restore_user_regs
  75. add sp, sp, #S_OFF
  76. ldmib sp, {r1 - lr}^
  77. mov r0, r0
  78. ldr lr, [sp, #15*4]
  79. add sp, sp, #15*4+8
  80. movs pc, lr
  81. .endm
  82. .macro save_svc_regs
  83. str sp, [sp, #-16]!
  84. str lr, [sp, #8]
  85. str lr, [sp, #4]
  86. stmfd sp!, {r0 - r12}
  87. mov r0, #-1
  88. str r0, [sp, #S_OLD_R0]
  89. zero_fp
  90. .endm
  91. .macro save_svc_regs_irq
  92. str sp, [sp, #-16]!
  93. str lr, [sp, #4]
  94. ldr lr, .LCirq
  95. ldr lr, [lr]
  96. str lr, [sp, #8]
  97. stmfd sp!, {r0 - r12}
  98. mov r0, #-1
  99. str r0, [sp, #S_OLD_R0]
  100. zero_fp
  101. .endm
  102. .macro restore_svc_regs
  103. ldmfd sp, {r0 - pc}^
  104. .endm
  105. .macro mask_pc, rd, rm
  106. bic \rd, \rm, #PCMASK
  107. .endm
  108. .macro disable_irqs, temp
  109. mov \temp, pc
  110. orr \temp, \temp, #PSR_I_BIT
  111. teqp \temp, #0
  112. .endm
  113. .macro enable_irqs, temp
  114. mov \temp, pc
  115. and \temp, \temp, #~PSR_I_BIT
  116. teqp \temp, #0
  117. .endm
  118. .macro initialise_traps_extra
  119. .endm
  120. .macro get_thread_info, rd
  121. mov \rd, sp, lsr #13
  122. mov \rd, \rd, lsl #13
  123. .endm
  124. /*
  125. * These are the registers used in the syscall handler, and allow us to
  126. * have in theory up to 7 arguments to a function - r0 to r6.
  127. *
  128. * Note that tbl == why is intentional.
  129. *
  130. * We must set at least "tsk" and "why" when calling ret_with_reschedule.
  131. */
  132. scno .req r7 @ syscall number
  133. tbl .req r8 @ syscall table pointer
  134. why .req r8 @ Linux syscall (!= 0)
  135. tsk .req r9 @ current thread_info
  136. /*
  137. * Get the system call number.
  138. */
  139. .macro get_scno
  140. mask_pc lr, lr
  141. ldr scno, [lr, #-4] @ get SWI instruction
  142. .endm
  143. /*
  144. * -----------------------------------------------------------------------
  145. */
  146. /*
  147. * We rely on the fact that R0 is at the bottom of the stack (due to
  148. * slow/fast restore user regs).
  149. */
  150. #if S_R0 != 0
  151. #error "Please fix"
  152. #endif
  153. /*
  154. * This is the fast syscall return path. We do as little as
  155. * possible here, and this includes saving r0 back into the SVC
  156. * stack.
  157. */
  158. ret_fast_syscall:
  159. disable_irqs r1 @ disable interrupts
  160. ldr r1, [tsk, #TI_FLAGS]
  161. tst r1, #_TIF_WORK_MASK
  162. bne fast_work_pending
  163. fast_restore_user_regs
  164. /*
  165. * Ok, we need to do extra processing, enter the slow path.
  166. */
  167. fast_work_pending:
  168. str r0, [sp, #S_R0+S_OFF]! @ returned r0
  169. work_pending:
  170. tst r1, #_TIF_NEED_RESCHED
  171. bne work_resched
  172. tst r1, #_TIF_NOTIFY_RESUME | _TIF_SIGPENDING
  173. beq no_work_pending
  174. mov r0, sp @ 'regs'
  175. mov r2, why @ 'syscall'
  176. bl do_notify_resume
  177. disable_irqs r1 @ disable interrupts
  178. b no_work_pending
  179. work_resched:
  180. bl schedule
  181. /*
  182. * "slow" syscall return path. "why" tells us if this was a real syscall.
  183. */
  184. ENTRY(ret_to_user)
  185. ret_slow_syscall:
  186. disable_irqs r1 @ disable interrupts
  187. ldr r1, [tsk, #TI_FLAGS]
  188. tst r1, #_TIF_WORK_MASK
  189. bne work_pending
  190. no_work_pending:
  191. slow_restore_user_regs
  192. /*
  193. * This is how we return from a fork.
  194. */
  195. ENTRY(ret_from_fork)
  196. bl schedule_tail
  197. get_thread_info tsk
  198. ldr r1, [tsk, #TI_FLAGS] @ check for syscall tracing
  199. mov why, #1
  200. tst r1, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  201. beq ret_slow_syscall
  202. mov r1, sp
  203. mov r0, #1 @ trace exit [IP = 1]
  204. bl syscall_trace
  205. b ret_slow_syscall
  206. // FIXME - is this strictly necessary?
  207. #include "calls.S"
  208. /*=============================================================================
  209. * SWI handler
  210. *-----------------------------------------------------------------------------
  211. */
  212. .align 5
  213. ENTRY(vector_swi)
  214. save_user_regs
  215. zero_fp
  216. get_scno
  217. #ifdef CONFIG_ALIGNMENT_TRAP
  218. ldr ip, __cr_alignment
  219. ldr ip, [ip]
  220. mcr p15, 0, ip, c1, c0 @ update control register
  221. #endif
  222. enable_irqs ip
  223. str r4, [sp, #-S_OFF]! @ push fifth arg
  224. get_thread_info tsk
  225. ldr ip, [tsk, #TI_FLAGS] @ check for syscall tracing
  226. bic scno, scno, #0xff000000 @ mask off SWI op-code
  227. eor scno, scno, #OS_NUMBER << 20 @ check OS number
  228. adr tbl, sys_call_table @ load syscall table pointer
  229. tst ip, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  230. bne __sys_trace
  231. adral lr, ret_fast_syscall @ set return address
  232. orral lr, lr, #PSR_I_BIT | MODE_SVC26 @ Force SVC mode on return
  233. cmp scno, #NR_syscalls @ check upper syscall limit
  234. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  235. add r1, sp, #S_OFF
  236. 2: mov why, #0 @ no longer a real syscall
  237. cmp scno, #ARMSWI_OFFSET
  238. eor r0, scno, #OS_NUMBER << 20 @ put OS number back
  239. bcs arm_syscall
  240. b sys_ni_syscall @ not private func
  241. /*
  242. * This is the really slow path. We're going to be doing
  243. * context switches, and waiting for our parent to respond.
  244. */
  245. __sys_trace:
  246. add r1, sp, #S_OFF
  247. mov r0, #0 @ trace entry [IP = 0]
  248. bl syscall_trace
  249. adral lr, __sys_trace_return @ set return address
  250. orral lr, lr, #PSR_I_BIT | MODE_SVC26 @ Force SVC mode on return
  251. add r1, sp, #S_R0 + S_OFF @ pointer to regs
  252. cmp scno, #NR_syscalls @ check upper syscall limit
  253. ldmccia r1, {r0 - r3} @ have to reload r0 - r3
  254. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  255. b 2b
  256. __sys_trace_return:
  257. str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
  258. mov r1, sp
  259. mov r0, #1 @ trace exit [IP = 1]
  260. bl syscall_trace
  261. b ret_slow_syscall
  262. .align 5
  263. #ifdef CONFIG_ALIGNMENT_TRAP
  264. .type __cr_alignment, #object
  265. __cr_alignment:
  266. .word cr_alignment
  267. #endif
  268. .type sys_call_table, #object
  269. ENTRY(sys_call_table)
  270. #include "calls.S"
  271. /*============================================================================
  272. * Special system call wrappers
  273. */
  274. @ r0 = syscall number
  275. @ r5 = syscall table
  276. .type sys_syscall, #function
  277. sys_syscall:
  278. eor scno, r0, #OS_NUMBER << 20
  279. cmp scno, #NR_syscalls @ check range
  280. stmleia sp, {r5, r6} @ shuffle args
  281. movle r0, r1
  282. movle r1, r2
  283. movle r2, r3
  284. movle r3, r4
  285. ldrle pc, [tbl, scno, lsl #2]
  286. b sys_ni_syscall
  287. sys_fork_wrapper:
  288. add r0, sp, #S_OFF
  289. b sys_fork
  290. sys_vfork_wrapper:
  291. add r0, sp, #S_OFF
  292. b sys_vfork
  293. sys_execve_wrapper:
  294. add r3, sp, #S_OFF
  295. b sys_execve
  296. sys_clone_wapper:
  297. add r2, sp, #S_OFF
  298. b sys_clone
  299. sys_sigsuspend_wrapper:
  300. add r3, sp, #S_OFF
  301. b sys_sigsuspend
  302. sys_rt_sigsuspend_wrapper:
  303. add r2, sp, #S_OFF
  304. b sys_rt_sigsuspend
  305. sys_sigreturn_wrapper:
  306. add r0, sp, #S_OFF
  307. b sys_sigreturn
  308. sys_rt_sigreturn_wrapper:
  309. add r0, sp, #S_OFF
  310. b sys_rt_sigreturn
  311. sys_sigaltstack_wrapper:
  312. ldr r2, [sp, #S_OFF + S_SP]
  313. b do_sigaltstack
  314. /*
  315. * Note: off_4k (r5) is always units of 4K. If we can't do the requested
  316. * offset, we return EINVAL. FIXME - this lost some stuff from arm32 to
  317. * ifdefs. check it out.
  318. */
  319. sys_mmap2:
  320. tst r5, #((1 << (PAGE_SHIFT - 12)) - 1)
  321. moveq r5, r5, lsr #PAGE_SHIFT - 12
  322. streq r5, [sp, #4]
  323. beq do_mmap2
  324. mov r0, #-EINVAL
  325. RETINSTR(mov,pc, lr)
  326. /*
  327. * Design issues:
  328. * - We have several modes that each vector can be called from,
  329. * each with its own set of registers. On entry to any vector,
  330. * we *must* save the registers used in *that* mode.
  331. *
  332. * - This code must be as fast as possible.
  333. *
  334. * There are a few restrictions on the vectors:
  335. * - the SWI vector cannot be called from *any* non-user mode
  336. *
  337. * - the FP emulator is *never* called from *any* non-user mode undefined
  338. * instruction.
  339. *
  340. */
  341. .text
  342. .macro handle_irq
  343. 1: mov r4, #IOC_BASE
  344. ldrb r6, [r4, #0x24] @ get high priority first
  345. adr r5, irq_prio_h
  346. teq r6, #0
  347. ldreqb r6, [r4, #0x14] @ get low priority
  348. adreq r5, irq_prio_l
  349. teq r6, #0 @ If an IRQ happened...
  350. ldrneb r0, [r5, r6] @ get IRQ number
  351. movne r1, sp @ get struct pt_regs
  352. adrne lr, 1b @ Set return address to 1b
  353. orrne lr, lr, #PSR_I_BIT | MODE_SVC26 @ (and force SVC mode)
  354. bne asm_do_IRQ @ process IRQ (if asserted)
  355. .endm
  356. /*
  357. * Interrupt table (incorporates priority)
  358. */
  359. .macro irq_prio_table
  360. irq_prio_l: .byte 0, 0, 1, 0, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3
  361. .byte 4, 0, 1, 0, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3
  362. .byte 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
  363. .byte 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
  364. .byte 6, 6, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3
  365. .byte 6, 6, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3
  366. .byte 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
  367. .byte 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
  368. .byte 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
  369. .byte 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
  370. .byte 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
  371. .byte 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
  372. .byte 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
  373. .byte 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
  374. .byte 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
  375. .byte 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
  376. irq_prio_h: .byte 0, 8, 9, 8,10,10,10,10,11,11,11,11,10,10,10,10
  377. .byte 12, 8, 9, 8,10,10,10,10,11,11,11,11,10,10,10,10
  378. .byte 13,13,13,13,10,10,10,10,11,11,11,11,10,10,10,10
  379. .byte 13,13,13,13,10,10,10,10,11,11,11,11,10,10,10,10
  380. .byte 14,14,14,14,10,10,10,10,11,11,11,11,10,10,10,10
  381. .byte 14,14,14,14,10,10,10,10,11,11,11,11,10,10,10,10
  382. .byte 13,13,13,13,10,10,10,10,11,11,11,11,10,10,10,10
  383. .byte 13,13,13,13,10,10,10,10,11,11,11,11,10,10,10,10
  384. .byte 15,15,15,15,10,10,10,10,11,11,11,11,10,10,10,10
  385. .byte 15,15,15,15,10,10,10,10,11,11,11,11,10,10,10,10
  386. .byte 13,13,13,13,10,10,10,10,11,11,11,11,10,10,10,10
  387. .byte 13,13,13,13,10,10,10,10,11,11,11,11,10,10,10,10
  388. .byte 15,15,15,15,10,10,10,10,11,11,11,11,10,10,10,10
  389. .byte 15,15,15,15,10,10,10,10,11,11,11,11,10,10,10,10
  390. .byte 13,13,13,13,10,10,10,10,11,11,11,11,10,10,10,10
  391. .byte 13,13,13,13,10,10,10,10,11,11,11,11,10,10,10,10
  392. .endm
  393. #if 1
  394. /*
  395. * Uncomment these if you wish to get more debugging into about data aborts.
  396. * FIXME - I bet we can find a way to encode these and keep performance.
  397. */
  398. #define FAULT_CODE_LDRSTRPOST 0x80
  399. #define FAULT_CODE_LDRSTRPRE 0x40
  400. #define FAULT_CODE_LDRSTRREG 0x20
  401. #define FAULT_CODE_LDMSTM 0x10
  402. #define FAULT_CODE_LDCSTC 0x08
  403. #endif
  404. #define FAULT_CODE_PREFETCH 0x04
  405. #define FAULT_CODE_WRITE 0x02
  406. #define FAULT_CODE_FORCECOW 0x01
  407. /*=============================================================================
  408. * Undefined FIQs
  409. *-----------------------------------------------------------------------------
  410. */
  411. _unexp_fiq: ldr sp, .LCfiq
  412. mov r12, #IOC_BASE
  413. strb r12, [r12, #0x38] @ Disable FIQ register
  414. teqp pc, #PSR_I_BIT | PSR_F_BIT | MODE_SVC26
  415. mov r0, r0
  416. stmfd sp!, {r0 - r3, ip, lr}
  417. adr r0, Lfiqmsg
  418. bl printk
  419. ldmfd sp!, {r0 - r3, ip, lr}
  420. teqp pc, #PSR_I_BIT | PSR_F_BIT | MODE_FIQ26
  421. mov r0, r0
  422. movs pc, lr
  423. Lfiqmsg: .ascii "*** Unexpected FIQ\n\0"
  424. .align
  425. .LCfiq: .word __temp_fiq
  426. .LCirq: .word __temp_irq
  427. /*=============================================================================
  428. * Undefined instruction handler
  429. *-----------------------------------------------------------------------------
  430. * Handles floating point instructions
  431. */
  432. vector_undefinstr:
  433. tst lr, #MODE_SVC26 @ did we come from a non-user mode?
  434. bne __und_svc @ yes - deal with it.
  435. /* Otherwise, fall through for the user-space (common) case. */
  436. save_user_regs
  437. zero_fp @ zero frame pointer
  438. teqp pc, #PSR_I_BIT | MODE_SVC26 @ disable IRQs
  439. .Lbug_undef:
  440. ldr r4, .LC2
  441. ldr pc, [r4] @ Call FP module entry point
  442. /* FIXME - should we trap for a null pointer here? */
  443. /* The SVC mode case */
  444. __und_svc: save_svc_regs @ Non-user mode
  445. mask_pc r0, lr
  446. and r2, lr, #3
  447. sub r0, r0, #4
  448. mov r1, sp
  449. bl do_undefinstr
  450. restore_svc_regs
  451. /* We get here if the FP emulator doesnt handle the undef instr.
  452. * If the insn WAS handled, the emulator jumps to ret_from_exception by itself/
  453. */
  454. .globl fpundefinstr
  455. fpundefinstr:
  456. mov r0, lr
  457. mov r1, sp
  458. teqp pc, #MODE_SVC26
  459. bl do_undefinstr
  460. b ret_from_exception @ Normal FP exit
  461. #if defined CONFIG_FPE_NWFPE || defined CONFIG_FPE_FASTFPE
  462. /* The FPE is always present */
  463. .equ fpe_not_present, 0
  464. #else
  465. /* We get here if an undefined instruction happens and the floating
  466. * point emulator is not present. If the offending instruction was
  467. * a WFS, we just perform a normal return as if we had emulated the
  468. * operation. This is a hack to allow some basic userland binaries
  469. * to run so that the emulator module proper can be loaded. --philb
  470. * FIXME - probably a broken useless hack...
  471. */
  472. fpe_not_present:
  473. adr r10, wfs_mask_data
  474. ldmia r10, {r4, r5, r6, r7, r8}
  475. ldr r10, [sp, #S_PC] @ Load PC
  476. sub r10, r10, #4
  477. mask_pc r10, r10
  478. ldrt r10, [r10] @ get instruction
  479. and r5, r10, r5
  480. teq r5, r4 @ Is it WFS?
  481. beq ret_from_exception
  482. and r5, r10, r8
  483. teq r5, r6 @ Is it LDF/STF on sp or fp?
  484. teqne r5, r7
  485. bne fpundefinstr
  486. tst r10, #0x00200000 @ Does it have WB
  487. beq ret_from_exception
  488. and r4, r10, #255 @ get offset
  489. and r6, r10, #0x000f0000
  490. tst r10, #0x00800000 @ +/-
  491. ldr r5, [sp, r6, lsr #14] @ Load reg
  492. rsbeq r4, r4, #0
  493. add r5, r5, r4, lsl #2
  494. str r5, [sp, r6, lsr #14] @ Save reg
  495. b ret_from_exception
  496. wfs_mask_data: .word 0x0e200110 @ WFS/RFS
  497. .word 0x0fef0fff
  498. .word 0x0d0d0100 @ LDF [sp]/STF [sp]
  499. .word 0x0d0b0100 @ LDF [fp]/STF [fp]
  500. .word 0x0f0f0f00
  501. #endif
  502. .LC2: .word fp_enter
  503. /*=============================================================================
  504. * Prefetch abort handler
  505. *-----------------------------------------------------------------------------
  506. */
  507. #define DEBUG_UNDEF
  508. /* remember: lr = USR pc */
  509. vector_prefetch:
  510. sub lr, lr, #4
  511. tst lr, #MODE_SVC26
  512. bne __pabt_invalid
  513. save_user_regs
  514. teqp pc, #MODE_SVC26 @ Enable IRQs...
  515. mask_pc r0, lr @ Address of abort
  516. mov r1, sp @ Tasks registers
  517. bl do_PrefetchAbort
  518. teq r0, #0 @ If non-zero, we believe this abort..
  519. bne ret_from_exception
  520. #ifdef DEBUG_UNDEF
  521. adr r0, t
  522. bl printk
  523. #endif
  524. ldr lr, [sp,#S_PC] @ FIXME program to test this on. I think its
  525. b .Lbug_undef @ broken at the moment though!)
  526. __pabt_invalid: save_svc_regs
  527. mov r0, sp @ Prefetch aborts are definitely *not*
  528. mov r1, #BAD_PREFETCH @ allowed in non-user modes. We cant
  529. and r2, lr, #3 @ recover from this problem.
  530. b bad_mode
  531. #ifdef DEBUG_UNDEF
  532. t: .ascii "*** undef ***\r\n\0"
  533. .align
  534. #endif
  535. /*=============================================================================
  536. * Address exception handler
  537. *-----------------------------------------------------------------------------
  538. * These aren't too critical.
  539. * (they're not supposed to happen).
  540. * In order to debug the reason for address exceptions in non-user modes,
  541. * we have to obtain all the registers so that we can see what's going on.
  542. */
  543. vector_addrexcptn:
  544. sub lr, lr, #8
  545. tst lr, #3
  546. bne Laddrexcptn_not_user
  547. save_user_regs
  548. teq pc, #MODE_SVC26
  549. mask_pc r0, lr @ Point to instruction
  550. mov r1, sp @ Point to registers
  551. mov r2, #0x400
  552. mov lr, pc
  553. bl do_excpt
  554. b ret_from_exception
  555. Laddrexcptn_not_user:
  556. save_svc_regs
  557. and r2, lr, #3
  558. teq r2, #3
  559. bne Laddrexcptn_illegal_mode
  560. teqp pc, #MODE_SVC26
  561. mask_pc r0, lr
  562. mov r1, sp
  563. orr r2, r2, #0x400
  564. bl do_excpt
  565. ldmia sp, {r0 - lr} @ I cant remember the reason I changed this...
  566. add sp, sp, #15*4
  567. movs pc, lr
  568. Laddrexcptn_illegal_mode:
  569. mov r0, sp
  570. str lr, [sp, #-4]!
  571. orr r1, r2, #PSR_I_BIT | PSR_F_BIT
  572. teqp r1, #0 @ change into mode (wont be user mode)
  573. mov r0, r0
  574. mov r1, r8 @ Any register from r8 - r14 can be banked
  575. mov r2, r9
  576. mov r3, r10
  577. mov r4, r11
  578. mov r5, r12
  579. mov r6, r13
  580. mov r7, r14
  581. teqp pc, #PSR_F_BIT | MODE_SVC26 @ back to svc
  582. mov r0, r0
  583. stmfd sp!, {r1-r7}
  584. ldmia r0, {r0-r7}
  585. stmfd sp!, {r0-r7}
  586. mov r0, sp
  587. mov r1, #BAD_ADDREXCPTN
  588. b bad_mode
  589. /*=============================================================================
  590. * Interrupt (IRQ) handler
  591. *-----------------------------------------------------------------------------
  592. * Note: if the IRQ was taken whilst in user mode, then *no* kernel routine
  593. * is running, so do not have to save svc lr.
  594. *
  595. * Entered in IRQ mode.
  596. */
  597. vector_IRQ: ldr sp, .LCirq @ Setup some temporary stack
  598. sub lr, lr, #4
  599. str lr, [sp] @ push return address
  600. tst lr, #3
  601. bne __irq_non_usr
  602. __irq_usr: teqp pc, #PSR_I_BIT | MODE_SVC26 @ Enter SVC mode
  603. mov r0, r0
  604. ldr lr, .LCirq
  605. ldr lr, [lr] @ Restore lr for jump back to USR
  606. save_user_regs
  607. handle_irq
  608. mov why, #0
  609. get_thread_info tsk
  610. b ret_to_user
  611. @ Place the IRQ priority table here so that the handle_irq macros above
  612. @ and below here can access it.
  613. irq_prio_table
  614. __irq_non_usr: teqp pc, #PSR_I_BIT | MODE_SVC26 @ Enter SVC mode
  615. mov r0, r0
  616. save_svc_regs_irq
  617. and r2, lr, #3
  618. teq r2, #3
  619. bne __irq_invalid @ IRQ not from SVC mode
  620. handle_irq
  621. restore_svc_regs
  622. __irq_invalid: mov r0, sp
  623. mov r1, #BAD_IRQ
  624. b bad_mode
  625. /*=============================================================================
  626. * Data abort handler code
  627. *-----------------------------------------------------------------------------
  628. *
  629. * This handles both exceptions from user and SVC modes, computes the address
  630. * range of the problem, and does any correction that is required. It then
  631. * calls the kernel data abort routine.
  632. *
  633. * This is where I wish that the ARM would tell you which address aborted.
  634. */
  635. vector_data: sub lr, lr, #8 @ Correct lr
  636. tst lr, #3
  637. bne Ldata_not_user
  638. save_user_regs
  639. teqp pc, #MODE_SVC26
  640. mask_pc r0, lr
  641. bl Ldata_do
  642. b ret_from_exception
  643. Ldata_not_user:
  644. save_svc_regs
  645. and r2, lr, #3
  646. teq r2, #3
  647. bne Ldata_illegal_mode
  648. tst lr, #PSR_I_BIT
  649. teqeqp pc, #MODE_SVC26
  650. mask_pc r0, lr
  651. bl Ldata_do
  652. restore_svc_regs
  653. Ldata_illegal_mode:
  654. mov r0, sp
  655. mov r1, #BAD_DATA
  656. b bad_mode
  657. Ldata_do: mov r3, sp
  658. ldr r4, [r0] @ Get instruction
  659. mov r2, #0
  660. tst r4, #1 << 20 @ Check to see if it is a write instruction
  661. orreq r2, r2, #FAULT_CODE_WRITE @ Indicate write instruction
  662. mov r1, r4, lsr #22 @ Now branch to the relevent processing routine
  663. and r1, r1, #15 << 2
  664. add pc, pc, r1
  665. movs pc, lr
  666. b Ldata_unknown
  667. b Ldata_unknown
  668. b Ldata_unknown
  669. b Ldata_unknown
  670. b Ldata_ldrstr_post @ ldr rd, [rn], #m
  671. b Ldata_ldrstr_numindex @ ldr rd, [rn, #m] @ RegVal
  672. b Ldata_ldrstr_post @ ldr rd, [rn], rm
  673. b Ldata_ldrstr_regindex @ ldr rd, [rn, rm]
  674. b Ldata_ldmstm @ ldm*a rn, <rlist>
  675. b Ldata_ldmstm @ ldm*b rn, <rlist>
  676. b Ldata_unknown
  677. b Ldata_unknown
  678. b Ldata_ldrstr_post @ ldc rd, [rn], #m @ Same as ldr rd, [rn], #m
  679. b Ldata_ldcstc_pre @ ldc rd, [rn, #m]
  680. b Ldata_unknown
  681. Ldata_unknown: @ Part of jumptable
  682. mov r0, r1
  683. mov r1, r4
  684. mov r2, r3
  685. b baddataabort
  686. Ldata_ldrstr_post:
  687. mov r0, r4, lsr #14 @ Get Rn
  688. and r0, r0, #15 << 2 @ Mask out reg.
  689. teq r0, #15 << 2
  690. ldr r0, [r3, r0] @ Get register
  691. biceq r0, r0, #PCMASK
  692. mov r1, r0
  693. #ifdef FAULT_CODE_LDRSTRPOST
  694. orr r2, r2, #FAULT_CODE_LDRSTRPOST
  695. #endif
  696. b do_DataAbort
  697. Ldata_ldrstr_numindex:
  698. mov r0, r4, lsr #14 @ Get Rn
  699. and r0, r0, #15 << 2 @ Mask out reg.
  700. teq r0, #15 << 2
  701. ldr r0, [r3, r0] @ Get register
  702. mov r1, r4, lsl #20
  703. biceq r0, r0, #PCMASK
  704. tst r4, #1 << 23
  705. addne r0, r0, r1, lsr #20
  706. subeq r0, r0, r1, lsr #20
  707. mov r1, r0
  708. #ifdef FAULT_CODE_LDRSTRPRE
  709. orr r2, r2, #FAULT_CODE_LDRSTRPRE
  710. #endif
  711. b do_DataAbort
  712. Ldata_ldrstr_regindex:
  713. mov r0, r4, lsr #14 @ Get Rn
  714. and r0, r0, #15 << 2 @ Mask out reg.
  715. teq r0, #15 << 2
  716. ldr r0, [r3, r0] @ Get register
  717. and r7, r4, #15
  718. biceq r0, r0, #PCMASK
  719. teq r7, #15 @ Check for PC
  720. ldr r7, [r3, r7, lsl #2] @ Get Rm
  721. and r8, r4, #0x60 @ Get shift types
  722. biceq r7, r7, #PCMASK
  723. mov r9, r4, lsr #7 @ Get shift amount
  724. and r9, r9, #31
  725. teq r8, #0
  726. moveq r7, r7, lsl r9
  727. teq r8, #0x20 @ LSR shift
  728. moveq r7, r7, lsr r9
  729. teq r8, #0x40 @ ASR shift
  730. moveq r7, r7, asr r9
  731. teq r8, #0x60 @ ROR shift
  732. moveq r7, r7, ror r9
  733. tst r4, #1 << 23
  734. addne r0, r0, r7
  735. subeq r0, r0, r7 @ Apply correction
  736. mov r1, r0
  737. #ifdef FAULT_CODE_LDRSTRREG
  738. orr r2, r2, #FAULT_CODE_LDRSTRREG
  739. #endif
  740. b do_DataAbort
  741. Ldata_ldmstm:
  742. mov r7, #0x11
  743. orr r7, r7, r7, lsl #8
  744. and r0, r4, r7
  745. and r1, r4, r7, lsl #1
  746. add r0, r0, r1, lsr #1
  747. and r1, r4, r7, lsl #2
  748. add r0, r0, r1, lsr #2
  749. and r1, r4, r7, lsl #3
  750. add r0, r0, r1, lsr #3
  751. add r0, r0, r0, lsr #8
  752. add r0, r0, r0, lsr #4
  753. and r7, r0, #15 @ r7 = no. of registers to transfer.
  754. mov r5, r4, lsr #14 @ Get Rn
  755. and r5, r5, #15 << 2
  756. ldr r0, [r3, r5] @ Get reg
  757. eor r6, r4, r4, lsl #2
  758. tst r6, #1 << 23 @ Check inc/dec ^ writeback
  759. rsbeq r7, r7, #0
  760. add r7, r0, r7, lsl #2 @ Do correction (signed)
  761. subne r1, r7, #1
  762. subeq r1, r0, #1
  763. moveq r0, r7
  764. tst r4, #1 << 21 @ Check writeback
  765. strne r7, [r3, r5]
  766. eor r6, r4, r4, lsl #1
  767. tst r6, #1 << 24 @ Check Pre/Post ^ inc/dec
  768. addeq r0, r0, #4
  769. addeq r1, r1, #4
  770. teq r5, #15*4 @ CHECK FOR PC
  771. biceq r1, r1, #PCMASK
  772. biceq r0, r0, #PCMASK
  773. #ifdef FAULT_CODE_LDMSTM
  774. orr r2, r2, #FAULT_CODE_LDMSTM
  775. #endif
  776. b do_DataAbort
  777. Ldata_ldcstc_pre:
  778. mov r0, r4, lsr #14 @ Get Rn
  779. and r0, r0, #15 << 2 @ Mask out reg.
  780. teq r0, #15 << 2
  781. ldr r0, [r3, r0] @ Get register
  782. mov r1, r4, lsl #24 @ Get offset
  783. biceq r0, r0, #PCMASK
  784. tst r4, #1 << 23
  785. addne r0, r0, r1, lsr #24
  786. subeq r0, r0, r1, lsr #24
  787. mov r1, r0
  788. #ifdef FAULT_CODE_LDCSTC
  789. orr r2, r2, #FAULT_CODE_LDCSTC
  790. #endif
  791. b do_DataAbort
  792. /*
  793. * This is the return code to user mode for abort handlers
  794. */
  795. ENTRY(ret_from_exception)
  796. get_thread_info tsk
  797. mov why, #0
  798. b ret_to_user
  799. .data
  800. ENTRY(fp_enter)
  801. .word fpe_not_present
  802. .text
  803. /*
  804. * Register switch for older 26-bit only ARMs
  805. */
  806. ENTRY(__switch_to)
  807. add r0, r0, #TI_CPU_SAVE
  808. stmia r0, {r4 - sl, fp, sp, lr}
  809. add r1, r1, #TI_CPU_SAVE
  810. ldmia r1, {r4 - sl, fp, sp, pc}^
  811. /*
  812. *=============================================================================
  813. * Low-level interface code
  814. *-----------------------------------------------------------------------------
  815. * Trap initialisation
  816. *-----------------------------------------------------------------------------
  817. *
  818. * Note - FIQ code has changed. The default is a couple of words in 0x1c, 0x20
  819. * that call _unexp_fiq. Nowever, we now copy the FIQ routine to 0x1c (removes
  820. * some excess cycles).
  821. *
  822. * What we need to put into 0-0x1c are branches to branch to the kernel.
  823. */
  824. .section ".init.text",#alloc,#execinstr
  825. .Ljump_addresses:
  826. swi SYS_ERROR0
  827. .word vector_undefinstr - 12
  828. .word vector_swi - 16
  829. .word vector_prefetch - 20
  830. .word vector_data - 24
  831. .word vector_addrexcptn - 28
  832. .word vector_IRQ - 32
  833. .word _unexp_fiq - 36
  834. b . + 8
  835. /*
  836. * initialise the trap system
  837. */
  838. ENTRY(__trap_init)
  839. stmfd sp!, {r4 - r7, lr}
  840. adr r1, .Ljump_addresses
  841. ldmia r1, {r1 - r7, ip, lr}
  842. orr r2, lr, r2, lsr #2
  843. orr r3, lr, r3, lsr #2
  844. orr r4, lr, r4, lsr #2
  845. orr r5, lr, r5, lsr #2
  846. orr r6, lr, r6, lsr #2
  847. orr r7, lr, r7, lsr #2
  848. orr ip, lr, ip, lsr #2
  849. mov r0, #0
  850. stmia r0, {r1 - r7, ip}
  851. ldmfd sp!, {r4 - r7, pc}^
  852. .bss
  853. __temp_irq: .space 4 @ saved lr_irq
  854. __temp_fiq: .space 128