Skip to content

Commit 7c012af

Browse files
authored
Merge pull request #5314 from GuEe-GUI/master
fixup .bss size define in link.lds and set spsel=1 in aarch64
2 parents ccfb3cb + efbdbc2 commit 7c012af

File tree

8 files changed

+33
-41
lines changed

8 files changed

+33
-41
lines changed

bsp/qemu-virt64-aarch64/link.lds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,4 @@ SECTIONS
148148
.debug_varnames 0 : { *(.debug_varnames) }
149149
}
150150

151-
__bss_size = (__bss_end - __bss_start)>>3;
151+
__bss_size = SIZEOF(.bss);

bsp/raspberry-pi/raspi3-64/link.lds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ SECTIONS
137137
.debug_varnames 0 : { *(.debug_varnames) }
138138
}
139139

140-
__bss_size = (__bss_end - __bss_start)>>3;
140+
__bss_size = SIZEOF(.bss);

bsp/raspberry-pi/raspi4-64/link.lds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ SECTIONS
137137
.debug_varnames 0 : { *(.debug_varnames) }
138138
}
139139

140-
__bss_size = (__bss_end - __bss_start)>>3;
140+
__bss_size = SIZEOF(.bss);

libcpu/aarch64/common/context_gcc.S

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
*
66
* Change Logs:
77
* Date Author Notes
8-
* 2018-10-06 ZhaoXiaowei the first version
8+
* 2018-10-06 ZhaoXiaowei the first version
9+
* 2021-11-04 GuEe-GUI set sp with SP_ELx
910
*/
1011

11-
/*
12+
/*
1213
*enable gtimer
1314
*/
1415
.globl rt_hw_gtimer_enable
@@ -17,6 +18,14 @@ rt_hw_gtimer_enable:
1718
MSR CNTP_CTL_EL0,X0
1819
RET
1920

21+
/*
22+
*disable gtimer
23+
*/
24+
.globl rt_hw_gtimer_disable
25+
rt_hw_gtimer_disable:
26+
MSR CNTP_CTL_EL0,XZR
27+
RET
28+
2029
/*
2130
*set gtimer CNTP_TVAL_EL0 value
2231
*/
@@ -48,10 +57,6 @@ rt_hw_get_gtimer_frq:
4857
RET
4958

