1 ###############################################################################
3 # MN10300 Exception and interrupt entry points
5 # Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
6 # Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
7 # Modified by David Howells (dhowells@redhat.com)
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public Licence
11 # as published by the Free Software Foundation; either version
12 # 2 of the Licence, or (at your option) any later version.
14 ###############################################################################
15 #include <linux/sys.h>
16 #include <linux/linkage.h>
18 #include <asm/irqflags.h>
19 #include <asm/thread_info.h>
20 #include <asm/intctl-regs.h>
21 #include <asm/busctl-regs.h>
22 #include <asm/timer-regs.h>
23 #include <unit/leds.h>
25 #include <asm/pgtable.h>
26 #include <asm/errno.h>
27 #include <asm/asm-offsets.h>
28 #include <asm/frame.inc>
30 #if defined(CONFIG_SMP) && defined(CONFIG_GDBSTUB)
31 #include <asm/gdb-stub.h>
32 #endif /* CONFIG_SMP && CONFIG_GDBSTUB */
35 #define preempt_stop LOCAL_IRQ_DISABLE
38 #define resume_kernel restore_all
43 ###############################################################################
45 # the return path for a forked child
46 # - on entry, D0 holds the address of the previous task to run
48 ###############################################################################
50 call schedule_tail[],0
53 # return 0 to indicate child process
58 ENTRY(ret_from_kernel_thread)
59 call schedule_tail[],0
65 ENTRY(ret_from_kernel_execve)
66 add -12,d0 /* pt_regs -> frame */
72 ###############################################################################
76 ###############################################################################
80 mov d0,(REG_ORIG_D0,fp)
84 btst _TIF_SYSCALL_TRACE,(TI_flags,a2)
85 bne syscall_entry_trace
90 mov (sys_call_table,a1),a0
94 # make sure we don't miss an interrupt setting need_resched or
95 # sigpending between sampling and the rti
98 btst _TIF_ALLWORK_MASK,d2
103 ###############################################################################
105 # perform work that needs to be done immediately before resumption and syscall
108 ###############################################################################
113 beq resume_kernel # returning to supervisor mode
115 btst _TIF_SYSCALL_TRACE,d2
117 LOCAL_IRQ_ENABLE # could let syscall_trace_exit() call
120 call syscall_trace_exit[],0 # do_syscall_trace(regs)
125 btst _TIF_NEED_RESCHED,d2
131 # make sure we don't miss an interrupt setting need_resched or
132 # sigpending between sampling and the rti
135 # is there any work to be done other than syscall tracing?
137 btst _TIF_WORK_MASK,d2
139 btst _TIF_NEED_RESCHED,d2
142 # deal with pending signals and notify-resume requests
146 call do_notify_resume[],0
149 # perform syscall entry tracing
154 call syscall_trace_entry[],0 # returns the syscall number to actually use
165 # userspace resumption stub bypassing syscall exit tracing
166 .globl ret_from_exception, ret_from_intr
172 mov (REG_EPSW,fp),d0 # need to deliver signals before
173 # returning to userspace
175 beq resume_kernel # returning to supervisor mode
177 ENTRY(resume_userspace)
178 # make sure we don't miss an interrupt setting need_resched or
179 # sigpending between sampling and the rti
182 # is there any work to be done on int/exception return?
184 btst _TIF_WORK_MASK,d2
188 #ifdef CONFIG_PREEMPT
191 mov (TI_preempt_count,a2),d0 # non-zero preempt_count ?
196 btst _TIF_NEED_RESCHED,(TI_flags,a2)
200 cmp EPSW_IM_7,d0 # interrupts off (exception path) ?
202 call preempt_schedule_irq[],0
207 ###############################################################################
209 # IRQ handler entry point
210 # - intended to be entered at multiple priorities
212 ###############################################################################
219 mov d0,(REG_ORIG_D0,fp)
222 call do_IRQ[],0 # do_IRQ(regs)
226 ###############################################################################
228 # Double Fault handler entry point
229 # - note that there will not be a stack, D0/A0 will hold EPSW/PC as were
231 ###############################################################################
239 mov a0,(__df_stack-4) # PC as was
240 mov d0,(__df_stack-8) # EPSW as was
241 mn10300_set_dbfleds # display 'db-f' on the LEDs
243 mov d0,(__df_stack-12) # no ORIG_D0
244 mov sp,a0 # save corrupted SP
245 mov __df_stack-12,sp # emergency supervisor stack
247 mov a0,(REG_A0,fp) # save corrupted SP as A0 (which got
248 # clobbered by the CPU)
250 calls do_double_fault
252 bra double_fault_loop
254 ###############################################################################
256 # Bus Error handler entry point
257 # - handle external (async) bus errors separately
259 ###############################################################################
263 #if defined(CONFIG_ERRATUM_NEED_TO_RELOAD_MMUCTR)
267 mov (BCBERR),d0 # what
268 btst BCBERR_BEMR_DMA,d0 # see if it was an external bus error
269 beq __common_exception_aux # it wasn't
272 mov (BCBEAR),d1 # destination of erroneous access
274 mov (REG_ORIG_D0,fp),d2
277 mov d2,(REG_ORIG_D0,fp)
280 mov fp,(12,sp) # frame pointer
281 call io_bus_error[],0
284 ###############################################################################
286 # NMI exception entry points
288 # This is used by ordinary interrupt channels that have the GxICR_NMI bit set
289 # in addition to the main NMI and Watchdog channels. SMP NMI IPIs use this
292 ###############################################################################
300 mov d0,(sp) # save d0(TBR)
304 cmp CALL_FUNCTION_NMI_IPI,d0
305 bne nmi_not_smp_callfunc # if not call function, jump
307 # function call nmi ipi
308 add 4,sp # no need to store TBR
309 mov GxICR_DETECT,d0 # clear NMI request
310 movbu d0,(GxICR(CALL_FUNCTION_NMI_IPI))
311 movhu (GxICR(CALL_FUNCTION_NMI_IPI)),d0
312 and ~EPSW_NMID,epsw # enable NMI
314 mov (sp),d0 # restore d0
316 call smp_nmi_call_function_interrupt[],0
319 nmi_not_smp_callfunc:
320 #ifdef CONFIG_KERNEL_DEBUGGER
321 cmp DEBUGGER_NMI_IPI,d0
322 bne nmi_not_debugger # if not kernel debugger NMI IPI, jump
324 # kernel debugger NMI IPI
325 add 4,sp # no need to store TBR
326 mov GxICR_DETECT,d0 # clear NMI
327 movbu d0,(GxICR(DEBUGGER_NMI_IPI))
328 movhu (GxICR(DEBUGGER_NMI_IPI)),d0
329 and ~EPSW_NMID,epsw # enable NMI
333 mov fp,d0 # arg 0: stacked register file
334 mov a2,d1 # arg 1: exception number
335 call debugger_nmi_interrupt[],0
339 #endif /* CONFIG_KERNEL_DEBUGGER */
340 mov (sp),d0 # restore TBR to d0
342 #endif /* CONFIG_SMP */
344 bra __common_exception_nonmi
346 ###############################################################################
348 # General exception entry point
350 ###############################################################################
351 ENTRY(__common_exception)
354 #if defined(CONFIG_ERRATUM_NEED_TO_RELOAD_MMUCTR)
359 __common_exception_aux:
361 and ~EPSW_NMID,epsw # turn NMIs back on if not NMI
364 __common_exception_nonmi:
365 and 0x0000FFFF,d0 # turn the exception code into a vector
373 SAVE_ALL # build the stack frame
375 mov (REG_D0,fp),a2 # get the exception number
376 mov (REG_ORIG_D0,fp),d0
379 mov d0,(REG_ORIG_D0,fp)
381 #ifdef CONFIG_GDBSTUB
383 call gdbstub_busy_check[],0
384 and d0,d0 # check return value
386 #else /* CONFIG_SMP */
387 btst 0x01,(gdbstub_busy)
389 #endif /* CONFIG_SMP */
393 call gdbstub_exception[],0 # gdbstub itself caused an exception
396 #endif /* CONFIG_GDBSTUB */
398 mov fp,d0 # arg 0: stacked register file
399 mov a2,d1 # arg 1: exception number
402 mov (exception_table,a2),a2
404 jmp ret_from_exception
406 1: pi # BUG() equivalent
408 ###############################################################################
410 # Exception handler functions table
412 ###############################################################################
414 ENTRY(exception_table)
416 .long uninitialised_exception
420 ###############################################################################
422 # Change an entry in the exception table
423 # - D0 exception code, D1 handler
425 ###############################################################################
426 ENTRY(set_excp_vector)
428 add exception_table,d0
433 ###############################################################################
437 ###############################################################################
439 ENTRY(sys_call_table)
440 .long sys_restart_syscall /* 0 */
445 .long sys_open /* 5 */
450 .long sys_unlink /* 10 */
455 .long sys_chmod /* 15 */
457 .long sys_ni_syscall /* old break syscall holder */
460 .long sys_getpid /* 20 */
465 .long sys_stime /* 25 */
470 .long sys_utime /* 30 */
471 .long sys_ni_syscall /* old stty syscall holder */
472 .long sys_ni_syscall /* old gtty syscall holder */
475 .long sys_ni_syscall /* 35 - old ftime syscall holder */
480 .long sys_rmdir /* 40 */
484 .long sys_ni_syscall /* old prof syscall holder */
485 .long sys_brk /* 45 */
490 .long sys_getegid16 /* 50 */
492 .long sys_umount /* recycled never used phys() */
493 .long sys_ni_syscall /* old lock syscall holder */
495 .long sys_fcntl /* 55 */
496 .long sys_ni_syscall /* old mpx syscall holder */
498 .long sys_ni_syscall /* old ulimit syscall holder */
499 .long sys_ni_syscall /* old sys_olduname */
500 .long sys_umask /* 60 */
505 .long sys_getpgrp /* 65 */
510 .long sys_setreuid16 /* 70 */
514 .long sys_sethostname
515 .long sys_setrlimit /* 75 */
516 .long sys_old_getrlimit
518 .long sys_gettimeofday
519 .long sys_settimeofday
520 .long sys_getgroups16 /* 80 */
521 .long sys_setgroups16
525 .long sys_readlink /* 85 */
529 .long sys_old_readdir
530 .long old_mmap /* 90 */
535 .long sys_fchown16 /* 95 */
536 .long sys_getpriority
537 .long sys_setpriority
538 .long sys_ni_syscall /* old profil syscall holder */
540 .long sys_fstatfs /* 100 */
541 .long sys_ni_syscall /* ioperm */
545 .long sys_getitimer /* 105 */
549 .long sys_ni_syscall /* old sys_uname */
550 .long sys_ni_syscall /* 110 - iopl */
552 .long sys_ni_syscall /* old "idle" system call */
553 .long sys_ni_syscall /* vm86old */
555 .long sys_swapoff /* 115 */
560 .long sys_clone /* 120 */
561 .long sys_setdomainname
563 .long sys_ni_syscall /* modify_ldt */
565 .long sys_mprotect /* 125 */
566 .long sys_sigprocmask
567 .long sys_ni_syscall /* old "create_module" */
568 .long sys_init_module
569 .long sys_delete_module
570 .long sys_ni_syscall /* 130: old "get_kernel_syms" */
575 .long sys_sysfs /* 135 */
576 .long sys_personality
577 .long sys_ni_syscall /* reserved for afs_syscall */
580 .long sys_llseek /* 140 */
585 .long sys_readv /* 145 */
590 .long sys_mlock /* 150 */
594 .long sys_sched_setparam
595 .long sys_sched_getparam /* 155 */
596 .long sys_sched_setscheduler
597 .long sys_sched_getscheduler
598 .long sys_sched_yield
599 .long sys_sched_get_priority_max
600 .long sys_sched_get_priority_min /* 160 */
601 .long sys_sched_rr_get_interval
604 .long sys_setresuid16
605 .long sys_getresuid16 /* 165 */
606 .long sys_ni_syscall /* vm86 */
607 .long sys_ni_syscall /* Old sys_query_module */
609 .long sys_ni_syscall /* was nfsservctl */
610 .long sys_setresgid16 /* 170 */
611 .long sys_getresgid16
613 .long sys_rt_sigreturn
614 .long sys_rt_sigaction
615 .long sys_rt_sigprocmask /* 175 */
616 .long sys_rt_sigpending
617 .long sys_rt_sigtimedwait
618 .long sys_rt_sigqueueinfo
619 .long sys_rt_sigsuspend
620 .long sys_pread64 /* 180 */
625 .long sys_capset /* 185 */
626 .long sys_sigaltstack
628 .long sys_ni_syscall /* reserved for streams1 */
629 .long sys_ni_syscall /* reserved for streams2 */
630 .long sys_vfork /* 190 */
634 .long sys_ftruncate64
635 .long sys_stat64 /* 195 */
640 .long sys_getgid /* 200 */
645 .long sys_getgroups /* 205 */
650 .long sys_setresgid /* 210 */
655 .long sys_setfsuid /* 215 */
660 .long sys_getdents64 /* 220 */
662 .long sys_ni_syscall /* reserved for TUX */
665 .long sys_readahead /* 225 */
670 .long sys_lgetxattr /* 230 */
675 .long sys_removexattr /* 235 */
676 .long sys_lremovexattr
677 .long sys_fremovexattr
680 .long sys_futex /* 240 */
681 .long sys_sched_setaffinity
682 .long sys_sched_getaffinity
683 .long sys_ni_syscall /* sys_set_thread_area */
684 .long sys_ni_syscall /* sys_get_thread_area */
685 .long sys_io_setup /* 245 */
687 .long sys_io_getevents
690 .long sys_fadvise64 /* 250 */
693 .long sys_lookup_dcookie
694 .long sys_epoll_create
695 .long sys_epoll_ctl /* 255 */
697 .long sys_remap_file_pages
698 .long sys_set_tid_address
699 .long sys_timer_create
700 .long sys_timer_settime /* 260 */
701 .long sys_timer_gettime
702 .long sys_timer_getoverrun
703 .long sys_timer_delete
704 .long sys_clock_settime
705 .long sys_clock_gettime /* 265 */
706 .long sys_clock_getres
707 .long sys_clock_nanosleep
710 .long sys_tgkill /* 270 */
712 .long sys_fadvise64_64
713 .long sys_ni_syscall /* sys_vserver */
715 .long sys_get_mempolicy /* 275 */
716 .long sys_set_mempolicy
719 .long sys_mq_timedsend
720 .long sys_mq_timedreceive /* 280 */
722 .long sys_mq_getsetattr
725 .long sys_ni_syscall /* 285 */ /* available */
727 .long sys_request_key
730 .long sys_ioprio_set /* 290 */
732 .long sys_inotify_init
733 .long sys_inotify_add_watch
734 .long sys_inotify_rm_watch
735 .long sys_migrate_pages /* 295 */
740 .long sys_futimesat /* 300 */
745 .long sys_symlinkat /* 305 */
750 .long sys_ppoll /* 310 */
752 .long sys_set_robust_list
753 .long sys_get_robust_list
755 .long sys_sync_file_range /* 315 */
760 .long sys_epoll_pwait /* 320 */
763 .long sys_timerfd_create
765 .long sys_fallocate /* 325 */
766 .long sys_timerfd_settime
767 .long sys_timerfd_gettime
770 .long sys_epoll_create1 /* 330 */
773 .long sys_inotify_init1
775 .long sys_pwritev /* 335 */
776 .long sys_rt_tgsigqueueinfo
777 .long sys_perf_event_open
782 nr_syscalls=(.-sys_call_table)/4