1
0
Fork 0
forked from AbleOS/ableos
This commit is contained in:
koniifer 2024-10-23 21:22:28 +01:00
parent b35b430047
commit 6ff65eee41
11 changed files with 64 additions and 51 deletions

View file

@ -251,6 +251,7 @@ unsafe extern "C" fn start() -> ! {
/// Spin loop /// Spin loop
pub fn spin_loop() -> ! { pub fn spin_loop() -> ! {
loop { loop {
core::hint::spin_loop();
x86_64::instructions::hlt() x86_64::instructions::hlt()
} }
} }

View file

@ -75,16 +75,14 @@ pub fn memory_msg_handler(
match msg_type { match msg_type {
0 => unsafe { 0 => unsafe {
let page_count = msg_vec[1]; let page_count = msg_vec[1];
let mptr_raw: [u8; 8] = msg_vec[2..10].try_into().unwrap();
let mptr: u64 = u64::from_le_bytes(mptr_raw);
log::debug!("Allocating {} pages @ {:x}", page_count, mptr);
let ptr = alloc(Layout::from_size_align_unchecked( let ptr = alloc(Layout::from_size_align_unchecked(
page_count as usize * 4096, page_count as usize * 4096,
8, 8,
)); ));
log::debug!("Allocating {} pages @ {:x}", page_count, ptr as u64);
vm.registers[1] = hbvm::value::Value(ptr as u64); vm.registers[1] = hbvm::value::Value(ptr as u64);
log::debug!("Kernel ptr: {:x}", ptr as u64); log::debug!("Kernel ptr: {:x}", ptr as u64);
}, },

View file

@ -25,6 +25,7 @@ create_window := fn(channel: int): ^render.Surface {
if windowing_system_buffer == 0 { if windowing_system_buffer == 0 {
return 0 return 0
} else { } else {
// ! bad able, stop using string messages :ragey:
// msg := "\{01}\0" // msg := "\{01}\0"
// msg_length := 2 // msg_length := 2
@ -33,7 +34,7 @@ create_window := fn(channel: int): ^render.Surface {
x := 0 x := 0
loop if x > 1000 break else x += 1 loop if x > 1000 break else x += 1
ret := buffer.recv(windowing_system_buffer, mem_buf, 4096) ret := buffer.recv([u8; 4096], windowing_system_buffer, mem_buf)
if ret == 0 { if ret == 0 {
log.info("No messages\0") log.info("No messages\0")
} }

View file

@ -30,9 +30,9 @@ clone_surface := fn(surface: ^Surface): Surface {
return new return new
} }
free_surface := fn(surface: ^Surface): void { // ! is broken, check memory.free function
// todo: depends on stn.memory.free free_surface := fn(surface: Surface): void {
return return @inline(memory.free, Color, surface.buf, @intcast(surface.width * surface.height), false)
} }
framebuffer := @as(^Color, idk) framebuffer := @as(^Color, idk)
@ -53,6 +53,10 @@ clear := fn(surface: Surface, color: Color): void {
} }
sync := fn(surface: Surface): void { sync := fn(surface: Surface): void {
// vague safety
if surface.buf == framebuffer {
return
}
return @inline(memory.copy, Color, surface.buf, framebuffer, @bitcast(surface.width * surface.height)) return @inline(memory.copy, Color, surface.buf, framebuffer, @bitcast(surface.width * surface.height))
} }

View file

@ -1,11 +1,11 @@
string := @use("string.hb") string := @use("string.hb")
recv := fn(buffer_id: int, memory_map_location: ^u8, length: int): ^u8 { recv := fn($Expr: type, buffer_id: int, memory_map_location: ^u8): ^Expr {
return @eca(4, buffer_id, memory_map_location, length) return @eca(4, buffer_id, memory_map_location, @sizeof(Expr))
} }
write := fn(msg: ^u8, buffer_id: int, length: int): void { write := fn($Expr: type, msg: ^Expr, buffer_id: int): void {
return @eca(3, buffer_id, msg, length) return @eca(3, buffer_id, msg, @sizeof(Expr))
} }
BufferMsg := packed struct {operation: u8, msg: ^u8, msg_len: uint} BufferMsg := packed struct {operation: u8, msg: ^u8, msg_len: uint}

View file

@ -1,65 +1,79 @@
PAGE_SIZE := 4096 PAGE_SIZE := 4096
MAX_ALLOC := 0xFF MAX_ALLOC := 0xFF
MAX_FREE := 0xFF
calc_pages := fn($Expr: type, num: int): int {
return 1 + @bitcast(@sizeof(Expr)) * num / PAGE_SIZE
}
alloc := fn($Expr: type, num: int): ^Expr { alloc := fn($Expr: type, num: int): ^Expr {
pages := 1 + @bitcast(@sizeof(Expr)) * num / PAGE_SIZE pages := @inline(calc_pages, Expr, num)
if pages <= MAX_ALLOC { if pages <= MAX_ALLOC {
return @bitcast(@inline(request_page, pages)) return @bitcast(request_page(@intcast(pages)))
} }
ptr := @inline(request_page, 0xFF) ptr := request_page(0xFF)
remaining := pages - MAX_ALLOC remaining := pages - MAX_ALLOC
loop if remaining <= 0 break else { loop if remaining <= 0 break else {
if remaining < MAX_ALLOC { if remaining < MAX_ALLOC {
request_page(remaining) request_page(@intcast(remaining))
} else { } else {
request_page(MAX_ALLOC) request_page(@intcast(MAX_ALLOC))
} }
remaining -= MAX_ALLOC remaining -= MAX_ALLOC
} }
return @bitcast(ptr) return @bitcast(ptr)
} }
free := fn($Expr: type, ptr: ^Expr, num: int): void { // ! is broked, somebody fix please :(
// todo free := fn($Expr: type, ptr: ^Expr, num: int, nullify: bool): void {
if nullify {
null := @as(u8, 0)
set(u8, &null, @bitcast(ptr), @bitcast(num) * @bitcast(PAGE_SIZE))
}
pages := @inline(calc_pages, Expr, num)
if pages <= MAX_FREE {
return release_page(@bitcast(ptr), @intcast(pages))
}
page_ptr := @as(^[u8; PAGE_SIZE], @bitcast(ptr)) + 1
remaining := pages - MAX_FREE
loop if remaining <= 0 break else {
if remaining < MAX_FREE {
release_page(@bitcast(page_ptr), @intcast(remaining))
} else {
release_page(@bitcast(page_ptr), @intcast(MAX_FREE))
}
remaining -= MAX_FREE
page_ptr += 1
}
return return
} }
request_page := fn(page_count: u8): ^u8 { RqPageMsg := packed struct {a: u8, count: u8}
msg := "\{00}\{01}xxxxxxxx\0" request_page := fn(count: u8): ^u8 {
msg_page_count := msg + 1; return @eca(3, 2, &RqPageMsg.(0, count), @sizeof(RqPageMsg))
*msg_page_count = page_count
return @eca(3, 2, msg, 12)
} }
release_page := fn(ptr: ^u8, page_count: u8): void { RlPageMsg := packed struct {a: u8, count: u8, ptr: ^u8}
msg := "\{01}\{00}xxxxxxxx\0" release_page := fn(ptr: ^u8, count: u8): void {
return @eca(3, 2, &RlPageMsg.(1, count, ptr), @sizeof(RlPageMsg))
msg_page_count := msg + 1;
*msg_page_count = page_count
msg_ptr := @as(^^u8, @bitcast(msg + 2));
*msg_ptr = ptr
return @eca(3, 2, msg, 12)
} }
OutbMsg := packed struct {a: u8, b: u8, addr: u16, value: u8} OutbMsg := packed struct {a: u8, b: u8, addr: u16, value: u8}
InbMsg := packed struct {a: u8, b: u8, addr: u16}
OutlMsg := packed struct {a: u8, b: u8, addr: u16, value: u32}
InlMsg := packed struct {a: u8, b: u8, addr: u16}
outb := fn(addr: u16, value: u8): void { outb := fn(addr: u16, value: u8): void {
return @eca(3, 3, &OutbMsg.(1, 0, addr, value), @sizeof(OutbMsg)) return @eca(3, 3, &OutbMsg.(1, 0, addr, value), @sizeof(OutbMsg))
} }
InbMsg := packed struct {a: u8, b: u8, addr: u16}
inb := fn(addr: u16): u8 { inb := fn(addr: u16): u8 {
return @eca(3, 3, &InbMsg.(0, 0, addr), @sizeof(InbMsg)) return @eca(3, 3, &InbMsg.(0, 0, addr), @sizeof(InbMsg))
} }
OutlMsg := packed struct {a: u8, b: u8, addr: u16, value: u32}
outl := fn(addr: u16, value: u32): void { outl := fn(addr: u16, value: u32): void {
return @eca(3, 3, &OutlMsg.(1, 2, addr, value), @sizeof(OutlMsg)) return @eca(3, 3, &OutlMsg.(1, 2, addr, value), @sizeof(OutlMsg))
} }
InlMsg := packed struct {a: u8, b: u8, addr: u16}
inl := fn(addr: u16): u32 { inl := fn(addr: u16): u32 {
return @eca(3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg)) return @eca(3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg))
} }

View file

@ -18,7 +18,6 @@ Window := struct {
main := fn(): int { main := fn(): int {
win_buff := buffer.create("XHorizon\0") win_buff := buffer.create("XHorizon\0")
// BUG: Backbuffering is disabled
screen := render.init(true) screen := render.init(true)
// Clear the screen to black. // Clear the screen to black.
@ -41,7 +40,7 @@ main := fn(): int {
// TODO: Read the window buffer here // TODO: Read the window buffer here
{ {
ret := buffer.recv(win_buff, mem_buf, 4096) ret := buffer.recv([u8; 4096], win_buff, mem_buf)
if ret == 0 { if ret == 0 {
log.info("No messages\0") log.info("No messages\0")
} }

View file

@ -1,4 +1,4 @@
.{memory, log, string, buffer} := @use("../../../libraries/stn/src/lib.hb") .{memory, log, buffer} := @use("../../../libraries/stn/src/lib.hb")
send_byte := fn(byte: u8): u8 { send_byte := fn(byte: u8): u8 {
memory.outb(96, byte) memory.outb(96, byte)
@ -15,7 +15,6 @@ main := fn(): int {
if send_byte(244) == 250 { if send_byte(244) == 250 {
log.info("Enabled scanning\0") log.info("Enabled scanning\0")
} }
ptr := memory.request_page(1)
prev_input := 250 prev_input := 250
loop { loop {
input := memory.inb(96) input := memory.inb(96)
@ -23,7 +22,7 @@ main := fn(): int {
continue continue
} }
prev_input = input prev_input = input
buffer.write(&input, buf, 1) buffer.write(u8, &input, buf)
} }
return 0 return 0
} }

View file

@ -25,7 +25,7 @@ main := fn(): int {
mem := memory.request_page(1) mem := memory.request_page(1)
loop { loop {
ptr := @eca(4, a, mem, 0x1000) ptr := @as(^u8, @eca(4, a, mem, 0x1000))
if ptr == 0 { if ptr == 0 {
serial_println("No message\0") serial_println("No message\0")
} }

View file

@ -6,7 +6,7 @@ log_info := fn(): void {
} else { } else {
msg := "XABC\0" msg := "XABC\0"
msg_length := @inline(string.length, msg) msg_length := @inline(string.length, msg)
@eca(3, a, msg, msg_length) @as(void, @eca(3, a, msg, msg_length))
} }
return return

View file

@ -25,15 +25,15 @@ resolution = "1024x768x24"
# [boot.limine.ableos.modules.tests] # [boot.limine.ableos.modules.tests]
# path = "boot:///tests.hbf" # path = "boot:///tests.hbf"
# [boot.limine.ableos.modules.serial_driver]
# path = "boot:///serial_driver.hbf"
# [boot.limine.ableos.modules.diskio_driver] # [boot.limine.ableos.modules.diskio_driver]
# path = "boot:///diskio_driver.hbf" # path = "boot:///diskio_driver.hbf"
[boot.limine.ableos.modules.render_example] [boot.limine.ableos.modules.render_example]
path = "boot:///render_example.hbf" path = "boot:///render_example.hbf"
# [boot.limine.ableos.modules.serial_driver]
# path = "boot:///serial_driver.hbf"
# [boot.limine.ableos.modules.serial_driver_test] # [boot.limine.ableos.modules.serial_driver_test]
# path = "boot:///serial_driver_test.hbf" # path = "boot:///serial_driver_test.hbf"
@ -57,6 +57,3 @@ path = "boot:///render_example.hbf"
# [boot.limine.ableos.modules.pumpkin_print] # [boot.limine.ableos.modules.pumpkin_print]
# path = "boot:///pumpkin_print.hbf" # path = "boot:///pumpkin_print.hbf"
# [boot.limine.ableos.modules.tetris]
# path = "boot:///tetris.hbf"