more modules

This commit is contained in:
MeexReay 2025-01-29 01:49:10 +03:00
parent 6aee6bd749
commit 7d247fab3c
10 changed files with 132 additions and 27 deletions

13
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,13 @@
{
"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"
]
}

46
Cargo.lock generated
View File

@ -2,6 +2,52 @@
# It is not intended for manual editing.
version = 4
[[package]]
name = "bit_field"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
[[package]]
name = "bitflags"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
[[package]]
name = "mxrox_kernel"
version = "0.1.0"
dependencies = [
"volatile 0.6.1",
"x86_64",
]
[[package]]
name = "rustversion"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4"
[[package]]
name = "volatile"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793"
[[package]]
name = "volatile"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af8ca9a5d4debca0633e697c88269395493cebf2e10db21ca2dbde37c1356452"
[[package]]
name = "x86_64"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f042214de98141e9c8706e8192b73f56494087cc55ebec28ce10f26c5c364ae"
dependencies = [
"bit_field",
"bitflags",
"rustversion",
"volatile 0.4.6",
]

View File

@ -4,3 +4,5 @@ version = "0.1.0"
edition = "2021"
[dependencies]
x86_64 = "0.15.2"
volatile = "0.6.1"

View File

@ -2,7 +2,7 @@
build/mxrox.iso: build/kernel.elf build_dir
cp 'grub.cfg' build/iso/boot/grub
cp '$<' build/iso/bootmxrox
cp '$<' build/iso/boot
grub-mkrescue -o '$@' build/iso
build/boot.o: boot.s build_dir
@ -19,7 +19,6 @@ build/kernel.o: build_dir
build_dir:
mkdir -p build
mkdir -p build/iso
mkdir -p build/iso/lib
mkdir -p build/iso/boot
mkdir -p build/iso/boot/grub
@ -27,8 +26,8 @@ build: build/mxrox.iso
clean:
rm -rf build
rm -rf target
rm -rf Cargo.lock
# rm -rf target
# rm -rf Cargo.lock
mkdir build
run-kernel: build/kernel.elf

0
src/kernel/acpi.rs Normal file
View File

14
src/kernel/mod.rs Normal file
View File

@ -0,0 +1,14 @@
use vga::{fill, fill_with_color, put_char, put_string_by_index, read_char, VgaColor};
mod vga;
mod ps2;
mod acpi;
mod thread;
pub fn show_error(message: &str) {
put_string_by_index(0, message, VgaColor::BLACK, VgaColor::LIGHT_RED);
}
pub fn start_kernel() {
fill_with_color(VgaColor::BLACK);
}

23
src/kernel/ps2.rs Normal file
View File

@ -0,0 +1,23 @@
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!()
}
fn read_ps2_data() -> u8 {
todo!()
}
fn send_ps2_command(command: u8) {
todo!()
}
fn read_ps2_status() -> u8 {
todo!()
}
/// returns device type bytes
fn init_ps2_controller() -> vec![u8; 2] {
todo!()
}

0
src/kernel/thread.rs Normal file
View File

View File

@ -1,6 +1,7 @@
pub const TERMINAL_BUFFER: *mut u16 = 0xB8000 as *mut u16;
pub const TERMINAL_WIDTH: usize = 80;
pub const TERMINAL_HEIGHT: usize = 25;
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);
@ -23,27 +24,38 @@ impl VgaColor {
pub const WHITE: u8 = 15;
}
pub fn put_char(x: usize, y: usize, c: char, bg: u8, fg: u8) {
pub fn put_char_by_index(index: 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)
ptr::write_volatile(VGA_BUFFER.add(index), c16 | (color16 << 8));
}
}
pub fn put_char(x: usize, y: usize, c: char, bg: u8, fg: u8) {
put_char_by_index(y * VGA_WIDTH + x, c, bg, fg)
}
pub fn put_string_by_index(index: usize, text: &str, bg: u8, fg: u8) {
for (i, c) in text.char_indices() {
put_char_by_index(index + i, c, bg, fg);
}
}
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);
}
put_string_by_index(y * VGA_WIDTH + x, text, bg, fg)
}
pub fn fill(c: char, bg: u8, fg: u8) {
for x in 0..TERMINAL_WIDTH {
for y in 0..TERMINAL_HEIGHT {
for x in 0..VGA_WIDTH {
for y in 0..VGA_HEIGHT {
put_char(x, y, c, bg, fg);
}
}
}
pub fn fill_with_color(color: u8) {
fill(' ', color, 0)
}

View File

@ -10,24 +10,20 @@ use core::panic::PanicInfo;
use core::sync::atomic;
use core::sync::atomic::Ordering;
use kernel::{start_kernel, show_error};
mod kernel;
#[inline(never)]
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {
atomic::compiler_fence(Ordering::SeqCst);
}
fn panic(info: &PanicInfo) -> ! {
show_error(info.message().as_str().unwrap_or("mxrox death"));
loop {}
}
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);
start_kernel();
loop {}
}