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 <hwregs/asm/reg_map_asm.h>
28 #include <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.
79 .type ret_from_fork,@function
85 .size ret_from_fork, . - ret_from_fork
87 .type ret_from_intr,@function
89 ;; Check for resched if preemptive kernel, or if we're going back to
90 ;; user-mode. This test matches the user_regs(regs) macro. Don't simply
91 ;; test CCS since that doesn't necessarily reflect what mode we'll
93 addoq +PT_ccs, $sp, $acr
95 btstq 16, $r0 ; User-mode flag.
97 .size ret_from_intr, . - ret_from_intr + 2 ; +2 includes the dslot.
99 ; Note that di below is in delay slot.
100 .type _resume_userspace,@function
102 di ; So need_resched and sigpending don't change.
104 movs.w -8192, $r0 ; THREAD_SIZE == 8192
107 addoq +TI_flags, $r0, $acr ; current->work
109 and.d _TIF_WORK_MASK, $r10 ; Work to be done on return?
114 .size _resume_userspace, . - _resume_userspace
116 ;; The system_call is called by a BREAK instruction, which looks pretty
117 ;; much like any other exception.
119 ;; System calls can't be made from interrupts but we still stack ERP
120 ;; to have a complete stack frame.
122 ;; In r9 we have the wanted syscall number. Arguments come in r10,r11,r12,
125 ;; This function looks on the _surface_ like spaghetti programming, but it's
126 ;; really designed so that the fast-path does not force cache-loading of
127 ;; non-used instructions. Only the non-common cases cause the outlined code
130 .type system_call,@function
132 ;; Stack-frame similar to the irq heads, which is reversed in
133 ;; ret_from_sys_call.
135 sub.d 92, $sp ; Skip EXS and EDA.
148 ei ; Enable interrupts while processing syscalls.
151 ; Set S-bit when kernel debugging to keep hardware breakpoints active.
152 #ifdef CONFIG_ETRAX_KGDB
159 addoq +PT_r10, $sp, $acr
162 ;; Check if this process is syscall-traced.
163 movs.w -8192, $r0 ; THREAD_SIZE == 8192
166 addoq +TI_flags, $r0, $acr
168 btstq TIF_SYSCALL_TRACE, $r0
169 bmi _syscall_trace_entry
173 ;; Check for sanity in the requested syscall number.
174 cmpu.w NR_syscalls, $r9
175 bhs ret_from_sys_call
176 lslq 2, $r9 ; Multiply by 4, in the delay slot.
178 ;; The location on the stack for the register structure is passed as a
179 ;; seventh argument. Some system calls need this.
184 ;; The registers carrying parameters (R10-R13) are intact. The optional
185 ;; fifth and sixth parameters is in MOF and SRP respectively. Put them
186 ;; back on the stack.
192 ;; Actually to the system call.
193 addo.d +sys_call_table, $r9, $acr
198 addq 3*4, $sp ; Pop the mof, srp and regs parameters.
199 addoq +PT_r10, $sp, $acr
200 move.d $r10, [$acr] ; Save the return value.
202 moveq 1, $r9 ; "Parameter" to ret_from_sys_call to
203 ; show it was a sys call.
205 ;; Fall through into ret_from_sys_call to return.
208 ;; R9 is a parameter:
212 ;; Get the current task-struct pointer.
213 movs.w -8192, $r0 ; THREAD_SIZE == 8192
216 di ; Make sure need_resched and sigpending don't change.
218 addoq +TI_flags, $r0, $acr
220 and.d _TIF_ALLWORK_MASK, $r1
221 bne _syscall_exit_work
223 .size system_call, . - system_call
225 .type _Rexit,@function
227 ;; This epilogue MUST match the prologues in multiple_interrupt, irq.h
229 addq 4, $sp ; Skip orig_r10.
230 movem [$sp+], $r13 ; Registers R0-R13.
239 addq 8, $sp ; Skip EXS, EDA.
241 rfe ; Restore condition code stack in delay-slot.
242 .size _Rexit, . - _Rexit
244 ;; We get here after doing a syscall if extra work might need to be done
245 ;; perform syscall exit tracing if needed.
247 .type _syscall_exit_work,@function
249 ;; R0 contains current at this point and irq's are disabled.
251 addoq +TI_flags, $r0, $acr
253 btstq TIF_SYSCALL_TRACE, $r1
257 move.d $r9, $r1 ; Preserve R9.
263 .size _syscall_exit_work, . - _syscall_exit_work
265 .type _work_pending,@function
267 addoq +TI_flags, $r0, $acr
269 btstq TIF_NEED_RESCHED, $r10 ; Need resched?
270 bpl _work_notifysig ; No, must be signal/notify.
272 .size _work_pending, . - _work_pending
274 .type _work_resched,@function
276 move.d $r9, $r1 ; Preserve R9.
282 addoq +TI_flags, $r0, $acr
284 and.d _TIF_WORK_MASK, $r1 ; Ignore sycall trace counter.
287 btstq TIF_NEED_RESCHED, $r1
288 bmi _work_resched ; current->work.need_resched.
290 .size _work_resched, . - _work_resched
292 .type _work_notifysig,@function
294 ;; Deal with pending signals and notify-resume requests.
296 addoq +TI_flags, $r0, $acr
297 move.d [$acr], $r12 ; The thread_info_flags parameter.
298 move.d $sp, $r11 ; The regs param.
300 move.d $r9, $r10 ; do_notify_resume syscall/irq param.
304 .size _work_notifysig, . - _work_notifysig
306 ;; We get here as a sidetrack when we've entered a syscall with the
307 ;; trace-bit set. We need to call do_syscall_trace and then continue
310 _syscall_trace_entry:
311 ;; PT_r10 in the frame contains -ENOSYS as required, at this point.
316 ;; Now re-enter the syscall code to do the syscall itself. We need to
317 ;; restore R9 here to contain the wanted syscall, and the other
318 ;; parameter-bearing registers.
319 addoq +PT_r9, $sp, $acr
321 addoq +PT_orig_r10, $sp, $acr
322 move.d [$acr], $r10 ; PT_r10 is already -ENOSYS.
323 addoq +PT_r11, $sp, $acr
325 addoq +PT_r12, $sp, $acr
327 addoq +PT_r13, $sp, $acr
329 addoq +PT_mof, $sp, $acr
331 addoq +PT_srp, $sp, $acr
337 ;; Resume performs the actual task-switching, by switching stack
338 ;; pointers. Input arguments are:
342 ;; R12 = thread offset in task struct.
344 ;; Returns old current in R10.
346 .type resume,@function
348 subq 4, $sp ; Make space for srp.
350 add.d $r12, $r10 ; R10 = current tasks tss.
351 addoq +THREAD_ccs, $r10, $acr
352 move $srp, [$sp] ; Keep old/new PC on the stack.
353 move $ccs, [$acr] ; Save IRQ enable state.
356 addoq +THREAD_usp, $r10, $acr
357 subq 10*4, $sp ; Make room for R9.
358 move $usp, [$acr] ; Save user-mode stackpointer.
360 ;; See copy_thread for the reason why register R9 is saved.
361 movem $r9, [$sp] ; Save non-scratch registers and R9.
363 addoq +THREAD_ksp, $r10, $acr
364 move.d $sp, $r10 ; Return last running task in R10.
365 move.d $sp, [$acr] ; Save kernel SP for old task.
367 and.d -8192, $r10 ; Get thread_info from stackpointer.
368 addoq +TI_task, $r10, $acr
369 add.d $r12, $r11 ; Find the new tasks tss.
370 move.d [$acr], $r10 ; Get task.
371 addoq +THREAD_ksp, $r11, $acr
372 move.d [$acr], $sp ; Switch to new stackframe.
373 addoq +THREAD_usp, $r11, $acr
374 movem [$sp+], $r9 ; Restore non-scratch registers and R9.
376 move [$acr], $usp ; Restore user-mode stackpointer.
378 addoq +THREAD_ccs, $r11, $acr
380 jump $r11 ; Restore PC.
381 move [$acr], $ccs ; Restore IRQ enable status.
382 .size resume, . - resume
386 ;; If we receive a watchdog interrupt while it is not expected, then set
387 ;; up a canonical frame and dump register contents before dying.
389 ;; This prologue MUST match the one in irq.h and the struct in ptregs.h!
390 subq 12, $sp ; Skip EXS, EDA.
404 subq 14*4, $sp ; Make room for R0-R13.
405 movem $r13, [$sp] ; Push R0-R13.
407 move.d $r10, [$sp] ; Push orig_r10.
408 move.d REG_ADDR(intr_vect, regi_irq, r_nmi), $r0
410 btstq REG_BIT(intr_vect, r_nmi, watchdog), $r0
413 jsr handle_watchdog_bite ; In time.c.
414 move.d $sp, $r10 ; Pointer to registers
415 1: btstq REG_BIT(intr_vect, r_nmi, ext), $r0
419 move.d $sp, $r10 ; Pointer to registers
420 1: addq 4, $sp ; Skip orig_r10
430 addq 8, $sp ; Skip EXS, EDA.
434 .comm cause_of_death, 4 ;; Don't declare this anywhere.
441 ;; This handles the case when multiple interrupts arrive at the same
442 ;; time. Jump to the first set interrupt bit in a priotiry fashion. The
443 ;; hardware will call the unserved interrupts after the handler
445 .type multiple_interrupt, @function
447 ;; This prologue MUST match the one in irq.h and the struct in ptregs.h!
448 subq 12, $sp ; Skip EXS, EDA.
462 subq 14*4, $sp ; Make room for R0-R13.
463 movem $r13, [$sp] ; Push R0-R13.
465 move.d $r10, [$sp] ; Push orig_r10.
467 ; Set S-bit when kernel debugging to keep hardware breakpoints active.
468 #ifdef CONFIG_ETRAX_KGDB
474 jsr crisv32_do_multiple
478 .size multiple_interrupt, . - multiple_interrupt
481 ;; Sigtraps the process that executed the BREAK instruction. Creates a
482 ;; frame that Rexit expects.
501 di ; Need to disable irq's at this point.
502 subq 14*4, $sp ; Make room for r0-r13.
503 movem $r13, [$sp] ; Push the r0-r13 registers.
505 move.d $r10, [$sp] ; Push orig_r10.
507 movs.w -8192, $r9 ; THREAD_SIZE == 8192
510 ;; thread_info as first parameter
512 moveq 5, $r11 ; SIGTRAP as second argument.
515 jump ret_from_intr ; Use the return routine for interrupts.
518 gdb_handle_exception:
521 #ifdef CONFIG_ETRAX_KGDB
522 move $ccs, $r0 ; U-flag not affected by previous insns.
523 btstq 16, $r0 ; Test the U-flag.
524 bmi _ugdb_handle_exception ; Go to user mode debugging.
525 nop ; Empty delay-slot (cannot pop R0 here).
526 ba kgdb_handle_exception ; Go to kernel debugging.
527 move.d [$sp+], $r0 ; Restore R0 in delay slot.
530 _ugdb_handle_exception:
531 ba do_sigtrap ; SIGTRAP the offending process.
532 move.d [$sp+], $r0 ; Restore R0 in delay slot.
534 .global kernel_execve
535 .type kernel_execve,@function
537 move.d __NR_execve, $r9
541 .size kernel_execve, . - kernel_execve
547 .long sys_restart_syscall ; 0 - old "setup()" system call, used
553 .long sys_open /* 5 */
558 .long sys_unlink /* 10 */
563 .long sys_chmod /* 15 */
565 .long sys_ni_syscall /* old break syscall holder */
568 .long sys_getpid /* 20 */
573 .long sys_stime /* 25 */
578 .long sys_utime /* 30 */
579 .long sys_ni_syscall /* old stty syscall holder */
580 .long sys_ni_syscall /* old gtty syscall holder */
583 .long sys_ni_syscall /* 35 old ftime syscall holder */
588 .long sys_rmdir /* 40 */
592 .long sys_ni_syscall /* old prof syscall holder */
593 .long sys_brk /* 45 */
598 .long sys_getegid16 /* 50 */
600 .long sys_umount /* recycled never used phys( */
601 .long sys_ni_syscall /* old lock syscall holder */
603 .long sys_fcntl /* 55 */
604 .long sys_ni_syscall /* old mpx syscall holder */
606 .long sys_ni_syscall /* old ulimit syscall holder */
607 .long sys_ni_syscall /* old sys_olduname holder */
608 .long sys_umask /* 60 */
613 .long sys_getpgrp /* 65 */
618 .long sys_setreuid16 /* 70 */
622 .long sys_sethostname
623 .long sys_setrlimit /* 75 */
624 .long sys_old_getrlimit
626 .long sys_gettimeofday
627 .long sys_settimeofday
628 .long sys_getgroups16 /* 80 */
629 .long sys_setgroups16
630 .long sys_select /* was old_select in Linux/E100 */
633 .long sys_readlink /* 85 */
637 .long sys_old_readdir
638 .long sys_old_mmap /* 90 */
643 .long sys_fchown16 /* 95 */
644 .long sys_getpriority
645 .long sys_setpriority
646 .long sys_ni_syscall /* old profil syscall holder */
648 .long sys_fstatfs /* 100 */
649 .long sys_ni_syscall /* sys_ioperm in i386 */
653 .long sys_getitimer /* 105 */
657 .long sys_ni_syscall /* old sys_uname holder */
658 .long sys_ni_syscall /* sys_iopl in i386 */
660 .long sys_ni_syscall /* old "idle" system call */
661 .long sys_ni_syscall /* vm86old in i386 */
663 .long sys_swapoff /* 115 */
668 .long sys_clone /* 120 */
669 .long sys_setdomainname
671 .long sys_ni_syscall /* sys_modify_ldt */
673 .long sys_mprotect /* 125 */
674 .long sys_sigprocmask
675 .long sys_ni_syscall /* old "create_module" */
676 .long sys_init_module
677 .long sys_delete_module
678 .long sys_ni_syscall /* 130: old "get_kernel_syms" */
683 .long sys_sysfs /* 135 */
684 .long sys_personality
685 .long sys_ni_syscall /* for afs_syscall */
688 .long sys_llseek /* 140 */
693 .long sys_readv /* 145 */
698 .long sys_mlock /* 150 */
702 .long sys_sched_setparam
703 .long sys_sched_getparam /* 155 */
704 .long sys_sched_setscheduler
705 .long sys_sched_getscheduler
706 .long sys_sched_yield
707 .long sys_sched_get_priority_max
708 .long sys_sched_get_priority_min /* 160 */
709 .long sys_sched_rr_get_interval
712 .long sys_setresuid16
713 .long sys_getresuid16 /* 165 */
714 .long sys_ni_syscall /* sys_vm86 */
715 .long sys_ni_syscall /* Old sys_query_module */
718 .long sys_setresgid16 /* 170 */
719 .long sys_getresgid16
721 .long sys_rt_sigreturn
722 .long sys_rt_sigaction
723 .long sys_rt_sigprocmask /* 175 */
724 .long sys_rt_sigpending
725 .long sys_rt_sigtimedwait
726 .long sys_rt_sigqueueinfo
727 .long sys_rt_sigsuspend
728 .long sys_pread64 /* 180 */
733 .long sys_capset /* 185 */
734 .long sys_sigaltstack
736 .long sys_ni_syscall /* streams1 */
737 .long sys_ni_syscall /* streams2 */
738 .long sys_vfork /* 190 */
742 .long sys_ftruncate64
743 .long sys_stat64 /* 195 */
748 .long sys_getgid /* 200 */
753 .long sys_getgroups /* 205 */
758 .long sys_setresgid /* 210 */
763 .long sys_setfsuid /* 215 */
768 .long sys_getdents64 /* 220 */
770 .long sys_ni_syscall /* reserved for TUX */
773 .long sys_readahead /* 225 */
778 .long sys_lgetxattr /* 230 */
783 .long sys_removexattr /* 235 */
784 .long sys_lremovexattr
785 .long sys_fremovexattr
788 .long sys_futex /* 240 */
789 .long sys_sched_setaffinity
790 .long sys_sched_getaffinity
791 .long sys_ni_syscall /* sys_set_thread_area */
792 .long sys_ni_syscall /* sys_get_thread_area */
793 .long sys_io_setup /* 245 */
795 .long sys_io_getevents
798 .long sys_fadvise64 /* 250 */
801 .long sys_lookup_dcookie
802 .long sys_epoll_create
803 .long sys_epoll_ctl /* 255 */
805 .long sys_remap_file_pages
806 .long sys_set_tid_address
807 .long sys_timer_create
808 .long sys_timer_settime /* 260 */
809 .long sys_timer_gettime
810 .long sys_timer_getoverrun
811 .long sys_timer_delete
812 .long sys_clock_settime
813 .long sys_clock_gettime /* 265 */
814 .long sys_clock_getres
815 .long sys_clock_nanosleep
818 .long sys_tgkill /* 270 */
820 .long sys_fadvise64_64
821 .long sys_ni_syscall /* sys_vserver */
822 .long sys_ni_syscall /* sys_mbind */
823 .long sys_ni_syscall /* 275 sys_get_mempolicy */
824 .long sys_ni_syscall /* sys_set_mempolicy */
827 .long sys_mq_timedsend
828 .long sys_mq_timedreceive /* 280 */
830 .long sys_mq_getsetattr
831 .long sys_ni_syscall /* reserved for kexec */
833 .long sys_ni_syscall /* 285 */ /* available */
835 .long sys_request_key
838 .long sys_ioprio_get /* 290 */
839 .long sys_inotify_init
840 .long sys_inotify_add_watch
841 .long sys_inotify_rm_watch
842 .long sys_migrate_pages
843 .long sys_openat /* 295 */
848 .long sys_fstatat64 /* 300 */
853 .long sys_readlinkat /* 305 */
858 .long sys_unshare /* 310 */
859 .long sys_set_robust_list
860 .long sys_get_robust_list
862 .long sys_sync_file_range
863 .long sys_tee /* 315 */
867 .long sys_epoll_pwait
868 .long sys_utimensat /* 320 */
870 .long sys_timerfd_create
873 .long sys_timerfd_settime /* 325 */
874 .long sys_timerfd_gettime
877 .long sys_epoll_create1
878 .long sys_dup3 /* 330 */
880 .long sys_inotify_init1
883 .long sys_setns /* 335 */
886 * NOTE!! This doesn't have to be exact - we just have
887 * to make sure we have _enough_ of the "sys_ni_syscall"
888 * entries. Don't panic if you notice that this hasn't
889 * been shrunk every time we add a new system call.
892 .rept NR_syscalls - (.-sys_call_table) / 4