mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
baremetal: move aarch64 el.c into dump_regs.c
Also start disassembling registers nicely dump_regs so we can have a single executable to handle all register queries.
This commit is contained in:
70
README.adoc
70
README.adoc
@@ -13376,14 +13376,14 @@ ARM exception levels are analogous to x86 <<ring0,rings>>.
|
|||||||
Print the EL at the beginning of a baremetal simulation:
|
Print the EL at the beginning of a baremetal simulation:
|
||||||
|
|
||||||
....
|
....
|
||||||
./run --arch arm --baremetal baremetal/arch/arm/el.c
|
./run --arch arm --baremetal baremetal/arch/arm/dump_regs.c
|
||||||
./run --arch aarch64 --baremetal baremetal/arch/aarch64/el.c
|
./run --arch aarch64 --baremetal baremetal/arch/aarch64/dump_regs.c
|
||||||
....
|
....
|
||||||
|
|
||||||
Sources:
|
Sources:
|
||||||
|
|
||||||
* link:baremetal/arch/arm/el.c[]
|
* link:baremetal/arch/arm/dump_regs.c[]
|
||||||
* link:baremetal/arch/aarch64/el.c[]
|
* link:baremetal/arch/aarch64/dump_regs.c[]
|
||||||
|
|
||||||
The instructions that find the ARM EL are explained at: https://stackoverflow.com/questions/31787617/what-is-the-current-execution-mode-exception-level-etc
|
The instructions that find the ARM EL are explained at: https://stackoverflow.com/questions/31787617/what-is-the-current-execution-mode-exception-level-etc
|
||||||
|
|
||||||
@@ -13392,53 +13392,53 @@ The lower ELs are not mandated by the architecture, and can be controlled throug
|
|||||||
In QEMU, you can configure the lowest EL as explained at https://stackoverflow.com/questions/42824706/qemu-system-aarch64-entering-el1-when-emulating-a53-power-up
|
In QEMU, you can configure the lowest EL as explained at https://stackoverflow.com/questions/42824706/qemu-system-aarch64-entering-el1-when-emulating-a53-power-up
|
||||||
|
|
||||||
....
|
....
|
||||||
./run --arch arm --baremetal baremetal/arch/arm/el.c
|
./run --arch arm --baremetal baremetal/arch/arm/dump_regs.c | grep CPSR.M
|
||||||
./run --arch arm --baremetal baremetal/arch/arm/el.c -- -machine virtualization=on
|
./run --arch arm --baremetal baremetal/arch/arm/dump_regs.c -- -machine virtualization=on | grep CPSR.M
|
||||||
./run --arch arm --baremetal baremetal/arch/arm/el.c -- -machine secure=on
|
./run --arch arm --baremetal baremetal/arch/arm/dump_regs.c -- -machine secure=on | grep CPSR.M
|
||||||
./run --arch aarch64 --baremetal baremetal/arch/aarch64/el.c
|
./run --arch aarch64 --baremetal baremetal/arch/aarch64/dump_regs.c | grep CurrentEL.EL
|
||||||
./run --arch aarch64 --baremetal baremetal/arch/aarch64/el.c -- -machine virtualization=on
|
./run --arch aarch64 --baremetal baremetal/arch/aarch64/dump_regs.c -- -machine virtualization=on | grep CurrentEL.EL
|
||||||
./run --arch aarch64 --baremetal baremetal/arch/aarch64/el.c -- -machine secure=on
|
./run --arch aarch64 --baremetal baremetal/arch/aarch64/dump_regs.c -- -machine secure=on | grep CurrentEL.EL
|
||||||
....
|
....
|
||||||
|
|
||||||
outputs respectively:
|
outputs respectively:
|
||||||
|
|
||||||
....
|
....
|
||||||
19
|
CPSR.M 0x3
|
||||||
19
|
CPSR.M 0x3
|
||||||
19
|
CPSR.M 0x3
|
||||||
1
|
CurrentEL.EL 0x1
|
||||||
2
|
CurrentEL.EL 0x2
|
||||||
3
|
CurrentEL.EL 0x3
|
||||||
....
|
....
|
||||||
|
|
||||||
TODO: why is `arm` stuck at `19` which equals Supervisor mode?
|
TODO: why is arm `CPSR.M` stuck at `0x3` which equals Supervisor mode?
|
||||||
|
|
||||||
In gem5, you can configure the lowest EL with:
|
In gem5, you can configure the lowest EL with:
|
||||||
|
|
||||||
....
|
....
|
||||||
./run --arch arm --baremetal baremeta/arch/arm/el.c --emulator gem5
|
./run --arch arm --baremetal baremetal/arch/arm/dump_regs.c --emulator gem5
|
||||||
cat "$(./getvar --arch arm --emulator gem5 gem5_guest_terminal_file)"
|
grep CPSR.M "$(./getvar --arch arm --emulator gem5 gem5_guest_terminal_file)"
|
||||||
./run --arch arm --baremetal baremetal/arch/arm/el.c --emulator gem5 -- --param 'system.have_virtualization = True'
|
./run --arch arm --baremetal baremetal/arch/arm/dump_regs.c --emulator gem5 -- --param 'system.have_virtualization = True'
|
||||||
cat "$(./getvar --arch arm --emulator gem5 gem5_guest_terminal_file)"
|
grep CPSR.M "$(./getvar --arch arm --emulator gem5 gem5_guest_terminal_file)"
|
||||||
./run --arch arm --baremetal baremetal/arch/arm/el.c --emulator gem5 -- --param 'system.have_security = True'
|
./run --arch arm --baremetal baremetal/arch/arm/dump_regs.c --emulator gem5 -- --param 'system.have_security = True'
|
||||||
cat "$(./getvar --arch arm --emulator gem5 gem5_guest_terminal_file)"
|
grep CPSR.M "$(./getvar --arch arm --emulator gem5 gem5_guest_terminal_file)"
|
||||||
./run --arch aarch64 --baremetal baremetal/arch/aarch64/el.c --emulator gem5
|
./run --arch aarch64 --baremetal baremetal/arch/aarch64/dump_regs.c --emulator gem5
|
||||||
cat "$(./getvar --arch aarch64 --emulator gem5 gem5_guest_terminal_file)"
|
grep CurrentEL.EL "$(./getvar --arch aarch64 --emulator gem5 gem5_guest_terminal_file)"
|
||||||
./run --arch aarch64 --baremetal baremetal/arch/aarch64/el.c --emulator gem5 -- --param 'system.have_virtualization = True'
|
./run --arch aarch64 --baremetal baremetal/arch/aarch64/dump_regs.c --emulator gem5 -- --param 'system.have_virtualization = True'
|
||||||
cat "$(./getvar --arch aarch64 --emulator gem5 gem5_guest_terminal_file)"
|
grep CurrentEL.EL "$(./getvar --arch aarch64 --emulator gem5 gem5_guest_terminal_file)"
|
||||||
./run --arch aarch64 --baremetal baremetal/arch/aarch64/el.c --emulator gem5 -- --param 'system.have_security = True'
|
./run --arch aarch64 --baremetal baremetal/arch/aarch64/dump_regs.c --emulator gem5 -- --param 'system.have_security = True'
|
||||||
cat "$(./getvar --arch aarch64 --emulator gem5 gem5_guest_terminal_file)"
|
grep CurrentEL.EL "$(./getvar --arch aarch64 --emulator gem5 gem5_guest_terminal_file)"
|
||||||
....
|
....
|
||||||
|
|
||||||
output:
|
output:
|
||||||
|
|
||||||
....
|
....
|
||||||
19
|
CPSR.M 0x3
|
||||||
26
|
CPSR.M 0x3
|
||||||
19
|
CPSR.M 0x3
|
||||||
1
|
CurrentEL.EL 0x1
|
||||||
2
|
CurrentEL.EL 0x2
|
||||||
3
|
CurrentEL.EL 0x3
|
||||||
....
|
....
|
||||||
|
|
||||||
==== svc
|
==== svc
|
||||||
|
|||||||
@@ -6,6 +6,13 @@
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
uint32_t sctlr_el1;
|
uint32_t sctlr_el1;
|
||||||
__asm__ ("mrs %0, sctlr_el1" : "=r" (sctlr_el1) : :);
|
__asm__ ("mrs %0, sctlr_el1" : "=r" (sctlr_el1) : :);
|
||||||
printf("sctlr_el1 0x%" PRIx32 "\n", sctlr_el1);
|
printf("SCTLR_EL1 0x%" PRIX32 "\n", sctlr_el1);
|
||||||
|
printf("SCTLR_EL1.A 0x%" PRIX32 "\n", (sctlr_el1 >> 1) & 1);
|
||||||
|
|
||||||
|
uint64_t CurrentEL;
|
||||||
|
__asm__ ("mrs %0, CurrentEL;" : "=r" (CurrentEL) : :);
|
||||||
|
printf("CurrentEL 0x%" PRIX64 "\n", CurrentEL);
|
||||||
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#arm-exception-levels */
|
||||||
|
printf("CurrentEL.EL 0x%" PRIX64 "\n", CurrentEL >> 2);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#arm-exception-levels */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
uint64_t el;
|
|
||||||
__asm__ ("mrs %0, CurrentEL;" : "=r" (el) : :);
|
|
||||||
printf("%" PRIu64 "\n", el >> 2);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -4,12 +4,14 @@
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
uint32_t cpsr;
|
uint32_t cpsr;
|
||||||
__asm__ ("mrs %0, cpsr" : "=r" (cpsr) : :);
|
__asm__ ("mrs %0, cpsr" : "=r" (cpsr) : :);
|
||||||
printf("cpsr %" PRIx32 "\n", cpsr);
|
printf("CPSR 0x%" PRIX32 "\n", cpsr);
|
||||||
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#arm-exception-levels */
|
||||||
|
printf("CPSR.M 0x%" PRIX32 "\n", cpsr & 0xF);
|
||||||
|
|
||||||
/* TODO this is blowing up an exception, how to I read from it? */
|
/* TODO this is blowing up an exception, how to I read from it? */
|
||||||
/*uint32_t mvfr1;*/
|
/*uint32_t mvfr1;*/
|
||||||
/*__asm__ ("vmrs %0, mvfr1" : "=r" (mvfr1) : :);*/
|
/*__asm__ ("vmrs %0, mvfr1" : "=r" (mvfr1) : :);*/
|
||||||
/*printf("mvfr1 %" PRIx32 "\n", mvfr1);*/
|
/*printf("MVFR1 0x%" PRIX32 "\n", mvfr1);*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#arm-exception-levels */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
uint32_t cpsr;
|
|
||||||
__asm__ ("mrs %0, CPSR" : "=r" (cpsr) : :);
|
|
||||||
printf("%" PRIu32 "\n", cpsr & 0x1F);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user