more modules
This commit is contained in:
parent
6aee6bd749
commit
7d247fab3c
13
.vscode/settings.json
vendored
Normal file
13
.vscode/settings.json
vendored
Normal 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
46
Cargo.lock
generated
@ -2,6 +2,52 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
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]]
|
[[package]]
|
||||||
name = "mxrox_kernel"
|
name = "mxrox_kernel"
|
||||||
version = "0.1.0"
|
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",
|
||||||
|
]
|
||||||
|
@ -4,3 +4,5 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
x86_64 = "0.15.2"
|
||||||
|
volatile = "0.6.1"
|
7
Makefile
7
Makefile
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
build/mxrox.iso: build/kernel.elf build_dir
|
build/mxrox.iso: build/kernel.elf build_dir
|
||||||
cp 'grub.cfg' build/iso/boot/grub
|
cp 'grub.cfg' build/iso/boot/grub
|
||||||
cp '$<' build/iso/bootmxrox
|
cp '$<' build/iso/boot
|
||||||
grub-mkrescue -o '$@' build/iso
|
grub-mkrescue -o '$@' build/iso
|
||||||
|
|
||||||
build/boot.o: boot.s build_dir
|
build/boot.o: boot.s build_dir
|
||||||
@ -19,7 +19,6 @@ build/kernel.o: build_dir
|
|||||||
build_dir:
|
build_dir:
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
mkdir -p build/iso
|
mkdir -p build/iso
|
||||||
mkdir -p build/iso/lib
|
|
||||||
mkdir -p build/iso/boot
|
mkdir -p build/iso/boot
|
||||||
mkdir -p build/iso/boot/grub
|
mkdir -p build/iso/boot/grub
|
||||||
|
|
||||||
@ -27,8 +26,8 @@ build: build/mxrox.iso
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf build
|
rm -rf build
|
||||||
rm -rf target
|
# rm -rf target
|
||||||
rm -rf Cargo.lock
|
# rm -rf Cargo.lock
|
||||||
mkdir build
|
mkdir build
|
||||||
|
|
||||||
run-kernel: build/kernel.elf
|
run-kernel: build/kernel.elf
|
||||||
|
0
src/kernel/acpi.rs
Normal file
0
src/kernel/acpi.rs
Normal file
14
src/kernel/mod.rs
Normal file
14
src/kernel/mod.rs
Normal 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
23
src/kernel/ps2.rs
Normal 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
0
src/kernel/thread.rs
Normal file
@ -1,6 +1,7 @@
|
|||||||
pub const TERMINAL_BUFFER: *mut u16 = 0xB8000 as *mut u16;
|
const VGA_BUFFER: *mut u16 = 0xB8000 as *mut u16;
|
||||||
pub const TERMINAL_WIDTH: usize = 80;
|
|
||||||
pub const TERMINAL_HEIGHT: usize = 25;
|
pub const VGA_WIDTH: usize = 80;
|
||||||
|
pub const VGA_HEIGHT: usize = 25;
|
||||||
|
|
||||||
pub struct VgaColor(u8);
|
pub struct VgaColor(u8);
|
||||||
|
|
||||||
@ -23,27 +24,38 @@ impl VgaColor {
|
|||||||
pub const WHITE: u8 = 15;
|
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 c16 = c as u16;
|
||||||
let color = fg | bg << 4;
|
let color = fg | bg << 4;
|
||||||
let color16 = color as u16;
|
let color16 = color as u16;
|
||||||
let index = y * TERMINAL_WIDTH + x;
|
|
||||||
|
|
||||||
unsafe {
|
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) {
|
pub fn put_string(x: usize, y: usize, text: &str, bg: u8, fg: u8) {
|
||||||
for (i, c) in text.char_indices() {
|
put_string_by_index(y * VGA_WIDTH + x, text, bg, fg)
|
||||||
put_char(x+i, y, c, bg, fg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fill(c: char, bg: u8, fg: u8) {
|
pub fn fill(c: char, bg: u8, fg: u8) {
|
||||||
for x in 0..TERMINAL_WIDTH {
|
for x in 0..VGA_WIDTH {
|
||||||
for y in 0..TERMINAL_HEIGHT {
|
for y in 0..VGA_HEIGHT {
|
||||||
put_char(x, y, c, bg, fg);
|
put_char(x, y, c, bg, fg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn fill_with_color(color: u8) {
|
||||||
|
fill(' ', color, 0)
|
||||||
|
}
|
18
src/main.rs
18
src/main.rs
@ -10,24 +10,20 @@ use core::panic::PanicInfo;
|
|||||||
use core::sync::atomic;
|
use core::sync::atomic;
|
||||||
use core::sync::atomic::Ordering;
|
use core::sync::atomic::Ordering;
|
||||||
|
|
||||||
|
use kernel::{start_kernel, show_error};
|
||||||
|
|
||||||
|
mod kernel;
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(_info: &PanicInfo) -> ! {
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
loop {
|
show_error(info.message().as_str().unwrap_or("mxrox death"));
|
||||||
atomic::compiler_fence(Ordering::SeqCst);
|
loop {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mod terminal;
|
|
||||||
|
|
||||||
use terminal::{fill, put_string, VgaColor};
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
fill(' ', VgaColor::BLACK, VgaColor::BLACK);
|
start_kernel();
|
||||||
put_string(0, 0, "Hello World from MxRox!", VgaColor::BLACK, VgaColor::WHITE);
|
|
||||||
|
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user