@@ -5,6 +5,12 @@ macro_rules! cfg_global_asm {
5
5
{ @inner, [ $( $x: tt) * ] , } => {
6
6
global_asm!{ $( $x) * }
7
7
} ;
8
+ ( @inner, [ $( $x: tt) * ] , #[ cfg( $meta: meta) ] { $( $y: tt) * } $( $rest: tt) * ) => {
9
+ #[ cfg( $meta) ]
10
+ cfg_global_asm!{ @inner, [ $( $x) * ] , $( $y) * $( $rest) * }
11
+ #[ cfg( not( $meta) ) ]
12
+ cfg_global_asm!{ @inner, [ $( $x) * ] , $( $rest) * }
13
+ } ;
8
14
( @inner, [ $( $x: tt) * ] , #[ cfg( $meta: meta) ] $asm: literal, $( $rest: tt) * ) => {
9
15
#[ cfg( $meta) ]
10
16
cfg_global_asm!{ @inner, [ $( $x) * $asm, ] , $( $rest) * }
@@ -80,17 +86,14 @@ _abs_start:
80
86
la t0, abort // If hart_id > _max_hart_id, jump to abort
81
87
jr t0
82
88
1:" , // only valid harts reach this point
83
- ) ;
84
89
85
90
// INITIALIZE GLOBAL POINTER, STACK POINTER, AND FRAME POINTER
86
- cfg_global_asm ! (
87
91
".option push
88
92
.option norelax
89
93
la gp, __global_pointer$
90
94
.option pop" ,
91
- ) ;
92
95
#[ cfg( not( feature = "single-hart" ) ) ]
93
- cfg_global_asm ! (
96
+ {
94
97
"mv t2, a0
95
98
lui t0, %hi(_hart_stack_size)
96
99
add t0, t0, %lo(_hart_stack_size)" ,
@@ -104,17 +107,13 @@ cfg_global_asm!(
104
107
addi t2, t2, -1
105
108
bnez t2, 1b
106
109
2: " ,
107
- ) ;
108
- cfg_global_asm ! (
110
+ }
109
111
"la t1, _stack_start" ,
110
112
#[ cfg( not( feature = "single-hart" ) ) ]
111
113
"sub t1, t1, t0" ,
112
114
"andi sp, t1, -16 // align stack to 16-bytes
113
115
add s0, sp, zero" ,
114
- ) ;
115
-
116
116
// STORE A0..A2 IN THE STACK, AS THEY WILL BE NEEDED LATER BY main
117
- cfg_global_asm ! (
118
117
#[ cfg( target_arch = "riscv32" ) ]
119
118
"addi sp, sp, -4 * 4 // we must keep stack aligned to 16-bytes
120
119
sw a0, 4 * 0(sp)
@@ -125,10 +124,8 @@ cfg_global_asm!(
125
124
sd a0, 8 * 0(sp)
126
125
sd a1, 8 * 1(sp)
127
126
sd a2, 8 * 2(sp)" ,
128
- ) ;
129
127
130
128
// CALL __pre_init (IF ENABLED) AND INITIALIZE RAM
131
- cfg_global_asm ! (
132
129
#[ cfg( not( feature = "single-hart" ) ) ]
133
130
// Skip RAM initialization if current hart is not the boot hart
134
131
"call _mp_hook
@@ -169,11 +166,10 @@ cfg_global_asm!(
169
166
bltu t0, t2, 3b" ,
170
167
"
171
168
4: // RAM initialized" ,
172
- ) ;
173
169
174
170
// INITIALIZE FLOATING POINT UNIT
175
171
#[ cfg( any( riscvf, riscvd) ) ]
176
- cfg_global_asm ! (
172
+ {
177
173
"
178
174
li t0, 0x4000 // bit 14 is FS most significant bit
179
175
li t2, 0x2000 // bit 13 is FS least significant bit
@@ -185,10 +181,9 @@ cfg_global_asm!(
185
181
"csrrc x0, mstatus, t0
186
182
csrrs x0, mstatus, t2" ,
187
183
"fscsr x0" ,
188
- ) ;
184
+ }
189
185
190
186
// SET UP INTERRUPTS, RESTORE a0..a2, AND JUMP TO MAIN RUST FUNCTION
191
- cfg_global_asm ! (
192
187
"call _setup_interrupts" ,
193
188
#[ cfg( target_arch = "riscv32" ) ]
194
189
"lw a0, 4 * 0(sp)
@@ -203,9 +198,7 @@ cfg_global_asm!(
203
198
"la t0, main
204
199
jr t0
205
200
.cfi_endproc" ,
206
- ) ;
207
201
208
- cfg_global_asm ! (
209
202
#[ cfg( not( feature = "single-hart" ) ) ]
210
203
// Default implementation of `_mp_hook` wakes hart 0 and busy-loops all the other harts.
211
204
// Users can override this function by defining their own `_mp_hook`.
0 commit comments