2019-01-23 17:29:54 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018, Synopsys, Inc.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
#define __ASSEMBLY__
|
2020-01-16 16:00:13 +08:00
|
|
|
#include "include/arc/arc.h"
|
|
|
|
#include "include/arc/arc_asm_common.h"
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2020-01-16 16:00:13 +08:00
|
|
|
.global rt_interrupt_enter;
|
|
|
|
.global rt_interrupt_leave;
|
|
|
|
.global context_switch_reqflg;
|
|
|
|
.global rt_interrupt_from_thread;
|
|
|
|
.global rt_interrupt_to_thread;
|
|
|
|
.global exc_nest_count;
|
|
|
|
.global set_hw_stack_check;
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
.text
|
|
|
|
.align 4
|
2019-01-23 17:29:54 +08:00
|
|
|
dispatcher:
|
2022-01-18 13:35:13 +08:00
|
|
|
st sp, [r0]
|
|
|
|
ld sp, [r1]
|
2020-01-16 16:00:13 +08:00
|
|
|
#if ARC_FEATURE_STACK_CHECK
|
|
|
|
#if ARC_FEATURE_SEC_PRESENT
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_SEC_STAT]
|
|
|
|
bclr r0, r0, AUX_SEC_STAT_BIT_SSC
|
|
|
|
sflag r0
|
2020-01-16 16:00:13 +08:00
|
|
|
#else
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_STATUS32]
|
|
|
|
bclr r0, r0, AUX_STATUS_BIT_SC
|
|
|
|
kflag r0
|
2020-01-16 16:00:13 +08:00
|
|
|
#endif
|
2022-01-18 13:35:13 +08:00
|
|
|
jl set_hw_stack_check
|
2020-01-16 16:00:13 +08:00
|
|
|
#if ARC_FEATURE_SEC_PRESENT
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_SEC_STAT]
|
|
|
|
bset r0, r0, AUX_SEC_STAT_BIT_SSC
|
|
|
|
sflag r0
|
2020-01-16 16:00:13 +08:00
|
|
|
#else
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_STATUS32]
|
|
|
|
bset r0, r0, AUX_STATUS_BIT_SC
|
|
|
|
kflag r0
|
2020-01-16 16:00:13 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
2022-01-18 13:35:13 +08:00
|
|
|
pop r0
|
|
|
|
j [r0]
|
2019-01-23 17:29:54 +08:00
|
|
|
|
|
|
|
/* return routine when task dispatch happened in task context */
|
|
|
|
dispatch_r:
|
2022-01-18 13:35:13 +08:00
|
|
|
RESTORE_NONSCRATCH_REGS
|
|
|
|
j [blink]
|
2019-01-23 17:29:54 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* rt_base_t rt_hw_interrupt_disable();
|
|
|
|
*/
|
2022-01-18 13:35:13 +08:00
|
|
|
.global rt_hw_interrupt_disable
|
|
|
|
.align 4
|
2019-01-23 17:29:54 +08:00
|
|
|
rt_hw_interrupt_disable:
|
2022-01-18 13:35:13 +08:00
|
|
|
clri r0
|
|
|
|
j [blink]
|
2019-01-23 17:29:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* void rt_hw_interrupt_enable(rt_base_t level);
|
|
|
|
*/
|
2022-01-18 13:35:13 +08:00
|
|
|
.global rt_hw_interrupt_enable
|
|
|
|
.align 4
|
2019-01-23 17:29:54 +08:00
|
|
|
rt_hw_interrupt_enable:
|
2022-01-18 13:35:13 +08:00
|
|
|
seti r0
|
|
|
|
j [blink]
|
2019-01-23 17:29:54 +08:00
|
|
|
|
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
.global rt_hw_context_switch_interrupt
|
|
|
|
.align 4
|
2019-01-23 17:29:54 +08:00
|
|
|
rt_hw_context_switch_interrupt:
|
2022-01-18 13:35:13 +08:00
|
|
|
st r0, [rt_interrupt_from_thread]
|
|
|
|
st r1, [rt_interrupt_to_thread]
|
|
|
|
mov r0, 1
|
|
|
|
st r0, [context_switch_reqflg]
|
|
|
|
j [blink]
|
2019-01-23 17:29:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
|
|
|
|
* r0 --> from
|
|
|
|
* r1 --> to
|
|
|
|
*/
|
2022-01-18 13:35:13 +08:00
|
|
|
.global rt_hw_context_switch
|
|
|
|
.align 4
|
2019-01-23 17:29:54 +08:00
|
|
|
rt_hw_context_switch:
|
2022-01-18 13:35:13 +08:00
|
|
|
SAVE_NONSCRATCH_REGS
|
|
|
|
mov r2, dispatch_r
|
|
|
|
push r2
|
|
|
|
b dispatcher
|
2019-01-23 17:29:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* void rt_hw_context_switch_to(rt_uint32 to);
|
|
|
|
* r0 --> to
|
|
|
|
*/
|
2022-01-18 13:35:13 +08:00
|
|
|
.global rt_hw_context_switch_to
|
|
|
|
.align 4
|
2019-01-23 17:29:54 +08:00
|
|
|
rt_hw_context_switch_to:
|
2022-01-18 13:35:13 +08:00
|
|
|
ld sp, [r0]
|
2020-01-16 16:00:13 +08:00
|
|
|
#if ARC_FEATURE_STACK_CHECK
|
2022-01-18 13:35:13 +08:00
|
|
|
mov r1, r0
|
2020-01-16 16:00:13 +08:00
|
|
|
#if ARC_FEATURE_SEC_PRESENT
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_SEC_STAT]
|
|
|
|
bclr r0, r0, AUX_SEC_STAT_BIT_SSC
|
|
|
|
sflag r0
|
2020-01-16 16:00:13 +08:00
|
|
|
#else
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_STATUS32]
|
|
|
|
bclr r0, r0, AUX_STATUS_BIT_SC
|
|
|
|
kflag r0
|
2020-01-16 16:00:13 +08:00
|
|
|
#endif
|
2022-01-18 13:35:13 +08:00
|
|
|
jl set_hw_stack_check
|
2020-01-16 16:00:13 +08:00
|
|
|
#if ARC_FEATURE_SEC_PRESENT
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_SEC_STAT]
|
|
|
|
bset r0, r0, AUX_SEC_STAT_BIT_SSC
|
|
|
|
sflag r0
|
2020-01-16 16:00:13 +08:00
|
|
|
#else
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_STATUS32]
|
|
|
|
bset r0, r0, AUX_STATUS_BIT_SC
|
|
|
|
kflag r0
|
2020-01-16 16:00:13 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
2022-01-18 13:35:13 +08:00
|
|
|
pop r0
|
|
|
|
j [r0]
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
.global start_r
|
|
|
|
.align 4
|
2019-01-23 17:29:54 +08:00
|
|
|
start_r:
|
2022-01-18 13:35:13 +08:00
|
|
|
pop blink;
|
|
|
|
pop r1
|
|
|
|
pop r2
|
|
|
|
pop r0
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
j_s.d [r1]
|
|
|
|
kflag r2
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2020-01-16 16:00:13 +08:00
|
|
|
/*
|
|
|
|
* int __rt_ffs(int value);
|
|
|
|
* r0 --> value
|
|
|
|
*/
|
2022-01-18 13:35:13 +08:00
|
|
|
.global __rt_ffs
|
|
|
|
.align 4
|
2020-01-16 16:00:13 +08:00
|
|
|
__rt_ffs:
|
2022-01-18 13:35:13 +08:00
|
|
|
breq r0, 0, __rt_ffs_return
|
|
|
|
ffs r1, r0
|
|
|
|
add r0, r1, 1
|
2020-01-16 16:00:13 +08:00
|
|
|
__rt_ffs_return:
|
2022-01-18 13:35:13 +08:00
|
|
|
j [blink]
|
2020-01-16 16:00:13 +08:00
|
|
|
|
2019-01-23 17:29:54 +08:00
|
|
|
/****** exceptions and interrupts handing ******/
|
|
|
|
/****** entry for exception handling ******/
|
2022-01-18 13:35:13 +08:00
|
|
|
.global exc_entry_cpu
|
|
|
|
.align 4
|
2019-01-23 17:29:54 +08:00
|
|
|
exc_entry_cpu:
|
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
EXCEPTION_PROLOGUE
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
mov blink, sp
|
|
|
|
mov r3, sp /* as exception handler's para(p_excinfo) */
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
ld r0, [exc_nest_count]
|
|
|
|
add r1, r0, 1
|
|
|
|
st r1, [exc_nest_count]
|
|
|
|
brne r0, 0, exc_handler_1
|
2019-01-23 17:29:54 +08:00
|
|
|
/* change to exception stack if interrupt happened in task context */
|
2022-01-18 13:35:13 +08:00
|
|
|
mov sp, _e_stack
|
2019-01-23 17:29:54 +08:00
|
|
|
exc_handler_1:
|
2022-01-18 13:35:13 +08:00
|
|
|
PUSH blink
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_ECR]
|
|
|
|
lsr r0, r0, 16
|
|
|
|
mov r1, exc_int_handler_table
|
|
|
|
ld.as r2, [r1, r0]
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
mov r0, r3
|
|
|
|
jl [r2]
|
2019-01-23 17:29:54 +08:00
|
|
|
|
|
|
|
/* interrupts are not allowed */
|
|
|
|
ret_exc:
|
2022-01-18 13:35:13 +08:00
|
|
|
POP sp
|
|
|
|
mov r1, exc_nest_count
|
|
|
|
ld r0, [r1]
|
|
|
|
sub r0, r0, 1
|
|
|
|
st r0, [r1]
|
|
|
|
brne r0, 0, ret_exc_1 /* nest exception case */
|
|
|
|
lr r1, [AUX_IRQ_ACT] /* nest interrupt case */
|
|
|
|
brne r1, 0, ret_exc_1
|
|
|
|
|
|
|
|
ld r0, [context_switch_reqflg]
|
|
|
|
brne r0, 0, ret_exc_2
|
|
|
|
ret_exc_1: /* return from non-task context, interrupts or exceptions are nested */
|
|
|
|
EXCEPTION_EPILOGUE
|
|
|
|
rtie
|
2019-01-23 17:29:54 +08:00
|
|
|
|
|
|
|
/* there is a dispatch request */
|
|
|
|
ret_exc_2:
|
2022-01-18 13:35:13 +08:00
|
|
|
/* clear dispatch request */
|
|
|
|
mov r0, 0
|
|
|
|
st r0, [context_switch_reqflg]
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
SAVE_CALLEE_REGS /* save callee save registers */
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
/* clear exception bit to do exception exit by SW */
|
|
|
|
lr r0, [AUX_STATUS32]
|
|
|
|
bclr r0, r0, AUX_STATUS_BIT_AE
|
|
|
|
kflag r0
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
mov r1, ret_exc_r /* save return address */
|
|
|
|
PUSH r1
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
ld r0, [rt_interrupt_from_thread]
|
|
|
|
ld r1, [rt_interrupt_to_thread]
|
|
|
|
b dispatcher
|
2019-01-23 17:29:54 +08:00
|
|
|
|
|
|
|
ret_exc_r:
|
2022-01-18 13:35:13 +08:00
|
|
|
/* recover exception status */
|
|
|
|
lr r0, [AUX_STATUS32]
|
|
|
|
bset r0, r0, AUX_STATUS_BIT_AE
|
|
|
|
kflag r0
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
RESTORE_CALLEE_REGS
|
|
|
|
EXCEPTION_EPILOGUE
|
|
|
|
rtie
|
2019-01-23 17:29:54 +08:00
|
|
|
|
|
|
|
/****** entry for normal interrupt exception handling ******/
|
2022-01-18 13:35:13 +08:00
|
|
|
.global exc_entry_int /* entry for interrupt handling */
|
|
|
|
.align 4
|
2019-01-23 17:29:54 +08:00
|
|
|
exc_entry_int:
|
|
|
|
#if ARC_FEATURE_FIRQ == 1
|
|
|
|
/* check whether it is P0 interrupt */
|
|
|
|
#if ARC_FEATURE_RGF_NUM_BANKS > 1
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_IRQ_ACT]
|
|
|
|
btst r0, 0
|
|
|
|
jnz exc_entry_firq
|
2019-01-23 17:29:54 +08:00
|
|
|
#else
|
2022-01-18 13:35:13 +08:00
|
|
|
PUSH r10
|
|
|
|
lr r10, [AUX_IRQ_ACT]
|
|
|
|
btst r10, 0
|
|
|
|
POP r10
|
|
|
|
jnz exc_entry_firq
|
2019-01-23 17:29:54 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
2022-01-18 13:35:13 +08:00
|
|
|
INTERRUPT_PROLOGUE
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
mov blink, sp
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
clri /* disable interrupt */
|
|
|
|
ld r3, [exc_nest_count]
|
|
|
|
add r2, r3, 1
|
|
|
|
st r2, [exc_nest_count]
|
|
|
|
seti /* enable higher priority interrupt */
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
brne r3, 0, irq_handler_1
|
2019-01-23 17:29:54 +08:00
|
|
|
/* change to exception stack if interrupt happened in task context */
|
2022-01-18 13:35:13 +08:00
|
|
|
mov sp, _e_stack
|
2020-01-16 16:00:13 +08:00
|
|
|
#if ARC_FEATURE_STACK_CHECK
|
|
|
|
#if ARC_FEATURE_SEC_PRESENT
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_SEC_STAT]
|
|
|
|
bclr r0, r0, AUX_SEC_STAT_BIT_SSC
|
|
|
|
sflag r0
|
2020-01-16 16:00:13 +08:00
|
|
|
#else
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_STATUS32]
|
|
|
|
bclr r0, r0, AUX_STATUS_BIT_SC
|
|
|
|
kflag r0
|
2020-01-16 16:00:13 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
2019-01-23 17:29:54 +08:00
|
|
|
irq_handler_1:
|
2022-01-18 13:35:13 +08:00
|
|
|
PUSH blink
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
jl rt_interrupt_enter
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_IRQ_CAUSE]
|
|
|
|
sr r0, [AUX_IRQ_SELECT]
|
|
|
|
mov r1, exc_int_handler_table
|
|
|
|
ld.as r2, [r1, r0] /* r2 = exc_int_handler_table + irqno *4 */
|
2019-01-23 17:29:54 +08:00
|
|
|
/* handle software triggered interrupt */
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r3, [AUX_IRQ_HINT]
|
|
|
|
cmp r3, r0
|
|
|
|
bne.d irq_hint_handled
|
|
|
|
xor r3, r3, r3
|
|
|
|
sr r3, [AUX_IRQ_HINT]
|
2019-01-23 17:29:54 +08:00
|
|
|
irq_hint_handled:
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r3, [AUX_IRQ_PRIORITY]
|
|
|
|
PUSH r3 /* save irq priority */
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
jl [r2] /* jump to interrupt handler */
|
|
|
|
jl rt_interrupt_leave
|
2019-01-23 17:29:54 +08:00
|
|
|
ret_int:
|
2022-01-18 13:35:13 +08:00
|
|
|
clri /* disable interrupt */
|
|
|
|
POP r3 /* irq priority */
|
|
|
|
POP sp
|
|
|
|
mov r1, exc_nest_count
|
|
|
|
ld r0, [r1]
|
|
|
|
sub r0, r0, 1
|
|
|
|
st r0, [r1]
|
2020-01-16 16:00:13 +08:00
|
|
|
/* if there are multi-bits set in IRQ_ACT, it's still in nest interrupt */
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_IRQ_CAUSE]
|
|
|
|
sr r0, [AUX_IRQ_SELECT]
|
|
|
|
lr r3, [AUX_IRQ_PRIORITY]
|
|
|
|
lr r1, [AUX_IRQ_ACT]
|
|
|
|
bclr r2, r1, r3
|
|
|
|
brne r2, 0, ret_int_1
|
|
|
|
|
|
|
|
ld r0, [context_switch_reqflg]
|
|
|
|
brne r0, 0, ret_int_2
|
|
|
|
ret_int_1: /* return from non-task context */
|
|
|
|
INTERRUPT_EPILOGUE
|
|
|
|
rtie
|
2019-01-23 17:29:54 +08:00
|
|
|
/* there is a dispatch request */
|
|
|
|
ret_int_2:
|
2022-01-18 13:35:13 +08:00
|
|
|
/* clear dispatch request */
|
|
|
|
mov r0, 0
|
|
|
|
st r0, [context_switch_reqflg]
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
/* interrupt return by SW */
|
|
|
|
lr r10, [AUX_IRQ_ACT]
|
|
|
|
PUSH r10
|
|
|
|
bclr r10, r10, r3 /* clear related bits in IRQ_ACT */
|
|
|
|
sr r10, [AUX_IRQ_ACT]
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
SAVE_CALLEE_REGS /* save callee save registers */
|
|
|
|
mov r1, ret_int_r /* save return address */
|
|
|
|
PUSH r1
|
2019-01-23 17:29:54 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
ld r0, [rt_interrupt_from_thread]
|
|
|
|
ld r1, [rt_interrupt_to_thread]
|
|
|
|
b dispatcher
|
2019-01-23 17:29:54 +08:00
|
|
|
|
|
|
|
ret_int_r:
|
2022-01-18 13:35:13 +08:00
|
|
|
RESTORE_CALLEE_REGS
|
|
|
|
/* recover AUX_IRQ_ACT to restore the interrup status */
|
|
|
|
POPAX AUX_IRQ_ACT
|
|
|
|
INTERRUPT_EPILOGUE
|
|
|
|
rtie
|
2020-01-16 16:00:13 +08:00
|
|
|
|
|
|
|
/****** entry for fast irq exception handling ******/
|
2022-01-18 13:35:13 +08:00
|
|
|
.global exc_entry_firq
|
|
|
|
.weak exc_entry_firq
|
|
|
|
.align 4
|
2020-01-16 16:00:13 +08:00
|
|
|
exc_entry_firq:
|
2022-01-18 13:35:13 +08:00
|
|
|
SAVE_FIQ_EXC_REGS
|
2020-01-16 16:00:13 +08:00
|
|
|
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r0, [AUX_IRQ_CAUSE]
|
|
|
|
mov r1, exc_int_handler_table
|
2020-01-16 16:00:13 +08:00
|
|
|
/* r2 = _kernel_exc_tbl + irqno *4 */
|
2022-01-18 13:35:13 +08:00
|
|
|
ld.as r2, [r1, r0]
|
2020-01-16 16:00:13 +08:00
|
|
|
|
|
|
|
/* for the case of software triggered interrupt */
|
2022-01-18 13:35:13 +08:00
|
|
|
lr r3, [AUX_IRQ_HINT]
|
|
|
|
cmp r3, r0
|
|
|
|
bne.d firq_hint_handled
|
|
|
|
xor r3, r3, r3
|
|
|
|
sr r3, [AUX_IRQ_HINT]
|
2020-01-16 16:00:13 +08:00
|
|
|
firq_hint_handled:
|
|
|
|
/* jump to interrupt handler */
|
2022-01-18 13:35:13 +08:00
|
|
|
mov r0, sp
|
|
|
|
jl [r2]
|
2020-01-16 16:00:13 +08:00
|
|
|
|
|
|
|
firq_return:
|
2022-01-18 13:35:13 +08:00
|
|
|
RESTORE_FIQ_EXC_REGS
|
|
|
|
rtie
|