xref: /nrf52832-nimble/rt-thread/libcpu/arm/arm926/context_iar.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 * 2015-04-15     ArdaFu     convert from context_gcc.s
10 */
11
12#define NOINT            0xc0
13
14    SECTION    .text:CODE(6)
15/*
16 * rt_base_t rt_hw_interrupt_disable();
17 */
18    PUBLIC rt_hw_interrupt_disable
19rt_hw_interrupt_disable:
20    MRS     R0, CPSR
21    ORR     R1, R0, #NOINT
22    MSR     CPSR_C, R1
23    MOV     PC, LR
24
25/*
26 * void rt_hw_interrupt_enable(rt_base_t level);
27 */
28    PUBLIC rt_hw_interrupt_enable
29rt_hw_interrupt_enable:
30    MSR     CPSR_CXSF, R0
31    MOV     PC, LR
32
33/*
34 * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
35 * r0 --> from
36 * r1 --> to
37 */
38    PUBLIC rt_hw_context_switch
39rt_hw_context_switch:
40    STMFD   SP!, {LR}          ; push pc (lr should be pushed in place of PC)
41    STMFD   SP!, {R0-R12, LR}       ; push lr & register file
42    MRS     R4, CPSR
43    STMFD   SP!, {R4}               ; push cpsr
44    STR     SP, [R0]                ; store sp in preempted tasks TCB
45    LDR     SP, [R1]                ; get new task stack pointer
46    LDMFD   SP!, {R4}               ; pop new task spsr
47    MSR     SPSR_cxsf, R4
48    LDMFD   SP!, {R0-R12, LR, PC}^  ; pop new task r0-r12, lr & pc
49
50/*
51 * void rt_hw_context_switch_to(rt_uint32 to);
52 * r0 --> to
53 */
54    PUBLIC rt_hw_context_switch_to
55rt_hw_context_switch_to:
56    LDR     SP, [R0]                ; get new task stack pointer
57    LDMFD   SP!, {R4}               ; pop new task spsr
58    MSR     SPSR_cxsf, R4
59    LDMFD   SP!, {R0-R12, LR, PC}^   ; pop new task r0-r12, lr & pc
60
61/*
62 * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
63 */
64    IMPORT rt_thread_switch_interrupt_flag
65    IMPORT rt_interrupt_from_thread
66    IMPORT rt_interrupt_to_thread
67    PUBLIC rt_hw_context_switch_interrupt
68rt_hw_context_switch_interrupt:
69    LDR     R2, =rt_thread_switch_interrupt_flag
70    LDR     R3, [R2]
71    CMP     R3, #1
72    BEQ     _reswitch
73    MOV     R3, #1                          ; set flag to 1
74    STR     R3, [R2]
75    LDR     R2, =rt_interrupt_from_thread   ; set rt_interrupt_from_thread
76    STR     R0, [R2]
77_reswitch:
78    LDR     R2, =rt_interrupt_to_thread     ; set rt_interrupt_to_thread
79    STR     R1, [R2]
80    MOV     PC, LR
81    END
82
83