minor changes, svga work

This commit is contained in:
koniifer 2024-09-19 20:40:10 +01:00
parent 6ad68dabac
commit 0bbc76124f
13 changed files with 131 additions and 197 deletions

183
Cargo.lock generated
View file

@ -38,15 +38,6 @@ dependencies = [
"zerocopy",
]
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]]
name = "allocator-api2"
version = "0.2.18"
@ -68,55 +59,6 @@ dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.6.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
[[package]]
name = "anstyle-parse"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"
dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
dependencies = [
"anstyle",
"windows-sys 0.52.0",
]
[[package]]
name = "anyhow"
version = "1.0.89"
@ -200,15 +142,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
version = "1.7.1"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3"
[[package]]
name = "cc"
version = "1.1.20"
version = "1.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45bcde016d64c21da4be18b655631e5ab6d3107607e71a73a9f53eb48aae23fb"
checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0"
dependencies = [
"shlex",
]
@ -233,12 +175,6 @@ dependencies = [
"windows-targets",
]
[[package]]
name = "colorchoice"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
@ -322,29 +258,6 @@ dependencies = [
"syn",
]
[[package]]
name = "env_filter"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab"
dependencies = [
"log",
"regex",
]
[[package]]
name = "env_logger"
version = "0.11.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d"
dependencies = [
"anstream",
"anstyle",
"env_filter",
"humantime",
"log",
]
[[package]]
name = "equivalent"
version = "1.0.1"
@ -477,28 +390,26 @@ dependencies = [
[[package]]
name = "hbbytecode"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#e4e7f8d5b5cefd2094a427cc6c5b78c169565a3e"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0d118c17b2d0e770161be834c5452753eb9c34dd"
[[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#0d118c17b2d0e770161be834c5452753eb9c34dd"
[[package]]
name = "hblang"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#e4e7f8d5b5cefd2094a427cc6c5b78c169565a3e"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0d118c17b2d0e770161be834c5452753eb9c34dd"
dependencies = [
"env_logger",
"hbvm 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)",
"log",
"regalloc2",
]
[[package]]
name = "hbvm"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#e4e7f8d5b5cefd2094a427cc6c5b78c169565a3e"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0d118c17b2d0e770161be834c5452753eb9c34dd"
dependencies = [
"hbbytecode 0.1.0 (git+https://git.ablecorp.us/AbleOS/holey-bytes.git)",
]
@ -506,7 +417,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#0d118c17b2d0e770161be834c5452753eb9c34dd"
dependencies = [
"hbbytecode 0.1.0 (git+https://git.ablecorp.us/ableos/holey-bytes.git)",
]
@ -557,12 +468,6 @@ version = "1.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "hyper"
version = "1.4.1"
@ -669,12 +574,6 @@ version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itoa"
version = "1.0.11"
@ -749,18 +648,18 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]]
name = "logos"
version = "0.14.1"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff1ceb190eb9bdeecdd8f1ad6a71d6d632a50905948771718741b5461fb01e13"
checksum = "1c6b6e02facda28ca5fb8dbe4b152496ba3b1bd5a4b40bb2b1b2d8ad74e0f39b"
dependencies = [
"logos-derive",
]
[[package]]
name = "logos-codegen"
version = "0.14.1"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90be66cb7bd40cb5cc2e9cfaf2d1133b04a3d93b72344267715010a466e0915a"
checksum = "b32eb6b5f26efacd015b000bfc562186472cd9b34bdba3f6b264e2a052676d10"
dependencies = [
"beef",
"fnv",
@ -773,9 +672,9 @@ dependencies = [
[[package]]
name = "logos-derive"
version = "0.14.1"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45154231e8e96586b39494029e58f12f8ffcb5ecf80333a603a13aa205ea8cbd"
checksum = "3e5d0c5463c911ef55624739fc353238b4e310f0144be1f875dc42fec6bfd5ec"
dependencies = [
"logos-codegen",
]
@ -1004,39 +903,13 @@ dependencies = [
[[package]]
name = "regalloc2"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12908dbeb234370af84d0579b9f68258a0f67e201412dd9a2814e6f45b2fc0f0"
source = "git+https://github.com/jakubDoka/regalloc2#7e74b2fde4f022816cded93ab5685e46f8e3a159"
dependencies = [
"hashbrown",
"log",
"rustc-hash",
"slice-group-by",
"smallvec",
]
[[package]]
name = "regex"
version = "1.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.4"
@ -1274,12 +1147,6 @@ dependencies = [
"autocfg",
]
[[package]]
name = "slice-group-by"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7"
[[package]]
name = "smallvec"
version = "1.13.2"
@ -1515,18 +1382,18 @@ checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
[[package]]
name = "unicode-normalization"
version = "0.1.23"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5"
checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956"
dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-xid"
version = "0.2.5"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]]
name = "untrusted"
@ -1545,12 +1412,6 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "version_check"
version = "0.9.5"
@ -1677,9 +1538,9 @@ dependencies = [
[[package]]
name = "webpki-roots"
version = "0.26.5"
version = "0.26.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a"
checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958"
dependencies = [
"rustls-pki-types",
]

View file

@ -56,7 +56,7 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! {
disp.set_attribute("width", fb1.width);
disp.set_attribute("height", fb1.height);
disp.set_attribute("bits per pixel", fb1.bpp);
disp.set_attribute("bpp", fb1.bpp);
disp.set_attribute("pitch", fb1.pitch);
dt.devices.insert("Displays".to_string(), alloc::vec![disp]);
}

View file

@ -345,11 +345,12 @@ fn run(release: bool, target: Target) -> Result<(), Error> {
com.args([
"-bios", &ovmf_path.change_context(Error::OvmfFetch)?,
"-drive", "file=target/disk.img,format=raw",
"-m", "4G",
"-smp", "cores=4",
"-enable-kvm",
"-device", "vmware-svga",
"-m", "2G",
"-smp", "1",
"-machine", "accel=kvm",
"-cpu", "host",
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04"
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04",
]);
}
Target::Riscv64Virt => {

View file

@ -1,5 +1,4 @@
stn := @use("../../stn/src/lib.hb");
.{string, memory, buffer} := stn
.{string, memory, buffer, log} := @use("../../stn/src/lib.hb")
PCIAddress := struct {
bus: u8,
@ -51,9 +50,9 @@ check_device := fn(bus: u8, device: u8): PciDeviceInfo {
pci_id := get_ids(bus, device, 0)
if pci_id.vendor == 0xFFFF {
stn.log.warn(":|\0")
log.warn(":|\0")
} else {
stn.log.info(":)\0")
log.info(":)\0")
}
address := calculate_address(bus, device, 0, 0x8)
reg2 := config_read32(bus, device, 0, 0x8)

View file

@ -1,5 +1,5 @@
integer := fn(): int {
return @eca(int, 3, 4)
return @eca(3, 4)
}
integer_range := fn(min: int, max: int): int {

View file

@ -1,4 +1,4 @@
.{example} := @use("./examples/square.hb")
.{example} := @use("./examples/amogus.hb")
main := fn(): void {
@inline(example)

View file

@ -25,7 +25,7 @@ main := fn(): int {
mem := memory.request_page(1)
loop {
ptr := @eca(int, 4, a, mem, 0x1000)
ptr := @eca(4, a, mem, 0x1000)
if ptr == 0 {
serial_println("No message\0")
}

View file

@ -6,7 +6,7 @@ log_info := fn(): void {
} else {
msg := "XABC\0"
msg_length := @inline(string.length, msg)
@eca(void, 3, a, msg, msg_length)
@eca(3, a, msg, msg_length)
}
return

View file

@ -2,7 +2,25 @@ stn := @use("../../../libraries/stn/src/lib.hb");
.{string, memory, buffer, log} := stn
pci := @use("../../../libraries/pci/src/lib.hb");
.{PCIAddress} := pci
.{PCIAddress, get_ids, config_read32} := pci;
.{dt_get} := @use("../../../libraries/dt_api/src/lib.hb")
reg := @use("./reg.hb")
PCI_VENDOR_ID_VMWARE := 0x15AD
PCI_DEVICE_ID_VMWARE_SVGA2 := 0x405
read_reg := fn(svga_dev: ^SVGADevice, index: u32): u32 {
memory.outl(svga_dev.ioBase, index)
return memory.inl(svga_dev.ioBase + 4)
}
write_reg := fn(svga_dev: ^SVGADevice, index: u32, value: u32): void {
memory.outl(svga_dev.ioBase, index)
memory.outl(svga_dev.ioBase + 4, value)
return
}
FIFO := struct {
reserved_size: u32,
@ -51,4 +69,63 @@ svga_device := fn(): SVGADevice {
fifo := new_fifo()
irq := new_irq()
return SVGADevice.(pci_addr, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, fifo, irq)
}
setup_device := fn(svga_dev: ^SVGADevice): void {
svga_dev.pciAddr = PCIAddress.(0, 2, 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)
// 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)
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))
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
}
clear_screen := fn(svga_dev: ^SVGADevice, color: u32): void {
y := 0
loop if y == svga_dev.height break else {
x := 0
loop if x == svga_dev.width break else {
draw_pixel(svga_dev, x, y, color)
x += 1
}
y += 1
}
return
}

View file

@ -5,18 +5,9 @@ stn := @use("../../../libraries/stn/src/lib.hb");
.{string, memory, buffer, log} := stn
reg := @use("reg.hb")
PCI_VENDOR_ID_VMWARE := 0x15AD
PCI_DEVICE_ID_VMWARE_SVGA2 := 0x405
init := fn(): void {
svga_struct := device.svga_device()
pci_dev := pci.check_device(0, 2)
return
}
write_reg := fn(index: u32, value: u32): void {
}
@ -26,13 +17,13 @@ SVGA_disable := fn(): void {
}
main := fn(): int {
a := pci.config_read32(0, 2, 0, 0x8)
b := "\0\0\0\0\0\0\0"
svga_dev := device.svga_device()
string.display_int(a, b)
stn.log.info(b)
device.setup_device(&svga_dev)
device.setup_framebuffer(&svga_dev)
init()
device.clear_screen(&svga_dev, 0xFF)
device.draw_pixel(&svga_dev, 100, 100, 0xFF0000)
return 0
}

View file

@ -1,4 +1,9 @@
SVGA_REG_ENABLE_DISABLE := 0
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_ENABLE_ENABLE_HIDE := SVGA_REG_ENABLE_ENABLE | SVGA_REG_ENABLE_HIDE
SVGA_REG_ENABLE := 1
SVGA_REG_WIDTH := 2
SVGA_REG_HEIGHT := 3
SVGA_REG_BITS_PER_PIXEL := 7
SVGA_REG_BYTES_PER_LINE := 12

View file

@ -2,7 +2,7 @@
service_search := fn(): void {
a := "\{01}\0"
@eca(void, 3, 0, a, 2)
@eca(3, 0, a, 2)
return
}

View file

@ -26,8 +26,8 @@ resolution = "1024x768x24"
# [boot.limine.ableos.modules.diskio_driver]
# path = "boot:///diskio_driver.hbf"
[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.serial_driver_test]
# path = "boot:///serial_driver_test.hbf"
@ -41,11 +41,11 @@ path = "boot:///render_example.hbf"
# [boot.limine.ableos.modules.dt_buffer_test]
# path = "boot:///dt_buffer_test.hbf"
# [boot.limine.ableos.modules.svga_driver]
# path = "boot:///svga_driver.hbf"
[boot.limine.ableos.modules.svga_driver]
path = "boot:///svga_driver.hbf"
[boot.limine.ableos.modules.ps2_driver]
path = "boot:///ps2_driver.hbf"
# [boot.limine.ableos.modules.ps2_driver]
# path = "boot:///ps2_driver.hbf"
# [boot.limine.ableos.modules.filesystem_fat32]
# path = "boot:///filesystem_fat32.hbf"