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