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/thread_info.h>
18 #include <asm/unistd.h>
20 #if !defined(CONFIG_NFSD) && !defined(CONFIG_NFSD_MODULE)
21 #define sys_nfsservctl sys_ni_syscall
24 #if !defined(CONFIG_MMU)
25 #define sys_madvise sys_ni_syscall
26 #define sys_readahead sys_ni_syscall
27 #define sys_mprotect sys_ni_syscall
28 #define sys_msync sys_ni_syscall
29 #define sys_mlock sys_ni_syscall
30 #define sys_munlock sys_ni_syscall
31 #define sys_mlockall sys_ni_syscall
32 #define sys_munlockall sys_ni_syscall
33 #define sys_mremap sys_ni_syscall
34 #define sys_mincore sys_ni_syscall
35 #define sys_remap_file_pages sys_ni_syscall
39 ! GNU as (as of 2.9.1) changes bf/s into bt/s and bra, when the address
40 ! to be jumped is too far, but it causes illegal slot exception.
43 * entry.S contains the system-call and fault low-level handling routines.
44 * This also contains the timer-interrupt handler, as well as all interrupts
45 * and faults that can result in a task-switch.
47 * NOTE: This code handles signal-recognition, which happens every time
48 * after a timer-interrupt and after each system call.
50 * NOTE: This code uses a convention that instructions in the delay slot
51 * of a transfer-control instruction are indented by an extra space, thus:
53 * jmp @k0 ! control-transfer instruction
54 * ldc k1, ssr ! delay slot
56 * Stack layout in 'ret_from_syscall':
57 * ptrace needs to have all regs on the stack.
58 * if the order here is changed, it needs to be
59 * updated in ptrace.c and ptrace.h
77 #if defined(CONFIG_CPU_SH3)
80 #if defined(CONFIG_CPU_SUBTYPE_SH7707) || defined(CONFIG_CPU_SUBTYPE_SH7709) || \
81 defined(CONFIG_CPU_SUBTYPE_SH7300) || defined(CONFIG_CPU_SUBTYPE_SH7705)
82 INTEVT = 0xa4000000 ! INTEVTE2(0xa4000000)
86 MMU_TEA = 0xfffffffc ! TLB Exception Address Register
87 #elif defined(CONFIG_CPU_SH4)
91 MMU_TEA = 0xff00000c ! TLB Exception Address Register
94 #if defined(CONFIG_KGDB_NMI)
95 NMI_VEC = 0x1c0 ! Must catch early for debounce
98 /* Offsets to the stack */
99 OFF_R0 = 0 /* Return value. New ABI also arg4 */
100 OFF_R1 = 4 /* New ABI: arg5 */
101 OFF_R2 = 8 /* New ABI: arg6 */
102 OFF_R3 = 12 /* New ABI: syscall_nr */
103 OFF_R4 = 16 /* New ABI: arg0 */
104 OFF_R5 = 20 /* New ABI: arg1 */
105 OFF_R6 = 24 /* New ABI: arg2 */
106 OFF_R7 = 28 /* New ABI: arg3 */
119 #define k_ex_code r2_bank /* r2_bank1 */
120 #define g_imask r6 /* r6_bank1 */
121 #define k_g_imask r6_bank /* r6_bank1 */
122 #define current r7 /* r7_bank1 */
125 * Kernel mode register usage:
128 * k2 scratch (Exception code)
129 * k3 scratch (Return address)
132 * k6 Global Interrupt Mask (0--15 << 4)
133 * k7 CURRENT_THREAD_INFO (pointer to current thread info)
137 ! TLB Miss / Initial Page write exception handling
139 ! TLB hits, but the access violate the protection.
140 ! It can be valid access, such as stack grow and/or C-O-W.
143 ! Find the pmd/pte entry and loadtlb
144 ! If it's not found, cause address error (SEGV)
146 ! Although this could be written in assembly language (and it'd be faster),
147 ! this first version depends *much* on C implementation.
156 mov.l __INV_IMASK, r11; \
159 stc k_g_imask, r11; \
163 #if defined(CONFIG_PREEMPT)
164 # define preempt_stop() CLI()
166 # define preempt_stop()
167 # define resume_kernel restore_all
170 #if defined(CONFIG_MMU)
177 ENTRY(tlb_miss_store)
182 ENTRY(initial_page_write)
187 ENTRY(tlb_protection_violation_load)
192 ENTRY(tlb_protection_violation_store)
220 2: .long __do_page_fault
221 3: .long do_page_fault
224 ENTRY(address_error_load)
226 mov #0,r5 ! writeaccess = 0
229 ENTRY(address_error_store)
231 mov #1,r5 ! writeaccess = 1
236 mov.l @r0, r6 ! address
243 2: .long do_address_error
244 #endif /* CONFIG_MMU */
246 #if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
247 ! Handle kernel debug if either kgdb (SW) or gdb-stub (FW) is present.
248 ! If both are configured, handle the debug traps (breakpoints) in SW,
249 ! but still allow BIOS traps to FW.
253 #if defined(CONFIG_SH_STANDARD_BIOS) && defined(CONFIG_SH_KGDB)
254 /* Force BIOS call to FW (debug_trap put TRA in r8) */
259 #endif /* CONFIG_SH_STANDARD_BIOS && CONFIG_SH_KGDB */
262 #if defined(CONFIG_SH_KGDB)
263 /* Jump to kgdb, pass stacked regs as arg */
269 3: .long kgdb_handle_exception
270 #endif /* CONFIG_SH_KGDB */
272 #if defined(CONFIG_SH_STANDARD_BIOS)
273 /* Unwind the stack and jmp to the debug entry */
284 mov.l 1f, r9 ! BL =1, RB=1, IMASK=0x0F
286 ldc r8, sr ! here, change the register bank
309 2: .long gdb_vbr_vector
310 #endif /* CONFIG_SH_STANDARD_BIOS */
312 #endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */
317 #if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
319 mov.l @(r0,r15), r0 ! get status register
321 shll r0 ! kernel space?
324 mov.l @r15, r0 ! Restore R0 value
330 ENTRY(exception_error)
339 1: .long break_point_trap_software
340 2: .long do_exception_error
348 mov.l @(r0,r15), r0 ! get status register
350 shll r0 ! kernel space?
351 bt/s resume_kernel ! Yes, it's from kernel, go back soon
354 #ifdef CONFIG_PREEMPT
358 mov.l @(TI_PRE_COUNT,r8), r0 ! current_thread_info->preempt_count
362 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
363 tst #_TIF_NEED_RESCHED, r0 ! need_resched set?
367 mov.l @(r0,r15), r0 ! get status register
368 and #0xf0, r0 ! interrupts off (exception path)?
373 mov.l r0, @(TI_PRE_COUNT,r8)
380 mov.l r0, @(TI_PRE_COUNT,r8)
390 1: .long PREEMPT_ACTIVE
394 ENTRY(resume_userspace)
395 ! r8: current_thread_info
397 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
398 tst #_TIF_WORK_MASK, r0
400 tst #_TIF_NEED_RESCHED, r0
404 ! r0: current_thread_info->flags
405 ! r8: current_thread_info
406 ! t: result of "tst #_TIF_NEED_RESCHED, r0"
408 tst #_TIF_SIGPENDING, r0
418 #ifndef CONFIG_PREEMPT
420 mov.l @(OFF_SP,r15), r0 ! get user space stack pointer
427 ! SP >= 0xc0000000 : gUSA mark
428 mov.l @(r0,r15), r2 ! get user space PC (program counter)
429 mov.l @(OFF_R0,r15), r3 ! end point
430 cmp/hs r3, r2 ! r2 >= r3?
432 add r3, r1 ! rewind point #2
433 mov.l r1, @(r0,r15) ! reset PC to rewind point #2
442 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
443 tst #_TIF_WORK_MASK, r0
446 tst #_TIF_NEED_RESCHED, r0
454 ! r0: current_thread_info->flags
455 ! r8: current_thread_info
456 tst #_TIF_SYSCALL_TRACE, r0
458 tst #_TIF_NEED_RESCHED, r0
460 ! XXX setup arguments...
461 mov.l 4f, r0 ! do_syscall_trace
470 ! XXX setup arguments...
471 mov.l 4f, r11 ! Call do_syscall_trace which notifies
472 jsr @r11 ! superior (will chomp R[0-7])
474 ! Reload R0-R4 from kernel stack, where the
475 ! parent may have modified them using
476 ! ptrace(POKEUSR). (Note that R0-R2 are
477 ! used by the system call handler directly
478 ! from the kernel stack anyway, so don't need
479 ! to be reloaded here.) This allows the parent
480 ! to rewrite system calls and args on the fly.
481 mov.l @(OFF_R4,r15), r4 ! arg0
482 mov.l @(OFF_R5,r15), r5
483 mov.l @(OFF_R6,r15), r6
484 mov.l @(OFF_R7,r15), r7 ! arg3
485 mov.l @(OFF_R3,r15), r3 ! syscall_nr
486 ! Arrange for do_syscall_trace to be called
487 ! again as the system call returns.
488 mov.l 2f, r10 ! Number of syscalls
493 mov.l r0, @(OFF_R0,r15) ! Return value
499 * Arguments #0 to #3: R4--R7
500 * Arguments #4 to #6: R0, R1, R2
501 * TRA: (number of arguments + 0x10) x 4
503 * This code also handles delegating other traps to the BIOS/gdb stub
509 * 0x0-0xf old syscall ABI
510 * 0x10-0x1f new syscall ABI
511 * 0x20-0xff delegated through debug_trap to BIOS/gdb stub.
513 * Note: When we're first called, the TRA value must be shifted
514 * right 2 bits in order to get the value that was used as the "trapa"
527 1: .long schedule_tail
531 mov.l @r9, r8 ! Read from TRA (Trap Address) Register
533 ! Is the trap argument >= 0x20? (TRA will be >= 0x80)
540 mov.l r8, @r9 ! set TRA value to tra
542 ! Call the system call handler through the table.
543 ! First check for bad syscall number
545 mov.l 2f, r8 ! Number of syscalls
547 bf/s good_system_call
549 syscall_badsys: ! Bad syscall number
552 mov.l r0, @(OFF_R0,r15) ! Return value
558 good_system_call: ! Good syscall number
559 mov.l @(TI_FLAGS,r8), r8
560 mov #_TIF_SYSCALL_TRACE, r10
562 bf syscall_trace_entry
566 mov.l 3f, r8 ! Load the address of sys_call_table
569 jsr @r8 ! jump to specific syscall handler
571 mov.l r0, @(OFF_R0,r15) ! save the return value
577 mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
578 tst #_TIF_ALLWORK_MASK, r0
592 or r9, r8 ! BL =1, RB=1
593 ldc r8, sr ! here, change the register bank
602 mov.l @r15+, k4 ! original stack pointer
605 mov.l @r15+, k3 ! original SR
609 add #4, r15 ! Skip syscall number
612 mov.l @r15+, k0 ! DSP mode marker
614 cmp/eq k0, k1 ! Do we have a DSP stack frame?
617 stc sr, k0 ! Enable CPU DSP mode
618 or k1, k0 ! (within kernel it may be disabled)
620 mov r2, k0 ! Backup r2
622 ! Restore DSP registers from stack
641 mov k0, r2 ! Restore r2
645 ! Calculate new SR value
646 mov k3, k2 ! original SR value
648 and k1, k2 ! Mask orignal SR value
650 mov k3, k0 ! Calculate IMASK-bits
658 6: or k0, k2 ! Set the IMASK-bits
661 #if defined(CONFIG_KGDB_NMI)
667 mov.l @r15+, k2 ! restore EXPEVT
675 3: .long sys_call_table
676 4: .long do_syscall_trace
677 5: .long 0x00001000 ! DSP
681 .long 0xffffff0f ! ~(IMASK)
683 ! Exception Vector Base
685 ! Should be aligned page boundary.
699 2: .long ret_from_exception
713 #if defined(CONFIG_KGDB_NMI)
714 ! Debounce (filter nested NMI)
728 #endif /* defined(CONFIG_KGDB_NMI) */
735 3: .long ret_from_irq
736 4: .long ret_from_exception
742 ! Using k0, k1 for scratch registers (r0_bank1, r1_bank),
743 ! save all registers onto stack.
745 stc ssr, k0 ! Is it from kernel space?
746 shll k0 ! Check MD bit (bit30) by shifting it into...
747 shll k0 ! ...the T bit
748 bt/s 1f ! It's a kernel to kernel transition.
749 mov r15, k0 ! save original stack to k0
750 /* User space to kernel */
752 shll8 k1 ! k1 := 8192 (== THREAD_SIZE)
754 mov k1, r15 ! change to kernel stack
760 mov.l r2, @-r15 ! Save r2, we need another reg
763 tst r2, k4 ! Check if in DSP mode
764 mov.l @r15+, r2 ! Restore r2 now
766 mov #0, k4 ! Set marker for no stack frame
768 mov r2, k4 ! Backup r2 (in k4) for later
770 ! Save DSP registers on stack
781 ! GAS is broken, does not generate correct "movs.l Ds,@-As" instr.
783 ! FIXME: Make sure that this is still the case with newer toolchains,
784 ! as we're not at all interested in supporting ancient toolchains at
785 ! this point. -- PFM.
788 .word 0xf653 ! movs.l a1, @-r2
789 .word 0xf6f3 ! movs.l a0g, @-r2
790 .word 0xf6d3 ! movs.l a1g, @-r2
791 .word 0xf6c3 ! movs.l m0, @-r2
792 .word 0xf6e3 ! movs.l m1, @-r2
795 mov k4, r2 ! Restore r2
796 mov.l 1f, k4 ! Force DSP stack frame
798 mov.l k4, @-r15 ! Push DSP mode marker onto stack
800 ! Save the user registers on the stack.
801 mov.l k2, @-r15 ! EXPEVT
802 mov.l k4, @-r15 ! set TRA (default: -1)
811 lds k3, pr ! Set the return address to pr
813 mov.l k0, @-r15 ! save orignal stack
822 stc sr, r8 ! Back to normal register bank, and
823 or k1, r8 ! Block all interrupts
826 ldc r8, sr ! ...changed here.
836 ! Then, dispatch to the handler, according to the exception code.
847 1: .long 0x00001000 ! DSP=1
848 2: .long 0x000080f0 ! FD=1, IMASK=15
849 3: .long 0xcfffffff ! RB=0, BL=0
850 4: .long exception_handling_table
853 ENTRY(exception_none)
858 ENTRY(sys_call_table)
859 .long sys_ni_syscall /* 0 - old "setup()" system call*/
864 .long sys_open /* 5 */
869 .long sys_unlink /* 10 */
874 .long sys_chmod /* 15 */
876 .long sys_ni_syscall /* old break syscall holder */
879 .long sys_getpid /* 20 */
884 .long sys_stime /* 25 */
889 .long sys_utime /* 30 */
890 .long sys_ni_syscall /* old stty syscall holder */
891 .long sys_ni_syscall /* old gtty syscall holder */
894 .long sys_ni_syscall /* 35 */ /* old ftime syscall holder */
899 .long sys_rmdir /* 40 */
903 .long sys_ni_syscall /* old prof syscall holder */
904 .long sys_brk /* 45 */
909 .long sys_getegid16 /* 50 */
911 .long sys_umount /* recycled never used phys() */
912 .long sys_ni_syscall /* old lock syscall holder */
914 .long sys_fcntl /* 55 */
915 .long sys_ni_syscall /* old mpx syscall holder */
917 .long sys_ni_syscall /* old ulimit syscall holder */
918 .long sys_ni_syscall /* sys_olduname */
919 .long sys_umask /* 60 */
924 .long sys_getpgrp /* 65 */
929 .long sys_setreuid16 /* 70 */
933 .long sys_sethostname
934 .long sys_setrlimit /* 75 */
935 .long sys_old_getrlimit
937 .long sys_gettimeofday
938 .long sys_settimeofday
939 .long sys_getgroups16 /* 80 */
940 .long sys_setgroups16
941 .long sys_ni_syscall /* sys_oldselect */
944 .long sys_readlink /* 85 */
949 .long old_mmap /* 90 */
954 .long sys_fchown16 /* 95 */
955 .long sys_getpriority
956 .long sys_setpriority
957 .long sys_ni_syscall /* old profil syscall holder */
959 .long sys_fstatfs /* 100 */
960 .long sys_ni_syscall /* ioperm */
964 .long sys_getitimer /* 105 */
969 .long sys_ni_syscall /* 110 */ /* iopl */
971 .long sys_ni_syscall /* idle */
972 .long sys_ni_syscall /* vm86old */
974 .long sys_swapoff /* 115 */
979 .long sys_clone /* 120 */
980 .long sys_setdomainname
982 .long sys_ni_syscall /* sys_modify_ldt */
984 .long sys_mprotect /* 125 */
985 .long sys_sigprocmask
986 .long sys_ni_syscall /* old "create_module" */
987 .long sys_init_module
988 .long sys_delete_module
989 .long sys_ni_syscall /* 130: old "get_kernel_syms" */
994 .long sys_sysfs /* 135 */
995 .long sys_personality
996 .long sys_ni_syscall /* for afs_syscall */
999 .long sys_llseek /* 140 */
1004 .long sys_readv /* 145 */
1009 .long sys_mlock /* 150 */
1012 .long sys_munlockall
1013 .long sys_sched_setparam
1014 .long sys_sched_getparam /* 155 */
1015 .long sys_sched_setscheduler
1016 .long sys_sched_getscheduler
1017 .long sys_sched_yield
1018 .long sys_sched_get_priority_max
1019 .long sys_sched_get_priority_min /* 160 */
1020 .long sys_sched_rr_get_interval
1023 .long sys_setresuid16
1024 .long sys_getresuid16 /* 165 */
1025 .long sys_ni_syscall /* vm86 */
1026 .long sys_ni_syscall /* old "query_module" */
1028 .long sys_nfsservctl
1029 .long sys_setresgid16 /* 170 */
1030 .long sys_getresgid16
1032 .long sys_rt_sigreturn
1033 .long sys_rt_sigaction
1034 .long sys_rt_sigprocmask /* 175 */
1035 .long sys_rt_sigpending
1036 .long sys_rt_sigtimedwait
1037 .long sys_rt_sigqueueinfo
1038 .long sys_rt_sigsuspend
1039 .long sys_pread_wrapper /* 180 */
1040 .long sys_pwrite_wrapper
1044 .long sys_capset /* 185 */
1045 .long sys_sigaltstack
1047 .long sys_ni_syscall /* streams1 */
1048 .long sys_ni_syscall /* streams2 */
1049 .long sys_vfork /* 190 */
1052 .long sys_truncate64
1053 .long sys_ftruncate64
1054 .long sys_stat64 /* 195 */
1059 .long sys_getgid /* 200 */
1064 .long sys_getgroups /* 205 */
1069 .long sys_setresgid /* 210 */
1074 .long sys_setfsuid /* 215 */
1076 .long sys_pivot_root
1079 .long sys_getdents64 /* 220 */
1081 .long sys_ni_syscall /* reserved for TUX */
1082 .long sys_ni_syscall /* Reserved for Security */
1084 .long sys_readahead /* 225 */
1089 .long sys_lgetxattr /* 230 */
1092 .long sys_llistxattr
1093 .long sys_flistxattr
1094 .long sys_removexattr /* 235 */
1095 .long sys_lremovexattr
1096 .long sys_fremovexattr
1098 .long sys_sendfile64
1099 .long sys_futex /* 240 */
1100 .long sys_sched_setaffinity
1101 .long sys_sched_getaffinity
1102 .long sys_ni_syscall
1103 .long sys_ni_syscall
1104 .long sys_io_setup /* 245 */
1105 .long sys_io_destroy
1106 .long sys_io_getevents
1109 .long sys_fadvise64 /* 250 */
1110 .long sys_ni_syscall
1111 .long sys_exit_group
1112 .long sys_lookup_dcookie
1113 .long sys_epoll_create
1114 .long sys_epoll_ctl /* 255 */
1115 .long sys_epoll_wait
1116 .long sys_remap_file_pages
1117 .long sys_set_tid_address
1118 .long sys_timer_create
1119 .long sys_timer_settime /* 260 */
1120 .long sys_timer_gettime
1121 .long sys_timer_getoverrun
1122 .long sys_timer_delete
1123 .long sys_clock_settime
1124 .long sys_clock_gettime /* 265 */
1125 .long sys_clock_getres
1126 .long sys_clock_nanosleep
1129 .long sys_tgkill /* 270 */
1131 .long sys_fadvise64_64_wrapper
1132 .long sys_ni_syscall /* Reserved for vserver */
1133 .long sys_ni_syscall /* Reserved for mbind */
1134 .long sys_ni_syscall /* 275 - get_mempolicy */
1135 .long sys_ni_syscall /* set_mempolicy */
1138 .long sys_mq_timedsend
1139 .long sys_mq_timedreceive /* 280 */
1141 .long sys_mq_getsetattr
1143 /* End of entry.S */