From 07ee8de9f183b006cc57cdce162a528cf9b84bce Mon Sep 17 00:00:00 2001 From: koniifer Date: Mon, 30 Sep 2024 21:45:57 +0100 Subject: [PATCH] push it to prod :smile: experimental avx stuff (enable it yourself, coward) update hblang & fiddle with stuff --- Cargo.lock | 202 +++++------------- kernel/.cargo/config.toml | 7 +- kernel/Cargo.toml | 33 ++- .../src/arch/aarch64/device_info_collector.rs | 13 +- kernel/src/arch/x86_64/mod.rs | 64 +++++- kernel/src/arch/x86_64/pci/mod.rs | 5 +- kernel/src/arch/x86_64/virtio/mod.rs | 2 +- kernel/src/device_tree/mod.rs | 15 +- kernel/src/holeybytes/ecah.rs | 57 +++-- .../kernel_services/dt_msg_handler.rs | 47 ++-- kernel/src/holeybytes/mem.rs | 6 +- kernel/src/ipc/protocol.rs | 13 +- kernel/src/kmain.rs | 3 +- kernel/src/lib.rs | 1 + kernel/src/utils.rs | 9 +- kernel/targets/x86_64-ableos.json | 40 ++-- kernel/targets/x86_64-v3-ableos.json | 22 ++ repbuild/Cargo.toml | 21 +- repbuild/src/main.rs | 3 + sysdata/libraries/dt_api/src/lib.hb | 8 +- sysdata/libraries/stn/src/memory.hb | 8 +- .../render_example/src/examples/square.hb | 8 +- sysdata/programs/render_example/src/main.hb | 2 +- sysdata/system_config.toml | 4 +- 24 files changed, 283 insertions(+), 310 deletions(-) create mode 100644 kernel/targets/x86_64-v3-ableos.json diff --git a/Cargo.lock b/Cargo.lock index 3fe7792..93ff235 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,15 +67,9 @@ checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" - -[[package]] -name = "az" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "backtrace" @@ -133,6 +127,9 @@ name = "bumpalo" version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +dependencies = [ + "allocator-api2", +] [[package]] name = "byteorder" @@ -148,9 +145,9 @@ checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "cc" -version = "1.1.21" +version = "1.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +checksum = "3bbb537bb4a30b90362caddba8f360c0a56bc13d3a5570028e7197204cb54a17" dependencies = [ "shlex", ] @@ -224,40 +221,6 @@ dependencies = [ "logos", ] -[[package]] -name = "embedded-graphics" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0649998afacf6d575d126d83e68b78c0ab0e00ca2ac7e9b3db11b4cbe8274ef0" -dependencies = [ - "az", - "byteorder", - "embedded-graphics-core", - "float-cmp", - "micromath", -] - -[[package]] -name = "embedded-graphics-core" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba9ecd261f991856250d2207f6d8376946cd9f412a2165d3b75bc87a0bc7a044" -dependencies = [ - "az", - "byteorder", -] - -[[package]] -name = "enumn" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -286,15 +249,6 @@ dependencies = [ "log", ] -[[package]] -name = "float-cmp" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" -dependencies = [ - "num-traits", -] - [[package]] name = "fnv" version = "1.0.7" @@ -390,22 +344,24 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0e9f4402cb686da817ef876abd764676e262759a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#1f5846afaacb237245c0061422d9799f71d7f623" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0e9f4402cb686da817ef876abd764676e262759a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#1f5846afaacb237245c0061422d9799f71d7f623" dependencies = [ + "hashbrown", "hbbytecode", "hbvm", + "log", "regalloc2", ] [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#0e9f4402cb686da817ef876abd764676e262759a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#1f5846afaacb237245c0061422d9799f71d7f623" dependencies = [ "hbbytecode", ] @@ -452,9 +408,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] name = "hyper" @@ -495,9 +451,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ "bytes", "futures-channel", @@ -508,7 +464,6 @@ dependencies = [ "pin-project-lite", "socket2", "tokio", - "tower", "tower-service", "tracing", ] @@ -584,7 +539,6 @@ dependencies = [ "aarch64-cpu", "crossbeam-queue", "derive_more", - "embedded-graphics", "hashbrown", "hbvm", "limine", @@ -594,7 +548,6 @@ dependencies = [ "spin", "uart_16550", "versioning", - "virtio-drivers", "x2apic", "x86_64 0.15.1", "xml", @@ -608,9 +561,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "limine" @@ -673,12 +626,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "micromath" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c8dda44ff03a2f238717214da50f65d5a53b45cd213a7370424ffdb6fae815" - [[package]] name = "mime" version = "0.3.17" @@ -726,9 +673,12 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" +dependencies = [ + "portable-atomic", +] [[package]] name = "paste" @@ -742,26 +692,6 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -774,6 +704,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" + [[package]] name = "ppv-lite86" version = "0.2.20" @@ -891,18 +827,21 @@ dependencies = [ [[package]] name = "regalloc2" version = "0.10.2" -source = "git+https://github.com/jakubDoka/regalloc2#52b2bbe908e78af1715de88f562f62a83e36ca96" +source = "git+https://github.com/jakubDoka/regalloc2?branch=reuse-allocations#c4d21e228dd70fda27b3e92eeff282d32858d613" dependencies = [ + "allocator-api2", + "bumpalo", "hashbrown", + "log", "rustc-hash", "smallvec", ] [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "repbuild" @@ -912,6 +851,7 @@ dependencies = [ "error-stack", "fatfs", "hblang", + "log", "reqwest", "str-reader", "toml", @@ -919,9 +859,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.7" +version = "0.12.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" dependencies = [ "base64", "bytes", @@ -1012,19 +952,18 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "2.1.3" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" dependencies = [ - "base64", "rustls-pki-types", ] [[package]] name = "rustls-pki-types" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" [[package]] name = "rustls-webpki" @@ -1101,9 +1040,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ "serde", ] @@ -1174,9 +1113,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -1194,18 +1133,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", @@ -1282,9 +1221,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.21" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "serde", @@ -1293,27 +1232,6 @@ dependencies = [ "winnow", ] -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-layer" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" - [[package]] name = "tower-service" version = "0.3.3" @@ -1414,18 +1332,6 @@ dependencies = [ "serde", ] -[[package]] -name = "virtio-drivers" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6a39747311dabb3d37807037ed1c3c38d39f99198d091b5b79ecd5c8d82f799" -dependencies = [ - "bitflags 2.6.0", - "enumn", - "log", - "zerocopy", -] - [[package]] name = "volatile" version = "0.4.6" @@ -1656,9 +1562,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] diff --git a/kernel/.cargo/config.toml b/kernel/.cargo/config.toml index 5e82bd2..dc3c3df 100644 --- a/kernel/.cargo/config.toml +++ b/kernel/.cargo/config.toml @@ -5,5 +5,8 @@ build-std-features = ["compiler-builtins-mem"] [build] target = "./targets/x86_64-ableos.json" -[target.'cfg(target_arch = "x86_64")'] -rustflags = ["-C", "target-feature=+rdrand"] +# [target.'cfg(target_arch = "x86_64")'] +# rustflags = [ +# "-C", +#"target-feature=+sse4.1,+avx,+aes,+fma,+popcnt,+bmi2,+avx2,+lzcnt,+xsave", +# ] diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index f42624c..ff6604b 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -5,8 +5,10 @@ version = "0.2.0" [dependencies] -embedded-graphics = "0.8" -hbvm.git = "https://git.ablecorp.us/AbleOS/holey-bytes.git" +# embedded-graphics = "0.8" +hbvm = { git = "https://git.ablecorp.us/AbleOS/holey-bytes.git", features = [ + "nightly", +] } log = "0.4" spin = "0.9" slab = { version = "0.4", default-features = false } @@ -15,10 +17,7 @@ xml.git = "https://git.ablecorp.us/ableos/ableos_userland" versioning.git = "https://git.ablecorp.us/ableos/ableos_userland" # able_graphics_library.git = "https://git.ablecorp.us/ableos/ableos_userland" hashbrown = { version = "0.14", features = ["nightly"] } - -[dependencies.limine] -version = "0.1" -#git = "https://github.com/limine-bootloader/limine-rs" +limine = "0.1" [dependencies.crossbeam-queue] version = "0.3" @@ -33,23 +32,23 @@ features = ["alloc", "nightly"] version = "1" default-features = false features = [ - "add", - "add_assign", - "constructor", - "display", - "from", - "into", - "mul", - "mul_assign", - "not", - "sum", + "add", + "add_assign", + "constructor", + "display", + "from", + "into", + "mul", + "mul_assign", + "not", + "sum", ] [target.'cfg(target_arch = "x86_64")'.dependencies] x86_64 = "0.15" x2apic = "0.4" -virtio-drivers = "0.7" +# virtio-drivers = "0.7" [target.'cfg(target_arch = "riscv64")'.dependencies] sbi = "0.2.0" diff --git a/kernel/src/arch/aarch64/device_info_collector.rs b/kernel/src/arch/aarch64/device_info_collector.rs index c17d5d1..e70b138 100644 --- a/kernel/src/arch/aarch64/device_info_collector.rs +++ b/kernel/src/arch/aarch64/device_info_collector.rs @@ -1,6 +1,5 @@ use { - crate::{alloc::string::ToString, device_tree::DeviceTree, kmain::DEVICE_TREE}, - alloc::string::String, + crate::{device_tree::DeviceTree, kmain::DEVICE_TREE}, core::arch::asm, xml::XMLElement, }; @@ -28,7 +27,7 @@ fn collect_cpu_info(device_tree: &mut DeviceTree) { cpus.push(cpu); } -fn cpu_id() -> (String, u64) { +fn cpu_id<'a>() -> (&'a str, u64) { let mut cpu_id: u64; unsafe { asm!("mrs {cpu_id}, MIDR_EL1", @@ -39,11 +38,11 @@ fn cpu_id() -> (String, u64) { let cpu_name = match cpu_id { // the source of these two was a stackoverflow question // https://raspberrypi.stackexchange.com/questions/117175/how-do-i-read-the-cpuid-in-aarch64-asm - 0x410FD034 => "Cortex-A53".to_string(), - 0x410FD083 => "Cortex-A72".to_string(), + 0x410FD034 => "Cortex-A53", + 0x410FD083 => "Cortex-A72", // the source of this one was checking the cpu id :thinking: - 0x410FD493 => "Neoverse N2".to_string(), - _ => "Unknown".to_string(), + 0x410FD493 => "Neoverse N2", + _ => "Unknown", }; log::trace!("CPU Name: {cpu_name} - CPU ID: 0x{:X}", cpu_id); diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index 51dd9ee..413bde6 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -10,7 +10,7 @@ pub mod graphics; pub(crate) mod interrupts; pub mod logging; pub mod pci; -pub mod virtio; +// pub mod virtio; pub use {logging::log, memory::PAGE_SIZE}; @@ -31,8 +31,9 @@ const INITIAL_KERNEL_HEAP_SIZE: *const () = _initial_kernel_heap_size as _; #[no_mangle] #[naked] unsafe extern "C" fn _kernel_start() -> ! { - // Initialise SSE and jump to kernel entrypoint + // Initialise SSE, then jump to kernel entrypoint core::arch::asm!( + // Initialise SSE "mov rax, cr0", "and ax, 0xfffb", "or ax, 0x2", @@ -40,12 +41,71 @@ unsafe extern "C" fn _kernel_start() -> ! { "mov rax, cr4", "or ax, 3 << 9", "mov cr4, rax", + + // Jump to the kernel entry point "jmp {}", sym start, options(noreturn), ) } +// #[no_mangle] +// #[naked] +// unsafe extern "C" fn _kernel_start() -> ! { +// core::arch::asm!( +// // Enable protected mode and configure control registers +// "mov rax, cr0", +// "and ax, 0xFFFB", // Clear CR0.EM (bit 2) for coprocessor emulation +// "or ax, 0x2", // Set CR0.MP (bit 1) for coprocessor monitoring +// "mov cr0, rax", + +// "mov rax, cr4", +// "or ax, (1 << 9) | (1 << 10)", // Set CR4.OSFXSR (bit 9) and CR4.OSXMMEXCPT (bit 10) +// "mov cr4, rax", + +// // Enable OSXSAVE (required for AVX, AVX2, and XSAVE) +// "mov rax, cr4", +// "or eax, 1 << 18", // Set CR4.OSXSAVE (bit 18) +// "mov cr4, rax", + +// // Enable AVX and AVX2 state saving +// "xor rcx, rcx", +// "xgetbv", +// "or eax, 7", // Enable SSE, AVX, and AVX2 state saving +// "xsetbv", + +// // Check for AVX and XSAVE support +// "mov eax, 1", +// "cpuid", +// "and ecx, 0x18000000", +// "cmp ecx, 0x18000000", +// "jne {1}", // Jump if AVX/OSXSAVE is not supported + +// // Check for BMI2 and AVX2 support +// "mov eax, 7", +// "xor ecx, ecx", +// "cpuid", +// "and ebx, (1 << 8) | (1 << 5)", // Check BMI2 (bit 8) and AVX2 (bit 5) +// "cmp ebx, (1 << 8) | (1 << 5)", // Compare to ensure both are supported + +// // Check for LZCNT and POPCNT support +// "mov eax, 1", +// "cpuid", +// "and ecx, (1 << 5) | (1 << 23)", // Check LZCNT (bit 5) and POPCNT (bit 23) +// "cmp ecx, (1 << 5) | (1 << 23)", // Compare to ensure both are supported + +// // Jump to the kernel entry point +// "jmp {0}", +// sym start, +// sym oops, +// options(noreturn), +// ) +// } + +unsafe extern "C" fn oops() -> ! { + panic!("your cpu is ancient >:(") +} + unsafe extern "C" fn start() -> ! { logging::init(); crate::logger::init().expect("failed to set logger"); diff --git a/kernel/src/arch/x86_64/pci/mod.rs b/kernel/src/arch/x86_64/pci/mod.rs index 872e3a8..af0fe63 100644 --- a/kernel/src/arch/x86_64/pci/mod.rs +++ b/kernel/src/arch/x86_64/pci/mod.rs @@ -8,13 +8,12 @@ pub struct PciDeviceInfo { pub full_class: PciFullClass, pub rev_id: u8, } -use crate::alloc::string::ToString; /// Enumerate PCI devices and run initialisation routines on ones we support pub fn init(device_tree: &mut DeviceTree) { device_tree .devices - .insert("Unidentified PCI".to_string(), alloc::vec![]); + .insert("Unidentified PCI", alloc::vec![]); let mut devices = alloc::vec![]; for bus in 0..=255 { @@ -48,7 +47,7 @@ pub fn init(device_tree: &mut DeviceTree) { pci_info.set_attribute("device", device_info.device); pci_info.set_attribute("vendor", vendor); pci_info.set_attribute("bus", bus); - pci_info.set_attribute("class", device_info.full_class.to_string()); + pci_info.set_attribute("class", device_info.full_class); dev.set_child(pci_info); devices.push((dev_type, dev)); } diff --git a/kernel/src/arch/x86_64/virtio/mod.rs b/kernel/src/arch/x86_64/virtio/mod.rs index bcc4906..6088ff1 100644 --- a/kernel/src/arch/x86_64/virtio/mod.rs +++ b/kernel/src/arch/x86_64/virtio/mod.rs @@ -1,5 +1,5 @@ use { - core::{ptr::NonNull}, + core::ptr::NonNull, virtio_drivers::{BufferDirection, Hal, PhysAddr}, }; diff --git a/kernel/src/device_tree/mod.rs b/kernel/src/device_tree/mod.rs index 8d1c64c..9dd85cb 100644 --- a/kernel/src/device_tree/mod.rs +++ b/kernel/src/device_tree/mod.rs @@ -1,11 +1,6 @@ //! A tree of hardware devices -use { - crate::alloc::string::ToString, - alloc::{string::String, vec::Vec}, - core::fmt, - hashbrown::HashMap, -}; +use {alloc::vec::Vec, core::fmt, hashbrown::HashMap}; /// A device object. /// TODO define device @@ -14,11 +9,11 @@ pub type Device = xml::XMLElement; /// A tree of devices // TODO: alphabetize this list #[derive(Debug)] -pub struct DeviceTree { +pub struct DeviceTree<'a> { /// The device tree - pub devices: HashMap>, + pub devices: HashMap<&'a str, Vec>, } -impl DeviceTree { +impl<'a> DeviceTree<'a> { /// Build the device tree. Does not populate the device tree pub fn new() -> Self { let mut dt = Self { @@ -47,7 +42,7 @@ impl DeviceTree { } } use crate::{device_tree, tab, utils::TAB}; -impl fmt::Display for DeviceTree { +impl<'a> fmt::Display for DeviceTree<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f)?; for (device_type, devices) in &self.devices { diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 1566dd7..24fb324 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -8,11 +8,21 @@ use crate::holeybytes::kernel_services::{ use { super::Vm, crate::{arch, ipc::buffer::IpcBuffer, kmain::IPC_BUFFERS}, + hbvm::value::Value, log::{debug, error, info, trace}, }; +#[cfg(target_arch = "x86_64")] +unsafe fn x86_out(address: u16, value: T) { + x86_64::instructions::port::Port::new(address).write(value); +} +#[cfg(target_arch = "x86_64")] +unsafe fn x86_in(address: u16) -> T { + x86_64::instructions::port::Port::new(address).read() +} + pub fn handler(vm: &mut Vm) { - let ecall_number = vm.registers[2].cast::(); + let Value(ecall_number) = vm.registers[2]; // log::info!("eca called :pensive:"); // debug!("Ecall number {:?}", ecall_number); //info!("Register dump: {:?}", vm.registers); @@ -28,15 +38,15 @@ pub fn handler(vm: &mut Vm) { 1 => { // Make buffer - let bounded = match vm.registers[3].cast::() { - 0 => false, - 1 => true, + let bounded = match vm.registers[3] { + Value(0) => false, + Value(1) => true, _ => { panic!("Bad"); } }; - let length = vm.registers[4].cast::(); + let Value(length) = vm.registers[4]; let mut buffs = IPC_BUFFERS.lock(); let abc; @@ -59,9 +69,12 @@ pub fn handler(vm: &mut Vm) { } 3 => { // Send a message to a buffer - let buffer_id = vm.registers[3].cast::(); - let mem_addr = vm.registers[4].cast::(); - let length = vm.registers[5].cast::() as usize; + let Value(buffer_id) = vm.registers[3]; + let Value(mem_addr) = vm.registers[4]; + let length = { + let Value(length) = vm.registers[5]; + length as usize + }; trace!("IPC address: {:?}", mem_addr); use alloc::vec::Vec; @@ -81,19 +94,8 @@ pub fn handler(vm: &mut Vm) { Err(_) => {} } } - #[cfg(not(target_arch = "x86_64"))] - 3 => info!("TODO: implement whatever buffer 3 does for no x86_64"), #[cfg(target_arch = "x86_64")] 3 => { - unsafe fn x86_out( - address: u16, - value: T, - ) { - x86_64::instructions::port::Port::new(address).write(value); - } - unsafe fn x86_in(address: u16) -> T { - x86_64::instructions::port::Port::new(address).read() - } let msg_vec = block_read(mem_addr, length); let msg_type = msg_vec[0]; match msg_type { @@ -142,6 +144,7 @@ pub fn handler(vm: &mut Vm) { Ok(()) => {} Err(_) => log::error!("Improper dt query"), }, + buffer_id => { let mut buffs = IPC_BUFFERS.lock(); match buffs.get_mut(&buffer_id) { @@ -168,9 +171,9 @@ pub fn handler(vm: &mut Vm) { } } 4 => { - let buffer_id = vm.registers[3].cast::(); - let mut map_ptr = vm.registers[4].cast::(); - let max_length = vm.registers[5].cast::(); + let Value(buffer_id) = vm.registers[3]; + let Value(mut map_ptr) = vm.registers[4]; + let Value(max_length) = vm.registers[5]; let mut buffs = IPC_BUFFERS.lock(); let buff: &mut IpcBuffer; @@ -204,14 +207,8 @@ pub fn handler(vm: &mut Vm) { 5 => { #[cfg(target_arch = "x86_64")] { - let r2 = vm.registers[2].cast::(); - unsafe fn x86_in(address: u16) -> u32 { - x86_64::instructions::port::Port::new(address).read() - } - unsafe fn x86_out(address: u16, value: u32) { - x86_64::instructions::port::Port::new(address).write(value); - } - let x = hbvm::value::Value(unsafe { x86_in(r2 as u16) } as u64); + let Value(r2) = vm.registers[2]; + let x = hbvm::value::Value(unsafe { x86_in::(r2 as u16) } as u64); // info!("Read {:?} from Port {:?}", x, r2); vm.registers[3] = x } diff --git a/kernel/src/holeybytes/kernel_services/dt_msg_handler.rs b/kernel/src/holeybytes/kernel_services/dt_msg_handler.rs index 876abb8..318e763 100644 --- a/kernel/src/holeybytes/kernel_services/dt_msg_handler.rs +++ b/kernel/src/holeybytes/kernel_services/dt_msg_handler.rs @@ -1,9 +1,6 @@ use { crate::holeybytes::{kernel_services::block_read, Vm}, - alloc::{ - string::{String, ToString}, - vec::Vec, - }, + alloc::vec::Vec, }; pub enum DtError { QueryFailure, @@ -11,14 +8,13 @@ pub enum DtError { pub fn dt_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), DtError> { let msg_vec = block_read(mem_addr, length); - let mut bytes: Vec = Vec::new(); - for byte in msg_vec { - if *byte == 0 { - break; - } - bytes.push(*byte) - } - let query_string = String::from_utf8(bytes).unwrap(); + let query_string = core::str::from_utf8( + msg_vec + .split_once(|&byte| byte == 0) + .unwrap_or((msg_vec, &[])) + .0, + ) + .unwrap(); log::trace!("Query {}", query_string); let ret = query_parse(query_string); @@ -29,17 +25,13 @@ pub fn dt_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), D Ok(()) } -fn query_parse(query_string: String) -> u64 { - let qt_parse_step_one = query_string.split("/"); - let mut qt_parse_step_two: Vec = Vec::new(); - for a in qt_parse_step_one { - qt_parse_step_two.push(a.to_string()); - } +fn query_parse(query_string: &str) -> u64 { + let query = query_string.split('/').collect::>(); - let first_fragment: &str = &qt_parse_step_two[0]; + let first_fragment: &str = &query[0]; let ret = match first_fragment { - "framebuffer" => framebuffer_parse(qt_parse_step_two), - "cpu" => cpu_parse(qt_parse_step_two), + "framebuffer" => framebuffer_parse(query), + "cpu" => cpu_parse(query), _ => 0, }; @@ -47,8 +39,8 @@ fn query_parse(query_string: String) -> u64 { return ret; } -fn cpu_parse(qt_parse_step_two: Vec) -> u64 { - let second_fragment: &str = &qt_parse_step_two[1]; +fn cpu_parse(qt_parse_step_two: Vec<&str>) -> u64 { + let second_fragment: &str = qt_parse_step_two[1]; match second_fragment { // "architecture" => { // return 0; @@ -59,15 +51,14 @@ fn cpu_parse(qt_parse_step_two: Vec) -> u64 { }; } -fn framebuffer_parse(qt_parse_step_two: Vec) -> u64 { +fn framebuffer_parse(qt_parse_step_two: Vec<&str>) -> u64 { use crate::kmain::FB_REQ; - let fbs = &FB_REQ.get_response().get().unwrap().framebuffers(); - - let second_fragment: &str = &qt_parse_step_two[1]; + let fbs = &mut FB_REQ.get_response().get().unwrap().framebuffers(); + let second_fragment: &str = qt_parse_step_two[1]; match second_fragment { "fb0" => { let fb_front = &fbs[0]; - let third_fragment: &str = &qt_parse_step_two[2]; + let third_fragment: &str = qt_parse_step_two[2]; let ret = match third_fragment { "ptr" => { let ptr = fb_front.address.as_ptr().unwrap(); diff --git a/kernel/src/holeybytes/mem.rs b/kernel/src/holeybytes/mem.rs index 35a423b..6b58290 100644 --- a/kernel/src/holeybytes/mem.rs +++ b/kernel/src/holeybytes/mem.rs @@ -37,8 +37,8 @@ impl hbvm::mem::Memory for Memory { target: *mut u8, count: usize, ) -> Result<(), hbvm::mem::LoadError> { - if addr.get() % 4096 == 0 {} - core::ptr::copy(addr.get() as *const u8, target, count); + // if addr.get() % 4096 == 0 {} + core::ptr::copy_nonoverlapping(addr.get() as *const u8, target, count); Ok(()) } @@ -49,7 +49,7 @@ impl hbvm::mem::Memory for Memory { source: *const u8, count: usize, ) -> Result<(), hbvm::mem::StoreError> { - core::ptr::copy(source, addr.get() as *mut u8, count); + core::ptr::copy_nonoverlapping(source, addr.get() as *mut u8, count); Ok(()) } diff --git a/kernel/src/ipc/protocol.rs b/kernel/src/ipc/protocol.rs index 0e8427e..72bc8e3 100644 --- a/kernel/src/ipc/protocol.rs +++ b/kernel/src/ipc/protocol.rs @@ -1,18 +1,15 @@ -use { - alloc::{string::String, vec::Vec}, - hashbrown::HashMap, -}; +use {alloc::vec::Vec, hashbrown::HashMap}; #[derive(Debug, PartialEq, Clone)] pub struct Type {} #[derive(Debug, PartialEq, Clone)] -pub struct Funct { - takes: Vec, - gives: Vec, +pub struct Funct<'a> { + takes: Vec<&'a str>, + gives: Vec<&'a str>, } #[derive(Debug, PartialEq, Clone)] pub struct Protocol<'a> { types: HashMap<&'a str, Type>, - fns: HashMap<&'a str, Funct>, + fns: HashMap<&'a str, Funct<'a>>, } impl<'a> Protocol<'a> { pub fn void() -> Self { diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index 9b6a945..347aa34 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -50,7 +50,6 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! { let fb1: &NonNullPtr = &FB_REQ.get_response().get().unwrap().framebuffers()[0]; { - use crate::alloc::string::ToString; let mut dt = DEVICE_TREE.lock(); let mut disp = xml::XMLElement::new("display_0"); @@ -58,7 +57,7 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! { disp.set_attribute("height", fb1.height); disp.set_attribute("bpp", fb1.bpp); disp.set_attribute("pitch", fb1.pitch); - dt.devices.insert("Displays".to_string(), alloc::vec![disp]); + dt.devices.insert("Displays", alloc::vec![disp]); } debug!("Graphics initialised"); debug!( diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index fd0b1dd..9a8060b 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -3,6 +3,7 @@ //! Akern is woefully undersupported at the moment but we are looking to add support improve hardware discovery and make our lives as kernel and operating system developers easier and better #![no_std] #![feature( + slice_split_once, exclusive_wrapper, new_uninit, abi_x86_interrupt, diff --git a/kernel/src/utils.rs b/kernel/src/utils.rs index ce78fbc..ade830f 100644 --- a/kernel/src/utils.rs +++ b/kernel/src/utils.rs @@ -4,15 +4,14 @@ /// Used when tab `\t` in hardware is not known and we will default to two spaces pub const TAB: &str = " "; - // NOTE: this only reduces the code duplication in source code not in generated code! // Written by Yours Truly: Munir /// A simple macro to reduce code duplication when we use TAB internally #[macro_export] macro_rules! tab { - ($num:expr) => { + ($num:expr) => { TAB.repeat($num) - } + }; } // NOTE: this only reduces the code duplication in source code not in generated code! @@ -22,7 +21,7 @@ macro_rules! tab { macro_rules! device_tree { ($devtree:expr, $dev_type_vec:expr) => { for each_device_type in $dev_type_vec { - $devtree.devices.insert(each_device_type.to_string(), Vec::new()); + $devtree.devices.insert(each_device_type, Vec::new()); } }; } @@ -50,4 +49,4 @@ macro_rules! cpu_features { $result_vec.push(("rdseed", rdseed)); $result_vec.push(("x2apic", x2)); }; -} \ No newline at end of file +} diff --git a/kernel/targets/x86_64-ableos.json b/kernel/targets/x86_64-ableos.json index 37be33d..576e7cc 100644 --- a/kernel/targets/x86_64-ableos.json +++ b/kernel/targets/x86_64-ableos.json @@ -1,22 +1,22 @@ { - "llvm-target": "x86_64-unknown-none", - "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", - "arch": "x86_64", - "target-endian": "little", - "target-pointer-width": "64", - "target-c-int-width": "32", - "os": "none", - "executables": true, - "linker-flavor": "ld.lld", - "linker": "rust-lld", - "panic-strategy": "abort", - "disable-redzone": true, - "features": "", - "code-model": "kernel", - "pre-link-args": { - "ld.lld": [ - "--gc-sections", - "--script=kernel/lds/x86_64.ld" - ] - } + "llvm-target": "x86_64-unknown-none", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", + "arch": "x86_64", + "target-endian": "little", + "target-pointer-width": "64", + "target-c-int-width": "32", + "os": "none", + "executables": true, + "linker-flavor": "ld.lld", + "linker": "rust-lld", + "panic-strategy": "abort", + "disable-redzone": true, + "features": "", + "code-model": "kernel", + "pre-link-args": { + "ld.lld": [ + "--gc-sections", + "--script=kernel/lds/x86_64.ld" + ] + } } \ No newline at end of file diff --git a/kernel/targets/x86_64-v3-ableos.json b/kernel/targets/x86_64-v3-ableos.json new file mode 100644 index 0000000..a496085 --- /dev/null +++ b/kernel/targets/x86_64-v3-ableos.json @@ -0,0 +1,22 @@ +{ + "llvm-target": "x86_64-unknown-none", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", + "arch": "x86_64", + "target-endian": "little", + "target-pointer-width": "64", + "target-c-int-width": "32", + "os": "none", + "executables": true, + "linker-flavor": "ld.lld", + "linker": "rust-lld", + "panic-strategy": "abort", + "disable-redzone": true, + "features": "+sse4.1,+avx,+aes,+fma,+popcnt,+bmi2,+avx2,+lzcnt,+xsave", + "code-model": "kernel", + "pre-link-args": { + "ld.lld": [ + "--gc-sections", + "--script=kernel/lds/x86_64.ld" + ] + } +} \ No newline at end of file diff --git a/repbuild/Cargo.toml b/repbuild/Cargo.toml index a082573..71aa93a 100644 --- a/repbuild/Cargo.toml +++ b/repbuild/Cargo.toml @@ -6,22 +6,23 @@ edition = "2021" [dependencies] str-reader = "0.1" derive_more = { version = "1", default-features = false, features = [ - "add", - "add_assign", - "constructor", - "display", - "from", - "into", - "mul", - "mul_assign", - "not", - "sum", + "add", + "add_assign", + "constructor", + "display", + "from", + "into", + "mul", + "mul_assign", + "not", + "sum", ] } error-stack = "0.5" fatfs = "0.3" toml = "0.8" # hbasm.git = "https://git.ablecorp.us/AbleOS/holey-bytes.git" hblang.git = "https://git.ablecorp.us/AbleOS/holey-bytes.git" +log = "0.4" [dependencies.reqwest] version = "0.12" diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index af25649..3032333 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -21,6 +21,9 @@ fn main() -> Result<(), Error> { let mut args = std::env::args(); args.next(); + log::set_logger(&hblang::Logger).unwrap(); + log::set_max_level(log::LevelFilter::Error); + match args.next().as_deref() { Some("build" | "b") => { let mut release = false; diff --git a/sysdata/libraries/dt_api/src/lib.hb b/sysdata/libraries/dt_api/src/lib.hb index 78ddd1c..8f2dffe 100644 --- a/sysdata/libraries/dt_api/src/lib.hb +++ b/sysdata/libraries/dt_api/src/lib.hb @@ -1,8 +1,6 @@ -stn := @use("../../stn/src/lib.hb"); -.{string, memory, buffer} := stn +.{string} := @use("../../stn/src/lib.hb") dt_get := fn(query: ^u8): int { - message_length := string.length(query) - - return @eca(3, 5, query, message_length) + length := string.length(query) + return @eca(3, 5, query, length) } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/memory.hb b/sysdata/libraries/stn/src/memory.hb index d1da701..4cbdd6d 100644 --- a/sysdata/libraries/stn/src/memory.hb +++ b/sysdata/libraries/stn/src/memory.hb @@ -17,10 +17,10 @@ release_page := fn(ptr: ^u8, page_count: u8): void { return @eca(3, 2, msg, 12) } -OutbMsg := struct {a: u8, b: u8, addr: u16, value: u8} -InbMsg := struct {a: u8, b: u8, addr: u16} -OutlMsg := struct {a: u8, b: u8, addr: u16, value: u32} -InlMsg := struct {a: u8, b: u8, addr: u16} +OutbMsg := packed struct {a: u8, b: u8, addr: u16, value: u8} +InbMsg := packed struct {a: u8, b: u8, addr: u16} +OutlMsg := packed struct {a: u8, b: u8, addr: u16, value: u32} +InlMsg := packed struct {a: u8, b: u8, addr: u16} outb := fn(addr: u16, value: u8): void { return @eca(3, 3, &OutbMsg.(1, 0, addr, value), @sizeof(OutbMsg)) diff --git a/sysdata/programs/render_example/src/examples/square.hb b/sysdata/programs/render_example/src/examples/square.hb index 55f9805..84b013b 100644 --- a/sysdata/programs/render_example/src/examples/square.hb +++ b/sysdata/programs/render_example/src/examples/square.hb @@ -1,7 +1,8 @@ +.{random} := @use("../../../../libraries/stn/src/lib.hb") render := @use("../../../../libraries/render/src/lib.hb") /* expected result: - the white outline of a square bounces around the screen */ + a square that changes colour bounces around the screen */ example := fn(): void { render.init() @@ -9,16 +10,19 @@ example := fn(): void { pos := render.IVec2.(100, 100) width := render.width() height := render.height() + color := @as(render.Color, @intcast(random.integer_range(0, 0xFFFFFF))) loop { - render.put_rect(pos, .(100, 100), render.white) + render.put_filled_rect(pos, .(100, 100), color) render.sync() render.clear(render.black) if pos.x == 0 | pos.x == width - 100 { vel.x = -vel.x + color = @as(render.Color, @intcast(random.integer_range(0, 0xFFFFFF))) } if pos.y == 0 | pos.y == height - 100 { vel.y = -vel.y + color = @as(render.Color, @intcast(random.integer_range(0, 0xFFFFFF))) } pos += vel diff --git a/sysdata/programs/render_example/src/main.hb b/sysdata/programs/render_example/src/main.hb index 35b2706..052e1cf 100644 --- a/sysdata/programs/render_example/src/main.hb +++ b/sysdata/programs/render_example/src/main.hb @@ -1,4 +1,4 @@ -.{example} := @use("./examples/amogus.hb") +.{example} := @use("./examples/square.hb") main := fn(): void { @inline(example) diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 82e2aa3..2d11d43 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -44,8 +44,8 @@ path = "boot:///render_example.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"