Imgui initial changes & shim (Claude Opus 4.6)

Can now draw ImGui demo.
This commit is contained in:
2026-02-22 21:06:59 +00:00
parent 8be364c990
commit 51a29244ed
17 changed files with 3124 additions and 102 deletions
+4 -1
View File
@@ -5,9 +5,12 @@ VOLUME ["/code"]
ENV DEBIAN_FRONTEND=noninteractive
RUN dpkg --add-architecture i386
RUN apt-get update && apt-get install -y \
curl dos2unix wget git make nasm binutils:i386 xorriso grub-pc-bin && \
curl dos2unix wget git make nasm binutils xorriso grub-pc-bin \
gcc-multilib g++-multilib && \
apt-get clean my room
RUN git clone --depth=1 --recurse-submodules https://github.com/cimgui/cimgui.git /cimgui
SHELL ["/bin/bash", "-c"]
ARG FPC_VERSION=2.6.4
RUN curl -sL https://sourceforge.net/projects/freepascal/files/Linux/$FPC_VERSION/fpc-$FPC_VERSION.i386-linux.tar/download | tar -xf - && \
+1
View File
@@ -23,6 +23,7 @@ runOrFail() {
declare -a run_steps=(
"compile_stub.sh" "Failed to compile stub!"
"compile_vergen.sh" "Versions failed to compile"
"compile_imgui.sh" "Failed to compile ImGui!"
"compile_sources.sh" "Failed to compile FPC Sources!"
"compile_link.sh" "Failed linking!"
"compile_isogen.sh" "Failed to create ISO!"
+90
View File
@@ -0,0 +1,90 @@
#!/usr/bin/env bash
echo " "
echo "======================="
echo " "
echo "Compiling ImGui (cimgui)..."
echo " "
IMGUI_DIR=/cimgui
IMGUI_SRC=$IMGUI_DIR/imgui
BRIDGE_SRC=src/driver/video/imgui
# Flags shared by all C/C++ compilation units:
# -m32 -> i386 target
# -ffreestanding -> no implicit stdlib inclusion
# -fno-builtin -> don't inline memcpy/memset/etc. so our stubs are used
# -O2 -> optimise for speed
# -ffunction-sections -fdata-sections -> allow --gc-sections in linker
C_FLAGS="-m32 -ffreestanding -fno-builtin -O2 -ffunction-sections -fdata-sections"
# Extra flags for C++ translation units (cimgui/imgui sources):
# -fno-exceptions -> no stack-unwinding machinery
# -fno-rtti -> no typeinfo / dynamic_cast
# -fno-use-cxa-atexit -> don't emit __cxa_atexit calls for static dtors
# -fno-threadsafe-statics -> no guard-variable emission for local statics
# NOTE: *not* -ffreestanding / -fno-builtin here — imgui includes <cmath> and
# other hosted headers that refuse to compile in freestanding mode.
# The object files are archived into a static lib and linked freestanding;
# any hosted-stdlib calls (malloc/free/sin/cos/…) resolve to crtshim.c.
CPP_FLAGS="-m32 -O2 -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti -fno-use-cxa-atexit -fno-threadsafe-statics -fno-stack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -DNDEBUG -DIMGUI_ENABLE_STB_TRUETYPE"
INCLUDE="-I$IMGUI_DIR -I$IMGUI_SRC"
echo "Compiling C runtime shim..."
gcc $C_FLAGS $INCLUDE \
-c $BRIDGE_SRC/crtshim.c \
-o lib/imgui_crtshim.o || { echo "Failed: crtshim.c"; exit 1; }
echo "Compiling render bridge..."
# imgbridge is compiled as C++ so it sees cimgui.h function declarations
# (C++ mode is required; the .c extension is overridden with -x c++)
g++ $CPP_FLAGS $INCLUDE \
-x c++ \
-DCIMGUI_DEFINE_ENUMS_AND_STRUCTS \
-c $BRIDGE_SRC/imgbridge.c \
-o lib/imgui_bridge.o || { echo "Failed: imgbridge.c"; exit 1; }
echo "Compiling cimgui wrapper..."
g++ $CPP_FLAGS $INCLUDE \
-c $IMGUI_DIR/cimgui.cpp \
-o lib/imgui_cimgui.o || { echo "Failed: cimgui.cpp"; exit 1; }
echo "Compiling imgui core..."
g++ $CPP_FLAGS $INCLUDE \
-c $IMGUI_SRC/imgui.cpp \
-o lib/imgui_core.o || { echo "Failed: imgui.cpp"; exit 1; }
echo "Compiling imgui draw..."
g++ $CPP_FLAGS $INCLUDE \
-c $IMGUI_SRC/imgui_draw.cpp \
-o lib/imgui_draw.o || { echo "Failed: imgui_draw.cpp"; exit 1; }
echo "Compiling imgui tables..."
g++ $CPP_FLAGS $INCLUDE \
-c $IMGUI_SRC/imgui_tables.cpp \
-o lib/imgui_tables.o || { echo "Failed: imgui_tables.cpp"; exit 1; }
echo "Compiling imgui widgets..."
g++ $CPP_FLAGS $INCLUDE \
-c $IMGUI_SRC/imgui_widgets.cpp \
-o lib/imgui_widgets.o || { echo "Failed: imgui_widgets.cpp"; exit 1; }
echo "Compiling imgui demo..."
g++ $CPP_FLAGS $INCLUDE \
-c $IMGUI_SRC/imgui_demo.cpp \
-o lib/imgui_demo.o || { echo "Failed: imgui_demo.cpp"; exit 1; }
echo "Archiving cimgui.a..."
# NOTE: imgui_bridge.o and imgui_crtshim.o are NOT in the archive because
# compile_link.sh already picks them up individually via find lib/ -name "*.o".
# Including them here would cause duplicate symbol errors.
ar rcs lib/cimgui.a \
lib/imgui_cimgui.o \
lib/imgui_core.o \
lib/imgui_draw.o \
lib/imgui_tables.o \
lib/imgui_widgets.o \
lib/imgui_demo.o || { echo "Failed: ar"; exit 1; }
echo "ImGui compiled successfully."
exit 0
+3 -1
View File
@@ -14,4 +14,6 @@ done;
objstring=lib/stub.o" "$objstring
echo "Object Files: "$objstring
echo " "
ld -m elf_i386 -s --gc-sections -Tlinker.script -o bin/kernel.bin $objstring
LIBGCC=$(gcc -m32 -print-libgcc-file-name)
ld -m elf_i386 -s --gc-sections -Tlinker.script -o bin/kernel.bin $objstring \
--start-group lib/cimgui.a $LIBGCC --end-group
+1 -1
View File
@@ -4,4 +4,4 @@ echo "======================="
echo " "
echo "Compiling FPC Sources..."
echo " "
fpc -Aelf -gw -g -gl -n -vlewn -O3 -Op3 -Si -Sc -Sg -Xd -CX -XXs -CfSSE -CfSSE2 -Rintel -Pi386 -Tlinux -FElib/ -Fusrc/* -Fusrc/driver/* -Fusrc/driver/net/* src/kernel.pas
fpc -Aelf -gw -g -gl -n -vlewn -O3 -Op3 -Si -Sc -Sg -Xd -CX -XXs -CfSSE -CfSSE2 -Rintel -Pi386 -Tlinux -FElib/ -Fusrc/* -Fusrc/driver/* -Fusrc/driver/net/* -Fusrc/driver/video/* -Fusrc/driver/video/imgui/* src/kernel.pas
+20
View File
@@ -0,0 +1,20 @@
4023:CIMGUI_API float igGetWindowDpiScale(void);
4081:CIMGUI_API const ImVec4_c* igGetStyleColorVec4(ImGuiCol idx);
4082:CIMGUI_API ImVec2_c igGetCursorScreenPos(void);
4084:CIMGUI_API ImVec2_c igGetContentRegionAvail(void);
4085:CIMGUI_API ImVec2_c igGetCursorPos(void);
4086:CIMGUI_API float igGetCursorPosX(void);
4087:CIMGUI_API float igGetCursorPosY(void);
4091:CIMGUI_API ImVec2_c igGetCursorStartPos(void);
4350:CIMGUI_API void igBeginDisabled(bool disabled);
4372:CIMGUI_API ImVec2_c igGetItemRectMin(void);
4373:CIMGUI_API ImVec2_c igGetItemRectMax(void);
4374:CIMGUI_API ImVec2_c igGetItemRectSize(void);
4377:CIMGUI_API ImDrawList* igGetBackgroundDrawList(ImGuiViewport* viewport);
4378:CIMGUI_API ImDrawList* igGetForegroundDrawList_ViewportPtr(ImGuiViewport* viewport);
4387:CIMGUI_API ImVec2_c igCalcTextSize(const char* text,const char* text_end,bool hide_text_after_double_hash,float wrap_width);
4388:CIMGUI_API ImVec4_c igColorConvertU32ToFloat4(ImU32 in);
4405:CIMGUI_API bool igIsMouseDoubleClicked_Nil(ImGuiMouseButton button);
5092:CIMGUI_API ImDrawList* igGetForegroundDrawList_WindowPtr(ImGuiWindow* window);
5161:CIMGUI_API void igBeginDisabledOverrideReenable(void);
5244:CIMGUI_API bool igIsMouseDoubleClicked_ID(ImGuiMouseButton button,ImGuiID owner_id);
+10
View File
@@ -34,4 +34,14 @@ SECTIONS
}
end = .; _end = .; __end = .;
kernel_end = .;
/DISCARD/ : {
*(.init_array*)
*(.fini_array*)
*(.ctors)
*(.dtors)
*(.eh_frame*)
*(.gcc_except_table*)
*(.note.GNU-stack)
}
}
+38 -33
View File
@@ -49,8 +49,12 @@ type
y : sint32;
end;
{ Mouse hook callback: receives absolute position and button states }
TMouseHook = procedure(x, y: sint32; lmb, rmb, mmb: boolean);
procedure init();
procedure DrawCursor;
procedure setHook(h: TMouseHook);
implementation
@@ -67,6 +71,7 @@ var
LMouseDownPos : TMousePos;
LMouseDown : Boolean;
RMouseDown : Boolean;
MouseHookCB : TMouseHook = nil;
procedure DrawCursor;
var
@@ -174,43 +179,38 @@ begin
if Current.y > (Console.getConsoleProperties^.Height-8) then Current.y:= (Console.getConsoleProperties^.Height-8);
end;
Cycle:= 0;
if Packet.LMB_Down then begin
if not LMouseDown then begin
LMouseDown:= true;
LMouseDownPos.x:= Current.x;
LMouseDownPos.y:= Current.y;
//MouseDownEvent
console._mouseDown();
end;
{ Track button transitions }
if Packet.LMB_Down and (not LMouseDown) then begin
LMouseDown:= true;
LMouseDownPos.x:= Current.x;
LMouseDownPos.y:= Current.y;
end;
if not Packet.LMB_Down then begin
if LMouseDown then begin
If (Current.x = LMouseDownPos.x) and (Current.y = LMouseDownPos.y) then begin
Console._MouseClick(true);
end;
//MouseUpEvent
Console._MouseUp();
LMouseDown:= false;
end;
if (not Packet.LMB_Down) and LMouseDown then
LMouseDown:= false;
if Packet.RMB_Down and (not RMouseDown) then begin
RMouseDown:= true;
RMouseDownPos.x:= Current.x;
RMouseDownPos.y:= Current.y;
end;
if Packet.RMB_Down then begin
if not RMouseDown then begin
RMouseDown:= true;
RMouseDownPos.x:= Current.x;
RMouseDownPos.y:= Current.y;
end;
end;
if not Packet.RMB_Down then begin
if RMouseDown then begin
if (Current.x = RMouseDownPos.x) and (Current.y = RMouseDownPos.y) then begin
Console._MouseClick(false);
end;
end;
if (not Packet.RMB_Down) and RMouseDown then
RMouseDown:= false;
{ Dispatch to hook or console }
if MouseHookCB <> nil then
MouseHookCB(Current.x, Current.y, Packet.LMB_Down, Packet.RMB_Down, Packet.MMB_Down)
else begin
if Packet.LMB_Down and (not LMouseDown) then console._mouseDown();
if (not Packet.LMB_Down) and LMouseDown then begin
if (Current.x = LMouseDownPos.x) and (Current.y = LMouseDownPos.y) then
Console._MouseClick(true);
Console._MouseUp();
end;
if (not Packet.RMB_Down) and RMouseDown then begin
if (Current.x = RMouseDownPos.x) and (Current.y = RMouseDownPos.y) then
Console._MouseClick(false);
end;
console.setMousePosition(Current.x, Current.y);
end;
console.setMousePosition(Current.x, Current.y);
end;
end;
end;
@@ -242,6 +242,11 @@ begin
pop_trace;
end;
procedure setHook(h: TMouseHook);
begin
MouseHookCB := h;
end;
procedure init();
var
devid : TDeviceIdentifier;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+16
View File
@@ -35,10 +35,26 @@ implementation
procedure Main();
var
i : integer;
faulting_addr : uint32;
begin
CLI;
{ Read CR2 — the linear address that caused the page fault }
asm
MOV EAX, CR2
MOV faulting_addr, EAX
end;
correctInterruptRegisters(true);
console.writestring('[PF] Faulting address: ');
console.writehexln(faulting_addr);
if IntSpec <> nil then begin
console.writestring('[PF] Faulting EIP: ');
console.writehexln(IntSpec^.EIP);
end;
if IntErr <> nil then begin
console.writestring('[PF] Error code: ');
console.writehexln(IntErr^.Error);
end;
BSOD('PF', 'Page Fault.');
console.writestringln('Page Fault.');
util.halt_and_catch_fire;
+1 -1
View File
@@ -22,7 +22,7 @@ unit multiboot;
interface
const
KERNEL_STACKSIZE = $4000;
KERNEL_STACKSIZE = $40000;
MULTIBOOT_BOOTLOADER_MAGIC = $2BADB002;
type
+30
View File
@@ -152,8 +152,38 @@ var
procedure init();
{ 64-bit multiply compilerproc required by FPC on i386 when
any int64/uint64 arithmetic occurs (e.g. sint32 * uint32 promotion).
Must live in the system unit so the compiler can resolve it. }
function fpc_mul_int64(f1, f2: int64): int64; compilerproc;
implementation
function fpc_mul_int64(f1, f2: int64): int64; [public, alias: 'FPC_MUL_INT64']; compilerproc;
{ 64×64→64 multiply using three 32-bit MUL instructions.
We only keep the low 64 bits of the 128-bit product. }
var
res: int64;
begin
asm
MOV EAX, DWORD [f1] { f1_lo }
MUL DWORD [f2] { EDX:EAX = f1_lo * f2_lo }
MOV DWORD [res], EAX { result_lo }
MOV ECX, EDX { carry = high(f1_lo * f2_lo) }
MOV EAX, DWORD [f1] { f1_lo }
MUL DWORD [f2+4] { EDX:EAX = f1_lo * f2_hi }
ADD ECX, EAX { carry += low(f1_lo * f2_hi) }
MOV EAX, DWORD [f1+4] { f1_hi }
MUL DWORD [f2] { EDX:EAX = f1_hi * f2_lo }
ADD ECX, EAX { carry += low(f1_hi * f2_lo) }
MOV DWORD [res+4], ECX { result_hi }
end;
fpc_mul_int64 := res;
end;
procedure init();
begin
ASURO_KERNEL_START := uint32(@AK_START);
+67 -64
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -49,7 +49,7 @@ MULTIBOOT_HEADER_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEA
;
; Kernel stack size
;
KERNEL_STACKSIZE equ 0x4000
KERNEL_STACKSIZE equ 0x40000
KERNEL_VIRTUAL_BASE equ 0xC0000000
KERNEL_PAGE_NUMBER equ (KERNEL_VIRTUAL_BASE >> 22)