Skip to content

Commit

Permalink
fw: adapt fw syscall to hw syscall implementation
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
dehanj and agren committed Nov 21, 2024
1 parent 2bd235f commit cc0621f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
40 changes: 21 additions & 19 deletions hw/application_fpga/fw/tk1/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion hw/application_fpga/fw/tk1/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cc0621f

Please sign in to comment.