/*************************************************************************** * Copyright (c) 2024 Microsoft Corporation * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. * * SPDX-License-Identifier: MIT **************************************************************************/ #include "tx_port.h" #if __riscv_xlen == 64 #define REG_STORE sd #define REG_LOAD ld #define REG_BYTES 8 #else #define REG_STORE sw #define REG_LOAD lw #define REG_BYTES 4 #endif .section .text .balign 4 .global trap_entry .type trap_entry, @function trap_entry: addi sp, sp, -TX_RISCV_TRAP_FRAME_SIZE REG_STORE ra, (28 * REG_BYTES)(sp) call _tx_thread_context_save csrr a0, mcause csrr a1, mepc csrr a2, mtval addi sp, sp, -TX_RISCV_TRAP_CALL_FRAME_SIZE REG_STORE ra, 0(sp) call trap_handler REG_LOAD ra, 0(sp) addi sp, sp, TX_RISCV_TRAP_CALL_FRAME_SIZE call _tx_thread_context_restore 1: j 1b .size trap_entry, .-trap_entry