aarch64-cpu icon indicating copy to clipboard operation
aarch64-cpu copied to clipboard

Access to AArch32 view of AArch64 registers

Open CUB3D opened this issue 2 months ago • 3 comments

When running a AArch32 guest (EL1) under a AArch64 hypervisor (EL2) it is useful for the hypervisor to be able to access the registers of the guest, for example SPSR_hyp. Accessing these AArch32 registers directly via MRS is not possible from AArch64 code, so they can't be accessed using AArch32 libraries e.g. aarch32-cpu. Instead these registers are mapped to relevant AArch64 registers, like the low 32-bits of SPSR_EL2 in this case.

In these situations the fields of the registers differ from the AArch64 fields, e.g bit 23 of SPSR_EL2 is UAO for AArch64, whereas in AArch32 this is the SSBS field. Currently accessing these fields with this library isn't possible.

I see a few ways to handle this: 1: Simply have all fields as part of the register definition, specify via comments that they are only valid for A64 / A32. (field names match the docs) 2: Same as 1 but use a prefix to differentiate (A32_SSBS / A64_UAO) (field names don't match docs). This is what I'm currently maintaining on a fork. 3: Have two copies of registers where this applies SPSR_EL2_A32 / SPSR_EL2_A64

I don't really have a preference but I'd like to see this use case be supported if possible.

CUB3D avatar Oct 31 '25 14:10 CUB3D

I would probably keep aarch64 registers as they are now and add a shadow module like aarch32_view in which the guest register view would be defined.

This would allow to have a module level documentation for aarch32_view explaining why these definitions exist.

Wdyt?

berkus avatar Nov 05 '25 11:11 berkus

Does it make sense to import aarch32-cpu there and re-use the register definitions?

jonathanpallant avatar Nov 05 '25 12:11 jonathanpallant

Probably as an optional dep, might work.

berkus avatar Nov 05 '25 13:11 berkus

@CUB3D you wanna drive this further?

berkus avatar Nov 29 '25 15:11 berkus