commit 0a34a214c1e05a7aafb73ee925efb391ab25b64e Author: MeexReay Date: Mon Jan 27 23:59:29 2025 +0300 hello world diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock new file mode 100644 index 0000000..45dc146 --- /dev/null +++ b/kernel/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "kernel" +version = "0.1.0" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml new file mode 100644 index 0000000..f84cf70 --- /dev/null +++ b/kernel/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "kernel" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/kernel/src/main.rs b/kernel/src/main.rs new file mode 100644 index 0000000..8def41f --- /dev/null +++ b/kernel/src/main.rs @@ -0,0 +1,33 @@ +#![no_std] +#![no_main] + +#![feature(lang_items)] + +#[lang = "eh_personality"] +extern "C" fn eh_personality() {} + +use core::panic::PanicInfo; +use core::sync::atomic; +use core::sync::atomic::Ordering; + + +#[inline(never)] +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + loop { + atomic::compiler_fence(Ordering::SeqCst); + } +} + + +mod terminal; + +use terminal::{fill, put_string, VgaColor}; + +#[no_mangle] +fn main() -> ! { + fill(' ', VgaColor::BLACK, VgaColor::BLACK); + put_string(0, 0, "Hello World from MxRox!", VgaColor::BLACK, VgaColor::WHITE); + + loop {} +} \ No newline at end of file diff --git a/kernel/src/terminal.rs b/kernel/src/terminal.rs new file mode 100644 index 0000000..b56c6b5 --- /dev/null +++ b/kernel/src/terminal.rs @@ -0,0 +1,49 @@ +pub const TERMINAL_BUFFER: *mut u16 = 0xB8000 as *mut u16; +pub const TERMINAL_WIDTH: usize = 80; +pub const TERMINAL_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 fn put_char(x: usize, y: usize, c: char, bg: u8, fg: u8) { + let c16 = c as u16; + let color = fg | bg << 4; + let color16 = color as u16; + let index = y * TERMINAL_WIDTH + x; + + unsafe { + *TERMINAL_BUFFER.add(index) = c16 | (color16 << 8) + } +} + +pub fn put_string(x: usize, y: usize, text: &str, bg: u8, fg: u8) { + for (i, c) in text.char_indices() { + put_char(x+i, y, c, bg, fg); + } +} + +pub fn fill(c: char, bg: u8, fg: u8) { + for x in 0..TERMINAL_WIDTH { + for y in 0..TERMINAL_HEIGHT { + put_char(x, y, c, bg, fg); + } + } +} \ No newline at end of file diff --git a/kernel/x86-unknown-bare_metal.json b/kernel/x86-unknown-bare_metal.json new file mode 100644 index 0000000..f699c61 --- /dev/null +++ b/kernel/x86-unknown-bare_metal.json @@ -0,0 +1,16 @@ +{ + "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