Skip to content

Commit fb0e4b1

Browse files
committed
arm64: Avoid clobbering the stack pointer when returning to EL1
We use x18 as a temp register but in hybrid kernels this is clobbered when restoring callee-saved registers.
1 parent 3100761 commit fb0e4b1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

sys/arm64/arm64/exception.S

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,17 @@
181181
* registers so must always do this.
182182
*/
183183
#endif
184+
.if \el == 1
185+
/*
186+
* In the kernel, x18 is always used as the per-CPU data pointer and is
187+
* reset to the value in tpidr_el1 further below. At this point when
188+
* returning to EL1, x18 contains the saved stack pointer, so be careful
189+
* not to clobber it.
190+
*/
191+
ldr CAP(19), [PTRN(sp), #(TF_X + 19 * CAP_WIDTH)]
192+
.else
184193
ldp CAP(18), CAP(19), [PTRN(sp), #(TF_X + 18 * CAP_WIDTH)]
194+
.endif
185195
ldp CAP(20), CAP(21), [PTRN(sp), #(TF_X + 20 * CAP_WIDTH)]
186196
ldp CAP(22), CAP(23), [PTRN(sp), #(TF_X + 22 * CAP_WIDTH)]
187197
ldp CAP(24), CAP(25), [PTRN(sp), #(TF_X + 24 * CAP_WIDTH)]

0 commit comments

Comments
 (0)