Skip to content

Commit

Permalink
Merge pull request #13 from lucasmln/fix_compilation+release+fix_shel…
Browse files Browse the repository at this point in the history
…l_string_print

FIX: fix compilation warning, add release to makefile, fix many bugs …
  • Loading branch information
avan-pra authored Dec 13, 2023
2 parents 7b31a70 + f2fc3ff commit 32362ca
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ atoi = { version = "2.0.0", default-features = false }
spin = "0.9.8"

[dependencies.lazy_static]
version = "1.0"
version = "1.4"
features = ["spin_no_std"]
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUSTC = rustc
KERNEL = kernel
KERNEL_LIB = libkernel.a
KERNEL_LIB_PATH = target/x86/debug/$(KERNEL_LIB)
KERNEL_LIB_RELEASE_PATH = target/x86/release/$(KERNEL_LIB)
CFG = build/grub.cfg
LINKER_FILE = build/linker.ld
ISO_PATH := iso
Expand All @@ -23,17 +24,24 @@ OBJ = $(SRCS:.rs=.o)

.PHONY: all
all: bootloader kernel linker iso
@echo Make has completed.

release: bootloader kernel_release linker_release iso

bootloader:
nasm -f elf32 boot.asm -o boot.o

kernel:
cargo build

kernel_release:
cargo build --release

linker: bootloader kernel
ld -m elf_i386 -T $(LINKER_FILE) -o $(KERNEL) boot.o $(KERNEL_LIB_PATH)

linker_release: bootloader kernel_release
ld -m elf_i386 -T $(LINKER_FILE) -o $(KERNEL) boot.o $(KERNEL_LIB_RELEASE_PATH)

iso: kernel
$(MKDIR) $(GRUB_PATH)
$(CP) $(KERNEL) $(BOOT_PATH)
Expand Down
2 changes: 1 addition & 1 deletion src/idt/idt.s
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ test_function:
xor %dx, %dx
mov $0, %cx
div %cx
ret
ret
4 changes: 2 additions & 2 deletions src/idt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use core::mem::size_of;
use core::ffi::c_void;

use crate::{print, println};
use crate::io::{outb, inb};
use crate::io::outb;
use crate::keyboard::handle_keypress;

const IDT_ENTRY_AMOUT: usize = 256;

extern "C" {
fn test_function();
fn isr_stub_0();
fn isr_stub_1();
fn isr_stub_2();
Expand Down Expand Up @@ -110,6 +109,7 @@ pub struct IdtTable {

impl Default for IdtTable {
fn default() -> Self {
#[allow(deref_nullptr)]
Self { idt: unsafe { &mut *(0x0 as *mut [IdtEntry; IDT_ENTRY_AMOUT]) } }
}
}
Expand Down
12 changes: 0 additions & 12 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ pub fn outb(port: u16, value: u8) {
core::arch::asm!("out dx, al", in("dx") port, in("al") value);
}
}
pub fn outw(port: u16, value: u16) {
unsafe {
core::arch::asm!("out dx, al", in("dx") port, in("ax") value);
}
}

pub fn inb(port: u16) -> u8 {
let mut value: u8;
Expand All @@ -16,10 +11,3 @@ pub fn inb(port: u16) -> u8 {
}
return value;
}
pub fn inw(port: u16) -> u16 {
let mut value: u16;
unsafe {
core::arch::asm!("in al, dx", out("ax") value, in("dx") port);
}
return value;
}
7 changes: 3 additions & 4 deletions src/keyboard/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
pub mod en;
pub mod fr;

use crate::{print, println};
use crate::io::{outb, inb};
use crate::io::inb;
use crate::shell;


Expand Down Expand Up @@ -53,7 +52,7 @@ pub struct KeyboardState<'a> {
loption: bool,
lcmd: bool,
rcmd: bool,
fn_btn: bool,
_fn_btn: bool,
caps_lock: bool,
lang: [Kmap<'a>; 2],
lang_id: usize,
Expand All @@ -70,7 +69,7 @@ impl Default for KeyboardState<'_> {
loption: false,
lcmd: false,
rcmd: false,
fn_btn: false,
_fn_btn: false,
caps_lock: false,
lang: [
Kmap {
Expand Down
14 changes: 10 additions & 4 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,28 @@ fn print_memory(mut command: &[u8], address_str: Option<&[u8]>) {
}
}
b's' => {
let mut counter: usize = 0;
unsafe {
print!("\"");
for _ in 0..200 {
let c = *get_kernel_address::<i8>(address);
let c = *get_kernel_address::<u8>(address);
if c == 0 {
if counter == 0 {
address += 1;
}
break;
}
address += 1;
if (32..126).contains(&c) {
print!("{}", c as u8 as char);
}
else {
print!("\\{:o}", c);
}
address += 1;
counter += 1;
}
print!("\"");
if *get_kernel_address::<i8>(address) != 0 {
if counter == 200 && *get_kernel_address::<u8>(address) != 0 {
print!("...");
}
}
Expand Down Expand Up @@ -297,9 +302,10 @@ pub fn interpret(mut shell_str: &[u8])
else if x.starts_with("set_color".as_bytes()) { set_color(shell_str_splitted.next()); }
else if x.starts_with("panic".as_bytes()) { panic!("You called panic !"); }
else if x.starts_with("x".as_bytes()) { print_memory(x, shell_str_splitted.next()); }
else if x == [] {}
else { unknown_command(Some(x)); }
}
None => { unknown_command(command); }
None => { }
}
}

Expand Down

0 comments on commit 32362ca

Please sign in to comment.