-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos_cpu_a.asm~
146 lines (127 loc) · 2.79 KB
/
os_cpu_a.asm~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
IMPORT OSTCBCur
IMPORT OSTCBNext
EXPORT OS_ENTER_CRITICAL
EXPORT OS_EXIT_CRITICAL
EXPORT OSStart
EXPORT PendSV_Handler
EXPORT OSCtxSw
NVIC_INT_CTRL EQU 0xE000ED04 ;Address of NVIC Interruptions Control Register
NVIC_PENDSVSET EQU 0x10000000 ;Enable PendSV
NVIC_SYSPRI14 EQU 0xE000ED22 ; System priority register (priority 14).
NVIC_PENDSV_PRI EQU 0xFF ; PendSV priority value (lowest).
PRESERVE8
AREA |.text|, CODE, READONLY
THUMB
;/******************OS_ENTER_CRITICAL************/
OS_ENTER_CRITICAL
CPSIE I ; Enable interruptions
BX LR ; Return
;/******************OS_EXIT_CRITICAL************/
OS_EXIT_CRITICAL
CPSID I ; Disable interruptions
BX LR ; Return
;/******************OSStart************/
OSStart
; disable interruptions
CPSID I
; initialize PendSV
LDR R0, =NVIC_SYSPRI14 ; Set the PendSV exception priority
LDR R1, =NVIC_PENDSV_PRI
STRB R1, [R0]
; initialize PSP as 0
MOV R4, #0
MSR PSP, R4
; trigger PendSV
LDR R4, =NVIC_INT_CTRL
LDR R5, =NVIC_PENDSVSET
STR R5, [R4]
; enable interruptions
CPSIE I
; should never get here
OSStartHang
B OSStartHang
;/******************PendSV_Handler************/
PendSV_Handler
CPSID I
; judge if using PSP
MRS R0, PSP
CBZ R0, PendSV_Handler_NoSave
; judge PSR, PC, LR, R12
; R12, R3, R2, R1
;SUB R0, R0, #0x20
;
;; store R11
;STR R11, [R0]
;SUB R0, R0, #0x4
;; store R10
;STR R10, [R0]
;SUB R0, R0, #0x4
;; store R9
;STR R9, [R0]
;SUB R0, R0, #0x4
;; store R8
;STR R8 , [R0]
;SUB R0, R0, #0x4
;; store R7
;STR R7 , [R0]
;SUB R0, R0, #0x4
;; store R6
;STR R6 , [R0]
;SUB R0, R0, #0x4
;; store R5
;STR R5 , [R0]
;SUB R0, R0, #0x4
;; store R4
;STR R4 , [R0]
;SUB R0, R0, #0x4
;ADD R0, R0, #0x20
SUB R0, R0, #0x20
STM R0, {R4-R11}
LDR R1, =OSTCBCur
LDR R1, [R1]
STR R0, [R1]
PendSV_Handler_NoSave
; OSTCBCur->OSTCBStkPtr = OSTCBNext->OSTCBStkPtr;
LDR R0, =OSTCBCur
LDR R1, =OSTCBNext
LDR R2, [R1]
STR R2, [R0]
LDR R0, [R2]
; LDM R0, {R4-R11}
; load R4
LDR R4, [R0]
ADD R0, R0, #0x4
; load R5
LDR R5, [R0]
ADD R0, R0, #0x4
; load R6
LDR R6, [R0]
ADD R0, R0, #0x4
; load R7
LDR R7 , [R0]
ADD R0, R0, #0x4
; load R8
LDR R8 , [R0]
ADD R0, R0, #0x4
; load R9
LDR R9 , [R0]
ADD R0, R0, #0x4
; load R10
LDR R10 , [R0]
ADD R0, R0, #0x4
; load R11
LDR R11 , [R0]
ADD R0, R0, #0x4
MSR PSP, R0
ORR LR, LR, #0x04
CPSIE I
BX LR
OSCtxSw
PUSH {R4, R5}
LDR R4, =NVIC_INT_CTRL
LDR R5, =NVIC_PENDSVSET
STR R5, [R4]
POP {R4, R5}
BX LR
align 4
end