xref: /nrf52832-nimble/rt-thread/libcpu/arm/s3c44b0/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 * 2006-09-06     XuXinming    first version
9 */
10
11/*!
12 * \addtogroup S3C44B0
13 */
14/*@{*/
15
16#define NOINT			0xc0
17
18/*
19 * rt_base_t rt_hw_interrupt_disable();
20 */
21.globl rt_hw_interrupt_disable
22rt_hw_interrupt_disable:
23	mrs r0, cpsr
24	orr r1, r0, #NOINT
25	msr cpsr_c, r1
26	mov pc, lr
27
28/*
29 * void rt_hw_interrupt_enable(rt_base_t level);
30 */
31.globl rt_hw_interrupt_enable
32rt_hw_interrupt_enable:
33	msr cpsr, r0
34	mov pc, lr
35
36/*
37 * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
38 * r0 --> from
39 * r1 --> to
40 */
41.globl rt_hw_context_switch
42rt_hw_context_switch:
43	stmfd	sp!, {lr}		@ push pc (lr should be pushed in place of PC)
44	stmfd	sp!, {r0-r12, lr}	@ push lr & register file
45
46	mrs	r4, cpsr
47	stmfd	sp!, {r4}		@ push cpsr
48	mrs	r4, spsr
49	stmfd	sp!, {r4}		@ push spsr
50
51	str	sp, [r0]			@ store sp in preempted tasks TCB
52	ldr	sp, [r1]			@ get new task stack pointer
53
54	ldmfd	sp!, {r4}		@ pop new task spsr
55	msr	spsr_cxsf, r4
56	ldmfd	sp!, {r4}		@ pop new task cpsr
57	msr	cpsr_cxsf, r4
58
59	ldmfd	sp!, {r0-r12, lr, pc}	@ pop new task r0-r12, lr & pc
60
61/*
62 * void rt_hw_context_switch_to(rt_uint32 to);
63 * r0 --> to
64 */
65.globl rt_hw_context_switch_to
66rt_hw_context_switch_to:
67	ldr	sp, [r0]		@ get new task stack pointer
68
69	ldmfd	sp!, {r4}		@ pop new task spsr
70	msr	spsr_cxsf, r4
71	ldmfd	sp!, {r4}		@ pop new task cpsr
72	msr	cpsr_cxsf, r4
73
74	ldmfd	sp!, {r0-r12, lr, pc}	@ pop new task r0-r12, lr & pc
75
76/*
77 * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
78 */
79.globl rt_thread_switch_interrupt_flag
80.globl rt_interrupt_from_thread
81.globl rt_interrupt_to_thread
82.globl rt_hw_context_switch_interrupt
83rt_hw_context_switch_interrupt:
84	ldr r2, =rt_thread_switch_interrupt_flag
85	ldr r3, [r2]
86	cmp r3, #1
87	beq _reswitch
88	mov r3, #1				@ set rt_thread_switch_interrupt_flag to 1
89	str r3, [r2]
90	ldr r2, =rt_interrupt_from_thread	@ set rt_interrupt_from_thread
91	str r0, [r2]
92_reswitch:
93	ldr r2, =rt_interrupt_to_thread		@ set rt_interrupt_to_thread
94	str r1, [r2]
95	mov pc, lr
96