зеркало из https://github.com/microsoft/Komodo.git
SMC test code
* avoid trampling r4 * changed from -march=armv7-a to -mcpu=cortex-a7 to enable SMC instruction (why?)
This commit is contained in:
Родитель
a4eeeec048
Коммит
5017bee158
6
Makefile
6
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
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
void smchandler(void)
|
||||
#include <stdint.h>
|
||||
|
||||
uintptr_t smchandler(void)
|
||||
{
|
||||
return 0x37;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче