Skip to content

Commit

Permalink
arm64: Avoid clobbering the stack pointer when returning to EL1
Browse files Browse the repository at this point in the history
We use x18 as a temp register but in hybrid kernels this is clobbered when
restoring callee-saved registers.
  • Loading branch information
markjdb committed Jan 1, 2025
1 parent 3100761 commit fb0e4b1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sys/arm64/arm64/exception.S
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,17 @@
* registers so must always do this.
*/
#endif
.if \el == 1
/*
* In the kernel, x18 is always used as the per-CPU data pointer and is
* reset to the value in tpidr_el1 further below. At this point when
* returning to EL1, x18 contains the saved stack pointer, so be careful
* not to clobber it.
*/
ldr CAP(19), [PTRN(sp), #(TF_X + 19 * CAP_WIDTH)]
.else
ldp CAP(18), CAP(19), [PTRN(sp), #(TF_X + 18 * CAP_WIDTH)]
.endif
ldp CAP(20), CAP(21), [PTRN(sp), #(TF_X + 20 * CAP_WIDTH)]
ldp CAP(22), CAP(23), [PTRN(sp), #(TF_X + 22 * CAP_WIDTH)]
ldp CAP(24), CAP(25), [PTRN(sp), #(TF_X + 24 * CAP_WIDTH)]
Expand Down

0 comments on commit fb0e4b1

Please sign in to comment.