From f3819a54508a606a557100697b0f70fb2543b999 Mon Sep 17 00:00:00 2001 From: hwacha Date: Mon, 20 Apr 2026 16:33:41 +0900 Subject: [PATCH] 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 }