wip swift in kernel
This commit is contained in:
+3
-56
@@ -2,59 +2,6 @@
|
||||
.global _start
|
||||
|
||||
_start:
|
||||
add x1, x0, #64
|
||||
ldr x2, [x1] // base
|
||||
ldr x3, [x1, #16] // width
|
||||
ldr x4, [x1, #24] // height
|
||||
|
||||
mul x5, x3, x4
|
||||
mov x7, #5
|
||||
udiv x10, x5, x7 // stripe size
|
||||
|
||||
// 0x00RRGGBB
|
||||
// lblue: 5B CE FA
|
||||
mov w11, #0xCEFA
|
||||
movk w11, #0x5B, lsl #16
|
||||
|
||||
// pink: F5 A7 B8
|
||||
mov w12, #0xA7B8
|
||||
movk w12, #0xF5, lsl #16
|
||||
|
||||
// white: FF FF FF
|
||||
mov w13, #0xFFFF
|
||||
movk w13, #0xFF, lsl #16
|
||||
|
||||
mov x14, #0 // pixels in curr stripe
|
||||
mov x15, #0 // stripe index
|
||||
|
||||
fill_loop:
|
||||
cbz x5, done
|
||||
|
||||
cmp x15, #0
|
||||
b.eq set_blue
|
||||
cmp x15, #1
|
||||
b.eq set_pink
|
||||
cmp x15, #2
|
||||
b.eq set_white
|
||||
cmp x15, #3
|
||||
b.eq set_pink
|
||||
b set_blue
|
||||
|
||||
set_blue: mov w6, w11; b draw
|
||||
set_pink: mov w6, w12; b draw
|
||||
set_white: mov w6, w13
|
||||
|
||||
draw:
|
||||
str w6, [x2], #4
|
||||
sub x5, x5, #1
|
||||
add x14, x14, #1
|
||||
|
||||
cmp x14, x10
|
||||
b.lt fill_loop
|
||||
|
||||
mov x14, #0
|
||||
add x15, x15, #1
|
||||
b fill_loop
|
||||
|
||||
done:
|
||||
b done
|
||||
bl kmain
|
||||
.hang:
|
||||
b .hang
|
||||
@@ -0,0 +1,22 @@
|
||||
@_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)
|
||||
let stripe = total / 5
|
||||
|
||||
var i = 0
|
||||
while i < total {
|
||||
let s = i / stripe
|
||||
let color: UInt32
|
||||
if s == 0 || s >= 4 { color = 0x5BCEFA }
|
||||
else if s == 2 { color = 0xFFFFFF }
|
||||
else { color = 0xF5A7B8 }
|
||||
pixels[i] = color
|
||||
i &+= 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <stddef.h>
|
||||
|
||||
void* memmove(void* dest, const void* src, unsigned long n) {
|
||||
unsigned char* d = (unsigned char*)dest;
|
||||
const unsigned char* s = (const unsigned char*)src;
|
||||
if (d < s) {
|
||||
while (n--) *d++ = *s++;
|
||||
} else {
|
||||
d += n; s += n;
|
||||
while (n--) *--d = *--s;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
void* memcpy(void* dest, const void* src, unsigned long n) {
|
||||
return memmove(dest, src, n);
|
||||
}
|
||||
|
||||
void* memset(void* dest, int c, unsigned long n) {
|
||||
unsigned char* d = (unsigned char*)dest;
|
||||
while (n--) *d++ = (unsigned char)c;
|
||||
return dest;
|
||||
}
|
||||
|
||||
// Stack protection
|
||||
long __stack_chk_guard = (long)0xDEADBEEFCAFEBABEULL;
|
||||
void __stack_chk_fail(void) { while (1); }
|
||||
|
||||
// Swift embedded uses putchar for print(); stub so it links but does nothing
|
||||
int putchar(int c) { return c; }
|
||||
|
||||
// Swift runtime allocator stubs — should never be called in embedded mode
|
||||
int posix_memalign(void** ptr, unsigned long align, unsigned long size) {
|
||||
(void)ptr; (void)align; (void)size;
|
||||
while (1);
|
||||
}
|
||||
|
||||
void free(void* ptr) { (void)ptr; }
|
||||
Reference in New Issue
Block a user