Merge pull request #2 from 0xKSor/wip/bridge

Added bridging header for swift
This commit is contained in:
Karina
2026-04-20 14:54:14 +04:00
committed by GitHub
4 changed files with 20 additions and 10 deletions
+1
View File
@@ -1,3 +1,4 @@
.build
.vscode
.DS_Store
compile_commands.json
+10
View File
@@ -74,6 +74,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}
@@ -93,3 +95,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"
)
+1
View File
@@ -0,0 +1 @@
#include "bootinfo.h"
+7 -9
View File
@@ -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<UInt>(bitPattern: bootInfo &+ 64)!.pointee
let width = UnsafePointer<UInt64>(bitPattern: bootInfo &+ 80)!.pointee
let height = UnsafePointer<UInt64>(bitPattern: bootInfo &+ 88)!.pointee
let pixels = UnsafeMutablePointer<UInt32>(bitPattern: fbBase)!
let total = Int(width) &* Int(height)
public func kernelMain(_ bootInfo: UnsafeMutablePointer<Bootinfo>) {
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
}