Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ qemu: iso
-drive if=pflash,format=raw,readonly=on,file=$(OVMF_CODE) \
-drive format=raw,file=$(ISO_FILE) \
-smp 4 -m 4G -cpu max -s -d unimp,guest_errors,int \
-monitor stdio \
-serial stdio \
-device qemu-xhci -device usb-kbd -audiodev pa,id=snd0 -machine pcspk-audiodev=snd0 -M q35 --no-reboot

qemu-nographic: iso # yo stop allocating so much my pc only has 8G atleast allocate 2G
Expand Down
17 changes: 17 additions & 0 deletions system/core/src/asm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mod asm {
pub fn outportb(port: u16, data: u8) {
core::arch::naked_asm!(
asm("outb %1, %0" : : "dN" (port), "a" (data));
)
}

pub fn inportb(port: u16) {
core::arch::naked_asm!(
u8 r;
asm("inb %1, %0" : "=a" (r) : "dN" (port));
return r;
)


}
}
59 changes: 59 additions & 0 deletions system/core/src/log.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
mod asm;
use asm::{inportb, outportb};

/*
How to use:
log::error(" filepath/file.rs: I don't like this variable "); --> [ERROR] filepath/file.rs: I don't like this variable.
log:warning(" filepath/file.rs: I'm so bad at rust."); --> [WARNING] filepath/file.rs: I'm so bad at rust
log::info(" filepath/file.rs: I'm so tired, stop with this.") --> [INFO] filepath/file.rs: I'm so tired of this.
*/

mod log {
fn serial_ready() -> bool {
return inportb(0x3F8 + 5) & 0x20 != 0; // check 0x3F8 is able to write.
}

fn serial_write(c: char) {
while !serial_ready() {}
outportb(0x3F8, c as u8);
}

pub fn init() {
outportb(0x3F8 + 1, 0x00); // disable interrupts

outportb(0x3F8 + 3, 0x80);
outportb(0x3F8 + 0, 0x03);
outportb(0x3F8 + 1, 0x00);
outportb(0x3F8 + 3, 0x03);
outportb(0x3F8 + 2, 0xC7);

outportb(0x3F8 + 4, 0x0B);
}

pub fn print(msg: Option<&str>) {
if msg.is_none() { return; }

for c in msg.unwrap().chars() { // write all characters one by one.. TODO: Add formatting.
serial_write(c);
}

serial_write('\n');
}

pub fn error(msg: Option<&str>) {
if let Some(txt) = msg {
print(Some(&format!("\033[31m [ERROR] \033[0m {}", txt)));
}
}
pub fn warning(msg: Option<&str>) {
if let Some(txt) = msg {
print(Some(&format!("\033[95m [WARNING] \033[0m {}", txt)));
}
}

pub fn info(msg: Option<&str>) {
if let Some(txt) = msg {
print(Some(&format!("\033[96m [INFO] \033[0m {}", txt)));
}
}
}