Compare commits
6 Commits
develop
...
private/ho
| Author | SHA1 | Date | |
|---|---|---|---|
| 7cc6e31688 | |||
| dd071a3d30 | |||
| 109cc2a7ad | |||
| 89e4d58c9e | |||
| 2d2a64aa7a | |||
| f8fa382b62 |
Submodule bare-metal-bsp updated: bf0e4ec057...d8728e319c
40
test_fw/CMakeLists.txt
Normal file
40
test_fw/CMakeLists.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
project(test_fw C)
|
||||
set(TARGET test_fw)
|
||||
add_executable(${TARGET} test_fw.c)
|
||||
# Paths to ThreadX
|
||||
set(THREADX_DIR "/scratch/hongyu/workarea/ThreadX/threadx/") # change to where ThreadX is located
|
||||
|
||||
|
||||
set(THREADX_LIB "${THREADX_DIR}/build_liu/libthreadx.a")
|
||||
|
||||
|
||||
|
||||
set(BOARD "iss" CACHE STRING "Target board")
|
||||
target_compile_options(test_fw PRIVATE
|
||||
-msmall-data-limit=0
|
||||
)
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../bare-metal-bsp bsp)
|
||||
target_link_libraries(${TARGET} PRIVATE
|
||||
-Wl,--start-group
|
||||
startup
|
||||
runtime
|
||||
wrap
|
||||
${THREADX_LIB}
|
||||
-Wl,--end-group
|
||||
)
|
||||
target_link_options(${TARGET} PRIVATE LINKER:-Map=${TARGET}.map)
|
||||
|
||||
|
||||
|
||||
#target_link_libraries(${TARGET} PRIVATE ${THREADX_LIB})
|
||||
|
||||
target_include_directories(${TARGET} PRIVATE
|
||||
${THREADX_DIR}/common/inc
|
||||
${THREADX_DIR}/ports/risc-v64/gnu/inc
|
||||
)
|
||||
|
||||
add_custom_command(TARGET ${TARGET} POST_BUILD
|
||||
COMMAND ${CMAKE_OBJDUMP} -S ${TARGET}.elf > ${TARGET}.dis
|
||||
COMMENT "Creating disassembly for ${TARGET}")
|
||||
122
test_fw/CMakePresets.json
Normal file
122
test_fw/CMakePresets.json
Normal file
@@ -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"]
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
53
test_fw/entry_threadx.S
Normal file
53
test_fw/entry_threadx.S
Normal file
@@ -0,0 +1,53 @@
|
||||
// See LICENSE for license details
|
||||
|
||||
#ifndef ENTRY_S
|
||||
#define ENTRY_S
|
||||
|
||||
#include "encoding.h"
|
||||
#include "bits.h"
|
||||
|
||||
msg:
|
||||
.string "enter trap_entry of entry_threadx!\n"
|
||||
.section .text.entry
|
||||
.align 2
|
||||
.global trap_entry
|
||||
.extern _tx_thread_context_save
|
||||
.extern _tx_thread_context_restore
|
||||
|
||||
trap_entry:
|
||||
|
||||
|
||||
|
||||
|
||||
#if defined(__riscv_float_abi_single) || defined(__riscv_float_abi_double)
|
||||
addi sp, sp, -65*REGBYTES // Allocate space for all registers - with floating point enabled
|
||||
#else
|
||||
addi sp, sp, -32*REGBYTES // Allocate space for all registers - without floating point enabled
|
||||
#endif
|
||||
|
||||
STORE x1, 28*REGBYTES(sp) // Store RA, 28*REGBYTES(because call will override ra [ra is a calle register in riscv])
|
||||
|
||||
#la a0, msg # a0 = pointer to string
|
||||
#jal ra, puts # call puts(msg)
|
||||
|
||||
call _tx_thread_context_save
|
||||
|
||||
# la a0, msg # a0 = pointer to string
|
||||
# jal ra, puts # call puts(msg)
|
||||
|
||||
csrr a0, mcause
|
||||
csrr a1, mepc
|
||||
mv a2, sp // which sp is needed? sp of interrupted context or the sp of _tx_thread_context_save???
|
||||
addi sp, sp, -8
|
||||
sd ra, 0(sp)
|
||||
call handle_trap
|
||||
ld ra, 0(sp)
|
||||
addi sp, sp, 8
|
||||
call _tx_thread_context_restore
|
||||
|
||||
//.weak handle_trap
|
||||
//handle_trap:
|
||||
//1:
|
||||
// j 1b
|
||||
|
||||
#endif
|
||||
42
test_fw/test_fw.c
Normal file
42
test_fw/test_fw.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "encoding.h"
|
||||
#include "platform.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void handle_m_time_interrupt() {
|
||||
uint64_t time = get_aclint_mtime(aclint);
|
||||
time += MTIMER_NEXT_TICK_INC;
|
||||
set_aclint_mtimecmp(aclint, time);
|
||||
puts("m_time_irq");
|
||||
}
|
||||
|
||||
int main() {
|
||||
puts("in main");
|
||||
// avoid getting interrupt upon enabling MIP/MIE_MTI
|
||||
set_aclint_mtimecmp(aclint, 0xffffffffffffffff);
|
||||
// enable global interrupt
|
||||
csr_set_bits_mstatus(MSTATUS_MIE_BIT_MASK);
|
||||
|
||||
puts("after enable MSTATUS_MIE/MPP");
|
||||
// enable MIE
|
||||
csr_set_bits_mie(MIE_MTI_BIT_MASK | MIE_MSI_BIT_MASK | MIE_MEI_BIT_MASK);
|
||||
puts("after enable MIE");
|
||||
|
||||
uint64_t time = get_aclint_mtime(aclint);
|
||||
printf("in main() get_aclint_mtime return %lu \n", (uint32_t)time);
|
||||
set_aclint_mtime(aclint, 9);
|
||||
time = get_aclint_mtime(aclint);
|
||||
printf("in main() get_aclint_mtime after set 9, return %lu \n", (uint32_t)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;
|
||||
}
|
||||
Reference in New Issue
Block a user