Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sw] Add a CMake option to choose whether to halt the core upon program termination #53

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ make
popd
```

The HALT_SIM_WHEN_EXIT CMake option can be used to automatically stop the simulation when the program exits (`cmake -DHALT_SIM_WHEN_EXIT=ON ../`). This option should be disabled when building software for loading into an FPGA, otherwise the chip will not accept subsequent applications via the `util/load_demo_system.sh` script once the current program exits.

Note the FPGA build relies on a fixed path to the initial binary (blank.vmem) so
if you want to create your build directory elsewhere you need to adjust the path
in `ibex_demo_system.core`
Expand Down
5 changes: 5 additions & 0 deletions sw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ project(demo_system_sw)

option(SIM_CTRL_OUTPUT
"Send string output to simulator control rather than UART")
option(HALT_SIM_WHEN_EXIT
"Halt the simulator when the program exits otherwise the core will be kept in a sleep loop")

if(SIM_CTRL_OUTPUT)
add_compile_definitions(SIM_CTRL_OUTPUT)
endif()
if(HALT_SIM_WHEN_EXIT)
add_compile_definitions(HALT_SIM_WHEN_EXIT)
endif()

set(COMMON_DIR "${CMAKE_CURRENT_LIST_DIR}/common")
set(LINKER_SCRIPT "${COMMON_DIR}/link.ld")
Expand Down
2 changes: 2 additions & 0 deletions sw/common/crt0.S
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ main_entry:
addi x11, x0, 0
jal x1, main

#ifdef HALT_SIM_WHEN_EXIT
/* Halt simulation */
li x5, SIM_CTRL_BASE + SIM_CTRL_CTRL
li x6, 1
sw x6, 0(x5)
#endif

/* If execution ends up here just put the core to sleep */
sleep_loop:
Expand Down