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
63 GET_THREAD_INFO a2 # A2 must be set on return from sys_exit()
68 ###############################################################################
72 ###############################################################################
76 mov d0,(REG_ORIG_D0,fp)
80 btst _TIF_SYSCALL_TRACE,(TI_flags,a2)
81 bne syscall_entry_trace
86 mov (sys_call_table,a1),a0
90 # make sure we don't miss an interrupt setting need_resched or
91 # sigpending between sampling and the rti
94 btst _TIF_ALLWORK_MASK,d2
99 ###############################################################################
101 # perform work that needs to be done immediately before resumption and syscall
104 ###############################################################################
109 beq resume_kernel # returning to supervisor mode
111 LOCAL_IRQ_ENABLE # could let syscall_trace_exit() call
113 btst _TIF_SYSCALL_TRACE,d2
116 call syscall_trace_exit[],0 # do_syscall_trace(regs)
121 btst _TIF_NEED_RESCHED,d2
128 # make sure we don't miss an interrupt setting need_resched or
129 # sigpending between sampling and the rti
132 # is there any work to be done other than syscall tracing?
134 btst _TIF_WORK_MASK,d2
138 btst _TIF_NEED_RESCHED,d2
141 # deal with pending signals and notify-resume requests
145 call do_notify_resume[],0
148 # perform syscall entry tracing
153 call syscall_trace_entry[],0 # returns the syscall number to actually use
164 # userspace resumption stub bypassing syscall exit tracing
165 .globl ret_from_exception, ret_from_intr
171 mov (REG_EPSW,fp),d0 # need to deliver signals before
172 # returning to userspace
174 beq resume_kernel # returning to supervisor mode
176 #ifdef CONFIG_PREEMPT
179 mov (TI_preempt_count,a2),d0 # non-zero preempt_count ?
184 btst _TIF_NEED_RESCHED,(TI_flags,a2)
188 cmp EPSW_IM_7,d0 # interrupts off (exception path) ?
190 call preempt_schedule_irq[],0
195 ###############################################################################
197 # IRQ handler entry point
198 # - intended to be entered at multiple priorities
200 ###############################################################################
207 mov d0,(REG_ORIG_D0,fp)
210 call do_IRQ[],0 # do_IRQ(regs)
214 ###############################################################################
216 # Double Fault handler entry point
217 # - note that there will not be a stack, D0/A0 will hold EPSW/PC as were
219 ###############################################################################
227 mov a0,(__df_stack-4) # PC as was
228 mov d0,(__df_stack-8) # EPSW as was
229 mn10300_set_dbfleds # display 'db-f' on the LEDs
231 mov d0,(__df_stack-12) # no ORIG_D0
232 mov sp,a0 # save corrupted SP
233 mov __df_stack-12,sp # emergency supervisor stack
235 mov a0,(REG_A0,fp) # save corrupted SP as A0 (which got
236 # clobbered by the CPU)
238 calls do_double_fault
240 bra double_fault_loop
242 ###############################################################################
244 # Bus Error handler entry point
245 # - handle external (async) bus errors separately
247 ###############################################################################
251 #if defined(CONFIG_ERRATUM_NEED_TO_RELOAD_MMUCTR)
255 mov (BCBERR),d0 # what
256 btst BCBERR_BEMR_DMA,d0 # see if it was an external bus error
257 beq __common_exception_aux # it wasn't
260 mov (BCBEAR),d1 # destination of erroneous access
262 mov (REG_ORIG_D0,fp),d2
265 mov d2,(REG_ORIG_D0,fp)
268 mov fp,(12,sp) # frame pointer
269 call io_bus_error[],0
272 ###############################################################################
274 # NMI exception entry points
276 # This is used by ordinary interrupt channels that have the GxICR_NMI bit set
277 # in addition to the main NMI and Watchdog channels. SMP NMI IPIs use this
280 ###############################################################################
288 mov d0,(sp) # save d0(TBR)
292 cmp CALL_FUNCTION_NMI_IPI,d0
293 bne nmi_not_smp_callfunc # if not call function, jump
295 # function call nmi ipi
296 add 4,sp # no need to store TBR
297 mov GxICR_DETECT,d0 # clear NMI request
298 movbu d0,(GxICR(CALL_FUNCTION_NMI_IPI))
299 movhu (GxICR(CALL_FUNCTION_NMI_IPI)),d0
300 and ~EPSW_NMID,epsw # enable NMI
302 mov (sp),d0 # restore d0
304 call smp_nmi_call_function_interrupt[],0
307 nmi_not_smp_callfunc:
308 #ifdef CONFIG_KERNEL_DEBUGGER
309 cmp DEBUGGER_NMI_IPI,d0
310 bne nmi_not_debugger # if not kernel debugger NMI IPI, jump
312 # kernel debugger NMI IPI
313 add 4,sp # no need to store TBR
314 mov GxICR_DETECT,d0 # clear NMI
315 movbu d0,(GxICR(DEBUGGER_NMI_IPI))
316 movhu (GxICR(DEBUGGER_NMI_IPI)),d0
317 and ~EPSW_NMID,epsw # enable NMI
321 mov fp,d0 # arg 0: stacked register file
322 mov a2,d1 # arg 1: exception number
323 call debugger_nmi_interrupt[],0
327 #endif /* CONFIG_KERNEL_DEBUGGER */
328 mov (sp),d0 # restore TBR to d0
330 #endif /* CONFIG_SMP */
332 bra __common_exception_nonmi
334 ###############################################################################
336 # General exception entry point
338 ###############################################################################
339 ENTRY(__common_exception)
342 #if defined(CONFIG_ERRATUM_NEED_TO_RELOAD_MMUCTR)
347 __common_exception_aux:
349 and ~EPSW_NMID,epsw # turn NMIs back on if not NMI
352 __common_exception_nonmi:
353 and 0x0000FFFF,d0 # turn the exception code into a vector
361 SAVE_ALL # build the stack frame
363 mov (REG_D0,fp),a2 # get the exception number
364 mov (REG_ORIG_D0,fp),d0
367 mov d0,(REG_ORIG_D0,fp)
369 #ifdef CONFIG_GDBSTUB
371 call gdbstub_busy_check[],0
372 and d0,d0 # check return value
374 #else /* CONFIG_SMP */
375 btst 0x01,(gdbstub_busy)
377 #endif /* CONFIG_SMP */
381 call gdbstub_exception[],0 # gdbstub itself caused an exception
384 #endif /* CONFIG_GDBSTUB */
386 mov fp,d0 # arg 0: stacked register file
387 mov a2,d1 # arg 1: exception number
390 mov (exception_table,a2),a2
392 jmp ret_from_exception
394 1: pi # BUG() equivalent
396 ###############################################################################
398 # Exception handler functions table
400 ###############################################################################
402 ENTRY(exception_table)
404 .long uninitialised_exception
408 ###############################################################################
410 # Change an entry in the exception table
411 # - D0 exception code, D1 handler
413 ###############################################################################
414 ENTRY(set_excp_vector)
416 add exception_table,d0
421 ###############################################################################
425 ###############################################################################
427 ENTRY(sys_call_table)
428 .long sys_restart_syscall /* 0 */
433 .long sys_open /* 5 */
438 .long sys_unlink /* 10 */
443 .long sys_chmod /* 15 */
445 .long sys_ni_syscall /* old break syscall holder */
448 .long sys_getpid /* 20 */
453 .long sys_stime /* 25 */
458 .long sys_utime /* 30 */
459 .long sys_ni_syscall /* old stty syscall holder */
460 .long sys_ni_syscall /* old gtty syscall holder */
463 .long sys_ni_syscall /* 35 - old ftime syscall holder */
468 .long sys_rmdir /* 40 */
472 .long sys_ni_syscall /* old prof syscall holder */
473 .long sys_brk /* 45 */
478 .long sys_getegid16 /* 50 */
480 .long sys_umount /* recycled never used phys() */
481 .long sys_ni_syscall /* old lock syscall holder */
483 .long sys_fcntl /* 55 */
484 .long sys_ni_syscall /* old mpx syscall holder */
486 .long sys_ni_syscall /* old ulimit syscall holder */
487 .long sys_ni_syscall /* old sys_olduname */
488 .long sys_umask /* 60 */
493 .long sys_getpgrp /* 65 */
498 .long sys_setreuid16 /* 70 */
502 .long sys_sethostname
503 .long sys_setrlimit /* 75 */
504 .long sys_old_getrlimit
506 .long sys_gettimeofday
507 .long sys_settimeofday
508 .long sys_getgroups16 /* 80 */
509 .long sys_setgroups16
513 .long sys_readlink /* 85 */
517 .long sys_old_readdir
518 .long old_mmap /* 90 */
523 .long sys_fchown16 /* 95 */
524 .long sys_getpriority
525 .long sys_setpriority
526 .long sys_ni_syscall /* old profil syscall holder */
528 .long sys_fstatfs /* 100 */
529 .long sys_ni_syscall /* ioperm */
533 .long sys_getitimer /* 105 */
537 .long sys_ni_syscall /* old sys_uname */
538 .long sys_ni_syscall /* 110 - iopl */
540 .long sys_ni_syscall /* old "idle" system call */
541 .long sys_ni_syscall /* vm86old */
543 .long sys_swapoff /* 115 */
548 .long sys_clone /* 120 */
549 .long sys_setdomainname
551 .long sys_ni_syscall /* modify_ldt */
553 .long sys_mprotect /* 125 */
554 .long sys_sigprocmask
555 .long sys_ni_syscall /* old "create_module" */
556 .long sys_init_module
557 .long sys_delete_module
558 .long sys_ni_syscall /* 130: old "get_kernel_syms" */
563 .long sys_sysfs /* 135 */
564 .long sys_personality
565 .long sys_ni_syscall /* reserved for afs_syscall */
568 .long sys_llseek /* 140 */
573 .long sys_readv /* 145 */
578 .long sys_mlock /* 150 */
582 .long sys_sched_setparam
583 .long sys_sched_getparam /* 155 */
584 .long sys_sched_setscheduler
585 .long sys_sched_getscheduler
586 .long sys_sched_yield
587 .long sys_sched_get_priority_max
588 .long sys_sched_get_priority_min /* 160 */
589 .long sys_sched_rr_get_interval
592 .long sys_setresuid16
593 .long sys_getresuid16 /* 165 */
594 .long sys_ni_syscall /* vm86 */
595 .long sys_ni_syscall /* Old sys_query_module */
597 .long sys_ni_syscall /* was nfsservctl */
598 .long sys_setresgid16 /* 170 */
599 .long sys_getresgid16
601 .long sys_rt_sigreturn
602 .long sys_rt_sigaction
603 .long sys_rt_sigprocmask /* 175 */
604 .long sys_rt_sigpending
605 .long sys_rt_sigtimedwait
606 .long sys_rt_sigqueueinfo
607 .long sys_rt_sigsuspend
608 .long sys_pread64 /* 180 */
613 .long sys_capset /* 185 */
614 .long sys_sigaltstack
616 .long sys_ni_syscall /* reserved for streams1 */
617 .long sys_ni_syscall /* reserved for streams2 */
618 .long sys_vfork /* 190 */
622 .long sys_ftruncate64
623 .long sys_stat64 /* 195 */
628 .long sys_getgid /* 200 */
633 .long sys_getgroups /* 205 */
638 .long sys_setresgid /* 210 */
643 .long sys_setfsuid /* 215 */
648 .long sys_getdents64 /* 220 */
650 .long sys_ni_syscall /* reserved for TUX */
653 .long sys_readahead /* 225 */
658 .long sys_lgetxattr /* 230 */
663 .long sys_removexattr /* 235 */
664 .long sys_lremovexattr
665 .long sys_fremovexattr
668 .long sys_futex /* 240 */
669 .long sys_sched_setaffinity
670 .long sys_sched_getaffinity
671 .long sys_ni_syscall /* sys_set_thread_area */
672 .long sys_ni_syscall /* sys_get_thread_area */
673 .long sys_io_setup /* 245 */
675 .long sys_io_getevents
678 .long sys_fadvise64 /* 250 */
681 .long sys_lookup_dcookie
682 .long sys_epoll_create
683 .long sys_epoll_ctl /* 255 */
685 .long sys_remap_file_pages
686 .long sys_set_tid_address
687 .long sys_timer_create
688 .long sys_timer_settime /* 260 */
689 .long sys_timer_gettime
690 .long sys_timer_getoverrun
691 .long sys_timer_delete
692 .long sys_clock_settime
693 .long sys_clock_gettime /* 265 */
694 .long sys_clock_getres
695 .long sys_clock_nanosleep
698 .long sys_tgkill /* 270 */
700 .long sys_fadvise64_64
701 .long sys_ni_syscall /* sys_vserver */
703 .long sys_get_mempolicy /* 275 */
704 .long sys_set_mempolicy
707 .long sys_mq_timedsend
708 .long sys_mq_timedreceive /* 280 */
710 .long sys_mq_getsetattr
713 .long sys_ni_syscall /* 285 */ /* available */
715 .long sys_request_key
718 .long sys_ioprio_set /* 290 */
720 .long sys_inotify_init
721 .long sys_inotify_add_watch
722 .long sys_inotify_rm_watch
723 .long sys_migrate_pages /* 295 */
728 .long sys_futimesat /* 300 */
733 .long sys_symlinkat /* 305 */
738 .long sys_ppoll /* 310 */
740 .long sys_set_robust_list
741 .long sys_get_robust_list
743 .long sys_sync_file_range /* 315 */
748 .long sys_epoll_pwait /* 320 */
751 .long sys_timerfd_create
753 .long sys_fallocate /* 325 */
754 .long sys_timerfd_settime
755 .long sys_timerfd_gettime
758 .long sys_epoll_create1 /* 330 */
761 .long sys_inotify_init1
763 .long sys_pwritev /* 335 */
764 .long sys_rt_tgsigqueueinfo
765 .long sys_perf_event_open
770 nr_syscalls=(.-sys_call_table)/4