xref: /nrf52832-nimble/rt-thread/libcpu/arm/arm926/context_rvds.S (revision 104654410c56c573564690304ae786df310c91fc)
1;/*
2; * Copyright (c) 2006-2018, RT-Thread Development Team
3; *
4; * SPDX-License-Identifier: Apache-2.0
5; *
6; * Change Logs:
7; * Date           Author       Notes
8; * 2011-08-14     weety    copy from mini2440
9; */
10
11NOINT    EQU        0XC0    ; disable interrupt in psr
12
13    AREA |.TEXT|, CODE, READONLY, ALIGN=2
14    ARM
15    REQUIRE8
16    PRESERVE8
17
18;/*
19; * rt_base_t rt_hw_interrupt_disable();
20; */
21rt_hw_interrupt_disable    PROC
22    EXPORT rt_hw_interrupt_disable
23    MRS     R0, CPSR
24    ORR     R1, R0, #NOINT
25    MSR     CPSR_C, R1
26    BX      LR
27    ENDP
28
29;/*
30; * void rt_hw_interrupt_enable(rt_base_t level);
31; */
32rt_hw_interrupt_enable    proc
33    export rt_hw_interrupt_enable
34    msr     cpsr_c, r0
35    bx      lr
36    endp
37
38;/*
39; * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
40; * r0 --> from
41; * r1 --> to
42; */
43rt_hw_context_switch    proc
44    export rt_hw_context_switch
45    stmfd   sp!, {lr}           ; push pc (lr should be pushed in place of pc)
46    stmfd   sp!, {r0-r12, lr}       ; push lr & register file
47    mrs     r4, cpsr
48    stmfd   sp!, {r4}               ; push cpsr
49    str     sp, [r0]                ; store sp in preempted tasks tcb
50    ldr     sp, [r1]                ; get new task stack pointer
51    ldmfd   sp!, {r4}               ; pop new task spsr
52    msr     spsr_cxsf, r4
53    ldmfd   sp!, {r0-r12, lr, pc}^  ; pop new task r0-r12, lr & pc
54    endp
55
56;/*
57; * void rt_hw_context_switch_to(rt_uint32 to);
58; * r0 --> to
59; */
60rt_hw_context_switch_to    proc
61    export rt_hw_context_switch_to
62    ldr     sp, [r0]                ; get new task stack pointer
63    ldmfd   sp!, {r4}               ; pop new task spsr
64    msr     spsr_cxsf, r4
65    ldmfd   sp!, {r0-r12, lr, pc}^   ; pop new task r0-r12, lr & pc
66    endp
67
68;/*
69; * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
70; */
71    import rt_thread_switch_interrupt_flag
72    import rt_interrupt_from_thread
73    import rt_interrupt_to_thread
74
75rt_hw_context_switch_interrupt    proc
76    export rt_hw_context_switch_interrupt
77    ldr     r2, =rt_thread_switch_interrupt_flag
78    ldr     r3, [r2]
79    cmp     r3, #1
80    beq     _reswitch
81    mov     r3, #1                          ; set flag to 1
82    str     r3, [r2]
83    ldr     r2, =rt_interrupt_from_thread   ; set rt_interrupt_from_thread
84    str     r0, [r2]
85_reswitch
86    ldr     r2, =rt_interrupt_to_thread     ; set rt_interrupt_to_thread
87    str     r1, [r2]
88    bx      lr
89    endp
90
91    end
92