mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
arm baremetal: SVC explain where the imm16 can be retrieved
Use upper case hex literals on all PRIXnn. .gitignore /out.docker
This commit is contained in:
@@ -11,55 +11,68 @@ int myvar = 0;
|
||||
|
||||
void lkmc_vector_trap_handler(LkmcVectorExceptionFrame *exception) {
|
||||
puts("lkmc_vector_trap_handler");
|
||||
printf("exc_type 0x%" PRIx64 "\n", exception->exc_type);
|
||||
printf("exc_type 0x%" PRIX64 "\n", exception->exc_type);
|
||||
if (exception->exc_type == LKMC_VECTOR_SYNC_SPX) {
|
||||
puts("exc_type is LKMC_VECTOR_SYNC_SPX");
|
||||
}
|
||||
printf("ESR 0x%" PRIx64 "\n", exception->exc_esr);
|
||||
printf("SP 0x%" PRIx64 "\n", exception->exc_sp);
|
||||
printf("ELR 0x%" PRIx64 "\n", exception->exc_elr);
|
||||
printf("SPSR 0x%" PRIx64 "\n", exception->exc_spsr);
|
||||
printf("x0 0x%" PRIx64 "\n", exception->x0);
|
||||
printf("x1 0x%" PRIx64 "\n", exception->x1);
|
||||
printf("x2 0x%" PRIx64 "\n", exception->x2);
|
||||
printf("x3 0x%" PRIx64 "\n", exception->x3);
|
||||
printf("x4 0x%" PRIx64 "\n", exception->x4);
|
||||
printf("x5 0x%" PRIx64 "\n", exception->x5);
|
||||
printf("x6 0x%" PRIx64 "\n", exception->x6);
|
||||
printf("x7 0x%" PRIx64 "\n", exception->x7);
|
||||
printf("x8 0x%" PRIx64 "\n", exception->x8);
|
||||
printf("x9 0x%" PRIx64 "\n", exception->x9);
|
||||
printf("x10 0x%" PRIx64 "\n", exception->x10);
|
||||
printf("x11 0x%" PRIx64 "\n", exception->x11);
|
||||
printf("x12 0x%" PRIx64 "\n", exception->x12);
|
||||
printf("x13 0x%" PRIx64 "\n", exception->x13);
|
||||
printf("x14 0x%" PRIx64 "\n", exception->x14);
|
||||
printf("x15 0x%" PRIx64 "\n", exception->x15);
|
||||
printf("x16 0x%" PRIx64 "\n", exception->x16);
|
||||
printf("x17 0x%" PRIx64 "\n", exception->x17);
|
||||
printf("x18 0x%" PRIx64 "\n", exception->x18);
|
||||
printf("x19 0x%" PRIx64 "\n", exception->x19);
|
||||
printf("x20 0x%" PRIx64 "\n", exception->x20);
|
||||
printf("x21 0x%" PRIx64 "\n", exception->x21);
|
||||
printf("x22 0x%" PRIx64 "\n", exception->x22);
|
||||
printf("x23 0x%" PRIx64 "\n", exception->x23);
|
||||
printf("x24 0x%" PRIx64 "\n", exception->x24);
|
||||
printf("x25 0x%" PRIx64 "\n", exception->x25);
|
||||
printf("x26 0x%" PRIx64 "\n", exception->x26);
|
||||
printf("x27 0x%" PRIx64 "\n", exception->x27);
|
||||
printf("x28 0x%" PRIx64 "\n", exception->x28);
|
||||
printf("x29 0x%" PRIx64 "\n", exception->x29);
|
||||
printf("x30 0x%" PRIx64 "\n", exception->x30);
|
||||
printf("ESR 0x%" PRIX64 "\n", exception->exc_esr);
|
||||
uint64_t esr_ec = (exception->exc_esr >> 26) & 0x3F;
|
||||
uint64_t iss = exception->exc_esr & 0xFFFFFF;
|
||||
printf("ESR.EC 0x%" PRIX64 "\n", esr_ec);
|
||||
if (
|
||||
esr_ec == LKMC_ESR_EC_SVC_AARCH32 ||
|
||||
esr_ec == LKMC_ESR_EC_SVC_AARCH64
|
||||
) {
|
||||
printf("ESR.EC.ISS.imm16 0x%" PRIX64 "\n", iss & 0xFFFF);
|
||||
}
|
||||
printf("SP 0x%" PRIX64 "\n", exception->exc_sp);
|
||||
printf("ELR 0x%" PRIX64 "\n", exception->exc_elr);
|
||||
printf("SPSR 0x%" PRIX64 "\n", exception->exc_spsr);
|
||||
printf("x0 0x%" PRIX64 "\n", exception->x0);
|
||||
printf("x1 0x%" PRIX64 "\n", exception->x1);
|
||||
printf("x2 0x%" PRIX64 "\n", exception->x2);
|
||||
printf("x3 0x%" PRIX64 "\n", exception->x3);
|
||||
printf("x4 0x%" PRIX64 "\n", exception->x4);
|
||||
printf("x5 0x%" PRIX64 "\n", exception->x5);
|
||||
printf("x6 0x%" PRIX64 "\n", exception->x6);
|
||||
printf("x7 0x%" PRIX64 "\n", exception->x7);
|
||||
printf("x8 0x%" PRIX64 "\n", exception->x8);
|
||||
printf("x9 0x%" PRIX64 "\n", exception->x9);
|
||||
printf("x10 0x%" PRIX64 "\n", exception->x10);
|
||||
printf("x11 0x%" PRIX64 "\n", exception->x11);
|
||||
printf("x12 0x%" PRIX64 "\n", exception->x12);
|
||||
printf("x13 0x%" PRIX64 "\n", exception->x13);
|
||||
printf("x14 0x%" PRIX64 "\n", exception->x14);
|
||||
printf("x15 0x%" PRIX64 "\n", exception->x15);
|
||||
printf("x16 0x%" PRIX64 "\n", exception->x16);
|
||||
printf("x17 0x%" PRIX64 "\n", exception->x17);
|
||||
printf("x18 0x%" PRIX64 "\n", exception->x18);
|
||||
printf("x19 0x%" PRIX64 "\n", exception->x19);
|
||||
printf("x20 0x%" PRIX64 "\n", exception->x20);
|
||||
printf("x21 0x%" PRIX64 "\n", exception->x21);
|
||||
printf("x22 0x%" PRIX64 "\n", exception->x22);
|
||||
printf("x23 0x%" PRIX64 "\n", exception->x23);
|
||||
printf("x24 0x%" PRIX64 "\n", exception->x24);
|
||||
printf("x25 0x%" PRIX64 "\n", exception->x25);
|
||||
printf("x26 0x%" PRIX64 "\n", exception->x26);
|
||||
printf("x27 0x%" PRIX64 "\n", exception->x27);
|
||||
printf("x28 0x%" PRIX64 "\n", exception->x28);
|
||||
printf("x29 0x%" PRIX64 "\n", exception->x29);
|
||||
printf("x30 0x%" PRIX64 "\n", exception->x30);
|
||||
myvar = 1;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
/* View initial relevant register values. */
|
||||
printf("daif 0x%" PRIx32 "\n", lkmc_sysreg_daif_read());
|
||||
printf("spsel 0x%" PRIx32 "\n", lkmc_sysreg_spsel_read());
|
||||
printf("vbar_el1 0x%" PRIx64 "\n", lkmc_sysreg_vbar_el1_read());
|
||||
printf("DAIF 0x%" PRIX32 "\n", lkmc_sysreg_daif_read());
|
||||
printf("SPSEL 0x%" PRIX32 "\n", lkmc_sysreg_spsel_read());
|
||||
printf("VBAR_EL1 0x%" PRIX64 "\n", lkmc_sysreg_vbar_el1_read());
|
||||
/* https://stackoverflow.com/questions/1777990/is-it-possible-to-store-the-address-of-a-label-in-a-variable-and-use-goto-to-jum */
|
||||
printf("after_svc %p\n", &&after_svc);
|
||||
assert(myvar == 0);
|
||||
LKMC_SVC(0x42);
|
||||
/* Max 16-bits. */
|
||||
LKMC_SVC(0xABCD);
|
||||
after_svc:
|
||||
assert(myvar == 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
.global main
|
||||
main:
|
||||
/* Do the svc. */
|
||||
svc 0
|
||||
svc 0xABCD
|
||||
|
||||
/* Confirm that svc was called and modified myvar. */
|
||||
ldr x0, myvar
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <lkmc/gicv3.h>
|
||||
|
||||
void lkmc_vector_trap_handler(LkmcVectorExceptionFrame *exception __attribute__((unused))) {
|
||||
printf("CNTVCT_EL0 0x%" PRIx64 "\n", lkmc_sysreg_cntvct_el0_read());
|
||||
printf("CNTVCT_EL0 0x%" PRIX64 "\n", lkmc_sysreg_cntvct_el0_read());
|
||||
}
|
||||
|
||||
#define CNTV_CTL_ENABLE (1 << 0) /* Enables the timer */
|
||||
@@ -30,14 +30,14 @@ void enable_irq(void) {
|
||||
|
||||
int main(void) {
|
||||
/* Initial state. */
|
||||
printf("CNTV_CTL_EL0 0x%" PRIx32 "\n", lkmc_sysreg_cntv_ctl_el0_read());
|
||||
printf("CNTFRQ_EL0 0x%" PRIx64 "\n", lkmc_sysreg_cntfrq_el0_read());
|
||||
printf("CNTV_CVAL_EL0 0x%" PRIx64 "\n", lkmc_sysreg_cntv_cval_el0_read());
|
||||
printf("CNTV_CTL_EL0 0x%" PRIX32 "\n", lkmc_sysreg_cntv_ctl_el0_read());
|
||||
printf("CNTFRQ_EL0 0x%" PRIX64 "\n", lkmc_sysreg_cntfrq_el0_read());
|
||||
printf("CNTV_CVAL_EL0 0x%" PRIX64 "\n", lkmc_sysreg_cntv_cval_el0_read());
|
||||
|
||||
/* Get the counter value many times to watch the time pass. */
|
||||
printf("CNTVCT_EL0 0x%" PRIx64 "\n", lkmc_sysreg_cntvct_el0_read());
|
||||
printf("CNTVCT_EL0 0x%" PRIx64 "\n", lkmc_sysreg_cntvct_el0_read());
|
||||
printf("CNTVCT_EL0 0x%" PRIx64 "\n", lkmc_sysreg_cntvct_el0_read());
|
||||
printf("CNTVCT_EL0 0x%" PRIX64 "\n", lkmc_sysreg_cntvct_el0_read());
|
||||
printf("CNTVCT_EL0 0x%" PRIX64 "\n", lkmc_sysreg_cntvct_el0_read());
|
||||
printf("CNTVCT_EL0 0x%" PRIX64 "\n", lkmc_sysreg_cntvct_el0_read());
|
||||
|
||||
/**/
|
||||
gic_v3_initialize();
|
||||
@@ -66,7 +66,7 @@ int main(void) {
|
||||
/* TODO crashes gem5. */
|
||||
puts("cntfrq_el0 = 1");
|
||||
lkmc_sysreg_cntfrq_el0_write(1);
|
||||
printf("cntfrq_el0 0x%" PRIx64 "\n", lkmc_sysreg_cntfrq_el0_read());
|
||||
printf("cntfrq_el0 0x%" PRIX64 "\n", lkmc_sysreg_cntfrq_el0_read());
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -28,7 +28,10 @@ lkmc_start:
|
||||
|
||||
LKMC_VECTOR_TABLE
|
||||
|
||||
/* Default trap handler. */
|
||||
/* Default handler for exceptions. This is called after some basic
|
||||
* setup done on the initial handler. Since this is a weak symbol,
|
||||
* you can redefine it in your own example, and your definition
|
||||
* will take precedence. */
|
||||
LKMC_WEAK(lkmc_vector_trap_handler)
|
||||
ldr x0, =lkmc_vector_trap_handler_error_message
|
||||
bl puts
|
||||
|
||||
Reference in New Issue
Block a user