From 022c1c196abbdfef203298ea6280d252e5e3d810 Mon Sep 17 00:00:00 2001 From: koniifer Date: Thu, 12 Sep 2024 18:14:26 +0100 Subject: [PATCH] works on arm and x86 without fiddling with stuff memory bug fixes update hblang update render examples obliterate render_driver (not useful) --- Cargo.lock | 10 +-- Cargo.toml | 10 +-- .../src/arch/aarch64/device_info_collector.rs | 4 +- kernel/src/holeybytes/mem.rs | 2 +- repbuild/src/main.rs | 2 +- sysdata/libraries/render/src/lib.hb | 64 ++++++++------- sysdata/libraries/render/src/software.hb | 81 ++++++++++++------- sysdata/programs/render_driver/meta.toml | 11 --- sysdata/programs/render_driver/src/main.hb | 6 -- .../render_example/src/examples/amogus.hb | 1 + .../render_example/src/examples/colors.hb | 1 + .../render_example/src/examples/lines.hb | 1 + .../render_example/src/examples/random.hb | 3 +- .../render_example/src/examples/square.hb | 1 + .../render_example/src/examples/strobe.hb | 1 + .../render_example/src/examples/svga.hb | 8 ++ sysdata/programs/render_example/src/main.hb | 2 +- sysdata/system_config.toml | 19 ++--- 18 files changed, 126 insertions(+), 101 deletions(-) delete mode 100644 sysdata/programs/render_driver/meta.toml delete mode 100644 sysdata/programs/render_driver/src/main.hb create mode 100644 sysdata/programs/render_example/src/examples/svga.hb diff --git a/Cargo.lock b/Cargo.lock index 7944be6a..28e23054 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -390,17 +390,17 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#dc418bd5e0b962ec9413af72e5d624e17febcbf2" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#641d344d2dcdf9392f6506831f5ccc31ed5e2ab8" [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/ableos/holey-bytes#dc418bd5e0b962ec9413af72e5d624e17febcbf2" +source = "git+https://git.ablecorp.us/ableos/holey-bytes#641d344d2dcdf9392f6506831f5ccc31ed5e2ab8" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#dc418bd5e0b962ec9413af72e5d624e17febcbf2" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#641d344d2dcdf9392f6506831f5ccc31ed5e2ab8" dependencies = [ "hbvm 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)", ] @@ -408,7 +408,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#dc418bd5e0b962ec9413af72e5d624e17febcbf2" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#641d344d2dcdf9392f6506831f5ccc31ed5e2ab8" dependencies = [ "hbbytecode 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)", ] @@ -416,7 +416,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/ableos/holey-bytes#dc418bd5e0b962ec9413af72e5d624e17febcbf2" +source = "git+https://git.ablecorp.us/ableos/holey-bytes#641d344d2dcdf9392f6506831f5ccc31ed5e2ab8" dependencies = [ "hbbytecode 0.1.0 (git+https://git.ablecorp.us/ableos/holey-bytes)", ] diff --git a/Cargo.toml b/Cargo.toml index 2a294677..38799da3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,8 @@ resolver = "2" members = ["dev", "kernel", "repbuild"] -[profile.release] -strip = "symbols" -codegen-units = 1 -lto = true -panic = "abort" +# [profile.release] +# strip = "symbols" +# codegen-units = 1 +# lto = true +# panic = "abort" diff --git a/kernel/src/arch/aarch64/device_info_collector.rs b/kernel/src/arch/aarch64/device_info_collector.rs index dd200d3e..c17d5d13 100644 --- a/kernel/src/arch/aarch64/device_info_collector.rs +++ b/kernel/src/arch/aarch64/device_info_collector.rs @@ -29,7 +29,7 @@ fn collect_cpu_info(device_tree: &mut DeviceTree) { } fn cpu_id() -> (String, u64) { - let mut cpu_id: u64 = 0; + let mut cpu_id: u64; unsafe { asm!("mrs {cpu_id}, MIDR_EL1", cpu_id = out(reg) cpu_id, @@ -41,6 +41,8 @@ fn cpu_id() -> (String, u64) { // https://raspberrypi.stackexchange.com/questions/117175/how-do-i-read-the-cpuid-in-aarch64-asm 0x410FD034 => "Cortex-A53".to_string(), 0x410FD083 => "Cortex-A72".to_string(), + // the source of this one was checking the cpu id :thinking: + 0x410FD493 => "Neoverse N2".to_string(), _ => "Unknown".to_string(), }; log::trace!("CPU Name: {cpu_name} - CPU ID: 0x{:X}", cpu_id); diff --git a/kernel/src/holeybytes/mem.rs b/kernel/src/holeybytes/mem.rs index a85a6f20..35a423ba 100644 --- a/kernel/src/holeybytes/mem.rs +++ b/kernel/src/holeybytes/mem.rs @@ -55,6 +55,6 @@ impl hbvm::mem::Memory for Memory { #[inline] unsafe fn prog_read(&mut self, addr: Address) -> T { - (addr.get() as *const T).read_unaligned() + (addr.get() as *const T).read() } } diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 02c1b8d7..eede3ed3 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -370,7 +370,7 @@ fn run(release: bool, target: Target) -> Result<(), Error> { #[rustfmt::skip] com.args([ "-M", "virt", - "-cpu", "max", + "-cpu", "neoverse-n2", "-device", "ramfb", "-device", "qemu-xhci", "-device", "usb-kbd", diff --git a/sysdata/libraries/render/src/lib.hb b/sysdata/libraries/render/src/lib.hb index 47a3b7e6..6cf0ccd5 100644 --- a/sysdata/libraries/render/src/lib.hb +++ b/sysdata/libraries/render/src/lib.hb @@ -1,44 +1,46 @@ svga := @use("rel:svga.hb") software := @use("rel:software.hb") -default := software +// default mode +mode := software -init := default.init +init := mode.init +doublebuffer := mode.doublebuffer // Colours -Color := default.Color -white := default.white -black := default.black -gray := default.gray -red := default.red -green := default.green -yellow := default.yellow -blue := default.blue -magenta := default.magenta -cyan := default.cyan -light_gray := default.light_gray -light_red := default.light_red -light_green := default.light_green -light_yellow := default.light_yellow -light_blue := default.light_blue -light_magenta := default.light_magenta -light_cyan := default.light_cyan +Color := mode.Color +white := mode.white +black := mode.black +gray := mode.gray +red := mode.red +green := mode.green +yellow := mode.yellow +blue := mode.blue +magenta := mode.magenta +cyan := mode.cyan +light_gray := mode.light_gray +light_red := mode.light_red +light_green := mode.light_green +light_yellow := mode.light_yellow +light_blue := mode.light_blue +light_magenta := mode.light_magenta +light_cyan := mode.light_cyan // Drawing -put_pixel := default.put_pixel -put_rect := default.put_rect -put_filled_rect := default.put_filled_rect -put_line := default.put_line -clear := default.clear +put_pixel := mode.put_pixel +put_rect := mode.put_rect +put_filled_rect := mode.put_filled_rect +put_line := mode.put_line +clear := mode.clear // Display -width := default.width -height := default.height -dimensions := default.dimensions -set_height := default.set_height -set_width := default.set_width -set_dimensions := default.set_dimensions -sync := default.sync +width := mode.width +height := mode.height +dimensions := mode.dimensions +set_height := mode.set_height +set_width := mode.set_width +set_dimensions := mode.set_dimensions +sync := mode.sync // Math UVec2 := struct {x: uint, y: uint} diff --git a/sysdata/libraries/render/src/software.hb b/sysdata/libraries/render/src/software.hb index 4354131b..48e13641 100644 --- a/sysdata/libraries/render/src/software.hb +++ b/sysdata/libraries/render/src/software.hb @@ -27,9 +27,24 @@ copy_pixels := math.min(0xC000, fb_bytes) >> 2 partitions := fb_pixels / copy_pixels total_pages := 1 + fb_bytes >> 12 -front_buffer := @as(^Color, @bitcast(0xFFFF8000C0000000)) -// jank back buffer time, im sure nothing will go wrong -back_buffer := front_buffer + fb_pixels +ctx := @as(Context, idk) + +Context := struct { + fb: ^Color, + bb: ^Color, + buf: ^Color, + double_buffer: bool, +} + +doublebuffer := fn(enable: bool): void { + if enable { + ctx.buf = ctx.bb + } else { + ctx.buf = ctx.fb + } + ctx.double_buffer = enable + return +} create_back_buffer := fn(): ^Color { if total_pages <= 0xFF { @@ -49,7 +64,7 @@ create_back_buffer := fn(): ^Color { } clear := fn(color: Color): void { - cursor := back_buffer + cursor := ctx.buf boundary := cursor + 512 loop if cursor == boundary break else { *cursor = color @@ -57,27 +72,32 @@ clear := fn(color: Color): void { } boundary += 512 * 7 loop if cursor == boundary break else { - *@as(^[Color; 512], @bitcast(cursor)) = *@as(^[Color; 512], @bitcast(back_buffer)) + *@as(^[Color; 512], @bitcast(cursor)) = *@as(^[Color; 512], @bitcast(ctx.buf)) cursor += 512 } boundary += copy_pixels - 4096 loop if cursor == boundary break else { - *@as(^[Color; 4096], @bitcast(cursor)) = *@as(^[Color; 4096], @bitcast(back_buffer)) + *@as(^[Color; 4096], @bitcast(cursor)) = *@as(^[Color; 4096], @bitcast(ctx.buf)) cursor += 4096 } boundary += (partitions - 1) * copy_pixels loop if cursor == boundary break else { - *@as(^[Color; copy_pixels], @bitcast(cursor)) = *@as(^[Color; copy_pixels], @bitcast(back_buffer)) + *@as(^[Color; copy_pixels], @bitcast(cursor)) = *@as(^[Color; copy_pixels], @bitcast(ctx.buf)) cursor += @sizeof([u8; copy_pixels]) } return } sync := fn(): void { - n := 0 - loop if n == partitions break else { - *(@as(^[Color; copy_pixels], @bitcast(front_buffer)) + n) = *(@as(^[Color; copy_pixels], @bitcast(back_buffer)) + n) - n += 1 + if ctx.double_buffer { + bb := ctx.buf + fb := ctx.fb + boundary := bb + fb_pixels + loop if bb == boundary break else { + *@as(^[Color; copy_pixels], @bitcast(fb)) = *@as(^[Color; copy_pixels], @bitcast(bb)) + bb += @sizeof([u8; copy_pixels]) + fb += @sizeof([u8; copy_pixels]) + } } return } @@ -95,7 +115,7 @@ screenidx := fn(x: int, y: int): int { } put_pixel := fn(pos: IVec2, color: Color): void { - *(back_buffer + @inline(screenidx, pos.x, pos.y)) = color + *(ctx.buf + @inline(screenidx, pos.x, pos.y)) = color return } @@ -105,7 +125,7 @@ put_filled_rect := fn(pos: IVec2, tr: IVec2, color: Color): void { end := pos + tr loop if x == end.x break else { loop if y == end.y break else { - *(back_buffer + @inline(screenidx, x, y)) = color + *(ctx.buf + @inline(screenidx, x, y)) = color y += 1 } x += 1 @@ -119,14 +139,14 @@ put_rect := fn(pos: IVec2, tr: IVec2, color: Color): void { y := pos.y end := pos + tr loop if y == end.y break else { - *(back_buffer + @inline(screenidx, x, y)) = color; - *(back_buffer + @inline(screenidx, x + tr.x, y)) = color + *(ctx.buf + @inline(screenidx, x, y)) = color; + *(ctx.buf + @inline(screenidx, x + tr.x, y)) = color y += 1 } y = pos.y loop if x == end.x break else { - *(back_buffer + @inline(screenidx, x, y)) = color; - *(back_buffer + @inline(screenidx, x, y + tr.y)) = color + *(ctx.buf + @inline(screenidx, x, y)) = color; + *(ctx.buf + @inline(screenidx, x, y + tr.y)) = color x += 1 } return @@ -144,7 +164,7 @@ put_line_low := fn(p0: IVec2, p1: IVec2, color: Color): void { y := p0.y x := p0.x loop if x == p1.x break else { - *(back_buffer + @inline(screenidx, x, y)) = color + *(ctx.buf + @inline(screenidx, x, y)) = color if D > 0 { y += yi D += 2 * (dy - dx) @@ -168,7 +188,7 @@ put_line_high := fn(p0: IVec2, p1: IVec2, color: Color): void { x := p0.x y := p0.y loop if y == p1.y break else { - *(back_buffer + @inline(screenidx, x, y)) = color + *(ctx.buf + @inline(screenidx, x, y)) = color if D > 0 { x += xi D += 2 * (dx - dy) @@ -214,13 +234,20 @@ set_dimensions := fn(new: IVec2): void { } init := fn(): void { - arch := @eca(int, 3, 5) - // 0: x86_64, 1: aarch64, 2: riscv, (2^64)-1: other - if arch == 0 { - front_buffer = @as(^Color, @bitcast(0xFFFF8000C0000000)) - } else if arch == 1 { - front_buffer = @as(^Color, @bitcast(0xFFFF8000BC430000)) + back_buffer := create_back_buffer() + ctx = Context.{ + fb: @as(^Color, @bitcast(0xFFFF8000C0000000)), + bb: back_buffer, + buf: back_buffer, + double_buffer: true, + } + // 0: x86_64, 1: aarch64, 2: riscv, (2^64)-1: other + arch := @eca(int, 3, 5) + if arch == 1 { + ctx.fb = @as(^Color, @bitcast(0xFFFF8000BC430000)) + return + } else { + // good luck + return } - back_buffer = create_back_buffer() - return } \ No newline at end of file diff --git a/sysdata/programs/render_driver/meta.toml b/sysdata/programs/render_driver/meta.toml deleted file mode 100644 index 95bd66f0..00000000 --- a/sysdata/programs/render_driver/meta.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "render_driver" -authors = ["koniifer"] - -[dependants.libraries] - -[dependants.binaries] -hblang.version = "1.0.0" - -[build] -command = "hblang src/main.hb" diff --git a/sysdata/programs/render_driver/src/main.hb b/sysdata/programs/render_driver/src/main.hb deleted file mode 100644 index a92a5375..00000000 --- a/sysdata/programs/render_driver/src/main.hb +++ /dev/null @@ -1,6 +0,0 @@ -render := @use("../../../libraries/render/src/lib.hb") - -main := fn(): void { - @inline(render.init) - return -} \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/amogus.hb b/sysdata/programs/render_example/src/examples/amogus.hb index 77feba73..eca4e485 100644 --- a/sysdata/programs/render_example/src/examples/amogus.hb +++ b/sysdata/programs/render_example/src/examples/amogus.hb @@ -4,6 +4,7 @@ render := @use("../../../../libraries/render/src/lib.hb") the impostor travels left and loops around the screen */ example := fn(): void { + render.init() x := 0 loop { render.put_rect(.(200 - x, 80), .(430, 380), render.red) diff --git a/sysdata/programs/render_example/src/examples/colors.hb b/sysdata/programs/render_example/src/examples/colors.hb index b357d629..5451d3d7 100644 --- a/sysdata/programs/render_example/src/examples/colors.hb +++ b/sysdata/programs/render_example/src/examples/colors.hb @@ -6,6 +6,7 @@ render := @use("../../../../libraries/render/src/lib.hb") note that this may happen too fast for you to notice... */ example := fn(): void { + render.init() color := render.light_cyan n := @as(u8, 1) loop { diff --git a/sysdata/programs/render_example/src/examples/lines.hb b/sysdata/programs/render_example/src/examples/lines.hb index ff2953c9..5a416096 100644 --- a/sysdata/programs/render_example/src/examples/lines.hb +++ b/sysdata/programs/render_example/src/examples/lines.hb @@ -5,6 +5,7 @@ render := @use("../../../../libraries/render/src/lib.hb") created on a blue background */ example := fn(): void { + render.init() render.clear(.(100, 50, 0, 255)) width := render.width() height := render.height() diff --git a/sysdata/programs/render_example/src/examples/random.hb b/sysdata/programs/render_example/src/examples/random.hb index 5f8d982c..7b0fbbb4 100644 --- a/sysdata/programs/render_example/src/examples/random.hb +++ b/sysdata/programs/render_example/src/examples/random.hb @@ -2,6 +2,8 @@ render := @use("../../../../libraries/render/src/lib.hb") example := fn(): void { + render.init() + render.doublebuffer(false) render.clear(render.black) loop { x := random.integer_range(0, 1024) @@ -10,7 +12,6 @@ example := fn(): void { g := random.integer_range(0, 75) b := random.integer_range(0, 155) render.put_pixel(.(x, y), .(b, g, r, 255)) - render.sync() } return } \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/square.hb b/sysdata/programs/render_example/src/examples/square.hb index 54b4416e..def4fea1 100644 --- a/sysdata/programs/render_example/src/examples/square.hb +++ b/sysdata/programs/render_example/src/examples/square.hb @@ -4,6 +4,7 @@ render := @use("../../../../libraries/render/src/lib.hb") the white outline of a square bounces around the screen */ example := fn(): void { + render.init() vel := render.IVec2.(1, 1) pos := render.IVec2.(100, 100) width := render.width() diff --git a/sysdata/programs/render_example/src/examples/strobe.hb b/sysdata/programs/render_example/src/examples/strobe.hb index e3d0b498..4681cc5e 100644 --- a/sysdata/programs/render_example/src/examples/strobe.hb +++ b/sysdata/programs/render_example/src/examples/strobe.hb @@ -4,6 +4,7 @@ render := @use("../../../../libraries/render/src/lib.hb") the screen rapidly flashes red then black */ example := fn(): void { + render.init() loop { render.clear(render.red) render.sync() diff --git a/sysdata/programs/render_example/src/examples/svga.hb b/sysdata/programs/render_example/src/examples/svga.hb new file mode 100644 index 00000000..101aa6fb --- /dev/null +++ b/sysdata/programs/render_example/src/examples/svga.hb @@ -0,0 +1,8 @@ +render := @use("../../../../libraries/render/src/lib.hb") + +render.mode = render.svga + +example := fn(): void { + render.init() + return +} \ No newline at end of file diff --git a/sysdata/programs/render_example/src/main.hb b/sysdata/programs/render_example/src/main.hb index 336f76d1..63d63909 100644 --- a/sysdata/programs/render_example/src/main.hb +++ b/sysdata/programs/render_example/src/main.hb @@ -1,4 +1,4 @@ -.{example} := @use("./examples/random.hb") +.{example} := @use("./examples/lines.hb") main := fn(): void { @inline(example) diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index d90a7fb5..98caf84e 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -17,20 +17,17 @@ resolution = "1024x768x24" [boot.limine.ableos.modules] -# [boot.limine.ableos.modules.tests] -# path = "boot:///tests.hbf" +[boot.limine.ableos.modules.tests] +path = "boot:///tests.hbf" -[boot.limine.ableos.modules.1render_driver] -path = "boot:///render_driver.hbf" +[boot.limine.ableos.modules.0serial_driver] +path = "boot:///serial_driver.hbf" -# [boot.limine.ableos.modules.0serial_driver] -# path = "boot:///serial_driver.hbf" - -# [boot.limine.ableos.modules.diskio_driver] -# path = "boot:///diskio_driver.hbf" +[boot.limine.ableos.modules.diskio_driver] +path = "boot:///diskio_driver.hbf" [boot.limine.ableos.modules.render_example] path = "boot:///render_example.hbf" -# [boot.limine.ableos.modules.serial_driver_test] -# path = "boot:///serial_driver_test.hbf" +[boot.limine.ableos.modules.serial_driver_test] +path = "boot:///serial_driver_test.hbf"