This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:multiasm:paarm:chapter_5_3 [2025/12/02 22:54] – [CPU registers] eriks.klavins | en:multiasm:paarm:chapter_5_3 [2025/12/11 08:14] (current) – [CPU Configuration] eriks.klavins | ||
|---|---|---|---|
| Line 44: | Line 44: | ||
| ===== CPU Configuration===== | ===== CPU Configuration===== | ||
| - | For Raspberry | + | The Raspberry |
| - | IMAGE IMAGE | + | ''< |
| + | |||
| + | ''< | ||
| + | |||
| + | {{: | ||
| + | |||
| + | In the image, all of the exception levels are visualised. The Orange area is so-called the untrusted or non-secure state. The region with a blue background is the Operating System and its parts and applications. User applications can request resources using SVC (supervisor calls), or on Raspberry Pi OS (and others), this is called SysCalls. The operating system is treated as a separate program on the exception level EL1 from the EL2 perspective. If the hypervisor is available, the OS may request resources via HVC (Hypervisor calls), and the hypervisor can request resources from the secure monitor via SMC (Secure monitor calls). On Raspberry Pi 5, the bootloader runs on EL3, loading memory and initialising the hardware. Then the operating system is started at the EL1 level, and the rest of the applications in the OS are at the EL0 level. Raspberry Pi 5 does not have hypervisor software, which is why Exception Level 2 is not used. | ||
| + | The Green region is a Secure State where only special secure applications and operating systems are executed. This may be used in system duplication, | ||
| We will look only at AArch64 registers to narrow the number of registers. | We will look only at AArch64 registers to narrow the number of registers. | ||
| - | There are a lot of registers dedicated to the CPU. Specialised registers will be left aside again to narrow the amount of information, | + | There are many registers dedicated to the CPU. Specialised registers will be left aside again to narrow the amount of information, |
| + | |||
| + | <table tab_label> | ||
| + | < | ||
| + | ^ Register | ||
| + | | AFSR0_EL1..3 and AFSR1_EL1..2 | ||
| + | | DBGAUTHSTATUS_EL1 | ||
| + | | DISR_EL1 | The Deferred Interrupt Status Register stores the records that an ESB (Error synchronisation barrier) instruction has consumed an SError (System Error) exception. | | ||
| + | | DSPSR_EL0 | The Debug Saved Program Status Register holds the saved process state for the Debug state. When entering the Debug state, PSTATE information is written in this register. Values are copied from this register to PSTATE on exiting the Debug state.| | ||
| + | | ERXGSR_EL1 | The Selected Error Record Group Status Register shows the status | ||
| + | | ERXSTATUS_EL1 | Selected Error Record Primary Status Register Accesses ERR< | ||
| + | | **FPSR** | The Floating-point Status Register provides floating-point system status information. | | ||
| + | | ICH_EISR_EL2 | Interrupt Controller End of Interrupt Status Register indicates which List registers have outstanding EOI (End Of Interrupt) maintenance interrupts. | | ||
| + | | ICH_ELRSR_EL2 | Interrupt Controller Empty List Register Status Register. These registers can locate a usable List register when the hypervisor delivers an interrupt to a VM (Virtual Machine). | | ||
| + | | IFSR32_EL2 | The Instruction Fault Status Register (EL2) allows access to the AArch32 IFSR register only from AArch64 state. Its value does not affect execution in AArch64 state. | | ||
| + | | ISR_EL1 | Interrupt Status Register shows the pending status of IRQ and FIQ interrupts and SError exceptions. | | ||
| + | | MDCCSR_EL0 | Monitor DCC Status Register is a read-only register containing control status flags for the DCC (Debug Communications Channel) | | ||
| + | | OSLSR_EL1 | OS Lock Status Register provides the status of the OS Lock. | | ||
| + | | **SPSR_EL1..3** | The Saved Program Status Register (EL1..EL3) holds the saved process state when an exception is taken to EL1, EL2, or EL3. | | ||
| + | | **SPSR_abt** | Saved Program Status Register (Abort mode) holds the saved process state when an exception is taken to Abort mode. | | ||
| + | | **SPSR_fiq** | The Saved Program Status Register (FIQ mode) holds the saved process state when an exception is taken into FIQ mode. | | ||
| + | | **SPSR_irq** | Saved Program Status Register (IRQ mode) holds the saved process state when an exception is taken to IRQ mode. | | ||
| + | | **SPSR_und** | Saved Program Status Register (Undefined mode) holds the saved process state when an exception is taken to Undefined mode. | | ||
| + | | TFSRE0_EL1 | The Tag Fault Status Register (EL0) holds accumulated Tag Check Faults occurring in EL0 that are not taken precisely. | | ||
| + | | TFSR_EL1..3 | Tag Fault Status Register (EL1..EL3) holds accumulated Tag Check Faults occurring in EL1, EL2 or EL3 that are not taken precisely | | ||
| + | | TRCAUTHSTATUS | The Trace Authentication Status Register provides information about the authentication interface' | ||
| + | | TRCOSLSR | Trace OS Lock Status Register returns the status of the Trace OS Lock | | ||
| + | | TRCRSR | The Trace Resources Status Register is used to set or read the status of the resources. | | ||
| + | | TRCSSCSR< | ||
| + | | TRCSTATR | Trace Status Register returns the trace unit status. | | ||
| + | | VDISR_EL2..3 | Virtual Deferred Interrupt Status Register (EL2..EL3) Records that a SError exception has been consumed by an ESB instruction executed at EL1 or EL2. | | ||
| + | </ | ||
| + | |||
| + | You can see how many states this processor has. Not all of them are used during program execution. Many registers are related to debugging and resource management. On the Raspberry Pi, the OS and bootloader have already configured all CPU Cores and the registers. Trace registers are used only when hardware debugging is enabled, such as JTAG or TRACE32. | ||
| + | Summarising: | ||
| + | |||
| + | There are rules for creating a Linux OS kernel module – it must contain functions that initialise the module and exit when the job is finished. The skeleton for the kernel module is given below in C. It will require a GCC compiler to compile the code, but inline assembly can be written directly in the code itself. After changing the Exception level from EL0 to EL1, only some system instruction executions will be allowed. | ||
| + | |||
| + | < | ||
| + | < | ||
| + | < | ||
| + | // mymod.c | ||
| + | #include < | ||
| + | #include < | ||
| - | TABLE | + | static int __init mymod_init(void) |
| + | { | ||
| + | asm volatile( | ||
| + | "mrs x0, CurrentEL\n" | ||
| + | "lsr x0, x0, # | ||
| + | // x0 now contains current EL (expect 1) | ||
| + | ); | ||
| + | pr_info(" | ||
| + | return 0; | ||
| + | } | ||
| + | static void __exit mymod_exit(void) | ||
| + | { | ||
| + | pr_info(" | ||
| + | } | ||
| + | module_init(mymod_init); | ||
| + | module_exit(mymod_exit); | ||
| + | MODULE_LICENSE(" | ||
| + | </ | ||
| + | </ | ||
| + | There are restrictions on the use of privileged instructions in the code. In EL0, privileged instruction execution will trap into the kernel. Note that switching between EL0 and EL1 is allowed only in the kernel and firmware. The firmware code will require access to the whole chip documentation, | ||