ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / cris / arch-v10 / kernel / entry.S
1 /* $Id: entry.S,v 1.16 2003/07/04 08:27:41 starvik Exp $
2  *
3  *  linux/arch/cris/entry.S
4  *
5  *  Copyright (C) 2000, 2001, 2002 Axis Communications AB
6  *
7  *  Authors:    Bjorn Wesen (bjornw@axis.com)
8  *
9  *  $Log: entry.S,v $
10  *  Revision 1.16  2003/07/04 08:27:41  starvik
11  *  Merge of Linux 2.5.74
12  *
13  *  Revision 1.15  2003/04/09 07:32:55  starvik
14  *  resume should return task_struct, not thread_info
15  *
16  *  Revision 1.14  2003/04/09 05:20:44  starvik
17  *  Merge of Linux 2.5.67
18  *
19  *  Revision 1.13  2002/12/11 15:42:02  starvik
20  *  Extracted v10 (ETRAX 100LX) specific stuff from arch/cris/kernel/*.c
21  *
22  *  Revision 1.12  2002/12/10 09:00:10  starvik
23  *  Merge of Linux 2.5.51
24  *
25  *  Revision 1.11  2002/12/05 07:53:10  starvik
26  *  Corrected constants used with btstq
27  *
28  *  Revision 1.10  2002/11/27 08:45:10  starvik
29  *  pid is in task_struct, not thread_info
30  *
31  *  Revision 1.9  2002/11/26 09:52:05  starvik
32  *  Added preemptive kernel scheduling (if CONFIG_PREEMPT)
33  *
34  *  Revision 1.8  2002/11/20 11:56:11  starvik
35  *  Merge of Linux 2.5.48
36  *
37  *  Revision 1.7  2002/11/18 13:02:42  starvik
38  *  Added fourth parameter to do_notify_resume
39  *  Minor cleanup
40  *
41  *  Revision 1.6  2002/11/11 10:37:50  starvik
42  *  Use new asm-offset defines
43  *  Modified for new location of current->work etc
44  *  Removed SYMBOL_NAME from syscalls
45  *  Added some new syscalls
46  *
47  *  Revision 1.5  2002/11/05 06:45:11  starvik
48  *  Merge of Linux 2.5.45
49  *
50  *  Revision 1.4  2002/02/05 15:41:31  bjornw
51  *  Rewritten to conform better to current 2.5 code (similar to arch/i386)
52  *
53  *  Revision 1.3  2002/01/21 15:22:20  bjornw
54  *  NICE_DOGGY fix from 2.4 arch/cris
55  *
56  *  Revision 1.37  2001/12/07 17:03:55  bjornw
57  *  Call a c-hook called watchdog_bite_hook instead of show_registers directly
58  *
59  *  Revision 1.36  2001/11/22 13:36:36  bjornw
60  *  * In ret_from_intr, check regs->dccr for usermode reentrance instead of
61  *    DCCR explicitely (because the latter might not reflect current reality)
62  *  * In mmu_bus_fault, set $r9 _after_ calling the C-code instead of before
63  *    since $r9 is call-clobbered and is potentially needed afterwards
64  *
65  *  Revision 1.35  2001/10/30 17:10:15  bjornw
66  *  Add some syscalls
67  *
68  *  Revision 1.34  2001/10/01 14:45:03  bjornw
69  *  Removed underscores and added register prefixes
70  *
71  *  Revision 1.33  2001/08/21 13:48:01  jonashg
72  *  Added fix by HP to avoid oops when doing a hard_reset_now.
73  *
74  *  Revision 1.32  2001/08/14 04:32:02  hp
75  *  In _resume, add comment why R9 is saved; don't sound like it's call-saved.
76  *
77  *  Revision 1.31  2001/07/25 16:07:42  bjornw
78  *  softirq_active/mask -> softirq_pending only
79  *
80  *  Revision 1.30  2001/07/05 01:03:32  hp
81  *  - include asm/errno.h to get ENOSYS.
82  *  - Use ENOSYS, not local constant LENOSYS; tweak comments.
83  *  - Explain why .include, not #include is used.
84  *  - Make oops-register-dump if watchdog bits and it's not expected.
85  *  - Don't jsr, use jump _hard_reset_now, and skip spurious nop.
86  *  - Use correct section attribute for section .rodata.
87  *  - Adjust sys_ni_syscall fill number.
88  *
89  *  Revision 1.29  2001/06/25 14:07:00  hp
90  *      Fix review comment.
91  *      * head.S: Use IO_STATE, IO_FIELD and IO_MASK constructs instead of
92  *      magic numbers.  Add comment that -traditional must not be used.
93  *      * entry.S (SYMBOL_NAME): Change redefinition to use ## concatenation.
94  *      Correct and update comment.
95  *      * Makefile (.S.o): Don't use -traditional.  Add comment why the
96  *      toplevel rule can't be used (now that there's a reason).
97  *
98  *  Revision 1.28  2001/06/21 02:00:40  hp
99  *      * entry.S: Include asm/unistd.h.
100  *      (_sys_call_table): Use section .rodata, not .data.
101  *      (_kernel_thread): Move from...
102  *      * process.c: ... here.
103  *      * entryoffsets.c (VAL): Break out from...
104  *      (OF): Use VAL.
105  *      (LCLONE_VM): New asmified value from CLONE_VM.
106  *
107  *  Revision 1.27  2001/05/29 11:25:27  markusl
108  *  In case of "spurious_interrupt", do hard_reset instead of hanging system in a loop...
109  *
110  *  Revision 1.26  2001/05/15 15:46:03  bjornw
111  *  Include config.h now that we use some CONFIG_ options
112  *
113  *  Revision 1.25  2001/05/15 05:38:47  hp
114  *  Tweaked code in _ret_from_sys_call
115  *
116  *  Revision 1.24  2001/05/15 05:27:49  hp
117  *  Save r9 in r1 over function call rather than on stack.
118  *
119  *  Revision 1.23  2001/05/15 05:10:00  hp
120  *  Generate entry.S structure offsets from C
121  *
122  *  Revision 1.22  2001/04/17 13:58:39  orjanf
123  *  * Renamed CONFIG_KGDB to CONFIG_ETRAX_KGDB.
124  *
125  *  Revision 1.21  2001/04/17 11:33:29  orjanf
126  *  Updated according to review:
127  *  * Included asm/sv_addr_ag.h to get macro for internal register.
128  *  * Corrected comment regarding system call argument passing.
129  *  * Removed comment about instruction being in a delay slot.
130  *  * Added comment about SYMBOL_NAME macro.
131  *
132  *  Revision 1.20  2001/04/12 08:51:07  hp
133  *  - Add entry for sys_fcntl64.  In fact copy last piece from i386 including ...
134  *  - .rept to fill table to safe state with sys_ni_syscall.
135  *
136  *  Revision 1.19  2001/04/04 09:43:32  orjanf
137  *  * Moved do_sigtrap from traps.c to entry.S.
138  *  * LTASK_PID need not be global anymore.
139  *
140  *  Revision 1.18  2001/03/26 09:25:02  markusl
141  *  Updated after review, should now handle USB interrupts correctly.
142  *
143  *  Revision 1.17  2001/03/21 16:12:55  bjornw
144  *  * Always make room for the cpu status record in the frame, in order to
145  *    use the same framelength and layout for both mmu busfaults and normal
146  *    irqs. No need to check for the explicit CRIS_FRAME_FIXUP type anymore.
147  *  * Fixed bug with using addq for popping the stack in the epilogue - it
148  *    destroyed the flag register. Use instructions that don't affect the
149  *    flag register instead.
150  *  * Removed write to R_PORT_PA_DATA during spurious_interrupt
151  *
152  *  Revision 1.16  2001/03/20 19:43:02  bjornw
153  *  * Get rid of esp0 setting
154  *  * Give a 7th argument to a systemcall - the stackframe
155  *
156  *  Revision 1.15  2001/03/05 13:14:30  bjornw
157  *  Spelling fix
158  *
159  *  Revision 1.14  2001/02/23 08:36:36  perf
160  *  New ABI; syscallnr=r9, arg5=mof, arg6=srp.
161  *  Corrected tracesys call check.
162  *
163  *  Revision 1.13  2001/02/15 08:40:55  perf
164  *  H-P by way of perf;
165  *  - (_system_call): Don't read system call function address into r1.
166  *  - (RBFExit): There is no such thing as a null pop.  Adjust sp by addq.
167  *  - (_system_call): Don't use r10 and don't save and restore it.
168  *  - (THREAD_ESP0): New constant.
169  *  - (_system_call): Inline set_esp0.
170  *
171  *  Revision 1.12  2001/01/31 17:56:25  orjanf
172  *  Added definition of LTASK_PID and made it global.
173  *
174  *  Revision 1.11  2001/01/10 21:13:29  bjornw
175  *  SYMBOL_NAME is defined incorrectly for the compiler options we currently use
176  *
177  *  Revision 1.10  2000/12/18 23:47:56  bjornw
178  *  * Added syscall trace support (ptrace), completely untested of course
179  *  * Removed redundant check for NULL entries in syscall_table
180  *
181  *  Revision 1.9  2000/11/21 16:40:51  bjornw
182  *  * New frame type used when an SBFS frame needs to be popped without
183  *    actually restarting the instruction
184  *  * Enable interrupts in signal_return (they did so in x86, I hope it's a good
185  *    idea)
186  *
187  *  Revision 1.8  2000/11/17 16:53:35  bjornw
188  *  Added detection of frame-type in Rexit, so that mmu_bus_fault can
189  *  use ret_from_intr in the return-path to check for signals (like SEGV)
190  *  and other foul things that might have occurred during the fault.
191  *
192  *  Revision 1.7  2000/10/06 15:04:28  bjornw
193  *  Include mof in register savings
194  *
195  *  Revision 1.6  2000/09/12 16:02:44  bjornw
196  *  Linux-2.4.0-test7 derived updates
197  *
198  *  Revision 1.5  2000/08/17 15:35:15  bjornw
199  *  2.4.0-test6 changed local_irq_count and friends API
200  *
201  *  Revision 1.4  2000/08/02 13:59:30  bjornw
202  *  Removed olduname and uname from the syscall list
203  *
204  *  Revision 1.3  2000/07/31 13:32:58  bjornw
205  *  * Export ret_from_intr
206  *  * _resume updated (prev/last tjohejsan)
207  *  * timer_interrupt obsolete
208  *  * SIGSEGV detection in mmu_bus_fault temporarily disabled
209  *
210  *
211  */
212
213 /*
214  * entry.S contains the system-call and fault low-level handling routines.
215  *
216  * NOTE: This code handles signal-recognition, which happens every time
217  * after a timer-interrupt and after each system call.
218  *
219  * Stack layout in 'ret_from_system_call':
220  *      ptrace needs to have all regs on the stack.
221  *      if the order here is changed, it needs to be 
222  *      updated in fork.c:copy_process, signal.c:do_signal,
223  *      ptrace.c and ptrace.h
224  *
225  */
226
227 #include <linux/config.h>
228 #include <linux/linkage.h>
229 #include <linux/sys.h>
230 #include <asm/unistd.h>
231 #include <asm/arch/sv_addr_ag.h>
232 #include <asm/errno.h>
233 #include <asm/thread_info.h>
234 #include <asm/arch/offset.h>
235                 
236         ;; functions exported from this file
237         
238         .globl system_call
239         .globl ret_from_intr
240         .globl ret_from_fork
241         .globl resume
242         .globl multiple_interrupt
243         .globl hwbreakpoint
244         .globl IRQ1_interrupt
245         .globl spurious_interrupt
246         .globl hw_bp_trigs
247         .globl mmu_bus_fault
248         .globl do_sigtrap
249         .globl gdb_handle_breakpoint
250         .globl sys_call_table
251         
252         ;; below are various parts of system_call which are not in the fast-path
253         
254 #ifdef CONFIG_PREEMPT   
255         ; Check if preemptive kernel scheduling should be done
256 _resume_kernel:
257         ; Load current task struct
258         movs.w  -8192, $r0      ;  THREAD_SIZE = 8192
259         and.d   $sp, $r0
260         move.d  [$r0+TI_preempt_count], $r10    ;  Preemption disabled?
261         bne     _Rexit
262         nop
263 _need_resched:
264         move.d  [$r0+TI_flags], $r10
265         btstq   TIF_NEED_RESCHED, $r10  ; Check if need_resched is set
266         bpl     _Rexit
267         nop
268         ; Ok, lets's do some preemptive kernel scheduling
269         move.d  PREEMPT_ACTIVE, $r10
270         move.d  $r10, [$r0+TI_preempt_count] ; Mark as active
271         ei
272         jsr     schedule
273         clear.d [$r0+TI_preempt_count] ;  Mark as inactive
274         di
275         ; Load new task struct
276         movs.w  -8192, $r0      ;  THREAD_SIZE = 8192
277         and.d   $sp, $r0
278         ; One more time (with new task)
279         ba      _need_resched
280         nop
281 #else
282 #define _resume_kernel _Rexit
283 #endif  
284
285         ; Called at exit from fork. schedule_tail must be called to drop
286         ; spinlock if CONFIG_PREEMPT
287 ret_from_fork:
288         jsr schedule_tail
289         ba  ret_from_sys_call
290         nop
291                 
292 ret_from_intr:
293         ;; check for resched if preemptive kernel or if we're going back to user-mode 
294         ;; this test matches the user_regs(regs) macro
295         ;; we cannot simply test $dccr, because that does not necessarily
296         ;; reflect what mode we'll return into.
297         
298         move.d  [$sp + PT_dccr], $r0; regs->dccr
299         btstq   8, $r0          ; U-flag
300         bpl     _resume_kernel
301         ; Note that di below is in delay slot 
302         
303 _resume_userspace:
304         di                      ; so need_resched and sigpending don't change
305
306         movs.w  -8192, $r0      ; THREAD_SIZE == 8192
307         and.d   $sp, $r0
308
309         move.d  [$r0+TI_flags], $r10    ; current->work
310         and.d   _TIF_WORK_MASK, $r10    ; is there any work to be done on return
311         bne     _work_pending
312         nop
313         ba      _Rexit
314         nop
315         
316         ;; The system_call is called by a BREAK instruction, which works like
317         ;; an interrupt call but it stores the return PC in BRP instead of IRP.
318         ;; Since we dont really want to have two epilogues (one for system calls
319         ;; and one for interrupts) we push the contents of BRP instead of IRP in the
320         ;; system call prologue, to make it look like an ordinary interrupt on the
321         ;; stackframe.
322         ;;
323         ;; Since we can't have system calls inside interrupts, it should not matter
324         ;; that we don't stack IRP.
325         ;; 
326         ;; In r9 we have the wanted syscall number. Arguments come in r10,r11,r12,r13,mof,srp
327         ;;
328         ;; This function looks on the _surface_ like spaghetti programming, but it's
329         ;; really designed so that the fast-path does not force cache-loading of non-used
330         ;; instructions. Only the non-common cases cause the outlined code to run..
331
332 system_call:
333         ;; stack-frame similar to the irq heads, which is reversed in ret_from_sys_call
334         move    $brp,[$sp=$sp-16]; instruction pointer and room for a fake SBFS frame
335         push    $srp
336         push    $dccr
337         push    $mof
338         subq    14*4, $sp               ; make room for r0-r13
339         movem   $r13, [$sp]     ; push r0-r13
340         push    $r10            ; push orig_r10
341         clear.d [$sp=$sp-4]     ; frametype == 0, normal stackframe
342         
343         movs.w  -ENOSYS, $r0
344         move.d  $r0, [$sp+PT_r10]       ; put the default return value in r10 in the frame
345
346         ;; check if this process is syscall-traced
347
348         movs.w  -8192, $r0      ; THREAD_SIZE == 8192
349         and.d   $sp, $r0
350         
351         move.d  [$r0+TI_flags], $r0
352         btstq   TIF_SYSCALL_TRACE, $r0
353         bmi     _syscall_trace_entry
354         nop     
355
356 _syscall_traced:        
357
358         ;; check for sanity in the requested syscall number
359         
360         cmpu.w  NR_syscalls, $r9        
361         bcc     ret_from_sys_call
362         lslq    2, $r9          ;  multiply by 4, in the delay slot
363
364         ;; as a bonus 7th parameter, we give the location on the stack
365         ;; of the register structure itself. some syscalls need this.
366
367         push    $sp
368         
369         ;; the parameter carrying registers r10, r11, r12 and 13 are intact.
370         ;; the fifth and sixth parameters (if any) was in mof and srp 
371         ;; respectively, and we need to put them on the stack.
372
373         push    $srp
374         push    $mof
375         
376         jsr     [$r9+sys_call_table]    ; actually do the system call
377         addq    3*4, $sp                ; pop the mof, srp and regs parameters
378         move.d  $r10, [$sp+PT_r10]      ; save the return value
379
380         moveq   1, $r9          ; "parameter" to ret_from_sys_call to show it was a sys call
381         
382         ;; fall through into ret_from_sys_call to return
383         
384 ret_from_sys_call:
385         ;; r9 is a parameter - if >=1 we came from a syscall, if 0, from an irq
386                 
387         ;; get the current task-struct pointer (see top for defs)
388
389         movs.w  -8192, $r0      ; THREAD_SIZE == 8192 
390         and.d   $sp, $r0
391
392         di                      ; make sure need_resched and sigpending don't change
393         move.d  [$r0+TI_flags],$r1
394         and.d   _TIF_ALLWORK_MASK, $r1
395         bne     _syscall_exit_work
396         nop
397
398 _Rexit:
399         ;; this epilogue MUST match the prologues in multiple_interrupt, irq.h and ptregs.h
400         pop     $r10            ; frametype
401         bne     _RBFexit        ; was not CRIS_FRAME_NORMAL, handle otherwise
402         addq    4, $sp          ; skip orig_r10, in delayslot
403         movem   [$sp+], $r13    ; registers r0-r13
404         pop     $mof            ; multiply overflow register 
405         pop     $dccr           ; condition codes
406         pop     $srp            ; subroutine return pointer
407         ;; now we have a 4-word SBFS frame which we do not want to restore
408         ;; using RBF since it was not stacked with SBFS. instead we would like to
409         ;; just get the PC value to restart it with, and skip the rest of
410         ;; the frame.
411         ;; Also notice that it's important to use instructions here that
412         ;; keep the interrupts disabled (since we've already popped DCCR)
413         move    [$sp=$sp+16], $p8; pop the SBFS frame from the sp
414         jmpu    [$sp-16]        ; return through the irp field in the sbfs frame
415
416 _RBFexit:
417         movem   [$sp+], $r13    ; registers r0-r13, in delay slot
418         pop     $mof            ; multiply overflow register 
419         pop     $dccr           ; condition codes
420         pop     $srp            ; subroutine return pointer
421         rbf     [$sp+]          ; return by popping the CPU status
422
423         ;; We get here after doing a syscall if extra work might need to be done
424         ;; perform syscall exit tracing if needed
425         
426 _syscall_exit_work:
427         ;; $r0 contains current at this point and irq's are disabled
428
429         move.d  [$r0+TI_flags], $r1
430         btstq   TIF_SYSCALL_TRACE, $r1
431         bpl     _work_pending
432         nop
433         
434         ei
435
436         move.d  $r9, $r1        ; preserve r9
437         jsr     do_syscall_trace
438         move.d  $r1, $r9
439         
440         ba      _resume_userspace
441         nop
442         
443 _work_pending:
444         move.d  [$r0+TI_flags], $r1
445         btstq   TIF_NEED_RESCHED, $r1
446         bpl     _work_notifysig ; was neither trace nor sched, must be signal/notify
447         nop
448         
449 _work_resched:
450         move.d  $r9, $r1        ; preserve r9
451         jsr     schedule
452         move.d  $r1, $r9
453         di
454
455         move.d  [$r0+TI_flags], $r1
456         and.d   _TIF_WORK_MASK, $r1; ignore the syscall trace counter
457         beq     _Rexit
458         nop
459         btstq   TIF_NEED_RESCHED, $r1
460         bmi     _work_resched   ; current->work.need_resched
461         nop
462
463 _work_notifysig:
464         ;; deal with pending signals and notify-resume requests
465
466         move.d  $r9, $r10       ; do_notify_resume syscall/irq param
467         moveq   0, $r11         ; oldset param - 0 in this case
468         move.d  $sp, $r12       ; the regs param
469         move.d  $r1, $r13       ; the thread_info_flags parameter
470         jsr     do_notify_resume
471         
472         ba _Rexit
473         nop
474
475         ;; We get here as a sidetrack when we've entered a syscall with the
476         ;; trace-bit set. We need to call do_syscall_trace and then continue
477         ;; with the call.
478         
479 _syscall_trace_entry:
480         ;; PT_r10 in the frame contains -ENOSYS as required, at this point
481         
482         jsr     do_syscall_trace
483
484         ;; now re-enter the syscall code to do the syscall itself
485         ;; we need to restore $r9 here to contain the wanted syscall, and
486         ;; the other parameter-bearing registers
487
488         move.d  [$sp+PT_r9], $r9
489         move.d  [$sp+PT_orig_r10], $r10  ; PT_r10 is already filled with -ENOSYS.
490         move.d  [$sp+PT_r11],      $r11
491         move.d  [$sp+PT_r12],      $r12
492         move.d  [$sp+PT_r13],      $r13
493         move    [$sp+PT_mof],      $mof
494         move    [$sp+PT_srp],      $srp
495         
496         ba      _syscall_traced
497         nop
498         
499         ;; resume performs the actual task-switching, by switching stack pointers
500         ;; input arguments: r10 = prev, r11 = next, r12 = thread offset in task struct
501         ;; returns old current in r10
502         ;;
503         ;; TODO:  see the i386 version. The switch_to which calls resume in our version
504         ;;        could really be an inline asm of this.
505
506 resume: 
507         push    $srp                     ; we keep the old/new PC on the stack 
508         add.d   $r12, $r10               ; r10 = current tasks tss
509         move    $dccr, [$r10+THREAD_dccr]; save irq enable state
510         di
511
512         move    $usp, [$r10+ THREAD_usp] ; save user-mode stackpointer
513         
514         ;; See copy_thread for the reason why register R9 is saved.
515         subq    10*4, $sp
516         movem   $r9, [$sp]               ; save non-scratch registers and R9.
517         
518         move.d  $sp, [$r10+THREAD_ksp]   ; save the kernel stack pointer for the old task
519         move.d  $sp, $r10                ; return last running task in r10
520         and.d   -8192, $r10              ; get thread_info from stackpointer
521         move.d  [$r10+TI_task], $r10     ; get task  
522         add.d   $r12, $r11               ; find the new tasks tss
523         move.d  [$r11+THREAD_ksp], $sp   ; switch into the new stackframe by restoring kernel sp
524
525         movem   [$sp+], $r9              ; restore non-scratch registers and R9.
526
527         move    [$r11+THREAD_usp], $usp ; restore user-mode stackpointer
528         
529         move    [$r11+THREAD_dccr], $dccr ; restore irq enable status
530         jump    [$sp+]                   ; restore PC
531
532         ;; This is the MMU bus fault handler.
533         ;; It needs to stack the CPU status and overall is different
534         ;; from the other interrupt handlers.
535
536 mmu_bus_fault:  
537         sbfs    [$sp=$sp-16]    ; push the internal CPU status
538         ;; the first longword in the sbfs frame was the interrupted PC
539         ;; which fits nicely with the "IRP" slot in pt_regs normally used to
540         ;; contain the return address. used by Oops to print kernel errors..
541         push    $srp            ; make a stackframe similar to pt_regs
542         push    $dccr
543         push    $mof
544         di
545         subq    14*4, $sp
546         movem   $r13, [$sp]
547         push    $r10            ; dummy orig_r10
548         moveq   1, $r10
549         push    $r10            ; frametype == 1, BUSFAULT frame type
550
551         move.d  $sp, $r10       ; pt_regs argument to handle_mmu_bus_fault
552                 
553         jsr     handle_mmu_bus_fault  ; in arch/cris/mm/fault.c
554
555         ;; now we need to return through the normal path, we cannot just
556         ;; do the RBFexit since we might have killed off the running
557         ;; process due to a SEGV, scheduled due to a page blocking or
558         ;; whatever.
559
560         moveq   0, $r9          ; busfault is equivalent to an irq
561                 
562         ba      ret_from_intr
563         nop
564                 
565         ;; special handlers for breakpoint and NMI
566 #if 0                   
567 hwbreakpoint:
568         push    $dccr
569         di
570         push    $r10
571         push    $r11
572         push    $r12
573         push    $r13
574         clearf  b
575         move    $brp,$r11
576         move.d  [hw_bp_msg],$r10
577         jsr     printk
578         setf    b
579         pop     $r13
580         pop     $r12
581         pop     $r11
582         pop     $r10
583         pop     $dccr
584         retb
585         nop
586 #else
587 hwbreakpoint:
588         push    $dccr
589         di
590 #if 1
591         push    $r10
592         push    $r11
593         move.d  [hw_bp_trig_ptr],$r10
594         move.d  [$r10],$r11
595         cmp.d   42,$r11
596         beq     1f
597         nop
598         move    $brp,$r11
599         move.d  $r11,[$r10+]
600         move.d  $r10,[hw_bp_trig_ptr]
601 1:      pop     $r11
602         pop     $r10
603 #endif
604         pop     $dccr
605         retb
606         nop
607 #endif
608         
609 IRQ1_interrupt:
610
611 #if defined(CONFIG_ETRAX_WATCHDOG) && !defined(CONFIG_SVINTO_SIM)
612 ;; If we receive a watchdog interrupt while it is not expected, then set
613 ;; up a canonical frame and dump register contents before dying.
614
615         ;; this prologue MUST match the one in irq.h and the struct in ptregs.h!!!
616         move    $brp,[$sp=$sp-16]; instruction pointer and room for a fake SBFS frame
617         push    $srp
618         push    $dccr
619         push    $mof
620         di
621         subq    14*4, $sp
622         movem   $r13, [$sp]
623         push    $r10            ; push orig_r10
624         clear.d [$sp=$sp-4]     ; frametype == 0, normal frame
625
626 ;; We don't check that we actually were bit by the watchdog as opposed to
627 ;; an external NMI, since there is currently no handler for external NMI.
628
629 ;; Check if we're waiting for reset to happen, as signalled by
630 ;; hard_reset_now setting cause_of_death to a magic value.  If so, just
631 ;; get stuck until reset happens.
632         .comm   cause_of_death, 4       ;; Don't declare this anywhere.
633         move.d  [cause_of_death], $r10
634         cmp.d   0xbedead, $r10
635 _killed_by_death:
636         beq     _killed_by_death
637         nop
638
639 ;; We'll see this in ksymoops dumps.
640 Watchdog_bite:
641
642 #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
643        ;; We just restart the watchdog here to be sure we dont get
644        ;; hit while printing the watchdogmsg below
645        ;; This restart is compatible with the rest of the C-code, so
646        ;; the C-code can keep restarting the watchdog after this point.
647        ;; The non-NICE_DOGGY code below though, disables the possibility
648        ;; to restart since it changes the watchdog key, to avoid any
649        ;; buggy loops etc. keeping the watchdog alive after this.
650        jsr     reset_watchdog
651 #else
652
653 ;; We need to extend the 3.3ms after the NMI at watchdog bite, so we have
654 ;; time for an oops-dump over a 115k2 serial wire.  Another 100ms should do.
655
656 ;; Change the watchdog key to an arbitrary 3-bit value and restart the
657 ;; watchdog.
658 #define WD_INIT 2
659         moveq     IO_FIELD (R_WATCHDOG, key, WD_INIT), $r10
660         move.d  R_WATCHDOG, $r11
661
662         move.d  $r10, [$r11]
663         moveq     IO_FIELD (R_WATCHDOG, key,                            \
664                             IO_EXTRACT (R_WATCHDOG, key,                \
665                                         IO_MASK (R_WATCHDOG, key))      \
666                             ^ WD_INIT)                                  \
667                 | IO_STATE (R_WATCHDOG, enable, start), $r10
668         move.d  $r10, [$r11]
669
670 #endif
671         
672 ;; Note that we don't do "setf m" here (or after two necessary NOPs),
673 ;; since *not* doing that saves us from re-entrancy checks.  We don't want
674 ;; to get here again due to possible subsequent NMIs; we want the watchdog
675 ;; to reset us.
676
677         move.d  _watchdogmsg,$r10
678         jsr     printk
679
680         move.d  $sp, $r10
681         jsr     watchdog_bite_hook
682
683 ;; This nop is here so we see the "Watchdog_bite" label in ksymoops dumps
684 ;; rather than "spurious_interrupt".
685         nop
686 ;; At this point we drop down into spurious_interrupt, which will do a
687 ;; hard reset.
688
689         .section .rodata,"a"
690 _watchdogmsg:
691         .ascii  "Oops: bitten by watchdog\n\0"
692         .previous
693
694 #endif /* CONFIG_ETRAX_WATCHDOG and not CONFIG_SVINTO_SIM */
695
696 spurious_interrupt:     
697         di
698         jump hard_reset_now
699
700         ;; this handles the case when multiple interrupts arrive at the same time
701         ;; we jump to the first set interrupt bit in a priority fashion
702         ;; the hardware will call the unserved interrupts after the handler finishes
703         
704 multiple_interrupt:
705         ;; this prologue MUST match the one in irq.h and the struct in ptregs.h!!!
706         move    $irp,[$sp=$sp-16]; instruction pointer and room for a fake SBFS frame
707         push    $srp
708         push    $dccr
709         push    $mof
710         di
711         subq    14*4, $sp
712         movem   $r13, [$sp]
713         push    $r10            ; push orig_r10
714         clear.d [$sp=$sp-4]     ; frametype == 0, normal frame
715         
716         move.d  irq_shortcuts + 8, $r1
717         moveq   2, $r2          ; first bit we care about is the timer0 irq
718         move.d  [R_VECT_MASK_RD], $r0; read the irq bits that triggered the multiple irq
719 1:      
720         btst    $r2, $r0        ; check for the irq given by bit r2
721         bmi     _do_shortcut    ; actually do the shortcut
722         nop
723         addq    1, $r2          ; next vector bit
724         addq    4, $r1          ; next vector
725         cmp.b   32, $r2
726         bne     1b      ; process all irq's up to and including number 31
727         nop
728         
729         ;; strange, we didn't get any set vector bits.. oh well, just return
730         
731         ba      _Rexit
732         nop
733
734 _do_shortcut:
735         test.d  [$r1]
736         beq     _Rexit
737         nop
738         jump    [$r1]           ; jump to the irq handlers shortcut
739
740 do_sigtrap:
741         ;; 
742         ;; SIGTRAP the process that executed the break instruction.
743         ;; Make a frame that Rexit in entry.S expects.
744         ;;
745         move    $brp, [$sp=$sp-16]      ; Push BRP while faking a cpu status record.
746         push    $srp                    ; Push subroutine return pointer.
747         push    $dccr                   ; Push condition codes.
748         push    $mof                    ; Push multiply overflow reg.
749         di                              ; Need to disable irq's at this point.
750         subq    14*4, $sp               ; Make room for r0-r13.
751         movem   $r13, [$sp]             ; Push the r0-r13 registers.
752         push    $r10                    ; Push orig_r10.
753         clear.d [$sp=$sp-4]             ; Frametype - this is a normal stackframe.
754
755         movs.w  -8192,$r9               ; THREAD_SIZE == 8192
756         and.d   $sp, $r9
757         move.d  [$r9+TI_task], $r10
758         move.d  [$r10+TASK_pid], $r10   ; current->pid as arg1. 
759         moveq   5, $r11                 ; SIGTRAP as arg2.
760         jsr     sys_kill       
761         jump    ret_from_intr           ; Use the return routine for interrupts.
762
763 gdb_handle_breakpoint:  
764         push    $dccr
765         push    $r0
766 #ifdef CONFIG_ETRAX_KGDB
767         move    $dccr, $r0              ; U-flag not affected by previous insns. 
768         btstq   8, $r0                  ; Test the U-flag.
769         bmi     _ugdb_handle_breakpoint ; Go to user mode debugging. 
770         nop                             ; Empty delay slot (cannot pop r0 here). 
771         pop     $r0                     ; Restore r0.
772         ba      kgdb_handle_breakpoint  ; Go to kernel debugging. 
773         pop     $dccr                   ; Restore dccr in delay slot.
774 #endif
775         
776 _ugdb_handle_breakpoint:        
777         move    $brp, $r0               ; Use r0 temporarily for calculation.
778         subq    2, $r0                  ; Set to address of previous instruction.
779         move    $r0, $brp
780         pop     $r0                     ; Restore r0. 
781         ba      do_sigtrap              ; SIGTRAP the offending process. 
782         pop     $dccr                   ; Restore dccr in delay slot.
783         
784         .data
785
786 hw_bp_trigs:
787         .space 64*4
788 hw_bp_trig_ptr:
789         .dword hw_bp_trigs
790
791         .section .rodata,"a"
792 sys_call_table: 
793         .long sys_restart_syscall       /* 0 - old "setup()" system call, used for restarting */
794         .long sys_exit
795         .long sys_fork
796         .long sys_read
797         .long sys_write
798         .long sys_open          /* 5 */
799         .long sys_close
800         .long sys_waitpid
801         .long sys_creat
802         .long sys_link
803         .long sys_unlink        /* 10 */
804         .long sys_execve
805         .long sys_chdir
806         .long sys_time
807         .long sys_mknod
808         .long sys_chmod         /* 15 */
809         .long sys_lchown16
810         .long sys_ni_syscall    /* old break syscall holder */
811         .long sys_stat
812         .long sys_lseek
813         .long sys_getpid        /* 20 */
814         .long sys_mount
815         .long sys_oldumount
816         .long sys_setuid16
817         .long sys_getuid16
818         .long sys_stime         /* 25 */
819         .long sys_ptrace
820         .long sys_alarm
821         .long sys_fstat
822         .long sys_pause
823         .long sys_utime         /* 30 */
824         .long sys_ni_syscall    /* old stty syscall holder */
825         .long sys_ni_syscall    /* old gtty syscall holder */
826         .long sys_access
827         .long sys_nice
828         .long sys_ni_syscall    /* 35  old ftime syscall holder */
829         .long sys_sync
830         .long sys_kill
831         .long sys_rename
832         .long sys_mkdir
833         .long sys_rmdir         /* 40 */
834         .long sys_dup
835         .long sys_pipe
836         .long sys_times
837         .long sys_ni_syscall    /* old prof syscall holder */
838         .long sys_brk           /* 45 */
839         .long sys_setgid16
840         .long sys_getgid16
841         .long sys_signal
842         .long sys_geteuid16
843         .long sys_getegid16     /* 50 */
844         .long sys_acct
845         .long sys_umount        /* recycled never used phys( */
846         .long sys_ni_syscall    /* old lock syscall holder */
847         .long sys_ioctl
848         .long sys_fcntl         /* 55 */
849         .long sys_ni_syscall    /* old mpx syscall holder */
850         .long sys_setpgid
851         .long sys_ni_syscall    /* old ulimit syscall holder */
852         .long sys_ni_syscall    /* old sys_olduname holder */
853         .long sys_umask         /* 60 */
854         .long sys_chroot
855         .long sys_ustat
856         .long sys_dup2
857         .long sys_getppid
858         .long sys_getpgrp       /* 65 */
859         .long sys_setsid
860         .long sys_sigaction
861         .long sys_sgetmask
862         .long sys_ssetmask
863         .long sys_setreuid16    /* 70 */
864         .long sys_setregid16
865         .long sys_sigsuspend
866         .long sys_sigpending
867         .long sys_sethostname
868         .long sys_setrlimit     /* 75 */
869         .long sys_old_getrlimit
870         .long sys_getrusage
871         .long sys_gettimeofday
872         .long sys_settimeofday
873         .long sys_getgroups16   /* 80 */
874         .long sys_setgroups16
875         .long sys_select        /* was old_select in Linux/E100 */
876         .long sys_symlink
877         .long sys_lstat
878         .long sys_readlink      /* 85 */
879         .long sys_uselib
880         .long sys_swapon
881         .long sys_reboot
882         .long old_readdir
883         .long old_mmap          /* 90 */
884         .long sys_munmap
885         .long sys_truncate
886         .long sys_ftruncate
887         .long sys_fchmod
888         .long sys_fchown16      /* 95 */
889         .long sys_getpriority
890         .long sys_setpriority
891         .long sys_ni_syscall    /* old profil syscall holder */
892         .long sys_statfs
893         .long sys_fstatfs       /* 100 */
894         .long sys_ni_syscall    /* sys_ioperm in i386 */
895         .long sys_socketcall
896         .long sys_syslog
897         .long sys_setitimer
898         .long sys_getitimer     /* 105 */
899         .long sys_newstat
900         .long sys_newlstat
901         .long sys_newfstat
902         .long sys_ni_syscall    /* old sys_uname holder */
903         .long sys_ni_syscall    /* sys_iopl in i386 */
904         .long sys_vhangup
905         .long sys_ni_syscall    /* old "idle" system call */
906         .long sys_ni_syscall    /* vm86old in i386 */
907         .long sys_wait4
908         .long sys_swapoff       /* 115 */
909         .long sys_sysinfo
910         .long sys_ipc
911         .long sys_fsync
912         .long sys_sigreturn
913         .long sys_clone         /* 120 */
914         .long sys_setdomainname
915         .long sys_newuname
916         .long sys_ni_syscall    /* sys_modify_ldt */
917         .long sys_adjtimex
918         .long sys_mprotect      /* 125 */
919         .long sys_sigprocmask
920         .long sys_ni_syscall    /* old "create_module" */ 
921         .long sys_init_module
922         .long sys_delete_module
923         .long sys_ni_syscall    /* 130: old "get_kernel_syms" */
924         .long sys_quotactl
925         .long sys_getpgid
926         .long sys_fchdir
927         .long sys_bdflush
928         .long sys_sysfs         /* 135 */
929         .long sys_personality
930         .long sys_ni_syscall    /* for afs_syscall */
931         .long sys_setfsuid16
932         .long sys_setfsgid16
933         .long sys_llseek        /* 140 */
934         .long sys_getdents
935         .long sys_select
936         .long sys_flock
937         .long sys_msync
938         .long sys_readv         /* 145 */
939         .long sys_writev
940         .long sys_getsid
941         .long sys_fdatasync
942         .long sys_sysctl
943         .long sys_mlock         /* 150 */
944         .long sys_munlock
945         .long sys_mlockall
946         .long sys_munlockall
947         .long sys_sched_setparam
948         .long sys_sched_getparam        /* 155 */
949         .long sys_sched_setscheduler
950         .long sys_sched_getscheduler
951         .long sys_sched_yield
952         .long sys_sched_get_priority_max
953         .long sys_sched_get_priority_min        /* 160 */
954         .long sys_sched_rr_get_interval
955         .long sys_nanosleep
956         .long sys_mremap
957         .long sys_setresuid16
958         .long sys_getresuid16   /* 165 */
959         .long sys_ni_syscall    /* sys_vm86 */
960         .long sys_ni_syscall    /* Old sys_query_module */
961         .long sys_poll
962         .long sys_nfsservctl
963         .long sys_setresgid16   /* 170 */
964         .long sys_getresgid16
965         .long sys_prctl
966         .long sys_rt_sigreturn
967         .long sys_rt_sigaction
968         .long sys_rt_sigprocmask        /* 175 */
969         .long sys_rt_sigpending
970         .long sys_rt_sigtimedwait
971         .long sys_rt_sigqueueinfo
972         .long sys_rt_sigsuspend
973         .long sys_pread64       /* 180 */
974         .long sys_pwrite64
975         .long sys_chown16
976         .long sys_getcwd
977         .long sys_capget
978         .long sys_capset        /* 185 */
979         .long sys_sigaltstack
980         .long sys_sendfile
981         .long sys_ni_syscall    /* streams1 */
982         .long sys_ni_syscall    /* streams2 */
983         .long sys_vfork         /* 190 */
984         .long sys_getrlimit
985         .long sys_mmap2
986         .long sys_truncate64
987         .long sys_ftruncate64
988         .long sys_stat64        /* 195 */
989         .long sys_lstat64
990         .long sys_fstat64
991         .long sys_lchown
992         .long sys_getuid
993         .long sys_getgid        /* 200 */
994         .long sys_geteuid
995         .long sys_getegid
996         .long sys_setreuid
997         .long sys_setregid
998         .long sys_getgroups     /* 205 */
999         .long sys_setgroups
1000         .long sys_fchown
1001         .long sys_setresuid
1002         .long sys_getresuid
1003         .long sys_setresgid     /* 210 */
1004         .long sys_getresgid
1005         .long sys_chown
1006         .long sys_setuid
1007         .long sys_setgid
1008         .long sys_setfsuid      /* 215 */
1009         .long sys_setfsgid
1010         .long sys_pivot_root
1011         .long sys_mincore
1012         .long sys_madvise
1013         .long sys_getdents64    /* 220 */
1014         .long sys_fcntl64
1015         .long sys_ni_syscall    /* reserved for TUX */
1016         .long sys_ni_syscall
1017         .long sys_gettid
1018         .long sys_readahead     /* 225 */
1019         .long sys_setxattr
1020         .long sys_lsetxattr
1021         .long sys_fsetxattr
1022         .long sys_getxattr
1023         .long sys_lgetxattr     /* 230 */
1024         .long sys_fgetxattr
1025         .long sys_listxattr
1026         .long sys_llistxattr
1027         .long sys_flistxattr
1028         .long sys_removexattr   /* 235 */
1029         .long sys_lremovexattr
1030         .long sys_fremovexattr
1031         .long sys_tkill
1032         .long sys_sendfile64
1033         .long sys_futex         /* 240 */
1034         .long sys_sched_setaffinity
1035         .long sys_sched_getaffinity
1036         .long sys_ni_syscall    /* sys_set_thread_area */
1037         .long sys_ni_syscall    /* sys_get_thread_area */
1038         .long sys_io_setup      /* 245 */
1039         .long sys_io_destroy
1040         .long sys_io_getevents
1041         .long sys_io_submit
1042         .long sys_io_cancel
1043         .long sys_fadvise64     /* 250 */
1044         .long sys_ni_syscall
1045         .long sys_exit_group
1046         .long sys_lookup_dcookie
1047         .long sys_epoll_create
1048         .long sys_epoll_ctl     /* 255 */
1049         .long sys_epoll_wait
1050         .long sys_remap_file_pages
1051         .long sys_set_tid_address
1052         .long sys_timer_create
1053         .long sys_timer_settime         /* 260 */
1054         .long sys_timer_gettime
1055         .long sys_timer_getoverrun
1056         .long sys_timer_delete
1057         .long sys_clock_settime
1058         .long sys_clock_gettime         /* 265 */
1059         .long sys_clock_getres
1060         .long sys_clock_nanosleep
1061         .long sys_statfs64
1062         .long sys_fstatfs64     
1063                 
1064         /*
1065          * NOTE!! This doesn't have to be exact - we just have
1066          * to make sure we have _enough_ of the "sys_ni_syscall"
1067          * entries. Don't panic if you notice that this hasn't
1068          * been shrunk every time we add a new system call.
1069          */
1070
1071         .rept NR_syscalls-(.-sys_call_table)/4
1072                 .long sys_ni_syscall
1073         .endr
1074