From f59776e7929db9c43da559171eb1058c5a464dae Mon Sep 17 00:00:00 2001 From: Sam Buckley Date: Tue, 16 Jul 2024 22:42:49 +0100 Subject: [PATCH 1/3] Update string lib for num format - Trees --- kernel/src/holeybytes/ecah.rs | 4 +- sysdata/libraries/stn/src/string.hb | 46 ++++++++++++++++- sysdata/limine.cfg | 2 +- sysdata/programs/time_driver/meta.toml | 11 ++++ sysdata/programs/time_driver/src/main.hb | 64 ++++++++++++++++++++++++ sysdata/system_config.toml | 7 ++- 6 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 sysdata/programs/time_driver/meta.toml create mode 100644 sysdata/programs/time_driver/src/main.hb diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index fbf0f103a..846957b7a 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -177,7 +177,9 @@ pub fn handler(vm: &mut Vm) { unsafe fn x86_out(address: u16, value: u32) { x86_64::instructions::port::Port::new(address).write(value); } - vm.registers[3] = hbvm::value::Value(unsafe { x86_in(r2 as u16) } as u64); + let x = hbvm::value::Value(unsafe { x86_in(r2 as u16) } as u64); + info!("Read {:?} from Port {:?}", x, r2); + vm.registers[3] = x } } // 5 diff --git a/sysdata/libraries/stn/src/string.hb b/sysdata/libraries/stn/src/string.hb index 3ee31a618..ab4e5fe31 100644 --- a/sysdata/libraries/stn/src/string.hb +++ b/sysdata/libraries/stn/src/string.hb @@ -5,4 +5,48 @@ length := fn(ptr: ^u8): int { ptr += 1; } return len; -} \ No newline at end of file +} + +display_int := fn(num: int): ^u8 { + p := page; + i := 0; + if num == 0 { + set(p, 48); + return p; + } + loop { + if num == 0 break; + set(p + i, num % 10 + 48); + num /= 10; + i += 1; + } + reverse(p); + //null terminate + set(p + i, 0); + return p; +} + +reverse := fn(s: ^u8): void { + //reverse a string, don't remove digits + len := 0; + loop { + if *(s + len) == 0 break; + len += 1; + } + i := 0; + j := len - 1; + loop { + if i >= j break; + temp := *(s + i); + *(s + i) = *(s + j); + *(s + j) = temp; + i += 1; + j -= 1; + } + return; +} + +set := fn(change: ^int, new: int): void { + *(change) = new; + return; +} diff --git a/sysdata/limine.cfg b/sysdata/limine.cfg index 14ad16eae..18ec894c9 100644 --- a/sysdata/limine.cfg +++ b/sysdata/limine.cfg @@ -37,4 +37,4 @@ TERM_BACKDROP=008080 MODULE_CMDLINE="height=10 width=10 arch=${ARCH}" MODULE_PATH=boot:///serial_driver.hbf - MODULE_CMDLINE="arch=${ARCH}" \ No newline at end of file + MODULE_CMDLINE="arch=${ARCH}" diff --git a/sysdata/programs/time_driver/meta.toml b/sysdata/programs/time_driver/meta.toml new file mode 100644 index 000000000..84cc97e6e --- /dev/null +++ b/sysdata/programs/time_driver/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "time_driver" +authors = ["SamBuckley"] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/time_driver/src/main.hb b/sysdata/programs/time_driver/src/main.hb new file mode 100644 index 000000000..78a24960f --- /dev/null +++ b/sysdata/programs/time_driver/src/main.hb @@ -0,0 +1,64 @@ +stn := @use("../../../libraries/stn/src/lib.hb"); +log := stn.log; +mem := stn.memory; +page := 0 + +main := fn(): void { + page += mem.request_page(1); + port_str := "\0\{46}\0"; + a := @eca(u8, 3, 3, port_str, 2); + log.debug(&a); + n := 5000000; + loop { + if n == 0 break; + n -= 1; + stack_reclamation_edge_case := 0; + } + td := display_int(100); + log.debug(td); + return; +} + +display_int := fn(num: int): ^u8 { + p := page; + i := 0; + if num == 0 { + set(p, 48); + return p; + } + loop { + if num == 0 break; + set(p + i, num % 10 + 48); + num /= 10; + i += 1; + } + reverse(p); + //null terminate + set(p + i, 0); + return p; +} + +reverse := fn(s: ^u8): void { + //reverse a string, don't remove digits + len := 0; + loop { + if *(s + len) == 0 break; + len += 1; + } + i := 0; + j := len - 1; + loop { + if i >= j break; + temp := *(s + i); + *(s + i) = *(s + j); + *(s + j) = temp; + i += 1; + j -= 1; + } + return; +} + +set := fn(change: ^int, new: int): void { + *(change) = new; + return; +} diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 553cc875d..d7975bf62 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -24,5 +24,8 @@ path = "boot:///tests.hbf" # [boot.limine.ableos.modules.diskio_driver] # path = "boot:///diskio_driver.hbf" -[boot.limine.ableos.modules.fb_driver] -path = "boot:///fb_driver.hbf" +# [boot.limine.ableos.modules.fb_driver] +# path = "boot:///fb_driver.hbf" + +[boot.limine.ableos.modules.time_driver] +path = "boot:///time_driver.hbf" \ No newline at end of file From 9f9c7af85faf0a4bc031b9cc5acfe83a7575e9d7 Mon Sep 17 00:00:00 2001 From: Sam Buckley Date: Wed, 17 Jul 2024 01:24:24 +0100 Subject: [PATCH 2/3] Add string stuff to library --- sysdata/libraries/stn/src/string.hb | 3 +- sysdata/programs/time_driver/src/main.hb | 51 ++---------------------- 2 files changed, 5 insertions(+), 49 deletions(-) diff --git a/sysdata/libraries/stn/src/string.hb b/sysdata/libraries/stn/src/string.hb index ab4e5fe31..8abed2427 100644 --- a/sysdata/libraries/stn/src/string.hb +++ b/sysdata/libraries/stn/src/string.hb @@ -7,8 +7,7 @@ length := fn(ptr: ^u8): int { return len; } -display_int := fn(num: int): ^u8 { - p := page; +display_int := fn(num: int, p: ^u8): ^u8 { i := 0; if num == 0 { set(p, 48); diff --git a/sysdata/programs/time_driver/src/main.hb b/sysdata/programs/time_driver/src/main.hb index 78a24960f..91d2d7e43 100644 --- a/sysdata/programs/time_driver/src/main.hb +++ b/sysdata/programs/time_driver/src/main.hb @@ -1,64 +1,21 @@ stn := @use("../../../libraries/stn/src/lib.hb"); log := stn.log; mem := stn.memory; +s := stn.string; page := 0 main := fn(): void { page += mem.request_page(1); - port_str := "\0\{46}\0"; + port_str := "\0\{47}\0"; a := @eca(u8, 3, 3, port_str, 2); - log.debug(&a); + n := 5000000; loop { if n == 0 break; n -= 1; stack_reclamation_edge_case := 0; } - td := display_int(100); + td := s.display_int(a, page); log.debug(td); return; } - -display_int := fn(num: int): ^u8 { - p := page; - i := 0; - if num == 0 { - set(p, 48); - return p; - } - loop { - if num == 0 break; - set(p + i, num % 10 + 48); - num /= 10; - i += 1; - } - reverse(p); - //null terminate - set(p + i, 0); - return p; -} - -reverse := fn(s: ^u8): void { - //reverse a string, don't remove digits - len := 0; - loop { - if *(s + len) == 0 break; - len += 1; - } - i := 0; - j := len - 1; - loop { - if i >= j break; - temp := *(s + i); - *(s + i) = *(s + j); - *(s + j) = temp; - i += 1; - j -= 1; - } - return; -} - -set := fn(change: ^int, new: int): void { - *(change) = new; - return; -} From 314523fce7e7b3b6d2e77b0237827c9e1e0e0f70 Mon Sep 17 00:00:00 2001 From: Sam Buckley Date: Wed, 17 Jul 2024 01:28:04 +0100 Subject: [PATCH 3/3] Reenable fb driver --- sysdata/system_config.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index d7975bf62..a7060f8d3 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -24,8 +24,8 @@ path = "boot:///tests.hbf" # [boot.limine.ableos.modules.diskio_driver] # path = "boot:///diskio_driver.hbf" -# [boot.limine.ableos.modules.fb_driver] -# path = "boot:///fb_driver.hbf" +[boot.limine.ableos.modules.fb_driver] +path = "boot:///fb_driver.hbf" [boot.limine.ableos.modules.time_driver] path = "boot:///time_driver.hbf" \ No newline at end of file