]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - arch/arc/kernel/entry.S
Merge branch 'stable' of git://git.kernel.org/pub/scm/linux/kernel/git/cmetcalf/linux...
[karo-tx-linux.git] / arch / arc / kernel / entry.S
index d625b77c14bd548bc5eb393a2193761f80efb83c..91eeab81f52d3d66a408a215f06b4ff19022d364 100644 (file)
@@ -7,6 +7,16 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  *
+ * vineetg: May 2011
+ *  -Userspace unaligned access emulation
+ *
+ * vineetg: Feb 2011 (ptrace low level code fixes)
+ *  -traced syscall return code (r0) was not saved into pt_regs for restoring
+ *   into user reg-file when traded task rets to user space.
+ *  -syscalls needing arch-wrappers (mainly for passing sp as pt_regs)
+ *   were not invoking post-syscall trace hook (jumping directly into
+ *   ret_from_system_call)
+ *
  * vineetg: Nov 2010:
  *  -Vector table jumps (@8 bytes) converted into branches (@4 bytes)
  *  -To maintain the slot size of 8 bytes/vector, added nop, which is
@@ -24,6 +34,8 @@
  *   exception. Thus FAKE RTIE needed in low level Priv-Violation handler.
  *   Instr Error could also cause similar scenario, so same there as well.
  *
+ * Vineetg: March 2009 (Supporting 2 levels of Interrupts)
+ *
  * Vineetg: Aug 28th 2008: Bug #94984
  *  -Zero Overhead Loop Context shd be cleared when entering IRQ/EXcp/Trap
  *   Normally CPU does this automatically, however when doing FAKE rtie,
@@ -32,6 +44,9 @@
  *   was being "CLEARED" rather then "SET". Since it is Loop INHIBIT Bit,
  *   setting it and not clearing it clears ZOL context
  *
+ * Vineetg: May 16th, 2008
+ *  - r25 now contains the Current Task when in kernel
+ *
  * Vineetg: Dec 22, 2007
  *    Minor Surgery of Low Level ISR to make it SMP safe
  *    - MMU_SCRATCH0 Reg used for freeing up r9 in Level 1 ISR
@@ -86,13 +101,25 @@ VECTOR   mem_service             ; 0x8, Mem exception   (0x1)
 VECTOR   instr_service           ; 0x10, Instrn Error   (0x2)
 
 ; ******************** Device ISRs **********************
+#ifdef CONFIG_ARC_IRQ3_LV2
+VECTOR   handle_interrupt_level2
+#else
 VECTOR   handle_interrupt_level1
+#endif
 
 VECTOR   handle_interrupt_level1
 
+#ifdef CONFIG_ARC_IRQ5_LV2
+VECTOR   handle_interrupt_level2
+#else
 VECTOR   handle_interrupt_level1
+#endif
 
+#ifdef CONFIG_ARC_IRQ6_LV2
+VECTOR   handle_interrupt_level2
+#else
 VECTOR   handle_interrupt_level1
+#endif
 
 .rept   25
 VECTOR   handle_interrupt_level1 ; Other devices
@@ -122,13 +149,24 @@ VECTOR   reserved                ; Reserved Exceptions
 
 ;##################### Scratch Mem for IRQ stack switching #############
 
-       .section .data          ; NOT .global
+ARCFP_DATA int1_saved_reg
        .align 32
        .type   int1_saved_reg, @object
        .size   int1_saved_reg, 4
 int1_saved_reg:
        .zero 4
 
+/* Each Interrupt level needs it's own scratch */
+#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
+
+ARCFP_DATA int2_saved_reg
+       .type   int2_saved_reg, @object
+       .size   int2_saved_reg, 4
+int2_saved_reg:
+       .zero 4
+
+#endif
+
 ; ---------------------------------------------
        .section .text, "ax",@progbits
 
@@ -142,13 +180,66 @@ reserved:         ; processor restart
 
 ;##################### Interrupt Handling ##############################
 
