1
0
Fork 0
forked from AbleOS/ableos

thumbs up

This commit is contained in:
Able 2024-09-20 05:06:08 -05:00
parent 04a449965b
commit 758629df0a
6 changed files with 59 additions and 25 deletions

9
Cargo.lock generated
View file

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

View file

@ -106,13 +106,14 @@ pub fn handler(vm: &mut Vm) {
2 => x86_in::<u32>(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(

View file

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

View file

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

View file

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

View file

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