dwelch67 / raspberrypi

Raspberry Pi ARM based bare metal examples
2.7k stars 483 forks source link

Save ELR_hyp and cpsr in pi 2 blinker 5 #40

Open Dan12 opened 5 years ago

Dan12 commented 5 years ago

https://github.com/dwelch67/raspberrypi/blob/cbb3a102d83dfeb4586e503749111d1bfbf8fc88/boards/pi2/HYP/blinker05/vectors.s#L54

Since we are dealing with the raspberry pi 2 in hypervisor mode I think it is a bit misleading to just save those registers in the irq handler since the actual lr used by eret is ELR_hyp. Additionally, the cpsr register has some important information for conditional instructions that should be saved across the irq handler.

I think adding the following code would be beneficial for users:

  mrs r0, ELR_hyp
  mrs r1, cpsr
  push {r0, r1}
  bl c_irq_handler
  pop {r0, r1}
  msr ELR_hyp, r0 
  msr cpsr, r1

(for context, I was trying to implement context switching for a bare metal os and the lack of state saving caused a few bugs for me 😄)