+#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
+; ---------------------------------------------
+;  Level 2 ISR: Can interrupt a Level 1 ISR
+; ---------------------------------------------
+ARC_ENTRY handle_interrupt_level2
+
+       ; TODO-vineetg for SMP this wont work
+       ; free up r9 as scratchpad
+       st  r9, [@int2_saved_reg]
+
+       ;Which mode (user/kernel) was the system in when intr occured
+       lr  r9, [status32_l2]
+
+       SWITCH_TO_KERNEL_STK
+       SAVE_ALL_INT2
+
+       ;------------------------------------------------------
+       ; if L2 IRQ interrupted a L1 ISR, disable preemption
+       ;------------------------------------------------------
+
+       ld r9, [sp, PT_status32]        ; get statu32_l2 (saved in pt_regs)
+       bbit0 r9, STATUS_A1_BIT, 1f     ; L1 not active when L2 IRQ, so normal
+
+       ; A1 is set in status32_l2
+       ; bump thread_info->preempt_count (Disable preemption)
+       GET_CURR_THR_INFO_FROM_SP   r10
+       ld      r9, [r10, THREAD_INFO_PREEMPT_COUNT]
+       add     r9, r9, 1
+       st      r9, [r10, THREAD_INFO_PREEMPT_COUNT]
+
+1:
+       ;------------------------------------------------------
+       ; setup params for Linux common ISR and invoke it
+       ;------------------------------------------------------
+       lr  r0, [icause2]
+       and r0, r0, 0x1f
+
+       bl.d  @arch_do_IRQ
+       mov r1, sp
+
+       mov r8,0x2
+       sr r8, [AUX_IRQ_LV12]       ; clear bit in Sticky Status Reg
+
+       b   ret_from_exception
+
+ARC_EXIT handle_interrupt_level2
+
+#endif
+
 ; ---------------------------------------------
 ;  Level 1 ISR
 ; ---------------------------------------------
 ARC_ENTRY handle_interrupt_level1
 
        /* free up r9 as scratchpad */
+#ifdef CONFIG_SMP
+       sr  r9, [ARC_REG_SCRATCH_DATA0]
+#else
        st   r9, [@int1_saved_reg]
+#endif
 
        ;Which mode (user/kernel) was the system in when intr occured
        lr  r9, [status32_l1]
@@ -299,7 +390,17 @@ ARC_ENTRY EV_TLBProtV
        mov r1, r4              ; faulting address
        mov r2, sp              ; pt_regs
 
+#ifdef  CONFIG_ARC_MISALIGN_ACCESS
+       SAVE_CALLEE_SAVED_USER
+       mov r3, sp              ; callee_regs
+#endif
+
        bl  do_misaligned_access
+
+#ifdef  CONFIG_ARC_MISALIGN_ACCESS
+       DISCARD_CALLEE_SAVED_USER
+#endif
+
        b   ret_from_exception
 
 ARC_EXIT EV_TLBProtV
@@ -344,14 +445,58 @@ ARC_ENTRY EV_Extension
        b   ret_from_exception
 ARC_EXIT EV_Extension
 
+;######################### System Call Tracing #########################
+
+tracesys:
+       ; save EFA in case tracer wants the PC of traced task
+       ; using ERET won't work since next-PC has already committed
+       lr  r12, [efa]
+       GET_CURR_TASK_FIELD_PTR   TASK_THREAD, r11
+       st  r12, [r11, THREAD_FAULT_ADDR]       ; thread.fault_address
+
+       ; PRE Sys Call Ptrace hook
+       mov r0, sp                      ; pt_regs needed
+       bl  @syscall_trace_entry
+
+       ; Tracing code now returns the syscall num (orig or modif)
+       mov r8, r0
+
+       ; Do the Sys Call as we normally would.
+       ; Validate the Sys Call number
+       cmp     r8,  NR_syscalls
+       mov.hi  r0, -ENOSYS
+       bhi     tracesys_exit
+
+       ; Restore the sys-call args. Mere invocation of the hook abv could have
+       ; clobbered them (since they are in scratch regs). The tracer could also
+       ; have deliberately changed the syscall args: r0-r7
+       ld  r0, [sp, PT_r0]
+       ld  r1, [sp, PT_r1]
+       ld  r2, [sp, PT_r2]
+       ld  r3, [sp, PT_r3]
+       ld  r4, [sp, PT_r4]
+       ld  r5, [sp, PT_r5]
+       ld  r6, [sp, PT_r6]
+       ld  r7, [sp, PT_r7]
+       ld.as   r9, [sys_call_table, r8]
+       jl      [r9]        ; Entry into Sys Call Handler
+
+tracesys_exit:
+       st  r0, [sp, PT_r0]     ; sys call return value in pt_regs
+
+       ;POST Sys Call Ptrace Hook
+       bl  @syscall_trace_exit
+       b   ret_from_exception ; NOT ret_from_system_call at is saves r0 which
+       ; we'd done before calling post hook above
+
 ;################### Break Point TRAP ##########################
 
        ; ======= (5b) Trap is due to Break-Point =========
 
 trap_with_param:
 
-       ;make sure orig_r8 is a positive value
-       st  NR_syscalls + 2, [sp, PT_orig_r8]
+       ; stop_pc info by gdb needs this info
+       stw orig_r8_IS_BRKPT, [sp, PT_orig_r8]
 
        mov r0, r12
        lr  r1, [efa]
@@ -409,6 +554,11 @@ ARC_ENTRY EV_Trap
        ; Before doing anything, return from CPU Exception Mode
        FAKE_RET_FROM_EXCPN r11
 
