Wip syscall function.

PoC of how a syscall could look like.
This commit is contained in:
Daniel Jobson 2024-09-17 14:54:19 +02:00
parent f62930984d
commit b602de145c
No known key found for this signature in database
GPG Key ID: 3707A9DBF4BB8F1A
3 changed files with 99 additions and 3 deletions

View File

@ -94,7 +94,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 \
@ -112,7 +113,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 \
@ -129,7 +131,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 \

View File

@ -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 <stdint.h>
int syscall(syscall_t *ctx)
{
partition_table_t part_table;
part_table_init(&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;
}

View File

@ -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 <stdint.h>
#include <stddef.h>
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