wip: extend shared library support, window demo
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
# Makefile for libhello shared library
|
||||
# Builds libhello.lib at fixed address 0x400000 (relocated at load time)
|
||||
|
||||
# Target architecture.
|
||||
ARCH := x86_64
|
||||
|
||||
# Toolchain
|
||||
TOOLCHAIN_PREFIX := $(shell cd ../../.. && pwd)/toolchain/local/bin/x86_64-elf-
|
||||
CXX := $(TOOLCHAIN_PREFIX)g++
|
||||
NM := $(TOOLCHAIN_PREFIX)nm
|
||||
STRIP := $(TOOLCHAIN_PREFIX)strip
|
||||
|
||||
# Compiler flags: freestanding, no stdlib
|
||||
override CXXFLAGS := \
|
||||
-std=gnu++20 \
|
||||
-g -O2 -pipe \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-nostdinc \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-fno-stack-check \
|
||||
-fno-PIC \
|
||||
-fno-rtti \
|
||||
-fno-exceptions \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
-m64 \
|
||||
-march=x86-64 \
|
||||
-mno-80387 \
|
||||
-mno-mmx \
|
||||
-mno-red-zone \
|
||||
-mcmodel=small \
|
||||
-I ../../include \
|
||||
-isystem ../../include/libc \
|
||||
-isystem ../../include/montauk \
|
||||
-isystem ../../include/gui \
|
||||
-isystem ../../../kernel/freestnd-c-hdrs/x86_64/include \
|
||||
-isystem ../../../kernel/freestnd-cxx-hdrs/x86_64/include
|
||||
|
||||
# Linker flags: freestanding static ELF at fixed address
|
||||
# Note: NOT using --gc-sections so all functions are kept
|
||||
override LDFLAGS := \
|
||||
-nostdlib \
|
||||
-static \
|
||||
-Wl,--build-id=none \
|
||||
-Wl,-m,elf_x86_64 \
|
||||
-T link.ld
|
||||
|
||||
# Output
|
||||
OUTDIR := ../../bin/os
|
||||
LIBNAME := libhello
|
||||
LIBSRC := src/libhello.cpp
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(OUTDIR)/$(LIBNAME).lib $(OUTDIR)/$(LIBNAME).lib.sym
|
||||
|
||||
$(OUTDIR)/$(LIBNAME).lib: $(LIBSRC)
|
||||
@mkdir -p $(OUTDIR)
|
||||
$(CXX) $(CXXFLAGS) -c src/libhello.cpp -o src/libhello.o
|
||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) src/libhello.o -o $@
|
||||
|
||||
# Generate symbol file from nm output
|
||||
# Format: "symbol_name,offset_in_hex"
|
||||
$(OUTDIR)/$(LIBNAME).lib.sym: $(OUTDIR)/$(LIBNAME).lib
|
||||
@mkdir -p $(OUTDIR)
|
||||
@echo "# Symbol table for $(LIBNAME)" > $@
|
||||
@echo "# This file maps symbol names to offsets from library base" >> $@
|
||||
@$(NM) $(OUTDIR)/$(LIBNAME).lib | grep ' T ' | awk '{printf "%s,0x%x\n", $$3, strtonum("0x" $$1) - 0x400000}' >> $@
|
||||
@echo "Generated symbol file: $@"
|
||||
|
||||
clean:
|
||||
rm -rf ../../bin/os/$(LIBNAME).lib ../../bin/os/$(LIBNAME).lib.sym src/libhello.o src/stb_truetype_impl.o
|
||||
@@ -0,0 +1,13 @@
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x400000;
|
||||
.text : {
|
||||
*(.text)
|
||||
}
|
||||
.eh_frame : {
|
||||
*(.eh_frame)
|
||||
}
|
||||
.rodata : {
|
||||
*(.rodata)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* libhello.cpp
|
||||
* Sample shared GUI library for MontaukOS
|
||||
* Creates a window and renders text as a demo of the shared library + GUI system
|
||||
* Copyright (c) 2026 Daniel Hammer
|
||||
*/
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
|
||||
// Exported demo function - creates a window and renders until closed
|
||||
extern "C" int hello_run() {
|
||||
// Create window
|
||||
Montauk::WinCreateResult wres;
|
||||
if (montauk::win_create("libhello Demo", 320, 200, &wres) < 0 || wres.id < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int winId = wres.id;
|
||||
uint32_t* pixels = (uint32_t*)(uintptr_t)wres.pixelVa;
|
||||
int width = 200;
|
||||
int height = 320;
|
||||
|
||||
// Simple render - fill with a color pattern
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
// Dark blue background
|
||||
pixels[y * width + x] = 0xFF1a1a2e;
|
||||
}
|
||||
}
|
||||
|
||||
// Present the initial frame
|
||||
montauk::win_present(winId);
|
||||
|
||||
// Event loop
|
||||
while (true) {
|
||||
Montauk::WinEvent ev;
|
||||
int r = montauk::win_poll(winId, &ev);
|
||||
|
||||
if (r < 0) {
|
||||
break;
|
||||
}
|
||||
if (r == 0) {
|
||||
montauk::sleep_ms(16);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ev.type == 3) { // close
|
||||
break;
|
||||
}
|
||||
if (ev.type == 2) { // resize
|
||||
width = ev.resize.w;
|
||||
height = ev.resize.h;
|
||||
pixels = (uint32_t*)(uintptr_t)montauk::win_resize(winId, width, height);
|
||||
|
||||
// Re-render on resize
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
pixels[y * width + x] = 0xFF1a1a2e;
|
||||
}
|
||||
}
|
||||
montauk::win_present(winId);
|
||||
}
|
||||
}
|
||||
|
||||
montauk::win_destroy(winId);
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* stb_truetype_impl.cpp
|
||||
* Single compilation unit for stb_truetype in libhello
|
||||
* Copyright (c) 2026 Daniel Hammer
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <montauk/heap.h>
|
||||
#include <montauk/string.h>
|
||||
#include <gui/stb_math.h>
|
||||
|
||||
#define STBTT_ifloor(x) ((int) stb_floor(x))
|
||||
#define STBTT_iceil(x) ((int) stb_ceil(x))
|
||||
#define STBTT_sqrt(x) stb_sqrt(x)
|
||||
#define STBTT_pow(x,y) stb_pow(x,y)
|
||||
#define STBTT_fmod(x,y) stb_fmod(x,y)
|
||||
#define STBTT_cos(x) stb_cos(x)
|
||||
#define STBTT_acos(x) stb_acos(x)
|
||||
#define STBTT_fabs(x) stb_fabs(x)
|
||||
|
||||
#define STBTT_malloc(x,u) ((void)(u), montauk::malloc(x))
|
||||
#define STBTT_free(x,u) ((void)(u), montauk::mfree(x))
|
||||
|
||||
#define STBTT_memcpy(d,s,n) montauk::memcpy(d,s,n)
|
||||
#define STBTT_memset(d,v,n) montauk::memset(d,v,n)
|
||||
|
||||
#define STBTT_strlen(x) montauk::slen(x)
|
||||
|
||||
#define STBTT_assert(x) ((void)(x))
|
||||
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#include <gui/stb_truetype.h>
|
||||
Reference in New Issue
Block a user