more stuff!

This commit is contained in:
2026-08-21 15:24:31 -04:00
parent 58fd50a595
commit a9f3182de3
9 changed files with 116 additions and 4 deletions
+1
View File
@@ -1 +1,2 @@
/target
/tests
+13
View File
@@ -0,0 +1,13 @@
use core::arch::x86_64::__cpuid;
pub fn init() {
let cpuid = unsafe { __cpuid(0) };
let mut vendor = [0u8;12];
vendor[0..4].copy_from_slice(&cpuid.ebx.to_le_bytes());
vendor[4..8].copy_from_slice(&cpuid.edx.to_le_bytes());
vendor[8..12].copy_from_slice(&cpuid.ecx.to_le_bytes());
crate::kprintln!("CPU Vendor: {}", core::str::from_utf8(&vendor).unwrap_or("Unknown"));
}
+5 -1
View File
@@ -1 +1,5 @@
//
pub mod cpu;
pub fn init() {
cpu::init();
}
+1
View File
@@ -0,0 +1 @@
pub mod serial;
+52
View File
@@ -0,0 +1,52 @@
use core::arch::asm;
const SERIAL_COM1: u16 = 0x3F8;
pub unsafe fn init() {
outb(SERIAL_COM1 + 1, 0x00); // Disable interrupts
outb(SERIAL_COM1 + 3, 0x80);
outb(SERIAL_COM1, 0x03); // 38400 baud (divisor = 3)
outb(SERIAL_COM1 + 1, 0x00);
outb(SERIAL_COM1 + 3, 0x03);
outb(SERIAL_COM1 + 2, 0xC7);
outb(SERIAL_COM1 + 4, 0x0B);
}
pub unsafe fn write_byte(byte: u8) {
while (inb(SERIAL_COM1 + 5) & 0x20) == 0 {}
outb(SERIAL_COM1, byte);
}
pub unsafe fn write_bytes(bytes: &[u8]) {
for &byte in bytes {
write_byte(byte);
}
}
pub unsafe fn write_str(string: &str) {
write_bytes(string.as_bytes());
}
unsafe fn outb(port: u16, value: u8) {
asm!(
"out dx, al",
in("dx") port,
in("al") value,
options(nostack, nomem, preserves_flags)
);
}
unsafe fn inb(port: u16) -> u8 {
let value: u8;
unsafe {
asm!("in al, dx",in("dx") port,out("al") value,options(nostack, nomem, preserves_flags));
}
value
}
+4 -1
View File
@@ -1,3 +1,6 @@
pub fn init() {
// something something init kernel
unsafe {
crate::driver::serial::init();
}
crate::arch::x86_64::init();
}
+36
View File
@@ -0,0 +1,36 @@
use core::fmt::{self, Write};
struct Logger;
impl Write for Logger {
fn write_str(&mut self, string: &str) -> fmt::Result {
unsafe {
crate::driver::serial::write_str(string);
}
Ok(())
}
}
pub fn print(args: fmt::Arguments) {
let mut logger = Logger;
logger.write_fmt(args).ok();
}
#[macro_export]
macro_rules! kprint {
($($arg:tt)*) => {
$crate::kernel::log::print(core::format_args!($($arg)*))
};
}
#[macro_export]
macro_rules! kprintln {
() => {
$crate::kprint!("\r\n")
};
($($arg:tt)*) => {
$crate::kprint!("{}\r\n", core::format_args!($($arg)*))
};
}
+2 -1
View File
@@ -1 +1,2 @@
pub mod init;
pub mod init;
pub mod log;
+2 -1
View File
@@ -2,12 +2,13 @@
#![no_main]
mod arch;
mod driver;
mod kernel;
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
kernel::init::init();
loop {}
}