commit d112eeac2637d50931ebc98ebd8ae4f543d30404 Author: Kris Kwiatkowski Date: Mon Feb 17 09:09:14 2025 +0000 Init diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..31555d1 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +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-ar rcs runner runner.elf + + arm-none-eabi-objcopy -O binary libpqscheme_test.elf libpqscheme_test.bin + +run: + qemu-system-arm \ + -M mps2-an386 \ + -cpu cortex-m4 \ + -nographic \ + -kernel runner.elf \ + -initrd libpqscheme_test.elf \ + -semihosting + +clean: + rm -rf *.o *.a *.elf + +proper: clean + cd runtime_mps2 && cmake --build --preset an386 --target clean \ No newline at end of file diff --git a/libpqscheme.ld b/libpqscheme.ld new file mode 100644 index 0000000..f163475 --- /dev/null +++ b/libpqscheme.ld @@ -0,0 +1,18 @@ +MEMORY +{ + RAM (rwx) : ORIGIN = 0x00000000, LENGTH = 16K +} + +SECTIONS +{ + .text : { + *(.text) + *(.rodata) + } > RAM + + .data : { + KEEP(*(.magic_number)) /* Ensure the magic number is kept */ + LONG(ADDR(.text) + 4) /* Entry point */ + *(.data) + } > RAM +} \ No newline at end of file diff --git a/libpqscheme_test.bin b/libpqscheme_test.bin new file mode 100644 index 0000000..522c5c3 Binary files /dev/null and b/libpqscheme_test.bin differ diff --git a/libpqscheme_test.c b/libpqscheme_test.c new file mode 100644 index 0000000..0ca75dd --- /dev/null +++ b/libpqscheme_test.c @@ -0,0 +1,15 @@ +#include +#include + +__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() { + // Run unit tests for cryptographic scheme + //while(1); // Debug loop + return 7; +} diff --git a/runner b/runner new file mode 100644 index 0000000..5a04b0e Binary files /dev/null and b/runner differ diff --git a/runner.c b/runner.c new file mode 100644 index 0000000..767d802 --- /dev/null +++ b/runner.c @@ -0,0 +1,42 @@ +#include +#include +#include + +#define RAM_START 0x20000000 +#define RAM_END RAM_START + 0x00400000 +#define LIB_MAGIC 0xDEADBEEFu + +typedef int (*func_t)(void); + +void execute_library_function() { + printf("Scanning RAM...\n"); + volatile 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); + func_t test_func = (func_t)entry_point; + if (test_func) { + printf("Try exec...%X\n", entry_point); + printf(">> %d\n", test_func()); + } + return; + } + ptr++; + } + + printf("Test binary not found!\n"); +} + +void main() { + platform_init(PLATFORM_CLOCK_MAX); + platform_sync(); + + printf("Runner started\n"); + execute_library_function(); + printf("Execution finished\n"); +} diff --git a/runtime_mps2 b/runtime_mps2 new file mode 160000 index 0000000..7c6a05c --- /dev/null +++ b/runtime_mps2 @@ -0,0 +1 @@ +Subproject commit 7c6a05c1bb2882b8c6fdf6dadacdedc072f2e835