@@ -5,6 +5,12 @@ macro_rules! cfg_global_asm {
55 { @inner, [ $( $x: tt) * ] , } => {
66 global_asm!{ $( $x) * }
77 } ;
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+ } ;
814 ( @inner, [ $( $x: tt) * ] , #[ cfg( $meta: meta) ] $asm: literal, $( $rest: tt) * ) => {
915 #[ cfg( $meta) ]
1016 cfg_global_asm!{ @inner, [ $( $x) * $asm, ] , $( $rest) * }
@@ -80,17 +86,14 @@ _abs_start:
8086 la t0, abort // If hart_id > _max_hart_id, jump to abort
8187 jr t0
82881:" , // only valid harts reach this point
83- ) ;
8489
8590// INITIALIZE GLOBAL POINTER, STACK POINTER, AND FRAME POINTER
86- cfg_global_asm ! (
8791 ".option push
8892 .option norelax
8993 la gp, __global_pointer$
9094 .option pop" ,
91- ) ;
9295#[ cfg( not( feature = "single-hart" ) ) ]
93- cfg_global_asm ! (
96+ {
9497 "mv t2, a0
9598 lui t0, %hi(_hart_stack_size)
9699 add t0, t0, %lo(_hart_stack_size)" ,
@@ -104,17 +107,13 @@ cfg_global_asm!(
104107 addi t2, t2, -1
105108 bnez t2, 1b
1061092: " ,
107- ) ;
108- cfg_global_asm ! (
110+ }
109111 "la t1, _stack_start" ,
110112 #[ cfg( not( feature = "single-hart" ) ) ]
111113 "sub t1, t1, t0" ,
112114 "andi sp, t1, -16 // align stack to 16-bytes
113115 add s0, sp, zero" ,
114- ) ;
115-
116116// STORE A0..A2 IN THE STACK, AS THEY WILL BE NEEDED LATER BY main
117- cfg_global_asm ! (
118117 #[ cfg( target_arch = "riscv32" ) ]
119118 "addi sp, sp, -4 * 4 // we must keep stack aligned to 16-bytes
120119 sw a0, 4 * 0(sp)
@@ -125,10 +124,8 @@ cfg_global_asm!(
125124 sd a0, 8 * 0(sp)
126125 sd a1, 8 * 1(sp)
127126 sd a2, 8 * 2(sp)" ,
128- ) ;
129127
130128// CALL __pre_init (IF ENABLED) AND INITIALIZE RAM
131- cfg_global_asm ! (
132129 #[ cfg( not( feature = "single-hart" ) ) ]
133130 // Skip RAM initialization if current hart is not the boot hart
134131 "call _mp_hook
@@ -169,11 +166,10 @@ cfg_global_asm!(
169166 bltu t0, t2, 3b" ,
170167 "
1711684: // RAM initialized" ,
172- ) ;
173169
174170// INITIALIZE FLOATING POINT UNIT
175171#[ cfg( any( riscvf, riscvd) ) ]
176- cfg_global_asm ! (
172+ {
177173 "
178174 li t0, 0x4000 // bit 14 is FS most significant bit
179175 li t2, 0x2000 // bit 13 is FS least significant bit
@@ -185,10 +181,9 @@ cfg_global_asm!(
185181 "csrrc x0, mstatus, t0
186182 csrrs x0, mstatus, t2" ,
187183 "fscsr x0" ,
188- ) ;
184+ }
189185
190186// SET UP INTERRUPTS, RESTORE a0..a2, AND JUMP TO MAIN RUST FUNCTION
191- cfg_global_asm ! (
192187 "call _setup_interrupts" ,
193188 #[ cfg( target_arch = "riscv32" ) ]
194189 "lw a0, 4 * 0(sp)
@@ -203,9 +198,7 @@ cfg_global_asm!(
203198 "la t0, main
204199 jr t0
205200 .cfi_endproc" ,
206- ) ;
207201
208- cfg_global_asm ! (
209202 #[ cfg( not( feature = "single-hart" ) ) ]
210203 // Default implementation of `_mp_hook` wakes hart 0 and busy-loops all the other harts.
211204 // Users can override this function by defining their own `_mp_hook`.
0 commit comments