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/system.h>
19 #include <asm/irqflags.h>
20 #include <asm/thread_info.h>
21 #include <asm/intctl-regs.h>
22 #include <asm/busctl-regs.h>
23 #include <asm/timer-regs.h>
24 #include <unit/leds.h>
26 #include <asm/pgtable.h>
27 #include <asm/errno.h>
28 #include <asm/asm-offsets.h>
29 #include <asm/frame.inc>
31 #if defined(CONFIG_SMP) && defined(CONFIG_GDBSTUB)
32 #include <asm/gdb-stub.h>
33 #endif /* CONFIG_SMP && CONFIG_GDBSTUB */
36 #define preempt_stop LOCAL_IRQ_DISABLE
39 #define resume_kernel restore_all
44 ###############################################################################
46 # the return path for a forked child
47 # - on entry, D0 holds the address of the previous task to run
49 ###############################################################################
51 call schedule_tail[],0
54 # return 0 to indicate child process
59 ###############################################################################
63 ###############################################################################
67 mov d0,(REG_ORIG_D0,fp)
71 btst _TIF_SYSCALL_TRACE,(TI_flags,a2)
72 bne syscall_entry_trace
77 mov (sys_call_table,a1),a0
81 # make sure we don't miss an interrupt setting need_resched or
82 # sigpending between sampling and the rti
85 btst _TIF_ALLWORK_MASK,d2
90 ###############################################################################
92 # perform work that needs to be done immediately before resumption and syscall
95 ###############################################################################
98 btst _TIF_SYSCALL_TRACE,d2
100 LOCAL_IRQ_ENABLE # could let syscall_trace_exit() call
103 call syscall_trace_exit[],0 # do_syscall_trace(regs)
108 btst _TIF_NEED_RESCHED,d2
114 # make sure we don't miss an interrupt setting need_resched or
115 # sigpending between sampling and the rti
118 # is there any work to be done other than syscall tracing?
120 btst _TIF_WORK_MASK,d2
122 btst _TIF_NEED_RESCHED,d2
125 # deal with pending signals and notify-resume requests
129 call do_notify_resume[],0
132 # perform syscall entry tracing
137 call syscall_trace_entry[],0 # returns the syscall number to actually use
148 # userspace resumption stub bypassing syscall exit tracing
149 .globl ret_from_exception, ret_from_intr
155 mov (REG_EPSW,fp),d0 # need to deliver signals before
156 # returning to userspace
158 beq resume_kernel # returning to supervisor mode
160 ENTRY(resume_userspace)
161 # make sure we don't miss an interrupt setting need_resched or
162 # sigpending between sampling and the rti
165 # is there any work to be done on int/exception return?
167 btst _TIF_WORK_MASK,d2
171 #ifdef CONFIG_PREEMPT
174 mov (TI_preempt_count,a2),d0 # non-zero preempt_count ?
179 btst _TIF_NEED_RESCHED,(TI_flags,a2)
183 cmp EPSW_IM_7,d0 # interrupts off (exception path) ?
185 call preempt_schedule_irq[],0
190 ###############################################################################
192 # IRQ handler entry point
193 # - intended to be entered at multiple priorities
195 ###############################################################################
202 mov d0,(REG_ORIG_D0,fp)
205 call do_IRQ[],0 # do_IRQ(regs)
209 ###############################################################################
211 # Double Fault handler entry point
212 # - note that there will not be a stack, D0/A0 will hold EPSW/PC as were
214 ###############################################################################
222 mov a0,(__df_stack-4) # PC as was
223 mov d0,(__df_stack-8) # EPSW as was
224 mn10300_set_dbfleds # display 'db-f' on the LEDs
226 mov d0,(__df_stack-12) # no ORIG_D0
227 mov sp,a0 # save corrupted SP
228 mov __df_stack-12,sp # emergency supervisor stack
230 mov a0,(REG_A0,fp) # save corrupted SP as A0 (which got
231 # clobbered by the CPU)
233 calls do_double_fault
235 bra double_fault_loop
237 ###############################################################################
239 # Bus Error handler entry point
240 # - handle external (async) bus errors separately
242 ###############################################################################
246 #if defined(CONFIG_ERRATUM_NEED_TO_RELOAD_MMUCTR)
250 mov (BCBERR),d0 # what
251 btst BCBERR_BEMR_DMA,d0 # see if it was an external bus error
252 beq __common_exception_aux # it wasn't
255 mov (BCBEAR),d1 # destination of erroneous access
257 mov (REG_ORIG_D0,fp),d2
260 mov d2,(REG_ORIG_D0,fp)
263 mov fp,(12,sp) # frame pointer
264 call io_bus_error[],0
267 ###############################################################################
269 # Miscellaneous exception entry points
271 ###############################################################################
279 mov d0,(sp) # save d0(TBR)
283 cmp CALL_FUNCTION_NMI_IPI,d0
284 bne 5f # if not call function, jump
286 # function call nmi ipi
287 add 4,sp # no need to store TBR
288 mov GxICR_DETECT,d0 # clear NMI request
289 movbu d0,(GxICR(CALL_FUNCTION_NMI_IPI))
290 movhu (GxICR(CALL_FUNCTION_NMI_IPI)),d0
291 and ~EPSW_NMID,epsw # enable NMI
293 mov (sp),d0 # restore d0
295 call smp_nmi_call_function_interrupt[],0
299 #ifdef CONFIG_GDBSTUB
301 bne 3f # if not gdb nmi ipi, jump
304 add 4,sp # no need to store TBR
305 mov GxICR_DETECT,d0 # clear NMI
306 movbu d0,(GxICR(GDB_NMI_IPI))
307 movhu (GxICR(GDB_NMI_IPI)),d0
308 and ~EPSW_NMID,epsw # enable NMI
309 #ifdef CONFIG_MN10300_CACHE_ENABLED
310 mov (gdbstub_nmi_opr_type),d0
311 cmp GDBSTUB_NMI_CACHE_PURGE,d0
312 bne 4f # if not gdb cache purge, jump
314 # gdb cache purge nmi ipi
321 call gdbstub_local_purge_cache[],0
325 mov gdbstub_nmi_cpumask,a0
337 #endif /* CONFIG_MN10300_CACHE_ENABLED */
341 call gdbstub_nmi_wait[],0
344 #endif /* CONFIG_GDBSTUB */
345 mov (sp),d0 # restore TBR to d0
347 #endif /* CONFIG_SMP */
349 bra __common_exception_nonmi
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 */
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
781 nr_syscalls=(.-sys_call_table)/4