Skip to content
Open
1 change: 1 addition & 0 deletions files.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ RUST_SRCS = main.rs \
task.rs \
signal.rs \
queue.rs \
kinit.rs\
errno.rs \
debug.rs\
$(SYSCALL_SRCS) \
Expand Down
13 changes: 6 additions & 7 deletions srcs/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use crate::string::{String, ToString};
use crate::syscalls::exit::sys_waitpid;
use crate::syscalls::signal::sys_kill;
use crate::vec::Vec;
use crate::vga_buffer::{hexdump, screenclear};
use crate::{io, kprint, kprintln};
use crate::vga_buffer::screenclear;
use crate::x86::io;
use crate::{kprint, kprintln};

const NB_CMDS: usize = 13;

Expand All @@ -34,9 +35,8 @@ const KNOWN_CMD: [&str; NB_CMDS] = [
];

fn kill(command: Vec<String>) {
let mut count: usize = 0;
let mut wstatus: i32 = 0;
let mut pid: Pid = 0;
let pid: Pid;

if command.len() != 2 {
kprintln!("Invalid argument.");
Expand Down Expand Up @@ -167,13 +167,12 @@ fn hexdump_parser(command: Vec<String>) {
return;
}

hexdump(args[0] as *const u8, args[1]);
crate::vga_buffer::hexdump(args[0] as *const u8, args[1]);
}

use crate::keyboard::{KEYMAP, KEYMAP_FR, KEYMAP_US};

fn keymap(command: Vec<String>) {
let mut count: usize = 0;

if command.len() != 2 {
kprintln!("Invalid number of arguments.");
Expand All @@ -196,7 +195,7 @@ extern "C" {
}

fn interrupt(command: Vec<String>) {
let mut arg: usize = 0;
let arg: usize;

if command.len() != 2 {
kprintln!("Invalid number of arguments.");
Expand Down
2 changes: 1 addition & 1 deletion srcs/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl fmt::Write for DWriter {
/// Send to SERIAL_COM2 all bytes from s
fn write_str(&mut self, s: &str) -> fmt::Result {
for i in s.bytes() {
crate::io::outb(SERIAL_COM2, i);
crate::x86::io::outb(SERIAL_COM2, i);
}
Ok(())
}
Expand Down
46 changes: 7 additions & 39 deletions srcs/interrupts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,16 @@
//! Setup interrupts and exception handler
use crate::x86::interrupt::{
EXCEPTION_SIZE,
IDT_MAX_DESCRIPTORS,
IDT_SIZE,
STR_EXCEPTION
};

use crate::proc::process::Status;
use crate::proc::task::{schedule_task, switch_task, Task};
use crate::proc::task::{switch_task, Task};
use crate::syscalls::syscall_handler;

const GDT_OFFSET_KERNEL_CODE: u16 = 0x08;
const IDT_SIZE: usize = 48;
const IDT_MAX_DESCRIPTORS: usize = 256;

const EXCEPTION_SIZE: usize = 32;
const STR_EXCEPTION: [&'static str; EXCEPTION_SIZE] = [
"Divide-by-zero",
"Debug",
"Non-maskable Interrupt",
"Breakpoint",
"Overflow",
"Bound Range Exceeded",
"Invalid Opcode",
"Device Not Available",
"Double Fault",
"Coprocessor Segment Overrun",
"Invalid TSS",
"Segment Not Present",
"Stack-Segment Fault",
"General Protection Fault",
"Page Fault",
"Reserved",
"x87 Floating-Point Exception",
"Alignment Check",
"Machine Check",
"SIMD Floating-Point Exception",
"Virtualization Exception",
"Control Protection Exception",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Hypervisor Injection Exception",
"VMM Communication Exception",
"Security Exception",
"Reserved"
];

extern "C" {
static mut isr_stub_table: [u32; IDT_SIZE];
Expand Down
3 changes: 2 additions & 1 deletion srcs/keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Keyboard handler and key mapping

use crate::vga_buffer::NB_SCREEN;
use crate::{io, kprint, vga_buffer};
use crate::x86::io;
use crate::vga_buffer;

const PRESSED: usize = 0;
const RELEASED: usize = 1;
Expand Down
2 changes: 1 addition & 1 deletion srcs/kinit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ mod string;
mod vec;
#[macro_use]
mod syscalls;
mod io;
mod pic;
mod proc;
mod user;
Expand All @@ -88,6 +87,7 @@ mod errno;
mod sound;
mod spin;
mod utils;
mod x86;
#[macro_use]
mod debug;

Expand Down
28 changes: 3 additions & 25 deletions srcs/memory/paging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn init_paging() {
bitmap::physmap_as_mut().get_page().unwrap();
// Use identity mapping to setup kernel page
let init_pt_paddr: PhysAddr = pd_paddr + 0x1000;
let mut init_page_tab: &mut PageTable = &mut *(init_pt_paddr as *mut _);
let init_page_tab: &mut PageTable = &mut *(init_pt_paddr as *mut _);
init_page_tab
.set_entry(768, kernel_pt_paddr | PAGE_WRITABLE | PAGE_PRESENT);
refresh_tlb!();
Expand Down Expand Up @@ -126,27 +126,5 @@ macro_rules! get_vaddr {
};
}

macro_rules! refresh_tlb {
() => {
core::arch::asm!("mov eax, cr3", "mov cr3, eax")
};
}

#[allow(unused)]
macro_rules! enable_paging {
($page_directory:expr) => (core::arch::asm!("mov eax, {p}",
"mov cr3, eax",
"mov eax, cr0",
"or eax, 0x80000001",
"mov cr0, eax",
p = in(reg) (&$page_directory as *const _) as usize););
}

#[allow(unused)]
macro_rules! disable_paging {
() => {
core::arch::asm!("mov ebx, cr0", "and ebx, ~(1 << 31)", "mov cr0, ebx")
};
}

pub(crate) use {get_paddr, get_vaddr, refresh_tlb};
pub(crate) use crate::refresh_tlb;
pub(crate) use {get_paddr, get_vaddr};
3 changes: 1 addition & 2 deletions srcs/pic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Setup Programmable Interrupt Controller

use crate::io::{inb, io_wait, outb};
use crate::x86::io::{inb, io_wait, outb};

pub mod handlers;
pub mod pit;
Expand Down
26 changes: 15 additions & 11 deletions srcs/pic/pit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::io::{inb, outb};

use crate::x86::io::{inb, outb};
use crate::x86::port::PortWriteOnly;
// I/O port Usage
// 0x40 Channel 0 data port (read/write)
// 0x41 Channel 1 data port (read/write)
Expand Down Expand Up @@ -89,18 +89,22 @@ pub fn set_irq0_in_ms(ms: f32) {
}

pub fn set_pit(channel: u8, access: u8, mode: u8, data: u16) {
let port: u16 = match channel {
CHANNEL_0 => CHAN0_DATA.into(),
CHANNEL_1 => CHAN1_DATA.into(),
CHANNEL_2 => CHAN2_DATA.into(),
let mut cmd_port: PortWriteOnly<u8> = PortWriteOnly::new(MODE_CMD as u16);

let mut data_port: PortWriteOnly<u8> = match channel {
CHANNEL_0 => PortWriteOnly::new(CHAN0_DATA.into()),
CHANNEL_1 => PortWriteOnly::new(CHAN1_DATA.into()),
CHANNEL_2 => PortWriteOnly::new(CHAN2_DATA.into()),
_ => panic!("PIT Channel {channel} doesn't exist")
};
// Set cmd mod selected
outb(MODE_CMD as u16, channel | access | mode);
unsafe {
// Set cmd mod selected
cmd_port.write(channel | access | mode);

// Sending data to commands
outb(port, (data & 0xff) as u8);
outb(port, ((data & 0xff00) >> 8) as u8);
// Sending data to commands
data_port.write((data & 0xff) as u8);
data_port.write((data >> 8) as u8);
}
}

pub fn play_sound(frequency: f32) {
Expand Down
2 changes: 1 addition & 1 deletion srcs/proc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@ pub fn change_kernel_stack(addr: VirtAddr) {
get_paddr!(addr),
PAGE_WRITABLE | PAGE_GLOBAL
);
refresh_tlb!();
crate::refresh_tlb!();
}
}
2 changes: 1 addition & 1 deletion srcs/proc/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Task {
get_paddr!(MASTER_PROCESS.kernel_stack.offset),
PAGE_WRITABLE
);
refresh_tlb!();
crate::refresh_tlb!();
MASTER_PROCESS.stack = <MemoryZone as Stack>::init_addr(
stack_addr,
0x1000,
Expand Down
8 changes: 4 additions & 4 deletions srcs/sound/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::main::sleep;
use crate::pic::pit::{play_sound, speaker_off, speaker_on};
use crate::pic::pit::{speaker_off, speaker_on};
use crate::vec::Vec;

mod notes_frequencies;
Expand Down Expand Up @@ -52,7 +52,7 @@ impl Partition {
note_tempo: NoteTempo,
note_type: NoteType
) -> &mut Self {
let mut duration: usize = match note_tempo {
let duration: usize = match note_tempo {
NoteTempo::WHOLE => self.whole_note_duration,
NoteTempo::HALF => self.half_note_duration,
NoteTempo::QUARTER => self.quarter_note_duration,
Expand All @@ -79,7 +79,7 @@ impl Partition {
frequencies: (f32, f32, f32),
note_tempo: NoteTempo
) {
let mut duration: usize = match note_tempo {
let duration: usize = match note_tempo {
NoteTempo::WHOLE => self.whole_note_duration,
NoteTempo::HALF => self.half_note_duration,
NoteTempo::QUARTER => self.quarter_note_duration,
Expand All @@ -98,7 +98,7 @@ impl Partition {
note_tempo: NoteTempo,
div: usize
) {
let mut duration: usize = match note_tempo {
let duration: usize = match note_tempo {
NoteTempo::WHOLE => self.whole_note_duration,
NoteTempo::HALF => self.half_note_duration,
NoteTempo::QUARTER => self.quarter_note_duration,
Expand Down
1 change: 1 addition & 0 deletions srcs/sound/notes_frequencies.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(non_upper_case_globals)]
pub const C2: f32 = 65.41;
pub const Cs2: f32 = 69.30;
pub const Db2: f32 = Cs2;
Expand Down
8 changes: 4 additions & 4 deletions srcs/sound/overworld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Partition {
partition.add_note(G5, NoteTempo::QUARTER, NoteType::BASE);
partition.add_note(G4, NoteTempo::QUARTER, NoteType::BASE);

for i in 0..2 {
for _ in 0..2 {
partition.add_note(C5, NoteTempo::EIGTH, NoteType::DOTTED);
partition.add_note(G4, NoteTempo::EIGTH, NoteType::DOTTED);
partition.add_note(E4, NoteTempo::EIGTH, NoteType::BASE);
Expand All @@ -38,7 +38,7 @@ impl Partition {
}

// B
for i in 0..2 {
for _ in 0..2 {
partition.add_note(Rest, NoteTempo::EIGTH, NoteType::BASE);
partition.add_note(G5, NoteTempo::SIXTEENTH, NoteType::BASE);
partition.add_note(Gb5, NoteTempo::SIXTEENTH, NoteType::BASE);
Expand Down Expand Up @@ -138,7 +138,7 @@ impl Partition {
partition.add_note(G4, NoteTempo::QUARTER, NoteType::BASE);

// A'
for i in 0..2 {
for _ in 0..2 {
partition.add_note(C5, NoteTempo::EIGTH, NoteType::DOTTED);
partition.add_note(G4, NoteTempo::EIGTH, NoteType::DOTTED);
partition.add_note(E4, NoteTempo::EIGTH, NoteType::BASE);
Expand All @@ -160,7 +160,7 @@ impl Partition {
}

// D
for i in 0..2 {
for _ in 0..2 {
partition.add_note(E5, NoteTempo::SIXTEENTH, NoteType::BASE);
partition.add_note(C5, NoteTempo::EIGTH, NoteType::BASE);
partition.add_note(G4, NoteTempo::EIGTH, NoteType::DOTTED);
Expand Down
3 changes: 2 additions & 1 deletion srcs/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::vga_buffer::color::Color;
use crate::{io, vga_buffer, KTRACKER};
use crate::x86::io;
use crate::{vga_buffer, KTRACKER};

#[cfg(test)]
#[macro_export]
Expand Down
2 changes: 1 addition & 1 deletion srcs/vga_buffer/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::io;
use crate::vga_buffer::{ColorCode, BUFFER_WIDTH};
use crate::x86::io;

#[derive(Debug, Clone, Copy)]
pub struct Cursor {
Expand Down
3 changes: 2 additions & 1 deletion srcs/vga_buffer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Handler for vga buffer

use crate::{io, Command};
use crate::x86::io;
use crate::Command;
use core::fmt;
use core::fmt::Write;
use core::panic::PanicInfo;
Expand Down
38 changes: 38 additions & 0 deletions srcs/x86/interrupt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
pub const IDT_SIZE: usize = 48;
pub const IDT_MAX_DESCRIPTORS: usize = 256;

pub const EXCEPTION_SIZE: usize = 32;
pub const STR_EXCEPTION: [&'static str; EXCEPTION_SIZE] = [
"Divide-by-zero",
"Debug",
"Non-maskable Interrupt",
"Breakpoint",
"Overflow",
"Bound Range Exceeded",
"Invalid Opcode",
"Device Not Available",
"Double Fault",
"Coprocessor Segment Overrun",
"Invalid TSS",
"Segment Not Present",
"Stack-Segment Fault",
"General Protection Fault",
"Page Fault",
"Reserved",
"x87 Floating-Point Exception",
"Alignment Check",
"Machine Check",
"SIMD Floating-Point Exception",
"Virtualization Exception",
"Control Protection Exception",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Hypervisor Injection Exception",
"VMM Communication Exception",
"Security Exception",
"Reserved"
];
File renamed without changes.
Loading