diff --git a/.cargo/config.toml b/.cargo/config.toml index 1149f5c..6ce8bc9 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,6 +1,6 @@ [unstable] -build-std = ["core", "compiler_builtins"] +build-std = ["core", "compiler_builtins", "alloc"] build-std-features = ["compiler-builtins-mem"] [build] diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 7d2f122..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,13 +0,0 @@ - - -{ - "rust-analyzer.cargo.allTargets": false, - "rust-analyzer.checkOnSave.allTargets": true, // not sure if this one is needed - "rust-analyzer.checkOnSave.overrideCommand": [ - "./cargo", - "xcheck", - "--json-output", - "--target", - "thumbv7m-none-eabi" - ] -} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 4d4e0c9..fa155f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,16 +18,32 @@ checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" name = "mxrox_kernel" version = "0.1.0" dependencies = [ + "stable-vec", "volatile 0.6.1", "x86_64", ] +[[package]] +name = "no-std-compat" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df270209a7f04d62459240d890ecb792714d5db12c92937823574a09930276b4" + [[package]] name = "rustversion" version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" +[[package]] +name = "stable-vec" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1dff32a2ce087283bec878419027cebd888760d8760b2941ad0843531dc9ec8" +dependencies = [ + "no-std-compat", +] + [[package]] name = "volatile" version = "0.4.6" diff --git a/Cargo.toml b/Cargo.toml index 71a28c8..a2704c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,5 @@ edition = "2021" [dependencies] x86_64 = "0.15.2" -volatile = "0.6.1" \ No newline at end of file +volatile = "0.6.1" +stable-vec = "0.4.1" \ No newline at end of file diff --git a/src/kernel/mod.rs b/src/kernel/mod.rs index e2cec0f..1537dbf 100644 --- a/src/kernel/mod.rs +++ b/src/kernel/mod.rs @@ -1,14 +1,23 @@ -use vga::{fill, fill_with_color, put_char, put_string_by_index, read_char, VgaColor}; +use stable_vec::StableVec; +use vga::{ + fill_with_color, + put_string_by_index, + VGA_COLOR_BLACK, + VGA_COLOR_RED +}; mod vga; mod ps2; mod acpi; mod thread; +type Vec = StableVec; + pub fn show_error(message: &str) { - put_string_by_index(0, message, VgaColor::BLACK, VgaColor::LIGHT_RED); + fill_with_color(VGA_COLOR_BLACK); + put_string_by_index(0, message, VGA_COLOR_BLACK, VGA_COLOR_RED); } pub fn start_kernel() { - fill_with_color(VgaColor::BLACK); + show_error("error test"); } \ No newline at end of file diff --git a/src/kernel/ps2.rs b/src/kernel/ps2.rs index 63f7e79..48e3ae1 100644 --- a/src/kernel/ps2.rs +++ b/src/kernel/ps2.rs @@ -1,23 +1,27 @@ +use core::ptr::{read_volatile, write_volatile}; + +use super::Vec; + const DATA_PORT: *mut u8 = 0x60 as *mut u8; const STATUS_PORT: *mut u8 = 0x64 as *mut u8; fn write_ps2_data(data: u8) { - todo!() + unsafe { write_volatile(DATA_PORT, data) } } fn read_ps2_data() -> u8 { - todo!() + unsafe { read_volatile(DATA_PORT) } } fn send_ps2_command(command: u8) { - todo!() + unsafe { write_volatile(STATUS_PORT, command) } } fn read_ps2_status() -> u8 { - todo!() + unsafe { read_volatile(STATUS_PORT) } } /// returns device type bytes -fn init_ps2_controller() -> vec![u8; 2] { +fn init_ps2_controller() -> Vec { todo!() } \ No newline at end of file diff --git a/src/kernel/vga.rs b/src/kernel/vga.rs index 80ebbb5..8609778 100644 --- a/src/kernel/vga.rs +++ b/src/kernel/vga.rs @@ -1,28 +1,26 @@ +use core::ptr::write_volatile; + const VGA_BUFFER: *mut u16 = 0xB8000 as *mut u16; pub const VGA_WIDTH: usize = 80; pub const VGA_HEIGHT: usize = 25; -pub struct VgaColor(u8); - -impl VgaColor { - pub const BLACK: u8 = 0; - pub const BLUE: u8 = 1; - pub const GREEN: u8 = 2; - pub const CYAN: u8 = 3; - pub const RED: u8 = 4; - pub const MAGENTA: u8 = 5; - pub const BROWN: u8 = 6; - pub const LIGHT_GREY: u8 = 7; - pub const DARK_GREY: u8 = 8; - pub const LIGHT_BLUE: u8 = 9; - pub const LIGHT_GREEN: u8 = 10; - pub const LIGHT_CYAN: u8 = 11; - pub const LIGHT_RED: u8 = 12; - pub const LIGHT_MAGENTA: u8 = 13; - pub const LIGHT_BROWN: u8 = 14; - pub const WHITE: u8 = 15; -} +pub const VGA_COLOR_BLACK: u8 = 0; +pub const VGA_COLOR_BLUE: u8 = 1; +pub const VGA_COLOR_GREEN: u8 = 2; +pub const VGA_COLOR_CYAN: u8 = 3; +pub const VGA_COLOR_RED: u8 = 4; +pub const VGA_COLOR_MAGENTA: u8 = 5; +pub const VGA_COLOR_BROWN: u8 = 6; +pub const VGA_COLOR_LIGHT_GREY: u8 = 7; +pub const VGA_COLOR_DARK_GREY: u8 = 8; +pub const VGA_COLOR_LIGHT_BLUE: u8 = 9; +pub const VGA_COLOR_LIGHT_GREEN: u8 = 10; +pub const VGA_COLOR_LIGHT_CYAN: u8 = 11; +pub const VGA_COLOR_LIGHT_RED: u8 = 12; +pub const VGA_COLOR_LIGHT_MAGENTA: u8 = 13; +pub const VGA_COLOR_LIGHT_BROWN: u8 = 14; +pub const VGA_COLOR_WHITE: u8 = 15; pub fn put_char_by_index(index: usize, c: char, bg: u8, fg: u8) { let c16 = c as u16; @@ -30,7 +28,7 @@ pub fn put_char_by_index(index: usize, c: char, bg: u8, fg: u8) { let color16 = color as u16; unsafe { - ptr::write_volatile(VGA_BUFFER.add(index), c16 | (color16 << 8)); + write_volatile(VGA_BUFFER.add(index), c16 | (color16 << 8)); } } diff --git a/src/main.rs b/src/main.rs index ce12032..62d0ef2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,8 +7,6 @@ extern "C" fn eh_personality() {} use core::panic::PanicInfo; -use core::sync::atomic; -use core::sync::atomic::Ordering; use kernel::{start_kernel, show_error}; @@ -23,7 +21,7 @@ fn panic(info: &PanicInfo) -> ! { #[no_mangle] -fn main() -> ! { +extern "C" fn main() -> ! { start_kernel(); loop {} } \ No newline at end of file diff --git a/x86-unknown-bare_metal.json b/x86-unknown-bare_metal.json index f699c61..b797a05 100644 --- a/x86-unknown-bare_metal.json +++ b/x86-unknown-bare_metal.json @@ -1,16 +1,15 @@ { - "llvm-target": "i686-unknown-none", - "data-layout": "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128", - "arch": "x86", - "target-endian": "little", - "target-pointer-width": "32", - "target-c-int-width": "32", - "os": "none", - "executables": true, - "linker-flavor": "ld.lld", - "linker": "rust-lld", - "panic-strategy": "abort", - "disable-redzone": true, - "features": "+soft-float,-sse" - } - \ No newline at end of file + "llvm-target": "i686-unknown-none", + "data-layout": "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128", + "arch": "x86", + "target-endian": "little", + "target-pointer-width": "32", + "target-c-int-width": "32", + "os": "none", + "executables": true, + "linker-flavor": "ld.lld", + "linker": "rust-lld", + "panic-strategy": "abort", + "disable-redzone": true, + "features": "+soft-float,-sse" +}