WIP
This commit is contained in:
parent
113fed4ae1
commit
e392f01c65
11
Makefile
11
Makefile
@ -1,6 +1,6 @@
|
||||
all:
|
||||
arm-none-eabi-gcc -r -Tlibpqscheme.ld -fPIC -nostartfiles -o libpqscheme_test.elf libpqscheme_test.c -Iruntime_mps2/out/an386/pack/include
|
||||
arm-none-eabi-gcc -mcpu=Cortex-M4 -Truntime_mps2/out/an386/pack/lib/mps2.ld -nostartfiles -o runner.elf runner.c -Lruntime_mps2/out/an386/pack/lib -lmps2-an386_runtime -Iruntime_mps2/out/an386/pack/include
|
||||
arm-none-eabi-gcc -ggdb -mcpu=Cortex-M4 -mthumb -r -Tlibpqscheme.ld -fPIC -nostartfiles -o libpqscheme_test.elf libpqscheme_test.c -Iruntime_mps2/out/an386/pack/include
|
||||
arm-none-eabi-gcc -ggdb -mcpu=Cortex-M4 -mthumb -Truntime_mps2/out/an386/pack/lib/mps2.ld -nostartfiles -o runner.elf runner.c -Lruntime_mps2/out/an386/pack/lib -lmps2-an386_runtime -Iruntime_mps2/out/an386/pack/include
|
||||
arm-none-eabi-ar rcs runner runner.elf
|
||||
|
||||
arm-none-eabi-objcopy -O binary libpqscheme_test.elf libpqscheme_test.bin
|
||||
@ -11,8 +11,11 @@ run:
|
||||
-cpu cortex-m4 \
|
||||
-nographic \
|
||||
-kernel runner.elf \
|
||||
-initrd libpqscheme_test.elf \
|
||||
-semihosting
|
||||
-semihosting \
|
||||
-device loader,file=libpqscheme_test.elf,addr=0x00300000
|
||||
# -S -gdb tcp::1234
|
||||
# -monitor unix:/tmp/qemu-monitor,server,nowait
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf *.o *.a *.elf *.bin
|
||||
|
@ -1,18 +1,25 @@
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00300000, LENGTH = 0x00100000 /* Runner */
|
||||
RAM (rwx) : ORIGIN = 0x00000000, LENGTH = 16K
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.magic_header : {
|
||||
LONG(0x88DAD0F2) /* Magic header containing */
|
||||
LONG(ADDR(.text)) /* Entry point */
|
||||
LONG(0x88DAD0F3) /* Magic header containing */
|
||||
LONG(ADDR(.magic_header)) /* Entry point */
|
||||
} > RAM
|
||||
|
||||
.text : {
|
||||
*(.text)
|
||||
*(.rodata)
|
||||
} > RAM
|
||||
} > FLASH
|
||||
|
||||
.data : {
|
||||
KEEP(*(.magic_number)) /* Ensure the magic number is kept */
|
||||
LONG(ADDR(.text) + 4) /* Entry point */
|
||||
*(.data)
|
||||
} > RAM
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,14 +1,7 @@
|
||||
#include <platform/printf.h>
|
||||
#include <stdint.h>
|
||||
|
||||
__attribute__((section(".magic_number"))) volatile const uint32_t magic_number =
|
||||
0xDEADBEEF; // Prevent optimization
|
||||
|
||||
__attribute__((
|
||||
section(".magic_number1"))) volatile const uint32_t magic_number1 =
|
||||
0xDEADBEEA; // Prevent optimization
|
||||
|
||||
__attribute__((section(".text"))) int cryptographic_test() {
|
||||
static const uint32_t vv = 0xDEADBEEF;
|
||||
// Run unit tests for cryptographic scheme
|
||||
//while(1); // Debug loop
|
||||
return 7;
|
||||
|
40
runner.c
40
runner.c
@ -2,28 +2,46 @@
|
||||
#include <platform/printf.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define RAM_START 0x20000000
|
||||
#define RAM_END RAM_START + 0x00400000
|
||||
#define LIB_MAGIC 0xDEADBEEFu
|
||||
#define RAM_START 0x00300000
|
||||
#define RAM_END RAM_START + 0x00800000
|
||||
#define LIB_MAGIC 0x88DAD0F2
|
||||
|
||||
typedef int (*func_t)(void);
|
||||
typedef int (*func_t)();
|
||||
|
||||
void execute_library_function() {
|
||||
printf("Scanning RAM...\n");
|
||||
volatile uint32_t *ptr = (uint32_t *)RAM_START;
|
||||
uint32_t *ptr = (uint32_t *)RAM_START;
|
||||
|
||||
while ((uint32_t)ptr < RAM_END) {
|
||||
if (*ptr == LIB_MAGIC) {
|
||||
printf("Found libpqscheme_test!\n");
|
||||
uint32_t entry_point = *(ptr + 4);
|
||||
printf("%X\n", entry_point);
|
||||
entry_point += 4;
|
||||
printf("%X\n", entry_point);
|
||||
printf("Found libpqscheme_test 0x%X!\n", ptr);
|
||||
|
||||
printf("1>...%X 0x%X\n", ptr + 1, *(ptr + 1));
|
||||
printf("2>...%X 0x%X\n", ptr + 2, *(ptr + 2));
|
||||
printf("3>...%X 0x%X\n", ptr + 3, *(ptr + 3));
|
||||
|
||||
for (size_t i = 0; i < 20; i++) {
|
||||
printf("%X %2X \n", (((uint8_t *)ptr) + i),
|
||||
*(((uint8_t *)ptr) + i));
|
||||
}
|
||||
|
||||
/*
|
||||
uint32_t entry_point = *((uint32_t *)(ptr + 0x10));
|
||||
uint8_t *p = (uint8_t *)entry_point;
|
||||
printf("\n");
|
||||
|
||||
func_t test_func = (func_t)entry_point;
|
||||
if (test_func) {
|
||||
printf("Try exec...%X\n", entry_point);
|
||||
printf("Try exec...0x%X 0x%X\n", entry_point,
|
||||
0x20000034 + 0x10);
|
||||
printf(">> %d\n", test_func());
|
||||
}
|
||||
*/
|
||||
uint32_t entry_point = 0x300044 | 1;
|
||||
func_t test_func = (func_t)entry_point;
|
||||
printf("> Entry point\n", entry_point);
|
||||
int res = test_func();
|
||||
printf(">> %d\n", res);
|
||||
return;
|
||||
}
|
||||
ptr++;
|
||||
|
Loading…
Reference in New Issue
Block a user