From de8000f5960101d287ad0c838df3a1cf2bb59679 Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 13 Oct 2024 23:15:10 +0200 Subject: [PATCH 01/23] Fixed software renderer; added vline,hline,trirect --- sysdata/libraries/render/src/lib.hb | 3 + sysdata/libraries/render/src/software.hb | 58 ++++++++++++- .../src/examples/tactical_screen.hb | 83 +++++++++++++++++++ sysdata/programs/render_example/src/main.hb | 2 +- sysdata/programs/tetris/src/main.hb | 25 ++++-- sysdata/system_config.toml | 4 +- 6 files changed, 165 insertions(+), 10 deletions(-) create mode 100644 sysdata/programs/render_example/src/examples/tactical_screen.hb diff --git a/sysdata/libraries/render/src/lib.hb b/sysdata/libraries/render/src/lib.hb index 5c0baed..7300319 100644 --- a/sysdata/libraries/render/src/lib.hb +++ b/sysdata/libraries/render/src/lib.hb @@ -30,7 +30,10 @@ light_cyan := mode.light_cyan put_pixel := mode.put_pixel put_rect := mode.put_rect put_filled_rect := mode.put_filled_rect +put_trirect := mode.put_trirect put_line := mode.put_line +put_vline := mode.put_vline +put_hline := mode.put_hline clear := mode.clear put_img := mode.put_img diff --git a/sysdata/libraries/render/src/software.hb b/sysdata/libraries/render/src/software.hb index a89057b..87b1bdb 100644 --- a/sysdata/libraries/render/src/software.hb +++ b/sysdata/libraries/render/src/software.hb @@ -119,7 +119,7 @@ sync := fn(): void { bb := ctx.buf fb := ctx.fb boundary := bb + ctx.pixels - loop if bb == boundary break else { + loop if bb >= boundary break else { *@as(^[Color; copy_pixels], @bitcast(fb)) = *@as(^[Color; copy_pixels], @bitcast(bb)) bb += copy_pixels fb += copy_pixels @@ -137,6 +137,9 @@ height := fn(): int { } screenidx := fn(x: int, y: int): int { + /*if x < 0 || y < 0 || x >= ctx.width || y >= ctx.height { + return -1 + }*/ return x + ctx.width * y } @@ -178,6 +181,27 @@ put_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void { return } +put_trirect := fn(pos: Vec2(int), size: Vec2(int), color0: Color, color1: Color): void { + step := Vec2(int).(1, 1) + if size.x < 0 { + step.x = -1 + } + if size.y < 0 { + step.y = size.y / size.x + } + + start_y := pos.y + target := pos + size + + loop if pos.x == target.x break else { + put_vline(pos.x, pos.y, target.y, color0) + put_vline(pos.x, pos.y, start_y, color1) + pos += step + } + + return +} + put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { dx := p1.x - p0.x dy := p1.y - p0.y @@ -243,6 +267,38 @@ put_line := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { return } +put_vline := fn(x: int, y0: int, y1: int, color: Color): void { + if y1 < y0 { + tmp := y0 + y0 = y1 + y1 = tmp + } + y := y0 + + loop if y == y1 break else { + *(ctx.buf + @inline(screenidx, x, y)) = color + y += 1 + } + + return +} + +put_hline := fn(y: int, x0: int, x1: int, color: Color): void { + if x1 < x0 { + tmp := x0 + x0 = x1 + x1 = tmp + } + x := x0 + + loop if x == x1 break else { + *(ctx.buf + @inline(screenidx, x, y)) = color + x += 1 + } + + return +} + set_height := fn(new: int): void { return } diff --git a/sysdata/programs/render_example/src/examples/tactical_screen.hb b/sysdata/programs/render_example/src/examples/tactical_screen.hb new file mode 100644 index 0000000..4f227de --- /dev/null +++ b/sysdata/programs/render_example/src/examples/tactical_screen.hb @@ -0,0 +1,83 @@ +render := @use("../../../../libraries/render/src/lib.hb"); +.{math, random} := @use("../../../../libraries/stn/src/lib.hb") +Vec2 := math.Vec2 + +/* expected result: + a grid of green lines scrolling from the left top corner to the right bottom one + with a "target" randomly apperaing in one of them and a "seeker" "catching" it*/ + +example := fn(): void { + render.init() + + width := render.width() + height := render.height() + cell_size := 0 + range := Vec2(int).(0, 0) + if width > height { + cell_size = width / 40 + range = .(39, height / cell_size - 1) + } else { + cell_size = height / 40 + range = .(width / cell_size - 1, 39) + } + width -= 1 + height -= 1 + + scroll := 0 + target := Vec2(int).(random.range(int, 0, range.x), random.range(int, 0, range.y)) + + halfcell := cell_size / 2 + octcell := cell_size / 8 + sevenoctcell := cell_size - octcell + + seeker := Vec2(int).(random.range(int, 0, range.x), random.range(int, 0, range.y)) + + loop { + render.clear(render.black) + + target_pixel_coord := target * .(cell_size, cell_size) + .(scroll, scroll) + render.put_trirect(target_pixel_coord, .(cell_size, cell_size), render.red, render.light_red) + + render.put_hline(target_pixel_coord.y + halfcell, target_pixel_coord.x - octcell, target_pixel_coord.x - sevenoctcell, render.light_red) + render.put_hline(target_pixel_coord.y + halfcell, target_pixel_coord.x + cell_size + octcell, target_pixel_coord.x + cell_size + sevenoctcell, render.light_red) + render.put_vline(target_pixel_coord.x + halfcell, target_pixel_coord.y - octcell, target_pixel_coord.y - sevenoctcell, render.light_red) + render.put_vline(target_pixel_coord.x + halfcell, target_pixel_coord.y + cell_size + octcell, target_pixel_coord.y + cell_size + sevenoctcell, render.light_red) + + x := scroll + loop if x > width break else { + render.put_vline(x, 0, height, .(0, 127, 0, 127)) + x += cell_size + } + + y := scroll + loop if y > height break else { + render.put_hline(y, 0, width, .(0, 127, 0, 127)) + y += cell_size + } + + render.put_hline(seeker.y * cell_size + halfcell + scroll, 0, width, render.light_green) + render.put_vline(seeker.x * cell_size + halfcell + scroll, 0, height, render.light_green) + + render.sync() + + if seeker.x < target.x { + seeker.x += 1 + } else if seeker.x > target.x { + seeker.x -= 1 + } else if seeker.y < target.y { + seeker.y += 1 + } else if seeker.y > target.y { + seeker.y -= 1 + } else { + target = .(random.range(int, 0, range.x), random.range(int, 0, range.y)) + } + + scroll += 1 + if scroll > cell_size { + scroll = 0 + target += .(1, 1) + seeker += .(1, 1) + } + } + 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 35b2706..5d15c24 100644 --- a/sysdata/programs/render_example/src/main.hb +++ b/sysdata/programs/render_example/src/main.hb @@ -1,4 +1,4 @@ -.{example} := @use("./examples/amogus.hb") +.{example} := @use("./examples/tactical_screen.hb") main := fn(): void { @inline(example) diff --git a/sysdata/programs/tetris/src/main.hb b/sysdata/programs/tetris/src/main.hb index e61324b..65aebf3 100644 --- a/sysdata/programs/tetris/src/main.hb +++ b/sysdata/programs/tetris/src/main.hb @@ -1,14 +1,27 @@ -.{memory, log, string, buffer} := @use("../../../libraries/stn/src/lib.hb") +.{memory, log, string, buffer, math} := @use("../../../libraries/stn/src/lib.hb") +render := @use("../../../libraries/render/src/lib.hb") +Color := render.Color +Vec2 := math.Vec2 main := fn(): void { - storage := @as(u8, 0) + input := @as(u8, 0) output_buffer := memory.request_page(1) input_buffer := buffer.search("XKeyboard\0") + + render.init() + loop { - buffer.recv(input_buffer, &storage, 1) - if storage != 0 { - log.info(string.display_int(storage, output_buffer)) - storage = 0 + render.clear(render.black) + render.put_vline(100, 255, 128, Color.(255, 255, 255, 255)) + render.put_hline(64, 100 - 64, 164, Color.(255, 255, 255, 255)) + render.put_trirect(Vec2(int).(128, 128 + 256), Vec2(int).(256, -256), Color.(147, 147, 147, 255), Color.(107, 107, 107, 255)) + render.put_filled_rect(Vec2(int).(128 + 32, 128 + 32), Vec2(int).(256 - 64, 256 - 64), Color.(127, 127, 127, 127)) + render.sync() + + buffer.recv(input_buffer, &input, 1) + if input != 0 { + log.info(string.display_int(input, output_buffer)) + input = 0 } } return diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index e4bd86f..48aa105 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -3,7 +3,7 @@ default_entry = 1 timeout = 0 verbose = false -interface_resolution = "1024x768x24" +interface_resolution = "1600x900x24" # interface_resolution = "640x480x32" # Terminal related settings term_wallpaper = "boot:///background.bmp" @@ -16,7 +16,7 @@ protocol = "limine" kernel_path = "boot:///kernel_${ARCH}" kernel_cmdline = "" # resolution = "640x480x32" -resolution = "1024x768x24" +resolution = "1600x900x24" [boot.limine.ableos.modules] -- 2.44.1 From 39ebaa03ba233f63c7aea2d2858b018e8c42abd1 Mon Sep 17 00:00:00 2001 From: peony Date: Mon, 14 Oct 2024 14:35:41 +0200 Subject: [PATCH 02/23] Uuuugh --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bfd0b3e..c7b2722 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -350,12 +350,12 @@ checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#6d7e726066109e8b08f049bbc4684bba2a2eb88a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#dc2e0cc5b36f84f9d5bb82b6f48e6b29869746d5" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#6d7e726066109e8b08f049bbc4684bba2a2eb88a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#dc2e0cc5b36f84f9d5bb82b6f48e6b29869746d5" dependencies = [ "hashbrown 0.15.0", "hbbytecode", @@ -367,7 +367,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#6d7e726066109e8b08f049bbc4684bba2a2eb88a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#dc2e0cc5b36f84f9d5bb82b6f48e6b29869746d5" dependencies = [ "hbbytecode", ] -- 2.44.1 From 3708acc077b730c41cf9b7cf55ae6ed79a660dff Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 10 Nov 2024 15:09:41 +0100 Subject: [PATCH 03/23] Revert to mainline --- sysdata/libraries/render/src/lib.hb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sysdata/libraries/render/src/lib.hb b/sysdata/libraries/render/src/lib.hb index dd8a3f1..4e656a2 100644 --- a/sysdata/libraries/render/src/lib.hb +++ b/sysdata/libraries/render/src/lib.hb @@ -46,9 +46,9 @@ clear := mode.clear put_surface := mode.put_surface put_text := mode.put_text // thanks peony for these three! -put_trirect := mode.put_trirect -put_vline := mode.put_vline -put_hline := mode.put_hline +//put_trirect := mode.put_trirect +//put_vline := mode.put_vline +//put_hline := mode.put_hline // Display sync := mode.sync \ No newline at end of file -- 2.44.1 From 4c0adbe15d51052eed4e6b1a4b44df228db3f233 Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 10 Nov 2024 15:19:55 +0100 Subject: [PATCH 04/23] Circle rendring. --- sysdata/libraries/render/src/lib.hb | 3 + sysdata/libraries/render/src/software.hb | 84 ++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/sysdata/libraries/render/src/lib.hb b/sysdata/libraries/render/src/lib.hb index 4e656a2..00279a3 100644 --- a/sysdata/libraries/render/src/lib.hb +++ b/sysdata/libraries/render/src/lib.hb @@ -39,6 +39,9 @@ put_pixel := mode.put_pixel put_rect := mode.put_rect put_filled_rect := mode.put_filled_rect put_trirect := mode.put_trirect +put_circle := mode.put_circle +put_filled_circle := mode.put_filled_circle +put_textured_circle := mode.put_textured_circle put_line := mode.put_line put_vline := mode.put_vline put_hline := mode.put_hline diff --git a/sysdata/libraries/render/src/software.hb b/sysdata/libraries/render/src/software.hb index efc8d92..0c4780e 100644 --- a/sysdata/libraries/render/src/software.hb +++ b/sysdata/libraries/render/src/software.hb @@ -251,6 +251,90 @@ put_hline := fn(surface: Surface, y: uint, x0: uint, x1: uint, color: Color): vo return } + +put_circle := fn(surface: Surface, pos: Vec2(uint), radius: uint, color: Color): void { + x := 0 + y := radius + error := @as(int, 3) - @as(int, @intcast(2 * radius)); + *@inline(indexptr, surface, pos.x + radius, pos.y) = color; + *@inline(indexptr, surface, pos.x - radius, pos.y) = color; + *@inline(indexptr, surface, pos.x, pos.y + radius) = color; + *@inline(indexptr, surface, pos.x, pos.y - radius) = color + + loop if y < x break else { + x += 1 + + if error > 0 { + y -= 1 + error += 4 * (@as(int, @intcast(x)) - @as(int, @intcast(y))) + 10 + } else { + error += 4 * @intcast(x) + 6 + }; + *@inline(indexptr, surface, pos.x + x, pos.y + y) = color; + *@inline(indexptr, surface, pos.x + y, pos.y + x) = color; + *@inline(indexptr, surface, pos.x - x, pos.y + y) = color; + *@inline(indexptr, surface, pos.x - y, pos.y + x) = color; + *@inline(indexptr, surface, pos.x + x, pos.y - y) = color; + *@inline(indexptr, surface, pos.x + y, pos.y - x) = color; + *@inline(indexptr, surface, pos.x - x, pos.y - y) = color; + *@inline(indexptr, surface, pos.x - y, pos.y - x) = color + } + + return +} + +put_filled_circle := fn(surface: Surface, pos: Vec2(uint), radius: uint, color: Color): void { + x := 0 + y := radius + error := @as(int, 3) - @as(int, @intcast(2 * radius)) + @inline(put_hline, surface, pos.y - x, pos.x - radius, pos.x + radius, color); + *@inline(indexptr, surface, pos.x, pos.y + radius) = color; + *@inline(indexptr, surface, pos.x, pos.y - radius) = color + + loop if y < x break else { + x += 1 + + if error > 0 { + @inline(put_hline, surface, pos.y + y, pos.x - x, pos.x + x, color) + @inline(put_hline, surface, pos.y - y, pos.x - x, pos.x + x, color) + y -= 1 + error += 4 * (@as(int, @intcast(x)) - @as(int, @intcast(y))) + 10 + } else { + error += 4 * @intcast(x) + 6 + } + @inline(put_hline, surface, pos.y + x, pos.x - y, pos.x + y, color) + @inline(put_hline, surface, pos.y - x, pos.x - y, pos.x + y, color) + } + + return +} + +put_textured_circle := fn(surface: Surface, source: Surface, source_pos: Vec2(uint), pos: Vec2(uint), radius: uint): void { + x := 0 + y := radius + error := @as(int, 3) - @as(int, @intcast(2 * radius)) + @inline(memory.copy, Color, @inline(indexptr, source, source_pos.x - y, source_pos.y), @inline(indexptr, surface, pos.x - y, pos.y), 2 * y); + *@inline(indexptr, surface, pos.x, pos.y + y) = *@inline(indexptr, source, source_pos.x, source_pos.y + y); + *@inline(indexptr, surface, pos.x, pos.y - y) = *@inline(indexptr, source, source_pos.x, source_pos.y - y) + + loop if y < x break else { + x += 1 + + if error > 0 { + @inline(memory.copy, Color, @inline(indexptr, source, source_pos.x - x, source_pos.y + y), @inline(indexptr, surface, pos.x - x, pos.y + y), 2 * x) + @inline(memory.copy, Color, @inline(indexptr, source, source_pos.x - x, source_pos.y - y), @inline(indexptr, surface, pos.x - x, pos.y - y), 2 * x) + y -= 1 + error += 4 * (@as(int, @intcast(x)) - @as(int, @intcast(y))) + 10 + } else { + error += 4 * @intcast(x) + 6 + } + @inline(memory.copy, Color, @inline(indexptr, source, source_pos.x - y, source_pos.y + x), @inline(indexptr, surface, pos.x - y, pos.y + x), 2 * y) + @inline(memory.copy, Color, @inline(indexptr, source, source_pos.x - y, source_pos.y - x), @inline(indexptr, surface, pos.x - y, pos.y - x), 2 * y) + } + + return +} + utf8_len_table := [u8].(0, 0, 2, 3) put_text := fn(surface: Surface, font: Font, pos: Vec2(uint), color: Color, str: ^u8): void { -- 2.44.1 From 8f5833955f535dc81df956380795c67428ebf00c Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 10 Nov 2024 15:42:41 +0100 Subject: [PATCH 05/23] Circle test. (Precision issues) --- .../render_example/src/examples/orbit.hb | 36 +++++++++++++++++++ sysdata/programs/render_example/src/main.hb | 2 +- sysdata/programs/tetris/src/main.hb | 28 --------------- sysdata/system_config.toml | 12 +++---- 4 files changed, 43 insertions(+), 35 deletions(-) create mode 100644 sysdata/programs/render_example/src/examples/orbit.hb delete mode 100644 sysdata/programs/tetris/src/main.hb diff --git a/sysdata/programs/render_example/src/examples/orbit.hb b/sysdata/programs/render_example/src/examples/orbit.hb new file mode 100644 index 0000000..84b47e3 --- /dev/null +++ b/sysdata/programs/render_example/src/examples/orbit.hb @@ -0,0 +1,36 @@ +.{Vec2, sin, cos, PI} := @use("../../../../libraries/stn/src/lib.hb").math +render := @use("../../../../libraries/render/src/lib.hb") + +able_bmp := @embed("../../../../assets/able.bmp") +mini_bmp := @embed("../../../../assets/mini.bmp") + +/* expected result: + two textured circles rotating + around one yellow filled circle + with a blue line showing their + 'orbit' */ + +example := fn(): void { + able := render.image.from(@bitcast(&able_bmp)) + mini := render.image.from(@bitcast(&mini_bmp)) + if able == null | mini == null { + return + } + + angle := 0.0 + + screen := render.init(true) + + loop { + render.clear(screen, render.black) + render.put_filled_circle(screen, .(screen.width / 2, screen.height / 2), 128, render.light_yellow) + render.put_circle(screen, .(screen.width / 2, screen.height / 2), 256, render.light_blue) + // Precision issues? + render.put_textured_circle(screen, able, .(able.width / 2, able.height / 2), .(screen.width / 2 + @intcast(@fti(sin(angle) * 256)), screen.height / 2 + @intcast(@fti(cos(angle) * 256))), able.width / 2 - 1) + render.put_textured_circle(screen, mini, .(mini.width / 2, mini.height / 2), .(screen.width / 2 + @intcast(@fti(sin(angle + PI) * 256)), screen.height / 2 + @intcast(@fti(cos(angle + PI) * 256))), mini.width / 2 - 1) + render.sync(screen) + + angle += 0.01 + } + 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 77cb04c..ab66cfa 100644 --- a/sysdata/programs/render_example/src/main.hb +++ b/sysdata/programs/render_example/src/main.hb @@ -1 +1 @@ -.{example: main} := @use("./examples/text.hb") \ No newline at end of file +.{example: main} := @use("./examples/orbit.hb") \ No newline at end of file diff --git a/sysdata/programs/tetris/src/main.hb b/sysdata/programs/tetris/src/main.hb deleted file mode 100644 index f4eaa3b..0000000 --- a/sysdata/programs/tetris/src/main.hb +++ /dev/null @@ -1,28 +0,0 @@ -.{memory, log, string, buffer, math} := @use("../../../libraries/stn/src/lib.hb") -render := @use("../../../libraries/render/src/lib.hb") -Color := render.Color -Vec2 := math.Vec2 - -main := fn(): void { - input := @as(u8, 0) - output_buffer := memory.request_page(1) - input_buffer := buffer.search("XKeyboard\0") - - render.init() - - loop { - render.clear(render.black) - render.put_vline(100, 255, 128, Color.(255, 255, 255, 255)) - render.put_hline(64, 100 - 64, 164, Color.(255, 255, 255, 255)) - render.put_trirect(Vec2(int).(128, 128 + 256), Vec2(int).(256, -256), Color.(147, 147, 147, 255), Color.(107, 107, 107, 255)) - render.put_filled_rect(Vec2(int).(128 + 32, 128 + 32), Vec2(int).(256 - 64, 256 - 64), Color.(127, 127, 127, 127)) - render.sync() - - buffer.recv(input_buffer, &input, 1) - if input != 0 { - log.info(string.display_int(input, output_buffer)) - input = 0 - } - } - return -} diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 1992a80..93bd739 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -22,14 +22,14 @@ resolution = "1024x768x24" [boot.limine.ableos.modules] -# [boot.limine.ableos.modules.render_example] -# path = "boot:///render_example.hbf" +[boot.limine.ableos.modules.render_example] +path = "boot:///render_example.hbf" -[boot.limine.ableos.modules.horizon] -path = "boot:///horizon.hbf" +# [boot.limine.ableos.modules.horizon] +# path = "boot:///horizon.hbf" -[boot.limine.ableos.modules.ps2_mouse_driver] -path = "boot:///ps2_mouse_driver.hbf" +# [boot.limine.ableos.modules.ps2_mouse_driver] +# path = "boot:///ps2_mouse_driver.hbf" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" -- 2.44.1 From 89d08d8a624325721fc55e9603c4ca0c6a0294ce Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 10 Nov 2024 15:44:17 +0100 Subject: [PATCH 06/23] Alighning with master. --- sysdata/libraries/render/src/lib.hb | 3 --- 1 file changed, 3 deletions(-) diff --git a/sysdata/libraries/render/src/lib.hb b/sysdata/libraries/render/src/lib.hb index 00279a3..ff77208 100644 --- a/sysdata/libraries/render/src/lib.hb +++ b/sysdata/libraries/render/src/lib.hb @@ -49,9 +49,6 @@ clear := mode.clear put_surface := mode.put_surface put_text := mode.put_text // thanks peony for these three! -//put_trirect := mode.put_trirect -//put_vline := mode.put_vline -//put_hline := mode.put_hline // Display sync := mode.sync \ No newline at end of file -- 2.44.1 From aac1164d55a94994ffa125c45343dbd2b8e02868 Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 10 Nov 2024 15:45:01 +0100 Subject: [PATCH 07/23] More git stuff --- sysdata/libraries/render/src/lib.hb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sysdata/libraries/render/src/lib.hb b/sysdata/libraries/render/src/lib.hb index ff77208..00279a3 100644 --- a/sysdata/libraries/render/src/lib.hb +++ b/sysdata/libraries/render/src/lib.hb @@ -49,6 +49,9 @@ clear := mode.clear put_surface := mode.put_surface put_text := mode.put_text // thanks peony for these three! +//put_trirect := mode.put_trirect +//put_vline := mode.put_vline +//put_hline := mode.put_hline // Display sync := mode.sync \ No newline at end of file -- 2.44.1 From be6a095c149ac1488a9001884099cb92af2dcc42 Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 10 Nov 2024 19:14:20 +0100 Subject: [PATCH 08/23] Cargo stuff --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 56dc2fc..dfc9b2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,12 +228,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8b98c2ed1becb92046bb7b687ca00813da441248" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#654005eea293b1a2e7d81a08d5d4cb542d4cc8a2" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8b98c2ed1becb92046bb7b687ca00813da441248" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#654005eea293b1a2e7d81a08d5d4cb542d4cc8a2" dependencies = [ "hashbrown 0.15.1", "hbbytecode", @@ -245,7 +245,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8b98c2ed1becb92046bb7b687ca00813da441248" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#654005eea293b1a2e7d81a08d5d4cb542d4cc8a2" dependencies = [ "hbbytecode", ] -- 2.44.1 From cc4a32afaa5541f392b6874bc4465170fb5231d9 Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 10 Nov 2024 21:24:19 +0100 Subject: [PATCH 09/23] PS/2 work --- Cargo.lock | 6 +- sysdata/programs/ps2_driver/README.md | 12 +++ sysdata/programs/ps2_driver/meta.toml | 11 +++ sysdata/programs/ps2_driver/src/main.hb | 108 ++++++++++++++++++++++++ sysdata/system_config.toml | 7 +- 5 files changed, 139 insertions(+), 5 deletions(-) create mode 100644 sysdata/programs/ps2_driver/README.md create mode 100644 sysdata/programs/ps2_driver/meta.toml create mode 100644 sysdata/programs/ps2_driver/src/main.hb diff --git a/Cargo.lock b/Cargo.lock index dfc9b2e..1e01574 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,12 +228,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#654005eea293b1a2e7d81a08d5d4cb542d4cc8a2" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c61efc393361089f5217db9f4a9011ed0248b8db" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#654005eea293b1a2e7d81a08d5d4cb542d4cc8a2" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c61efc393361089f5217db9f4a9011ed0248b8db" dependencies = [ "hashbrown 0.15.1", "hbbytecode", @@ -245,7 +245,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#654005eea293b1a2e7d81a08d5d4cb542d4cc8a2" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c61efc393361089f5217db9f4a9011ed0248b8db" dependencies = [ "hbbytecode", ] diff --git a/sysdata/programs/ps2_driver/README.md b/sysdata/programs/ps2_driver/README.md new file mode 100644 index 0000000..c0a3d83 --- /dev/null +++ b/sysdata/programs/ps2_driver/README.md @@ -0,0 +1,12 @@ +# Unified PS/2 Driver + +Te entire thing is heavily documented with comments because I'm not sure how else to make this understandable. + +## !!Assumptions!! +Anyone who works on this should work to keep this list as small as possible/remove as many of these as possible. +- Bit 5 of the response form 0x64 indicates which port the data is coming from. (Not true on all systems) +- A parity or timeout error never occurs. +- PS/2 controller exists. +- Both PS/2 ports being broken doesn't need handling. +- One PS/2 port being broken doesn't need special attention. +- PS/2 controller doesn't need to perform a self-check. diff --git a/sysdata/programs/ps2_driver/meta.toml b/sysdata/programs/ps2_driver/meta.toml new file mode 100644 index 0000000..005cb92 --- /dev/null +++ b/sysdata/programs/ps2_driver/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "ps2_driver" +authors = ["Peony"] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb new file mode 100644 index 0000000..351187b --- /dev/null +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -0,0 +1,108 @@ +.{memory, log} := @use("../../../libraries/stn/src/lib.hb") + +DeviceID := struct {value: u16} + +$Mouse3Button := DeviceID.(0x0) +$MouseScrollwheel := DeviceID.(0x3) +$Mouse5Button := DeviceID.(0x4) +$Spacesaver := DeviceID.(0xAB84) +$Keyboard122Key := DeviceID.(0xAB86) +$KeyboardJapaneseG := DeviceID.(0xAB90) +$KeyboardJapanesep := DeviceID.(0xAB91) +$KeyboardJapaneseA := DeviceID.(0xAB92) +$KeyboardNCDSun := DeviceID.(0xACA1) +$NoDevice := DeviceID.(0xFFFF) + +Port := struct {exists: bool, device: DeviceID, command_queued: bool, command_queue: u8} + +$check_bit := fn(value: u8, bit: u8, state: u8): bool { + return value >> bit & 1 == state +} + +ports := [Port].(.(true, NoDevice, false, 0xFF), .(true, NoDevice, false, 0xFF)) + +$initialize_controller := fn(): void { + memory.outb(0x64, 0xAD) + memory.outb(0x64, 0xA7) + //Disables ports to make sure that they won't interfere with the setup process. + + loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) + //Flushes any output because apperantly that might interfere with stuff. + + memory.outb(0x64, 0xA8) + //Enables port 2. + memory.outb(0x64, 0x20) + //Gimme configuration byte. + loop if (memory.inb(0x64) & 1) == 1 break + ports[1].exists = check_bit(memory.inb(0x60), 5, 0) + if ports[1].exists { + memory.outb(0x64, 0xA7) + } + + loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) + //Flushes any output because apperantly that might interfere with stuff. + + memory.outb(0x64, 0xAB) + loop if (memory.inb(0x64) & 1) == 1 break + ports[0].exists = memory.inb(0x60) == 0x0 + //Test port 1. + + if ports[1].exists { + memory.outb(0x64, 0xA9) + loop if (memory.inb(0x64) & 1) == 1 break + ports[1].exists = memory.inb(0x60) == 0x0 + } + //Test port 2. + + if (ports[0].exists | ports[1].exists) == false { + log.error("No ports detected! No input will be processed! Cannot handle this!\0") + } + + if ports[0].exists { + memory.outb(0x64, 0xAE) + //Enables port 1. + ports[0].command_queued = true + } + if ports[1].exists { + memory.outb(0x64, 0xA8) + //Enables port 2. + ports[1].command_queued = true + } +} + +handle_input := fn(port: uint, input: u8): void { +} + +main := fn(): void { + loop { + port_info := memory.inb(0x64) + //Enables port 1. + if (port_info & 0x40) > 0 { + log.error("Timeout error! Cannot handle these!\0") + } + if (port_info & 0x80) > 0 { + log.error("Parity error! Cannot handle these!\0") + } + + if (port_info & 1) == 0 { + if ports[0].exists & ports[0].command_queued { + memory.outb(0x60, ports[0].command_queue) + ports[0].command_queued = false + } + if ports[1].exists & ports[1].command_queued { + memory.outb(0x64, 0xD4) + memory.outb(0x60, ports[1].command_queue) + ports[1].command_queued = false + } + } + + port := 0 + if ports[1].exists { + port = port_info >> 5 & 1 + } + + if ports[port].exists { + @inline(handle_input, port, memory.inb(0x60)) + } + } +} \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 93bd739..688c762 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -22,8 +22,8 @@ resolution = "1024x768x24" [boot.limine.ableos.modules] -[boot.limine.ableos.modules.render_example] -path = "boot:///render_example.hbf" +# [boot.limine.ableos.modules.render_example] +# path = "boot:///render_example.hbf" # [boot.limine.ableos.modules.horizon] # path = "boot:///horizon.hbf" @@ -33,3 +33,6 @@ path = "boot:///render_example.hbf" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" + +[boot.limine.ableos.modules.ps2_driver] +path = "boot:///ps2_driver.hbf" -- 2.44.1 From a1bfd8e85fff4f16fd77d15739fd792bbf2e856c Mon Sep 17 00:00:00 2001 From: peony Date: Tue, 12 Nov 2024 22:36:43 +0100 Subject: [PATCH 10/23] Driver not work --- Cargo.lock | 22 +++++++-------- sysdata/programs/ps2_driver/src/main.hb | 37 ++++++++++++++++++------- sysdata/system_config.toml | 11 +++++--- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4664788..54ba9a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.19" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611cc2ae7d2e242c457e4be7f97036b8ad9ca152b499f53faf99b1ed8fc2553f" +checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9" [[package]] name = "anyhow" @@ -82,9 +82,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.1.37" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40545c26d092346d8a8dab71ee48e7685a7a9cba76e634790c215b41a4a7b4cf" +checksum = "1aeb932158bd710538c73702db6945cb68a8fb08c519e6e12706b94263b36db8" dependencies = [ "shlex", ] @@ -228,12 +228,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#b6274f3455d0545a64f2cc866b39d409e0a73427" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0d87bf8f0977fd929af28f6cd8007b603bc974bc" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#b6274f3455d0545a64f2cc866b39d409e0a73427" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0d87bf8f0977fd929af28f6cd8007b603bc974bc" dependencies = [ "hashbrown 0.15.1", "hbbytecode", @@ -245,7 +245,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#b6274f3455d0545a64f2cc866b39d409e0a73427" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0d87bf8f0977fd929af28f6cd8007b603bc974bc" dependencies = [ "hbbytecode", ] @@ -675,18 +675,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index 351187b..dc4bbe0 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -5,23 +5,27 @@ DeviceID := struct {value: u16} $Mouse3Button := DeviceID.(0x0) $MouseScrollwheel := DeviceID.(0x3) $Mouse5Button := DeviceID.(0x4) -$Spacesaver := DeviceID.(0xAB84) -$Keyboard122Key := DeviceID.(0xAB86) -$KeyboardJapaneseG := DeviceID.(0xAB90) -$KeyboardJapanesep := DeviceID.(0xAB91) -$KeyboardJapaneseA := DeviceID.(0xAB92) -$KeyboardNCDSun := DeviceID.(0xACA1) +$Spacesaver := DeviceID.(0x84AB) +$Keyboard122Key := DeviceID.(0x86AB) +$KeyboardJapaneseG := DeviceID.(0x90AB) +$KeyboardJapanesep := DeviceID.(0x91AB) +$KeyboardJapaneseA := DeviceID.(0x92AB) +$KeyboardNCDSun := DeviceID.(0xA1AC) $NoDevice := DeviceID.(0xFFFF) -Port := struct {exists: bool, device: DeviceID, command_queued: bool, command_queue: u8} +State := struct {value: u8} +$Recive := State.(0) +$Reboot := State.(1) + +Port := struct {exists: bool, device: DeviceID, command_queued: bool, command_queue: u8, state: State, expecting: bool, expecting_data: u8} $check_bit := fn(value: u8, bit: u8, state: u8): bool { - return value >> bit & 1 == state + return (value >> bit & 1) == state } -ports := [Port].(.(true, NoDevice, false, 0xFF), .(true, NoDevice, false, 0xFF)) +ports := [Port].(.(true, NoDevice, false, 0xFF, Reboot, false, 0x0), .(true, NoDevice, false, 0xFF, Reboot, false, 0x0)) -$initialize_controller := fn(): void { +initialize_controller := fn(): void { memory.outb(0x64, 0xAD) memory.outb(0x64, 0xA7) //Disables ports to make sure that they won't interfere with the setup process. @@ -71,9 +75,22 @@ $initialize_controller := fn(): void { } handle_input := fn(port: uint, input: u8): void { + if ports[port].state.value == Recive.value { + } else if ports[port].state.value == Reboot.value { + if input == 0xAA { + log.info("Device rebooted!\0") + ports[port].state = Recive + } else if (ports[port].device.value & 15) == 0 { + ports[port].device.value |= input + } else { + ports[port].device.value |= input << 4 + } + } } main := fn(): void { + @inline(initialize_controller) + loop { port_info := memory.inb(0x64) //Enables port 1. diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index da9cbd0..89830c9 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -34,8 +34,11 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" -[boot.limine.ableos.modules.sunset_client] -path = "boot:///sunset_client.hbf" +[boot.limine.ableos.modules.ps2_driver] +path = "boot:///ps2_driver.hbf" -[boot.limine.ableos.modules.sunset_server] -path = "boot:///sunset_server.hbf" +# [boot.limine.ableos.modules.sunset_client] +# path = "boot:///sunset_client.hbf" + +# [boot.limine.ableos.modules.sunset_server] +# path = "boot:///sunset_server.hbf" -- 2.44.1 From 08099b0877da5fbcfb13138caac07634f32d3488 Mon Sep 17 00:00:00 2001 From: peony Date: Fri, 15 Nov 2024 20:47:11 +0100 Subject: [PATCH 11/23] Barely any PS/2 driver work --- Cargo.lock | 10 +++++----- sysdata/programs/ps2_driver/src/main.hb | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 54ba9a5..2a1a426 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,12 +228,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0d87bf8f0977fd929af28f6cd8007b603bc974bc" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#f524013c34ff5868eadc0afdf1168239f31c7ee0" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0d87bf8f0977fd929af28f6cd8007b603bc974bc" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#f524013c34ff5868eadc0afdf1168239f31c7ee0" dependencies = [ "hashbrown 0.15.1", "hbbytecode", @@ -245,7 +245,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0d87bf8f0977fd929af28f6cd8007b603bc974bc" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#f524013c34ff5868eadc0afdf1168239f31c7ee0" dependencies = [ "hbbytecode", ] @@ -824,9 +824,9 @@ dependencies = [ [[package]] name = "uart_16550" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4922792855b1bce30997fbaa5418597902c278a92d20dfe348e6f062c3bd861d" +checksum = "e492212ac378a5e00da953718dafb1340d9fbaf4f27d6f3c5cab03d931d1c049" dependencies = [ "bitflags 2.6.0", "rustversion", diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index dc4bbe0..a6dccf6 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -1,4 +1,5 @@ -.{memory, log} := @use("../../../libraries/stn/src/lib.hb") +.{memory, log, string} := @use("../../../libraries/stn/src/lib.hb") +format_page := memory.dangling(u8) DeviceID := struct {value: u16} @@ -63,11 +64,13 @@ initialize_controller := fn(): void { } if ports[0].exists { + log.info("Port 1 exists.\0") memory.outb(0x64, 0xAE) //Enables port 1. ports[0].command_queued = true } if ports[1].exists { + log.info("Port 2 exists.\0") memory.outb(0x64, 0xA8) //Enables port 2. ports[1].command_queued = true @@ -75,20 +78,17 @@ initialize_controller := fn(): void { } handle_input := fn(port: uint, input: u8): void { - if ports[port].state.value == Recive.value { - } else if ports[port].state.value == Reboot.value { - if input == 0xAA { - log.info("Device rebooted!\0") - ports[port].state = Recive - } else if (ports[port].device.value & 15) == 0 { - ports[port].device.value |= input - } else { - ports[port].device.value |= input << 4 - } + if input == 0xAA { + log.info("Device rebooted!\0") + log.info(string.display_int(@intcast(port + 1), format_page, 16)) + ports[port].state = Recive + } else if ports[port].state.value == Recive.value { } } main := fn(): void { + format_page = memory.alloc(u8, 1024) + @inline(initialize_controller) loop { -- 2.44.1 From efcd6c0631df6666a69e932d098545000b082d4d Mon Sep 17 00:00:00 2001 From: peony Date: Fri, 15 Nov 2024 22:55:44 +0100 Subject: [PATCH 12/23] Uuugh, jesus this sucks --- sysdata/programs/ps2_driver/src/main.hb | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index a6dccf6..21946cf 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -17,14 +17,16 @@ $NoDevice := DeviceID.(0xFFFF) State := struct {value: u8} $Recive := State.(0) $Reboot := State.(1) +$GetID := State.(2) +$TurnOnStreaming := State.(3) -Port := struct {exists: bool, device: DeviceID, command_queued: bool, command_queue: u8, state: State, expecting: bool, expecting_data: u8} +Port := struct {exists: bool, device: DeviceID, commands_queued: u8, command_queue: [u8; 8], awaiting_ack: bool, state: State, expecting: bool, expecting_data: u8} $check_bit := fn(value: u8, bit: u8, state: u8): bool { return (value >> bit & 1) == state } -ports := [Port].(.(true, NoDevice, false, 0xFF, Reboot, false, 0x0), .(true, NoDevice, false, 0xFF, Reboot, false, 0x0)) +ports := [Port].(.(true, NoDevice, 1, .(0xFF, 0, 0, 0, 0, 0, 0, 0), false, Reboot, false, 0x0), .(true, NoDevice, 1, .(0xFF, 0, 0, 0, 0, 0, 0, 0), false, Reboot, false, 0x0)) initialize_controller := fn(): void { memory.outb(0x64, 0xAD) @@ -67,13 +69,13 @@ initialize_controller := fn(): void { log.info("Port 1 exists.\0") memory.outb(0x64, 0xAE) //Enables port 1. - ports[0].command_queued = true + ports[0].commands_queued = 1 } if ports[1].exists { log.info("Port 2 exists.\0") memory.outb(0x64, 0xA8) //Enables port 2. - ports[1].command_queued = true + ports[1].commands_queued = 1 } } @@ -102,14 +104,14 @@ main := fn(): void { } if (port_info & 1) == 0 { - if ports[0].exists & ports[0].command_queued { + if ports[0].exists & ports[0].commands_queued > 0 { memory.outb(0x60, ports[0].command_queue) - ports[0].command_queued = false + ports[0].commands_queued -= 1 } - if ports[1].exists & ports[1].command_queued { + if ports[1].exists & ports[1].commands_queued > 0 { memory.outb(0x64, 0xD4) memory.outb(0x60, ports[1].command_queue) - ports[1].command_queued = false + ports[1].commands_queued -= 1 } } @@ -119,7 +121,12 @@ main := fn(): void { } if ports[port].exists { - @inline(handle_input, port, memory.inb(0x60)) + input := memory.inb(0x60) + if ports[port].awaiting_ack & input == 0xFA { + ports[port].awaiting_ack = false + } else { + @inline(handle_input, port, input) + } } } } \ No newline at end of file -- 2.44.1 From f5c6d7d822a49588b59fbced23a5ca9f8e9b81ea Mon Sep 17 00:00:00 2001 From: peony Date: Sat, 16 Nov 2024 21:51:55 +0100 Subject: [PATCH 13/23] PS/2 driver refactoring and poassibly completion process --- Cargo.lock | 55 ++----- sysdata/programs/ps2_driver/src/bits.hb | 26 ++++ sysdata/programs/ps2_driver/src/controller.hb | 53 +++++++ sysdata/programs/ps2_driver/src/main.hb | 126 --------------- .../programs/ps2_driver/src/main_legacy.hb | 144 ++++++++++++++++++ sysdata/programs/ps2_driver/src/port.hb | 10 ++ 6 files changed, 243 insertions(+), 171 deletions(-) create mode 100644 sysdata/programs/ps2_driver/src/bits.hb create mode 100644 sysdata/programs/ps2_driver/src/controller.hb create mode 100644 sysdata/programs/ps2_driver/src/main_legacy.hb create mode 100644 sysdata/programs/ps2_driver/src/port.hb diff --git a/Cargo.lock b/Cargo.lock index 17a86d6..a0152a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,15 +65,6 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -dependencies = [ - "allocator-api2", -] - [[package]] name = "byteorder" version = "1.5.0" @@ -208,12 +199,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hashbrown" version = "0.15.1" @@ -228,24 +213,23 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#7058efe75c7ad245db80986e77a97d426b9be8a4" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a64383e72b0920ef1c03773aac197404c78b330f" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#7058efe75c7ad245db80986e77a97d426b9be8a4" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a64383e72b0920ef1c03773aac197404c78b330f" dependencies = [ - "hashbrown 0.15.1", + "hashbrown", "hbbytecode", "hbvm", "log", - "regalloc2", ] [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#7058efe75c7ad245db80986e77a97d426b9be8a4" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a64383e72b0920ef1c03773aac197404c78b330f" dependencies = [ "hbbytecode", ] @@ -396,7 +380,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.15.1", + "hashbrown", ] [[package]] @@ -406,7 +390,7 @@ dependencies = [ "aarch64-cpu", "crossbeam-queue", "derive_more", - "hashbrown 0.15.1", + "hashbrown", "hbvm", "limine", "log", @@ -428,9 +412,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.162" +version = "0.2.164" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" +checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" [[package]] name = "limine" @@ -553,19 +537,6 @@ dependencies = [ "bitflags 2.6.0", ] -[[package]] -name = "regalloc2" -version = "0.10.2" -source = "git+https://github.com/jakubDoka/regalloc2?branch=reuse-allocations#21c43e3ee182824e92e2b25f1d3c03ed47f9c02b" -dependencies = [ - "allocator-api2", - "bumpalo", - "hashbrown 0.14.5", - "log", - "rustc-hash", - "smallvec", -] - [[package]] name = "regex-syntax" version = "0.8.5" @@ -602,12 +573,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "rustc-hash" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" - [[package]] name = "rustc_version" version = "0.4.1" @@ -619,9 +584,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.16" +version = "0.23.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" +checksum = "7f1a745511c54ba6d4465e8d5dfbd81b45791756de28d4981af70d6dca128f1e" dependencies = [ "log", "once_cell", diff --git a/sysdata/programs/ps2_driver/src/bits.hb b/sysdata/programs/ps2_driver/src/bits.hb new file mode 100644 index 0000000..3a8afeb --- /dev/null +++ b/sysdata/programs/ps2_driver/src/bits.hb @@ -0,0 +1,26 @@ +//Do not question. + +$bit0 := fn(value: u8): bool { + return (value & 0x1) > 0 +} +$bit1 := fn(value: u8): bool { + return (value & 0x2) > 0 +} +$bit2 := fn(value: u8): bool { + return (value & 0x4) > 0 +} +$bit3 := fn(value: u8): bool { + return (value & 0x8) > 0 +} +$bit4 := fn(value: u8): bool { + return (value & 0x10) > 0 +} +$bit5 := fn(value: u8): bool { + return (value & 0x20) > 0 +} +$bit6 := fn(value: u8): bool { + return (value & 0x40) > 0 +} +$bit7 := fn(value: u8): bool { + return (value & 0x80) > 0 +} \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/controller.hb b/sysdata/programs/ps2_driver/src/controller.hb new file mode 100644 index 0000000..00a83f6 --- /dev/null +++ b/sysdata/programs/ps2_driver/src/controller.hb @@ -0,0 +1,53 @@ +.{memory, log} := @use("../../../libraries/stn/src/lib.hb"); +.{bit5} := @use("bits.hb") + +init := fn(): void { + memory.outb(0x64, 0xAD) + memory.outb(0x64, 0xA7) + //Disables ports to make sure that they won't interfere with the setup process. + + loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) + //Flushes any output because apperantly that might interfere with stuff. + + memory.outb(0x64, 0xA8) + //Enables port 2. + memory.outb(0x64, 0x20) + //Gimme configuration byte. + loop if (memory.inb(0x64) & 1) == 1 break + ports[1].exists = bit5(memory.inb(0x60)) == false + if ports[1].exists { + memory.outb(0x64, 0xA7) + } + + loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) + //Flushes any output because apperantly that might interfere with stuff. + + memory.outb(0x64, 0xAB) + loop if (memory.inb(0x64) & 1) == 1 break + ports[0].exists = memory.inb(0x60) == 0x0 + //Test port 1. + + if ports[1].exists { + memory.outb(0x64, 0xA9) + loop if (memory.inb(0x64) & 1) == 1 break + ports[1].exists = memory.inb(0x60) == 0x0 + } + //Test port 2. + + if (ports[0].exists | ports[1].exists) == false { + log.error("No ports detected! No input will be processed! Cannot handle this!\0") + } + + if ports[0].exists { + log.info("Port 1 exists.\0") + memory.outb(0x64, 0xAE) + //Enables port 1. + ports[0].commands_queued = 1 + } + if ports[1].exists { + log.info("Port 2 exists.\0") + memory.outb(0x64, 0xA8) + //Enables port 2. + ports[1].commands_queued = 1 + } +} \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index 21946cf..a62e9e1 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -1,132 +1,6 @@ .{memory, log, string} := @use("../../../libraries/stn/src/lib.hb") format_page := memory.dangling(u8) -DeviceID := struct {value: u16} - -$Mouse3Button := DeviceID.(0x0) -$MouseScrollwheel := DeviceID.(0x3) -$Mouse5Button := DeviceID.(0x4) -$Spacesaver := DeviceID.(0x84AB) -$Keyboard122Key := DeviceID.(0x86AB) -$KeyboardJapaneseG := DeviceID.(0x90AB) -$KeyboardJapanesep := DeviceID.(0x91AB) -$KeyboardJapaneseA := DeviceID.(0x92AB) -$KeyboardNCDSun := DeviceID.(0xA1AC) -$NoDevice := DeviceID.(0xFFFF) - -State := struct {value: u8} -$Recive := State.(0) -$Reboot := State.(1) -$GetID := State.(2) -$TurnOnStreaming := State.(3) - -Port := struct {exists: bool, device: DeviceID, commands_queued: u8, command_queue: [u8; 8], awaiting_ack: bool, state: State, expecting: bool, expecting_data: u8} - -$check_bit := fn(value: u8, bit: u8, state: u8): bool { - return (value >> bit & 1) == state -} - -ports := [Port].(.(true, NoDevice, 1, .(0xFF, 0, 0, 0, 0, 0, 0, 0), false, Reboot, false, 0x0), .(true, NoDevice, 1, .(0xFF, 0, 0, 0, 0, 0, 0, 0), false, Reboot, false, 0x0)) - -initialize_controller := fn(): void { - memory.outb(0x64, 0xAD) - memory.outb(0x64, 0xA7) - //Disables ports to make sure that they won't interfere with the setup process. - - loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) - //Flushes any output because apperantly that might interfere with stuff. - - memory.outb(0x64, 0xA8) - //Enables port 2. - memory.outb(0x64, 0x20) - //Gimme configuration byte. - loop if (memory.inb(0x64) & 1) == 1 break - ports[1].exists = check_bit(memory.inb(0x60), 5, 0) - if ports[1].exists { - memory.outb(0x64, 0xA7) - } - - loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) - //Flushes any output because apperantly that might interfere with stuff. - - memory.outb(0x64, 0xAB) - loop if (memory.inb(0x64) & 1) == 1 break - ports[0].exists = memory.inb(0x60) == 0x0 - //Test port 1. - - if ports[1].exists { - memory.outb(0x64, 0xA9) - loop if (memory.inb(0x64) & 1) == 1 break - ports[1].exists = memory.inb(0x60) == 0x0 - } - //Test port 2. - - if (ports[0].exists | ports[1].exists) == false { - log.error("No ports detected! No input will be processed! Cannot handle this!\0") - } - - if ports[0].exists { - log.info("Port 1 exists.\0") - memory.outb(0x64, 0xAE) - //Enables port 1. - ports[0].commands_queued = 1 - } - if ports[1].exists { - log.info("Port 2 exists.\0") - memory.outb(0x64, 0xA8) - //Enables port 2. - ports[1].commands_queued = 1 - } -} - -handle_input := fn(port: uint, input: u8): void { - if input == 0xAA { - log.info("Device rebooted!\0") - log.info(string.display_int(@intcast(port + 1), format_page, 16)) - ports[port].state = Recive - } else if ports[port].state.value == Recive.value { - } -} - main := fn(): void { format_page = memory.alloc(u8, 1024) - - @inline(initialize_controller) - - loop { - port_info := memory.inb(0x64) - //Enables port 1. - if (port_info & 0x40) > 0 { - log.error("Timeout error! Cannot handle these!\0") - } - if (port_info & 0x80) > 0 { - log.error("Parity error! Cannot handle these!\0") - } - - if (port_info & 1) == 0 { - if ports[0].exists & ports[0].commands_queued > 0 { - memory.outb(0x60, ports[0].command_queue) - ports[0].commands_queued -= 1 - } - if ports[1].exists & ports[1].commands_queued > 0 { - memory.outb(0x64, 0xD4) - memory.outb(0x60, ports[1].command_queue) - ports[1].commands_queued -= 1 - } - } - - port := 0 - if ports[1].exists { - port = port_info >> 5 & 1 - } - - if ports[port].exists { - input := memory.inb(0x60) - if ports[port].awaiting_ack & input == 0xFA { - ports[port].awaiting_ack = false - } else { - @inline(handle_input, port, input) - } - } - } } \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/main_legacy.hb b/sysdata/programs/ps2_driver/src/main_legacy.hb new file mode 100644 index 0000000..04b8228 --- /dev/null +++ b/sysdata/programs/ps2_driver/src/main_legacy.hb @@ -0,0 +1,144 @@ +.{memory, log, string} := @use("../../../libraries/stn/src/lib.hb") +format_page := memory.dangling(u8) + +DeviceID := struct {value: u16} + +$Mouse3Button := DeviceID.(0x0) +$MouseScrollwheel := DeviceID.(0x3) +$Mouse5Button := DeviceID.(0x4) +$Spacesaver := DeviceID.(0x84AB) +$Keyboard122Key := DeviceID.(0x86AB) +$KeyboardJapaneseG := DeviceID.(0x90AB) +$KeyboardJapanesep := DeviceID.(0x91AB) +$KeyboardJapaneseA := DeviceID.(0x92AB) +$KeyboardNCDSun := DeviceID.(0xA1AC) +$NoDevice := DeviceID.(0xFFFF) + +State := struct {value: u8} +$Recive := State.(0) +$Reboot := State.(1) +$GetID := State.(2) +$TurnOnStreaming := State.(3) + +CommandQueue := struct {queue: [u8; 8]} + +Port := struct {exists: bool, device: DeviceID, commands_queued: u8, command_queue: [u8; 8], command_index: u8, awaiting_acks: u8, state: State, expecting: bool} + +$check_bit := fn(value: u8, bit: u8, state: u8): bool { + return (value >> bit & 1) == state +} + +ports := [Port].(.(true, NoDevice, 1, .(0xFF, 0, 0, 0, 0, 0, 0, 0), 0, 0, Reboot, false), .(true, NoDevice, 1, .(0xFF, 0, 0, 0, 0, 0, 0, 0), 0, 0, Reboot, false)) + +$send_byte := fn(port: uint, value: u8): void { + //Sending over 8 bytes will cause and overflow, don't do pwease? + ports[port].command_queue[(ports[port].command_index + 1) % 8] = value + ports[port].awaiting_acks += 1 +} + +initialize_controller := fn(): void { + memory.outb(0x64, 0xAD) + memory.outb(0x64, 0xA7) + //Disables ports to make sure that they won't interfere with the setup process. + + loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) + //Flushes any output because apperantly that might interfere with stuff. + + memory.outb(0x64, 0xA8) + //Enables port 2. + memory.outb(0x64, 0x20) + //Gimme configuration byte. + loop if (memory.inb(0x64) & 1) == 1 break + ports[1].exists = check_bit(memory.inb(0x60), 5, 0) + if ports[1].exists { + memory.outb(0x64, 0xA7) + } + + loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) + //Flushes any output because apperantly that might interfere with stuff. + + memory.outb(0x64, 0xAB) + loop if (memory.inb(0x64) & 1) == 1 break + ports[0].exists = memory.inb(0x60) == 0x0 + //Test port 1. + + if ports[1].exists { + memory.outb(0x64, 0xA9) + loop if (memory.inb(0x64) & 1) == 1 break + ports[1].exists = memory.inb(0x60) == 0x0 + } + //Test port 2. + + if (ports[0].exists | ports[1].exists) == false { + log.error("No ports detected! No input will be processed! Cannot handle this!\0") + } + + if ports[0].exists { + log.info("Port 1 exists.\0") + memory.outb(0x64, 0xAE) + //Enables port 1. + ports[0].commands_queued = 1 + } + if ports[1].exists { + log.info("Port 2 exists.\0") + memory.outb(0x64, 0xA8) + //Enables port 2. + ports[1].commands_queued = 1 + } +} + +handle_input := fn(port: uint, input: u8): void { + if input == 0xAA { + log.info("Device rebooted!\0") + log.info(string.display_int(@intcast(port + 1), format_page, 16)) + ports[port].state = GetID + send_byte(port, 0xF2) + //Get ID + } else if ports[port].state.value == Recive.value { + } +} + +main := fn(): void { + format_page = memory.alloc(u8, 1024) + + @inline(initialize_controller) + + loop { + port_info := memory.inb(0x64) + //Enables port 1. + if (port_info & 0x40) > 0 { + log.error("Timeout error! Cannot handle these!\0") + } + if (port_info & 0x80) > 0 { + log.error("Parity error! Cannot handle these!\0") + } + + if (port_info & 1) == 0 { + if ports[0].exists & ports[0].commands_queued > 0 { + memory.outb(0x60, ports[0].command_queue[ports[0].command_index]) + ports[0].commands_queued -= 1 + ports[0].command_index = (ports[0].command_index + 1) % 8 + } + if ports[1].exists & ports[1].commands_queued > 0 { + memory.outb(0x64, 0xD4) + memory.outb(0x60, ports[1].command_queue[ports[1].command_index]) + ports[1].commands_queued -= 1 + ports[1].command_index = (ports[1].command_index + 1) % 8 + } + } + + port := 0 + if ports[1].exists { + port = port_info >> 5 & 1 + } + + if ports[port].exists { + input := memory.inb(0x60) + if ports[port].awaiting_acks > 0 & input == 0xFA { + ports[port].awaiting_acks -= 1 + } else { + @inline(handle_input, port, input) + } + } + } +} \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/port.hb b/sysdata/programs/ps2_driver/src/port.hb new file mode 100644 index 0000000..6591840 --- /dev/null +++ b/sysdata/programs/ps2_driver/src/port.hb @@ -0,0 +1,10 @@ +Port := struct { + exists: bool + device: DeviceID + commands_queued: u8 + command_queue: [u8; 8] + command_index: u8 + awaiting_acks: u8 + state: State + expecting: bool +} \ No newline at end of file -- 2.44.1 From 11976b752f13412faf5dbbbfbb383ae057fe7d5e Mon Sep 17 00:00:00 2001 From: peony Date: Sat, 16 Nov 2024 22:56:00 +0100 Subject: [PATCH 14/23] PS/2 driver going well (it still doesn't work) --- sysdata/programs/ps2_driver/src/controller.hb | 59 ++++++++++++------- sysdata/programs/ps2_driver/src/devices.hb | 12 ++++ sysdata/programs/ps2_driver/src/port.hb | 2 + 3 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 sysdata/programs/ps2_driver/src/devices.hb diff --git a/sysdata/programs/ps2_driver/src/controller.hb b/sysdata/programs/ps2_driver/src/controller.hb index 00a83f6..a6826da 100644 --- a/sysdata/programs/ps2_driver/src/controller.hb +++ b/sysdata/programs/ps2_driver/src/controller.hb @@ -1,35 +1,52 @@ .{memory, log} := @use("../../../libraries/stn/src/lib.hb"); -.{bit5} := @use("bits.hb") +.{bit0, bit5} := @use("bits.hb") + +$disable_port1 := fn(): void memory.outb(0x64, 0xAD) +$enable_port1 := fn(): void memory.outb(0x64, 0xAE) +$disable_port2 := fn(): void memory.outb(0x64, 0xA7) +$enable_port2 := fn(): void memory.outb(0x64, 0xA8) + +//TODO test functions +/*test_port1 := fn(): bool { + +}*/ + +get_config_byte := fn(): u8 { + memory.outb(0x64, 0x20) + loop if has_input(get_info()) break + return memory.inb(0x60) +} + +Info := struct {d: u8} + +$get_info := fn(): u8 return .(memory.inb(0x64)) +$has_input := fn(info: Info): bool return bit0(info.d) + +flush_input := fn(): void { + loop if has_input(get_info()) == false break else memory.inb(0x60) +} init := fn(): void { - memory.outb(0x64, 0xAD) - memory.outb(0x64, 0xA7) + disable_port1() + disable_port2() //Disables ports to make sure that they won't interfere with the setup process. - loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) - //Flushes any output because apperantly that might interfere with stuff. + flush_input() - memory.outb(0x64, 0xA8) - //Enables port 2. - memory.outb(0x64, 0x20) - //Gimme configuration byte. - loop if (memory.inb(0x64) & 1) == 1 break - ports[1].exists = bit5(memory.inb(0x60)) == false - if ports[1].exists { - memory.outb(0x64, 0xA7) - } + enable_port2() + ports[1].exists = bit5(@inline(get_config_byte)) == false + disable_port2() - loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) - //Flushes any output because apperantly that might interfere with stuff. + flush_input() memory.outb(0x64, 0xAB) - loop if (memory.inb(0x64) & 1) == 1 break + loop if has_input(get_info()) break ports[0].exists = memory.inb(0x60) == 0x0 //Test port 1. if ports[1].exists { memory.outb(0x64, 0xA9) - loop if (memory.inb(0x64) & 1) == 1 break + loop if has_input(get_info()) break ports[1].exists = memory.inb(0x60) == 0x0 } //Test port 2. @@ -40,14 +57,12 @@ init := fn(): void { if ports[0].exists { log.info("Port 1 exists.\0") - memory.outb(0x64, 0xAE) - //Enables port 1. + enable_port1() ports[0].commands_queued = 1 } if ports[1].exists { log.info("Port 2 exists.\0") - memory.outb(0x64, 0xA8) - //Enables port 2. + enable_port2() ports[1].commands_queued = 1 } } \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/devices.hb b/sysdata/programs/ps2_driver/src/devices.hb new file mode 100644 index 0000000..db92593 --- /dev/null +++ b/sysdata/programs/ps2_driver/src/devices.hb @@ -0,0 +1,12 @@ +DeviceID := struct {value: u16} + +$Mouse3Button := DeviceID.(0x0) +$MouseScrollwheel := DeviceID.(0x3) +$Mouse5Button := DeviceID.(0x4) +$Spacesaver := DeviceID.(0x84AB) +$Keyboard122Key := DeviceID.(0x86AB) +$KeyboardJapaneseG := DeviceID.(0x90AB) +$KeyboardJapanesep := DeviceID.(0x91AB) +$KeyboardJapaneseA := DeviceID.(0x92AB) +$KeyboardNCDSun := DeviceID.(0xA1AC) +$NoDevice := DeviceID.(0xFFFF) \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/port.hb b/sysdata/programs/ps2_driver/src/port.hb index 6591840..1bcc674 100644 --- a/sysdata/programs/ps2_driver/src/port.hb +++ b/sysdata/programs/ps2_driver/src/port.hb @@ -1,3 +1,5 @@ +.{DeviceID} := @use("devices.hb") + Port := struct { exists: bool device: DeviceID -- 2.44.1 From 284aa5a5e647848358250a278d27656779c7ff52 Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 17 Nov 2024 11:17:32 +0100 Subject: [PATCH 15/23] PS/2 is so close --- sysdata/programs/ps2_driver/src/controller.hb | 63 ++++++++++++------- sysdata/programs/ps2_driver/src/main.hb | 3 + .../programs/ps2_driver/src/main_legacy.hb | 2 +- sysdata/programs/ps2_driver/src/port.hb | 30 +++++---- 4 files changed, 64 insertions(+), 34 deletions(-) diff --git a/sysdata/programs/ps2_driver/src/controller.hb b/sysdata/programs/ps2_driver/src/controller.hb index a6826da..6478587 100644 --- a/sysdata/programs/ps2_driver/src/controller.hb +++ b/sysdata/programs/ps2_driver/src/controller.hb @@ -1,31 +1,56 @@ .{memory, log} := @use("../../../libraries/stn/src/lib.hb"); -.{bit0, bit5} := @use("bits.hb") +.{bit0, bit5, bit6, bit7} := @use("bits.hb"); +.{Port, port_at_startup} := @use("port.hb") $disable_port1 := fn(): void memory.outb(0x64, 0xAD) $enable_port1 := fn(): void memory.outb(0x64, 0xAE) $disable_port2 := fn(): void memory.outb(0x64, 0xA7) $enable_port2 := fn(): void memory.outb(0x64, 0xA8) -//TODO test functions -/*test_port1 := fn(): bool { +test_port1 := fn(): bool { + memory.outb(0x64, 0xAB) + loop if has_input(get_info()) break + input := get_input() + return input == 0x0 +} -}*/ +test_port2 := fn(): bool { + memory.outb(0x64, 0xA9) + loop if has_input(get_info()) break + input := get_input() + return input == 0x0 +} get_config_byte := fn(): u8 { - memory.outb(0x64, 0x20) + memory.outb(0x64, 0x20) loop if has_input(get_info()) break - return memory.inb(0x60) + return get_input() } Info := struct {d: u8} $get_info := fn(): u8 return .(memory.inb(0x64)) $has_input := fn(info: Info): bool return bit0(info.d) +$timed_out := fn(info: Info): bool return bit6(info.d) +$check_parity := fn(info: Info): bool return bit7(info.d) +get_port := fn(info: Info): ^Port { + if bit5(info.d) { + return &port2 + } else { + return &port1 + } +} + +$get_input := fn(): u8 return memory.inb(0x60) +$write_out := fn(data: u8): void memory.outb(0x60, data) flush_input := fn(): void { - loop if has_input(get_info()) == false break else memory.inb(0x60) + loop if has_input(get_info()) == false break else get_info() } +port1 := port_at_startup +port2 := port_at_startup + init := fn(): void { disable_port1() disable_port2() @@ -34,35 +59,29 @@ init := fn(): void { flush_input() enable_port2() - ports[1].exists = bit5(@inline(get_config_byte)) == false + port2.exists = bit5(@inline(get_config_byte)) == false disable_port2() flush_input() - memory.outb(0x64, 0xAB) - loop if has_input(get_info()) break - ports[0].exists = memory.inb(0x60) == 0x0 - //Test port 1. + port1.exists = test_port1() - if ports[1].exists { - memory.outb(0x64, 0xA9) - loop if has_input(get_info()) break - ports[1].exists = memory.inb(0x60) == 0x0 + if port2.exists { + port2.exists = test_port2() } - //Test port 2. - if (ports[0].exists | ports[1].exists) == false { + if (port1.exists | port2.exists) == false { log.error("No ports detected! No input will be processed! Cannot handle this!\0") } - if ports[0].exists { + if port1.exists { log.info("Port 1 exists.\0") enable_port1() - ports[0].commands_queued = 1 + port1.commands.length = 1 } - if ports[1].exists { + if port2.exists { log.info("Port 2 exists.\0") enable_port2() - ports[1].commands_queued = 1 + port2.commands.length = 1 } } \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index a62e9e1..8362c4f 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -1,6 +1,9 @@ .{memory, log, string} := @use("../../../libraries/stn/src/lib.hb") +controller := @use("controller.hb") format_page := memory.dangling(u8) main := fn(): void { format_page = memory.alloc(u8, 1024) + + controller.init() } \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/main_legacy.hb b/sysdata/programs/ps2_driver/src/main_legacy.hb index 04b8228..5f33559 100644 --- a/sysdata/programs/ps2_driver/src/main_legacy.hb +++ b/sysdata/programs/ps2_driver/src/main_legacy.hb @@ -105,7 +105,7 @@ main := fn(): void { loop { port_info := memory.inb(0x64) - //Enables port 1. + if (port_info & 0x40) > 0 { log.error("Timeout error! Cannot handle these!\0") } diff --git a/sysdata/programs/ps2_driver/src/port.hb b/sysdata/programs/ps2_driver/src/port.hb index 1bcc674..5f270c1 100644 --- a/sysdata/programs/ps2_driver/src/port.hb +++ b/sysdata/programs/ps2_driver/src/port.hb @@ -1,12 +1,20 @@ -.{DeviceID} := @use("devices.hb") +.{DeviceID, NoDevice} := @use("devices.hb") -Port := struct { - exists: bool - device: DeviceID - commands_queued: u8 - command_queue: [u8; 8] - command_index: u8 - awaiting_acks: u8 - state: State - expecting: bool -} \ No newline at end of file +State := struct {s: u8} +$Reboot := State.(0) + +CommandQueue := packed struct {queue: [u8; 8], length: u8, current_index: u8} + +Port := packed struct { + exists: bool, + device: DeviceID, + commands: CommandQueue, + state: State, +} + +$port_at_startup := Port.( + true, + NoDevice, + .(.(0xFF, 0, 0, 0, 0, 0, 0, 0), 1, 0), + Reboot, +) \ No newline at end of file -- 2.44.1 From 23b45b1887b5a661112b7102f5172a2e4d0ecd38 Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 17 Nov 2024 17:57:06 +0100 Subject: [PATCH 16/23] Driver workkkk --- Cargo.lock | 6 ++-- sysdata/programs/ps2_driver/README.md | 1 + sysdata/programs/ps2_driver/src/controller.hb | 22 ++++++++----- sysdata/programs/ps2_driver/src/main.hb | 31 ++++++++++++++++++- sysdata/programs/ps2_driver/src/port.hb | 13 ++++---- sysdata/system_config.toml | 4 +-- 6 files changed, 57 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7d4cd9e..a336be8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#12bb7029b4bafd1edff77ed9a12888374cc7f8be" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#397b2a4b1b7c088f379f32d846e235c1286e17e0" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#12bb7029b4bafd1edff77ed9a12888374cc7f8be" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#397b2a4b1b7c088f379f32d846e235c1286e17e0" dependencies = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#12bb7029b4bafd1edff77ed9a12888374cc7f8be" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#397b2a4b1b7c088f379f32d846e235c1286e17e0" dependencies = [ "hbbytecode", ] diff --git a/sysdata/programs/ps2_driver/README.md b/sysdata/programs/ps2_driver/README.md index c0a3d83..c311653 100644 --- a/sysdata/programs/ps2_driver/README.md +++ b/sysdata/programs/ps2_driver/README.md @@ -10,3 +10,4 @@ Anyone who works on this should work to keep this list as small as possible/remo - Both PS/2 ports being broken doesn't need handling. - One PS/2 port being broken doesn't need special attention. - PS/2 controller doesn't need to perform a self-check. +- Stack overflows aren't a thing \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/controller.hb b/sysdata/programs/ps2_driver/src/controller.hb index 6478587..2c6af89 100644 --- a/sysdata/programs/ps2_driver/src/controller.hb +++ b/sysdata/programs/ps2_driver/src/controller.hb @@ -1,5 +1,5 @@ .{memory, log} := @use("../../../libraries/stn/src/lib.hb"); -.{bit0, bit5, bit6, bit7} := @use("bits.hb"); +.{bit0, bit1, bit5, bit6, bit7} := @use("bits.hb"); .{Port, port_at_startup} := @use("port.hb") $disable_port1 := fn(): void memory.outb(0x64, 0xAD) @@ -29,10 +29,12 @@ get_config_byte := fn(): u8 { Info := struct {d: u8} -$get_info := fn(): u8 return .(memory.inb(0x64)) -$has_input := fn(info: Info): bool return bit0(info.d) -$timed_out := fn(info: Info): bool return bit6(info.d) -$check_parity := fn(info: Info): bool return bit7(info.d) +$get_info := fn(): Info return .(memory.inb(0x64)) +//inline when can +has_input := fn(info: Info): bool return bit0(info.d) +can_send := fn(info: Info): bool return bit1(info.d) == false +timed_out := fn(info: Info): bool return bit6(info.d) +check_parity := fn(info: Info): bool return bit7(info.d) get_port := fn(info: Info): ^Port { if bit5(info.d) { return &port2 @@ -41,6 +43,14 @@ get_port := fn(info: Info): ^Port { } } +send_byte := fn(port: ^Port, byte: u8): void { + if port == port2 { + memory.outb(0x64, 0xD4) + } + loop if can_send(get_info()) break + memory.outb(0x60, byte) +} + $get_input := fn(): u8 return memory.inb(0x60) $write_out := fn(data: u8): void memory.outb(0x60, data) @@ -77,11 +87,9 @@ init := fn(): void { if port1.exists { log.info("Port 1 exists.\0") enable_port1() - port1.commands.length = 1 } if port2.exists { log.info("Port 2 exists.\0") enable_port2() - port2.commands.length = 1 } } \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index 8362c4f..ce6bd6b 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -1,9 +1,38 @@ -.{memory, log, string} := @use("../../../libraries/stn/src/lib.hb") +.{memory, log, string} := @use("../../../libraries/stn/src/lib.hb"); +.{Mouse3Button} := @use("devices.hb") controller := @use("controller.hb") format_page := memory.dangling(u8) +info := controller.Info.(0) + +process := fn(port: ^controller.Port): bool { +} + +check_complete := fn(port: ^controller.Port): bool { +} + main := fn(): void { format_page = memory.alloc(u8, 1024) controller.init() + + loop { + info = controller.get_info() + + if controller.timed_out(info) { + log.error("Timeout error! Cannot handle these!\0") + } + if controller.check_parity(info) { + log.error("Parity error! Cannot handle these!\0") + } + + if controller.has_input(info) { + port := controller.get_port(info) + port.packet[port.packet_length] = controller.get_input() + port.packet_length += 1 + if @inline(check_complete, port) { + process(port) + } + } + } } \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/port.hb b/sysdata/programs/ps2_driver/src/port.hb index 5f270c1..852d0d6 100644 --- a/sysdata/programs/ps2_driver/src/port.hb +++ b/sysdata/programs/ps2_driver/src/port.hb @@ -1,20 +1,19 @@ .{DeviceID, NoDevice} := @use("devices.hb") State := struct {s: u8} -$Reboot := State.(0) - -CommandQueue := packed struct {queue: [u8; 8], length: u8, current_index: u8} +$Recive := State.(0) +$Reboot := State.(1) Port := packed struct { exists: bool, device: DeviceID, - commands: CommandQueue, - state: State, + packet: [u8; 4], + packet_length: u8, } $port_at_startup := Port.( true, NoDevice, - .(.(0xFF, 0, 0, 0, 0, 0, 0, 0), 1, 0), - Reboot, + .(0, 0, 0, 0), + 0, ) \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 6bb34b7..89830c9 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -28,8 +28,8 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.horizon] # path = "boot:///horizon.hbf" -[boot.limine.ableos.modules.ps2_mouse_driver] -path = "boot:///ps2_mouse_driver.hbf" +# [boot.limine.ableos.modules.ps2_mouse_driver] +# path = "boot:///ps2_mouse_driver.hbf" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" -- 2.44.1 From 90a97cd16000899b015a6af03111927c128498be Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 17 Nov 2024 19:11:13 +0100 Subject: [PATCH 17/23] more work --- Cargo.lock | 6 +++--- sysdata/programs/ps2_driver/src/controller.hb | 6 +++--- sysdata/programs/ps2_driver/src/main.hb | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a336be8..1eaf3cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#397b2a4b1b7c088f379f32d846e235c1286e17e0" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#fe5a8631f66e7acde8707a68ad25074ab5b1f408" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#397b2a4b1b7c088f379f32d846e235c1286e17e0" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#fe5a8631f66e7acde8707a68ad25074ab5b1f408" dependencies = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#397b2a4b1b7c088f379f32d846e235c1286e17e0" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#fe5a8631f66e7acde8707a68ad25074ab5b1f408" dependencies = [ "hbbytecode", ] diff --git a/sysdata/programs/ps2_driver/src/controller.hb b/sysdata/programs/ps2_driver/src/controller.hb index 2c6af89..38863b1 100644 --- a/sysdata/programs/ps2_driver/src/controller.hb +++ b/sysdata/programs/ps2_driver/src/controller.hb @@ -2,6 +2,9 @@ .{bit0, bit1, bit5, bit6, bit7} := @use("bits.hb"); .{Port, port_at_startup} := @use("port.hb") +port1 := port_at_startup +port2 := port_at_startup + $disable_port1 := fn(): void memory.outb(0x64, 0xAD) $enable_port1 := fn(): void memory.outb(0x64, 0xAE) $disable_port2 := fn(): void memory.outb(0x64, 0xA7) @@ -58,9 +61,6 @@ flush_input := fn(): void { loop if has_input(get_info()) == false break else get_info() } -port1 := port_at_startup -port2 := port_at_startup - init := fn(): void { disable_port1() disable_port2() diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index ce6bd6b..362c101 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -5,7 +5,8 @@ format_page := memory.dangling(u8) info := controller.Info.(0) -process := fn(port: ^controller.Port): bool { +process := fn(port: ^controller.Port): void { + } check_complete := fn(port: ^controller.Port): bool { -- 2.44.1 From 2fdede7199363f1adf021a26bb17e9ace9a138d4 Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 17 Nov 2024 21:30:58 +0100 Subject: [PATCH 18/23] PS/2 workkkk --- Cargo.lock | 6 +- sysdata/programs/ps2_driver/README.md | 8 +- sysdata/programs/ps2_driver/src/controller.hb | 6 +- sysdata/programs/ps2_driver/src/devices.hb | 23 +-- sysdata/programs/ps2_driver/src/main.hb | 46 +++++- .../programs/ps2_driver/src/main_legacy.hb | 144 ------------------ sysdata/programs/ps2_driver/src/port.hb | 10 +- 7 files changed, 74 insertions(+), 169 deletions(-) delete mode 100644 sysdata/programs/ps2_driver/src/main_legacy.hb diff --git a/Cargo.lock b/Cargo.lock index 1eaf3cc..c82d462 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#fe5a8631f66e7acde8707a68ad25074ab5b1f408" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#542c69fd6042a4b48462199c4391761bfe1b7c2e" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#fe5a8631f66e7acde8707a68ad25074ab5b1f408" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#542c69fd6042a4b48462199c4391761bfe1b7c2e" dependencies = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#fe5a8631f66e7acde8707a68ad25074ab5b1f408" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#542c69fd6042a4b48462199c4391761bfe1b7c2e" dependencies = [ "hbbytecode", ] diff --git a/sysdata/programs/ps2_driver/README.md b/sysdata/programs/ps2_driver/README.md index c311653..6193606 100644 --- a/sysdata/programs/ps2_driver/README.md +++ b/sysdata/programs/ps2_driver/README.md @@ -10,4 +10,10 @@ Anyone who works on this should work to keep this list as small as possible/remo - Both PS/2 ports being broken doesn't need handling. - One PS/2 port being broken doesn't need special attention. - PS/2 controller doesn't need to perform a self-check. -- Stack overflows aren't a thing \ No newline at end of file +- These DeviceIDs never exist: + - 0xFFFD + - 0xFFFE + - 0xFFFF + - 0x01xx + - 0x03xx + - 0x04xx \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/controller.hb b/sysdata/programs/ps2_driver/src/controller.hb index 38863b1..35fb4fe 100644 --- a/sysdata/programs/ps2_driver/src/controller.hb +++ b/sysdata/programs/ps2_driver/src/controller.hb @@ -1,9 +1,9 @@ .{memory, log} := @use("../../../libraries/stn/src/lib.hb"); .{bit0, bit1, bit5, bit6, bit7} := @use("bits.hb"); -.{Port, port_at_startup} := @use("port.hb") +.{Port, PORT_AT_STARTUP} := @use("port.hb") -port1 := port_at_startup -port2 := port_at_startup +port1 := PORT_AT_STARTUP +port2 := PORT_AT_STARTUP $disable_port1 := fn(): void memory.outb(0x64, 0xAD) $enable_port1 := fn(): void memory.outb(0x64, 0xAE) diff --git a/sysdata/programs/ps2_driver/src/devices.hb b/sysdata/programs/ps2_driver/src/devices.hb index db92593..7cfbdb0 100644 --- a/sysdata/programs/ps2_driver/src/devices.hb +++ b/sysdata/programs/ps2_driver/src/devices.hb @@ -1,12 +1,15 @@ DeviceID := struct {value: u16} -$Mouse3Button := DeviceID.(0x0) -$MouseScrollwheel := DeviceID.(0x3) -$Mouse5Button := DeviceID.(0x4) -$Spacesaver := DeviceID.(0x84AB) -$Keyboard122Key := DeviceID.(0x86AB) -$KeyboardJapaneseG := DeviceID.(0x90AB) -$KeyboardJapanesep := DeviceID.(0x91AB) -$KeyboardJapaneseA := DeviceID.(0x92AB) -$KeyboardNCDSun := DeviceID.(0xA1AC) -$NoDevice := DeviceID.(0xFFFF) \ No newline at end of file +$MOUSE_3_BUTTON := DeviceID.(0x0) +$MOUSE_SCROLLWHEEL := DeviceID.(0x3) +$MOUSE_5_BUTTON := DeviceID.(0x4) +$KEYBOARD_SPACESAVER := DeviceID.(0x84AB) +$KEYBOARD_122_KEY := DeviceID.(0x86AB) +$KEYBOARD_JAPANESE_G := DeviceID.(0x90AB) +$KEYBOARD_JAPANESE_P := DeviceID.(0x91AB) +$KEYBOARD_JAPANESE_A := DeviceID.(0x92AB) +$KEYBOARD_NCD_SUN := DeviceID.(0xA1AC) + +$MOUSE_INIT_1 := DeviceID.(0xFFFD) +$MOUSE_INIT_2 := DeviceID.(0xFFFE) +$NO_DEVICE := DeviceID.(0xFFFF) \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index 362c101..32b786a 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -1,15 +1,49 @@ -.{memory, log, string} := @use("../../../libraries/stn/src/lib.hb"); -.{Mouse3Button} := @use("devices.hb") +.{memory, log, string} := @use("../../../libraries/stn/src/lib.hb") +devices := @use("devices.hb") controller := @use("controller.hb") format_page := memory.dangling(u8) info := controller.Info.(0) process := fn(port: ^controller.Port): void { - + if port.device == devices.MOUSE_3_BUTTON { + } else if port.device == devices.MOUSE_INIT_1 { + port.device.value = port.packet[0] | port.packet[1] << 8 + if port.device == devices.MOUSE_SCROLLWHEEL { + port.device = devices.MOUSE_INIT_2 + } + } else if port.device == devices.MOUSE_INIT_2 { + port.device.value = port.packet[0] | port.packet[1] << 8 + } else if port.device == devices.NO_DEVICE { + if port.packet_length == 1 { + port.device.value = port.packet[0] + } else { + port.device.value = port.packet[1] | port.packet[0] << 8 + } + log.info("Identified device!\0") + log.info(string.display_int(port.device.value, format_page, 16)) + } } check_complete := fn(port: ^controller.Port): bool { + last_value := port.packet[port.packet_length - 1] + if port.device == devices.NO_DEVICE { + if last_value == 0 | last_value == 3 | last_value == 4 { + return true + } else if port.packet_length == 2 { + return true + } + } + if port.device == devices.MOUSE_3_BUTTON { + if port.packet_length == 3 return true + } + if port.device == devices.MOUSE_SCROLLWHEEL | port.device == devices.MOUSE_5_BUTTON { + if port.packet_length == 4 return true + } else { + log.error("Very unexpected error. Cannot handle this!\0") + return true + } + return false } main := fn(): void { @@ -29,7 +63,11 @@ main := fn(): void { if controller.has_input(info) { port := controller.get_port(info) - port.packet[port.packet_length] = controller.get_input() + input := controller.get_input() + if input == 0xAA & port.can_hot_plug { + port.device = devices.NO_DEVICE + } + port.packet[port.packet_length] = input port.packet_length += 1 if @inline(check_complete, port) { process(port) diff --git a/sysdata/programs/ps2_driver/src/main_legacy.hb b/sysdata/programs/ps2_driver/src/main_legacy.hb deleted file mode 100644 index 5f33559..0000000 --- a/sysdata/programs/ps2_driver/src/main_legacy.hb +++ /dev/null @@ -1,144 +0,0 @@ -.{memory, log, string} := @use("../../../libraries/stn/src/lib.hb") -format_page := memory.dangling(u8) - -DeviceID := struct {value: u16} - -$Mouse3Button := DeviceID.(0x0) -$MouseScrollwheel := DeviceID.(0x3) -$Mouse5Button := DeviceID.(0x4) -$Spacesaver := DeviceID.(0x84AB) -$Keyboard122Key := DeviceID.(0x86AB) -$KeyboardJapaneseG := DeviceID.(0x90AB) -$KeyboardJapanesep := DeviceID.(0x91AB) -$KeyboardJapaneseA := DeviceID.(0x92AB) -$KeyboardNCDSun := DeviceID.(0xA1AC) -$NoDevice := DeviceID.(0xFFFF) - -State := struct {value: u8} -$Recive := State.(0) -$Reboot := State.(1) -$GetID := State.(2) -$TurnOnStreaming := State.(3) - -CommandQueue := struct {queue: [u8; 8]} - -Port := struct {exists: bool, device: DeviceID, commands_queued: u8, command_queue: [u8; 8], command_index: u8, awaiting_acks: u8, state: State, expecting: bool} - -$check_bit := fn(value: u8, bit: u8, state: u8): bool { - return (value >> bit & 1) == state -} - -ports := [Port].(.(true, NoDevice, 1, .(0xFF, 0, 0, 0, 0, 0, 0, 0), 0, 0, Reboot, false), .(true, NoDevice, 1, .(0xFF, 0, 0, 0, 0, 0, 0, 0), 0, 0, Reboot, false)) - -$send_byte := fn(port: uint, value: u8): void { - //Sending over 8 bytes will cause and overflow, don't do pwease? - ports[port].command_queue[(ports[port].command_index + 1) % 8] = value - ports[port].awaiting_acks += 1 -} - -initialize_controller := fn(): void { - memory.outb(0x64, 0xAD) - memory.outb(0x64, 0xA7) - //Disables ports to make sure that they won't interfere with the setup process. - - loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) - //Flushes any output because apperantly that might interfere with stuff. - - memory.outb(0x64, 0xA8) - //Enables port 2. - memory.outb(0x64, 0x20) - //Gimme configuration byte. - loop if (memory.inb(0x64) & 1) == 1 break - ports[1].exists = check_bit(memory.inb(0x60), 5, 0) - if ports[1].exists { - memory.outb(0x64, 0xA7) - } - - loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) - //Flushes any output because apperantly that might interfere with stuff. - - memory.outb(0x64, 0xAB) - loop if (memory.inb(0x64) & 1) == 1 break - ports[0].exists = memory.inb(0x60) == 0x0 - //Test port 1. - - if ports[1].exists { - memory.outb(0x64, 0xA9) - loop if (memory.inb(0x64) & 1) == 1 break - ports[1].exists = memory.inb(0x60) == 0x0 - } - //Test port 2. - - if (ports[0].exists | ports[1].exists) == false { - log.error("No ports detected! No input will be processed! Cannot handle this!\0") - } - - if ports[0].exists { - log.info("Port 1 exists.\0") - memory.outb(0x64, 0xAE) - //Enables port 1. - ports[0].commands_queued = 1 - } - if ports[1].exists { - log.info("Port 2 exists.\0") - memory.outb(0x64, 0xA8) - //Enables port 2. - ports[1].commands_queued = 1 - } -} - -handle_input := fn(port: uint, input: u8): void { - if input == 0xAA { - log.info("Device rebooted!\0") - log.info(string.display_int(@intcast(port + 1), format_page, 16)) - ports[port].state = GetID - send_byte(port, 0xF2) - //Get ID - } else if ports[port].state.value == Recive.value { - } -} - -main := fn(): void { - format_page = memory.alloc(u8, 1024) - - @inline(initialize_controller) - - loop { - port_info := memory.inb(0x64) - - if (port_info & 0x40) > 0 { - log.error("Timeout error! Cannot handle these!\0") - } - if (port_info & 0x80) > 0 { - log.error("Parity error! Cannot handle these!\0") - } - - if (port_info & 1) == 0 { - if ports[0].exists & ports[0].commands_queued > 0 { - memory.outb(0x60, ports[0].command_queue[ports[0].command_index]) - ports[0].commands_queued -= 1 - ports[0].command_index = (ports[0].command_index + 1) % 8 - } - if ports[1].exists & ports[1].commands_queued > 0 { - memory.outb(0x64, 0xD4) - memory.outb(0x60, ports[1].command_queue[ports[1].command_index]) - ports[1].commands_queued -= 1 - ports[1].command_index = (ports[1].command_index + 1) % 8 - } - } - - port := 0 - if ports[1].exists { - port = port_info >> 5 & 1 - } - - if ports[port].exists { - input := memory.inb(0x60) - if ports[port].awaiting_acks > 0 & input == 0xFA { - ports[port].awaiting_acks -= 1 - } else { - @inline(handle_input, port, input) - } - } - } -} \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/port.hb b/sysdata/programs/ps2_driver/src/port.hb index 852d0d6..108c9aa 100644 --- a/sysdata/programs/ps2_driver/src/port.hb +++ b/sysdata/programs/ps2_driver/src/port.hb @@ -1,4 +1,4 @@ -.{DeviceID, NoDevice} := @use("devices.hb") +.{DeviceID, NO_DEVICE} := @use("devices.hb") State := struct {s: u8} $Recive := State.(0) @@ -7,13 +7,15 @@ $Reboot := State.(1) Port := packed struct { exists: bool, device: DeviceID, - packet: [u8; 4], + packet: [u8; 8], packet_length: u8, + can_hot_plug: bool, } -$port_at_startup := Port.( +$PORT_AT_STARTUP := Port.( true, - NoDevice, + NO_DEVICE, .(0, 0, 0, 0), 0, + true, ) \ No newline at end of file -- 2.44.1 From 3d5a8f6f10cae005387742f0b2ee4250a176a49a Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 17 Nov 2024 22:38:07 +0100 Subject: [PATCH 19/23] End meeeee --- sysdata/programs/ps2_driver/README.md | 7 ++- sysdata/programs/ps2_driver/src/controller.hb | 6 +- sysdata/programs/ps2_driver/src/main.hb | 61 +++++++++++++++---- sysdata/programs/ps2_driver/src/mouse.hb | 21 +++++++ sysdata/programs/ps2_driver/src/port.hb | 2 +- 5 files changed, 78 insertions(+), 19 deletions(-) create mode 100644 sysdata/programs/ps2_driver/src/mouse.hb diff --git a/sysdata/programs/ps2_driver/README.md b/sysdata/programs/ps2_driver/README.md index 6193606..3f5c580 100644 --- a/sysdata/programs/ps2_driver/README.md +++ b/sysdata/programs/ps2_driver/README.md @@ -1,6 +1,6 @@ # Unified PS/2 Driver -Te entire thing is heavily documented with comments because I'm not sure how else to make this understandable. +Te entire thing is held together inspite ## !!Assumptions!! Anyone who works on this should work to keep this list as small as possible/remove as many of these as possible. @@ -16,4 +16,7 @@ Anyone who works on this should work to keep this list as small as possible/remo - 0xFFFF - 0x01xx - 0x03xx - - 0x04xx \ No newline at end of file + - 0x04xx +- Literally all PS/2 keyboards can be handeled the exact same way. We have the capability for detecting different keyboard types, I just don't bother with it because that would litreally take months to get working. + +Supporting mice in the keyboard port and vice versa was a ***bad*** idea, but I do not regret it because it means we're "superior" to real world operating systems. \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/controller.hb b/sysdata/programs/ps2_driver/src/controller.hb index 35fb4fe..029fdd2 100644 --- a/sysdata/programs/ps2_driver/src/controller.hb +++ b/sysdata/programs/ps2_driver/src/controller.hb @@ -2,8 +2,8 @@ .{bit0, bit1, bit5, bit6, bit7} := @use("bits.hb"); .{Port, PORT_AT_STARTUP} := @use("port.hb") -port1 := PORT_AT_STARTUP -port2 := PORT_AT_STARTUP +port1 := @as(Port, PORT_AT_STARTUP) +port2 := @as(Port, PORT_AT_STARTUP) $disable_port1 := fn(): void memory.outb(0x64, 0xAD) $enable_port1 := fn(): void memory.outb(0x64, 0xAE) @@ -47,7 +47,7 @@ get_port := fn(info: Info): ^Port { } send_byte := fn(port: ^Port, byte: u8): void { - if port == port2 { + if port == &port2 { memory.outb(0x64, 0xD4) } loop if can_send(get_info()) break diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index 32b786a..527afc7 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -1,19 +1,51 @@ -.{memory, log, string} := @use("../../../libraries/stn/src/lib.hb") +.{memory, log, buffer, string} := @use("../../../libraries/stn/src/lib.hb"); +.{MouseEvent} := @use("../../../libraries/intouch/src/lib.hb").events; +.{bit0, bit1, bit2, bit3, bit4} := @use("bits.hb") devices := @use("devices.hb") controller := @use("controller.hb") +mouse := @use("mouse.hb") format_page := memory.dangling(u8) +mouse_buffer := 0 +keyboard_buffer := 0 info := controller.Info.(0) -process := fn(port: ^controller.Port): void { - if port.device == devices.MOUSE_3_BUTTON { - } else if port.device == devices.MOUSE_INIT_1 { - port.device.value = port.packet[0] | port.packet[1] << 8 - if port.device == devices.MOUSE_SCROLLWHEEL { - port.device = devices.MOUSE_INIT_2 +send_command := fn(port: ^controller.Port, byte: u8): void { + controller.send_byte(port, byte) + loop { + info = controller.get_info() + if controller.has_input(info) == false { + continue } + input := controller.get_input() + if controller.get_port(info) != port { + if check_complete(port) == false { + } + } + } +} + +process := fn(port: ^controller.Port): void { + if port.device.value < devices.MOUSE_5_BUTTON.value { + event := MouseEvent.(0, 0, false, false, false) + + event.left = bit0(port.packet[0]) + event.right = bit1(port.packet[0]) + event.middle = bit2(port.packet[0]) + + event.x_change = @intcast(port.packet[1]) + event.y_change = @intcast(port.packet[2]) + + buffer.write(MouseEvent, mouse_buffer, &event) + } else if port.device == devices.MOUSE_INIT_1 { + port.device.value = port.packet[0] + if port.device != devices.MOUSE_SCROLLWHEEL { + controller.send_byte(port, 0xF4) + return + } + port.device = devices.MOUSE_INIT_2 } else if port.device == devices.MOUSE_INIT_2 { - port.device.value = port.packet[0] | port.packet[1] << 8 + port.device.value = port.packet[0] } else if port.device == devices.NO_DEVICE { if port.packet_length == 1 { port.device.value = port.packet[0] @@ -33,11 +65,9 @@ check_complete := fn(port: ^controller.Port): bool { } else if port.packet_length == 2 { return true } - } - if port.device == devices.MOUSE_3_BUTTON { + } else if port.device == devices.MOUSE_3_BUTTON { if port.packet_length == 3 return true - } - if port.device == devices.MOUSE_SCROLLWHEEL | port.device == devices.MOUSE_5_BUTTON { + } else if port.device == devices.MOUSE_SCROLLWHEEL | port.device == devices.MOUSE_5_BUTTON { if port.packet_length == 4 return true } else { log.error("Very unexpected error. Cannot handle this!\0") @@ -47,6 +77,7 @@ check_complete := fn(port: ^controller.Port): bool { } main := fn(): void { + mouse_buffer = buffer.create("PS/2 Mouse\0") format_page = memory.alloc(u8, 1024) controller.init() @@ -63,14 +94,18 @@ main := fn(): void { if controller.has_input(info) { port := controller.get_port(info) + if port.packet_length > 0 & check_complete(port) { + process(port) + } input := controller.get_input() if input == 0xAA & port.can_hot_plug { port.device = devices.NO_DEVICE } port.packet[port.packet_length] = input port.packet_length += 1 - if @inline(check_complete, port) { + if check_complete(port) { process(port) + port.packet_length = 0 } } } diff --git a/sysdata/programs/ps2_driver/src/mouse.hb b/sysdata/programs/ps2_driver/src/mouse.hb new file mode 100644 index 0000000..a3dd51b --- /dev/null +++ b/sysdata/programs/ps2_driver/src/mouse.hb @@ -0,0 +1,21 @@ +Button := struct {id: u8} +$LEFT_BUTTON := Button.(1) +$RIGHT_BUTTON := Button.(2) +$MIDDLE_BUTTON := Button.(4) +$BUTTON4 := Button.(8) +$BUTTON5 := Button.(16) + +SampleRate := struct {value: u8} +$SR10 := SampleRate.(10) +$SR20 := SampleRate.(20) +$SR40 := SampleRate.(40) +$SR60 := SampleRate.(60) +$SR80 := SampleRate.(80) +$SR100 := SampleRate.(100) +$SR200 := SampleRate.(200) + +Resolution := struct {value: u8} +$RES_1COUNT_PER_MM := Resolution.(0) +$RES_2COUNT_PER_MM := Resolution.(1) +$RES_4COUNT_PER_MM := Resolution.(2) +$RES_8COUNT_PER_MM := Resolution.(3) \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/port.hb b/sysdata/programs/ps2_driver/src/port.hb index 108c9aa..76563d1 100644 --- a/sysdata/programs/ps2_driver/src/port.hb +++ b/sysdata/programs/ps2_driver/src/port.hb @@ -15,7 +15,7 @@ Port := packed struct { $PORT_AT_STARTUP := Port.( true, NO_DEVICE, - .(0, 0, 0, 0), + .(0, 0, 0, 0, 0, 0, 0, 0), 0, true, ) \ No newline at end of file -- 2.44.1 From 8f265ebf40415a843c26ac26722aa3987ef050ce Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 17 Nov 2024 22:59:05 +0100 Subject: [PATCH 20/23] PS/2 literally almost work --- sysdata/programs/ps2_driver/README.md | 1 + sysdata/programs/ps2_driver/src/main.hb | 54 +++++++++++++++++++------ 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/sysdata/programs/ps2_driver/README.md b/sysdata/programs/ps2_driver/README.md index 3f5c580..283b6ae 100644 --- a/sysdata/programs/ps2_driver/README.md +++ b/sysdata/programs/ps2_driver/README.md @@ -18,5 +18,6 @@ Anyone who works on this should work to keep this list as small as possible/remo - 0x03xx - 0x04xx - Literally all PS/2 keyboards can be handeled the exact same way. We have the capability for detecting different keyboard types, I just don't bother with it because that would litreally take months to get working. +- The device doesn't send any data while we're waiting for an `ACK`. Supporting mice in the keyboard port and vice versa was a ***bad*** idea, but I do not regret it because it means we're "superior" to real world operating systems. \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index 527afc7..a43a396 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -11,15 +11,25 @@ keyboard_buffer := 0 info := controller.Info.(0) send_command := fn(port: ^controller.Port, byte: u8): void { - controller.send_byte(port, byte) loop { - info = controller.get_info() - if controller.has_input(info) == false { - continue - } - input := controller.get_input() - if controller.get_port(info) != port { - if check_complete(port) == false { + controller.send_byte(port, byte) + loop { + info = controller.get_info() + if controller.has_input(info) == false { + continue + } + input := controller.get_input() + if controller.get_port(info) != port { + if check_complete(port) == false { + port.packet[port.packet_length] = input + port.packet_length += 1 + } + continue + } + if input == 0xFA { + return + } else { + break } } } @@ -51,9 +61,12 @@ process := fn(port: ^controller.Port): void { port.device.value = port.packet[0] } else { port.device.value = port.packet[1] | port.packet[0] << 8 + send_command(port, 0xF4) } log.info("Identified device!\0") log.info(string.display_int(port.device.value, format_page, 16)) + } else { + log.info("KEY PRESSED\0") } } @@ -70,8 +83,17 @@ check_complete := fn(port: ^controller.Port): bool { } else if port.device == devices.MOUSE_SCROLLWHEEL | port.device == devices.MOUSE_5_BUTTON { if port.packet_length == 4 return true } else { - log.error("Very unexpected error. Cannot handle this!\0") - return true + if port.packet[0] == 0xE1 { + if port.packet_length == 6 { + return true + } + } else if port.packet[0] != 0xE0 { + return true + } else if port.packet_length == 2 & port.packet[1] != 0x2A & port.packet[1] != 0xB7 { + return true + } else if port.packet_length == 4 { + return true + } } return false } @@ -82,6 +104,13 @@ main := fn(): void { controller.init() + if controller.port1.exists { + controller.send_byte(&controller.port1, 0xF4) + } + if controller.port2.exists { + controller.send_byte(&controller.port2, 0xF4) + } + loop { info = controller.get_info() @@ -98,9 +127,10 @@ main := fn(): void { process(port) } input := controller.get_input() - if input == 0xAA & port.can_hot_plug { + /*if input == 0xAA & port.can_hot_plug { port.device = devices.NO_DEVICE - } + controller.send_byte(port, 0xF4) + }*/ port.packet[port.packet_length] = input port.packet_length += 1 if check_complete(port) { -- 2.44.1 From d78878a12f4dac7258dbf09959b2175afccdddc1 Mon Sep 17 00:00:00 2001 From: peony Date: Mon, 18 Nov 2024 20:29:51 +0100 Subject: [PATCH 21/23] Compiler error --- sysdata/programs/ps2_driver/error.error | 122 ++++++++++++++++++++++++ sysdata/programs/ps2_driver/src/main.hb | 4 +- 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 sysdata/programs/ps2_driver/error.error diff --git a/sysdata/programs/ps2_driver/error.error b/sysdata/programs/ps2_driver/error.error new file mode 100644 index 0000000..0d74b66 --- /dev/null +++ b/sysdata/programs/ps2_driver/error.error @@ -0,0 +1,122 @@ +2 1 48 Node { kind: Then, inputs: [47], outputs: [90], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 10 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +2 1 88 Node { kind: Region, inputs: [70, 87], outputs: [89, 90], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 18 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +2 1 87 Node { kind: Else, inputs: [69], outputs: [88], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 17 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +2 1 69 Node { kind: If, inputs: [64, 68], outputs: [70, 87], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 16 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +2 1 64 Node { kind: Call { func: Func(18), args: Tuple(193) }, inputs: [63, 5, 39, 40], outputs: [69, 66, 68, 66], peep_triggers: [], clobbers: [0, 1], ty: Id(7), pos: 0, depth: Cell { value: 15 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +2 1 63 Node { kind: Then, inputs: [62], outputs: [64], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 14 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +2 1 70 Node { kind: Then, inputs: [69], outputs: [88, 86, 82, 81, 80, 76, 85, 75, 74, 84, 71, 73], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 17 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +3 1 48 Node { kind: Then, inputs: [47], outputs: [90], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 10 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +3 1 88 Node { kind: Region, inputs: [70, 87], outputs: [89, 90], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 18 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +3 1 87 Node { kind: Else, inputs: [69], outputs: [88], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 17 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +3 1 69 Node { kind: If, inputs: [64, 68], outputs: [70, 87], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 16 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +3 1 64 Node { kind: Call { func: Func(18), args: Tuple(193) }, inputs: [63, 5, 39, 40], outputs: [69, 66, 68, 66], peep_triggers: [], clobbers: [0, 1], ty: Id(7), pos: 0, depth: Cell { value: 15 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +3 1 63 Node { kind: Then, inputs: [62], outputs: [64], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 14 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +3 2 62 Node { kind: If, inputs: [59, 61], outputs: [63, 92], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 13 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 2 }, aclass: 0 } +3 2 59 Node { kind: Call { func: Func(17), args: Tuple(417) }, inputs: [57, 58, 40], outputs: [62, 61, 61], peep_triggers: [82], clobbers: [1], ty: Id(805306369), pos: 0, depth: Cell { value: 12 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 2 }, aclass: 0 } +3 2 57 Node { kind: Call { func: Func(4294967295), args: Tuple(292) }, inputs: [49, 7, 7, 51, 33, 40, 56], outputs: [59, 82, 94, 58], peep_triggers: [], clobbers: [1, 3], ty: Id(8), pos: 0, depth: Cell { value: 11 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 2 }, aclass: 0 } +3 2 49 Node { kind: Else, inputs: [47], outputs: [57], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 10 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 2 }, aclass: 0 } +3 1 70 Node { kind: Then, inputs: [69], outputs: [88, 86, 82, 81, 80, 76, 85, 75, 74, 84, 71, 73], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 17 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } +thread 'main' panicked at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/son.rs:1761:13: +explicit panic +stack backtrace: + 0: 0x607c994845ba - std::backtrace_rs::backtrace::libunwind::trace::h504b0125eda6b384 + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5 + 1: 0x607c994845ba - std::backtrace_rs::backtrace::trace_unsynchronized::hc81f5dfa1a7e52fe + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 + 2: 0x607c994845ba - std::sys::backtrace::_print_fmt::ha179fab1a0be4c59 + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/sys/backtrace.rs:66:9 + 3: 0x607c994845ba - ::fmt::hf209b603f512c5df + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/sys/backtrace.rs:39:26 + 4: 0x607c994ae4b3 - core::fmt::rt::Argument::fmt::h04f1d73255100c6c + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/core/src/fmt/rt.rs:177:76 + 5: 0x607c994ae4b3 - core::fmt::write::hb7459499d17d36c1 + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/core/src/fmt/mod.rs:1189:21 + 6: 0x607c99480003 - std::io::Write::write_fmt::h4275802de0932d6f + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/io/mod.rs:1884:15 + 7: 0x607c99484402 - std::sys::backtrace::BacktraceLock::print::hfbfa2f755b02b3d5 + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/sys/backtrace.rs:42:9 + 8: 0x607c9948557c - std::panicking::default_hook::{{closure}}::h807768543f95a41b + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:268:22 + 9: 0x607c994853c2 - std::panicking::default_hook::h7a17744703ed785c + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:295:9 + 10: 0x607c99485bb7 - std::panicking::rust_panic_with_hook::h4fba84c8b130fcc8 + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:801:13 + 11: 0x607c99485a4a - std::panicking::begin_panic_handler::{{closure}}::h9a05dc892413e069 + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:674:13 + 12: 0x607c99484a99 - std::sys::backtrace::__rust_end_short_backtrace::hb562433a6e41eea6 + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/sys/backtrace.rs:170:18 + 13: 0x607c994856dc - rust_begin_unwind + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:665:5 + 14: 0x607c994ac660 - core::panicking::panic_fmt::hb2b4d3a454bfbc1d + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/core/src/panicking.rs:76:14 + 15: 0x607c994ac7e6 - core::panicking::panic_display::h1590d2675ff6c7bf + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/core/src/panicking.rs:269:5 + 16: 0x607c994ac7e6 - core::panicking::panic_explicit::h703879b59c53c7df + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/core/src/panicking.rs:240:5 + 17: 0x607c9930378a - hblang::son::Nodes::check_loop_depth_integrity::panic_cold_explicit::h6e60a5356c746729 + at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic.rs:88:13 + 18: 0x607c992de896 - hblang::son::Nodes::check_loop_depth_integrity::had2b0c27d2c39985 + at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/son.rs:1761:13 + 19: 0x607c992fc774 - hblang::son::Codegen::finalize::h13f123c7cd0da7a9 + at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/son.rs:4730:13 + 20: 0x607c992fc155 - hblang::son::Codegen::emit_func::h15c8dc591b00f53d + at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/son.rs:4663:12 + 21: 0x607c992fb4f0 - hblang::son::Codegen::complete_call_graph::h8657dc9690902fa0 + at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/son.rs:4584:13 + 22: 0x607c992e2e76 - hblang::son::Codegen::generate::h1b2054aee9ce9790 + at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/son.rs:2496:9 + 23: 0x607c993a5ec8 - hblang::fs::run_compiler::h5f6a41b732f9e970 + at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/fs.rs:110:9 + 24: 0x607c98ea4e6d - repbuild::dev::Package::build::hdae17d117d475784 + at /home/b0c1/peo-able/repbuild/src/dev.rs:99:13 + 25: 0x607c98ecb684 - repbuild::get_fs::{{closure}}::h632dfb970319db7a + at /home/b0c1/peo-able/repbuild/src/main.rs:225:27 + 26: 0x607c98ed46c8 - core::iter::adapters::map::map_fold::{{closure}}::ha6a4808f4323eba7 + at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/adapters/map.rs:88:28 + 27: 0x607c98e928c8 - core::iter::traits::iterator::Iterator::fold::h1aebe574af7a3edc + at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:2546:21 + 28: 0x607c98ed3e6a - as core::iter::traits::iterator::Iterator>::fold::h5f00813cbd913ca4 + at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/adapters/map.rs:128:9 + 29: 0x607c98ed4476 - core::iter::traits::iterator::Iterator::for_each::h50c08b7e4fd54442 + at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:800:9 + 30: 0x607c98edeec2 - repbuild::get_fs::hf28ffbf58ae795af + at /home/b0c1/peo-able/repbuild/src/main.rs:211:9 + 31: 0x607c98edf79c - repbuild::build::hce2c223cc2728d29 + at /home/b0c1/peo-able/repbuild/src/main.rs:314:14 + 32: 0x607c98edb62a - repbuild::main::hb96a470eed1f6457 + at /home/b0c1/peo-able/repbuild/src/main.rs:71:13 + 33: 0x607c98e8de2b - core::ops::function::FnOnce::call_once::h378a33339d4a24f0 + at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5 + 34: 0x607c98ed3ddd - std::sys::backtrace::__rust_begin_short_backtrace::hdd497f77b8d07378 + at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:154:18 + 35: 0x607c98ebf9a1 - std::rt::lang_start::{{closure}}::hae9e3782edfc8e36 + at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:195:18 + 36: 0x607c99479b47 - core::ops::function::impls:: for &F>::call_once::hebb10914f9a99bfc + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/core/src/ops/function.rs:284:13 + 37: 0x607c99479b47 - std::panicking::try::do_call::he587bea39635f003 + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:557:40 + 38: 0x607c99479b47 - std::panicking::try::h066d0ac22ca08454 + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:520:19 + 39: 0x607c99479b47 - std::panic::catch_unwind::hc9ca199833b3a11d + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panic.rs:358:14 + 40: 0x607c99479b47 - std::rt::lang_start_internal::{{closure}}::hadaa4544f6d8e710 + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/rt.rs:174:48 + 41: 0x607c99479b47 - std::panicking::try::do_call::h53342b4fc8ceaf09 + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:557:40 + 42: 0x607c99479b47 - std::panicking::try::h51410bd76f769cad + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:520:19 + 43: 0x607c99479b47 - std::panic::catch_unwind::h1b027fc305be26d2 + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panic.rs:358:14 + 44: 0x607c99479b47 - std::rt::lang_start_internal::h4f9aa9060ab8cedd + at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/rt.rs:174:20 + 45: 0x607c98ebf97a - std::rt::lang_start::h0aff8b9ad9d9f551 + at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:194:17 + 46: 0x607c98ee23ae - main + 47: 0x7b317e02a1ca - __libc_start_call_main + at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16 + 48: 0x7b317e02a28b - __libc_start_main_impl + at ./csu/../csu/libc-start.c:360:3 + 49: 0x607c98e89025 - _start + 50: 0x0 - +sysdata/programs/ps2_driver/src/main.hb:13:17: panic occured here +send_command := fn(port: ^controller.Port, byte: u8): void { \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index a43a396..d2289c5 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -11,7 +11,8 @@ keyboard_buffer := 0 info := controller.Info.(0) send_command := fn(port: ^controller.Port, byte: u8): void { - loop { + tries := 3 + loop if tries == 0 break else { controller.send_byte(port, byte) loop { info = controller.get_info() @@ -32,6 +33,7 @@ send_command := fn(port: ^controller.Port, byte: u8): void { break } } + tries -= 1 } } -- 2.44.1 From 96c07e137bdd3cfd7e9d558160695f71189d4eae Mon Sep 17 00:00:00 2001 From: peony Date: Mon, 18 Nov 2024 20:47:46 +0100 Subject: [PATCH 22/23] Removed `error.error` because its in #aos-geeral. --- sysdata/programs/ps2_driver/error.error | 122 ------------------------ 1 file changed, 122 deletions(-) delete mode 100644 sysdata/programs/ps2_driver/error.error diff --git a/sysdata/programs/ps2_driver/error.error b/sysdata/programs/ps2_driver/error.error deleted file mode 100644 index 0d74b66..0000000 --- a/sysdata/programs/ps2_driver/error.error +++ /dev/null @@ -1,122 +0,0 @@ -2 1 48 Node { kind: Then, inputs: [47], outputs: [90], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 10 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -2 1 88 Node { kind: Region, inputs: [70, 87], outputs: [89, 90], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 18 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -2 1 87 Node { kind: Else, inputs: [69], outputs: [88], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 17 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -2 1 69 Node { kind: If, inputs: [64, 68], outputs: [70, 87], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 16 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -2 1 64 Node { kind: Call { func: Func(18), args: Tuple(193) }, inputs: [63, 5, 39, 40], outputs: [69, 66, 68, 66], peep_triggers: [], clobbers: [0, 1], ty: Id(7), pos: 0, depth: Cell { value: 15 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -2 1 63 Node { kind: Then, inputs: [62], outputs: [64], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 14 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -2 1 70 Node { kind: Then, inputs: [69], outputs: [88, 86, 82, 81, 80, 76, 85, 75, 74, 84, 71, 73], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 17 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -3 1 48 Node { kind: Then, inputs: [47], outputs: [90], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 10 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -3 1 88 Node { kind: Region, inputs: [70, 87], outputs: [89, 90], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 18 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -3 1 87 Node { kind: Else, inputs: [69], outputs: [88], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 17 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -3 1 69 Node { kind: If, inputs: [64, 68], outputs: [70, 87], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 16 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -3 1 64 Node { kind: Call { func: Func(18), args: Tuple(193) }, inputs: [63, 5, 39, 40], outputs: [69, 66, 68, 66], peep_triggers: [], clobbers: [0, 1], ty: Id(7), pos: 0, depth: Cell { value: 15 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -3 1 63 Node { kind: Then, inputs: [62], outputs: [64], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 14 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -3 2 62 Node { kind: If, inputs: [59, 61], outputs: [63, 92], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 13 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 2 }, aclass: 0 } -3 2 59 Node { kind: Call { func: Func(17), args: Tuple(417) }, inputs: [57, 58, 40], outputs: [62, 61, 61], peep_triggers: [82], clobbers: [1], ty: Id(805306369), pos: 0, depth: Cell { value: 12 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 2 }, aclass: 0 } -3 2 57 Node { kind: Call { func: Func(4294967295), args: Tuple(292) }, inputs: [49, 7, 7, 51, 33, 40, 56], outputs: [59, 82, 94, 58], peep_triggers: [], clobbers: [1, 3], ty: Id(8), pos: 0, depth: Cell { value: 11 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 2 }, aclass: 0 } -3 2 49 Node { kind: Else, inputs: [47], outputs: [57], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 10 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 2 }, aclass: 0 } -3 1 70 Node { kind: Then, inputs: [69], outputs: [88, 86, 82, 81, 80, 76, 85, 75, 74, 84, 71, 73], peep_triggers: [], clobbers: [], ty: Id(5), pos: 0, depth: Cell { value: 17 }, lock_rc: Cell { value: 0 }, loop_depth: Cell { value: 1 }, aclass: 0 } -thread 'main' panicked at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/son.rs:1761:13: -explicit panic -stack backtrace: - 0: 0x607c994845ba - std::backtrace_rs::backtrace::libunwind::trace::h504b0125eda6b384 - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5 - 1: 0x607c994845ba - std::backtrace_rs::backtrace::trace_unsynchronized::hc81f5dfa1a7e52fe - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 - 2: 0x607c994845ba - std::sys::backtrace::_print_fmt::ha179fab1a0be4c59 - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/sys/backtrace.rs:66:9 - 3: 0x607c994845ba - ::fmt::hf209b603f512c5df - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/sys/backtrace.rs:39:26 - 4: 0x607c994ae4b3 - core::fmt::rt::Argument::fmt::h04f1d73255100c6c - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/core/src/fmt/rt.rs:177:76 - 5: 0x607c994ae4b3 - core::fmt::write::hb7459499d17d36c1 - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/core/src/fmt/mod.rs:1189:21 - 6: 0x607c99480003 - std::io::Write::write_fmt::h4275802de0932d6f - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/io/mod.rs:1884:15 - 7: 0x607c99484402 - std::sys::backtrace::BacktraceLock::print::hfbfa2f755b02b3d5 - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/sys/backtrace.rs:42:9 - 8: 0x607c9948557c - std::panicking::default_hook::{{closure}}::h807768543f95a41b - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:268:22 - 9: 0x607c994853c2 - std::panicking::default_hook::h7a17744703ed785c - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:295:9 - 10: 0x607c99485bb7 - std::panicking::rust_panic_with_hook::h4fba84c8b130fcc8 - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:801:13 - 11: 0x607c99485a4a - std::panicking::begin_panic_handler::{{closure}}::h9a05dc892413e069 - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:674:13 - 12: 0x607c99484a99 - std::sys::backtrace::__rust_end_short_backtrace::hb562433a6e41eea6 - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/sys/backtrace.rs:170:18 - 13: 0x607c994856dc - rust_begin_unwind - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:665:5 - 14: 0x607c994ac660 - core::panicking::panic_fmt::hb2b4d3a454bfbc1d - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/core/src/panicking.rs:76:14 - 15: 0x607c994ac7e6 - core::panicking::panic_display::h1590d2675ff6c7bf - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/core/src/panicking.rs:269:5 - 16: 0x607c994ac7e6 - core::panicking::panic_explicit::h703879b59c53c7df - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/core/src/panicking.rs:240:5 - 17: 0x607c9930378a - hblang::son::Nodes::check_loop_depth_integrity::panic_cold_explicit::h6e60a5356c746729 - at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic.rs:88:13 - 18: 0x607c992de896 - hblang::son::Nodes::check_loop_depth_integrity::had2b0c27d2c39985 - at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/son.rs:1761:13 - 19: 0x607c992fc774 - hblang::son::Codegen::finalize::h13f123c7cd0da7a9 - at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/son.rs:4730:13 - 20: 0x607c992fc155 - hblang::son::Codegen::emit_func::h15c8dc591b00f53d - at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/son.rs:4663:12 - 21: 0x607c992fb4f0 - hblang::son::Codegen::complete_call_graph::h8657dc9690902fa0 - at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/son.rs:4584:13 - 22: 0x607c992e2e76 - hblang::son::Codegen::generate::h1b2054aee9ce9790 - at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/son.rs:2496:9 - 23: 0x607c993a5ec8 - hblang::fs::run_compiler::h5f6a41b732f9e970 - at /home/b0c1/.cargo/git/checkouts/holey-bytes-7306cae1e59cf4dd/37dd13c/lang/src/fs.rs:110:9 - 24: 0x607c98ea4e6d - repbuild::dev::Package::build::hdae17d117d475784 - at /home/b0c1/peo-able/repbuild/src/dev.rs:99:13 - 25: 0x607c98ecb684 - repbuild::get_fs::{{closure}}::h632dfb970319db7a - at /home/b0c1/peo-able/repbuild/src/main.rs:225:27 - 26: 0x607c98ed46c8 - core::iter::adapters::map::map_fold::{{closure}}::ha6a4808f4323eba7 - at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/adapters/map.rs:88:28 - 27: 0x607c98e928c8 - core::iter::traits::iterator::Iterator::fold::h1aebe574af7a3edc - at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:2546:21 - 28: 0x607c98ed3e6a - as core::iter::traits::iterator::Iterator>::fold::h5f00813cbd913ca4 - at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/adapters/map.rs:128:9 - 29: 0x607c98ed4476 - core::iter::traits::iterator::Iterator::for_each::h50c08b7e4fd54442 - at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:800:9 - 30: 0x607c98edeec2 - repbuild::get_fs::hf28ffbf58ae795af - at /home/b0c1/peo-able/repbuild/src/main.rs:211:9 - 31: 0x607c98edf79c - repbuild::build::hce2c223cc2728d29 - at /home/b0c1/peo-able/repbuild/src/main.rs:314:14 - 32: 0x607c98edb62a - repbuild::main::hb96a470eed1f6457 - at /home/b0c1/peo-able/repbuild/src/main.rs:71:13 - 33: 0x607c98e8de2b - core::ops::function::FnOnce::call_once::h378a33339d4a24f0 - at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5 - 34: 0x607c98ed3ddd - std::sys::backtrace::__rust_begin_short_backtrace::hdd497f77b8d07378 - at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:154:18 - 35: 0x607c98ebf9a1 - std::rt::lang_start::{{closure}}::hae9e3782edfc8e36 - at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:195:18 - 36: 0x607c99479b47 - core::ops::function::impls:: for &F>::call_once::hebb10914f9a99bfc - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/core/src/ops/function.rs:284:13 - 37: 0x607c99479b47 - std::panicking::try::do_call::he587bea39635f003 - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:557:40 - 38: 0x607c99479b47 - std::panicking::try::h066d0ac22ca08454 - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:520:19 - 39: 0x607c99479b47 - std::panic::catch_unwind::hc9ca199833b3a11d - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panic.rs:358:14 - 40: 0x607c99479b47 - std::rt::lang_start_internal::{{closure}}::hadaa4544f6d8e710 - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/rt.rs:174:48 - 41: 0x607c99479b47 - std::panicking::try::do_call::h53342b4fc8ceaf09 - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:557:40 - 42: 0x607c99479b47 - std::panicking::try::h51410bd76f769cad - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panicking.rs:520:19 - 43: 0x607c99479b47 - std::panic::catch_unwind::h1b027fc305be26d2 - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/panic.rs:358:14 - 44: 0x607c99479b47 - std::rt::lang_start_internal::h4f9aa9060ab8cedd - at /rustc/917a50a03931a9861c19a46f3e2a02a28f1da936/library/std/src/rt.rs:174:20 - 45: 0x607c98ebf97a - std::rt::lang_start::h0aff8b9ad9d9f551 - at /home/b0c1/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:194:17 - 46: 0x607c98ee23ae - main - 47: 0x7b317e02a1ca - __libc_start_call_main - at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16 - 48: 0x7b317e02a28b - __libc_start_main_impl - at ./csu/../csu/libc-start.c:360:3 - 49: 0x607c98e89025 - _start - 50: 0x0 - -sysdata/programs/ps2_driver/src/main.hb:13:17: panic occured here -send_command := fn(port: ^controller.Port, byte: u8): void { \ No newline at end of file -- 2.44.1 From f7f9fece4f8ae764b7d9f24d232280b81da2526a Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 24 Nov 2024 13:31:57 +0100 Subject: [PATCH 23/23] Merged once more --- Cargo.lock | 50 ++++++++++++------------- sysdata/programs/ps2_driver/src/main.hb | 26 ++++++++----- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f07974..838bfd4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#37dd13cab295aa9e74d704b3345685b4428d149a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#9dfb2eb606e9049bc5d372e674a75e0be2c57ff0" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#37dd13cab295aa9e74d704b3345685b4428d149a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#9dfb2eb606e9049bc5d372e674a75e0be2c57ff0" dependencies = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#37dd13cab295aa9e74d704b3345685b4428d149a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#9dfb2eb606e9049bc5d372e674a75e0be2c57ff0" dependencies = [ "hbbytecode", ] @@ -424,9 +424,9 @@ checksum = "02034f8f6b3e7bf050f310fbaf6db0018b8e54b75598d0a4c97172054752fede" [[package]] name = "litemap" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" [[package]] name = "lock_api" @@ -503,9 +503,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "proc-macro2" -version = "1.0.89" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -584,9 +584,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.17" +version = "0.23.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f1a745511c54ba6d4465e8d5dfbd81b45791756de28d4981af70d6dca128f1e" +checksum = "9c9cc1d47e243d655ace55ed38201c19ae02c148ae56412ab8750e8f0166ab7f" dependencies = [ "log", "once_cell", @@ -717,9 +717,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.87" +version = "2.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" dependencies = [ "proc-macro2", "quote", @@ -800,9 +800,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "unicode-xid" @@ -833,9 +833,9 @@ dependencies = [ [[package]] name = "url" -version = "2.5.3" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ "form_urlencoded", "idna", @@ -876,9 +876,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "webpki-roots" -version = "0.26.6" +version = "0.26.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +checksum = "5d642ff16b7e79272ae451b7322067cdc17cadf68c23264be9d94a32319efe7e" dependencies = [ "rustls-pki-types", ] @@ -1035,9 +1035,9 @@ dependencies = [ [[package]] name = "yoke" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" dependencies = [ "serde", "stable_deref_trait", @@ -1047,9 +1047,9 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", @@ -1059,18 +1059,18 @@ dependencies = [ [[package]] name = "zerofrom" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" dependencies = [ "zerofrom-derive", ] [[package]] name = "zerofrom-derive" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_driver/src/main.hb index d2289c5..edca6d4 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_driver/src/main.hb @@ -2,15 +2,16 @@ .{MouseEvent} := @use("../../../libraries/intouch/src/lib.hb").events; .{bit0, bit1, bit2, bit3, bit4} := @use("bits.hb") devices := @use("devices.hb") -controller := @use("controller.hb") +controller := @use("controller.hb"); +.{Info, Port} := controller mouse := @use("mouse.hb") format_page := memory.dangling(u8) mouse_buffer := 0 keyboard_buffer := 0 -info := controller.Info.(0) +info := Info.(0) -send_command := fn(port: ^controller.Port, byte: u8): void { +send_command := fn(port: ^Port, byte: u8): void { tries := 3 loop if tries == 0 break else { controller.send_byte(port, byte) @@ -37,6 +38,10 @@ send_command := fn(port: ^controller.Port, byte: u8): void { } } +enable_streaming := fn(port: ^Port): void { + @inline(send_command, port, 0xF4) +} + process := fn(port: ^controller.Port): void { if port.device.value < devices.MOUSE_5_BUTTON.value { event := MouseEvent.(0, 0, false, false, false) @@ -52,7 +57,7 @@ process := fn(port: ^controller.Port): void { } else if port.device == devices.MOUSE_INIT_1 { port.device.value = port.packet[0] if port.device != devices.MOUSE_SCROLLWHEEL { - controller.send_byte(port, 0xF4) + enable_streaming(port) return } port.device = devices.MOUSE_INIT_2 @@ -61,9 +66,11 @@ process := fn(port: ^controller.Port): void { } else if port.device == devices.NO_DEVICE { if port.packet_length == 1 { port.device.value = port.packet[0] + enable_streaming(port) + //TODO: Upgrade mouse. } else { port.device.value = port.packet[1] | port.packet[0] << 8 - send_command(port, 0xF4) + enable_streaming(port) } log.info("Identified device!\0") log.info(string.display_int(port.device.value, format_page, 16)) @@ -107,10 +114,11 @@ main := fn(): void { controller.init() if controller.port1.exists { - controller.send_byte(&controller.port1, 0xF4) + //log.info("Port 1 exists.\0") + controller.send_byte(@bitcast(0), 0xF4) } if controller.port2.exists { - controller.send_byte(&controller.port2, 0xF4) + //controller.send_byte(&controller.port2, 0xF4) } loop { @@ -122,7 +130,7 @@ main := fn(): void { if controller.check_parity(info) { log.error("Parity error! Cannot handle these!\0") } - + /* if controller.has_input(info) { port := controller.get_port(info) if port.packet_length > 0 & check_complete(port) { @@ -139,6 +147,6 @@ main := fn(): void { process(port) port.packet_length = 0 } - } + }*/ } } \ No newline at end of file -- 2.44.1