5059
.macro SAVE_CONTEXT
51-
52-
/* Switch to use the EL0 stack pointer. */
53-
MSR SPSEL, #0
54-
5560
/* Save the entire context. */
5661
STP X0, X1, [SP, #-0x10]!
5762
STP X2, X3, [SP, #-0x10]!
@@ -98,16 +103,9 @@ rt_hw_get_gtimer_frq:
98103

99104
MOV X0, SP /* Move SP into X0 for saving. */
100105

101-
/* Switch to use the ELx stack pointer. */
102-
MSR SPSEL, #1
103-
104106
.endm
105107

106108
.macro SAVE_CONTEXT_T
107-
108-
/* Switch to use the EL0 stack pointer. */
109-
MSR SPSEL, #0
110-
111109
/* Save the entire context. */
112110
STP X0, X1, [SP, #-0x10]!
113111
STP X2, X3, [SP, #-0x10]!
@@ -135,15 +133,15 @@ rt_hw_get_gtimer_frq:
135133
B.EQ 1f
136134
B .
137135
3:
138-
MRS X3, SPSR_EL3
136+
MOV X3, 0x0d
139137
MOV X2, X30
140138
B 0f
141139
2:
142-
MRS X3, SPSR_EL2
140+
MOV X3, 0x09
143141
MOV X2, X30
144142
B 0f
145143
1:
146-
MRS X3, SPSR_EL1
144+
MOV X3, 0x05
147145
MOV X2, X30
148146
B 0f
149147
0:
@@ -152,16 +150,10 @@ rt_hw_get_gtimer_frq:
152150

153151
MOV X0, SP /* Move SP into X0 for saving. */
154152

155-
/* Switch to use the ELx stack pointer. */
156-
MSR SPSEL, #1
157-
158153
.endm
159154

160155
.macro RESTORE_CONTEXT
161156

162-
/* Switch to use the EL0 stack pointer. */
163-
MSR SPSEL, #0
164-
165157
/* Set the SP to point to the stack of the task being restored. */
166158
MOV SP, X0
167159

@@ -206,9 +198,6 @@ rt_hw_get_gtimer_frq:
206198
LDP X2, X3, [SP], #0x10
207199
LDP X0, X1, [SP], #0x10
208200

209-
/* Switch to use the ELx stack pointer. _RB_ Might not be required. */
210-
MSR SPSEL, #1
211-
212201
ERET
213202

214203
.endm

libcpu/aarch64/common/stack.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
* Date Author Notes
88
* 2011-09-23 Bernard the first version
99
* 2011-10-05 Bernard add thumb mode
10+
* 2021-11-04 GuEe-GUI set sp with SP_ELx
1011
*/
1112
#include <rtthread.h>
1213
#include <board.h>
1314

1415
#include <armv8.h>
1516

16-
#define INITIAL_SPSR_EL3 (PSTATE_EL3 | SP_EL0)
17-
#define INITIAL_SPSR_EL2 (PSTATE_EL2 | SP_EL0)
18-
#define INITIAL_SPSR_EL1 (PSTATE_EL1 | SP_EL0)
17+
#define INITIAL_SPSR_EL3 (PSTATE_EL3 | SP_ELx)
18+
#define INITIAL_SPSR_EL2 (PSTATE_EL2 | SP_ELx)
19+
#define INITIAL_SPSR_EL1 (PSTATE_EL1 | SP_ELx)
1920

2021
/**
2122
* This function will initialize thread stack

libcpu/aarch64/common/vector_gcc.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ system_vectors:
1818
.align 11
1919
.set VBAR, system_vectors
2020
.org VBAR
21-
// Exception from CurrentEL (EL1) with SP_EL0 (SPSEL=1)
21+
// Exception from CurrentEL (EL1) with SP_EL0 (SPSEL=0)
2222
.org (VBAR + 0x00 + 0)
2323
B vector_error // Synchronous
2424
.org (VBAR + 0x80 + 0)

libcpu/aarch64/cortex-a/entry_point.S

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Date Author Notes
77
* 2020-01-15 bigmagic the first version
88
* 2020-08-10 SummerGift support clang compiler
9+
* 2021-11-04 GuEe-GUI set sp with SP_ELx
910
*/
1011

1112
.section ".text.entrypoint","ax"
@@ -32,14 +33,15 @@ cpu_setup:
3233
bne cpu_not_in_el3
3334

3435
/* Should never be executed, just for completeness. (EL3) */
35-
mov x0, #(1 << 0) /* EL0 and EL1 are in Non-Secure state */
36-
orr x0, x0, #(1 << 4) /* RES1 */
37-
orr x0, x0, #(1 << 5) /* RES1 */
38-
orr x0, x0, #(1 << 7) /* SMC instructions are undefined at EL1 and above */
39-
orr x0, x0, #(1 << 8) /* HVC instructions are enabled at EL1 and above */
40-
orr x0, x0, #(1 << 10) /* The next lower level is AArch64 */
36+
mov x2, #(1 << 0) /* EL0 and EL1 are in Non-Secure state */
37+
orr x2, x2, #(1 << 4) /* RES1 */
38+
orr x2, x2, #(1 << 5) /* RES1 */
39+
orr x2, x2, #(1 << 7) /* SMC instructions are undefined at EL1 and above */
40+
orr x2, x2, #(1 << 8) /* HVC instructions are enabled at EL1 and above */
41+
orr x2, x2, #(1 << 10) /* The next lower level is AArch64 */
4142
msr scr_el3, x2
4243

44+
/* Change execution level to EL2 */
4345
mov x2, #0x3c9
4446
msr spsr_el3, x2 /* 0b1111001001 */
4547
adr x2, cpu_not_in_el3
@@ -51,8 +53,6 @@ cpu_not_in_el3: /* Running at EL2 or EL1 */
5153
beq cpu_in_el1 /* Halt this core if running in El1 */
5254

5355
cpu_in_el2:
54-
msr sp_el1, x1
55-
5656
/* Enable CNTP for EL1 */
5757
mrs x0, cnthctl_el2 /* Counter-timer Hypervisor Control register */
5858
orr x0, x0, #3
@@ -71,6 +71,7 @@ cpu_in_el2:
7171
eret
7272

7373
cpu_in_el1:
74+
msr spsel, #1
7475
mov sp, x1 /* Set sp in el1 */
7576

7677
/* Avoid trap from SIMD or float point instruction */
@@ -89,7 +90,7 @@ cpu_in_el1:
8990
clean_bss_loop:
9091
cbz w2, jump_to_entry
9192
str xzr, [x1], #8
92-
sub w2, w2, #1
93+
sub w2, w2, #8
9394
cbnz w2, clean_bss_loop
9495

9596
jump_to_entry:

src/thread.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <rthw.h>
3333
#include <rtthread.h>
34+
#include <stddef.h>
3435

3536
#ifdef RT_USING_HOOK
3637
static void (*rt_thread_suspend_hook)(rt_thread_t thread);

0 commit comments

Comments
 (0)