From f3819a54508a606a557100697b0f70fb2543b999 Mon Sep 17 00:00:00 2001 From: hwacha Date: Mon, 20 Apr 2026 16:33:41 +0900 Subject: [PATCH 1/2] Added bridging header for swift c structures are now exposed to swift using a bridging header. it is possible to access bootinfo using the structure (as oppossed to doing bytesfifts blind) tested on aarch64 apple. please test on other systems --- Kernel/CMakeLists.txt | 2 ++ Kernel/Source/BridgingHeader.h | 1 + Kernel/Source/kernel.swift | 16 +++++++--------- 3 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 Kernel/Source/BridgingHeader.h diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 4134daa..0f4e984 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -70,6 +70,8 @@ add_custom_command( -wmo -O -Xcc -fno-stack-protector + -Xcc -I${CMAKE_CURRENT_SOURCE_DIR}/../Common + -import-bridging-header ${CMAKE_CURRENT_SOURCE_DIR}/Source/BridgingHeader.h -resource-dir ${SWIFT_RESOURCE_DIR} -c ${SWIFT_SOURCES} -o ${SWIFT_OBJ} diff --git a/Kernel/Source/BridgingHeader.h b/Kernel/Source/BridgingHeader.h new file mode 100644 index 0000000..49e7ea7 --- /dev/null +++ b/Kernel/Source/BridgingHeader.h @@ -0,0 +1 @@ +#include "bootinfo.h" diff --git a/Kernel/Source/kernel.swift b/Kernel/Source/kernel.swift index 384daaf..4dee551 100644 --- a/Kernel/Source/kernel.swift +++ b/Kernel/Source/kernel.swift @@ -1,12 +1,10 @@ @_cdecl("kmain") -public func kernelMain(_ bootInfo: UInt) { - // Bootinfo offsets: fb starts at 64, then base(8), baseSize(8), width(8), height(8) - let fbBase = UnsafePointer(bitPattern: bootInfo &+ 64)!.pointee - let width = UnsafePointer(bitPattern: bootInfo &+ 80)!.pointee - let height = UnsafePointer(bitPattern: bootInfo &+ 88)!.pointee - - let pixels = UnsafeMutablePointer(bitPattern: fbBase)! - let total = Int(width) &* Int(height) +public func kernelMain(_ bootInfo: UnsafeMutablePointer) { + let fb = bootInfo.pointee.framebuffer + let pixels = fb.base! + let width = Int(fb.width) + let height = Int(fb.height) + let total = width * height let stripe = total / 5 var i = 0 @@ -15,7 +13,7 @@ public func kernelMain(_ bootInfo: UInt) { let color: UInt32 if s == 0 || s >= 4 { color = 0x5BCEFA } else if s == 2 { color = 0xFFFFFF } - else { color = 0xF5A7B8 } + else { color = 0xF5A7B8 } pixels[i] = color i &+= 1 } From e1b74cd1565c57ce1181c36691cc8c64b515bf74 Mon Sep 17 00:00:00 2001 From: hwacha Date: Mon, 20 Apr 2026 18:31:27 +0900 Subject: [PATCH 2/2] Added LSP file auto-generator CMake will auto generate compile-commands.json file to help LSP find symbols. this file is gitignored and will be regenerated each build nothing else was changed, should work on any system, but please test --- .gitignore | 3 ++- Kernel/CMakeLists.txt | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 650360a..02ab928 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .build .vscode -.DS_Store \ No newline at end of file +.DS_Store +compile_commands.json \ No newline at end of file diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 0f4e984..f6cbb61 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -91,3 +91,11 @@ add_custom_command(TARGET kernel.elf POST_BUILD COMMAND ${LLVM_OBJCOPY} -O binary kernel.elf kernel.bin COMMENT "kernel.elf -> kernel.bin" ) + +# --- SourceKit-LSP: generate compile_commands.json for Swift --- +set(_COMMON_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../Common") +set(_BRIDGING_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/Source/BridgingHeader.h") + +file(GENERATE OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json" + CONTENT "[\n {\n \"file\": \"${SWIFT_SOURCES}\",\n \"directory\": \"${CMAKE_CURRENT_BINARY_DIR}\",\n \"arguments\": [\n \"${SWIFTC}\",\n \"-target\", \"aarch64-none-none-elf\",\n \"-enable-experimental-feature\", \"Embedded\",\n \"-parse-as-library\",\n \"-wmo\",\n \"-O\",\n \"-Xcc\", \"-fno-stack-protector\",\n \"-Xcc\", \"-I${_COMMON_DIR}\",\n \"-import-bridging-header\", \"${_BRIDGING_HEADER}\",\n \"-resource-dir\", \"${SWIFT_RESOURCE_DIR}\",\n \"${SWIFT_SOURCES}\"\n ]\n }\n]\n" +)