Skip to content

Commit 35684b1

Browse files
committed
arm exception level emulator entry examples
1 parent 0700030 commit 35684b1

File tree

3 files changed

+79
-8
lines changed

3 files changed

+79
-8
lines changed

README.adoc

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10396,19 +10396,77 @@ help architecture
1039610396

1039710397
shows ARM version up to `armv6`, so maybe `armv6` is not implemented?
1039810398

10399-
=== ARM EL
10399+
=== ARM exception level
1040010400

10401-
Find the ARM EL: https://stackoverflow.com/questions/31787617/what-is-the-current-execution-mode-exception-level-etc
10401+
ARM exception levels are analogous to x86 <<ring0,rings>>.
1040210402

10403-
Prints the EL at the beginning of a baremetal simulation:
10403+
Print the EL at the beginning of a baremetal simulation:
1040410404

1040510405
....
10406+
./run --arch arm --baremetal arch/arm/el
1040610407
./run --arch aarch64 --baremetal arch/aarch64/el
1040710408
....
1040810409

10409-
Source: link:baremetal/arch/aarch64/el.c[]
10410+
Sources:
10411+
10412+
* link:baremetal/arch/arm/el.c[]
10413+
* link:baremetal/arch/aarch64/el.c[]
10414+
10415+
The instructions that find the ARM EL are explained at: https://stackoverflow.com/questions/31787617/what-is-the-current-execution-mode-exception-level-etc
10416+
10417+
The lower ELs are not mandated by the architecture, and can be controlled through command line options in QEMU and gem5.
10418+
10419+
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
10420+
10421+
....
10422+
./run --arch arm --baremetal arch/arm/el
10423+
./run --arch arm --baremetal arch/arm/el -- -machine virtualization=on
10424+
./run --arch arm --baremetal arch/arm/el -- -machine secure=on
10425+
./run --arch aarch64 --baremetal arch/aarch64/el
10426+
./run --arch aarch64 --baremetal arch/aarch64/el -- -machine virtualization=on
10427+
./run --arch aarch64 --baremetal arch/aarch64/el -- -machine secure=on
10428+
....
10429+
10430+
outputs respectively:
10431+
10432+
....
10433+
19
10434+
19
10435+
19
10436+
1
10437+
2
10438+
3
10439+
....
10440+
10441+
TODO: why is `arm` stuck at `19` which equals Supervisor mode?
10442+
10443+
In gem5, you can configure the lowest EL with:
10444+
10445+
....
10446+
./run --arch arm --baremetal arch/arm/el --gem5
10447+
cat "$(./getvar --arch arm --gem5 gem5_guest_terminal_file)"
10448+
./run --arch arm --baremetal arch/arm/el --gem5 -- --param 'system.have_virtualization = True'
10449+
cat "$(./getvar --arch arm --gem5 gem5_guest_terminal_file)"
10450+
./run --arch arm --baremetal arch/arm/el --gem5 -- --param 'system.have_security = True'
10451+
cat "$(./getvar --arch arm --gem5 gem5_guest_terminal_file)"
10452+
./run --arch aarch64 --baremetal arch/aarch64/el --gem5
10453+
cat "$(./getvar --arch aarch64 --gem5 gem5_guest_terminal_file)"
10454+
./run --arch aarch64 --baremetal arch/aarch64/el --gem5 -- --param 'system.have_virtualization = True'
10455+
cat "$(./getvar --arch aarch64 --gem5 gem5_guest_terminal_file)"
10456+
./run --arch aarch64 --baremetal arch/aarch64/el --gem5 -- --param 'system.have_security = True'
10457+
cat "$(./getvar --arch aarch64 --gem5 gem5_guest_terminal_file)"
10458+
....
1041010459

10411-
The lower ELs are not mandatory, and in gem5 at least you can configure the lowest EL with configuration options TODO which, example.
10460+
output:
10461+
10462+
....
10463+
19
10464+
26
10465+
19
10466+
1
10467+
2
10468+
3
10469+
....
1041210470

1041310471
=== How we got some baremetal stuff to work
1041410472

baremetal/arch/aarch64/el.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
/* https://github.com/cirosantilli/linux-kernel-module-cheat#arm-exception-level */
2+
13
#include <stdio.h>
24
#include <inttypes.h>
35

46
int main(void) {
5-
register uint64_t x0 __asm__ ("x0");
6-
__asm__ ("mrs x0, CurrentEL;" : : : "%x0");
7-
printf("%" PRIu64 "\n", x0);
7+
register uint64_t x0 __asm__ ("x0");
8+
__asm__ ("mrs x0, CurrentEL;" : : : "%x0");
9+
printf("%" PRIu64 "\n", x0 >> 2);
810
return 0;
911
}

baremetal/arch/arm/el.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* https://github.com/cirosantilli/linux-kernel-module-cheat#arm-exception-level */
2+
3+
#include <stdio.h>
4+
#include <inttypes.h>
5+
6+
int main(void) {
7+
register uint32_t r0 __asm__ ("r0");
8+
__asm__ ("mrs r0, CPSR" : : : "%r0");
9+
printf("%" PRIu32 "\n", r0 & 0x1F);
10+
return 0;
11+
}

0 commit comments

Comments
 (0)