diff --git a/Cargo.lock b/Cargo.lock index a0152a0d9..7d4cd9e7f 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" @@ -213,12 +213,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a64383e72b0920ef1c03773aac197404c78b330f" +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#a64383e72b0920ef1c03773aac197404c78b330f" +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#a64383e72b0920ef1c03773aac197404c78b330f" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#12bb7029b4bafd1edff77ed9a12888374cc7f8be" dependencies = [ "hbbytecode", ] diff --git a/kernel/.cargo/config.toml b/kernel/.cargo/config.toml index e05259036..422bf9d2a 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 8e899a4d3..19ee79f64 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 c1a5e1bd9..305872f31 100644 --- a/kernel/src/arch/mod.rs +++ b/kernel/src/arch/mod.rs @@ -14,3 +14,29 @@ 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 { + list: HashMap::new(), + } + } +} +#[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; + 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 25c2931bd..4bd3c8a96 100644 --- a/kernel/src/arch/x86_64/interrupts.rs +++ b/kernel/src/arch/x86_64/interrupts.rs @@ -11,8 +11,9 @@ static mut LAPIC: LocalApic = unsafe { MaybeUninit::zeroed().assume_init() }; static mut IDT: InterruptDescriptorTable = unsafe { MaybeUninit::zeroed().assume_init() }; #[repr(u8)] -#[derive(Debug)] -enum Interrupt { +#[derive(Debug, Eq, Hash, PartialEq)] + +pub enum Interrupt { Timer = 32, ApicErr = u8::MAX - 1, Spurious = u8::MAX, @@ -61,6 +62,8 @@ extern "x86-interrupt" fn page_fault( } extern "x86-interrupt" fn timer(_isf: InterruptStackFrame) { + // interrupt(Interrupt::Timer); + unsafe { LAPIC.end_of_interrupt(); } @@ -80,7 +83,28 @@ extern "x86-interrupt" fn spurious(_: InterruptStackFrame) { } } -fn interrupt(interrupt_type: Interrupt){ - log::info!("Interrupt type {:?}", interrupt_type); - panic!() -} \ No newline at end of file +fn interrupt(interrupt_type: Interrupt) { + 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 {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); + } +} diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index aa4f6cd58..fbc362c11 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/holeybytes/kernel_services/service_definition_service.rs b/kernel/src/holeybytes/kernel_services/service_definition_service.rs index 7cf03ecc2..10db0945f 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 42e4812db..2c4dbab4f 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 { diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index a94f94b11..3eff39d8e 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 fcb14d005..9ee18cf01 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 9353a5446..e66400a04 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"] diff --git a/sysdata/libraries/stn/src/memory.hb b/sysdata/libraries/stn/src/memory.hb index 03a6cfece..609104ccb 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 84b47e3ca..b83d1d40f 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)