works on arm and x86 without fiddling with stuff

memory bug fixes
update hblang
update render examples
obliterate render_driver (not useful)
This commit is contained in:
koniifer 2024-09-12 18:14:26 +01:00
parent fef5487e62
commit 022c1c196a
18 changed files with 126 additions and 101 deletions

10
Cargo.lock generated
View file

@ -390,17 +390,17 @@ dependencies = [
[[package]] [[package]]
name = "hbbytecode" name = "hbbytecode"
version = "0.1.0" 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]] [[package]]
name = "hbbytecode" name = "hbbytecode"
version = "0.1.0" 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]] [[package]]
name = "hblang" name = "hblang"
version = "0.1.0" 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 = [ dependencies = [
"hbvm 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)", "hbvm 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)",
] ]
@ -408,7 +408,7 @@ dependencies = [
[[package]] [[package]]
name = "hbvm" name = "hbvm"
version = "0.1.0" 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 = [ dependencies = [
"hbbytecode 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)", "hbbytecode 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)",
] ]
@ -416,7 +416,7 @@ dependencies = [
[[package]] [[package]]
name = "hbvm" name = "hbvm"
version = "0.1.0" 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 = [ dependencies = [
"hbbytecode 0.1.0 (git+https://git.ablecorp.us/ableos/holey-bytes)", "hbbytecode 0.1.0 (git+https://git.ablecorp.us/ableos/holey-bytes)",
] ]

View file

@ -2,8 +2,8 @@
resolver = "2" resolver = "2"
members = ["dev", "kernel", "repbuild"] members = ["dev", "kernel", "repbuild"]
[profile.release] # [profile.release]
strip = "symbols" # strip = "symbols"
codegen-units = 1 # codegen-units = 1
lto = true # lto = true
panic = "abort" # panic = "abort"

View file

@ -29,7 +29,7 @@ fn collect_cpu_info(device_tree: &mut DeviceTree) {
} }
fn cpu_id() -> (String, u64) { fn cpu_id() -> (String, u64) {
let mut cpu_id: u64 = 0; let mut cpu_id: u64;
unsafe { unsafe {
asm!("mrs {cpu_id}, MIDR_EL1", asm!("mrs {cpu_id}, MIDR_EL1",
cpu_id = out(reg) cpu_id, 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 // https://raspberrypi.stackexchange.com/questions/117175/how-do-i-read-the-cpuid-in-aarch64-asm
0x410FD034 => "Cortex-A53".to_string(), 0x410FD034 => "Cortex-A53".to_string(),
0x410FD083 => "Cortex-A72".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(), _ => "Unknown".to_string(),
}; };
log::trace!("CPU Name: {cpu_name} - CPU ID: 0x{:X}", cpu_id); log::trace!("CPU Name: {cpu_name} - CPU ID: 0x{:X}", cpu_id);

View file

@ -55,6 +55,6 @@ impl hbvm::mem::Memory for Memory {
#[inline] #[inline]
unsafe fn prog_read<T: Copy>(&mut self, addr: Address) -> T { unsafe fn prog_read<T: Copy>(&mut self, addr: Address) -> T {
(addr.get() as *const T).read_unaligned() (addr.get() as *const T).read()
} }
} }

View file

@ -370,7 +370,7 @@ fn run(release: bool, target: Target) -> Result<(), Error> {
#[rustfmt::skip] #[rustfmt::skip]
com.args([ com.args([
"-M", "virt", "-M", "virt",
"-cpu", "max", "-cpu", "neoverse-n2",
"-device", "ramfb", "-device", "ramfb",
"-device", "qemu-xhci", "-device", "qemu-xhci",
"-device", "usb-kbd", "-device", "usb-kbd",

View file

@ -1,44 +1,46 @@
svga := @use("rel:svga.hb") svga := @use("rel:svga.hb")
software := @use("rel:software.hb") software := @use("rel:software.hb")
default := software // default mode
mode := software
init := default.init init := mode.init
doublebuffer := mode.doublebuffer
// Colours // Colours
Color := default.Color Color := mode.Color
white := default.white white := mode.white
black := default.black black := mode.black
gray := default.gray gray := mode.gray
red := default.red red := mode.red
green := default.green green := mode.green
yellow := default.yellow yellow := mode.yellow
blue := default.blue blue := mode.blue
magenta := default.magenta magenta := mode.magenta
cyan := default.cyan cyan := mode.cyan
light_gray := default.light_gray light_gray := mode.light_gray
light_red := default.light_red light_red := mode.light_red
light_green := default.light_green light_green := mode.light_green
light_yellow := default.light_yellow light_yellow := mode.light_yellow
light_blue := default.light_blue light_blue := mode.light_blue
light_magenta := default.light_magenta light_magenta := mode.light_magenta
light_cyan := default.light_cyan light_cyan := mode.light_cyan
// Drawing // Drawing
put_pixel := default.put_pixel put_pixel := mode.put_pixel
put_rect := default.put_rect put_rect := mode.put_rect
put_filled_rect := default.put_filled_rect put_filled_rect := mode.put_filled_rect
put_line := default.put_line put_line := mode.put_line
clear := default.clear clear := mode.clear
// Display // Display
width := default.width width := mode.width
height := default.height height := mode.height
dimensions := default.dimensions dimensions := mode.dimensions
set_height := default.set_height set_height := mode.set_height
set_width := default.set_width set_width := mode.set_width
set_dimensions := default.set_dimensions set_dimensions := mode.set_dimensions
sync := default.sync sync := mode.sync
// Math // Math
UVec2 := struct {x: uint, y: uint} UVec2 := struct {x: uint, y: uint}

View file

@ -27,9 +27,24 @@ copy_pixels := math.min(0xC000, fb_bytes) >> 2
partitions := fb_pixels / copy_pixels partitions := fb_pixels / copy_pixels
total_pages := 1 + fb_bytes >> 12 total_pages := 1 + fb_bytes >> 12
front_buffer := @as(^Color, @bitcast(0xFFFF8000C0000000)) ctx := @as(Context, idk)
// jank back buffer time, im sure nothing will go wrong
back_buffer := front_buffer + fb_pixels 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 { create_back_buffer := fn(): ^Color {
if total_pages <= 0xFF { if total_pages <= 0xFF {
@ -49,7 +64,7 @@ create_back_buffer := fn(): ^Color {
} }
clear := fn(color: Color): void { clear := fn(color: Color): void {
cursor := back_buffer cursor := ctx.buf
boundary := cursor + 512 boundary := cursor + 512
loop if cursor == boundary break else { loop if cursor == boundary break else {
*cursor = color *cursor = color
@ -57,27 +72,32 @@ clear := fn(color: Color): void {
} }
boundary += 512 * 7 boundary += 512 * 7
loop if cursor == boundary break else { 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 cursor += 512
} }
boundary += copy_pixels - 4096 boundary += copy_pixels - 4096
loop if cursor == boundary break else { 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 cursor += 4096
} }
boundary += (partitions - 1) * copy_pixels boundary += (partitions - 1) * copy_pixels
loop if cursor == boundary break else { 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]) cursor += @sizeof([u8; copy_pixels])
} }
return return
} }
sync := fn(): void { sync := fn(): void {
n := 0 if ctx.double_buffer {
loop if n == partitions break else { bb := ctx.buf
*(@as(^[Color; copy_pixels], @bitcast(front_buffer)) + n) = *(@as(^[Color; copy_pixels], @bitcast(back_buffer)) + n) fb := ctx.fb
n += 1 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 return
} }
@ -95,7 +115,7 @@ screenidx := fn(x: int, y: int): int {
} }
put_pixel := fn(pos: IVec2, color: Color): void { 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 return
} }
@ -105,7 +125,7 @@ put_filled_rect := fn(pos: IVec2, tr: IVec2, color: Color): void {
end := pos + tr end := pos + tr
loop if x == end.x break else { loop if x == end.x break else {
loop if y == end.y 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 y += 1
} }
x += 1 x += 1
@ -119,14 +139,14 @@ put_rect := fn(pos: IVec2, tr: IVec2, color: Color): void {
y := pos.y y := pos.y
end := pos + tr end := pos + tr
loop if y == end.y break else { loop if y == end.y break else {
*(back_buffer + @inline(screenidx, x, y)) = color; *(ctx.buf + @inline(screenidx, x, y)) = color;
*(back_buffer + @inline(screenidx, x + tr.x, y)) = color *(ctx.buf + @inline(screenidx, x + tr.x, y)) = color
y += 1 y += 1
} }
y = pos.y y = pos.y
loop if x == end.x break else { loop if x == end.x break else {
*(back_buffer + @inline(screenidx, x, y)) = color; *(ctx.buf + @inline(screenidx, x, y)) = color;
*(back_buffer + @inline(screenidx, x, y + tr.y)) = color *(ctx.buf + @inline(screenidx, x, y + tr.y)) = color
x += 1 x += 1
} }
return return
@ -144,7 +164,7 @@ put_line_low := fn(p0: IVec2, p1: IVec2, color: Color): void {
y := p0.y y := p0.y
x := p0.x x := p0.x
loop if x == p1.x break else { loop if x == p1.x break else {
*(back_buffer + @inline(screenidx, x, y)) = color *(ctx.buf + @inline(screenidx, x, y)) = color
if D > 0 { if D > 0 {
y += yi y += yi
D += 2 * (dy - dx) D += 2 * (dy - dx)
@ -168,7 +188,7 @@ put_line_high := fn(p0: IVec2, p1: IVec2, color: Color): void {
x := p0.x x := p0.x
y := p0.y y := p0.y
loop if y == p1.y break else { loop if y == p1.y break else {
*(back_buffer + @inline(screenidx, x, y)) = color *(ctx.buf + @inline(screenidx, x, y)) = color
if D > 0 { if D > 0 {
x += xi x += xi
D += 2 * (dx - dy) D += 2 * (dx - dy)
@ -214,13 +234,20 @@ set_dimensions := fn(new: IVec2): void {
} }
init := fn(): void { init := fn(): void {
arch := @eca(int, 3, 5) back_buffer := create_back_buffer()
// 0: x86_64, 1: aarch64, 2: riscv, (2^64)-1: other ctx = Context.{
if arch == 0 { fb: @as(^Color, @bitcast(0xFFFF8000C0000000)),
front_buffer = @as(^Color, @bitcast(0xFFFF8000C0000000)) bb: back_buffer,
} else if arch == 1 { buf: back_buffer,
front_buffer = @as(^Color, @bitcast(0xFFFF8000BC430000)) double_buffer: true,
} }
back_buffer = create_back_buffer() // 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 return
} else {
// good luck
return
}
} }

View file

@ -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"

View file

@ -1,6 +0,0 @@
render := @use("../../../libraries/render/src/lib.hb")
main := fn(): void {
@inline(render.init)
return
}

View file

@ -4,6 +4,7 @@ render := @use("../../../../libraries/render/src/lib.hb")
the impostor travels left and loops around the screen */ the impostor travels left and loops around the screen */
example := fn(): void { example := fn(): void {
render.init()
x := 0 x := 0
loop { loop {
render.put_rect(.(200 - x, 80), .(430, 380), render.red) render.put_rect(.(200 - x, 80), .(430, 380), render.red)

View file

@ -6,6 +6,7 @@ render := @use("../../../../libraries/render/src/lib.hb")
note that this may happen too fast for you to notice... */ note that this may happen too fast for you to notice... */
example := fn(): void { example := fn(): void {
render.init()
color := render.light_cyan color := render.light_cyan
n := @as(u8, 1) n := @as(u8, 1)
loop { loop {

View file

@ -5,6 +5,7 @@ render := @use("../../../../libraries/render/src/lib.hb")
created on a blue background */ created on a blue background */
example := fn(): void { example := fn(): void {
render.init()
render.clear(.(100, 50, 0, 255)) render.clear(.(100, 50, 0, 255))
width := render.width() width := render.width()
height := render.height() height := render.height()

View file

@ -2,6 +2,8 @@
render := @use("../../../../libraries/render/src/lib.hb") render := @use("../../../../libraries/render/src/lib.hb")
example := fn(): void { example := fn(): void {
render.init()
render.doublebuffer(false)
render.clear(render.black) render.clear(render.black)
loop { loop {
x := random.integer_range(0, 1024) x := random.integer_range(0, 1024)
@ -10,7 +12,6 @@ example := fn(): void {
g := random.integer_range(0, 75) g := random.integer_range(0, 75)
b := random.integer_range(0, 155) b := random.integer_range(0, 155)
render.put_pixel(.(x, y), .(b, g, r, 255)) render.put_pixel(.(x, y), .(b, g, r, 255))
render.sync()
} }
return return
} }

View file

@ -4,6 +4,7 @@ render := @use("../../../../libraries/render/src/lib.hb")
the white outline of a square bounces around the screen */ the white outline of a square bounces around the screen */
example := fn(): void { example := fn(): void {
render.init()
vel := render.IVec2.(1, 1) vel := render.IVec2.(1, 1)
pos := render.IVec2.(100, 100) pos := render.IVec2.(100, 100)
width := render.width() width := render.width()

View file

@ -4,6 +4,7 @@ render := @use("../../../../libraries/render/src/lib.hb")
the screen rapidly flashes red then black */ the screen rapidly flashes red then black */
example := fn(): void { example := fn(): void {
render.init()
loop { loop {
render.clear(render.red) render.clear(render.red)
render.sync() render.sync()

View file

@ -0,0 +1,8 @@
render := @use("../../../../libraries/render/src/lib.hb")
render.mode = render.svga
example := fn(): void {
render.init()
return
}

View file

@ -1,4 +1,4 @@
.{example} := @use("./examples/random.hb") .{example} := @use("./examples/lines.hb")
main := fn(): void { main := fn(): void {
@inline(example) @inline(example)

View file

@ -17,20 +17,17 @@ resolution = "1024x768x24"
[boot.limine.ableos.modules] [boot.limine.ableos.modules]
# [boot.limine.ableos.modules.tests] [boot.limine.ableos.modules.tests]
# path = "boot:///tests.hbf" path = "boot:///tests.hbf"
[boot.limine.ableos.modules.1render_driver] [boot.limine.ableos.modules.0serial_driver]
path = "boot:///render_driver.hbf" path = "boot:///serial_driver.hbf"
# [boot.limine.ableos.modules.0serial_driver] [boot.limine.ableos.modules.diskio_driver]
# path = "boot:///serial_driver.hbf" path = "boot:///diskio_driver.hbf"
# [boot.limine.ableos.modules.diskio_driver]
# 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_test] [boot.limine.ableos.modules.serial_driver_test]
# path = "boot:///serial_driver_test.hbf" path = "boot:///serial_driver_test.hbf"