hello world

This commit is contained in:
MeexReay 2025-01-27 23:59:29 +03:00
commit 0a34a214c1
5 changed files with 111 additions and 0 deletions

7
kernel/Cargo.lock generated Normal file
View File

@ -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"

6
kernel/Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "kernel"
version = "0.1.0"
edition = "2021"
[dependencies]

33
kernel/src/main.rs Normal file
View File

@ -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 {}
}

49
kernel/src/terminal.rs Normal file
View File

@ -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);
}
}
}

View File

@ -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"
}