From 758629df0acd67d397f468cbe9d36264f944bc19 Mon Sep 17 00:00:00 2001 From: Able Date: Fri, 20 Sep 2024 05:06:08 -0500 Subject: [PATCH] thumbs up --- Cargo.lock | 9 ++-- kernel/src/holeybytes/ecah.rs | 5 +- sysdata/libraries/pci/src/lib.hb | 3 +- sysdata/programs/svga_driver/src/device.hb | 56 +++++++++++++++++----- sysdata/programs/svga_driver/src/main.hb | 6 ++- sysdata/programs/svga_driver/src/reg.hb | 5 +- 6 files changed, 59 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e5cc60..870ae8c 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#0d118c17b2d0e770161be834c5452753eb9c34dd" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8e62bd747b88a1db1d07ffa355690fac48977bb2" [[package]] name = "hbbytecode" @@ -400,8 +400,9 @@ source = "git+https://git.ablecorp.us/ableos/holey-bytes.git#0d118c17b2d0e770161 [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0d118c17b2d0e770161be834c5452753eb9c34dd" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8e62bd747b88a1db1d07ffa355690fac48977bb2" dependencies = [ + "hbbytecode 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)", "hbvm 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)", "regalloc2", ] @@ -409,7 +410,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0d118c17b2d0e770161be834c5452753eb9c34dd" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8e62bd747b88a1db1d07ffa355690fac48977bb2" dependencies = [ "hbbytecode 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)", ] @@ -903,7 +904,7 @@ dependencies = [ [[package]] name = "regalloc2" version = "0.10.2" -source = "git+https://github.com/jakubDoka/regalloc2#7e74b2fde4f022816cded93ab5685e46f8e3a159" +source = "git+https://github.com/jakubDoka/regalloc2#52b2bbe908e78af1715de88f562f62a83e36ca96" dependencies = [ "hashbrown", "rustc-hash", diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 7ef5cb4..fcb37e0 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -106,13 +106,14 @@ pub fn handler(vm: &mut Vm) { 2 => x86_in::(addr) as u64, _ => panic!("Trying to read size other than: 8, 16, 32 from port."), }; - // info!("Read the value {} from address {}", value, addr); + info!("Read the value {} from address {}", value, addr); vm.registers[1] = hbvm::value::Value(value); }, 1 => unsafe { let size = msg_vec[1]; let addr = u16::from_le_bytes(msg_vec[2..4].try_into().unwrap()); - trace!("Setting address {}", addr); + info!("Setting address {}", addr); + match size { 0 => x86_out(addr, msg_vec[4]), 1 => x86_out( diff --git a/sysdata/libraries/pci/src/lib.hb b/sysdata/libraries/pci/src/lib.hb index 3ff73a7..db2b366 100644 --- a/sysdata/libraries/pci/src/lib.hb +++ b/sysdata/libraries/pci/src/lib.hb @@ -9,6 +9,7 @@ PCIAddress := struct { PCI_ID := struct { vendor: u16, device: u16, + inner: int, } get_ids := fn(bus: u8, device: u8, function: u8): PCI_ID { @@ -17,7 +18,7 @@ get_ids := fn(bus: u8, device: u8, function: u8): PCI_ID { dev_id &= 0xFFFF vnd_id := res & 0xFFFF - return PCI_ID.(dev_id, vnd_id) + return PCI_ID.(dev_id, vnd_id, 0) } PciDeviceInfo := struct { diff --git a/sysdata/programs/svga_driver/src/device.hb b/sysdata/programs/svga_driver/src/device.hb index 010f72c..954105b 100644 --- a/sysdata/programs/svga_driver/src/device.hb +++ b/sysdata/programs/svga_driver/src/device.hb @@ -9,7 +9,7 @@ pci := @use("../../../libraries/pci/src/lib.hb"); reg := @use("./reg.hb") PCI_VENDOR_ID_VMWARE := 0x15AD -PCI_DEVICE_ID_VMWARE_SVGA2 := 0x405 +PCI_DEVICE_ID_VMWARE_SVGA2 := 1029 read_reg := fn(svga_dev: ^SVGADevice, index: u32): u32 { memory.outl(svga_dev.ioBase, index) @@ -71,49 +71,79 @@ svga_device := fn(): SVGADevice { return SVGADevice.(pci_addr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, fifo, irq) } +// TODO : this function is broken +GetBARAddr := fn(addr: PCIAddress, index: int): u32 { + //bar := config_read32(addr, offsetof(PCIConfigSpace, BAR[index])); + bar := config_read32(0, 3, 0, 0) + PCI_CONF_BAR_IO := 0 + + mask := 0xF + + /* + if bar & PCI_CONF_BAR_IO { + 0x3 + } else { + }*/ + + return bar & (mask ^ 0xFFFFFFFF) +} + setup_device := fn(svga_dev: ^SVGADevice): void { - svga_dev.pciAddr = PCIAddress.(0, 2, 0) + // TODO: Fix this + // refer to https://git.ablecorp.us/able/vmware-svga/src/commit/eea7ddcd0d34702f8f0a33c1933718706c6318c5/lib/refdriver/svga.c#L55 + + + svga_dev.pciAddr = PCIAddress.(0, 3, 0) + /* pci_id := get_ids(svga_dev.pciAddr.bus, svga_dev.pciAddr.device, svga_dev.pciAddr.function) + if pci_id.vendor != PCI_VENDOR_ID_VMWARE | pci_id.device != PCI_DEVICE_ID_VMWARE_SVGA2 { log.error("SVGA device not found\0") return } + */ + svga_dev.ioBase = config_read32(svga_dev.pciAddr.bus, svga_dev.pciAddr.device, svga_dev.pciAddr.function, 0x10) & 0xFFFFFFF0 - write_reg(&svga_dev, reg.SVGA_REG_ENABLE, reg.SVGA_REG_ENABLE_ENABLE) - svga_dev.capabilities = read_reg(&svga_dev, 0x1) - svga_dev.deviceVersionId = read_reg(&svga_dev, 0x2) + write_reg(svga_dev, reg.SVGA_REG_ENABLE, reg.SVGA_REG_ENABLE_ENABLE) + svga_dev.capabilities = read_reg(svga_dev, 0x1) + svga_dev.deviceVersionId = read_reg(svga_dev, 0x2) + + svga_dev.fbMem = GetBARAddr(svga_dev.pciAddr, 1) + // hardcode values for now svga_dev.width = 1024 svga_dev.height = 768 svga_dev.bpp = 32 svga_dev.pitch = svga_dev.width * 4 - svga_dev.fbSize = svga_dev.width * svga_dev.height * svga_dev.bpp / 8 - svga_dev.vramSize = read_reg(&svga_dev, 0x10) + svga_dev.fbSize = svga_dev.width * svga_dev.height * svga_dev.bpp / 8 + + svga_dev.vramSize = read_reg(svga_dev, 0x10) log.info("SVGA device initialized successfully\0") + return } setup_framebuffer := fn(svga_dev: ^SVGADevice): void { - write_reg(svga_dev, SVGA_REG_WIDTH, svga_dev.width) - write_reg(svga_dev, SVGA_REG_HEIGHT, svga_dev.height) - write_reg(svga_dev, SVGA_REG_BITS_PER_PIXEL, svga_dev.bpp) - - // 0x23 is probably framebuffer address idk - svga_dev.fbMem = @as(^u8, read_reg(svga_dev, 0x23)) + write_reg(svga_dev, reg.SVGA_REG_WIDTH, svga_dev.width) + write_reg(svga_dev, reg.SVGA_REG_HEIGHT, svga_dev.height) + write_reg(svga_dev, reg.SVGA_REG_BITS_PER_PIXEL, svga_dev.bpp) log.info("Framebuffer setup complete\0") return } draw_pixel := fn(svga_dev: ^SVGADevice, x: int, y: int, color: u32): void { + /* if x >= svga_dev.width || y >= svga_dev.height { return // what happens if we write outside here : ) } + */ offset := y * svga_dev.pitch + x * svga_dev.bpp / 8 mem_addr := svga_dev.fbMem + offset memory.outl(mem_addr, color) + return } diff --git a/sysdata/programs/svga_driver/src/main.hb b/sysdata/programs/svga_driver/src/main.hb index 148df14..dbf2431 100644 --- a/sysdata/programs/svga_driver/src/main.hb +++ b/sysdata/programs/svga_driver/src/main.hb @@ -21,9 +21,11 @@ main := fn(): int { device.setup_device(&svga_dev) device.setup_framebuffer(&svga_dev) + device.draw_pixel(&svga_dev, 100, 100, 0xFF00FFFF) + /* + device.clear_screen(&svga_dev, 0xFF) - - device.draw_pixel(&svga_dev, 100, 100, 0xFF0000) + */ return 0 } \ No newline at end of file diff --git a/sysdata/programs/svga_driver/src/reg.hb b/sysdata/programs/svga_driver/src/reg.hb index a9a789b..8a810b3 100644 --- a/sysdata/programs/svga_driver/src/reg.hb +++ b/sysdata/programs/svga_driver/src/reg.hb @@ -3,10 +3,9 @@ SVGA_REG_ENABLE_ENABLE := 1 SVGA_REG_ENABLE_HIDE := 2 SVGA_REG_ENABLE_ENABLE_HIDE := SVGA_REG_ENABLE_ENABLE | SVGA_REG_ENABLE_HIDE - SVGA_REG_DISABLE := 0 SVGA_REG_ENABLE := 1 SVGA_REG_WIDTH := 2 -SVGA_REG_HEIGHT := 3 -SVGA_REG_BITS_PER_PIXEL := 7 +SVGA_REG_HEIGHT := 3 +SVGA_REG_BITS_PER_PIXEL := 7 SVGA_REG_BYTES_PER_LINE := 12 \ No newline at end of file