Commit | Line | Data |
---|---|---|
336f1d32 | 1 | /* |
de398406 | 2 | * Copyright (C) 1999, 2000, 2002 Niibe Yutaka |
336f1d32 | 3 | * Copyright (C) 2003 - 2008 Paul Mundt |
de398406 YS |
4 | * |
5 | * This file is subject to the terms and conditions of the GNU General Public | |
6 | * License. See the file "COPYING" in the main directory of this archive | |
7 | * for more details. | |
8 | * | |
9 | */ | |
10 | ||
11 | ! NOTE: | |
12 | ! GNU as (as of 2.9.1) changes bf/s into bt/s and bra, when the address | |
13 | ! to be jumped is too far, but it causes illegal slot exception. | |
14 | ||
15 | /* | |
16 | * entry.S contains the system-call and fault low-level handling routines. | |
17 | * This also contains the timer-interrupt handler, as well as all interrupts | |
18 | * and faults that can result in a task-switch. | |
19 | * | |
20 | * NOTE: This code handles signal-recognition, which happens every time | |
21 | * after a timer-interrupt and after each system call. | |
22 | * | |
23 | * NOTE: This code uses a convention that instructions in the delay slot | |
24 | * of a transfer-control instruction are indented by an extra space, thus: | |
25 | * | |
26 | * jmp @k0 ! control-transfer instruction | |
27 | * ldc k1, ssr ! delay slot | |
28 | * | |
29 | * Stack layout in 'ret_from_syscall': | |
30 | * ptrace needs to have all regs on the stack. | |
31 | * if the order here is changed, it needs to be | |
32 | * updated in ptrace.c and ptrace.h | |
33 | * | |
34 | * r0 | |
35 | * ... | |
36 | * r15 = stack pointer | |
37 | * spc | |
38 | * pr | |
39 | * ssr | |
40 | * gbr | |
41 | * mach | |
42 | * macl | |
43 | * syscall # | |
44 | * | |
45 | */ | |
cafb0dda | 46 | #include <asm/dwarf.h> |
de398406 YS |
47 | |
48 | #if defined(CONFIG_PREEMPT) | |
fd78a76a | 49 | # define preempt_stop() cli ; TRACE_IRQS_OFF |
de398406 YS |
50 | #else |
51 | # define preempt_stop() | |
52 | # define resume_kernel __restore_all | |
53 | #endif | |
54 | ||
de398406 YS |
55 | |
56 | .align 2 | |
57 | ENTRY(exception_error) | |
58 | ! | |
fd78a76a | 59 | TRACE_IRQS_ON |
de398406 | 60 | sti |
f413d0d9 | 61 | mov.l 1f, r0 |
de398406 YS |
62 | jmp @r0 |
63 | nop | |
64 | ||
de398406 | 65 | .align 2 |
f413d0d9 | 66 | 1: .long do_exception_error |
de398406 YS |
67 | |
68 | .align 2 | |
69 | ret_from_exception: | |
cafb0dda MF |
70 | CFI_STARTPROC simple |
71 | CFI_DEF_CFA r14, 0 | |
72 | CFI_REL_OFFSET 17, 64 | |
14269828 | 73 | CFI_REL_OFFSET 15, 60 |
cafb0dda | 74 | CFI_REL_OFFSET 14, 56 |
14269828 MF |
75 | CFI_REL_OFFSET 13, 52 |
76 | CFI_REL_OFFSET 12, 48 | |
77 | CFI_REL_OFFSET 11, 44 | |
78 | CFI_REL_OFFSET 10, 40 | |
79 | CFI_REL_OFFSET 9, 36 | |
80 | CFI_REL_OFFSET 8, 32 | |
de398406 YS |
81 | preempt_stop() |
82 | ENTRY(ret_from_irq) | |
83 | ! | |
84 | mov #OFF_SR, r0 | |
85 | mov.l @(r0,r15), r0 ! get status register | |
86 | shll r0 | |
87 | shll r0 ! kernel space? | |
88 | get_current_thread_info r8, r0 | |
89 | bt resume_kernel ! Yes, it's from kernel, go back soon | |
90 | ||
91 | #ifdef CONFIG_PREEMPT | |
92 | bra resume_userspace | |
93 | nop | |
94 | ENTRY(resume_kernel) | |
323b8c41 | 95 | cli |
f3a83088 | 96 | TRACE_IRQS_OFF |
de398406 YS |
97 | mov.l @(TI_PRE_COUNT,r8), r0 ! current_thread_info->preempt_count |
98 | tst r0, r0 | |
99 | bf noresched | |
100 | need_resched: | |
101 | mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags | |
102 | tst #_TIF_NEED_RESCHED, r0 ! need_resched set? | |
103 | bt noresched | |
104 | ||
105 | mov #OFF_SR, r0 | |
106 | mov.l @(r0,r15), r0 ! get status register | |
fea966f7 SM |
107 | shlr r0 |
108 | and #(0xf0>>1), r0 ! interrupts off (exception path)? | |
109 | cmp/eq #(0xf0>>1), r0 | |
de398406 | 110 | bt noresched |
afbfb52e | 111 | mov.l 3f, r0 |
323b8c41 | 112 | jsr @r0 ! call preempt_schedule_irq |
afbfb52e | 113 | nop |
de398406 YS |
114 | bra need_resched |
115 | nop | |
afbfb52e | 116 | |
de398406 YS |
117 | noresched: |
118 | bra __restore_all | |
119 | nop | |
120 | ||
121 | .align 2 | |
122 | 1: .long PREEMPT_ACTIVE | |
123 | 2: .long schedule | |
323b8c41 | 124 | 3: .long preempt_schedule_irq |
de398406 YS |
125 | #endif |
126 | ||
127 | ENTRY(resume_userspace) | |
128 | ! r8: current_thread_info | |
129 | cli | |
457b6461 | 130 | TRACE_IRQS_OFF |
de398406 | 131 | mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags |
c652d780 | 132 | tst #(_TIF_WORK_MASK & 0xff), r0 |
de398406 YS |
133 | bt/s __restore_all |
134 | tst #_TIF_NEED_RESCHED, r0 | |
135 | ||
136 | .align 2 | |
137 | work_pending: | |
138 | ! r0: current_thread_info->flags | |
139 | ! r8: current_thread_info | |
140 | ! t: result of "tst #_TIF_NEED_RESCHED, r0" | |
141 | bf/s work_resched | |
5e071e2b | 142 | tst #(_TIF_SIGPENDING | _TIF_NOTIFY_RESUME), r0 |
de398406 YS |
143 | work_notifysig: |
144 | bt/s __restore_all | |
145 | mov r15, r4 | |
146 | mov r12, r5 ! set arg1(save_r0) | |
147 | mov r0, r6 | |
6330c04b | 148 | sti |
de398406 YS |
149 | mov.l 2f, r1 |
150 | mov.l 3f, r0 | |
151 | jmp @r1 | |
152 | lds r0, pr | |
153 | work_resched: | |
de398406 YS |
154 | mov.l 1f, r1 |
155 | jsr @r1 ! schedule | |
156 | nop | |
157 | cli | |
fd78a76a | 158 | TRACE_IRQS_OFF |
de398406 YS |
159 | ! |
160 | mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags | |
c652d780 | 161 | tst #(_TIF_WORK_MASK & 0xff), r0 |
de398406 YS |
162 | bt __restore_all |
163 | bra work_pending | |
164 | tst #_TIF_NEED_RESCHED, r0 | |
165 | ||
166 | .align 2 | |
167 | 1: .long schedule | |
168 | 2: .long do_notify_resume | |
0b1689cf | 169 | 3: .long resume_userspace |
de398406 YS |
170 | |
171 | .align 2 | |
172 | syscall_exit_work: | |
173 | ! r0: current_thread_info->flags | |
174 | ! r8: current_thread_info | |
c652d780 | 175 | tst #(_TIF_WORK_SYSCALL_MASK & 0xff), r0 |
de398406 YS |
176 | bt/s work_pending |
177 | tst #_TIF_NEED_RESCHED, r0 | |
fd78a76a | 178 | TRACE_IRQS_ON |
de398406 | 179 | sti |
1322b9de | 180 | mov r15, r4 |
ab99c733 | 181 | mov.l 8f, r0 ! do_syscall_trace_leave |
de398406 YS |
182 | jsr @r0 |
183 | nop | |
184 | bra resume_userspace | |
185 | nop | |
186 | ||
187 | .align 2 | |
188 | syscall_trace_entry: | |
189 | ! Yes it is traced. | |
1322b9de | 190 | mov r15, r4 |
ab99c733 | 191 | mov.l 7f, r11 ! Call do_syscall_trace_enter which notifies |
de398406 YS |
192 | jsr @r11 ! superior (will chomp R[0-7]) |
193 | nop | |
ab99c733 | 194 | mov.l r0, @(OFF_R0,r15) ! Save return value |
de398406 YS |
195 | ! Reload R0-R4 from kernel stack, where the |
196 | ! parent may have modified them using | |
197 | ! ptrace(POKEUSR). (Note that R0-R2 are | |
198 | ! used by the system call handler directly | |
199 | ! from the kernel stack anyway, so don't need | |
200 | ! to be reloaded here.) This allows the parent | |
201 | ! to rewrite system calls and args on the fly. | |
202 | mov.l @(OFF_R4,r15), r4 ! arg0 | |
203 | mov.l @(OFF_R5,r15), r5 | |
204 | mov.l @(OFF_R6,r15), r6 | |
205 | mov.l @(OFF_R7,r15), r7 ! arg3 | |
206 | mov.l @(OFF_R3,r15), r3 ! syscall_nr | |
e0969e0c | 207 | ! |
de398406 YS |
208 | mov.l 2f, r10 ! Number of syscalls |
209 | cmp/hs r10, r3 | |
210 | bf syscall_call | |
211 | mov #-ENOSYS, r0 | |
212 | bra syscall_exit | |
213 | mov.l r0, @(OFF_R0,r15) ! Return value | |
214 | ||
215 | __restore_all: | |
f3a83088 MF |
216 | mov #OFF_SR, r0 |
217 | mov.l @(r0,r15), r0 ! get status register | |
218 | ||
219 | shlr2 r0 | |
220 | and #0x3c, r0 | |
221 | cmp/eq #0x3c, r0 | |
222 | bt 1f | |
223 | TRACE_IRQS_ON | |
224 | bra 2f | |
225 | nop | |
226 | 1: | |
227 | TRACE_IRQS_OFF | |
228 | 2: | |
229 | mov.l 3f, r0 | |
de398406 YS |
230 | jmp @r0 |
231 | nop | |
232 | ||
233 | .align 2 | |
f3a83088 | 234 | 3: .long restore_all |
de398406 | 235 | |
e0969e0c SM |
236 | .align 2 |
237 | syscall_badsys: ! Bad syscall number | |
561c2bcc | 238 | get_current_thread_info r8, r0 |
e0969e0c SM |
239 | mov #-ENOSYS, r0 |
240 | bra resume_userspace | |
241 | mov.l r0, @(OFF_R0,r15) ! Return value | |
f413d0d9 PM |
242 | |
243 | /* | |
244 | * The main debug trap handler. | |
245 | * | |
246 | * r8=TRA (not the trap number!) | |
247 | * | |
248 | * Note: This assumes that the trapa value is left in its original | |
249 | * form (without the shlr2 shift) so the calculation for the jump | |
250 | * call table offset remains a simple in place mask. | |
251 | */ | |
252 | debug_trap: | |
253 | mov r8, r0 | |
254 | and #(0xf << 2), r0 | |
255 | mov.l 1f, r8 | |
256 | add r0, r8 | |
257 | mov.l @r8, r8 | |
336f1d32 PM |
258 | jsr @r8 |
259 | nop | |
260 | bra __restore_all | |
f413d0d9 | 261 | nop |
cafb0dda | 262 | CFI_ENDPROC |
f413d0d9 PM |
263 | |
264 | .align 2 | |
265 | 1: .long debug_trap_table | |
e0969e0c | 266 | |
de398406 YS |
267 | /* |
268 | * Syscall interface: | |
269 | * | |
270 | * Syscall #: R3 | |
271 | * Arguments #0 to #3: R4--R7 | |
272 | * Arguments #4 to #6: R0, R1, R2 | |
f413d0d9 | 273 | * TRA: (number of arguments + ABI revision) x 4 |
de398406 YS |
274 | * |
275 | * This code also handles delegating other traps to the BIOS/gdb stub | |
276 | * according to: | |
277 | * | |
278 | * Trap number | |
f413d0d9 PM |
279 | * (TRA>>2) Purpose |
280 | * -------- ------- | |
281 | * 0x00-0x0f original SH-3/4 syscall ABI (not in general use). | |
282 | * 0x10-0x1f general SH-3/4 syscall ABI. | |
283 | * 0x20-0x2f syscall ABI for SH-2 parts. | |
284 | * 0x30-0x3f debug traps used by the kernel. | |
285 | * 0x40-0xff Not supported by all parts, so left unhandled. | |
de398406 YS |
286 | * |
287 | * Note: When we're first called, the TRA value must be shifted | |
288 | * right 2 bits in order to get the value that was used as the "trapa" | |
289 | * argument. | |
290 | */ | |
291 | ||
292 | .align 2 | |
293 | .globl ret_from_fork | |
294 | ret_from_fork: | |
295 | mov.l 1f, r8 | |
296 | jsr @r8 | |
297 | mov r0, r4 | |
298 | bra syscall_exit | |
299 | nop | |
7147e215 AV |
300 | |
301 | .align 2 | |
302 | .globl ret_from_kernel_thread | |
303 | ret_from_kernel_thread: | |
304 | mov.l 1f, r8 | |
305 | jsr @r8 | |
306 | mov r0, r4 | |
307 | mov.l @(OFF_R5,r15), r5 ! fn | |
308 | jsr @r5 | |
309 | mov.l @(OFF_R4,r15), r4 ! arg | |
310 | bra syscall_exit | |
311 | nop | |
312 | ||
de398406 YS |
313 | .align 2 |
314 | 1: .long schedule_tail | |
f413d0d9 PM |
315 | |
316 | /* | |
317 | * The poorly named main trapa decode and dispatch routine, for | |
318 | * system calls and debug traps through their respective jump tables. | |
319 | */ | |
de398406 | 320 | ENTRY(system_call) |
0b930489 | 321 | setup_frame_reg |
de398406 YS |
322 | #if !defined(CONFIG_CPU_SH2) |
323 | mov.l 1f, r9 | |
324 | mov.l @r9, r8 ! Read from TRA (Trap Address) Register | |
325 | #endif | |
ab6e570b PM |
326 | |
327 | mov #OFF_TRA, r10 | |
328 | add r15, r10 | |
329 | mov.l r8, @r10 ! set TRA value to tra | |
330 | ||
f413d0d9 PM |
331 | /* |
332 | * Check the trap type | |
333 | */ | |
334 | mov #((0x20 << 2) - 1), r9 | |
de398406 | 335 | cmp/hi r9, r8 |
f413d0d9 | 336 | bt/s debug_trap ! it's a debug trap.. |
ab6e570b PM |
337 | nop |
338 | ||
fd78a76a | 339 | TRACE_IRQS_ON |
de398406 | 340 | sti |
afbfb52e | 341 | |
de398406 | 342 | ! |
e0969e0c | 343 | get_current_thread_info r8, r10 |
de398406 | 344 | mov.l @(TI_FLAGS,r8), r8 |
c652d780 MF |
345 | mov #(_TIF_WORK_SYSCALL_MASK & 0xff), r10 |
346 | mov #(_TIF_WORK_SYSCALL_MASK >> 8), r9 | |
de398406 | 347 | tst r10, r8 |
c652d780 MF |
348 | shll8 r9 |
349 | bf syscall_trace_entry | |
350 | tst r9, r8 | |
de398406 YS |
351 | bf syscall_trace_entry |
352 | ! | |
e0969e0c SM |
353 | mov.l 2f, r8 ! Number of syscalls |
354 | cmp/hs r8, r3 | |
355 | bt syscall_badsys | |
356 | ! | |
de398406 | 357 | syscall_call: |
e0969e0c | 358 | shll2 r3 ! x4 |
de398406 | 359 | mov.l 3f, r8 ! Load the address of sys_call_table |
e0969e0c SM |
360 | add r8, r3 |
361 | mov.l @r3, r8 | |
de398406 YS |
362 | jsr @r8 ! jump to specific syscall handler |
363 | nop | |
364 | mov.l @(OFF_R0,r15), r12 ! save r0 | |
365 | mov.l r0, @(OFF_R0,r15) ! save the return value | |
366 | ! | |
367 | syscall_exit: | |
368 | cli | |
fd78a76a | 369 | TRACE_IRQS_OFF |
de398406 YS |
370 | ! |
371 | get_current_thread_info r8, r0 | |
372 | mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags | |
c652d780 MF |
373 | tst #(_TIF_ALLWORK_MASK & 0xff), r0 |
374 | mov #(_TIF_ALLWORK_MASK >> 8), r1 | |
375 | bf syscall_exit_work | |
376 | shlr8 r0 | |
377 | tst r0, r1 | |
de398406 YS |
378 | bf syscall_exit_work |
379 | bra __restore_all | |
380 | nop | |
381 | .align 2 | |
382 | #if !defined(CONFIG_CPU_SH2) | |
383 | 1: .long TRA | |
384 | #endif | |
385 | 2: .long NR_syscalls | |
386 | 3: .long sys_call_table | |
ab99c733 PM |
387 | 7: .long do_syscall_trace_enter |
388 | 8: .long do_syscall_trace_leave |