2011-12-17 12:14:22 +08:00
|
|
|
/*
|
2022-04-05 19:34:30 +08:00
|
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
2011-12-17 12:14:22 +08:00
|
|
|
*
|
2022-04-05 19:34:30 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2011-12-17 12:14:22 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2011-12-17 nl1031 first implementation for MicroBlaze.
|
|
|
|
*/
|
|
|
|
|
2011-12-18 13:13:10 +08:00
|
|
|
#include "microblaze.inc"
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
.text
|
|
|
|
.globl rt_interrupt_enter
|
|
|
|
.globl rt_interrupt_leave
|
2011-12-17 12:14:22 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* rt_base_t rt_hw_interrupt_disable()
|
|
|
|
* copy from ucos-ii
|
|
|
|
*/
|
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
.globl rt_hw_interrupt_disable
|
|
|
|
.ent rt_hw_interrupt_disable
|
|
|
|
.align 2
|
2011-12-17 12:14:22 +08:00
|
|
|
rt_hw_interrupt_disable:
|
2012-10-26 11:36:13 +08:00
|
|
|
ADDIK r1, r1, -4
|
|
|
|
SW r4, r1, r0
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
MFS r3, RMSR
|
|
|
|
ANDNI r4, r3, IE_BIT
|
|
|
|
MTS RMSR, r4
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
LW r4, r1, r0
|
|
|
|
ADDIK r1, r1, 4
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
AND r0, r0, r0 /* NO-OP - pipeline flush */
|
|
|
|
AND r0, r0, r0 /* NO-OP - pipeline flush */
|
|
|
|
AND r0, r0, r0 /* NO-OP - pipeline flush */
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
RTSD r15, 8
|
|
|
|
AND r0, r0, r0
|
|
|
|
.end rt_hw_interrupt_disable
|
2011-12-17 12:14:22 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* void rt_hw_interrupt_enable(rt_base_t level)
|
|
|
|
* copy from ucos-ii
|
|
|
|
*/
|
2012-10-26 11:36:13 +08:00
|
|
|
.globl rt_hw_interrupt_enable
|
|
|
|
.ent rt_hw_interrupt_enable
|
|
|
|
.align 2
|
2011-12-17 12:14:22 +08:00
|
|
|
rt_hw_interrupt_enable:
|
2012-10-26 11:36:13 +08:00
|
|
|
RTSD r15, 8
|
|
|
|
MTS rMSR, r5 /* Move the saved status from r5 into rMSR */
|
|
|
|
.end rt_hw_interrupt_enable
|
2011-12-17 12:14:22 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)
|
|
|
|
* r5 --> from
|
|
|
|
* r6 --> to
|
|
|
|
*/
|
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
.globl rt_interrupt_from_thread
|
|
|
|
.globl rt_interrupt_to_thread
|
|
|
|
.globl rt_hw_context_switch
|
|
|
|
.ent rt_hw_context_switch
|
|
|
|
.align 2
|
2011-12-17 12:14:22 +08:00
|
|
|
rt_hw_context_switch:
|
2012-10-26 11:36:13 +08:00
|
|
|
PUSH_ALL
|
|
|
|
MFS r3, RMSR /* save the MSR */
|
|
|
|
SWI r3, r1, STACK_RMSR
|
|
|
|
SWI r1, r5, 0 /* store sp in preempted tasks TCB */
|
|
|
|
LWI r1, r6, 0 /* get new task stack pointer */
|
|
|
|
|
|
|
|
LWI r3, r1, STACK_RMSR
|
|
|
|
ANDI r3, r3, IE_BIT
|
|
|
|
BNEI r3, rt_hw_context_switch_ie /*if IE bit set,should be use RTID (return from interrupt). */
|
|
|
|
|
|
|
|
LWI r3, r1, STACK_RMSR
|
|
|
|
MTS RMSR,r3
|
|
|
|
POP_ALL
|
|
|
|
ADDIK r1, r1, STACK_SIZE
|
|
|
|
RTSD r15, 8
|
|
|
|
AND r0, r0, r0
|
2011-12-17 12:14:22 +08:00
|
|
|
|
|
|
|
rt_hw_context_switch_ie:
|
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
LWI r3, r1, STACK_RMSR
|
|
|
|
ANDNI r3, r3, IE_BIT /* clear IE bit, prevent interrupt occur immediately*/
|
|
|
|
MTS RMSR,r3
|
|
|
|
LWI r3, r1, STACK_R03
|
|
|
|
POP_ALL
|
|
|
|
ADDIK r1, r1, STACK_SIZE
|
|
|
|
RTID r14, 0 /* IE bit will be set automatically */
|
|
|
|
AND r0, r0, r0
|
|
|
|
.end rt_hw_context_switch
|
2011-12-17 12:14:22 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* void rt_hw_context_switch_to(rt_uint32 to)
|
|
|
|
* r5 --> to
|
|
|
|
*/
|
2012-10-26 11:36:13 +08:00
|
|
|
.globl rt_hw_context_switch_to
|
|
|
|
.ent rt_hw_context_switch_to
|
|
|
|
.align 2
|
2011-12-17 12:14:22 +08:00
|
|
|
rt_hw_context_switch_to:
|
2012-10-26 11:36:13 +08:00
|
|
|
LWI r1, r5, 0 /* get new task stack pointer */
|
|
|
|
LWI r3, r1, STACK_RMSR
|
|
|
|
ANDNI r3, r3, IE_BIT /* clear IE bit, prevent interrupt occur immediately*/
|
|
|
|
MTS RMSR,r3
|
|
|
|
POP_ALL
|
|
|
|
ADDIK r1, r1, STACK_SIZE
|
|
|
|
RTID r14, 0 /* IE bit will be set automatically */
|
|
|
|
AND r0, r0, r0
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
.end rt_hw_context_switch_to
|
2011-12-17 12:14:22 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to)
|
|
|
|
*/
|
2012-10-26 11:36:13 +08:00
|
|
|
.globl rt_thread_switch_interrupt_flag
|
|
|
|
.globl rt_hw_context_switch_interrupt
|
|
|
|
.ent rt_hw_context_switch_interrupt
|
|
|
|
.align 2
|
2011-12-17 12:14:22 +08:00
|
|
|
rt_hw_context_switch_interrupt:
|
2012-10-26 11:36:13 +08:00
|
|
|
LA r3, r0, rt_thread_switch_interrupt_flag
|
|
|
|
LWI r4, r3, 0 /* load rt_thread_switch_interrupt_flag into r4 */
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
ANDI r4, r4, 1
|
|
|
|
BNEI r4, _reswitch /* if rt_thread_switch_interrupt_flag = 1 */
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
ADDIK r4, r0, 1 /* set rt_thread_switch_interrupt_flag to 1 */
|
|
|
|
SWI r4, r3, 0
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
LA r3, r0, rt_interrupt_from_thread /* set rt_interrupt_from_thread */
|
|
|
|
SWI r5, r3, 0 /* rt_interrupt_from_thread = from */
|
2011-12-17 12:14:22 +08:00
|
|
|
_reswitch:
|
2012-10-26 11:36:13 +08:00
|
|
|
LA r3, r0, rt_interrupt_to_thread /* set rt_interrupt_to_thread */
|
|
|
|
SWI r6, r3, 0 /* rt_interrupt_to_thread = to */
|
|
|
|
RTSD r15, 8
|
|
|
|
AND r0, r0, r0
|
|
|
|
.end rt_hw_context_switch_interrupt
|
2011-12-17 12:14:22 +08:00
|
|
|
|
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
.globl _interrupt_handler
|
|
|
|
.section .text
|
|
|
|
.align 2
|
|
|
|
.ent _interrupt_handler
|
|
|
|
.type _interrupt_handler, @function
|
2011-12-17 12:14:22 +08:00
|
|
|
|
|
|
|
_interrupt_handler:
|
2012-10-26 11:36:13 +08:00
|
|
|
PUSH_ALL
|
|
|
|
MFS r3, RMSR
|
|
|
|
ORI r3, r3, IE_BIT
|
|
|
|
SWI r3, r1, STACK_RMSR /* push MSR */
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
BRLID r15, rt_interrupt_enter
|
|
|
|
AND r0, r0, r0
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
BRLID r15, rt_hw_trap_irq
|
|
|
|
AND r0, r0, r0
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
BRLID r15, rt_interrupt_leave
|
|
|
|
AND r0, r0, r0
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
/*
|
|
|
|
* if rt_thread_switch_interrupt_flag set, jump to
|
|
|
|
* rt_hw_context_switch_interrupt_do and don't return
|
|
|
|
*/
|
|
|
|
LA r3, r0, rt_thread_switch_interrupt_flag
|
|
|
|
LWI r4, r3, 0
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
ANDI r4, r4, 1
|
|
|
|
BNEI r4, rt_hw_context_switch_interrupt_do
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
LWI r3, r1, STACK_RMSR
|
|
|
|
ANDNI r3, r3, IE_BIT
|
|
|
|
MTS RMSR,r3
|
|
|
|
POP_ALL
|
|
|
|
ADDIK r1, r1, STACK_SIZE
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
RTID r14, 0
|
|
|
|
AND r0, r0, r0
|
2011-12-17 12:14:22 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* void rt_hw_context_switch_interrupt_do(rt_base_t flag)
|
|
|
|
*/
|
|
|
|
rt_hw_context_switch_interrupt_do:
|
2012-10-26 11:36:13 +08:00
|
|
|
SWI r0, r3, 0 /* clear rt_thread_switch_interrupt_flag */
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
LA r3, r0, rt_interrupt_from_thread
|
|
|
|
LW r4, r0, r3
|
|
|
|
SWI r1, r4, 0 /* store sp in preempted tasks's TCB */
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
LA r3, r0, rt_interrupt_to_thread
|
|
|
|
LW r4, r0, r3
|
|
|
|
LWI r1, r4, 0 /* get new task's stack pointer */
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
LWI r3, r1, STACK_RMSR
|
|
|
|
ANDI r3, r3, IE_BIT
|
|
|
|
BNEI r3, return_with_ie /*if IE bit set,should be use RTID (return from interrupt). */
|
2011-12-17 12:14:22 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
LWI r3, r1, STACK_RMSR
|
|
|
|
MTS RMSR,r3
|
|
|
|
POP_ALL
|
|
|
|
ADDIK r1, r1, STACK_SIZE
|
|
|
|
RTSD r15, 8
|
|
|
|
AND r0, r0, r0
|
2011-12-17 12:14:22 +08:00
|
|
|
|
|
|
|
return_with_ie:
|
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
LWI r3, r1, STACK_RMSR
|
|
|
|
ANDNI r3, r3, IE_BIT /* clear IE bit, prevent interrupt occur immediately*/
|
|
|
|
MTS RMSR,r3
|
|
|
|
LWI r3, r1, STACK_R03
|
|
|
|
POP_ALL
|
|
|
|
ADDIK r1, r1, STACK_SIZE
|
|
|
|
RTID r14, 0 /* IE bit will be set automatically */
|
|
|
|
AND r0, r0, r0
|
2011-12-18 13:36:26 +08:00
|
|
|
|
2012-10-26 11:36:13 +08:00
|
|
|
.end _interrupt_handler
|
2011-12-17 12:14:22 +08:00
|
|
|
|