From 7a256dde681d941b287b26b02a8322f14cf24701 Mon Sep 17 00:00:00 2001
From: Able <abl3theabove@gmail.com>
Date: Tue, 17 Sep 2024 12:08:19 -0500
Subject: [PATCH] single file change

---
 Cargo.lock                                 |  6 +--
 sysdata/libraries/pci/src/lib.hb           | 53 +++++++++++++++++++++-
 sysdata/libraries/stn/src/acs.hb           |  6 +++
 sysdata/libraries/stn/src/file_io.hb       | 14 +++---
 sysdata/libraries/stn/src/lib.hb           |  1 -
 sysdata/libraries/stn/src/log.hb           |  4 +-
 sysdata/libraries/stn/src/memory.hb        |  6 +--
 sysdata/libraries/stn/src/pci.hb           | 50 --------------------
 sysdata/programs/svga_driver/src/device.hb | 10 ++--
 sysdata/programs/svga_driver/src/main.hb   |  5 +-
 sysdata/system_config.toml                 |  8 ++--
 11 files changed, 85 insertions(+), 78 deletions(-)
 delete mode 100644 sysdata/libraries/stn/src/pci.hb

diff --git a/Cargo.lock b/Cargo.lock
index 38975d1..62cf4a1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -390,7 +390,7 @@ dependencies = [
 [[package]]
 name = "hbbytecode"
 version = "0.1.0"
-source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4a9b9de87fd56a6bbd5d0ca2c622104d4807612b"
+source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#ece9bb8bf21507b5d2a7c870f55aa2e9c5ab9f26"
 
 [[package]]
 name = "hbbytecode"
@@ -400,7 +400,7 @@ source = "git+https://git.ablecorp.us/ableos/holey-bytes.git#4a9b9de87fd56a6bbd5
 [[package]]
 name = "hblang"
 version = "0.1.0"
-source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4a9b9de87fd56a6bbd5d0ca2c622104d4807612b"
+source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#ece9bb8bf21507b5d2a7c870f55aa2e9c5ab9f26"
 dependencies = [
  "hbvm 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)",
 ]
@@ -408,7 +408,7 @@ dependencies = [
 [[package]]
 name = "hbvm"
 version = "0.1.0"
-source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4a9b9de87fd56a6bbd5d0ca2c622104d4807612b"
+source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#ece9bb8bf21507b5d2a7c870f55aa2e9c5ab9f26"
 dependencies = [
  "hbbytecode 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)",
 ]
diff --git a/sysdata/libraries/pci/src/lib.hb b/sysdata/libraries/pci/src/lib.hb
index 431f082..7788ec6 100644
--- a/sysdata/libraries/pci/src/lib.hb
+++ b/sysdata/libraries/pci/src/lib.hb
@@ -7,8 +7,57 @@ PCIAddress := struct {
 	function: u8,
 }
 
-find_device := fn(vendor_id: int, device_id: int, pci_address: PCIAddress): int {
-	return 1
+PCI_ID := struct {
+	vendor: u16,
+	device: u16,
+}
+
+get_ids := fn(bus: u8, device: u8, function: u8): PCI_ID {
+	res := config_read32(bus, device, function, 0)
+	dev_id := res >> 16
+	dev_id &= 0xFFFF
+
+	vnd_id := res & 0xFFFF
+	return PCI_ID.(dev_id, vnd_id)
+}
+
+PciDeviceInfo := struct {
+	pci_id: PCI_ID,
+}
+
+calculate_address := fn(bus: u8, device: u8, function: u8, offset: u8): int {
+	address := bus << 16
+	address |= device << 11
+	address |= function << 8
+	address |= offset & 0xFC
+	address |= 0x80000000
+	return address
+}
+
+check_device := fn(bus: u8, device: u8): PciDeviceInfo {
+	pci_id := get_ids(bus, device, 0)
+
+	if pci_id.vendor == 0xFFFF {
+		stn.log.warn(":|\0")
+	} else {
+		stn.log.info(":)\0")
+	}
+
+	address := calculate_address(bus, device, 0, 0x8)
+	reg2 := config_read32(bus, device, 0, 0x8)
+	class := reg2 >> 16 & 0xFFFF
+	b := "\0\0\0\0\0\0\0"
+
+	string.display_int(class, b)
+	stn.log.info(b)
+
+	return PciDeviceInfo.(pci_id)
+}
+
+find_device := fn(vendor_id: int, device_id: int, pci_address: PCIAddress): PCI_ID {
+	pci_id := get_ids(0, 2, 0)
+
+	return pci_id
 }
 
 scan_bus := fn(): void {
diff --git a/sysdata/libraries/stn/src/acs.hb b/sysdata/libraries/stn/src/acs.hb
index 2f4ac8e..5f2a250 100644
--- a/sysdata/libraries/stn/src/acs.hb
+++ b/sysdata/libraries/stn/src/acs.hb
@@ -1,6 +1,12 @@
 //! This is a reserved file for use with the AbleOS Clustering System
 
 HostID := int
+
+FileID := struct {
+	host_id: HostID,
+	id: int,
+}
+
 // A DeviceID points to a specific device in the ACS.
 DeviceID := struct {
 	host_id: HostID,
diff --git a/sysdata/libraries/stn/src/file_io.hb b/sysdata/libraries/stn/src/file_io.hb
index 68ad9a1..d4054dd 100644
--- a/sysdata/libraries/stn/src/file_io.hb
+++ b/sysdata/libraries/stn/src/file_io.hb
@@ -1,13 +1,13 @@
-acs := @use("rel:acs.hb")
+acs := @use("rel:acs.hb");
+.{DiskID, FileID} := acs
 
 // Paths without a node-disk component are to be treated as local files.
 // file_path := "DID:/test\0";
-Path := struct {// DiskID holds the host id 
-disk_id: acs.DiskID, length: u8, data: ^u8}
-
-FileID := struct {
-	host_id: int,
-	id: int,
+Path := struct {
+	// DiskID holds the host id 
+	disk_id: DiskID,
+	length: u8,
+	data: ^u8,
 }
 
 open := fn(file_path: Path): FileID {
diff --git a/sysdata/libraries/stn/src/lib.hb b/sysdata/libraries/stn/src/lib.hb
index 5babcf7..d26ee80 100644
--- a/sysdata/libraries/stn/src/lib.hb
+++ b/sysdata/libraries/stn/src/lib.hb
@@ -6,5 +6,4 @@ memory := @use("rel:memory.hb")
 buffer := @use("rel:buffer.hb")
 math := @use("rel:math.hb")
 random := @use("rel:random.hb")
-pci := @use("rel:pci.hb")
 file := @use("rel:file_io.hb")
\ No newline at end of file
diff --git a/sysdata/libraries/stn/src/log.hb b/sysdata/libraries/stn/src/log.hb
index d643d76..bcd5f3e 100644
--- a/sysdata/libraries/stn/src/log.hb
+++ b/sysdata/libraries/stn/src/log.hb
@@ -4,8 +4,8 @@ buffer := @use("rel:buffer.hb")
 log := fn(message: ^u8, level: u8): void {
 	message_length := @inline(string.length, message);
 	*(message + message_length) = level
-	@eca(i32, 3, 1, message, message_length + 1)
-	return
+
+	return @eca(3, 1, message, message_length + 1)
 }
 
 error := fn(message: ^u8): void return log(message, 0)
diff --git a/sysdata/libraries/stn/src/memory.hb b/sysdata/libraries/stn/src/memory.hb
index 4feafa0..39d9468 100644
--- a/sysdata/libraries/stn/src/memory.hb
+++ b/sysdata/libraries/stn/src/memory.hb
@@ -23,7 +23,7 @@ OutlMsg := struct {a: u8, b: u8, addr: u16, value: u32}
 InlMsg := struct {a: u8, b: u8, addr: u16}
 
 outb := fn(addr: u16, value: u8): void {
-	return @eca(void, 3, 3, &OutbMsg.(1, 0, addr, value), @sizeof(OutbMsg))
+	return @eca(3, 3, &OutbMsg.(1, 0, addr, value), @sizeof(OutbMsg))
 }
 
 inb := fn(addr: u16): u8 {
@@ -31,9 +31,9 @@ inb := fn(addr: u16): u8 {
 }
 
 outl := fn(addr: u16, value: u32): void {
-	return @eca(void, 3, 3, &OutlMsg.(1, 2, addr, value), @sizeof(OutlMsg))
+	return @eca(3, 3, &OutlMsg.(1, 2, addr, value), @sizeof(OutlMsg))
 }
 
 inl := fn(addr: u16): u32 {
-	return @eca(u32, 3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg))
+	return @eca(3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg))
 }
\ No newline at end of file
diff --git a/sysdata/libraries/stn/src/pci.hb b/sysdata/libraries/stn/src/pci.hb
deleted file mode 100644
index c07b518..0000000
--- a/sysdata/libraries/stn/src/pci.hb
+++ /dev/null
@@ -1,50 +0,0 @@
-.{inl, outl} := @use("rel:memory.hb")
-
-config_read := fn(bus: u8, device: u8, func: u8, offset: u8): u32 {
-	lbus := @as(u32, bus)
-	ldevice := @as(u32, device)
-	lfunc := @as(u32, func)
-	loffset := @as(u32, offset)
-
-	address := lbus << 16 | ldevice << 11 | lfunc << 8 | loffset & 0xFC | @as(u32, 0x80000000)
-
-	outl(0xCF8, address)
-	return inl(0xCFC)
-}
-
-config_write := fn(bus: u8, device: u8, func: u8, offset: u8, value: u32): void {
-	lbus := @as(u32, bus)
-	ldevice := @as(u32, device)
-	lfunc := @as(u32, func)
-	loffset := @as(u32, offset)
-
-	address := lbus << 16 | ldevice << 11 | lfunc << 8 | loffset & 0xFC | @as(u32, 0x80000000)
-
-	outl(0xCF8, address)
-	outl(0xCFC, value)
-}
-
-get_header_type := fn(bus: u8, device: u8, func: u8): u8 {
-	return @as(u8, config_read(bus, device, func, 0xC) >> 16 & 0xFF)
-}
-
-Ids := struct {vendor: u16, device: u16}
-
-get_ids := fn(bus: u8, device: u8, func: u8): Ids {
-	res := config_read(bus, device, func, 0)
-	return .(@as(u16, res >> 16 & 0xFFFF), @as(u16, res & 0xFFFF))
-}
-
-PciDeviceInfo := struct {header_type: u8, device: u8, bus: u8, device_id: Ids, full_class: u16, rev_id: u8}
-
-check_device := fn(bus: u8, device: u8): PciDeviceInfo {
-	ids := get_ids(bus, device, 0)
-	if ids.vendor == 0xFFFF {
-		return .(0, 0, 0, .(0, 0), 0, 0)
-	}
-	reg2 := config_read(bus, device, 0, 0x8)
-	class := @as(u16, reg2 >> 16 & 0xFFFF)
-	header_type := get_header_type(bus, device, 0)
-
-	return .(header_type, device, bus, ids, class, @as(u8, reg2 & 0xFF))
-}
\ No newline at end of file
diff --git a/sysdata/programs/svga_driver/src/device.hb b/sysdata/programs/svga_driver/src/device.hb
index 11e3bb8..c0a6f71 100644
--- a/sysdata/programs/svga_driver/src/device.hb
+++ b/sysdata/programs/svga_driver/src/device.hb
@@ -1,15 +1,19 @@
+stn := @use("../../../libraries/stn/src/lib.hb");
+.{string, memory, buffer, log} := stn
+
 pci := @use("../../../libraries/pci/src/lib.hb");
 .{PCIAddress} := pci
 
 FIFO := struct {
 	reserved_size: u32,
 	using_bounce_buffer: u8,
-	bounce_buffer: [u8; 1024 * 1024],
+	//bounce_buffer: [u8; 1024 * 1024],
 	next_fence: u32,
 }
 new_fifo := fn(): FIFO {
-	bounce_buffer := @as([u8; 1024 * 1024], idk)
-	return FIFO.(0, 0, bounce_buffer, 0)
+	//bounce_buffer := @as([u8; 1024 * 1024], idk)
+	/*bounce_buffer,*/
+	return FIFO.(0, 0, 0)
 }
 
 IRQ := struct {
diff --git a/sysdata/programs/svga_driver/src/main.hb b/sysdata/programs/svga_driver/src/main.hb
index f09ed85..6cb8eed 100644
--- a/sysdata/programs/svga_driver/src/main.hb
+++ b/sysdata/programs/svga_driver/src/main.hb
@@ -12,9 +12,8 @@ PCI_DEVICE_ID_VMWARE_SVGA2 := 0x405
 init := fn(): void {
 	svga_struct := device.svga_device()
 
-	if pci.find_device(PCI_VENDOR_ID_VMWARE, PCI_DEVICE_ID_VMWARE_SVGA2, svga_struct.pciAddr) {
-		log.error("No VMware SVGA device found.\0")
-	}
+	pci_dev := pci.check_device(0, 2)
+
 	return
 }
 
diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml
index 109b9bd..8a4e85d 100644
--- a/sysdata/system_config.toml
+++ b/sysdata/system_config.toml
@@ -44,7 +44,7 @@ resolution = "1024x768x24"
 [boot.limine.ableos.modules.svga_driver]
 path = "boot:///svga_driver.hbf"
 
-[boot.limine.ableos.modules.filesystem_fat32]
-path = "boot:///filesystem_fat32.hbf"
-[boot.limine.ableos.modules.pumpkin_print]
-path = "boot:///pumpkin_print.hbf"
+# [boot.limine.ableos.modules.filesystem_fat32]
+# path = "boot:///filesystem_fat32.hbf"
+# [boot.limine.ableos.modules.pumpkin_print]
+# path = "boot:///pumpkin_print.hbf"