1 /* $Id: entry.S,v 1.37 2004/06/11 13:02:46 doyu Exp $
3 * linux/arch/sh/entry.S
5 * Copyright (C) 1999, 2000, 2002 Niibe Yutaka
6 * Copyright (C) 2003 Paul Mundt
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
14 #include <linux/sys.h>
15 #include <linux/linkage.h>
16 #include <linux/config.h>
17 #include <asm/asm-offsets.h>
18 #include <asm/thread_info.h>
19 #include <asm/unistd.h>
21 #if !defined(CONFIG_NFSD) && !defined(CONFIG_NFSD_MODULE)
22 #define sys_nfsservctl sys_ni_syscall
25 #if !defined(CONFIG_MMU)
26 #define sys_madvise sys_ni_syscall
27 #define sys_readahead sys_ni_syscall
28 #define sys_mprotect sys_ni_syscall
29 #define sys_msync sys_ni_syscall
30 #define sys_mlock sys_ni_syscall
31 #define sys_munlock sys_ni_syscall
32 #define sys_mlockall sys_ni_syscall
33 #define sys_munlockall sys_ni_syscall
34 #define sys_mremap sys_ni_syscall
35 #define sys_mincore sys_ni_syscall
36 #define sys_remap_file_pages sys_ni_syscall
40 ! GNU as (as of 2.9.1) changes bf/s into bt/s and bra, when the address
41 ! to be jumped is too far, but it causes illegal slot exception.
44 * entry.S contains the system-call and fault low-level handling routines.
45 * This also contains the timer-interrupt handler, as well as all interrupts
46 * and faults that can result in a task-switch.
48 * NOTE: This code handles signal-recognition, which happens every time
49 * after a timer-interrupt and after each system call.
51 * NOTE: This code uses a convention that instructions in the delay slot
52 * of a transfer-control instruction are indented by an extra space, thus:
54 * jmp @k0 ! control-transfer instruction
55 * ldc k1, ssr ! delay slot
57 * Stack layout in 'ret_from_syscall':
58 * ptrace needs to have all regs on the stack.
59 * if the order here is changed, it needs to be
60 * updated in ptrace.c and ptrace.h
78 #if defined(CONFIG_CPU_SH3)
81 #if defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709) || \
82 defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7705)
83 INTEVT = 0xa4000000 ! INTEVTE2(0xa4000000)
87 MMU_TEA = 0xfffffffc ! TLB Exception Address Register
88 #elif defined(CONFIG_CPU_SH4)
92 MMU_TEA = 0xff00000c ! TLB Exception Address Register
95 #if defined(CONFIG_KGDB_NMI)
96 NMI_VEC = 0x1c0 ! Must catch early for debounce
99 /* Offsets to the stack */
100 OFF_R0 = 0 /* Return value. New ABI also arg4 */
101 OFF_R1 = 4 /* New ABI: arg5 */
102 OFF_R2 = 8 /* New ABI: arg6 */
103 OFF_R3 = 12 /* New ABI: syscall_nr */
104 OFF_R4 = 16 /* New ABI: arg0 */
105 OFF_R5 = 20 /* New ABI: arg1 */
106 OFF_R6 = 24 /* New ABI: arg2 */
107 OFF_R7 = 28 /* New ABI: arg3 */
120 #define k_ex_code r2_bank /* r2_bank1 */
121 #define g_imask r6 /* r6_bank1 */
122 #define k_g_imask r6_bank /* r6_bank1 */
123 #define current r7 /* r7_bank1 */
126 * Kernel mode register usage:
129 * k2 scratch (Exception code)
130 * k3 scratch (Return address)
133 * k6 Global Interrupt Mask (0--15 << 4)
134 * k7 CURRENT_THREAD_INFO (pointer to current thread info)
138 ! TLB Miss / Initial Page write exception handling
140 ! TLB hits, but the access violate the protection.
141 ! It can be valid access, such as stack grow and/or C-O-W.
144 ! Find the pmd/pte entry and loadtlb
145 ! If it's not found, cause address error (SEGV)
147 ! Although this could be written in assembly language (and it'd be faster),
148 ! this first version depends *much* on C implementation.
157 mov.l __INV_IMASK, r11; \
160 stc k_g_imask, r11; \
164 #if defined(CONFIG_PREEMPT)
165 # define preempt_stop() CLI()
167 # define preempt_stop()
168 # define resume_kernel restore_all
171 #if defined(CONFIG_MMU)
178 ENTRY(tlb_miss_store)
183 ENTRY(initial_page_write)
188 ENTRY(tlb_protection_violation_load)
193 ENTRY(tlb_protection_violation_store)
221 2: .long __do_page_fault
222 3: .long do_page_fault
225 ENTRY(address_error_load)
227 mov #0,r5 ! writeaccess = 0
230 ENTRY(address_error_store)
232 mov #1,r5 ! writeaccess = 1
237 mov.l @r0, r6 ! address
244 2: .long do_address_error
245 #endif /* CONFIG_MMU */
247 #if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
248 ! Handle kernel debug if either kgdb (SW) or gdb-stub (FW) is present.
249 ! If both are configured, handle the debug traps (breakpoints) in SW,
250 ! but still allow BIOS traps to FW.
254 #if defined(CONFIG_SH_STANDARD_BIOS) && defined(CONFIG_SH_KGDB)
255 /* Force BIOS call to FW (debug_trap put TRA in r8) */
260 #endif /* CONFIG_SH_STANDARD_BIOS && CONFIG_SH_KGDB */
263 #if defined(CONFIG_SH_KGDB)
264 /* Jump to kgdb, pass stacked regs as arg */
270 3: .long kgdb_handle_exception
271 #endif /* CONFIG_SH_KGDB */
273 #if defined(CONFIG_SH_STANDARD_BIOS)
274 /* Unwind the stack and jmp to the debug entry */
285 mov.l 1f, r9 ! BL =1, RB=1, IMASK=0x0F
287 ldc r8, sr ! here, change the register bank
310 2: .long gdb_vbr_vector
311 #endif /* CONFIG_SH_STANDARD_BIOS */
313 #endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */
318 #if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
320 mov.l @(r0,r15), r0 ! get status register
322 shll r0 ! kernel space?
325 mov.l @r15, r0 ! Restore R0 value
331 ENTRY(exception_error)
340 1: .long break_point_trap_software
341 2: .long do_exception_error
349 mov.l @(r0,r15), r0 ! get status register
351 shll r0 ! kernel space?
352 bt/s resume_kernel ! Yes, it's from kernel, go back soon
355 #ifdef CONFIG_PREEMPT
359 mov.l @(TI_PRE_COUNT,r8), r0 ! current_thread_info->preempt_count
363 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
364 tst #_TIF_NEED_RESCHED, r0 ! need_resched set?
368 mov.l @(r0,r15), r0 ! get status register
369 and #0xf0, r0 ! interrupts off (exception path)?
374 mov.l r0, @(TI_PRE_COUNT,r8)
381 mov.l r0, @(TI_PRE_COUNT,r8)
391 1: .long PREEMPT_ACTIVE
395 ENTRY(resume_userspace)
396 ! r8: current_thread_info
398 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
399 tst #_TIF_WORK_MASK, r0
401 tst #_TIF_NEED_RESCHED, r0
405 ! r0: current_thread_info->flags
406 ! r8: current_thread_info
407 ! t: result of "tst #_TIF_NEED_RESCHED, r0"
409 tst #_TIF_SIGPENDING, r0
419 #ifndef CONFIG_PREEMPT
421 mov.l @(OFF_SP,r15), r0 ! get user space stack pointer
428 ! SP >= 0xc0000000 : gUSA mark
429 mov.l @(r0,r15), r2 ! get user space PC (program counter)
430 mov.l @(OFF_R0,r15), r3 ! end point
431 cmp/hs r3, r2 ! r2 >= r3?
433 add r3, r1 ! rewind point #2
434 mov.l r1, @(r0,r15) ! reset PC to rewind point #2
443 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
444 tst #_TIF_WORK_MASK, r0
447 tst #_TIF_NEED_RESCHED, r0
455 ! r0: current_thread_info->flags
456 ! r8: current_thread_info
457 tst #_TIF_SYSCALL_TRACE, r0
459 tst #_TIF_NEED_RESCHED, r0
461 ! XXX setup arguments...
462 mov.l 4f, r0 ! do_syscall_trace
471 ! XXX setup arguments...
472 mov.l 4f, r11 ! Call do_syscall_trace which notifies
473 jsr @r11 ! superior (will chomp R[0-7])
475 ! Reload R0-R4 from kernel stack, where the
476 ! parent may have modified them using
477 ! ptrace(POKEUSR). (Note that R0-R2 are
478 ! used by the system call handler directly
479 ! from the kernel stack anyway, so don't need
480 ! to be reloaded here.) This allows the parent
481 ! to rewrite system calls and args on the fly.
482 mov.l @(OFF_R4,r15), r4 ! arg0
483 mov.l @(OFF_R5,r15), r5
484 mov.l @(OFF_R6,r15), r6
485 mov.l @(OFF_R7,r15), r7 ! arg3
486 mov.l @(OFF_R3,r15), r3 ! syscall_nr
487 ! Arrange for do_syscall_trace to be called
488 ! again as the system call returns.
489 mov.l 2f, r10 ! Number of syscalls
494 mov.l r0, @(OFF_R0,r15) ! Return value
500 * Arguments #0 to #3: R4--R7
501 * Arguments #4 to #6: R0, R1, R2
502 * TRA: (number of arguments + 0x10) x 4
504 * This code also handles delegating other traps to the BIOS/gdb stub
510 * 0x0-0xf old syscall ABI
511 * 0x10-0x1f new syscall ABI
512 * 0x20-0xff delegated through debug_trap to BIOS/gdb stub.
514 * Note: When we're first called, the TRA value must be shifted
515 * right 2 bits in order to get the value that was used as the "trapa"
528 1: .long schedule_tail
532 mov.l @r9, r8 ! Read from TRA (Trap Address) Register
534 ! Is the trap argument >= 0x20? (TRA will be >= 0x80)
541 mov.l r8, @r9 ! set TRA value to tra
543 ! Call the system call handler through the table.
544 ! First check for bad syscall number
546 mov.l 2f, r8 ! Number of syscalls
548 bf/s good_system_call
550 syscall_badsys: ! Bad syscall number
553 mov.l r0, @(OFF_R0,r15) ! Return value
559 good_system_call: ! Good syscall number
560 mov.l @(TI_FLAGS,r8), r8
561 mov #_TIF_SYSCALL_TRACE, r10
563 bf syscall_trace_entry
567 mov.l 3f, r8 ! Load the address of sys_call_table
570 jsr @r8 ! jump to specific syscall handler
572 mov.l r0, @(OFF_R0,r15) ! save the return value
578 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
579 tst #_TIF_ALLWORK_MASK, r0
593 or r9, r8 ! BL =1, RB=1
594 ldc r8, sr ! here, change the register bank
603 mov.l @r15+, k4 ! original stack pointer
606 mov.l @r15+, k3 ! original SR
610 add #4, r15 ! Skip syscall number
613 mov.l @r15+, k0 ! DSP mode marker
615 cmp/eq k0, k1 ! Do we have a DSP stack frame?
618 stc sr, k0 ! Enable CPU DSP mode
619 or k1, k0 ! (within kernel it may be disabled)
621 mov r2, k0 ! Backup r2
623 ! Restore DSP registers from stack
642 mov k0, r2 ! Restore r2
646 ! Calculate new SR value
647 mov k3, k2 ! original SR value
649 and k1, k2 ! Mask orignal SR value
651 mov k3, k0 ! Calculate IMASK-bits
659 6: or k0, k2 ! Set the IMASK-bits
662 #if defined(CONFIG_KGDB_NMI)
668 mov.l @r15+, k2 ! restore EXPEVT
676 3: .long sys_call_table
677 4: .long do_syscall_trace
678 5: .long 0x00001000 ! DSP
682 .long 0xffffff0f ! ~(IMASK)
684 ! Exception Vector Base
686 ! Should be aligned page boundary.
700 2: .long ret_from_exception
714 #if defined(CONFIG_KGDB_NMI)
715 ! Debounce (filter nested NMI)
729 #endif /* defined(CONFIG_KGDB_NMI) */
736 3: .long ret_from_irq
737 4: .long ret_from_exception
743 ! Using k0, k1 for scratch registers (r0_bank1, r1_bank),
744 ! save all registers onto stack.
746 stc ssr, k0 ! Is it from kernel space?
747 shll k0 ! Check MD bit (bit30) by shifting it into...
748 shll k0 ! ...the T bit
749 bt/s 1f ! It's a kernel to kernel transition.
750 mov r15, k0 ! save original stack to k0
751 /* User space to kernel */
753 shll8 k1 ! k1 := 8192 (== THREAD_SIZE)
755 mov k1, r15 ! change to kernel stack
761 mov.l r2, @-r15 ! Save r2, we need another reg
764 tst r2, k4 ! Check if in DSP mode
765 mov.l @r15+, r2 ! Restore r2 now
767 mov #0, k4 ! Set marker for no stack frame
769 mov r2, k4 ! Backup r2 (in k4) for later
771 ! Save DSP registers on stack
782 ! GAS is broken, does not generate correct "movs.l Ds,@-As" instr.
784 ! FIXME: Make sure that this is still the case with newer toolchains,
785 ! as we're not at all interested in supporting ancient toolchains at
786 ! this point. -- PFM.
789 .word 0xf653 ! movs.l a1, @-r2
790 .word 0xf6f3 ! movs.l a0g, @-r2
791 .word 0xf6d3 ! movs.l a1g, @-r2
792 .word 0xf6c3 ! movs.l m0, @-r2
793 .word 0xf6e3 ! movs.l m1, @-r2
796 mov k4, r2 ! Restore r2
797 mov.l 1f, k4 ! Force DSP stack frame
799 mov.l k4, @-r15 ! Push DSP mode marker onto stack
801 ! Save the user registers on the stack.
802 mov.l k2, @-r15 ! EXPEVT
803 mov.l k4, @-r15 ! set TRA (default: -1)
812 lds k3, pr ! Set the return address to pr
814 mov.l k0, @-r15 ! save orignal stack
823 stc sr, r8 ! Back to normal register bank, and
824 or k1, r8 ! Block all interrupts
827 ldc r8, sr ! ...changed here.
837 ! Then, dispatch to the handler, according to the exception code.
848 1: .long 0x00001000 ! DSP=1
849 2: .long 0x000080f0 ! FD=1, IMASK=15
850 3: .long 0xcfffffff ! RB=0, BL=0
851 4: .long exception_handling_table
854 ENTRY(exception_none)
859 ENTRY(sys_call_table)
860 .long sys_ni_syscall /* 0 - old "setup()" system call*/
865 .long sys_open /* 5 */
870 .long sys_unlink /* 10 */
875 .long sys_chmod /* 15 */
877 .long sys_ni_syscall /* old break syscall holder */
880 .long sys_getpid /* 20 */
885 .long sys_stime /* 25 */
890 .long sys_utime /* 30 */
891 .long sys_ni_syscall /* old stty syscall holder */
892 .long sys_ni_syscall /* old gtty syscall holder */
895 .long sys_ni_syscall /* 35 */ /* old ftime syscall holder */
900 .long sys_rmdir /* 40 */
904 .long sys_ni_syscall /* old prof syscall holder */
905 .long sys_brk /* 45 */
910 .long sys_getegid16 /* 50 */
912 .long sys_umount /* recycled never used phys() */
913 .long sys_ni_syscall /* old lock syscall holder */
915 .long sys_fcntl /* 55 */
916 .long sys_ni_syscall /* old mpx syscall holder */
918 .long sys_ni_syscall /* old ulimit syscall holder */
919 .long sys_ni_syscall /* sys_olduname */
920 .long sys_umask /* 60 */
925 .long sys_getpgrp /* 65 */
930 .long sys_setreuid16 /* 70 */
934 .long sys_sethostname
935 .long sys_setrlimit /* 75 */
936 .long sys_old_getrlimit
938 .long sys_gettimeofday
939 .long sys_settimeofday
940 .long sys_getgroups16 /* 80 */
941 .long sys_setgroups16
942 .long sys_ni_syscall /* sys_oldselect */
945 .long sys_readlink /* 85 */
950 .long old_mmap /* 90 */
955 .long sys_fchown16 /* 95 */
956 .long sys_getpriority
957 .long sys_setpriority
958 .long sys_ni_syscall /* old profil syscall holder */
960 .long sys_fstatfs /* 100 */
961 .long sys_ni_syscall /* ioperm */
965 .long sys_getitimer /* 105 */
970 .long sys_ni_syscall /* 110 */ /* iopl */
972 .long sys_ni_syscall /* idle */
973 .long sys_ni_syscall /* vm86old */
975 .long sys_swapoff /* 115 */
980 .long sys_clone /* 120 */
981 .long sys_setdomainname
983 .long sys_ni_syscall /* sys_modify_ldt */
985 .long sys_mprotect /* 125 */
986 .long sys_sigprocmask
987 .long sys_ni_syscall /* old "create_module" */
988 .long sys_init_module
989 .long sys_delete_module
990 .long sys_ni_syscall /* 130: old "get_kernel_syms" */
995 .long sys_sysfs /* 135 */
996 .long sys_personality
997 .long sys_ni_syscall /* for afs_syscall */
1000 .long sys_llseek /* 140 */
1005 .long sys_readv /* 145 */
1010 .long sys_mlock /* 150 */
1013 .long sys_munlockall
1014 .long sys_sched_setparam
1015 .long sys_sched_getparam /* 155 */
1016 .long sys_sched_setscheduler
1017 .long sys_sched_getscheduler
1018 .long sys_sched_yield
1019 .long sys_sched_get_priority_max
1020 .long sys_sched_get_priority_min /* 160 */
1021 .long sys_sched_rr_get_interval
1024 .long sys_setresuid16
1025 .long sys_getresuid16 /* 165 */
1026 .long sys_ni_syscall /* vm86 */
1027 .long sys_ni_syscall /* old "query_module" */
1029 .long sys_nfsservctl
1030 .long sys_setresgid16 /* 170 */
1031 .long sys_getresgid16
1033 .long sys_rt_sigreturn
1034 .long sys_rt_sigaction
1035 .long sys_rt_sigprocmask /* 175 */
1036 .long sys_rt_sigpending
1037 .long sys_rt_sigtimedwait
1038 .long sys_rt_sigqueueinfo
1039 .long sys_rt_sigsuspend
1040 .long sys_pread_wrapper /* 180 */
1041 .long sys_pwrite_wrapper
1045 .long sys_capset /* 185 */
1046 .long sys_sigaltstack
1048 .long sys_ni_syscall /* streams1 */
1049 .long sys_ni_syscall /* streams2 */
1050 .long sys_vfork /* 190 */
1053 .long sys_truncate64
1054 .long sys_ftruncate64
1055 .long sys_stat64 /* 195 */
1060 .long sys_getgid /* 200 */
1065 .long sys_getgroups /* 205 */
1070 .long sys_setresgid /* 210 */
1075 .long sys_setfsuid /* 215 */
1077 .long sys_pivot_root
1080 .long sys_getdents64 /* 220 */
1082 .long sys_ni_syscall /* reserved for TUX */
1083 .long sys_ni_syscall /* Reserved for Security */
1085 .long sys_readahead /* 225 */
1090 .long sys_lgetxattr /* 230 */
1093 .long sys_llistxattr
1094 .long sys_flistxattr
1095 .long sys_removexattr /* 235 */
1096 .long sys_lremovexattr
1097 .long sys_fremovexattr
1099 .long sys_sendfile64
1100 .long sys_futex /* 240 */
1101 .long sys_sched_setaffinity
1102 .long sys_sched_getaffinity
1103 .long sys_ni_syscall
1104 .long sys_ni_syscall
1105 .long sys_io_setup /* 245 */
1106 .long sys_io_destroy
1107 .long sys_io_getevents
1110 .long sys_fadvise64 /* 250 */
1111 .long sys_ni_syscall
1112 .long sys_exit_group
1113 .long sys_lookup_dcookie
1114 .long sys_epoll_create
1115 .long sys_epoll_ctl /* 255 */
1116 .long sys_epoll_wait
1117 .long sys_remap_file_pages
1118 .long sys_set_tid_address
1119 .long sys_timer_create
1120 .long sys_timer_settime /* 260 */
1121 .long sys_timer_gettime
1122 .long sys_timer_getoverrun
1123 .long sys_timer_delete
1124 .long sys_clock_settime
1125 .long sys_clock_gettime /* 265 */
1126 .long sys_clock_getres
1127 .long sys_clock_nanosleep
1130 .long sys_tgkill /* 270 */
1132 .long sys_fadvise64_64_wrapper
1133 .long sys_ni_syscall /* Reserved for vserver */
1134 .long sys_ni_syscall /* Reserved for mbind */
1135 .long sys_ni_syscall /* 275 - get_mempolicy */
1136 .long sys_ni_syscall /* set_mempolicy */
1139 .long sys_mq_timedsend
1140 .long sys_mq_timedreceive /* 280 */
1142 .long sys_mq_getsetattr
1143 .long sys_ni_syscall /* Reserved for kexec */
1145 .long sys_add_key /* 285 */
1146 .long sys_request_key
1148 .long sys_ioprio_set
1149 .long sys_ioprio_get
1150 .long sys_inotify_init /* 290 */
1151 .long sys_inotify_add_watch
1152 .long sys_inotify_rm_watch
1154 /* End of entry.S */