-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow disabling exceptions for outer projects
Projects that include headers from libriscv can now be built without exceptions. libriscv will still need to be built with exceptions internally.
- Loading branch information
Showing
13 changed files
with
156 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(noexcept LANGUAGES CXX) | ||
|
||
add_subdirectory(../../lib riscv) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables") | ||
|
||
add_executable(example example.cpp) | ||
target_link_libraries(example riscv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## Adding _libriscv_ to your project | ||
|
||
This example project shows how you can build libriscv without C++ exceptions. | ||
|
||
For now, only the outer project is without exceptions. This is on-going work. | ||
|
||
## fib.rv64.elf | ||
|
||
The example program calculates fibonacci numbers. Run the program with the number as argument: | ||
|
||
``` | ||
./.build/example fib.rv64.elf 64 | ||
``` | ||
Will calculate the 64th fibonacci number. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
mkdir -p .build | ||
pushd .build | ||
cmake .. -DCMAKE_BUILD_TYPE=Release | ||
make -j4 | ||
popd | ||
|
||
# fib(64) == 10610209857723 | ||
./.build/example fib.rv64.elf 64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <fstream> | ||
#include <iostream> | ||
#include <libriscv/machine.hpp> | ||
using namespace riscv; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
if (argc < 2) { | ||
std::cout << argv[0] << ": [program file] [arguments ...]" << std::endl; | ||
return -1; | ||
} | ||
|
||
// Read the RISC-V program into a std::vector: | ||
std::ifstream stream(argv[1], std::ios::in | std::ios::binary); | ||
if (!stream) { | ||
std::cout << argv[1] << ": File not found?" << std::endl; | ||
return -1; | ||
} | ||
const std::vector<uint8_t> binary( | ||
(std::istreambuf_iterator<char>(stream)), | ||
std::istreambuf_iterator<char>() | ||
); | ||
|
||
// Take program arguments and make a new string vector, from 1..N | ||
std::vector<std::string> arguments { argv[1] }; | ||
for (size_t i = 2; i < argc; i++) | ||
arguments.push_back(argv[i]); | ||
|
||
// Create a new 64-bit RISC-V machine | ||
Machine<RISCV64> machine{binary, {.memory_max = 256UL << 20}}; | ||
|
||
// Use string vector as arguments to the RISC-V program | ||
machine.setup_linux( | ||
arguments, | ||
{"LC_TYPE=C", "LC_ALL=C", "USER=root"}); | ||
machine.setup_linux_syscalls(); | ||
|
||
// Run the program, but timeout after 128bn instructions | ||
machine.simulate(128'000'000'000ull); | ||
|
||
std::cout << "Program exited with status: " << machine.return_value<long>() << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../embed/fib.rv64.elf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters