From f8fa382b6248885272776e089d09ecf664407dd0 Mon Sep 17 00:00:00 2001 From: Hongyu Liu Date: Fri, 14 Nov 2025 15:24:08 +0100 Subject: [PATCH] add test_fw --- test_fw/CMakeLists.txt | 13 ++++ test_fw/CMakePresets.json | 122 ++++++++++++++++++++++++++++++++++++++ test_fw/test_fw.c | 45 ++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 test_fw/CMakeLists.txt create mode 100644 test_fw/CMakePresets.json create mode 100644 test_fw/test_fw.c diff --git a/test_fw/CMakeLists.txt b/test_fw/CMakeLists.txt new file mode 100644 index 0000000..2988b7c --- /dev/null +++ b/test_fw/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.21) +project(test_fw C) +set(TARGET test_fw) +add_executable(${TARGET} test_fw.c) + +set(BOARD "iss" CACHE STRING "Target board") +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../bare-metal-bsp bsp) +target_link_libraries(${TARGET} PRIVATE bsp) +target_link_options(${TARGET} PRIVATE LINKER:-Map=${TARGET}.map) + +add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND ${CMAKE_OBJDUMP} -S ${TARGET}.elf > ${TARGET}.dis + COMMENT "Creating disassembly for ${TARGET}") diff --git a/test_fw/CMakePresets.json b/test_fw/CMakePresets.json new file mode 100644 index 0000000..bacab6f --- /dev/null +++ b/test_fw/CMakePresets.json @@ -0,0 +1,122 @@ +{ + "version": 3, + "vendor": { + "conan": {} + }, + "cmakeMinimumRequired": { + "major": 3, + "minor": 24, + "patch": 0 + }, + "configurePresets": [ + { + "name": "32imc", + "hidden": true, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/../bare-metal-bsp/cmake/rv32imc.cmake" + } + }, + { + "name": "64imc", + "hidden": true, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/../bare-metal-bsp/cmake/rv64gc.cmake" + } + }, + { + "name": "iss", + "hidden": true, + "cacheVariables": { + "BOARD": "iss" + } + }, + { + "name": "moonlight", + "hidden": true, + "cacheVariables": { + "BOARD": "moonlight" + } + }, + { + "name": "riscv_vp", + "hidden": true, + "cacheVariables": { + "BOARD": "riscv_vp", + "LINKER_SCRIPT": "/scratch/hongyu/workarea/Firmwares/bare-metal-bsp/env/riscv_vp/flash.lds" + } + }, + { + "name": "rtl", + "hidden": true, + "cacheVariables": { + "BOARD": "rtl" + } + }, + { + "name": "debug", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "release", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "ISS_Debug", + "inherits": ["iss", "debug", "32imc"] + }, + { + "name": "Moonlight_Debug", + "inherits": ["moonlight", "debug", "32imc"] + }, + { + "name": "riscv_vp_Debug", + "inherits": ["riscv_vp", "debug", "32imc"] + }, + { + "name": "ISS_Debug_64", + "inherits": ["iss", "debug", "64imc"] + }, + { + "name": "Moonlight_Debug_64", + "hidden": true, + "inherits": ["moonlight", "debug", "64imc"] + }, + { + "name": "riscv_vp_Debug_64", + "inherits": ["riscv_vp", "debug", "64imc"] + }, + { + "name": "ISS_Release", + "inherits": ["iss", "release", "32imc"] + }, + { + "name": "Moonlight_Release", + "inherits": ["moonlight", "release", "32imc"] + }, + { + "name": "riscv_vp_Release", + "inherits": ["riscv_vp", "release", "32imc"] + }, + { + "name": "ISS_Release_64", + "inherits": ["iss", "release", "64imc"] + }, + { + "name": "Moonlight_Release_64", + "hidden": true, + "inherits": ["moonlight", "release", "64imc"] + }, + { + "name": "riscv_vp_Release_64", + "hidden": true, + "inherits": ["riscv_vp", "release", "64imc"] + } + + ] +} \ No newline at end of file diff --git a/test_fw/test_fw.c b/test_fw/test_fw.c new file mode 100644 index 0000000..4e122ca --- /dev/null +++ b/test_fw/test_fw.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include + +#include "platform.h" +#include "encoding.h" +#include + +extern void _init(); +int main() { + //board_init(); + _init(); + puts("after _init"); + +// set only MPP +__asm__ volatile ( + "csrs mstatus, %0" + : + : "r"(MSTATUS_MPP | MSTATUS_MIE) + : "memory" + ); + +puts("after enable MSTATUS_MIE/MPP"); +/* +// enable MIE + write_csr(mie,MIE_MTIE | MIE_MSIE | MIE_MEIE); + puts("after enable MIE"); +*/ + + uint64_t time = get_aclint_mtime(aclint); + printf("in main() get_aclint_mtime return %d \n ",time); + set_aclint_mtime(aclint, 9); + time = get_aclint_mtime(aclint); + printf("in main() get_aclint_mtime after set 9, return %d \n ",time); + + set_aclint_mtimecmp(aclint, (time+3)); + puts("set mtimecmp"); + + uint64_t timecmp = get_aclint_mtimecmp(aclint); + printf("in main() get_aclint_mtimecmp return %d \n ",timecmp); + + puts(" finshed "); + return 0; +}