Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9f3182de3 | ||
|
|
58fd50a595 | ||
|
|
fefaeac362 |
@@ -0,0 +1,2 @@
|
|||||||
|
[build]
|
||||||
|
target = "x86_64-unknown-none"
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
/target
|
||||||
|
/tests
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "illuminance"
|
||||||
|
version = "1.0.0"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "illuminance"
|
||||||
|
version = "1.0.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
pub mod x86_64;
|
||||||
@@ -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"));
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
pub mod cpu;
|
||||||
|
|
||||||
|
pub fn init() {
|
||||||
|
cpu::init();
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
pub mod serial;
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
pub fn init() {
|
||||||
|
unsafe {
|
||||||
|
crate::driver::serial::init();
|
||||||
|
}
|
||||||
|
crate::arch::x86_64::init();
|
||||||
|
}
|
||||||
@@ -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)*))
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod init;
|
||||||
|
pub mod log;
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
mod arch;
|
||||||
|
mod driver;
|
||||||
|
mod kernel;
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn _start() -> ! {
|
||||||
|
kernel::init::init();
|
||||||
|
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[panic_handler] // providing a panic handler since there is no std
|
||||||
|
fn panic(_info: &core::panic::PanicInfo) -> !/*<-- function will never return (loop {} = while True(){})*/ {
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user