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.
34 .globl ret_from_kernel_thread
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.
80 .type ret_from_fork,@function
86 .size ret_from_fork, . - ret_from_fork
88 .type ret_from_kernel_thread,@function
89 ret_from_kernel_thread:
95 moveq 0, $r9 ; no syscall restarts, TYVM...
98 .size ret_from_kernel_thread, . - ret_from_kernel_thread
100 .type ret_from_intr,@function
102 moveq 0, $r9 ; not a syscall
104 ;; Check for resched if preemptive kernel, or if we're going back to
105 ;; user-mode. This test matches the user_regs(regs) macro. Don't simply
106 ;; test CCS since that doesn't necessarily reflect what mode we'll
108 addoq +PT_ccs, $sp, $acr
110 btstq 16, $r0 ; User-mode flag.
112 .size ret_from_intr, . - ret_from_intr + 2 ; +2 includes the dslot.
114 ; Note that di below is in delay slot.
115 .type _resume_userspace,@function
117 di ; So need_resched and sigpending don't change.
119 movs.w -8192, $r0 ; THREAD_SIZE == 8192
122 addoq +TI_flags, $r0, $acr ; current->work
124 and.d _TIF_WORK_MASK, $r10 ; Work to be done on return?
129 .size _resume_userspace, . - _resume_userspace
131 ;; The system_call is called by a BREAK instruction, which looks pretty
132 ;; much like any other exception.
134 ;; System calls can't be made from interrupts but we still stack ERP
135 ;; to have a complete stack frame.
137 ;; In r9 we have the wanted syscall number. Arguments come in r10,r11,r12,
140 ;; This function looks on the _surface_ like spaghetti programming, but it's
141 ;; really designed so that the fast-path does not force cache-loading of
142 ;; non-used instructions. Only the non-common cases cause the outlined code
145 .type system_call,@function
147 ;; Stack-frame similar to the irq heads, which is reversed in
148 ;; ret_from_sys_call.
150 sub.d 92, $sp ; Skip EDA.
161 move.d $r9, $r7 ; Store syscall number in EXS
164 ei ; Enable interrupts while processing syscalls.
167 ; Set S-bit when kernel debugging to keep hardware breakpoints active.
168 #ifdef CONFIG_ETRAX_KGDB
175 addoq +PT_r10, $sp, $acr
178 ;; Check if this process is syscall-traced.
179 movs.w -8192, $r0 ; THREAD_SIZE == 8192
182 addoq +TI_flags, $r0, $acr
184 btstq TIF_SYSCALL_TRACE, $r0
185 bmi _syscall_trace_entry
189 ;; Check for sanity in the requested syscall number.
190 cmpu.w NR_syscalls, $r9
191 bhs ret_from_sys_call
192 lslq 2, $r9 ; Multiply by 4, in the delay slot.
194 ;; The location on the stack for the register structure is passed as a
195 ;; seventh argument. Some system calls need this.
200 ;; The registers carrying parameters (R10-R13) are intact. The optional
201 ;; fifth and sixth parameters is in MOF and SRP respectively. Put them
202 ;; back on the stack.
208 ;; Actually to the system call.
209 addo.d +sys_call_table, $r9, $acr
214 addq 3*4, $sp ; Pop the mof, srp and regs parameters.
215 addoq +PT_r10, $sp, $acr
216 move.d $r10, [$acr] ; Save the return value.
218 moveq 1, $r9 ; "Parameter" to ret_from_sys_call to
219 ; show it was a sys call.
221 ;; Fall through into ret_from_sys_call to return.
224 ;; R9 is a parameter:
228 ;; Get the current task-struct pointer.
229 movs.w -8192, $r0 ; THREAD_SIZE == 8192
232 di ; Make sure need_resched and sigpending don't change.
234 addoq +TI_flags, $r0, $acr
236 and.d _TIF_ALLWORK_MASK, $r1
237 bne _syscall_exit_work
239 .size system_call, . - system_call
241 .type _Rexit,@function
243 #if defined(CONFIG_TRACE_IRQFLAGS)
244 addoq +PT_ccs, $sp, $acr
249 jsr trace_hardirqs_on
254 ;; This epilogue MUST match the prologues in multiple_interrupt, irq.h
256 addq 4, $sp ; Skip orig_r10.
257 movem [$sp+], $r13 ; Registers R0-R13.
266 addq 8, $sp ; Skip EXS, EDA.
268 rfe ; Restore condition code stack in delay-slot.
269 .size _Rexit, . - _Rexit
271 ;; We get here after doing a syscall if extra work might need to be done
272 ;; perform syscall exit tracing if needed.
274 .type _syscall_exit_work,@function
276 ;; R0 contains current at this point and irq's are disabled.
278 addoq +TI_flags, $r0, $acr
280 btstq TIF_SYSCALL_TRACE, $r1
284 move.d $r9, $r1 ; Preserve R9.
290 .size _syscall_exit_work, . - _syscall_exit_work
292 .type _work_pending,@function
294 addoq +TI_flags, $r0, $acr
295 move.d [$acr], $r12 ; The thread_info_flags parameter.
296 move.d $sp, $r11 ; The regs param.
298 move.d $r9, $r10 ; The syscall/irq param.
302 .size _work_pending, . - _work_pending
304 ;; We get here as a sidetrack when we've entered a syscall with the
305 ;; trace-bit set. We need to call do_syscall_trace and then continue
308 _syscall_trace_entry:
309 ;; PT_r10 in the frame contains -ENOSYS as required, at this point.
314 ;; Now re-enter the syscall code to do the syscall itself. We need to
315 ;; restore R9 here to contain the wanted syscall, and the other
316 ;; parameter-bearing registers.
317 addoq +PT_r9, $sp, $acr
319 addoq +PT_orig_r10, $sp, $acr
320 move.d [$acr], $r10 ; PT_r10 is already -ENOSYS.
321 addoq +PT_r11, $sp, $acr
323 addoq +PT_r12, $sp, $acr
325 addoq +PT_r13, $sp, $acr
327 addoq +PT_mof, $sp, $acr
329 addoq +PT_srp, $sp, $acr
335 ;; Resume performs the actual task-switching, by switching stack
336 ;; pointers. Input arguments are:
340 ;; R12 = thread offset in task struct.
342 ;; Returns old current in R10.
344 .type resume,@function
346 subq 4, $sp ; Make space for srp.
348 add.d $r12, $r10 ; R10 = current tasks tss.
349 addoq +THREAD_ccs, $r10, $acr
350 move $srp, [$sp] ; Keep old/new PC on the stack.
351 move $ccs, [$acr] ; Save IRQ enable state.
354 addoq +THREAD_usp, $r10, $acr
355 subq 10*4, $sp ; Make room for R9.
356 move $usp, [$acr] ; Save user-mode stackpointer.
358 ;; See copy_thread for the reason why register R9 is saved.
359 movem $r9, [$sp] ; Save non-scratch registers and R9.
361 addoq +THREAD_ksp, $r10, $acr
362 move.d $sp, $r10 ; Return last running task in R10.
363 move.d $sp, [$acr] ; Save kernel SP for old task.
365 and.d -8192, $r10 ; Get thread_info from stackpointer.
366 addoq +TI_task, $r10, $acr
367 add.d $r12, $r11 ; Find the new tasks tss.
368 move.d [$acr], $r10 ; Get task.
369 addoq +THREAD_ksp, $r11, $acr
370 move.d [$acr], $sp ; Switch to new stackframe.
371 addoq +THREAD_usp, $r11, $acr
372 movem [$sp+], $r9 ; Restore non-scratch registers and R9.
374 move [$acr], $usp ; Restore user-mode stackpointer.
376 addoq +THREAD_ccs, $r11, $acr
378 jump $r11 ; Restore PC.
379 move [$acr], $ccs ; Restore IRQ enable status.
380 .size resume, . - resume
384 ;; If we receive a watchdog interrupt while it is not expected, then set
385 ;; up a canonical frame and dump register contents before dying.
387 ;; This prologue MUST match the one in irq.h and the struct in ptregs.h!
388 subq 12, $sp ; Skip EXS, EDA.
402 subq 14*4, $sp ; Make room for R0-R13.
403 movem $r13, [$sp] ; Push R0-R13.
405 move.d $r10, [$sp] ; Push orig_r10.
406 move.d REG_ADDR(intr_vect, regi_irq, r_nmi), $r0
408 btstq REG_BIT(intr_vect, r_nmi, watchdog), $r0
411 jsr handle_watchdog_bite ; In time.c.
412 move.d $sp, $r10 ; Pointer to registers
413 1: btstq REG_BIT(intr_vect, r_nmi, ext), $r0
417 move.d $sp, $r10 ; Pointer to registers
418 1: addq 4, $sp ; Skip orig_r10
428 addq 8, $sp ; Skip EXS, EDA.
432 .comm cause_of_death, 4 ;; Don't declare this anywhere.
439 ;; This handles the case when multiple interrupts arrive at the same
440 ;; time. Jump to the first set interrupt bit in a priority fashion. The
441 ;; hardware will call the unserved interrupts after the handler
443 .type multiple_interrupt, @function
445 ;; This prologue MUST match the one in irq.h and the struct in ptregs.h!
446 subq 12, $sp ; Skip EXS, EDA.
460 subq 14*4, $sp ; Make room for R0-R13.
461 movem $r13, [$sp] ; Push R0-R13.
463 move.d $r10, [$sp] ; Push orig_r10.
465 ; Set S-bit when kernel debugging to keep hardware breakpoints active.
466 #ifdef CONFIG_ETRAX_KGDB
472 jsr crisv32_do_multiple
476 .size multiple_interrupt, . - multiple_interrupt
479 ;; Sigtraps the process that executed the BREAK instruction. Creates a
480 ;; frame that Rexit expects.
499 di ; Need to disable irq's at this point.
500 subq 14*4, $sp ; Make room for r0-r13.
501 movem $r13, [$sp] ; Push the r0-r13 registers.
503 move.d $r10, [$sp] ; Push orig_r10.
505 movs.w -8192, $r9 ; THREAD_SIZE == 8192
508 ;; thread_info as first parameter
510 moveq 5, $r11 ; SIGTRAP as second argument.
513 jump ret_from_intr ; Use the return routine for interrupts.
516 gdb_handle_exception:
519 #ifdef CONFIG_ETRAX_KGDB
520 move $ccs, $r0 ; U-flag not affected by previous insns.
521 btstq 16, $r0 ; Test the U-flag.
522 bmi _ugdb_handle_exception ; Go to user mode debugging.
523 nop ; Empty delay-slot (cannot pop R0 here).
524 ba kgdb_handle_exception ; Go to kernel debugging.
525 move.d [$sp+], $r0 ; Restore R0 in delay slot.
528 _ugdb_handle_exception:
529 ba do_sigtrap ; SIGTRAP the offending process.
530 move.d [$sp+], $r0 ; Restore R0 in delay slot.
536 .long sys_restart_syscall ; 0 - old "setup()" system call, used
542 .long sys_open /* 5 */
547 .long sys_unlink /* 10 */
552 .long sys_chmod /* 15 */
554 .long sys_ni_syscall /* old break syscall holder */
557 .long sys_getpid /* 20 */
562 .long sys_stime /* 25 */
567 .long sys_utime /* 30 */
568 .long sys_ni_syscall /* old stty syscall holder */
569 .long sys_ni_syscall /* old gtty syscall holder */
572 .long sys_ni_syscall /* 35 old ftime syscall holder */
577 .long sys_rmdir /* 40 */
581 .long sys_ni_syscall /* old prof syscall holder */
582 .long sys_brk /* 45 */
587 .long sys_getegid16 /* 50 */
589 .long sys_umount /* recycled never used phys( */
590 .long sys_ni_syscall /* old lock syscall holder */
592 .long sys_fcntl /* 55 */
593 .long sys_ni_syscall /* old mpx syscall holder */
595 .long sys_ni_syscall /* old ulimit syscall holder */
596 .long sys_ni_syscall /* old sys_olduname holder */
597 .long sys_umask /* 60 */
602 .long sys_getpgrp /* 65 */
607 .long sys_setreuid16 /* 70 */
611 .long sys_sethostname
612 .long sys_setrlimit /* 75 */
613 .long sys_old_getrlimit
615 .long sys_gettimeofday
616 .long sys_settimeofday
617 .long sys_getgroups16 /* 80 */
618 .long sys_setgroups16
619 .long sys_select /* was old_select in Linux/E100 */
622 .long sys_readlink /* 85 */
626 .long sys_old_readdir
627 .long sys_old_mmap /* 90 */
632 .long sys_fchown16 /* 95 */
633 .long sys_getpriority
634 .long sys_setpriority
635 .long sys_ni_syscall /* old profil syscall holder */
637 .long sys_fstatfs /* 100 */
638 .long sys_ni_syscall /* sys_ioperm in i386 */
642 .long sys_getitimer /* 105 */
646 .long sys_ni_syscall /* old sys_uname holder */
647 .long sys_ni_syscall /* sys_iopl in i386 */
649 .long sys_ni_syscall /* old "idle" system call */
650 .long sys_ni_syscall /* vm86old in i386 */
652 .long sys_swapoff /* 115 */
657 .long sys_clone /* 120 */
658 .long sys_setdomainname
660 .long sys_ni_syscall /* sys_modify_ldt */
662 .long sys_mprotect /* 125 */
663 .long sys_sigprocmask
664 .long sys_ni_syscall /* old "create_module" */
665 .long sys_init_module
666 .long sys_delete_module
667 .long sys_ni_syscall /* 130: old "get_kernel_syms" */
672 .long sys_sysfs /* 135 */
673 .long sys_personality
674 .long sys_ni_syscall /* for afs_syscall */
677 .long sys_llseek /* 140 */
682 .long sys_readv /* 145 */
687 .long sys_mlock /* 150 */
691 .long sys_sched_setparam
692 .long sys_sched_getparam /* 155 */
693 .long sys_sched_setscheduler
694 .long sys_sched_getscheduler
695 .long sys_sched_yield
696 .long sys_sched_get_priority_max
697 .long sys_sched_get_priority_min /* 160 */
698 .long sys_sched_rr_get_interval
701 .long sys_setresuid16
702 .long sys_getresuid16 /* 165 */
703 .long sys_ni_syscall /* sys_vm86 */
704 .long sys_ni_syscall /* Old sys_query_module */
706 .long sys_ni_syscall /* Old nfsservctl */
707 .long sys_setresgid16 /* 170 */
708 .long sys_getresgid16
710 .long sys_rt_sigreturn
711 .long sys_rt_sigaction
712 .long sys_rt_sigprocmask /* 175 */
713 .long sys_rt_sigpending
714 .long sys_rt_sigtimedwait
715 .long sys_rt_sigqueueinfo
716 .long sys_rt_sigsuspend
717 .long sys_pread64 /* 180 */
722 .long sys_capset /* 185 */
723 .long sys_sigaltstack
725 .long sys_ni_syscall /* streams1 */
726 .long sys_ni_syscall /* streams2 */
727 .long sys_vfork /* 190 */
731 .long sys_ftruncate64
732 .long sys_stat64 /* 195 */
737 .long sys_getgid /* 200 */
742 .long sys_getgroups /* 205 */
747 .long sys_setresgid /* 210 */
752 .long sys_setfsuid /* 215 */
757 .long sys_getdents64 /* 220 */
759 .long sys_ni_syscall /* reserved for TUX */
762 .long sys_readahead /* 225 */
767 .long sys_lgetxattr /* 230 */
772 .long sys_removexattr /* 235 */
773 .long sys_lremovexattr
774 .long sys_fremovexattr
777 .long sys_futex /* 240 */
778 .long sys_sched_setaffinity
779 .long sys_sched_getaffinity
780 .long sys_ni_syscall /* sys_set_thread_area */
781 .long sys_ni_syscall /* sys_get_thread_area */
782 .long sys_io_setup /* 245 */
784 .long sys_io_getevents
787 .long sys_fadvise64 /* 250 */
790 .long sys_lookup_dcookie
791 .long sys_epoll_create
792 .long sys_epoll_ctl /* 255 */
794 .long sys_remap_file_pages
795 .long sys_set_tid_address
796 .long sys_timer_create
797 .long sys_timer_settime /* 260 */
798 .long sys_timer_gettime
799 .long sys_timer_getoverrun
800 .long sys_timer_delete
801 .long sys_clock_settime
802 .long sys_clock_gettime /* 265 */
803 .long sys_clock_getres
804 .long sys_clock_nanosleep
807 .long sys_tgkill /* 270 */
809 .long sys_fadvise64_64
810 .long sys_ni_syscall /* sys_vserver */
811 .long sys_ni_syscall /* sys_mbind */
812 .long sys_ni_syscall /* 275 sys_get_mempolicy */
813 .long sys_ni_syscall /* sys_set_mempolicy */
816 .long sys_mq_timedsend
817 .long sys_mq_timedreceive /* 280 */
819 .long sys_mq_getsetattr
820 .long sys_ni_syscall /* reserved for kexec */
822 .long sys_ni_syscall /* 285 */ /* available */
824 .long sys_request_key
827 .long sys_ioprio_get /* 290 */
828 .long sys_inotify_init
829 .long sys_inotify_add_watch
830 .long sys_inotify_rm_watch
831 .long sys_migrate_pages
832 .long sys_openat /* 295 */
837 .long sys_fstatat64 /* 300 */
842 .long sys_readlinkat /* 305 */
847 .long sys_unshare /* 310 */
848 .long sys_set_robust_list
849 .long sys_get_robust_list
851 .long sys_sync_file_range
852 .long sys_tee /* 315 */
856 .long sys_epoll_pwait
857 .long sys_utimensat /* 320 */
859 .long sys_timerfd_create
862 .long sys_timerfd_settime /* 325 */
863 .long sys_timerfd_gettime
866 .long sys_epoll_create1
867 .long sys_dup3 /* 330 */
869 .long sys_inotify_init1
872 .long sys_setns /* 335 */
873 .long sys_name_to_handle_at
874 .long sys_open_by_handle_at
875 .long sys_rt_tgsigqueueinfo
876 .long sys_perf_event_open
877 .long sys_recvmmsg /* 340 */
879 .long sys_fanotify_init
880 .long sys_fanotify_mark
882 .long sys_clock_adjtime /* 345 */
885 .long sys_process_vm_readv
886 .long sys_process_vm_writev
887 .long sys_kcmp /* 350 */
888 .long sys_finit_module
889 .long sys_sched_setattr
890 .long sys_sched_getattr
892 .long sys_seccomp /* 355 */
894 .long sys_memfd_create
899 * NOTE!! This doesn't have to be exact - we just have
900 * to make sure we have _enough_ of the "sys_ni_syscall"
901 * entries. Don't panic if you notice that this hasn't
902 * been shrunk every time we add a new system call.
905 .rept NR_syscalls - (.-sys_call_table) / 4