Skip to content

Commit babdfc9

Browse files
committed
esp32s3: fix boot crash caused by LLVM 22 / lld l32r relocation bug
Replace movi instructions with constants outside the 12-bit signed range (-2048..2047) with movi+slli sequences. Large constants cause the assembler to emit auto-generated .literal section entries, which triggers an lld bug where l32r PC-relative offsets are miscalculated when .literal.* sections are merged with .text.* sections. Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 2602d4c commit babdfc9

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/device/esp/esp32s3.S

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,14 @@ call_start_cpu0:
102102

103103
// ---- 1. Windowed-ABI register file setup ----
104104

105-
// Disable WOE so we can safely manipulate WINDOWSTART.
105+
// Disable WOE (bit 18 of PS).
106+
// Avoid large movi constants to prevent auto-generated .literal section
107+
// entries, which cause l32r offset miscalculation in LLVM 22 / lld.
106108
rsr.ps a2
107-
movi a3, ~(PS_WOE)
108-
and a2, a2, a3
109+
movi a3, 1
110+
slli a3, a3, 18 // a3 = PS_WOE (0x40000)
111+
and a3, a2, a3 // isolate WOE bit
112+
xor a2, a2, a3 // clear WOE bit
109113
wsr.ps a2
110114
rsync
111115

@@ -122,7 +126,8 @@ call_start_cpu0:
122126

123127
// Re-enable WOE.
124128
rsr.ps a2
125-
movi a3, PS_WOE
129+
movi a3, 1
130+
slli a3, a3, 18 // a3 = PS_WOE (0x40000)
126131
or a2, a2, a3
127132
wsr.ps a2
128133
rsync
@@ -213,7 +218,9 @@ call_start_cpu0:
213218
// and cannot service flash accesses.
214219

215220
// 4a. Configure ICache mode: 16KB, 8-way, 32-byte line
216-
movi a6, 0x4000 // cache_size = 16KB
221+
// Use movi+slli to avoid auto-literal generation (lld l32r bug).
222+
movi a6, 1
223+
slli a6, a6, 14 // a6 = 0x4000 = 16KB
217224
movi a7, 8 // ways = 8
218225
movi a8, 32 // line_size = 32
219226
mov a5, a1
@@ -226,7 +233,8 @@ call_start_cpu0:
226233
callx4 a4
227234

228235
// 4c. Configure DCache mode: 32KB, 8-way, 32-byte line
229-
movi a6, 0x8000 // cache_size = 32KB
236+
movi a6, 1
237+
slli a6, a6, 15 // a6 = 0x8000 = 32KB
230238
movi a7, 8 // ways = 8
231239
movi a8, 32 // line_size = 32
232240
mov a5, a1

0 commit comments

Comments
 (0)