mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
arm: thumb understanding++
This commit is contained in:
21
userland/arch/aarch64/dump_regs.c
Normal file
21
userland/arch/aarch64/dump_regs.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/* Dump non-EL0 readable registers. We need a separate program from EL0
|
||||
* because we cannot determine the current EL from EL0, since CurrentEL
|
||||
* cannot be read from it.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
int main(void) {
|
||||
uint32_t sctlr_el1;
|
||||
__asm__ ("mrs %0, sctlr_el1" : "=r" (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;
|
||||
}
|
||||
16
userland/arch/arm/dump_regs.c
Normal file
16
userland/arch/arm/dump_regs.c
Normal file
@@ -0,0 +1,16 @@
|
||||
/* Dump ARM registers that can be read in EL0 (and higher). */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
int main(void) {
|
||||
uint32_t cpsr;
|
||||
uint32_t cpsr_m;
|
||||
__asm__ ("mrs %0, cpsr" : "=r" (cpsr) : :);
|
||||
printf("CPSR 0x%" PRIX32 "\n", cpsr);
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#arm-exception-levels */
|
||||
cpsr_m = cpsr & 0xF;
|
||||
printf("CPSR.M 0x%" PRIX32 "\n", cpsr_m);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
.text
|
||||
.global _start
|
||||
_start:
|
||||
asm_main_after_prologue:
|
||||
/* write */
|
||||
mov r0, 1 /* stdout */
|
||||
adr r1, msg /* buffer */
|
||||
|
||||
22
userland/arch/arm/freestanding/linux/hello_thumb.S
Normal file
22
userland/arch/arm/freestanding/linux/hello_thumb.S
Normal file
@@ -0,0 +1,22 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#arm-thumb-encoding */
|
||||
|
||||
.thumb_func
|
||||
.syntax unified
|
||||
.text
|
||||
.global _start
|
||||
_start:
|
||||
asm_main_after_prologue:
|
||||
/* write */
|
||||
mov r0, 1 /* stdout */
|
||||
adr r1, msg /* buffer */
|
||||
ldr r2, =len /* len */
|
||||
mov r7, 4 /* syscall number */
|
||||
svc 0
|
||||
|
||||
/* exit */
|
||||
mov r0, 0 /* exit status */
|
||||
mov r7, 1 /* syscall number */
|
||||
svc 0
|
||||
msg:
|
||||
.ascii "hello\n"
|
||||
len = . - msg
|
||||
@@ -1,21 +1,12 @@
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#arm-instruction-encodings
|
||||
*
|
||||
* Illustrates features that are only available in thumb.
|
||||
* TODO ensure that we are actually inside of thumb.
|
||||
*/
|
||||
/* https://github.com/cirosantilli/linux-kernel-module-cheat#arm-thumb-encoding */
|
||||
|
||||
#include <lkmc.h>
|
||||
|
||||
.syntax unified
|
||||
.text
|
||||
.thumb_func
|
||||
.global main
|
||||
main:
|
||||
main_after_prologue:
|
||||
LKMC_PROLOGUE
|
||||
|
||||
/* CBZ: cmp and branch if zero instruction. Equivalent to CMP + BEQ.
|
||||
* TODO create an interesting assertion here.
|
||||
*/
|
||||
/* TODO: #if 0 something that is not thumb encodable. */
|
||||
cbz r1, 1f
|
||||
1:
|
||||
|
||||
mov r0, 0
|
||||
bx lr
|
||||
LKMC_EPILOGUE
|
||||
|
||||
Reference in New Issue
Block a user