wip: extend shared library support, window demo

This commit is contained in:
2026-04-05 21:38:05 +02:00
parent 01c242d4de
commit 6f0707bc80
14 changed files with 268 additions and 53 deletions
+57 -1
View File
@@ -7,8 +7,9 @@
#include <montauk/syscall.h>
#include <libloader/libloader.h>
// Forward declaration
// Forward declarations
static void print_int(int val);
static void print_hex(uint64_t val);
extern "C" void _start() {
montauk::print("=== Dynamic Library Test ===\n\n");
@@ -78,6 +79,39 @@ extern "C" void _start() {
libloader::dlclose(lib);
montauk::print("Library unloaded.\n");
// Test loading libhello (GUI library)
montauk::print("\nLoading libhello (GUI library)...\n");
LibHandle* hellolib = libloader::dlopen("0:/os/libhello.lib");
if (!hellolib) {
montauk::print("ERROR: Failed to load libhello.lib\n");
montauk::exit(1);
}
montauk::print("Library loaded successfully!\n\n");
// Resolve hello_run
typedef int (*hello_run_t)(void);
hello_run_t hello_run = (hello_run_t)libloader::dlsym(hellolib, "hello_run");
if (!hello_run) {
montauk::print("ERROR: Failed to resolve hello_run\n");
montauk::exit(1);
}
montauk::print(" hello_run: OK\n\n");
// Debug: print hello_run address
montauk::print(" DEBUG: hello_run @ ");
print_hex((uint64_t)hello_run);
montauk::print("\n");
// Run the GUI demo (this creates a window and event loop)
montauk::print("Running GUI demo...\n");
hello_run();
// Unload the library
montauk::print("GUI demo closed.\n");
montauk::print("Unloading library...\n");
libloader::dlclose(hellolib);
montauk::print("Library unloaded.\n");
montauk::print("\n=== All tests passed! ===\n");
montauk::exit(0);
}
@@ -110,3 +144,25 @@ static void print_int(int val) {
montauk::putchar(buf[i]);
}
}
// Print hex value (uppercase, with 0x prefix)
static void print_hex(uint64_t val) {
montauk::print("0x");
char buf[20];
int idx = 0;
if (val == 0) {
buf[idx++] = '0';
} else {
while (val > 0) {
int digit = val & 0xF;
buf[idx++] = (digit < 10) ? ('0' + digit) : ('A' + digit - 10);
val >>= 4;
}
}
// Reverse the buffer
for (int i = idx - 1; i >= 0; i--) {
montauk::putchar(buf[i]);
}
}