fw: adapt fw syscall to hw syscall implementation

- Use new syscall API from hw
- 4 byte align the syscall function
- Restore blake2s
- Remove setting system_mode_ctrl since it is done by the hardware instead

Co-authored-by: Mikael Ågren <mikael@tillitis.se>
This commit is contained in:
Daniel Jobson 2024-11-13 15:55:29 +01:00
parent a65eddbb00
commit 8c073c3d01
No known key found for this signature in database
GPG Key ID: 3707A9DBF4BB8F1A
2 changed files with 27 additions and 20 deletions

View File

@ -21,22 +21,23 @@
#include <stdint.h>
// clang-format off
static volatile uint32_t *uds = (volatile uint32_t *)TK1_MMIO_UDS_FIRST;
static volatile uint32_t *system_mode_ctrl = (volatile uint32_t *)TK1_MMIO_TK1_SYSTEM_MODE_CTRL;
static volatile uint32_t *name0 = (volatile uint32_t *)TK1_MMIO_TK1_NAME0;
static volatile uint32_t *name1 = (volatile uint32_t *)TK1_MMIO_TK1_NAME1;
static volatile uint32_t *ver = (volatile uint32_t *)TK1_MMIO_TK1_VERSION;
static volatile uint32_t *udi = (volatile uint32_t *)TK1_MMIO_TK1_UDI_FIRST;
static volatile uint32_t *cdi = (volatile uint32_t *)TK1_MMIO_TK1_CDI_FIRST;
static volatile uint32_t *app_addr = (volatile uint32_t *)TK1_MMIO_TK1_APP_ADDR;
static volatile uint32_t *app_size = (volatile uint32_t *)TK1_MMIO_TK1_APP_SIZE;
static volatile uint32_t *fw_blake2s_addr = (volatile uint32_t *)TK1_MMIO_TK1_BLAKE2S;
static volatile uint32_t *timer = (volatile uint32_t *)TK1_MMIO_TIMER_TIMER;
static volatile uint32_t *timer_prescaler = (volatile uint32_t *)TK1_MMIO_TIMER_PRESCALER;
static volatile uint32_t *timer_status = (volatile uint32_t *)TK1_MMIO_TIMER_STATUS;
static volatile uint32_t *timer_ctrl = (volatile uint32_t *)TK1_MMIO_TIMER_CTRL;
static volatile uint32_t *ram_addr_rand = (volatile uint32_t *)TK1_MMIO_TK1_RAM_ADDR_RAND;
static volatile uint32_t *ram_data_rand = (volatile uint32_t *)TK1_MMIO_TK1_RAM_DATA_RAND;
static volatile uint32_t *uds = (volatile uint32_t *)TK1_MMIO_UDS_FIRST;
/*static volatile uint32_t *system_mode_ctrl = (volatile uint32_t *)TK1_MMIO_TK1_SYSTEM_MODE_CTRL;*/
static volatile uint32_t *name0 = (volatile uint32_t *)TK1_MMIO_TK1_NAME0;
static volatile uint32_t *name1 = (volatile uint32_t *)TK1_MMIO_TK1_NAME1;
static volatile uint32_t *ver = (volatile uint32_t *)TK1_MMIO_TK1_VERSION;
static volatile uint32_t *udi = (volatile uint32_t *)TK1_MMIO_TK1_UDI_FIRST;
static volatile uint32_t *cdi = (volatile uint32_t *)TK1_MMIO_TK1_CDI_FIRST;
static volatile uint32_t *app_addr = (volatile uint32_t *)TK1_MMIO_TK1_APP_ADDR;
static volatile uint32_t *app_size = (volatile uint32_t *)TK1_MMIO_TK1_APP_SIZE;
static volatile uint32_t *fw_blake2s_addr = (volatile uint32_t *)TK1_MMIO_TK1_BLAKE2S;
static volatile uint32_t *syscall_addr = (volatile uint32_t *)TK1_MMIO_TK1_SYSCALL;
static volatile uint32_t *timer = (volatile uint32_t *)TK1_MMIO_TIMER_TIMER;
static volatile uint32_t *timer_prescaler = (volatile uint32_t *)TK1_MMIO_TIMER_PRESCALER;
static volatile uint32_t *timer_status = (volatile uint32_t *)TK1_MMIO_TIMER_STATUS;
static volatile uint32_t *timer_ctrl = (volatile uint32_t *)TK1_MMIO_TIMER_CTRL;
static volatile uint32_t *ram_addr_rand = (volatile uint32_t *)TK1_MMIO_TK1_RAM_ADDR_RAND;
static volatile uint32_t *ram_data_rand = (volatile uint32_t *)TK1_MMIO_TK1_RAM_DATA_RAND;
// clang-format on
// Context for the loading of a TKey program
@ -367,7 +368,7 @@ static void run(const struct context *ctx, partition_table_t *part_table)
// clang-format on
// Flip over to application mode
*system_mode_ctrl = 1;
/**system_mode_ctrl = 1;*/
// XXX Firmware stack now no longer available
// Don't use any function calls!
@ -419,8 +420,9 @@ int main(void)
print_hw_version();
// Let the app know the function address for blake2s()
*fw_blake2s_addr = (uint32_t)syscall;
/**fw_blake2s_addr = (uint32_t)blake2s;*/
*fw_blake2s_addr = (uint32_t)blake2s;
// Let the app know the function address for syscall()
*syscall_addr = (uint32_t)syscall;
/*@-mustfreeonly@*/
/* Yes, splint, this points directly to RAM and we don't care

View File

@ -14,7 +14,12 @@
void inner_syscall(volatile syscall_t *ctx);
void syscall(syscall_t *ctx)
/*
* Syscall need to be word aligned (4 bytes) since the CPU only reads
* instructions from word aligned addresses. This is not guaranteed with 16-bits
* instructions.
*/
void __attribute__((aligned(4))) syscall(syscall_t *ctx)
{
#ifdef USE_FW_RAM_IN_SYSCALL