Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/arch/i686/interrupts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod exceptions;
pub mod idt;
mod irq;
mod pic;
mod software;

#[inline(always)]
pub unsafe fn init()
Expand Down Expand Up @@ -86,6 +87,10 @@ pub unsafe extern "C" fn interrupt_handler(state: &State)
{
irq::handler(state);
}
0x30 | 0x80 =>
{
software::handler(state);
}
_ =>
{
crate::serial_println!("Got unhandled interrupt {:02x}", interrupt);
Expand Down
51 changes: 51 additions & 0 deletions src/arch/i686/interrupts/software.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use super::State;

use core::slice;

#[derive(Copy, Clone)]
pub struct Syscall
{
name: &'static str,
pub handler: unsafe fn(u32, u32, u32)
}

pub static SYSCALLS: [Syscall; 2] =
[
Syscall {name: "read", handler: sys_dummy},
Syscall {name: "write", handler: sys_write}
];


pub unsafe fn handler(state: &State)
{
syscall(state.eax, state.ebx, state.ecx, state.edx);
}

unsafe fn syscall(syscall_number: u32, arg1: u32, arg2: u32, arg3: u32)
{
if (syscall_number as usize) < SYSCALLS.len()
{
let syscall = SYSCALLS[syscall_number as usize];
crate::serial_println!("Called syscall {}({}, {}, {})", syscall.name, arg1, arg2, arg3);
(syscall.handler)(arg1, arg2, arg3);
}
else
{
panic!("Invalid syscall {}({}, {}, {})", syscall_number, arg1, arg2, arg3);
}
}

unsafe fn sys_dummy(_arg1: u32, _arg2: u32, _arg3: u32)
{

}

unsafe fn sys_write(_file_descriptor: u32, buffer: u32, len: u32)
{
let len = len as usize;
let buffer = slice::from_raw_parts(buffer as *const u8, len);
for i in 0..len
{
crate::log!("{}", buffer[i] as char);
}
}
8 changes: 7 additions & 1 deletion src/elsos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ pub extern "C" fn kernel_main(magic: u32, address: u32)
logln!(" #+# #+# :` .'._.'. `; Willkumme uf elsOS {}.{}.{}{}", VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION);
logln!(" ### ######### '-`'.___.'`-' Hello, kernel world !");
logln!();
tests();
tty::prompt();
unsafe
{
arch::interrupts::init();
arch::interrupts::enable();
}
tests();
loop
{
arch::halt();
Expand All @@ -72,6 +72,12 @@ pub extern "C" fn kernel_main(magic: u32, address: u32)
fn tests()
{
// put tests here
unsafe
{
let text = [b'H', b'e', b'l', b'l', b'o', b'\n'];
let len = 6;
ferramenta::syscall(1, 0, &text as *const _ as u32, len);
}
}

fn init_vga()
Expand Down
16 changes: 15 additions & 1 deletion src/ferramenta.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use core::slice;
use crate::memory;

use core::slice;
use core::arch::asm;

pub fn shutdown_qemu()
{
crate::arch::port::outw(0x604, 0x2000);
Expand Down Expand Up @@ -93,6 +95,18 @@ pub unsafe fn print_memory_bin(ptr: *const u8, n: usize)
crate::logln!();
}

pub unsafe fn syscall(syscall_number: u32, arg1: u32, arg2: u32, arg3: u32) -> u32
{
let ret: u32;
asm!("int 0x80",
in("eax") syscall_number,
in("ebx") arg1,
in("ecx") arg2,
in("edx") arg3,
lateout("eax") ret);
ret
}

#[macro_export]
macro_rules! get_reg
{
Expand Down