xref: /nrf52832-nimble/rt-thread/libcpu/arm/cortex-a/context_gcc.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 * 2013-07-05     Bernard      the first version
9 */
10
11.section .text, "ax"
12/*
13 * rt_base_t rt_hw_interrupt_disable();
14 */
15.globl rt_hw_interrupt_disable
16rt_hw_interrupt_disable:
17    mrs r0, cpsr
18    cpsid i
19    bx  lr
20
21/*
22 * void rt_hw_interrupt_enable(rt_base_t level);
23 */
24.globl rt_hw_interrupt_enable
25rt_hw_interrupt_enable:
26    msr cpsr, r0
27    bx  lr
28
29/*
30 * void rt_hw_context_switch_to(rt_uint32 to);
31 * r0 --> to
32 */
33.globl rt_hw_context_switch_to
34rt_hw_context_switch_to:
35    ldr sp, [r0]            @ get new task stack pointer
36
37    ldmfd sp!, {r4}         @ pop new task spsr
38    msr spsr_cxsf, r4
39
40    ldmfd sp!, {r0-r12, lr, pc}^   @ pop new task r0-r12, lr & pc
41
42.section .bss.share.isr
43_guest_switch_lvl:
44    .word 0
45
46.globl vmm_virq_update
47
48.section .text.isr, "ax"
49/*
50 * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
51 * r0 --> from
52 * r1 --> to
53 */
54.globl rt_hw_context_switch
55rt_hw_context_switch:
56    stmfd   sp!, {lr}       @ push pc (lr should be pushed in place of PC)
57    stmfd   sp!, {r0-r12, lr}   @ push lr & register file
58
59    mrs r4, cpsr
60    tst lr, #0x01
61    orrne r4, r4, #0x20     @ it's thumb code
62
63    stmfd sp!, {r4}         @ push cpsr
64
65    str sp, [r0]            @ store sp in preempted tasks TCB
66    ldr sp, [r1]            @ get new task stack pointer
67
68    ldmfd sp!, {r4}         @ pop new task cpsr to spsr
69    msr spsr_cxsf, r4
70    ldmfd sp!, {r0-r12, lr, pc}^  @ pop new task r0-r12, lr & pc, copy spsr to cpsr
71
72/*
73 * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
74 */
75.globl rt_thread_switch_interrupt_flag
76.globl rt_interrupt_from_thread
77.globl rt_interrupt_to_thread
78.globl rt_hw_context_switch_interrupt
79rt_hw_context_switch_interrupt:
80    ldr r2, =rt_thread_switch_interrupt_flag
81    ldr r3, [r2]
82    cmp r3, #1
83    beq _reswitch
84    ldr ip, =rt_interrupt_from_thread   @ set rt_interrupt_from_thread
85    mov r3, #1              @ set rt_thread_switch_interrupt_flag to 1
86    str r0, [ip]
87    str r3, [r2]
88_reswitch:
89    ldr r2, =rt_interrupt_to_thread     @ set rt_interrupt_to_thread
90    str r1, [r2]
91    bx  lr
92