Skip to content

Commit

Permalink
Vga graphics (#14)
Browse files Browse the repository at this point in the history
* green screen

* somewhat working

* back to text

* cleanup

* small syscall to draw pixels from userspace
  • Loading branch information
jbreu authored May 4, 2024
1 parent e220ddc commit a39156c
Show file tree
Hide file tree
Showing 7 changed files with 767 additions and 11 deletions.
12 changes: 1 addition & 11 deletions kernel/src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::kprint;
use crate::kprintln;
use crate::time;
use crate::userland;
use crate::util::out_port_b;
use crate::USERLAND;
use core::arch::asm;
use core::arch::global_asm;
Expand Down Expand Up @@ -138,17 +139,6 @@ pub extern "C" fn irq_handler(int_no: u64) {
out_port_b(0x20, 0x20);
}

fn out_port_b(port: u16, value: u8) {
unsafe {
asm!(
r#"out %al, %dx"#,
in("dx") port,
in("al") value,
options(att_syntax)
);
}
}

fn set_idt_gate(num: usize, base: u64, sel: u16, flags: u8) {
unsafe {
IDT_ENTRIES[num].base_low = (base & 0xFFFF) as u16;
Expand Down
8 changes: 8 additions & 0 deletions kernel/src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ mod process;
mod syscall;
mod time;
mod userland;
mod util;
mod vga;

/// This function is called on panic.
#[panic_handler]
Expand All @@ -38,6 +40,12 @@ pub extern "C" fn kernel_main() -> ! {
kprintln!("successfull boot!");
kprintln!("Hellö Wörld!");

vga::vga_enter();
vga::vga_clear_screen();

//vga::vga_exit();
//kprintln!("Back in text mode");

// Trigger test exception
//unsafe {
// asm!("int3", options(nomem, nostack));
Expand Down
22 changes: 22 additions & 0 deletions kernel/src/syscall.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::vga::{vga_flip, vga_plot_pixel};
use crate::USERLAND;
use crate::{kprintln, logging::log};
use core::arch::asm;
Expand All @@ -16,13 +17,34 @@ pub extern "C" fn system_call() -> u64 {
match syscall_nr {
1 => return syscall_write(),
2 => return syscall_getpid(),
3 => return syscall_plot_pixel(),
_ => {
kprintln!("Undefined system call triggered");
return 0xdeadbeef;
}
}
}

fn syscall_plot_pixel() -> u64 {
let mut x: u32;
let mut y: u32;
let mut color: u32;

unsafe {
// TODO this must be possible more elegantly
asm!("",
out("r8") x,
out("r9") y,
out("r10") color
);
}

vga_plot_pixel(x, y, color as u8);
vga_flip();

return 0;
}

fn syscall_getpid() -> u64 {
USERLAND.lock().get_current_process_id() as u64
}
Expand Down
20 changes: 20 additions & 0 deletions kernel/src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use core::arch::asm;

pub fn out_port_b(port: u32, value: u8) {
unsafe {
asm!(
r#"out %al, %dx"#,
in("edx") port,
in("al") value,
options(att_syntax)
);
}
}

pub fn in_port_b(port: u32) -> u8 {
let mut key;
unsafe {
asm!("in al, dx", out("al") key, in("rdx") port);
}
return key;
}
Loading

0 comments on commit a39156c

Please sign in to comment.