From 3d53b641bf475b1588559d8d130a6d491d59927a Mon Sep 17 00:00:00 2001 From: Able Date: Sat, 16 Nov 2024 02:51:58 -0600 Subject: [PATCH 1/5] interrupt work --- kernel/src/arch/mod.rs | 22 ++++++++++++ kernel/src/arch/x86_64/interrupts.rs | 36 +++++++++++++++++-- .../service_definition_service.rs | 3 +- kernel/src/holeybytes/mod.rs | 2 +- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/kernel/src/arch/mod.rs b/kernel/src/arch/mod.rs index c1a5e1b..30621ca 100644 --- a/kernel/src/arch/mod.rs +++ b/kernel/src/arch/mod.rs @@ -14,3 +14,25 @@ arch_cond!( riscv64: "riscv64", x86_64: "x86_64", ); +use {crate::arch::interrupts::Interrupt, alloc::string::String}; +pub struct InterruptList { + list: HashMap, +} +use hashbrown::HashMap; +impl InterruptList { + pub fn new() -> Self { + Self { + list: HashMap::new(), + } + } +} +use { + alloc::vec::Vec, + spin::{Lazy, Mutex}, +}; +pub static INTERRUPT_LIST: Lazy> = Lazy::new(|| { + let mut il = InterruptList::new(); + use crate::alloc::string::ToString; + il.list.insert(Interrupt::Timer, "PS/2 Mouse".to_string()); + Mutex::new(il) +}); diff --git a/kernel/src/arch/x86_64/interrupts.rs b/kernel/src/arch/x86_64/interrupts.rs index 25c2931..0d3215d 100644 --- a/kernel/src/arch/x86_64/interrupts.rs +++ b/kernel/src/arch/x86_64/interrupts.rs @@ -11,7 +11,10 @@ static mut LAPIC: LocalApic = unsafe { MaybeUninit::zeroed().assume_init() }; static mut IDT: InterruptDescriptorTable = unsafe { MaybeUninit::zeroed().assume_init() }; #[repr(u8)] -#[derive(Debug)] +#[derive(Debug)]#[derive(Eq, Hash, PartialEq)] + + +pub enum Interrupt { Timer = 32, ApicErr = u8::MAX - 1, @@ -61,6 +64,8 @@ extern "x86-interrupt" fn page_fault( } extern "x86-interrupt" fn timer(_isf: InterruptStackFrame) { + interrupt(Interrupt::Timer); + unsafe { LAPIC.end_of_interrupt(); } @@ -81,6 +86,31 @@ extern "x86-interrupt" fn spurious(_: InterruptStackFrame) { } fn interrupt(interrupt_type: Interrupt){ - log::info!("Interrupt type {:?}", interrupt_type); - panic!() + + use crate::arch::INTERRUPT_LIST; + let il = INTERRUPT_LIST.lock(); + let val = il.list.get(&interrupt_type).unwrap(); + + use crate::holeybytes::kernel_services::service_definition_service::sds_search_service; + let buffer = sds_search_service(val); + if buffer != 0 { + use alloc::vec::Vec;use crate::kmain::IPC_BUFFERS; + let mut buffs = IPC_BUFFERS.lock(); + match buffs.get_mut(&buffer) { + Some(buff) => { + let mut msg_vec = Vec::new(); + msg_vec.push(0xff); + buff.push(msg_vec.to_vec()); + log::debug!("Sent Message {:?} to Buffer({})", msg_vec, buffer); + } + None => { + log::error!("Access of non-existent buffer {}", buffer) + } + } + + + + // log::info!("{}", buffer); + +} } \ No newline at end of file diff --git a/kernel/src/holeybytes/kernel_services/service_definition_service.rs b/kernel/src/holeybytes/kernel_services/service_definition_service.rs index 7cf03ec..10db094 100644 --- a/kernel/src/holeybytes/kernel_services/service_definition_service.rs +++ b/kernel/src/holeybytes/kernel_services/service_definition_service.rs @@ -92,8 +92,7 @@ fn sds_create_service(protocol: &'static str) -> u64 { // let a: protocol::Protocol = protocol.into(); buff_id } - -fn sds_search_service(protocol: &str) -> u64 { +pub fn sds_search_service(protocol: &str) -> u64 { let services = SERVICES.lock(); let compare = Protocol::from(protocol); for (bid, protocol_canidate) in &services.0 { diff --git a/kernel/src/holeybytes/mod.rs b/kernel/src/holeybytes/mod.rs index 42e4812..2c4dbab 100644 --- a/kernel/src/holeybytes/mod.rs +++ b/kernel/src/holeybytes/mod.rs @@ -1,5 +1,5 @@ mod ecah; -mod kernel_services; +pub mod kernel_services; mod mem; use { From ee82bc5705df1547dc3d5216c5866012c49b779d Mon Sep 17 00:00:00 2001 From: koniifer Date: Sat, 16 Nov 2024 09:30:43 +0000 Subject: [PATCH 2/5] minor changes --- Cargo.lock | 10 +++++----- sysdata/libraries/stn/src/memory.hb | 4 ++-- sysdata/programs/render_example/src/examples/orbit.hb | 1 - 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 17a86d6..1e7ac8f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,12 +228,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#7058efe75c7ad245db80986e77a97d426b9be8a4" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#baa70d3f1272c2cbb208ca17115dc54b7d31af5c" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#7058efe75c7ad245db80986e77a97d426b9be8a4" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#baa70d3f1272c2cbb208ca17115dc54b7d31af5c" dependencies = [ "hashbrown 0.15.1", "hbbytecode", @@ -245,7 +245,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#7058efe75c7ad245db80986e77a97d426b9be8a4" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#baa70d3f1272c2cbb208ca17115dc54b7d31af5c" dependencies = [ "hbbytecode", ] @@ -428,9 +428,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.162" +version = "0.2.163" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" +checksum = "1fdaeca4cf44ed4ac623e86ef41f056e848dbeab7ec043ecb7326ba300b36fd0" [[package]] name = "limine" diff --git a/sysdata/libraries/stn/src/memory.hb b/sysdata/libraries/stn/src/memory.hb index 03a6cfe..609104c 100644 --- a/sysdata/libraries/stn/src/memory.hb +++ b/sysdata/libraries/stn/src/memory.hb @@ -6,7 +6,7 @@ $uninit := fn($Expr: type): ?Expr { return null } -dangling := fn($Expr: type): ^Expr { +$dangling := fn($Expr: type): ^Expr { return @bitcast(@alignof(Expr)) } @@ -23,7 +23,7 @@ alloc := fn($Expr: type, num: uint): ^Expr { ptr := request_page(MAX_ALLOC) remaining := pages - MAX_ALLOC loop if remaining < MAX_ALLOC break else { - _ = request_page(@intcast(MAX_ALLOC)) + _ = request_page(MAX_ALLOC) remaining -= MAX_ALLOC } _ = request_page(@intcast(remaining)) diff --git a/sysdata/programs/render_example/src/examples/orbit.hb b/sysdata/programs/render_example/src/examples/orbit.hb index 84b47e3..b83d1d4 100644 --- a/sysdata/programs/render_example/src/examples/orbit.hb +++ b/sysdata/programs/render_example/src/examples/orbit.hb @@ -25,7 +25,6 @@ example := fn(): void { render.clear(screen, render.black) render.put_filled_circle(screen, .(screen.width / 2, screen.height / 2), 128, render.light_yellow) render.put_circle(screen, .(screen.width / 2, screen.height / 2), 256, render.light_blue) - // Precision issues? render.put_textured_circle(screen, able, .(able.width / 2, able.height / 2), .(screen.width / 2 + @intcast(@fti(sin(angle) * 256)), screen.height / 2 + @intcast(@fti(cos(angle) * 256))), able.width / 2 - 1) render.put_textured_circle(screen, mini, .(mini.width / 2, mini.height / 2), .(screen.width / 2 + @intcast(@fti(sin(angle + PI) * 256)), screen.height / 2 + @intcast(@fti(cos(angle + PI) * 256))), mini.width / 2 - 1) render.sync(screen) From d958a103faa4442b9fe6436b5399248e9ce37fe5 Mon Sep 17 00:00:00 2001 From: koniifer Date: Sat, 16 Nov 2024 09:34:17 +0000 Subject: [PATCH 3/5] fix --- kernel/src/arch/x86_64/interrupts.rs | 44 ++++++++++++---------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/kernel/src/arch/x86_64/interrupts.rs b/kernel/src/arch/x86_64/interrupts.rs index 0d3215d..4bd3c8a 100644 --- a/kernel/src/arch/x86_64/interrupts.rs +++ b/kernel/src/arch/x86_64/interrupts.rs @@ -11,11 +11,9 @@ static mut LAPIC: LocalApic = unsafe { MaybeUninit::zeroed().assume_init() }; static mut IDT: InterruptDescriptorTable = unsafe { MaybeUninit::zeroed().assume_init() }; #[repr(u8)] -#[derive(Debug)]#[derive(Eq, Hash, PartialEq)] +#[derive(Debug, Eq, Hash, PartialEq)] - -pub -enum Interrupt { +pub enum Interrupt { Timer = 32, ApicErr = u8::MAX - 1, Spurious = u8::MAX, @@ -64,7 +62,7 @@ extern "x86-interrupt" fn page_fault( } extern "x86-interrupt" fn timer(_isf: InterruptStackFrame) { - interrupt(Interrupt::Timer); + // interrupt(Interrupt::Timer); unsafe { LAPIC.end_of_interrupt(); @@ -85,8 +83,7 @@ extern "x86-interrupt" fn spurious(_: InterruptStackFrame) { } } -fn interrupt(interrupt_type: Interrupt){ - +fn interrupt(interrupt_type: Interrupt) { use crate::arch::INTERRUPT_LIST; let il = INTERRUPT_LIST.lock(); let val = il.list.get(&interrupt_type).unwrap(); @@ -94,23 +91,20 @@ fn interrupt(interrupt_type: Interrupt){ use crate::holeybytes::kernel_services::service_definition_service::sds_search_service; let buffer = sds_search_service(val); if buffer != 0 { - use alloc::vec::Vec;use crate::kmain::IPC_BUFFERS; - let mut buffs = IPC_BUFFERS.lock(); - match buffs.get_mut(&buffer) { - Some(buff) => { - let mut msg_vec = Vec::new(); - msg_vec.push(0xff); - buff.push(msg_vec.to_vec()); - log::debug!("Sent Message {:?} to Buffer({})", msg_vec, buffer); - } - None => { - log::error!("Access of non-existent buffer {}", buffer) - } - } - - - - // log::info!("{}", buffer); + use {crate::kmain::IPC_BUFFERS, alloc::vec::Vec}; + let mut buffs = IPC_BUFFERS.lock(); + match buffs.get_mut(&buffer) { + Some(buff) => { + let mut msg_vec = Vec::new(); + msg_vec.push(0xFF); + buff.push(msg_vec.to_vec()); + log::debug!("Sent Message {:?} to Buffer({})", msg_vec, buffer); + } + None => { + log::error!("Access of non-existent buffer {}", buffer) + } + } + // log::info!("{}", buffer); + } } -} \ No newline at end of file From 2808bc9e7c6f3dd0f284b7bbc26147fe8d9b8d27 Mon Sep 17 00:00:00 2001 From: koniifer Date: Sat, 16 Nov 2024 16:34:45 +0000 Subject: [PATCH 4/5] various fixes, update to latest rust nightly --- Cargo.lock | 57 +++++-------------------- kernel/.cargo/config.toml | 3 -- kernel/lds/x86_64.ld | 1 + kernel/src/arch/mod.rs | 12 ++++-- kernel/src/arch/x86_64/mod.rs | 6 +-- kernel/src/lib.rs | 3 +- kernel/targets/aarch64-virt-ableos.json | 2 +- rust-toolchain.toml | 4 +- 8 files changed, 27 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e7ac8f..86916ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aarch64-cpu" @@ -65,15 +65,6 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -dependencies = [ - "allocator-api2", -] - [[package]] name = "byteorder" version = "1.5.0" @@ -208,12 +199,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hashbrown" version = "0.15.1" @@ -228,24 +213,23 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#baa70d3f1272c2cbb208ca17115dc54b7d31af5c" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4088bd18b189b15996a4bdd6ab47141372457875" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#baa70d3f1272c2cbb208ca17115dc54b7d31af5c" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4088bd18b189b15996a4bdd6ab47141372457875" dependencies = [ - "hashbrown 0.15.1", + "hashbrown", "hbbytecode", "hbvm", "log", - "regalloc2", ] [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#baa70d3f1272c2cbb208ca17115dc54b7d31af5c" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4088bd18b189b15996a4bdd6ab47141372457875" dependencies = [ "hbbytecode", ] @@ -396,7 +380,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.15.1", + "hashbrown", ] [[package]] @@ -406,7 +390,7 @@ dependencies = [ "aarch64-cpu", "crossbeam-queue", "derive_more", - "hashbrown 0.15.1", + "hashbrown", "hbvm", "limine", "log", @@ -428,9 +412,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.163" +version = "0.2.164" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fdaeca4cf44ed4ac623e86ef41f056e848dbeab7ec043ecb7326ba300b36fd0" +checksum = "433bfe06b8c75da9b2e3fbea6e5329ff87748f0b144ef75306e674c3f6f7c13f" [[package]] name = "limine" @@ -553,19 +537,6 @@ dependencies = [ "bitflags 2.6.0", ] -[[package]] -name = "regalloc2" -version = "0.10.2" -source = "git+https://github.com/jakubDoka/regalloc2?branch=reuse-allocations#21c43e3ee182824e92e2b25f1d3c03ed47f9c02b" -dependencies = [ - "allocator-api2", - "bumpalo", - "hashbrown 0.14.5", - "log", - "rustc-hash", - "smallvec", -] - [[package]] name = "regex-syntax" version = "0.8.5" @@ -602,12 +573,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "rustc-hash" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" - [[package]] name = "rustc_version" version = "0.4.1" @@ -619,9 +584,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.16" +version = "0.23.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" +checksum = "7f1a745511c54ba6d4465e8d5dfbd81b45791756de28d4981af70d6dca128f1e" dependencies = [ "log", "once_cell", diff --git a/kernel/.cargo/config.toml b/kernel/.cargo/config.toml index e052590..422bf9d 100644 --- a/kernel/.cargo/config.toml +++ b/kernel/.cargo/config.toml @@ -1,6 +1,3 @@ [unstable] build-std = ["core", "compiler_builtins", "alloc"] build-std-features = ["compiler-builtins-mem"] - -[build] -target = "./targets/x86_64-ableos.json" diff --git a/kernel/lds/x86_64.ld b/kernel/lds/x86_64.ld index 8e899a4..19ee79f 100644 --- a/kernel/lds/x86_64.ld +++ b/kernel/lds/x86_64.ld @@ -38,6 +38,7 @@ SECTIONS .data : { *(.data .data.*) + *(.got .got.*) } :data .bss : { diff --git a/kernel/src/arch/mod.rs b/kernel/src/arch/mod.rs index 30621ca..305872f 100644 --- a/kernel/src/arch/mod.rs +++ b/kernel/src/arch/mod.rs @@ -14,11 +14,16 @@ arch_cond!( riscv64: "riscv64", x86_64: "x86_64", ); + +#[cfg(target_arch = "x86_64")] use {crate::arch::interrupts::Interrupt, alloc::string::String}; +#[cfg(target_arch = "x86_64")] pub struct InterruptList { list: HashMap, } +#[cfg(target_arch = "x86_64")] use hashbrown::HashMap; +#[cfg(target_arch = "x86_64")] impl InterruptList { pub fn new() -> Self { Self { @@ -26,10 +31,9 @@ impl InterruptList { } } } -use { - alloc::vec::Vec, - spin::{Lazy, Mutex}, -}; +#[cfg(target_arch = "x86_64")] +use spin::{Lazy, Mutex}; +#[cfg(target_arch = "x86_64")] pub static INTERRUPT_LIST: Lazy> = Lazy::new(|| { let mut il = InterruptList::new(); use crate::alloc::string::ToString; diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index aa4f6cd..fbc362c 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -33,7 +33,7 @@ const INITIAL_KERNEL_HEAP_SIZE: *const () = _initial_kernel_heap_size as _; #[cfg(not(target_feature = "avx2"))] unsafe extern "C" fn _kernel_start() -> ! { // Initialise SSE, then jump to kernel entrypoint - core::arch::asm!( + core::arch::naked_asm!( // Initialise SSE "mov rax, cr0", "and ax, 0xfffb", @@ -46,7 +46,6 @@ unsafe extern "C" fn _kernel_start() -> ! { // Jump to the kernel entry point "jmp {}", sym start, - options(noreturn), ) } @@ -54,7 +53,7 @@ unsafe extern "C" fn _kernel_start() -> ! { #[naked] #[cfg(target_feature = "avx2")] unsafe extern "C" fn _kernel_start() -> ! { - core::arch::asm!( + core::arch::naked_asm!( // Enable protected mode and configure control registers "mov rax, cr0", "and ax, 0xFFFB", // Clear CR0.EM (bit 2) for coprocessor emulation @@ -100,7 +99,6 @@ unsafe extern "C" fn _kernel_start() -> ! { "jmp {0}", sym start, sym oops, - options(noreturn), ) } diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index a94f94b..3eff39d 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -5,7 +5,6 @@ #![feature( slice_split_once, exclusive_wrapper, - new_uninit, core_intrinsics, abi_x86_interrupt, alloc_error_handler, @@ -15,7 +14,7 @@ pointer_is_aligned_to )] #![test_runner(crate::test_runner)] -#![allow(dead_code, internal_features)] +#![allow(dead_code, internal_features, static_mut_refs)] extern crate alloc; mod allocator; diff --git a/kernel/targets/aarch64-virt-ableos.json b/kernel/targets/aarch64-virt-ableos.json index fcb14d0..9ee18cf 100644 --- a/kernel/targets/aarch64-virt-ableos.json +++ b/kernel/targets/aarch64-virt-ableos.json @@ -1,6 +1,6 @@ { "arch": "aarch64", - "data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", + "data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32", "disable-redzone": true, "env": "", "executables": true, diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 9353a54..e66400a 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,5 @@ [toolchain] -channel = "nightly-2024-07-27" +# old toolchain +# channel = "nightly-2024-07-27" +channel = "nightly" components = ["rust-src", "llvm-tools"] From da5f1a7a193342e62bf11e0dd529ca14d250468f Mon Sep 17 00:00:00 2001 From: koniifer Date: Sat, 16 Nov 2024 20:42:16 +0000 Subject: [PATCH 5/5] compiler update --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 86916ee..7d4cd9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4088bd18b189b15996a4bdd6ab47141372457875" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#12bb7029b4bafd1edff77ed9a12888374cc7f8be" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4088bd18b189b15996a4bdd6ab47141372457875" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#12bb7029b4bafd1edff77ed9a12888374cc7f8be" dependencies = [ "hashbrown", "hbbytecode", @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#4088bd18b189b15996a4bdd6ab47141372457875" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#12bb7029b4bafd1edff77ed9a12888374cc7f8be" dependencies = [ "hbbytecode", ]