Home > Net >  Access to AArch32 registers in AArch64 state
Access to AArch32 registers in AArch64 state

Time:02-27

I saw the following sentences when learning ARMv8 exception handing:

When taking an exception from AArch32 to AArch64, there are some special considerations. AArch64 handler code can require access to AArch32 registers and the architecture therefore defines mappings to allow access to AArch32 registers.

And there is the banking map: enter image description here

So I want to ask:

  1. When and why we need to access AArch32 registers in AArch64 state?
  2. Is this mapping table visible to programmers? Whether we need to write corresponding Wn when coding? or just Rn?

CodePudding user response:

A typical use case would be a 64-bit operating system that wants to be able to run 32-bit ARM application programs. It would run the application at EL0 in AArch32 state, while the OS runs at EL1 in AArch64 state.

Suppose the 32-bit application needs to make a system call. It will set up the arguments in the AArch32 registers and cause an exception with svc / swi. The OS's exception handler, running at EL1 in AArch64 state, needs to be able to retrieve the contents of those registers to process the system call appropriately. So the mapping tells it, for instance, that whatever the application wrote to r1 will be found in x1.

When writing code, you simply use whatever register set is available in the state (AArch32/AArch64) you are writing for. For 32-bit code you write r0, r1, r2, etc, and for 64-bit code you use w0/x0, w1/x1, etc. For application programming, the mapping is irrelevant, and only comes into play if you are writing OS code that needs to interface between the two states.

  • Related