2 * Copyright (C) 2000-2003 Axis Communications AB
4 * Authors: Bjorn Wesen (bjornw@axis.com)
5 * Tobias Anderberg (tobiasa@axis.com), CRISv32 port.
7 * Code for the system-call and fault low-level handling routines.
9 * NOTE: This code handles signal-recognition, which happens every time
10 * after a timer-interrupt and after each system call.
12 * Stack layout in 'ret_from_system_call':
13 * ptrace needs to have all regs on the stack.
14 * if the order here is changed, it needs to be
15 * updated in fork.c:copy_process, signal.c:do_signal,
16 * ptrace.c and ptrace.h
20 #include <linux/config.h>
21 #include <linux/linkage.h>
22 #include <linux/sys.h>
23 #include <asm/unistd.h>
24 #include <asm/errno.h>
25 #include <asm/thread_info.h>
26 #include <asm/arch/offset.h>
28 #include <asm/arch/hwregs/asm/reg_map_asm.h>
29 #include <asm/arch/hwregs/asm/intr_vect_defs_asm.h>
31 ;; Exported functions.
36 .globl multiple_interrupt
38 .globl spurious_interrupt
40 .globl gdb_handle_exception
43 ; Check if preemptive kernel scheduling should be done.
47 ; Load current task struct.
48 movs.w -8192, $r0 ; THREAD_SIZE = 8192
51 addoq +TI_preempt_count, $r0, $acr
52 move.d [$acr], $r10 ; Preemption disabled?
57 addoq +TI_flags, $r0, $acr
59 btstq TIF_NEED_RESCHED, $r10 ; Check if need_resched is set.
63 ; Do preemptive kernel scheduling.
64 jsr preempt_schedule_irq
67 ; Load new task struct.
68 movs.w -8192, $r0 ; THREAD_SIZE = 8192.
71 ; One more time with new task.
75 #define _resume_kernel _Rexit
78 ; Called at exit from fork. schedule_tail must be called to drop
79 ; spinlock if CONFIG_PREEMPT.
87 ;; Check for resched if preemptive kernel, or if we're going back to
88 ;; user-mode. This test matches the user_regs(regs) macro. Don't simply
89 ;; test CCS since that doesn't necessarily reflect what mode we'll
91 addoq +PT_ccs, $sp, $acr
93 btstq 16, $r0 ; User-mode flag.
96 ; Note that di below is in delay slot.
99 di ; So need_resched and sigpending don't change.
101 movs.w -8192, $r0 ; THREAD_SIZE == 8192
104 addoq +TI_flags, $r0, $acr ; current->work
106 and.d _TIF_WORK_MASK, $r10 ; Work to be done on return?
112 ;; The system_call is called by a BREAK instruction, which looks pretty
113 ;; much like any other exception.
115 ;; System calls can't be made from interrupts but we still stack ERP
116 ;; to have a complete stack frame.
118 ;; In r9 we have the wanted syscall number. Arguments come in r10,r11,r12,
121 ;; This function looks on the _surface_ like spaghetti programming, but it's
122 ;; really designed so that the fast-path does not force cache-loading of
123 ;; non-used instructions. Only the non-common cases cause the outlined code
127 ;; Stack-frame similar to the irq heads, which is reversed in
128 ;; ret_from_sys_call.
129 subq 12, $sp ; Skip EXS, EDA.
136 ei ; Allow IRQs while handling system call
144 subq 14*4, $sp ; Make room for R0-R13.
145 movem $r13, [$sp] ; Push R0-R13
147 move.d $r10, [$sp] ; Push orig_r10.
149 ; Set S-bit when kernel debugging to keep hardware breakpoints active.
150 #ifdef CONFIG_ETRAX_KGDB
157 addoq +PT_r10, $sp, $acr
160 ;; Check if this process is syscall-traced.
161 movs.w -8192, $r0 ; THREAD_SIZE == 8192
164 addoq +TI_flags, $r0, $acr
166 btstq TIF_SYSCALL_TRACE, $r0
167 bmi _syscall_trace_entry
171 ;; Check for sanity in the requested syscall number.
172 cmpu.w NR_syscalls, $r9
173 bhs ret_from_sys_call
174 lslq 2, $r9 ; Multiply by 4, in the delay slot.
176 ;; The location on the stack for the register structure is passed as a
177 ;; seventh argument. Some system calls need this.
182 ;; The registers carrying parameters (R10-R13) are intact. The optional
183 ;; fifth and sixth parameters is in MOF and SRP respectivly. Put them
184 ;; back on the stack.
190 ;; Actually to the system call.
191 addo.d +sys_call_table, $r9, $acr
196 addq 3*4, $sp ; Pop the mof, srp and regs parameters.
197 addoq +PT_r10, $sp, $acr
198 move.d $r10, [$acr] ; Save the return value.
200 moveq 1, $r9 ; "Parameter" to ret_from_sys_call to
201 ; show it was a sys call.
203 ;; Fall through into ret_from_sys_call to return.
206 ;; R9 is a parameter:
210 ;; Get the current task-struct pointer.
211 movs.w -8192, $r0 ; THREAD_SIZE == 8192
214 di ; Make sure need_resched and sigpending don't change.
216 addoq +TI_flags, $r0, $acr
218 and.d _TIF_ALLWORK_MASK, $r1
219 bne _syscall_exit_work
223 ;; This epilogue MUST match the prologues in multiple_interrupt, irq.h
225 addq 4, $sp ; Skip orig_r10.
226 movem [$sp+], $r13 ; Registers R0-R13.
235 addq 8, $sp ; Skip EXS, EDA.
237 rfe ; Restore condition code stack in delay-slot.
239 ;; We get here after doing a syscall if extra work might need to be done
240 ;; perform syscall exit tracing if needed.
243 ;; R0 contains current at this point and irq's are disabled.
245 addoq +TI_flags, $r0, $acr
247 btstq TIF_SYSCALL_TRACE, $r1
251 move.d $r9, $r1 ; Preserve R9.
259 addoq +TI_flags, $r0, $acr
261 btstq TIF_NEED_RESCHED, $r10 ; Need resched?
262 bpl _work_notifysig ; No, must be signal/notify.
266 move.d $r9, $r1 ; Preserve R9.
272 addoq +TI_flags, $r0, $acr
274 and.d _TIF_WORK_MASK, $r1 ; Ignore sycall trace counter.
277 btstq TIF_NEED_RESCHED, $r1
278 bmi _work_resched ; current->work.need_resched.
282 ;; Deal with pending signals and notify-resume requests.
284 addoq +TI_flags, $r0, $acr
285 move.d [$acr], $r13 ; The thread_info_flags parameter.
286 move.d $r9, $r10 ; do_notify_resume syscall/irq param.
287 moveq 0, $r11 ; oldset param - 0 in this case.
288 move.d $sp, $r12 ; The regs param.
295 ;; We get here as a sidetrack when we've entered a syscall with the
296 ;; trace-bit set. We need to call do_syscall_trace and then continue
299 _syscall_trace_entry:
300 ;; PT_r10 in the frame contains -ENOSYS as required, at this point.
305 ;; Now re-enter the syscall code to do the syscall itself. We need to
306 ;; restore R9 here to contain the wanted syscall, and the other
307 ;; parameter-bearing registers.
308 addoq +PT_r9, $sp, $acr
310 addoq +PT_orig_r10, $sp, $acr
311 move.d [$acr], $r10 ; PT_r10 is already -ENOSYS.
312 addoq +PT_r11, $sp, $acr
314 addoq +PT_r12, $sp, $acr
316 addoq +PT_r13, $sp, $acr
318 addoq +PT_mof, $sp, $acr
320 addoq +PT_srp, $sp, $acr
326 ;; Resume performs the actual task-switching, by switching stack
327 ;; pointers. Input arguments are:
331 ;; R12 = thread offset in task struct.
333 ;; Returns old current in R10.
337 move $srp, [$sp] ; Keep old/new PC on the stack.
338 add.d $r12, $r10 ; R10 = current tasks tss.
339 addoq +THREAD_ccs, $r10, $acr
340 move $ccs, [$acr] ; Save IRQ enable state.
343 addoq +THREAD_usp, $r10, $acr
344 move $usp, [$acr] ; Save user-mode stackpointer.
346 ;; See copy_thread for the reason why register R9 is saved.
348 movem $r9, [$sp] ; Save non-scratch registers and R9.
350 addoq +THREAD_ksp, $r10, $acr
351 move.d $sp, [$acr] ; Save kernel SP for old task.
353 move.d $sp, $r10 ; Return last running task in R10.
354 and.d -8192, $r10 ; Get thread_info from stackpointer.
355 addoq +TI_task, $r10, $acr
356 move.d [$acr], $r10 ; Get task.
357 add.d $r12, $r11 ; Find the new tasks tss.
358 addoq +THREAD_ksp, $r11, $acr
359 move.d [$acr], $sp ; Switch to new stackframe.
360 movem [$sp+], $r9 ; Restore non-scratch registers and R9.
362 addoq +THREAD_usp, $r11, $acr
363 move [$acr], $usp ; Restore user-mode stackpointer.
365 addoq +THREAD_ccs, $r11, $acr
366 move [$acr], $ccs ; Restore IRQ enable status.
368 jump $acr ; Restore PC.
373 ;; If we receive a watchdog interrupt while it is not expected, then set
374 ;; up a canonical frame and dump register contents before dying.
376 ;; This prologue MUST match the one in irq.h and the struct in ptregs.h!
377 subq 12, $sp ; Skip EXS, EDA.
391 subq 14*4, $sp ; Make room for R0-R13.
392 movem $r13, [$sp] ; Push R0-R13.
394 move.d $r10, [$sp] ; Push orig_r10.
395 move.d REG_ADDR(intr_vect, regi_irq, r_nmi), $r0
397 btstq REG_BIT(intr_vect, r_nmi, watchdog), $r0
400 jsr handle_watchdog_bite ; In time.c.
401 move.d $sp, $r10 ; Pointer to registers
402 1: btstq REG_BIT(intr_vect, r_nmi, ext), $r0
406 move.d $sp, $r10 ; Pointer to registers
407 1: addq 4, $sp ; Skip orig_r10
417 addq 8, $sp ; Skip EXS, EDA.
421 .comm cause_of_death, 4 ;; Don't declare this anywhere.
428 ;; This handles the case when multiple interrupts arrive at the same
429 ;; time. Jump to the first set interrupt bit in a priotiry fashion. The
430 ;; hardware will call the unserved interrupts after the handler
433 ;; This prologue MUST match the one in irq.h and the struct in ptregs.h!
434 subq 12, $sp ; Skip EXS, EDA.
448 subq 14*4, $sp ; Make room for R0-R13.
449 movem $r13, [$sp] ; Push R0-R13.
451 move.d $r10, [$sp] ; Push orig_r10.
453 ; Set S-bit when kernel debugging to keep hardware breakpoints active.
454 #ifdef CONFIG_ETRAX_KGDB
460 jsr crisv32_do_multiple
466 ;; Sigtraps the process that executed the BREAK instruction. Creates a
467 ;; frame that Rexit expects.
486 di ; Need to disable irq's at this point.
487 subq 14*4, $sp ; Make room for r0-r13.
488 movem $r13, [$sp] ; Push the r0-r13 registers.
490 move.d $r10, [$sp] ; Push orig_r10.
492 movs.w -8192, $r9 ; THREAD_SIZE == 8192
495 ;; thread_info as first parameter
497 moveq 5, $r11 ; SIGTRAP as second argument.
500 jump ret_from_intr ; Use the return routine for interrupts.
503 gdb_handle_exception:
506 #ifdef CONFIG_ETRAX_KGDB
507 move $ccs, $r0 ; U-flag not affected by previous insns.
508 btstq 16, $r0 ; Test the U-flag.
509 bmi _ugdb_handle_exception ; Go to user mode debugging.
510 nop ; Empty delay-slot (cannot pop R0 here).
511 ba kgdb_handle_exception ; Go to kernel debugging.
512 move.d [$sp+], $r0 ; Restore R0 in delay slot.
515 _ugdb_handle_exception:
516 ba do_sigtrap ; SIGTRAP the offending process.
517 move.d [$sp+], $r0 ; Restore R0 in delay slot.
523 .long sys_restart_syscall ; 0 - old "setup()" system call, used
529 .long sys_open /* 5 */
534 .long sys_unlink /* 10 */
539 .long sys_chmod /* 15 */
541 .long sys_ni_syscall /* old break syscall holder */
544 .long sys_getpid /* 20 */
549 .long sys_stime /* 25 */
554 .long sys_utime /* 30 */
555 .long sys_ni_syscall /* old stty syscall holder */
556 .long sys_ni_syscall /* old gtty syscall holder */
559 .long sys_ni_syscall /* 35 old ftime syscall holder */
564 .long sys_rmdir /* 40 */
568 .long sys_ni_syscall /* old prof syscall holder */
569 .long sys_brk /* 45 */
574 .long sys_getegid16 /* 50 */
576 .long sys_umount /* recycled never used phys( */
577 .long sys_ni_syscall /* old lock syscall holder */
579 .long sys_fcntl /* 55 */
580 .long sys_ni_syscall /* old mpx syscall holder */
582 .long sys_ni_syscall /* old ulimit syscall holder */
583 .long sys_ni_syscall /* old sys_olduname holder */
584 .long sys_umask /* 60 */
589 .long sys_getpgrp /* 65 */
594 .long sys_setreuid16 /* 70 */
598 .long sys_sethostname
599 .long sys_setrlimit /* 75 */
600 .long sys_old_getrlimit
602 .long sys_gettimeofday
603 .long sys_settimeofday
604 .long sys_getgroups16 /* 80 */
605 .long sys_setgroups16
606 .long sys_select /* was old_select in Linux/E100 */
609 .long sys_readlink /* 85 */
614 .long old_mmap /* 90 */
619 .long sys_fchown16 /* 95 */
620 .long sys_getpriority
621 .long sys_setpriority
622 .long sys_ni_syscall /* old profil syscall holder */
624 .long sys_fstatfs /* 100 */
625 .long sys_ni_syscall /* sys_ioperm in i386 */
629 .long sys_getitimer /* 105 */
633 .long sys_ni_syscall /* old sys_uname holder */
634 .long sys_ni_syscall /* sys_iopl in i386 */
636 .long sys_ni_syscall /* old "idle" system call */
637 .long sys_ni_syscall /* vm86old in i386 */
639 .long sys_swapoff /* 115 */
644 .long sys_clone /* 120 */
645 .long sys_setdomainname
647 .long sys_ni_syscall /* sys_modify_ldt */
649 .long sys_mprotect /* 125 */
650 .long sys_sigprocmask
651 .long sys_ni_syscall /* old "create_module" */
652 .long sys_init_module
653 .long sys_delete_module
654 .long sys_ni_syscall /* 130: old "get_kernel_syms" */
659 .long sys_sysfs /* 135 */
660 .long sys_personality
661 .long sys_ni_syscall /* for afs_syscall */
664 .long sys_llseek /* 140 */
669 .long sys_readv /* 145 */
674 .long sys_mlock /* 150 */
678 .long sys_sched_setparam
679 .long sys_sched_getparam /* 155 */
680 .long sys_sched_setscheduler
681 .long sys_sched_getscheduler
682 .long sys_sched_yield
683 .long sys_sched_get_priority_max
684 .long sys_sched_get_priority_min /* 160 */
685 .long sys_sched_rr_get_interval
688 .long sys_setresuid16
689 .long sys_getresuid16 /* 165 */
690 .long sys_ni_syscall /* sys_vm86 */
691 .long sys_ni_syscall /* Old sys_query_module */
694 .long sys_setresgid16 /* 170 */
695 .long sys_getresgid16
697 .long sys_rt_sigreturn
698 .long sys_rt_sigaction
699 .long sys_rt_sigprocmask /* 175 */
700 .long sys_rt_sigpending
701 .long sys_rt_sigtimedwait
702 .long sys_rt_sigqueueinfo
703 .long sys_rt_sigsuspend
704 .long sys_pread64 /* 180 */
709 .long sys_capset /* 185 */
710 .long sys_sigaltstack
712 .long sys_ni_syscall /* streams1 */
713 .long sys_ni_syscall /* streams2 */
714 .long sys_vfork /* 190 */
718 .long sys_ftruncate64
719 .long sys_stat64 /* 195 */
724 .long sys_getgid /* 200 */
729 .long sys_getgroups /* 205 */
734 .long sys_setresgid /* 210 */
739 .long sys_setfsuid /* 215 */
744 .long sys_getdents64 /* 220 */
746 .long sys_ni_syscall /* reserved for TUX */
749 .long sys_readahead /* 225 */
754 .long sys_lgetxattr /* 230 */
759 .long sys_removexattr /* 235 */
760 .long sys_lremovexattr
761 .long sys_fremovexattr
764 .long sys_futex /* 240 */
765 .long sys_sched_setaffinity
766 .long sys_sched_getaffinity
767 .long sys_ni_syscall /* sys_set_thread_area */
768 .long sys_ni_syscall /* sys_get_thread_area */
769 .long sys_io_setup /* 245 */
771 .long sys_io_getevents
774 .long sys_fadvise64 /* 250 */
777 .long sys_lookup_dcookie
778 .long sys_epoll_create
779 .long sys_epoll_ctl /* 255 */
781 .long sys_remap_file_pages
782 .long sys_set_tid_address
783 .long sys_timer_create
784 .long sys_timer_settime /* 260 */
785 .long sys_timer_gettime
786 .long sys_timer_getoverrun
787 .long sys_timer_delete
788 .long sys_clock_settime
789 .long sys_clock_gettime /* 265 */
790 .long sys_clock_getres
791 .long sys_clock_nanosleep
794 .long sys_tgkill /* 270 */
796 .long sys_fadvise64_64
797 .long sys_ni_syscall /* sys_vserver */
798 .long sys_ni_syscall /* sys_mbind */
799 .long sys_ni_syscall /* 275 sys_get_mempolicy */
800 .long sys_ni_syscall /* sys_set_mempolicy */
803 .long sys_mq_timedsend
804 .long sys_mq_timedreceive /* 280 */
806 .long sys_mq_getsetattr
807 .long sys_ni_syscall /* reserved for kexec */
811 * NOTE!! This doesn't have to be exact - we just have
812 * to make sure we have _enough_ of the "sys_ni_syscall"
813 * entries. Don't panic if you notice that this hasn't
814 * been shrunk every time we add a new system call.
817 .rept NR_syscalls - (.-sys_call_table) / 4