summaryrefslogtreecommitdiff
path: root/test/tx/cmake/riscv/bsp/tx_initialize_low_level.S
diff options
context:
space:
mode:
Diffstat (limited to 'test/tx/cmake/riscv/bsp/tx_initialize_low_level.S')
-rw-r--r--test/tx/cmake/riscv/bsp/tx_initialize_low_level.S35
1 files changed, 27 insertions, 8 deletions
diff --git a/test/tx/cmake/riscv/bsp/tx_initialize_low_level.S b/test/tx/cmake/riscv/bsp/tx_initialize_low_level.S
index 8d474d66..d72c9b6a 100644
--- a/test/tx/cmake/riscv/bsp/tx_initialize_low_level.S
+++ b/test/tx/cmake/riscv/bsp/tx_initialize_low_level.S
@@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (c) 2026 10xEngineers
+ * Copyright (c) 2026 Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
@@ -8,10 +9,13 @@
* SPDX-License-Identifier: MIT
**************************************************************************/
+// Portions of this file were generated with AI assistance.
+
/* Trap entry and low-level init for RISC-V QEMU virt regression tests.
Supports both RV32 and RV64 via __riscv_xlen conditionals. */
#include "csr.h"
+#include "tx_port.h"
#if __riscv_xlen == 64
#define STORE sd
@@ -33,13 +37,28 @@
.extern trap_handler
.extern _tx_thread_context_restore
-trap_entry:
+/* Take the interrupt frame size from the port that this BSP is linked
+ against, so the two can never disagree. A port that publishes no
+ contract keeps the historical layout. */
+#ifndef TX_RISCV_TRAP_FRAME_SIZE
#if defined(__riscv_float_abi_single) || defined(__riscv_float_abi_double)
- addi sp, sp, -(65 * REGBYTES)
+#define TX_RISCV_TRAP_FRAME_SIZE (65 * REGBYTES)
#else
- addi sp, sp, -(32 * REGBYTES)
+#define TX_RISCV_TRAP_FRAME_SIZE (32 * REGBYTES)
+#endif
+#endif
+
+/* The RISC-V psABI requires sp to be 16-byte aligned at a call. */
+#ifndef TX_RISCV_TRAP_CALL_FRAME_SIZE
+#define TX_RISCV_TRAP_CALL_FRAME_SIZE 16
#endif
+ .equ TX_TRAP_FRAME_SIZE, TX_RISCV_TRAP_FRAME_SIZE
+ .equ TX_TRAP_CALL_FRAME_SIZE, TX_RISCV_TRAP_CALL_FRAME_SIZE
+
+trap_entry:
+ addi sp, sp, -TX_TRAP_FRAME_SIZE
+
STORE x1, (28 * REGBYTES)(sp)
call _tx_thread_context_save
@@ -47,11 +66,11 @@ trap_entry:
csrr a0, mcause
csrr a1, mepc
csrr a2, mtval
- addi sp, sp, -REGBYTES
+ addi sp, sp, -TX_TRAP_CALL_FRAME_SIZE
STORE ra, 0(sp)
call trap_handler
LOAD ra, 0(sp)
- addi sp, sp, REGBYTES
+ addi sp, sp, TX_TRAP_CALL_FRAME_SIZE
call _tx_thread_context_restore
@@ -80,7 +99,7 @@ _tx_initialize_low_level:
csrrc zero, mstatus, t0
li t0, (MSTATUS_MPP_M | MSTATUS_MPIE)
csrrs zero, mstatus, t0
- li t0, (MIE_MTIE | MIE_MSIE | MIE_MEIE)
+ li t0, (MIE_MTIE | MIE_MEIE) // No MSIE: software interrupts are never dispatched here
csrrs zero, mie, t0
#ifdef __riscv_flen
@@ -89,11 +108,11 @@ _tx_initialize_low_level:
fscsr x0
#endif
- addi sp, sp, -REGBYTES
+ addi sp, sp, -TX_TRAP_CALL_FRAME_SIZE
STORE ra, 0(sp)
call board_init
LOAD ra, 0(sp)
- addi sp, sp, REGBYTES
+ addi sp, sp, TX_TRAP_CALL_FRAME_SIZE
la t0, trap_entry
csrw mtvec, t0