From 23b76b617899adf9be859dcc33dd9be75b794dce Mon Sep 17 00:00:00 2001 From: Daniel Jobson Date: Tue, 17 Sep 2024 14:54:19 +0200 Subject: [PATCH] Wip syscall function. PoC of how a syscall could look like. --- hw/application_fpga/Makefile | 9 +++-- hw/application_fpga/fw/tk1/syscall.c | 58 ++++++++++++++++++++++++++++ hw/application_fpga/fw/tk1/syscall.h | 35 +++++++++++++++++ 3 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 hw/application_fpga/fw/tk1/syscall.c create mode 100644 hw/application_fpga/fw/tk1/syscall.h diff --git a/hw/application_fpga/Makefile b/hw/application_fpga/Makefile index be6e5f4..8eec96e 100644 --- a/hw/application_fpga/Makefile +++ b/hw/application_fpga/Makefile @@ -119,7 +119,8 @@ FIRMWARE_DEPS = \ $(P)/fw/tk1/htif.h \ $(P)/fw/tk1/rng.h \ $(P)/fw/tk1/mgmt_app.h \ - $(P)/fw/tk1/storage.h + $(P)/fw/tk1/storage.h \ + $(P)/fw/tk1/syscall.h FIRMWARE_OBJS = \ $(P)/fw/tk1/main.o \ @@ -137,7 +138,8 @@ FIRMWARE_OBJS = \ $(P)/fw/tk1/htif.o \ $(P)/fw/tk1/rng.o \ $(P)/fw/tk1/mgmt_app.o \ - $(P)/fw/tk1/storage.o + $(P)/fw/tk1/storage.o \ + $(P)/fw/tk1/syscall.o FIRMWARE_SOURCES = \ $(P)/fw/tk1/main.c \ @@ -154,7 +156,8 @@ FIRMWARE_SOURCES = \ $(P)/fw/tk1/htif.c \ $(P)/fw/tk1/rng.c \ $(P)/fw/tk1/mgmt_app.c \ - $(P)/fw/tk1/storage.c + $(P)/fw/tk1/storage.c \ + $(P)/fw/tk1/syscall.c TESTFW_OBJS = \ $(P)/fw/testfw/main.o \ diff --git a/hw/application_fpga/fw/tk1/syscall.c b/hw/application_fpga/fw/tk1/syscall.c new file mode 100644 index 0000000..514c3c4 --- /dev/null +++ b/hw/application_fpga/fw/tk1/syscall.c @@ -0,0 +1,58 @@ +// Copyright (C) 2024 - Tillitis AB +// SPDX-License-Identifier: GPL-2.0-only + +#include "syscall.h" +#include "mgmt_app.h" +#include "partition_table.h" +#include "preload_app.h" +#include "storage.h" + +#include + +int syscall(syscall_t *ctx) +{ + + partition_table_t part_table; + part_table_read(&part_table); + + switch (ctx->syscall_no) { + case ALLOC_AREA: + return storage_allocate_area(&part_table); + break; + + case DEALLOC_AREA: + return storage_deallocate_area(&part_table); + break; + + case READ_DATA: + return storage_read_data(&part_table, ctx->offset, ctx->data, + ctx->size); + break; + + case WRITE_DATA: + return storage_write_data(&part_table, ctx->offset, ctx->data, + ctx->size); + break; + + case PRELOAD_STORE: + return preload_store(&part_table); + break; + + case PRELOAD_DELETE: + return preload_delete(&part_table); + break; + + case MGMT_APP_REGISTER: + return mgmt_app_register(&part_table); + break; + + case MGMT_APP_UNREGISTER: + return mgmt_app_unregister(&part_table); + break; + + default: + /* return -1 */ + break; + } + return -1; +} diff --git a/hw/application_fpga/fw/tk1/syscall.h b/hw/application_fpga/fw/tk1/syscall.h new file mode 100644 index 0000000..1ab7bd6 --- /dev/null +++ b/hw/application_fpga/fw/tk1/syscall.h @@ -0,0 +1,35 @@ +// Copyright (C) 2024 - Tillitis AB +// SPDX-License-Identifier: GPL-2.0-only + +#ifndef SYSCALL_H +#define SYSCALL_H + +#include "partition_table.h" + +#include +#include + + +typedef struct { + uint8_t syscall_no; + uint32_t offset; + uint8_t *data; + size_t size; + uint32_t *ctx; +} syscall_t; + +enum syscall_cmd { + BLAKE2S = 0, + ALLOC_AREA, + DEALLOC_AREA, + WRITE_DATA, + READ_DATA, + PRELOAD_STORE, + PRELOAD_DELETE, + MGMT_APP_REGISTER, + MGMT_APP_UNREGISTER, +}; + +int syscall(syscall_t *ctx); + +#endif