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]]
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)",
]

View file

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

View file

@ -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);

View file

@ -55,6 +55,6 @@ impl hbvm::mem::Memory for Memory {
#[inline]
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]
com.args([
"-M", "virt",
"-cpu", "max",
"-cpu", "neoverse-n2",
"-device", "ramfb",
"-device", "qemu-xhci",
"-device", "usb-kbd",

View file

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

View file

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

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 */
example := fn(): void {
render.init()
x := 0
loop {
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... */
example := fn(): void {
render.init()
color := render.light_cyan
n := @as(u8, 1)
loop {

View file

@ -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()

View file

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

View file

@ -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()

View file

@ -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()

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 {
@inline(example)

View file

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