Back to home page

LXR

 
 

    


0001 /*
0002  * Common Low Level Interrupts/Traps/Exceptions(non-TLB) Handling for ARC
0003  * (included from entry-<isa>.S
0004  *
0005  * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
0006  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
0007  *
0008  * This program is free software; you can redistribute it and/or modify
0009  * it under the terms of the GNU General Public License version 2 as
0010  * published by the Free Software Foundation.
0011  */
0012 
0013 /*------------------------------------------------------------------
0014  *    Function                            ABI
0015  *------------------------------------------------------------------
0016  *
0017  *  Arguments                           r0 - r7
0018  *  Caller Saved Registers              r0 - r12
0019  *  Callee Saved Registers              r13- r25
0020  *  Global Pointer (gp)                 r26
0021  *  Frame Pointer (fp)                  r27
0022  *  Stack Pointer (sp)                  r28
0023  *  Branch link register (blink)        r31
0024  *------------------------------------------------------------------
0025  */
0026 
0027 ;################### Special Sys Call Wrappers ##########################
0028 
0029 ENTRY(sys_clone_wrapper)
0030     SAVE_CALLEE_SAVED_USER
0031     bl  @sys_clone
0032     DISCARD_CALLEE_SAVED_USER
0033 
0034     GET_CURR_THR_INFO_FLAGS   r10
0035     btst r10, TIF_SYSCALL_TRACE
0036     bnz  tracesys_exit
0037 
0038     b .Lret_from_system_call
0039 END(sys_clone_wrapper)
0040 
0041 ENTRY(ret_from_fork)
0042     ; when the forked child comes here from the __switch_to function
0043     ; r0 has the last task pointer.
0044     ; put last task in scheduler queue
0045     jl   @schedule_tail
0046 
0047     ld   r9, [sp, PT_status32]
0048     brne r9, 0, 1f
0049 
0050     jl.d [r14]      ; kernel thread entry point
0051     mov  r0, r13        ; (see PF_KTHREAD block in copy_thread)
0052 
0053 1:
0054     ; Return to user space
0055     ; 1. Any forked task (Reach here via BRne above)
0056     ; 2. First ever init task (Reach here via return from JL above)
0057     ;    This is the historic "kernel_execve" use-case, to return to init
0058     ;    user mode, in a round about way since that is always done from
0059     ;    a kernel thread which is executed via JL above but always returns
0060     ;    out whenever kernel_execve (now inline do_fork()) is involved
0061     b    ret_from_exception
0062 END(ret_from_fork)
0063 
0064 ;################### Non TLB Exception Handling #############################
0065 
0066 ; ---------------------------------------------
0067 ; Instruction Error Exception Handler
0068 ; ---------------------------------------------
0069 
0070 ENTRY(instr_service)
0071 
0072     EXCEPTION_PROLOGUE
0073 
0074     lr  r0, [efa]
0075     mov r1, sp
0076 
0077     FAKE_RET_FROM_EXCPN
0078 
0079     bl  do_insterror_or_kprobe
0080     b   ret_from_exception
0081 END(instr_service)
0082 
0083 ; ---------------------------------------------
0084 ; Machine Check Exception Handler
0085 ; ---------------------------------------------
0086 
0087 ENTRY(EV_MachineCheck)
0088 
0089     EXCEPTION_PROLOGUE
0090 
0091     lr  r2, [ecr]
0092     lr  r0, [efa]
0093     mov r1, sp
0094 
0095     lsr     r3, r2, 8
0096     bmsk    r3, r3, 7
0097     brne    r3, ECR_C_MCHK_DUP_TLB, 1f
0098 
0099     bl      do_tlb_overlap_fault
0100     b       ret_from_exception
0101 
0102 1:
0103     ; DEAD END: can't do much, display Regs and HALT
0104     SAVE_CALLEE_SAVED_USER
0105 
0106     GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r10
0107     st  sp, [r10, THREAD_CALLEE_REG]
0108 
0109     j  do_machine_check_fault
0110 
0111 END(EV_MachineCheck)
0112 
0113 ; ---------------------------------------------
0114 ; Privilege Violation Exception Handler
0115 ; ---------------------------------------------
0116 ENTRY(EV_PrivilegeV)
0117 
0118     EXCEPTION_PROLOGUE
0119 
0120     lr  r0, [efa]
0121     mov r1, sp
0122 
0123     FAKE_RET_FROM_EXCPN
0124 
0125     bl  do_privilege_fault
0126     b   ret_from_exception
0127 END(EV_PrivilegeV)
0128 
0129 ; ---------------------------------------------
0130 ; Extension Instruction Exception Handler
0131 ; ---------------------------------------------
0132 ENTRY(EV_Extension)
0133 
0134     EXCEPTION_PROLOGUE
0135 
0136     lr  r0, [efa]
0137     mov r1, sp
0138 
0139     FAKE_RET_FROM_EXCPN
0140 
0141     bl  do_extension_fault
0142     b   ret_from_exception
0143 END(EV_Extension)
0144 
0145 ;################ Trap Handling (Syscall, Breakpoint) ##################
0146 
0147 ; ---------------------------------------------
0148 ; syscall Tracing
0149 ; ---------------------------------------------
0150 tracesys:
0151     ; save EFA in case tracer wants the PC of traced task
0152     ; using ERET won't work since next-PC has already committed
0153     lr  r12, [efa]
0154     GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r11
0155     st  r12, [r11, THREAD_FAULT_ADDR]   ; thread.fault_address
0156 
0157     ; PRE Sys Call Ptrace hook
0158     mov r0, sp          ; pt_regs needed
0159     bl  @syscall_trace_entry
0160 
0161     ; Tracing code now returns the syscall num (orig or modif)
0162     mov r8, r0
0163 
0164     ; Do the Sys Call as we normally would.
0165     ; Validate the Sys Call number
0166     cmp     r8,  NR_syscalls
0167     mov.hi  r0, -ENOSYS
0168     bhi     tracesys_exit
0169 
0170     ; Restore the sys-call args. Mere invocation of the hook abv could have
0171     ; clobbered them (since they are in scratch regs). The tracer could also
0172     ; have deliberately changed the syscall args: r0-r7
0173     ld  r0, [sp, PT_r0]
0174     ld  r1, [sp, PT_r1]
0175     ld  r2, [sp, PT_r2]
0176     ld  r3, [sp, PT_r3]
0177     ld  r4, [sp, PT_r4]
0178     ld  r5, [sp, PT_r5]
0179     ld  r6, [sp, PT_r6]
0180     ld  r7, [sp, PT_r7]
0181     ld.as   r9, [sys_call_table, r8]
0182     jl      [r9]        ; Entry into Sys Call Handler
0183 
0184 tracesys_exit:
0185     st  r0, [sp, PT_r0]     ; sys call return value in pt_regs
0186 
0187     ;POST Sys Call Ptrace Hook
0188     bl  @syscall_trace_exit
0189     b   ret_from_exception ; NOT ret_from_system_call at is saves r0 which
0190     ; we'd done before calling post hook above
0191 
0192 ; ---------------------------------------------
0193 ; Breakpoint TRAP
0194 ; ---------------------------------------------
0195 trap_with_param:
0196 
0197     ; stop_pc info by gdb needs this info
0198     lr  r0, [efa]
0199     mov r1, sp
0200 
0201     ; Now that we have read EFA, it is safe to do "fake" rtie
0202     ;   and get out of CPU exception mode
0203     FAKE_RET_FROM_EXCPN
0204 
0205     ; Save callee regs in case gdb wants to have a look
0206     ; SP will grow up by size of CALLEE Reg-File
0207     ; NOTE: clobbers r12
0208     SAVE_CALLEE_SAVED_USER
0209 
0210     ; save location of saved Callee Regs @ thread_struct->pc
0211     GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r10
0212     st  sp, [r10, THREAD_CALLEE_REG]
0213 
0214     ; Call the trap handler
0215     bl  do_non_swi_trap
0216 
0217     ; unwind stack to discard Callee saved Regs
0218     DISCARD_CALLEE_SAVED_USER
0219 
0220     b   ret_from_exception
0221 
0222 ; ---------------------------------------------
0223 ; syscall TRAP
0224 ; ABI: (r0-r7) upto 8 args, (r8) syscall number
0225 ; ---------------------------------------------
0226 
0227 ENTRY(EV_Trap)
0228 
0229     EXCEPTION_PROLOGUE
0230 
0231     ;============ TRAP 1   :breakpoints
0232     ; Check ECR for trap with arg (PROLOGUE ensures r9 has ECR)
0233     bmsk.f 0, r9, 7
0234     bnz    trap_with_param
0235 
0236     ;============ TRAP  (no param): syscall top level
0237 
0238     ; First return from Exception to pure K mode (Exception/IRQs renabled)
0239     FAKE_RET_FROM_EXCPN
0240 
0241     ; If syscall tracing ongoing, invoke pre-post-hooks
0242     GET_CURR_THR_INFO_FLAGS   r10
0243     btst r10, TIF_SYSCALL_TRACE
0244     bnz tracesys  ; this never comes back
0245 
0246     ;============ Normal syscall case
0247 
0248     ; syscall num shd not exceed the total system calls avail
0249     cmp     r8,  NR_syscalls
0250     mov.hi  r0, -ENOSYS
0251     bhi     .Lret_from_system_call
0252 
0253     ; Offset into the syscall_table and call handler
0254     ld.as   r9,[sys_call_table, r8]
0255     jl      [r9]        ; Entry into Sys Call Handler
0256 
0257 .Lret_from_system_call:
0258 
0259     st  r0, [sp, PT_r0]     ; sys call return value in pt_regs
0260 
0261     ; fall through to ret_from_exception
0262 END(EV_Trap)
0263 
0264 ;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
0265 ;
0266 ; If ret to user mode do we need to handle signals, schedule() et al.
0267 
0268 ENTRY(ret_from_exception)
0269 
0270     ; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
0271     ld  r8, [sp, PT_status32]   ; returning to User/Kernel Mode
0272 
0273     bbit0  r8, STATUS_U_BIT, resume_kernel_mode
0274 
0275     ; Before returning to User mode check-for-and-complete any pending work
0276     ; such as rescheduling/signal-delivery etc.
0277 resume_user_mode_begin:
0278 
0279     ; Disable IRQs to ensures that chk for pending work itself is atomic
0280     ; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
0281     ; interim IRQ).
0282     IRQ_DISABLE r10
0283 
0284     ; Fast Path return to user mode if no pending work
0285     GET_CURR_THR_INFO_FLAGS   r9
0286     and.f  0,  r9, _TIF_WORK_MASK
0287     bz     .Lrestore_regs
0288 
0289     ; --- (Slow Path #1) task preemption ---
0290     bbit0  r9, TIF_NEED_RESCHED, .Lchk_pend_signals
0291     mov    blink, resume_user_mode_begin  ; tail-call to U mode ret chks
0292     j      @schedule    ; BTST+Bnz causes relo error in link
0293 
0294 .Lchk_pend_signals:
0295     IRQ_ENABLE  r10
0296 
0297     ; --- (Slow Path #2) pending signal  ---
0298     mov r0, sp  ; pt_regs for arg to do_signal()/do_notify_resume()
0299 
0300     GET_CURR_THR_INFO_FLAGS   r9
0301     bbit0  r9, TIF_SIGPENDING, .Lchk_notify_resume
0302 
0303     ; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
0304     ; in pt_reg since the "C" ABI (kernel code) will automatically
0305     ; save/restore callee-saved regs.
0306     ;
0307     ; However, here we need to explicitly save callee regs because
0308     ; (i)  If this signal causes coredump - full regfile needed
0309     ; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
0310     ;      tracer might call PEEKUSR(CALLEE reg)
0311     ;
0312     ; NOTE: SP will grow up by size of CALLEE Reg-File
0313     SAVE_CALLEE_SAVED_USER      ; clobbers r12
0314 
0315     ; save location of saved Callee Regs @ thread_struct->callee
0316     GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r10
0317     st  sp, [r10, THREAD_CALLEE_REG]
0318 
0319     bl  @do_signal
0320 
0321     ; Ideally we want to discard the Callee reg above, however if this was
0322     ; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
0323     RESTORE_CALLEE_SAVED_USER
0324 
0325     b      resume_user_mode_begin   ; loop back to start of U mode ret
0326 
0327     ; --- (Slow Path #3) notify_resume ---
0328 .Lchk_notify_resume:
0329     btst   r9, TIF_NOTIFY_RESUME
0330     blnz   @do_notify_resume
0331     b      resume_user_mode_begin   ; unconditionally back to U mode ret chks
0332                     ; for single exit point from this block
0333 
0334 resume_kernel_mode:
0335 
0336     ; Disable Interrupts from this point on
0337     ; CONFIG_PREEMPT: This is a must for preempt_schedule_irq()
0338     ; !CONFIG_PREEMPT: To ensure restore_regs is intr safe
0339     IRQ_DISABLE r9
0340 
0341 #ifdef CONFIG_PREEMPT
0342 
0343     ; Can't preempt if preemption disabled
0344     GET_CURR_THR_INFO_FROM_SP   r10
0345     ld  r8, [r10, THREAD_INFO_PREEMPT_COUNT]
0346     brne  r8, 0, .Lrestore_regs
0347 
0348     ; check if this task's NEED_RESCHED flag set
0349     ld  r9, [r10, THREAD_INFO_FLAGS]
0350     bbit0  r9, TIF_NEED_RESCHED, .Lrestore_regs
0351 
0352     ; Invoke PREEMPTION
0353     jl      preempt_schedule_irq
0354 
0355     ; preempt_schedule_irq() always returns with IRQ disabled
0356 #endif
0357 
0358     b   .Lrestore_regs
0359 
0360 ##### DONT ADD CODE HERE - .Lrestore_regs actually follows in entry-<isa>.S
0361