Skip to content
Open
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
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[unstable]
build-std = ["core", "compiler_builtins", "alloc"]
build-std-features = ["compiler-builtins-mem"]
bindeps = true
5 changes: 4 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
[workspace.package]
version = "0.4.0"
authors = ["Gianmatteo Palmieri <[email protected]>"]
edition = "2021"
edition = "2024"

[profile.dev]
panic = "abort"
Expand Down
2 changes: 1 addition & 1 deletion boot/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ fn main() {
"cargo:rustc-link-arg-bins=--script={}",
local_path.join("linker.ld").display()
);
}
}
10 changes: 5 additions & 5 deletions boot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ const BOOTLOADER_SIZE: u16 = 64; //bootloader size in sectors
//set data segments to zero and setup stack
global_asm!(include_str!("boot.asm"));

extern "C" {
unsafe extern "C" {
static _bootloader_start: u16;
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn main() -> ! {
clear();

Expand Down Expand Up @@ -56,15 +56,15 @@ fn print(message: &str) {
"2:",
"lodsb", //load a byte (next character) from si to al
"or al, al", //bitwise or on al, if al is null set zf to true
"jz 1f", //if zf is true (end of string) jump to end
"jz 3f", //if zf is true (end of string) jump to end

"mov ah, 0x0e",
"mov bh, 0",
"out 0xe9, al", //e9 port hack
"int 0x10", //tell the bios to write content of al to screen

"jmp 2b", //start again
"1:",
"3:",
in(reg) message.as_ptr());
}
}
Expand All @@ -76,7 +76,7 @@ fn jump(address: *const u16) {
}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn fail() -> ! {
print("[!] Failed loading bootloader!");

Expand Down
3 changes: 3 additions & 0 deletions bootloader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ authors.workspace = true
edition.workspace = true

[dependencies]

[dependencies.libfelix]
path = "../lib"
5 changes: 2 additions & 3 deletions bootloader/src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

use core::arch::asm;
use core::mem;
use libfelix::mutex::Mutex;

//Warning! Mutable static here
//TODO: Implement a mutex to get safe access to this
pub static mut DISK: Disk = Disk { lba: 0, buffer: 0 };
pub static mut DISK: Mutex<Disk> = Mutex::new(Disk { lba: 0, buffer: 0 });

const SECTOR_SIZE: u64 = 512;

Expand Down
16 changes: 10 additions & 6 deletions bootloader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fn panic(info: &PanicInfo) -> ! {
}

//bootloader entry point
#[no_mangle]
#[link_section = ".start"]
#[unsafe(no_mangle)]
#[unsafe(link_section = ".start")]
pub extern "C" fn _start() -> ! {
//uncomment to enable splashscreen
//clear!();
Expand All @@ -46,10 +46,14 @@ pub extern "C" fn _start() -> ! {
print!("[!] Loading kernel");

unsafe {
DISK.init(KERNEL_LBA, KERNEL_BUFFER);
DISK.read_sectors(KERNEL_SIZE, KERNEL_TARGET);

(*(&raw mut DISK)).acquire_mut().init(KERNEL_LBA, KERNEL_BUFFER);
(*(&raw mut DISK)).free();

(*(&raw mut DISK)).acquire_mut().read_sectors(KERNEL_SIZE, KERNEL_TARGET);
(*(&raw mut DISK)).free();
}

println!("[!] Kernel loaded to memory.");

//load dgt
Expand All @@ -65,7 +69,7 @@ pub extern "C" fn _start() -> ! {
loop {}
}

#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn fail() -> ! {
println!("[!] Read fail!");

Expand Down
13 changes: 8 additions & 5 deletions bootloader/src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

use core::arch::asm;
use core::fmt;
use libfelix::mutex::Mutex;

//Warning! Mutable static here
//TODO: Implement a mutex to get safe access to this
pub static mut PRINTER: Printer = Printer {};
pub static mut PRINTER: Mutex<Printer> = Mutex::new(Printer {});

pub struct Printer {}

Expand Down Expand Up @@ -80,14 +79,18 @@ macro_rules! println {
pub fn _print(args: fmt::Arguments) {
use core::fmt::Write;
unsafe {
PRINTER.write_fmt(args).unwrap();
let printer = (*(&raw mut PRINTER)).acquire_mut();
printer.write_fmt(args).unwrap();
(*(&raw mut PRINTER)).free();
}
}

#[allow(dead_code)]
pub fn _clear() {
unsafe {
PRINTER.clear();
let printer = (*(&raw mut PRINTER)).acquire_mut();
printer.clear();
(*(&raw mut PRINTER)).free();
}
}

Expand Down
5 changes: 2 additions & 3 deletions kernel/src/drivers/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
//Driver for ATA disk supporting PIO MODE

use core::arch::asm;
use libfelix::mutex::Mutex;

//Warning! Mutable static here
//TODO: Implement a mutex to get safe access to this
pub static mut DISK: Disk = Disk { enabled: false };
pub static mut DISK: Mutex<Disk> = Mutex::new(Disk { enabled: false });

//controller registers ports
const DATA_REGISTER: u16 = 0x1f0;
Expand Down
71 changes: 39 additions & 32 deletions kernel/src/drivers/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

use crate::drivers::pic::PICS;
use crate::shell::shell::SHELL;
use core::arch::asm;
use crate::libfelix::mutex::Mutex;
use core::arch::{asm, naked_asm};

//Warning! Mutable static here
//TODO: Implement a mutex to get safe access to this
pub static mut KEYBOARD: Keyboard = Keyboard { lshift: false };
pub static mut KEYBOARD: Mutex<Keyboard> = Mutex::new(Keyboard { lshift: false });

pub const KEYBOARD_INT: u8 = 33;
pub const KEYBAORD_CONTROLLER: u8 = 0x60;
Expand All @@ -18,30 +17,27 @@ pub struct Keyboard {
}

//keyboard handler
#[naked]
#[unsafe(naked)]
pub extern "C" fn keyboard() {
unsafe {
//push charset to keyboard handler before calling
asm!(
"push 0x6d6e6276",
"push 0x63787a6c",
"push 0x6b6a6867",
"push 0x66647361",
"push 0x706f6975",
"push 0x79747265",
"push 0x77713039",
"push 0x38373635",
"push 0x34333231",
"call keyboard_handler",
"add esp, 36",
"iretd",
options(noreturn)
);
}
//push charset to keyboard handler before calling
naked_asm!(
"push 0x6d6e6276",
"push 0x63787a6c",
"push 0x6b6a6867",
"push 0x66647361",
"push 0x706f6975",
"push 0x79747265",
"push 0x77713039",
"push 0x38373635",
"push 0x34333231",
"call keyboard_handler",
"add esp, 36",
"iretd",
);
}

#[allow(improper_ctypes_definitions)]
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn keyboard_handler(charset: [u8; CHAR_COUNT]) {
//read scancode from keyboard controller
let scancode: u8;
Expand All @@ -51,30 +47,36 @@ pub extern "C" fn keyboard_handler(charset: [u8; CHAR_COUNT]) {

//notify pics end of interrupt
PICS.end_interrupt(KEYBOARD_INT);

unsafe {
let keyboard = &mut (*(&raw mut KEYBOARD));
let shell = &mut (*(&raw mut SHELL));
match scancode {
//press left shift
0x2a => {
KEYBOARD.lshift = true;
keyboard.acquire_mut().lshift = true;
keyboard.free();
return;
}

//release left shift
0xaa => {
KEYBOARD.lshift = false;
keyboard.acquire_mut().lshift = false;
keyboard.free();
return;
}

//backspace
0x0e => {
SHELL.backspace();
shell.acquire_mut().backspace();
shell.free();
return;
}

//enter
0x1c => {
SHELL.enter();
shell.acquire_mut().enter();
shell.free();
return;
}

Expand All @@ -87,8 +89,10 @@ pub extern "C" fn keyboard_handler(charset: [u8; CHAR_COUNT]) {

if key != '\0' {
unsafe {
SHELL.add(key);
}
let shell = &mut (*(&raw mut SHELL));
shell.acquire_mut().add(key);
shell.free();
}
}
}

Expand All @@ -110,9 +114,12 @@ fn scancode_to_char(scancode: u8, charset: [u8; CHAR_COUNT]) -> char {
key = charset[index] as char;

unsafe {
if KEYBOARD.lshift {
let keyboard = &mut (*(&raw mut KEYBOARD));
//let keyboard = (*(&raw mut KEYBOARD)).acquire();
if keyboard.acquire().lshift {
key = key.to_ascii_uppercase();
}
keyboard.free();
}
}

Expand Down
18 changes: 12 additions & 6 deletions kernel/src/filesystem/fat.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//FAT16 FILESYSTEM IMPLEMENTATION

use crate::drivers::disk::DISK;
use crate::libfelix::mutex::Mutex;
use core::mem;
use libfelix::mutex::Mutex;


pub static mut FAT: Mutex<FatDriver> = Mutex::new(FatDriver {
header: NULL_HEADER,
Expand Down Expand Up @@ -124,7 +125,8 @@ impl FatDriver {
let sectors: u16 = 1;

unsafe {
DISK.read(target, lba, sectors);
(*(&raw mut DISK)).acquire_mut().read(target, lba, sectors);
(*(&raw mut DISK)).free();
}
}

Expand All @@ -144,7 +146,8 @@ impl FatDriver {
let sectors: u16 = size / self.header.bytes_per_sector;

unsafe {
DISK.read(target, lba, sectors);
(*(&raw mut DISK)).acquire_mut().read(target, lba, sectors);
(*(&raw mut DISK)).free();
}
}

Expand Down Expand Up @@ -183,7 +186,8 @@ impl FatDriver {
let sectors: u16 = 1;

unsafe {
DISK.read(target, lba, sectors);
(*(&raw mut DISK)).acquire_mut().read(target, lba, sectors);
(*(&raw mut DISK)).free();
}
}

Expand All @@ -201,7 +205,8 @@ impl FatDriver {
let sectors: u16 = self.header.sectors_per_cluster as u16;

unsafe {
DISK.read(target, lba, sectors);
(*(&raw mut DISK)).acquire().read(target, lba, sectors);
(*(&raw mut DISK)).free();
}
}

Expand All @@ -223,7 +228,8 @@ impl FatDriver {
let sectors: u16 = self.header.sectors_per_cluster as u16;

unsafe {
DISK.read(current_target, lba, sectors);
(*(&raw mut DISK)).acquire().read(current_target, lba, sectors);
(*(&raw mut DISK)).free();
}

next_cluster = self.table[next_cluster as usize];
Expand Down
Loading