Skip to content

Use Zig musl/libc++ toolchain to build programs #12

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**/build/
**/.zig/
**/build_*/
**/riscv32-unknown-elf/
**/riscv64-unknown-elf/
Expand Down
3 changes: 2 additions & 1 deletion engine/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export ENGINE_CC="ccache $CC"

# Build the script
pushd ../programs
source build.sh $@
#source build.sh $@
source zig.sh $@
popd

echo "RISC-V C-extension is: $CEXT"
Expand Down
16 changes: 8 additions & 8 deletions engine/scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@
add_shared_program(gameplay.elf 0x50000000
*[Gg]ameplay*
"src/gameplay.cpp"
"src/gameplay_remote.cpp"
#"src/gameplay_remote.cpp"
"src/events.cpp"
)

add_level(gui.elf 0x400000
add_level(gui.elf
"src/gui.cpp"
)
attach_program(gui.elf gameplay.elf)
#attach_program(gui.elf gameplay.elf)


add_level(level1.elf 0x400000
add_level(level1.elf
"src/level1.cpp"
"src/level1_local.cpp"
"src/level1_remote.cpp"
#"src/level1_remote.cpp"
"src/level1_threads.cpp"
"src/events.cpp"
)
attach_program(level1.elf gameplay.elf)
#attach_program(level1.elf gameplay.elf)

add_level(level2.elf 0x400000
add_level(level2.elf
"src/level2.cpp"
)
attach_program(level2.elf gameplay.elf)
#attach_program(level2.elf gameplay.elf)
2 changes: 1 addition & 1 deletion engine/scripts/src/events.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <api.h>
#include <include/event_loop.hpp>
#include <event_loop.hpp>

static std::array<Events<>, 2> events;

Expand Down
2 changes: 1 addition & 1 deletion engine/scripts/src/events.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <api.h>
#include <include/event_loop.hpp>
#include <event_loop.hpp>

PUBLIC(bool add_work(const Events<>::Work*));

Expand Down
20 changes: 3 additions & 17 deletions engine/scripts/src/gameplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ static void empty_function() {}

static void full_thread_function()
{
microthread::create([](int, int, int) { /* ... */ }, 1, 2, 3);
//microthread::create([](int, int, int) { /* ... */ }, 1, 2, 3);
}

static void oneshot_thread_function()
{
microthread::oneshot([](int, int, int) { /* ... */ }, 1, 2, 3);
//microthread::oneshot([](int, int, int) { /* ... */ }, 1, 2, 3);
}

static void direct_thread_function()
{
microthread::direct([] { /* ... */ });
//microthread::direct([] { /* ... */ });
}

static void opaque_dyncall_handler()
Expand All @@ -49,24 +49,10 @@ PUBLIC(void public_donothing())
/* nothing */
}

inline void* sys_memset(void* vdest, const int ch, std::size_t size)
{
register char* a0 asm("a0") = (char*)vdest;
register int a1 asm("a1") = ch;
register size_t a2 asm("a2") = size;
register long syscall_id asm("a7") = SYSCALL_MEMSET;

asm volatile ("ecall"
: "=m"(*(char(*)[size]) a0)
: "r"(a0), "r"(a1), "r"(a2), "r"(syscall_id));
return vdest;
}

static void bench_alloc_free()
{
auto x = std::make_unique_for_overwrite<char[]>(1024);
__asm__("" :: "m"(x[0]) : "memory");
//sys_memset(x.get(), 0, 1024);
}

PUBLIC(void benchmarks())
Expand Down
1 change: 1 addition & 0 deletions engine/scripts/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ measure_exception_throw()
{
print("Caught exception: ", e.what(), "\n");
}
//print("Exception handling done\n");
const auto cycle1 = rdcycle();
const auto time1 = rdtime();
return {cycle1-cycle0, time1-time0};
Expand Down
2 changes: 1 addition & 1 deletion engine/scripts/src/interface.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include <include/function.hpp>
#include <function.hpp>
#include <map>
#include <string>
#include <vector>
Expand Down
6 changes: 3 additions & 3 deletions engine/scripts/src/level1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ PUBLIC(void start())
print("** Threads **\n");

/* Test-run some micro-threads. */
do_threads_stuff();
//do_threads_stuff();
}

static std::unique_ptr<TestData[]> test_vector;
Expand Down Expand Up @@ -75,6 +75,6 @@ void do_benchmarks()
});


if (Game::setting("remote").value_or(false))
do_remote_stuff();
//if (Game::setting("remote").value_or(false))
// do_remote_stuff();
}
4 changes: 3 additions & 1 deletion engine/scripts/src/level1_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ void do_threads_stuff()
b = 4;
c = 6;
microthread::yield();
print("Done, back in the main thread!\n");

auto thread = microthread::create(
/*auto thread = microthread::create(
[](int a, int b, int c)
{
print(
Expand All @@ -40,6 +41,7 @@ void do_threads_stuff()
print("Joining the thread any time now...\n");
auto retval = microthread::join(thread);
print("Full thread exited, return value: ", retval, "\n");
*/

/* GDB can be automatically opened at this point. */
Game::breakpoint();
Expand Down
4 changes: 2 additions & 2 deletions engine/scripts/src/level2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ using namespace api;
PUBLIC(void start())
{
print("Hello from Level 2!\n");
int value = gameplay_allowed_function(123);
print("Back in Level2! Got result value = ", value, "\n");
//int value = gameplay_allowed_function(123);
//print("Back in Level2! Got result value = ", value, "\n");
}

int main() {}
2 changes: 1 addition & 1 deletion engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int main()
/* level2 can make remote calls to the gameplay program. */
level2.setup_strict_remote_calls_to(gameplay);
/* Allow calling *only* this function remotely, when in strict mode */
gameplay.add_allowed_remote_function("_Z25gameplay_allowed_functioni");
//gameplay.add_allowed_remote_function("_Z25gameplay_allowed_functioni");

if (!level2.call("start")) {
strf::to(stdout)("Level2 failed to start!\n");
Expand Down
Loading
Loading