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/linkage.h>
21 #include <linux/sys.h>
22 #include <asm/unistd.h>
23 #include <asm/errno.h>
24 #include <asm/thread_info.h>
25 #include <asm/asm-offsets.h>
27 #include <asm/arch/hwregs/asm/reg_map_asm.h>
28 #include <asm/arch/hwregs/asm/intr_vect_defs_asm.h>
30 ;; Exported functions.
35 .globl multiple_interrupt
37 .globl spurious_interrupt
39 .globl gdb_handle_exception
42 ; Check if preemptive kernel scheduling should be done.
46 ; Load current task struct.
47 movs.w -8192, $r0 ; THREAD_SIZE = 8192
50 addoq +TI_preempt_count, $r0, $acr
51 move.d [$acr], $r10 ; Preemption disabled?
56 addoq +TI_flags, $r0, $acr
58 btstq TIF_NEED_RESCHED, $r10 ; Check if need_resched is set.
62 ; Do preemptive kernel scheduling.
63 jsr preempt_schedule_irq
66 ; Load new task struct.
67 movs.w -8192, $r0 ; THREAD_SIZE = 8192.
70 ; One more time with new task.
74 #define _resume_kernel _Rexit
77 ; Called at exit from fork. schedule_tail must be called to drop
78 ; spinlock if CONFIG_PREEMPT.
86 ;; Check for resched if preemptive kernel, or if we're going back to
87 ;; user-mode. This test matches the user_regs(regs) macro. Don't simply
88 ;; test CCS since that doesn't necessarily reflect what mode we'll
90 addoq +PT_ccs, $sp, $acr
92 btstq 16, $r0 ; User-mode flag.
95 ; Note that di below is in delay slot.
98 di ; So need_resched and sigpending don't change.
100 movs.w -8192, $r0 ; THREAD_SIZE == 8192
103 addoq +TI_flags, $r0, $acr ; current->work
105 and.d _TIF_WORK_MASK, $r10 ; Work to be done on return?
111 ;; The system_call is called by a BREAK instruction, which looks pretty
112 ;; much like any other exception.
114 ;; System calls can't be made from interrupts but we still stack ERP
115 ;; to have a complete stack frame.
117 ;; In r9 we have the wanted syscall number. Arguments come in r10,r11,r12,
120 ;; This function looks on the _surface_ like spaghetti programming, but it's
121 ;; really designed so that the fast-path does not force cache-loading of
122 ;; non-used instructions. Only the non-common cases cause the outlined code
126 ;; Stack-frame similar to the irq heads, which is reversed in
127 ;; ret_from_sys_call.
128 subq 12, $sp ; Skip EXS, EDA.
135 ei ; Allow IRQs while handling system call
143 subq 14*4, $sp ; Make room for R0-R13.
144 movem $r13, [$sp] ; Push R0-R13
146 move.d $r10, [$sp] ; Push orig_r10.
148 ; Set S-bit when kernel debugging to keep hardware breakpoints active.
149 #ifdef CONFIG_ETRAX_KGDB
156 addoq +PT_r10, $sp, $acr
159 ;; Check if this process is syscall-traced.
160 movs.w -8192, $r0 ; THREAD_SIZE == 8192
163 addoq +TI_flags, $r0, $acr
165 btstq TIF_SYSCALL_TRACE, $r0
166 bmi _syscall_trace_entry
170 ;; Check for sanity in the requested syscall number.
171 cmpu.w NR_syscalls, $r9
172 bhs ret_from_sys_call
173 lslq 2, $r9 ; Multiply by 4, in the delay slot.
175 ;; The location on the stack for the register structure is passed as a
176 ;; seventh argument. Some system calls need this.
181 ;; The registers carrying parameters (R10-R13) are intact. The optional
182 ;; fifth and sixth parameters is in MOF and SRP respectivly. Put them
183 ;; back on the stack.
189 ;; Actually to the system call.
190 addo.d +sys_call_table, $r9, $acr
195 addq 3*4, $sp ; Pop the mof, srp and regs parameters.
196 addoq +PT_r10, $sp, $acr
197 move.d $r10, [$acr] ; Save the return value.
199 moveq 1, $r9 ; "Parameter" to ret_from_sys_call to
200 ; show it was a sys call.
202 ;; Fall through into ret_from_sys_call to return.
205 ;; R9 is a parameter:
209 ;; Get the current task-struct pointer.
210 movs.w -8192, $r0 ; THREAD_SIZE == 8192
213 di ; Make sure need_resched and sigpending don't change.
215 addoq +TI_flags, $r0, $acr
217 and.d _TIF_ALLWORK_MASK, $r1
218 bne _syscall_exit_work
222 ;; This epilogue MUST match the prologues in multiple_interrupt, irq.h
224 addq 4, $sp ; Skip orig_r10.
225 movem [$sp+], $r13 ; Registers R0-R13.
234 addq 8, $sp ; Skip EXS, EDA.
236 rfe ; Restore condition code stack in delay-slot.
238 ;; We get here after doing a syscall if extra work might need to be done
239 ;; perform syscall exit tracing if needed.
242 ;; R0 contains current at this point and irq's are disabled.
244 addoq +TI_flags, $r0, $acr
246 btstq TIF_SYSCALL_TRACE, $r1
250 move.d $r9, $r1 ; Preserve R9.
258 addoq +TI_flags, $r0, $acr
260 btstq TIF_NEED_RESCHED, $r10 ; Need resched?
261 bpl _work_notifysig ; No, must be signal/notify.
265 move.d $r9, $r1 ; Preserve R9.
271 addoq +TI_flags, $r0, $acr
273 and.d _TIF_WORK_MASK, $r1 ; Ignore sycall trace counter.
276 btstq TIF_NEED_RESCHED, $r1
277 bmi _work_resched ; current->work.need_resched.
281 ;; Deal with pending signals and notify-resume requests.
283 addoq +TI_flags, $r0, $acr
284 move.d [$acr], $r12 ; The thread_info_flags parameter.
285 move.d $sp, $r11 ; The regs param.
287 move.d $r9, $r10 ; do_notify_resume syscall/irq param.
292 ;; We get here as a sidetrack when we've entered a syscall with the
293 ;; trace-bit set. We need to call do_syscall_trace and then continue
296 _syscall_trace_entry:
297 ;; PT_r10 in the frame contains -ENOSYS as required, at this point.
302 ;; Now re-enter the syscall code to do the syscall itself. We need to
303 ;; restore R9 here to contain the wanted syscall, and the other
304 ;; parameter-bearing registers.
305 addoq +PT_r9, $sp, $acr
307 addoq +PT_orig_r10, $sp, $acr
308 move.d [$acr], $r10 ; PT_r10 is already -ENOSYS.
309 addoq +PT_r11, $sp, $acr
311 addoq +PT_r12, $sp, $acr
313 addoq +PT_r13, $sp, $acr
315 addoq +PT_mof, $sp, $acr
317 addoq +PT_srp, $sp, $acr
323 ;; Resume performs the actual task-switching, by switching stack
324 ;; pointers. Input arguments are:
328 ;; R12 = thread offset in task struct.
330 ;; Returns old current in R10.
334 move $srp, [$sp] ; Keep old/new PC on the stack.
335 add.d $r12, $r10 ; R10 = current tasks tss.
336 addoq +THREAD_ccs, $r10, $acr
337 move $ccs, [$acr] ; Save IRQ enable state.
340 addoq +THREAD_usp, $r10, $acr
341 move $usp, [$acr] ; Save user-mode stackpointer.
343 ;; See copy_thread for the reason why register R9 is saved.
345 movem $r9, [$sp] ; Save non-scratch registers and R9.
347 addoq +THREAD_ksp, $r10, $acr
348 move.d $sp, [$acr] ; Save kernel SP for old task.
350 move.d $sp, $r10 ; Return last running task in R10.
351 and.d -8192, $r10 ; Get thread_info from stackpointer.
352 addoq +TI_task, $r10, $acr
353 move.d [$acr], $r10 ; Get task.
354 add.d $r12, $r11 ; Find the new tasks tss.
355 addoq +THREAD_ksp, $r11, $acr
356 move.d [$acr], $sp ; Switch to new stackframe.
357 movem [$sp+], $r9 ; Restore non-scratch registers and R9.
359 addoq +THREAD_usp, $r11, $acr
360 move [$acr], $usp ; Restore user-mode stackpointer.
362 addoq +THREAD_ccs, $r11, $acr
363 move [$acr], $ccs ; Restore IRQ enable status.
365 jump $acr ; Restore PC.
370 ;; If we receive a watchdog interrupt while it is not expected, then set
371 ;; up a canonical frame and dump register contents before dying.
373 ;; This prologue MUST match the one in irq.h and the struct in ptregs.h!
374 subq 12, $sp ; Skip EXS, EDA.
388 subq 14*4, $sp ; Make room for R0-R13.
389 movem $r13, [$sp] ; Push R0-R13.
391 move.d $r10, [$sp] ; Push orig_r10.
392 move.d REG_ADDR(intr_vect, regi_irq, r_nmi), $r0
394 btstq REG_BIT(intr_vect, r_nmi, watchdog), $r0
397 jsr handle_watchdog_bite ; In time.c.
398 move.d $sp, $r10 ; Pointer to registers
399 1: btstq REG_BIT(intr_vect, r_nmi, ext), $r0
403 move.d $sp, $r10 ; Pointer to registers
404 1: addq 4, $sp ; Skip orig_r10
414 addq 8, $sp ; Skip EXS, EDA.
418 .comm cause_of_death, 4 ;; Don't declare this anywhere.
425 ;; This handles the case when multiple interrupts arrive at the same
426 ;; time. Jump to the first set interrupt bit in a priotiry fashion. The
427 ;; hardware will call the unserved interrupts after the handler
430 ;; This prologue MUST match the one in irq.h and the struct in ptregs.h!
431 subq 12, $sp ; Skip EXS, EDA.
445 subq 14*4, $sp ; Make room for R0-R13.
446 movem $r13, [$sp] ; Push R0-R13.
448 move.d $r10, [$sp] ; Push orig_r10.
450 ; Set S-bit when kernel debugging to keep hardware breakpoints active.
451 #ifdef CONFIG_ETRAX_KGDB
457 jsr crisv32_do_multiple
463 ;; Sigtraps the process that executed the BREAK instruction. Creates a
464 ;; frame that Rexit expects.
483 di ; Need to disable irq's at this point.
484 subq 14*4, $sp ; Make room for r0-r13.
485 movem $r13, [$sp] ; Push the r0-r13 registers.
487 move.d $r10, [$sp] ; Push orig_r10.
489 movs.w -8192, $r9 ; THREAD_SIZE == 8192
492 ;; thread_info as first parameter
494 moveq 5, $r11 ; SIGTRAP as second argument.
497 jump ret_from_intr ; Use the return routine for interrupts.
500 gdb_handle_exception:
503 #ifdef CONFIG_ETRAX_KGDB
504 move $ccs, $r0 ; U-flag not affected by previous insns.
505 btstq 16, $r0 ; Test the U-flag.
506 bmi _ugdb_handle_exception ; Go to user mode debugging.
507 nop ; Empty delay-slot (cannot pop R0 here).
508 ba kgdb_handle_exception ; Go to kernel debugging.
509 move.d [$sp+], $r0 ; Restore R0 in delay slot.
512 _ugdb_handle_exception:
513 ba do_sigtrap ; SIGTRAP the offending process.
514 move.d [$sp+], $r0 ; Restore R0 in delay slot.
516 .global kernel_execve
518 move.d __NR_execve, $r9
527 .long sys_restart_syscall ; 0 - old "setup()" system call, used
533 .long sys_open /* 5 */
538 .long sys_unlink /* 10 */
543 .long sys_chmod /* 15 */
545 .long sys_ni_syscall /* old break syscall holder */
548 .long sys_getpid /* 20 */
553 .long sys_stime /* 25 */
558 .long sys_utime /* 30 */
559 .long sys_ni_syscall /* old stty syscall holder */
560 .long sys_ni_syscall /* old gtty syscall holder */
563 .long sys_ni_syscall /* 35 old ftime syscall holder */
568 .long sys_rmdir /* 40 */
572 .long sys_ni_syscall /* old prof syscall holder */
573 .long sys_brk /* 45 */
578 .long sys_getegid16 /* 50 */
580 .long sys_umount /* recycled never used phys( */
581 .long sys_ni_syscall /* old lock syscall holder */
583 .long sys_fcntl /* 55 */
584 .long sys_ni_syscall /* old mpx syscall holder */
586 .long sys_ni_syscall /* old ulimit syscall holder */
587 .long sys_ni_syscall /* old sys_olduname holder */
588 .long sys_umask /* 60 */
593 .long sys_getpgrp /* 65 */
598 .long sys_setreuid16 /* 70 */
602 .long sys_sethostname
603 .long sys_setrlimit /* 75 */
604 .long sys_old_getrlimit
606 .long sys_gettimeofday
607 .long sys_settimeofday
608 .long sys_getgroups16 /* 80 */
609 .long sys_setgroups16
610 .long sys_select /* was old_select in Linux/E100 */
613 .long sys_readlink /* 85 */
618 .long old_mmap /* 90 */
623 .long sys_fchown16 /* 95 */
624 .long sys_getpriority
625 .long sys_setpriority
626 .long sys_ni_syscall /* old profil syscall holder */
628 .long sys_fstatfs /* 100 */
629 .long sys_ni_syscall /* sys_ioperm in i386 */
633 .long sys_getitimer /* 105 */
637 .long sys_ni_syscall /* old sys_uname holder */
638 .long sys_ni_syscall /* sys_iopl in i386 */
640 .long sys_ni_syscall /* old "idle" system call */
641 .long sys_ni_syscall /* vm86old in i386 */
643 .long sys_swapoff /* 115 */
648 .long sys_clone /* 120 */
649 .long sys_setdomainname
651 .long sys_ni_syscall /* sys_modify_ldt */
653 .long sys_mprotect /* 125 */
654 .long sys_sigprocmask
655 .long sys_ni_syscall /* old "create_module" */
656 .long sys_init_module
657 .long sys_delete_module
658 .long sys_ni_syscall /* 130: old "get_kernel_syms" */
663 .long sys_sysfs /* 135 */
664 .long sys_personality
665 .long sys_ni_syscall /* for afs_syscall */
668 .long sys_llseek /* 140 */
673 .long sys_readv /* 145 */
678 .long sys_mlock /* 150 */
682 .long sys_sched_setparam
683 .long sys_sched_getparam /* 155 */
684 .long sys_sched_setscheduler
685 .long sys_sched_getscheduler
686 .long sys_sched_yield
687 .long sys_sched_get_priority_max
688 .long sys_sched_get_priority_min /* 160 */
689 .long sys_sched_rr_get_interval
692 .long sys_setresuid16
693 .long sys_getresuid16 /* 165 */
694 .long sys_ni_syscall /* sys_vm86 */
695 .long sys_ni_syscall /* Old sys_query_module */
698 .long sys_setresgid16 /* 170 */
699 .long sys_getresgid16
701 .long sys_rt_sigreturn
702 .long sys_rt_sigaction
703 .long sys_rt_sigprocmask /* 175 */
704 .long sys_rt_sigpending
705 .long sys_rt_sigtimedwait
706 .long sys_rt_sigqueueinfo
707 .long sys_rt_sigsuspend
708 .long sys_pread64 /* 180 */
713 .long sys_capset /* 185 */
714 .long sys_sigaltstack
716 .long sys_ni_syscall /* streams1 */
717 .long sys_ni_syscall /* streams2 */
718 .long sys_vfork /* 190 */
722 .long sys_ftruncate64
723 .long sys_stat64 /* 195 */
728 .long sys_getgid /* 200 */
733 .long sys_getgroups /* 205 */
738 .long sys_setresgid /* 210 */
743 .long sys_setfsuid /* 215 */
748 .long sys_getdents64 /* 220 */
750 .long sys_ni_syscall /* reserved for TUX */
753 .long sys_readahead /* 225 */
758 .long sys_lgetxattr /* 230 */
763 .long sys_removexattr /* 235 */
764 .long sys_lremovexattr
765 .long sys_fremovexattr
768 .long sys_futex /* 240 */
769 .long sys_sched_setaffinity
770 .long sys_sched_getaffinity
771 .long sys_ni_syscall /* sys_set_thread_area */
772 .long sys_ni_syscall /* sys_get_thread_area */
773 .long sys_io_setup /* 245 */
775 .long sys_io_getevents
778 .long sys_fadvise64 /* 250 */
781 .long sys_lookup_dcookie
782 .long sys_epoll_create
783 .long sys_epoll_ctl /* 255 */
785 .long sys_remap_file_pages
786 .long sys_set_tid_address
787 .long sys_timer_create
788 .long sys_timer_settime /* 260 */
789 .long sys_timer_gettime
790 .long sys_timer_getoverrun
791 .long sys_timer_delete
792 .long sys_clock_settime
793 .long sys_clock_gettime /* 265 */
794 .long sys_clock_getres
795 .long sys_clock_nanosleep
798 .long sys_tgkill /* 270 */
800 .long sys_fadvise64_64
801 .long sys_ni_syscall /* sys_vserver */
802 .long sys_ni_syscall /* sys_mbind */
803 .long sys_ni_syscall /* 275 sys_get_mempolicy */
804 .long sys_ni_syscall /* sys_set_mempolicy */
807 .long sys_mq_timedsend
808 .long sys_mq_timedreceive /* 280 */
810 .long sys_mq_getsetattr
811 .long sys_ni_syscall /* reserved for kexec */
813 .long sys_ni_syscall /* 285 */ /* available */
815 .long sys_request_key
818 .long sys_ioprio_get /* 290 */
819 .long sys_inotify_init
820 .long sys_inotify_add_watch
821 .long sys_inotify_rm_watch
822 .long sys_migrate_pages
823 .long sys_openat /* 295 */
828 .long sys_fstatat64 /* 300 */
833 .long sys_readlinkat /* 305 */
838 .long sys_unshare /* 310 */
839 .long sys_set_robust_list
840 .long sys_get_robust_list
842 .long sys_sync_file_range
843 .long sys_tee /* 315 */
847 .long sys_epoll_pwait
848 .long sys_utimensat /* 320 */
850 .long sys_timerfd_create
853 .long sys_timerfd_settime /* 325 */
854 .long sys_timerfd_gettime
857 * NOTE!! This doesn't have to be exact - we just have
858 * to make sure we have _enough_ of the "sys_ni_syscall"
859 * entries. Don't panic if you notice that this hasn't
860 * been shrunk every time we add a new system call.
863 .rept NR_syscalls - (.-sys_call_table) / 4