diff --git a/Makefile b/Makefile index 954657a..58a6d28 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ OBJCOPY = $(PREFIX)objcopy LIBGCC = $(shell $(CC) -print-libgcc-file-name) -CFLAGS_ALL = -Wall -Werror -ffreestanding -nostdinc -march=armv7-a -std=c99 -g -O -I include -I pdclib/include +CFLAGS_ALL = -Wall -Werror -ffreestanding -nostdinc -mcpu=cortex-a7 -std=c99 -g -O -I include -I pdclib/include LDFLAGS_ALL = -nostdlib all: piimage/kevlar.img @@ -27,8 +27,8 @@ qemu: piimage/kevlar.img qemugdb: piimage/kevlar.img qemu-system-arm $(QEMU_ARGS) -bios $< -S -gdb: piloader/piloader.elf - $(PREFIX)gdb --symbols=$< -ex 'target remote :1234' +gdb: piimage/kevlar.elf + $(PREFIX)gdb -ex 'target remote :1234' dir := pdclib include $(dir)/subdir.mk diff --git a/monitor/entry.S b/monitor/entry.S index 3edd6a3..18b25e5 100644 --- a/monitor/entry.S +++ b/monitor/entry.S @@ -33,9 +33,9 @@ _monitor_vectors: _monitor_start: /* start of day entry, invoked only by the loader */ /* compute stack and switch to it */ - getstackaddr ip, r4 - stmdb r4!, {sp,lr} - mov sp, r4 + getstackaddr ip, r3 + stmdb r3!, {sp,lr} + mov sp, r3 /* call C */ bl monitor_start @@ -49,8 +49,9 @@ _smchandler: /* TODO: figure out calling convention, and which registers to pass/save */ /* call C */ - getstackaddr ip, r4 - stmdb r4!, {sp,lr} + getstackaddr ip, r3 + stmdb r3!, {sp,lr} + mov sp, r3 bl smchandler /* TODO: scrub secrets from registers */ diff --git a/monitor/smchandler.c b/monitor/smchandler.c index ee8b996..686ebcf 100644 --- a/monitor/smchandler.c +++ b/monitor/smchandler.c @@ -1,3 +1,6 @@ -void smchandler(void) +#include + +uintptr_t smchandler(void) { + return 0x37; } diff --git a/piloader/main.c b/piloader/main.c index 6a418df..06563ff 100644 --- a/piloader/main.c +++ b/piloader/main.c @@ -152,6 +152,30 @@ static void map_l2_pages(armpte_short_l2 *l2pt, uintptr_t vaddr, uintptr_t paddr } } +static uintptr_t smc(uint8_t imm, uintptr_t arg0, uintptr_t arg1, uintptr_t arg2) +{ + register uintptr_t r0 __asm("r0") = arg0; + register uintptr_t r1 __asm("r1") = arg1; + register uintptr_t r2 __asm("r2") = arg2; + + __asm("smc %3" + : "+r" (r0), "+r" (r1), "+r" (r2) + : "M" (imm), "0" (r0), "1" (r1), "2" (r2) + : "r3" + ); + + return r0; +} + +static void smc_test(void) +{ + console_printf("SMC test...\n"); + + uintptr_t ret = smc(0,0,0,0); + + console_printf("SMC returned: %lx\n", ret); +} + void __attribute__((noreturn)) main(void) { uint8_t coreid = mycoreid(); @@ -246,7 +270,11 @@ void __attribute__((noreturn)) main(void) __asm volatile("mcr p15, 0, %0, c1, c1, 0" : : "r" (reg)); __asm volatile("isb"); - console_printf("exited secure world, entering kernel...\n"); + console_printf("exited secure world\n"); + + smc_test(); + + console_printf("entering kernel...\n"); typedef void kernel_entry(uintptr_t zero, uintptr_t boardid, void *atags); ((kernel_entry *)0x8000)(0, 0xc43, (void *)0x100);