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 bne resume_userspace # returning to userspace
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
197 ###############################################################################
199 # IRQ handler entry point
200 # - intended to be entered at multiple priorities
202 ###############################################################################
209 mov d0,(REG_ORIG_D0,fp)
212 call do_IRQ[],0 # do_IRQ(regs)
216 ###############################################################################
218 # Double Fault handler entry point
219 # - note that there will not be a stack, D0/A0 will hold EPSW/PC as were
221 ###############################################################################
229 mov a0,(__df_stack-4) # PC as was
230 mov d0,(__df_stack-8) # EPSW as was
231 mn10300_set_dbfleds # display 'db-f' on the LEDs
233 mov d0,(__df_stack-12) # no ORIG_D0
234 mov sp,a0 # save corrupted SP
235 mov __df_stack-12,sp # emergency supervisor stack
237 mov a0,(REG_A0,fp) # save corrupted SP as A0 (which got
238 # clobbered by the CPU)
240 calls do_double_fault
242 bra double_fault_loop
244 ###############################################################################
246 # Bus Error handler entry point
247 # - handle external (async) bus errors separately
249 ###############################################################################
253 #if defined(CONFIG_ERRATUM_NEED_TO_RELOAD_MMUCTR)
257 mov (BCBERR),d0 # what
258 btst BCBERR_BEMR_DMA,d0 # see if it was an external bus error
259 beq __common_exception_aux # it wasn't
262 mov (BCBEAR),d1 # destination of erroneous access
264 mov (REG_ORIG_D0,fp),d2
267 mov d2,(REG_ORIG_D0,fp)
270 mov fp,(12,sp) # frame pointer
271 call io_bus_error[],0
274 ###############################################################################
276 # NMI exception entry points
278 # This is used by ordinary interrupt channels that have the GxICR_NMI bit set
279 # in addition to the main NMI and Watchdog channels. SMP NMI IPIs use this
282 ###############################################################################
290 mov d0,(sp) # save d0(TBR)
294 cmp CALL_FUNCTION_NMI_IPI,d0
295 bne nmi_not_smp_callfunc # if not call function, jump
297 # function call nmi ipi
298 add 4,sp # no need to store TBR
299 mov GxICR_DETECT,d0 # clear NMI request
300 movbu d0,(GxICR(CALL_FUNCTION_NMI_IPI))
301 movhu (GxICR(CALL_FUNCTION_NMI_IPI)),d0
302 and ~EPSW_NMID,epsw # enable NMI
304 mov (sp),d0 # restore d0
306 call smp_nmi_call_function_interrupt[],0
309 nmi_not_smp_callfunc:
310 #ifdef CONFIG_KERNEL_DEBUGGER
311 cmp DEBUGGER_NMI_IPI,d0
312 bne nmi_not_debugger # if not kernel debugger NMI IPI, jump
314 # kernel debugger NMI IPI
315 add 4,sp # no need to store TBR
316 mov GxICR_DETECT,d0 # clear NMI
317 movbu d0,(GxICR(DEBUGGER_NMI_IPI))
318 movhu (GxICR(DEBUGGER_NMI_IPI)),d0
319 and ~EPSW_NMID,epsw # enable NMI
323 mov fp,d0 # arg 0: stacked register file
324 mov a2,d1 # arg 1: exception number
325 call debugger_nmi_interrupt[],0
329 #endif /* CONFIG_KERNEL_DEBUGGER */
330 mov (sp),d0 # restore TBR to d0
332 #endif /* CONFIG_SMP */
334 bra __common_exception_nonmi
336 ###############################################################################
338 # General exception entry point
340 ###############################################################################
341 ENTRY(__common_exception)
344 #if defined(CONFIG_ERRATUM_NEED_TO_RELOAD_MMUCTR)
349 __common_exception_aux:
351 and ~EPSW_NMID,epsw # turn NMIs back on if not NMI
354 __common_exception_nonmi:
355 and 0x0000FFFF,d0 # turn the exception code into a vector
363 SAVE_ALL # build the stack frame
365 mov (REG_D0,fp),a2 # get the exception number
366 mov (REG_ORIG_D0,fp),d0
369 mov d0,(REG_ORIG_D0,fp)
371 #ifdef CONFIG_GDBSTUB
373 call gdbstub_busy_check[],0
374 and d0,d0 # check return value
376 #else /* CONFIG_SMP */
377 btst 0x01,(gdbstub_busy)
379 #endif /* CONFIG_SMP */
383 call gdbstub_exception[],0 # gdbstub itself caused an exception
386 #endif /* CONFIG_GDBSTUB */
388 mov fp,d0 # arg 0: stacked register file
389 mov a2,d1 # arg 1: exception number
392 mov (exception_table,a2),a2
394 jmp ret_from_exception
396 1: pi # BUG() equivalent
398 ###############################################################################
400 # Exception handler functions table
402 ###############################################################################
404 ENTRY(exception_table)
406 .long uninitialised_exception
410 ###############################################################################
412 # Change an entry in the exception table
413 # - D0 exception code, D1 handler
415 ###############################################################################
416 ENTRY(set_excp_vector)
418 add exception_table,d0
423 ###############################################################################
427 ###############################################################################
429 ENTRY(sys_call_table)
430 .long sys_restart_syscall /* 0 */
435 .long sys_open /* 5 */
440 .long sys_unlink /* 10 */
445 .long sys_chmod /* 15 */
447 .long sys_ni_syscall /* old break syscall holder */
450 .long sys_getpid /* 20 */
455 .long sys_stime /* 25 */
460 .long sys_utime /* 30 */
461 .long sys_ni_syscall /* old stty syscall holder */
462 .long sys_ni_syscall /* old gtty syscall holder */
465 .long sys_ni_syscall /* 35 - old ftime syscall holder */
470 .long sys_rmdir /* 40 */
474 .long sys_ni_syscall /* old prof syscall holder */
475 .long sys_brk /* 45 */
480 .long sys_getegid16 /* 50 */
482 .long sys_umount /* recycled never used phys() */
483 .long sys_ni_syscall /* old lock syscall holder */
485 .long sys_fcntl /* 55 */
486 .long sys_ni_syscall /* old mpx syscall holder */
488 .long sys_ni_syscall /* old ulimit syscall holder */
489 .long sys_ni_syscall /* old sys_olduname */
490 .long sys_umask /* 60 */
495 .long sys_getpgrp /* 65 */
500 .long sys_setreuid16 /* 70 */
504 .long sys_sethostname
505 .long sys_setrlimit /* 75 */
506 .long sys_old_getrlimit
508 .long sys_gettimeofday
509 .long sys_settimeofday
510 .long sys_getgroups16 /* 80 */
511 .long sys_setgroups16
515 .long sys_readlink /* 85 */
519 .long sys_old_readdir
520 .long old_mmap /* 90 */
525 .long sys_fchown16 /* 95 */
526 .long sys_getpriority
527 .long sys_setpriority
528 .long sys_ni_syscall /* old profil syscall holder */
530 .long sys_fstatfs /* 100 */
531 .long sys_ni_syscall /* ioperm */
535 .long sys_getitimer /* 105 */
539 .long sys_ni_syscall /* old sys_uname */
540 .long sys_ni_syscall /* 110 - iopl */
542 .long sys_ni_syscall /* old "idle" system call */
543 .long sys_ni_syscall /* vm86old */
545 .long sys_swapoff /* 115 */
550 .long sys_clone /* 120 */
551 .long sys_setdomainname
553 .long sys_ni_syscall /* modify_ldt */
555 .long sys_mprotect /* 125 */
556 .long sys_sigprocmask
557 .long sys_ni_syscall /* old "create_module" */
558 .long sys_init_module
559 .long sys_delete_module
560 .long sys_ni_syscall /* 130: old "get_kernel_syms" */
565 .long sys_sysfs /* 135 */
566 .long sys_personality
567 .long sys_ni_syscall /* reserved for afs_syscall */
570 .long sys_llseek /* 140 */
575 .long sys_readv /* 145 */
580 .long sys_mlock /* 150 */
584 .long sys_sched_setparam
585 .long sys_sched_getparam /* 155 */
586 .long sys_sched_setscheduler
587 .long sys_sched_getscheduler
588 .long sys_sched_yield
589 .long sys_sched_get_priority_max
590 .long sys_sched_get_priority_min /* 160 */
591 .long sys_sched_rr_get_interval
594 .long sys_setresuid16
595 .long sys_getresuid16 /* 165 */
596 .long sys_ni_syscall /* vm86 */
597 .long sys_ni_syscall /* Old sys_query_module */
599 .long sys_ni_syscall /* was nfsservctl */
600 .long sys_setresgid16 /* 170 */
601 .long sys_getresgid16
603 .long sys_rt_sigreturn
604 .long sys_rt_sigaction
605 .long sys_rt_sigprocmask /* 175 */
606 .long sys_rt_sigpending
607 .long sys_rt_sigtimedwait
608 .long sys_rt_sigqueueinfo
609 .long sys_rt_sigsuspend
610 .long sys_pread64 /* 180 */
615 .long sys_capset /* 185 */
616 .long sys_sigaltstack
618 .long sys_ni_syscall /* reserved for streams1 */
619 .long sys_ni_syscall /* reserved for streams2 */
620 .long sys_vfork /* 190 */
624 .long sys_ftruncate64
625 .long sys_stat64 /* 195 */
630 .long sys_getgid /* 200 */
635 .long sys_getgroups /* 205 */
640 .long sys_setresgid /* 210 */
645 .long sys_setfsuid /* 215 */
650 .long sys_getdents64 /* 220 */
652 .long sys_ni_syscall /* reserved for TUX */
655 .long sys_readahead /* 225 */
660 .long sys_lgetxattr /* 230 */
665 .long sys_removexattr /* 235 */
666 .long sys_lremovexattr
667 .long sys_fremovexattr
670 .long sys_futex /* 240 */
671 .long sys_sched_setaffinity
672 .long sys_sched_getaffinity
673 .long sys_ni_syscall /* sys_set_thread_area */
674 .long sys_ni_syscall /* sys_get_thread_area */
675 .long sys_io_setup /* 245 */
677 .long sys_io_getevents
680 .long sys_fadvise64 /* 250 */
683 .long sys_lookup_dcookie
684 .long sys_epoll_create
685 .long sys_epoll_ctl /* 255 */
687 .long sys_remap_file_pages
688 .long sys_set_tid_address
689 .long sys_timer_create
690 .long sys_timer_settime /* 260 */
691 .long sys_timer_gettime
692 .long sys_timer_getoverrun
693 .long sys_timer_delete
694 .long sys_clock_settime
695 .long sys_clock_gettime /* 265 */
696 .long sys_clock_getres
697 .long sys_clock_nanosleep
700 .long sys_tgkill /* 270 */
702 .long sys_fadvise64_64
703 .long sys_ni_syscall /* sys_vserver */
705 .long sys_get_mempolicy /* 275 */
706 .long sys_set_mempolicy
709 .long sys_mq_timedsend
710 .long sys_mq_timedreceive /* 280 */
712 .long sys_mq_getsetattr
715 .long sys_ni_syscall /* 285 */ /* available */
717 .long sys_request_key
720 .long sys_ioprio_set /* 290 */
722 .long sys_inotify_init
723 .long sys_inotify_add_watch
724 .long sys_inotify_rm_watch
725 .long sys_migrate_pages /* 295 */
730 .long sys_futimesat /* 300 */
735 .long sys_symlinkat /* 305 */
740 .long sys_ppoll /* 310 */
742 .long sys_set_robust_list
743 .long sys_get_robust_list
745 .long sys_sync_file_range /* 315 */
750 .long sys_epoll_pwait /* 320 */
753 .long sys_timerfd_create
755 .long sys_fallocate /* 325 */
756 .long sys_timerfd_settime
757 .long sys_timerfd_gettime
760 .long sys_epoll_create1 /* 330 */
763 .long sys_inotify_init1
765 .long sys_pwritev /* 335 */
766 .long sys_rt_tgsigqueueinfo
767 .long sys_perf_event_open
772 nr_syscalls=(.-sys_call_table)/4