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 | */ | |
46 | ||
47 | #if defined(CONFIG_PREEMPT) | |
48 | # define preempt_stop() cli | |
49 | #else | |
50 | # define preempt_stop() | |
51 | # define resume_kernel __restore_all | |
52 | #endif | |
53 | ||
de398406 YS |
54 | |
55 | .align 2 | |
56 | ENTRY(exception_error) | |
57 | ! | |
afbfb52e | 58 | #ifdef CONFIG_TRACE_IRQFLAGS |
f413d0d9 | 59 | mov.l 2f, r0 |
afbfb52e PM |
60 | jsr @r0 |
61 | nop | |
62 | #endif | |
de398406 | 63 | sti |
f413d0d9 | 64 | mov.l 1f, r0 |
de398406 YS |
65 | jmp @r0 |
66 | nop | |
67 | ||
de398406 | 68 | .align 2 |
f413d0d9 | 69 | 1: .long do_exception_error |
afbfb52e | 70 | #ifdef CONFIG_TRACE_IRQFLAGS |
f413d0d9 | 71 | 2: .long trace_hardirqs_on |
afbfb52e | 72 | #endif |
de398406 YS |
73 | |
74 | .align 2 | |
75 | ret_from_exception: | |
76 | preempt_stop() | |
afbfb52e PM |
77 | #ifdef CONFIG_TRACE_IRQFLAGS |
78 | mov.l 4f, r0 | |
79 | jsr @r0 | |
80 | nop | |
81 | #endif | |
de398406 YS |
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) | |
95 | mov.l @(TI_PRE_COUNT,r8), r0 ! current_thread_info->preempt_count | |
96 | tst r0, r0 | |
97 | bf noresched | |
98 | need_resched: | |
99 | mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags | |
100 | tst #_TIF_NEED_RESCHED, r0 ! need_resched set? | |
101 | bt noresched | |
102 | ||
103 | mov #OFF_SR, r0 | |
104 | mov.l @(r0,r15), r0 ! get status register | |
105 | and #0xf0, r0 ! interrupts off (exception path)? | |
106 | cmp/eq #0xf0, r0 | |
107 | bt noresched | |
108 | ||
109 | mov.l 1f, r0 | |
110 | mov.l r0, @(TI_PRE_COUNT,r8) | |
111 | ||
afbfb52e PM |
112 | #ifdef CONFIG_TRACE_IRQFLAGS |
113 | mov.l 3f, r0 | |
114 | jsr @r0 | |
115 | nop | |
116 | #endif | |
de398406 YS |
117 | sti |
118 | mov.l 2f, r0 | |
119 | jsr @r0 | |
120 | nop | |
121 | mov #0, r0 | |
122 | mov.l r0, @(TI_PRE_COUNT,r8) | |
123 | cli | |
afbfb52e PM |
124 | #ifdef CONFIG_TRACE_IRQFLAGS |
125 | mov.l 4f, r0 | |
126 | jsr @r0 | |
127 | nop | |
128 | #endif | |
de398406 YS |
129 | |
130 | bra need_resched | |
131 | nop | |
afbfb52e | 132 | |
de398406 YS |
133 | noresched: |
134 | bra __restore_all | |
135 | nop | |
136 | ||
137 | .align 2 | |
138 | 1: .long PREEMPT_ACTIVE | |
139 | 2: .long schedule | |
afbfb52e PM |
140 | #ifdef CONFIG_TRACE_IRQFLAGS |
141 | 3: .long trace_hardirqs_on | |
142 | 4: .long trace_hardirqs_off | |
143 | #endif | |
de398406 YS |
144 | #endif |
145 | ||
146 | ENTRY(resume_userspace) | |
147 | ! r8: current_thread_info | |
148 | cli | |
afbfb52e PM |
149 | #ifdef CONFIG_TRACE_IRQFLAGS |
150 | mov.l 5f, r0 | |
151 | jsr @r0 | |
152 | nop | |
153 | #endif | |
de398406 YS |
154 | mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags |
155 | tst #_TIF_WORK_MASK, r0 | |
156 | bt/s __restore_all | |
157 | tst #_TIF_NEED_RESCHED, r0 | |
158 | ||
159 | .align 2 | |
160 | work_pending: | |
161 | ! r0: current_thread_info->flags | |
162 | ! r8: current_thread_info | |
163 | ! t: result of "tst #_TIF_NEED_RESCHED, r0" | |
164 | bf/s work_resched | |
165 | tst #(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), r0 | |
166 | work_notifysig: | |
167 | bt/s __restore_all | |
168 | mov r15, r4 | |
169 | mov r12, r5 ! set arg1(save_r0) | |
170 | mov r0, r6 | |
171 | mov.l 2f, r1 | |
172 | mov.l 3f, r0 | |
173 | jmp @r1 | |
174 | lds r0, pr | |
175 | work_resched: | |
de398406 YS |
176 | mov.l 1f, r1 |
177 | jsr @r1 ! schedule | |
178 | nop | |
179 | cli | |
afbfb52e PM |
180 | #ifdef CONFIG_TRACE_IRQFLAGS |
181 | mov.l 5f, r0 | |
182 | jsr @r0 | |
183 | nop | |
184 | #endif | |
de398406 YS |
185 | ! |
186 | mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags | |
187 | tst #_TIF_WORK_MASK, r0 | |
188 | bt __restore_all | |
189 | bra work_pending | |
190 | tst #_TIF_NEED_RESCHED, r0 | |
191 | ||
192 | .align 2 | |
193 | 1: .long schedule | |
194 | 2: .long do_notify_resume | |
0b1689cf | 195 | 3: .long resume_userspace |
afbfb52e PM |
196 | #ifdef CONFIG_TRACE_IRQFLAGS |
197 | 4: .long trace_hardirqs_on | |
198 | 5: .long trace_hardirqs_off | |
199 | #endif | |
de398406 YS |
200 | |
201 | .align 2 | |
202 | syscall_exit_work: | |
203 | ! r0: current_thread_info->flags | |
204 | ! r8: current_thread_info | |
cec3fd3e | 205 | tst #_TIF_WORK_SYSCALL_MASK, r0 |
de398406 YS |
206 | bt/s work_pending |
207 | tst #_TIF_NEED_RESCHED, r0 | |
afbfb52e PM |
208 | #ifdef CONFIG_TRACE_IRQFLAGS |
209 | mov.l 5f, r0 | |
210 | jsr @r0 | |
211 | nop | |
212 | #endif | |
de398406 | 213 | sti |
1322b9de | 214 | mov r15, r4 |
ab99c733 | 215 | mov.l 8f, r0 ! do_syscall_trace_leave |
de398406 YS |
216 | jsr @r0 |
217 | nop | |
218 | bra resume_userspace | |
219 | nop | |
220 | ||
221 | .align 2 | |
222 | syscall_trace_entry: | |
223 | ! Yes it is traced. | |
1322b9de | 224 | mov r15, r4 |
ab99c733 | 225 | mov.l 7f, r11 ! Call do_syscall_trace_enter which notifies |
de398406 YS |
226 | jsr @r11 ! superior (will chomp R[0-7]) |
227 | nop | |
ab99c733 | 228 | mov.l r0, @(OFF_R0,r15) ! Save return value |
de398406 YS |
229 | ! Reload R0-R4 from kernel stack, where the |
230 | ! parent may have modified them using | |
231 | ! ptrace(POKEUSR). (Note that R0-R2 are | |
232 | ! used by the system call handler directly | |
233 | ! from the kernel stack anyway, so don't need | |
234 | ! to be reloaded here.) This allows the parent | |
235 | ! to rewrite system calls and args on the fly. | |
236 | mov.l @(OFF_R4,r15), r4 ! arg0 | |
237 | mov.l @(OFF_R5,r15), r5 | |
238 | mov.l @(OFF_R6,r15), r6 | |
239 | mov.l @(OFF_R7,r15), r7 ! arg3 | |
240 | mov.l @(OFF_R3,r15), r3 ! syscall_nr | |
e0969e0c | 241 | ! |
de398406 YS |
242 | mov.l 2f, r10 ! Number of syscalls |
243 | cmp/hs r10, r3 | |
244 | bf syscall_call | |
245 | mov #-ENOSYS, r0 | |
246 | bra syscall_exit | |
247 | mov.l r0, @(OFF_R0,r15) ! Return value | |
248 | ||
249 | __restore_all: | |
afbfb52e | 250 | mov.l 1f, r0 |
de398406 YS |
251 | jmp @r0 |
252 | nop | |
253 | ||
254 | .align 2 | |
255 | 1: .long restore_all | |
256 | ||
e0969e0c SM |
257 | .align 2 |
258 | syscall_badsys: ! Bad syscall number | |
561c2bcc | 259 | get_current_thread_info r8, r0 |
e0969e0c SM |
260 | mov #-ENOSYS, r0 |
261 | bra resume_userspace | |
262 | mov.l r0, @(OFF_R0,r15) ! Return value | |
f413d0d9 PM |
263 | |
264 | /* | |
265 | * The main debug trap handler. | |
266 | * | |
267 | * r8=TRA (not the trap number!) | |
268 | * | |
269 | * Note: This assumes that the trapa value is left in its original | |
270 | * form (without the shlr2 shift) so the calculation for the jump | |
271 | * call table offset remains a simple in place mask. | |
272 | */ | |
273 | debug_trap: | |
274 | mov r8, r0 | |
275 | and #(0xf << 2), r0 | |
276 | mov.l 1f, r8 | |
277 | add r0, r8 | |
278 | mov.l @r8, r8 | |
336f1d32 PM |
279 | jsr @r8 |
280 | nop | |
281 | bra __restore_all | |
f413d0d9 PM |
282 | nop |
283 | ||
284 | .align 2 | |
285 | 1: .long debug_trap_table | |
e0969e0c | 286 | |
de398406 YS |
287 | /* |
288 | * Syscall interface: | |
289 | * | |
290 | * Syscall #: R3 | |
291 | * Arguments #0 to #3: R4--R7 | |
292 | * Arguments #4 to #6: R0, R1, R2 | |
f413d0d9 | 293 | * TRA: (number of arguments + ABI revision) x 4 |
de398406 YS |
294 | * |
295 | * This code also handles delegating other traps to the BIOS/gdb stub | |
296 | * according to: | |
297 | * | |
298 | * Trap number | |
f413d0d9 PM |
299 | * (TRA>>2) Purpose |
300 | * -------- ------- | |
301 | * 0x00-0x0f original SH-3/4 syscall ABI (not in general use). | |
302 | * 0x10-0x1f general SH-3/4 syscall ABI. | |
303 | * 0x20-0x2f syscall ABI for SH-2 parts. | |
304 | * 0x30-0x3f debug traps used by the kernel. | |
305 | * 0x40-0xff Not supported by all parts, so left unhandled. | |
de398406 YS |
306 | * |
307 | * Note: When we're first called, the TRA value must be shifted | |
308 | * right 2 bits in order to get the value that was used as the "trapa" | |
309 | * argument. | |
310 | */ | |
311 | ||
312 | .align 2 | |
313 | .globl ret_from_fork | |
314 | ret_from_fork: | |
315 | mov.l 1f, r8 | |
316 | jsr @r8 | |
317 | mov r0, r4 | |
318 | bra syscall_exit | |
319 | nop | |
320 | .align 2 | |
321 | 1: .long schedule_tail | |
f413d0d9 PM |
322 | |
323 | /* | |
324 | * The poorly named main trapa decode and dispatch routine, for | |
325 | * system calls and debug traps through their respective jump tables. | |
326 | */ | |
de398406 YS |
327 | ENTRY(system_call) |
328 | #if !defined(CONFIG_CPU_SH2) | |
329 | mov.l 1f, r9 | |
330 | mov.l @r9, r8 ! Read from TRA (Trap Address) Register | |
331 | #endif | |
f413d0d9 PM |
332 | /* |
333 | * Check the trap type | |
334 | */ | |
335 | mov #((0x20 << 2) - 1), r9 | |
de398406 | 336 | cmp/hi r9, r8 |
f413d0d9 | 337 | bt/s debug_trap ! it's a debug trap.. |
de398406 YS |
338 | mov #OFF_TRA, r9 |
339 | add r15, r9 | |
de398406 | 340 | mov.l r8, @r9 ! set TRA value to tra |
afbfb52e PM |
341 | #ifdef CONFIG_TRACE_IRQFLAGS |
342 | mov.l 5f, r10 | |
343 | jsr @r10 | |
344 | nop | |
345 | #endif | |
de398406 | 346 | sti |
afbfb52e | 347 | |
de398406 | 348 | ! |
e0969e0c | 349 | get_current_thread_info r8, r10 |
de398406 | 350 | mov.l @(TI_FLAGS,r8), r8 |
cec3fd3e | 351 | mov #_TIF_WORK_SYSCALL_MASK, r10 |
de398406 YS |
352 | tst r10, r8 |
353 | bf syscall_trace_entry | |
354 | ! | |
e0969e0c SM |
355 | mov.l 2f, r8 ! Number of syscalls |
356 | cmp/hs r8, r3 | |
357 | bt syscall_badsys | |
358 | ! | |
de398406 | 359 | syscall_call: |
e0969e0c | 360 | shll2 r3 ! x4 |
de398406 | 361 | mov.l 3f, r8 ! Load the address of sys_call_table |
e0969e0c SM |
362 | add r8, r3 |
363 | mov.l @r3, r8 | |
de398406 YS |
364 | jsr @r8 ! jump to specific syscall handler |
365 | nop | |
366 | mov.l @(OFF_R0,r15), r12 ! save r0 | |
367 | mov.l r0, @(OFF_R0,r15) ! save the return value | |
368 | ! | |
369 | syscall_exit: | |
370 | cli | |
afbfb52e PM |
371 | #ifdef CONFIG_TRACE_IRQFLAGS |
372 | mov.l 6f, r0 | |
373 | jsr @r0 | |
374 | nop | |
375 | #endif | |
de398406 YS |
376 | ! |
377 | get_current_thread_info r8, r0 | |
378 | mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags | |
379 | tst #_TIF_ALLWORK_MASK, r0 | |
380 | bf syscall_exit_work | |
381 | bra __restore_all | |
382 | nop | |
383 | .align 2 | |
384 | #if !defined(CONFIG_CPU_SH2) | |
385 | 1: .long TRA | |
386 | #endif | |
387 | 2: .long NR_syscalls | |
388 | 3: .long sys_call_table | |
afbfb52e PM |
389 | #ifdef CONFIG_TRACE_IRQFLAGS |
390 | 5: .long trace_hardirqs_on | |
391 | 6: .long trace_hardirqs_off | |
392 | #endif | |
ab99c733 PM |
393 | 7: .long do_syscall_trace_enter |
394 | 8: .long do_syscall_trace_leave |