This commit is contained in:
Kris Kwiatkowski 2025-02-17 09:09:14 +00:00
commit d112eeac26
7 changed files with 97 additions and 0 deletions

21
Makefile Normal file
View File

@ -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

18
libpqscheme.ld Normal file
View File

@ -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
}

BIN
libpqscheme_test.bin Normal file

Binary file not shown.

15
libpqscheme_test.c Normal file
View File

@ -0,0 +1,15 @@
#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() {
// Run unit tests for cryptographic scheme
//while(1); // Debug loop
return 7;
}

BIN
runner Normal file

Binary file not shown.

42
runner.c Normal file
View File

@ -0,0 +1,42 @@
#include <platform/platform.h>
#include <platform/printf.h>
#include <stdint.h>
#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");
}

1
runtime_mps2 Submodule

@ -0,0 +1 @@
Subproject commit 7c6a05c1bb2882b8c6fdf6dadacdedc072f2e835