/* * linux/arch/nios2/kernel/entry.S * * Copyright (C) 2013-2014 Altera Corporation * Copyright (C) 2009, Wind River Systems Inc * * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com * * Copyright (C) 1999-2002, Greg Ungerer (gerg@snapgear.com) * Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>, * Kenneth Albanowski <kjahds@kjahds.com>, * Copyright (C) 2000 Lineo Inc. (www.lineo.com) * Copyright (C) 2004 Microtronix Datacom Ltd. * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Linux/m68k support by Hamish Macdonald * * 68060 fixes by Jesper Skov * ColdFire support by Greg Ungerer (gerg@snapgear.com) * 5307 fixes by David W. Miller * linux 2.4 support David McCullough <davidm@snapgear.com>
*/
.macro kuser_cmpxchg_check /* * Make sure our user space atomic helper is restarted if it was * interrupted in a critical region. * ea-4 = address of interrupted insn (ea must be preserved). * sp = saved regs. * cmpxchg_ldw = first critical insn, cmpxchg_stw = last critical insn. * If ea <= cmpxchg_stw and ea > cmpxchg_ldw then saved EA is set to * cmpxchg_ldw + 4.
*/ /* et = cmpxchg_stw + 4 */
movui et, (KUSER_BASE + 4 + (cmpxchg_stw - __kuser_helper_start))
bgtu ea, et, 1f
subi et, et, (cmpxchg_stw - cmpxchg_ldw) /* et = cmpxchg_ldw + 4 */
bltu ea, et, 1f
stw et, PT_EA(sp) /* fix up EA */
mov ea, et
1:
.endm
/* Clear EH bit before we get a new excpetion in the kernel * and after we have saved it to the exception frame. This is done * whether it's trap, tlb-miss or interrupt. If we don't do this * estatus is not updated the next exception.
*/
rdctl r24, status
movi r9, %lo(~STATUS_EH)
and r24, r24, r9
wrctl status, r24
/* Read cause and vector and branch to the associated handler */
mov r4, sp
rdctl r5, exception
movia r9, exception_table
add r24, r9, r5
ldw r24, 0(r24)
jmp r24
/*********************************************************************** * Handle system calls ***********************************************************************
*/
ENTRY(handle_system_call) /* Enable interrupts */
rdctl r10, status
ori r10, r10, STATUS_PIE
wrctl status, r10
/* Reload registers destroyed by common code. */
ldw r4, PT_R4(sp)
ldw r5, PT_R5(sp)
local_restart:
stw r2, PT_ORIG_R2(sp) /* Check that the requested system call is within limits */
movui r1, __NR_syscalls
bgeu r2, r1, ret_invsyscall
slli r1, r2, 2
movhi r11, %hiadj(sys_call_table)
add r1, r1, r11
ldw r1, %lo(sys_call_table)(r1)
/* Check if we are being traced */
GET_THREAD_INFO r11
ldw r11,TI_FLAGS(r11)
BTBNZ r11,r11,TIF_SYSCALL_TRACE,traced_system_call
/* Execute the system call */
callr r1
/* If the syscall returns a negative result: * Set r7 to 1 to indicate error, * Negate r2 to get a positive error code * If the syscall returns zero or a positive value: * Set r7 to 0. * The sigreturn system calls will skip the code below by * adding to register ra. To avoid destroying registers
*/
translate_rc_and_ret:
movi r1, 0
bge r2, zero, 3f
ldw r1, PT_ORIG_R2(sp)
addi r1, r1, 1
beq r1, zero, 3f sub r2, zero, r2
movi r1, 1
3:
stw r2, PT_R2(sp)
stw r1, PT_R7(sp)
end_translate_rc_and_ret:
ret_from_exception:
ldw r1, PT_ESTATUS(sp) /* if so, skip resched, signals */
TSTBNZ r1, r1, ESTATUS_EU, Luser_return
/* If the syscall number was invalid return ENOSYS */
ret_invsyscall:
movi r2, -ENOSYS
br translate_rc_and_ret
/* This implements the same as above, except it calls * do_syscall_trace_enter and do_syscall_trace_exit before and after the * syscall in order for utilities like strace and gdb to work.
*/
traced_system_call:
SAVE_SWITCH_STACK
call do_syscall_trace_enter
RESTORE_SWITCH_STACK
/* Create system call register arguments. The 5th and 6th arguments on stack are already in place at the beginning
of pt_regs. */
ldw r2, PT_R2(sp)
ldw r4, PT_R4(sp)
ldw r5, PT_R5(sp)
ldw r6, PT_R6(sp)
ldw r7, PT_R7(sp)
/* If the syscall returns a negative result: * Set r7 to 1 to indicate error, * Negate r2 to get a positive error code * If the syscall returns zero or a positive value: * Set r7 to 0. * The sigreturn system calls will skip the code below by * adding to register ra. To avoid destroying registers
*/
translate_rc_and_ret2:
movi r1, 0
bge r2, zero, 4f
ldw r1, PT_ORIG_R2(sp)
addi r1, r1, 1
beq r1, zero, 4f sub r2, zero, r2
movi r1, 1
4:
stw r2, PT_R2(sp)
stw r1, PT_R7(sp)
end_translate_rc_and_ret2:
SAVE_SWITCH_STACK
call do_syscall_trace_exit
RESTORE_SWITCH_STACK
br ret_from_exception
/* If the syscall number was invalid return ENOSYS */
traced_invsyscall:
movi r2, -ENOSYS
br translate_rc_and_ret2
Luser_return:
GET_THREAD_INFO r11 /* get thread_info pointer */
ldw r10, TI_FLAGS(r11) /* get thread_info->flags */
ANDI32 r11, r10, _TIF_WORK_MASK
beq r11, r0, restore_all /* Nothing to do */
BTBZ r1, r10, TIF_NEED_RESCHED, Lsignal_return
/* Reschedule work */
call schedule
br ret_from_exception
/*********************************************************************** * Handle external interrupts. ***********************************************************************
*/ /* * This is the generic interrupt handler (for all hardware interrupt * sources). It figures out the vector number and calls the appropriate * interrupt service routine directly.
*/
external_interrupt:
rdctl r12, ipending
rdctl r9, ienable
and r12, r12, r9 /* skip if no interrupt is pending */
beq r12, r0, ret_from_interrupt
/* * Process an external hardware interrupt.
*/
addi ea, ea, -4 /* re-issue the interrupted instruction */
stw ea, PT_EA(sp)
2: movi r4, %lo(-1) /* Start from bit position 0,
highest priority */ /* This is the IRQ # for handler call */
1: andi r10, r12, 1 /* Isolate bit we are interested in */
srli r12, r12, 1 /* shift count is costly without hardware
multiplier */
addi r4, r4, 1
beq r10, r0, 1b
mov r5, sp /* Setup pt_regs pointer for handler call */
call do_IRQ
rdctl r12, ipending /* check again if irq still pending */
rdctl r9, ienable /* Isolate possible interrupts */
and r12, r12, r9
bne r12, r0, 2b /* br ret_from_interrupt */ /* fall through to ret_from_interrupt */
ENTRY(ret_from_interrupt)
ldw r1, PT_ESTATUS(sp) /* check if returning to kernel */
TSTBNZ r1, r1, ESTATUS_EU, Luser_return
/*********************************************************************** * A few syscall wrappers ***********************************************************************
*/ /* * int clone(unsigned long clone_flags, unsigned long newsp, * int __user * parent_tidptr, int __user * child_tidptr, * int tls_val)
*/
ENTRY(sys_clone)
SAVE_SWITCH_STACK
subi sp, sp, 4 /* make space for tls pointer */
stw r8, 0(sp) /* pass tls pointer (r8) via stack (5th argument) */
call nios2_clone
addi sp, sp, 4
RESTORE_SWITCH_STACK
ret
/* * Kernel user helpers. * * Each segment is 64-byte aligned and will be mapped to the <User space>. * New segments (if ever needed) must be added after the existing ones. * This mechanism should be used only for things that are really small and * justified, and not be abused freely. *
*/
__kuser_cmpxchg: /* @ 0x1004 */ /* * r4 pointer to exchange variable * r5 old value * r6 new value
*/
cmpxchg_ldw:
ldw r2, 0(r4) /* load current value */ sub r2, r2, r5 /* compare with old value */
bne r2, zero, cmpxchg_ret
/* We had a match, store the new value */
cmpxchg_stw:
stw r6, 0(r4)
cmpxchg_ret:
ret
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.