Skip to content

Commit 6f32a0f

Browse files
committed
[arch][riscv] use newly discovered pseudo-instructions for load/stores
I hadn't noticed this before, but you can directly reference a global variable in a load/store in assembly, which combines a lla + ld/sd into a 2 instruction pair instead of 3 due to the 12 bit offset provided in the load/store.
1 parent 77eb84d commit 6f32a0f

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

arch/riscv/start.S

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ FUNCTION(_start)
8080
// Save a copy of _start in physical space. This is later used
8181
// as the entry point for secondary cpus.
8282
lla t0, _start
83-
lla t1, _start_physical
84-
STR t0, (t1)
83+
STR t0, (_start_physical), t1
8584
#endif
8685

8786
#if RISCV_MMU
@@ -91,9 +90,8 @@ FUNCTION(_start)
9190
#if WITH_SMP
9291
// Release any other harts into riscv_secondary_entry
9392
fence w, w
94-
lla t1, _boot_status
9593
li t0, 1
96-
sb t0, (t1)
94+
sb t0, (_boot_status), t1
9795
fence
9896
#endif
9997

@@ -118,8 +116,7 @@ END_FUNCTION(_start)
118116
LOCAL_FUNCTION(secondary_trap)
119117
#if WITH_SMP
120118
// wait for _boot_status to be nonzero, then go into riscv_secondary_entry
121-
lla t5, _boot_status
122-
lb t0, (t5)
119+
lb t0, (_boot_status)
123120
beqz t0, secondary_trap
124121

125122
// we've been released by the main cpu and/or we've been booted after the
@@ -156,18 +153,15 @@ LOCAL_FUNCTION(_mmu_init)
156153
lla t0, trampoline_pgtable
157154

158155
// store the physical address of the pgtable for future use
159-
lla t1, trampoline_pgtable_phys
160-
sd t0, (t1)
156+
sd t0, (trampoline_pgtable_phys), t1
161157

162158
// do the same for the main kernel pgtable
163159
lla t2, kernel_pgtable
164-
lla t1, kernel_pgtable_phys
165-
sd t2, (t1)
160+
sd t2, (kernel_pgtable_phys), t1
166161

167162
// and the 2nd level tables
168163
lla t2, kernel_l2_pgtable
169-
lla t1, kernel_l2_pgtable_phys
170-
sd t2, (t1)
164+
sd t2, (kernel_l2_pgtable_phys), t1
171165

172166
// compute kernel pgtable pointer (index 256)
173167
addi t1, t0, (8 * 128)
@@ -227,8 +221,7 @@ LOCAL_FUNCTION(_mmu_init)
227221
lla t1, .Lhigh
228222

229223
// bounce to the high address
230-
lla t0, .Lhigh_addr
231-
ld t0, (t0)
224+
ld t0, (.Lhigh_addr)
232225
jr t0
233226

234227
// the full virtual address of the .Lhigh label

0 commit comments

Comments
 (0)