diff --git a/port/moonlight/src/bootup.c b/port/moonlight/src/bootup.c index 17ac817..5230ffb 100644 --- a/port/moonlight/src/bootup.c +++ b/port/moonlight/src/bootup.c @@ -37,6 +37,7 @@ EXTERN_C function_t __init_array_start; EXTERN_C function_t __init_array_end; EXTERN_C function_t __fini_array_start; EXTERN_C function_t __fini_array_end; +EXTERN_C volatile uintptr_t tohost; // This function will be placed by the linker script according to the section // Raw function 'called' by the CPU with no runtime. @@ -119,9 +120,11 @@ void _initialize(void) { _exit(rc); } -// This should never be called. Busy loop with the CPU in idle state. +// This should never be called. Report the exit code through HTIF and idle the CPU. void _exit(int exit_code) { - (void)exit_code; + uintptr_t htif_exit_code = (((uintptr_t)(unsigned int)exit_code) << 1) | 1u; + + tohost = htif_exit_code; csr_clr_bits_mie(MIE_MTI_BIT_MASK); csr_clr_bits_mstatus(MSTATUS_MIE_BIT_MASK); while (1) { diff --git a/test/threadx/CMakeLists.txt b/test/threadx/CMakeLists.txt index 724ddc2..2eb06c7 100644 --- a/test/threadx/CMakeLists.txt +++ b/test/threadx/CMakeLists.txt @@ -140,26 +140,14 @@ function(add_threadx_regression_test TEST_SOURCE) list(APPEND TX_REGRESSION_TARGETS ${TEST_NAME}) set(TX_REGRESSION_TARGETS ${TX_REGRESSION_TARGETS} PARENT_SCOPE) - if(TEST_NAME STREQUAL "threadx_initialize_kernel_setup_test") - add_test( - NAME ${TEST_NAME} - COMMAND ${CMAKE_CURRENT_LIST_DIR}/run_threadx_simple_test.sh - ${THREADX_TEST_SIMULATOR} - ${THREADX_TEST_ISA} - $ - "Running Initialize Kernel Setup Test................................ SUCCESS!" - "Running Initialize Kernel Setup Test................................ ERROR!" - ) - else() - add_test( - NAME ${TEST_NAME} - COMMAND ${CMAKE_CURRENT_LIST_DIR}/run_threadx_test.sh - ${THREADX_TEST_SIMULATOR} - ${THREADX_TEST_ISA} - $ - ) - endif() - set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 10) + add_test( + NAME ${TEST_NAME} + COMMAND ${THREADX_TEST_SIMULATOR} + --isa=${THREADX_TEST_ISA} + -f $ + -m 60s + ) + set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 60) endfunction() foreach(test_case ${TX_REGRESSION_CASES}) diff --git a/test/threadx/run_threadx_simple_test.sh b/test/threadx/run_threadx_simple_test.sh deleted file mode 100755 index 1e9ef7c..0000000 --- a/test/threadx/run_threadx_simple_test.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -set -euo pipefail - -simulator="$1" -isa="$2" -elf="$3" -pass_pattern="$4" -fail_pattern="$5" - -if [ ! -x "$simulator" ]; then - echo "Simulator not found or not executable: $simulator" >&2 - exit 2 -fi - -if [ ! -f "$elf" ]; then - echo "ELF not found: $elf" >&2 - exit 2 -fi - -log_file=$(mktemp) -trap 'rm -f "$log_file"' EXIT - -"$simulator" \ - --isa="$isa" \ - -f "$elf" \ - -p tb.top.core.finish_condition=1 \ - -m 10s \ - | tee "$log_file" - -if grep -Fq "$fail_pattern" "$log_file"; then - echo "ThreadX regression reported failure pattern: $fail_pattern" >&2 - exit 1 -fi - -if ! grep -Fq "$pass_pattern" "$log_file"; then - echo "Missing expected success pattern in simulator output: $pass_pattern" >&2 - exit 1 -fi - -exit 0 diff --git a/test/threadx/run_threadx_test.sh b/test/threadx/run_threadx_test.sh deleted file mode 100755 index fa40c93..0000000 --- a/test/threadx/run_threadx_test.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -set -euo pipefail - -simulator="$1" -isa="$2" -elf="$3" - -if [ ! -x "$simulator" ]; then - echo "Simulator not found or not executable: $simulator" >&2 - exit 2 -fi - -if [ ! -f "$elf" ]; then - echo "ELF not found: $elf" >&2 - exit 2 -fi - -log_file=$(mktemp) -trap 'rm -f "$log_file"' EXIT - -"$simulator" \ - --isa="$isa" \ - -f "$elf" \ - -m 10s \ - | tee "$log_file" - -summary_line=$(grep -F "**** Test Summary:" "$log_file" | tail -n 1 || true) -if [ -z "$summary_line" ]; then - echo "Missing ThreadX test summary in simulator output" >&2 - exit 1 -fi - -read -r passed failed errors <&2 - exit 1 -fi - -if [ "$failed" -ne 0 ] || [ "$errors" -ne 0 ]; then - echo "ThreadX regression reported failure: passed=$passed failed=$failed errors=$errors" >&2 - exit 1 -fi - -exit 0