+       ; If syscall tracing ongoing, invoke pre-pos-hooks
+       GET_CURR_THR_INFO_FLAGS   r10
+       btst r10, TIF_SYSCALL_TRACE
+       bnz tracesys  ; this never comes back
+
        ;============ This is normal System Call case ==========
        ; Sys-call num shd not exceed the total system calls avail
        cmp     r8,  NR_syscalls
@@ -535,6 +685,17 @@ restore_regs :
        ; XXX can this be optimised out
        IRQ_DISABLE_SAVE    r9, r10     ;@r10 has prisitine (pre-disable) copy
 
+#ifdef CONFIG_ARC_CURR_IN_REG
+       ; Restore User R25
+       ; Earlier this used to be only for returning to user mode
+       ; However with 2 levels of IRQ this can also happen even if
+       ; in kernel mode
+       ld r9, [sp, PT_sp]
+       brhs r9, VMALLOC_START, 8f
+       RESTORE_USER_R25
+8:
+#endif
+
        ; Restore REG File. In case multiple Events outstanding,
        ; use the same priorty as rtie: EXCPN, L2 IRQ, L1 IRQ, None
        ; Note that we use realtime STATUS32 (not pt_regs->status32) to
@@ -549,6 +710,49 @@ restore_regs :
 
 not_exception:
 
+#ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
+
+       bbit0  r10, STATUS_A2_BIT, not_level2_interrupt
+
+       ;------------------------------------------------------------------
+       ; if L2 IRQ interrupted a L1 ISR,  we'd disbaled preemption earlier
+       ; so that sched doesnt move to new task, causing L1 to be delayed
+       ; undeterministically. Now that we've achieved that, lets reset
+       ; things to what they were, before returning from L2 context
+       ;----------------------------------------------------------------
+
+       ldw  r9, [sp, PT_orig_r8]      ; get orig_r8 to make sure it is
+       brne r9, orig_r8_IS_IRQ2, 149f ; infact a L2 ISR ret path
+
+       ld r9, [sp, PT_status32]       ; get statu32_l2 (saved in pt_regs)
+       bbit0 r9, STATUS_A1_BIT, 149f  ; L1 not active when L2 IRQ, so normal
+
+       ; A1 is set in status32_l2
+       ; decrement thread_info->preempt_count (re-enable preemption)
+       GET_CURR_THR_INFO_FROM_SP   r10
+       ld      r9, [r10, THREAD_INFO_PREEMPT_COUNT]
+
+       ; paranoid check, given A1 was active when A2 happened, preempt count
+       ; must not be 0 beccause we would have incremented it.
+       ; If this does happen we simply HALT as it means a BUG !!!
+       cmp     r9, 0
+       bnz     2f
+       flag 1
+
+2:
+       sub     r9, r9, 1
+       st      r9, [r10, THREAD_INFO_PREEMPT_COUNT]
+
+149:
+       ;return from level 2
+       RESTORE_ALL_INT2
+debug_marker_l2:
+       rtie
+
+not_level2_interrupt:
+
+#endif
+
        bbit0  r10, STATUS_A1_BIT, not_level1_interrupt
 
        ;return from level 1
@@ -588,27 +792,23 @@ ARC_EXIT ret_from_fork
 
 ;################### Special Sys Call Wrappers ##########################
 
-; TBD: call do_fork directly from here
-ARC_ENTRY sys_fork_wrapper
-       SAVE_CALLEE_SAVED_USER
-       bl  @sys_fork
-       DISCARD_CALLEE_SAVED_USER
-
-       b ret_from_system_call
-ARC_EXIT sys_fork_wrapper
-
-ARC_ENTRY sys_vfork_wrapper
-       SAVE_CALLEE_SAVED_USER
-       bl  @sys_vfork
-       DISCARD_CALLEE_SAVED_USER
-
-       b ret_from_system_call
-ARC_EXIT sys_vfork_wrapper
-
 ARC_ENTRY sys_clone_wrapper
        SAVE_CALLEE_SAVED_USER
        bl  @sys_clone
        DISCARD_CALLEE_SAVED_USER
 
+       GET_CURR_THR_INFO_FLAGS   r10
+       btst r10, TIF_SYSCALL_TRACE
+       bnz  tracesys_exit
+
        b ret_from_system_call
 ARC_EXIT sys_clone_wrapper
+
+#ifdef CONFIG_ARC_DW2_UNWIND
+; Workaround for bug 94179 (STAR ):
+; Despite -fasynchronous-unwind-tables, linker is not making dwarf2 unwinder
+; section (.debug_frame) as loadable. So we force it here.
+; This also fixes STAR 9000487933 where the prev-workaround (objcopy --setflag)
+; would not work after a clean build due to kernel build system dependencies.
+.section .debug_frame, "wa",@progbits
+#endif