Skip to content

Commit

Permalink
some stuff (#32)
Browse files Browse the repository at this point in the history
This stuff includes:

- binary optimization
- docs updates
- code aesthetic touches
- sad attemps at fixing some bugs
  • Loading branch information
adamperkowski authored Oct 15, 2024
2 parents c150192 + b29686e commit 72686a0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 51 deletions.
6 changes: 6 additions & 0 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ panic = "abort"

[profile.release]
panic = "abort"
opt-level = "z"
debug = false
lto = true
codegen-units = 1
strip = true
incremental = false
2 changes: 1 addition & 1 deletion kernel/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ unsafe impl GlobalAlloc for Dummy {
}

unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
panic!("dealloc should be never called")
panic!("dealloc should never be called")
}
}

Expand Down
49 changes: 9 additions & 40 deletions kernel/src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
// Copyleft 🄯 2024 Adam Perkowski

// use std::io;
// use std::io::Write;
// use std::process;

extern crate alloc;
use alloc::string::ToString;
use alloc::vec::Vec;
use alloc::{format, vec};
Expand All @@ -30,7 +23,7 @@ fn help(_args: Vec<&str>) -> i32 {
println!(
"HighlightOS Shell
List of commands:"
List of available commands:"
);

for cmd in COMMAND_LIST {
Expand All @@ -47,7 +40,7 @@ fn test(_args: Vec<&str>) -> i32 {

fn cc(_args: Vec<&str>) -> i32 {
println!(
"Copyright (C) 2024 Adam Perkowski
"Copyright (C) 2024 Adam Perkowski
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -66,24 +59,6 @@ fn cc(_args: Vec<&str>) -> i32 {
0
}

// fn exit_hls(_args: Vec<&str>) -> i32 {
// print!("are you sure you want to exit? [ y/N ] < ");

// let mut inpt = String::new();

// io::stdout().flush().unwrap();
// io::stdin().read_line(&mut inpt).unwrap();

// if inpt.to_lowercase() == "y\n" {
// println!();
// process::exit(0);
// }
// // return 0
// else {
// 3
// }
// }

fn document(_args: Vec<&str>) -> i32 {
if !_args.is_empty() {
let req_com = &_args[0].replace("\n", "");
Expand Down Expand Up @@ -122,7 +97,7 @@ fn chcolor(_args: Vec<&str>) -> i32 {
0
} else {
WRITER.lock().print_colored(
"Specify both fg and bg color.\nExample usage: chcolor red white\n".to_string(),
"Specify both foreground and background color.\nExample usage: chcolor red white\n".to_string(),
Color::LightRed,
Color::Black,
);
Expand All @@ -142,20 +117,20 @@ pub fn cmd_hist(_args: Vec<&str>) -> i32 {
#[cfg(debug_assertions)]
fn crasher(_args: Vec<&str>) -> i32 {
println!("CRASHING...\n\n");
panic!("Invoked by crasher");
panic!("Invoked by THE CRASHER >:)"); // FIXME: THIS IS NOT SAFE
}

pub const COMMAND_LIST: &[Command] = &[
Command {
name: "clrs",
args: "",
doc: "clear screen",
doc: "clear the output",
fun: clrs,
},
Command {
name: "help",
args: "",
doc: "show list of commands",
doc: "show a list of available commands",
fun: help,
},
Command {
Expand All @@ -170,22 +145,16 @@ pub const COMMAND_LIST: &[Command] = &[
doc: "display copyright info",
fun: cc,
},
// Command {
// name: "exit",
// args: "",
// doc: "exit the shell :((",
// fun: exit_hls,
// },
Command {
name: "getdoc",
args: "[cmd]",
doc: "display doc of selected command",
doc: "display the documentation of selected command",
fun: document,
},
// Command {
// name: "reinit",
// args: "",
// doc: "re-init the system",
// doc: "re-initialize the kernel",
// fun: crate::init_kernel,
// },
Command {
Expand All @@ -204,7 +173,7 @@ pub const COMMAND_LIST: &[Command] = &[
Command {
name: "crash_kernel",
args: "",
doc: "DEV | panic! the system",
doc: "DEV | cause a kernel panic",
fun: crasher,
},
];
8 changes: 3 additions & 5 deletions kernel/src/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ pub fn init_idt() {

extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
WRITER.lock().print_colored(
format!("\nKERNEL CRASHED\nEX: BREAKPOINT\n{:#?}\n\n", stack_frame),
format!("\nEX: BREAKPOINT\n{:#?}\n\n", stack_frame),
Color::Red,
Color::Black,
);
}

extern "x86-interrupt" fn double_fault_handler(stack_frame: InterruptStackFrame, _error_code: u64) -> ! {
panic!("\nKERNEL CRASHED\nEX: DOUBLE FAULT\n{:#?}\n", stack_frame);
panic!("\nEX: DOUBLE FAULT\n{:#?}\n", stack_frame);
}

extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
Expand Down Expand Up @@ -133,12 +133,10 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
}

KeyCode::ArrowUp => {
// TODO: zsh-like completion
let mut cmd_history = CMD_HISTORY.lock();

if cmd_history.history.len() > cmd_history.last {
while unsafe { BUFFER_INDEX } > 0 {
// TODO: add current to history
unsafe {
BUFFER_INDEX -= 1;
WRITER.lock().decrement_column_position();
Expand Down Expand Up @@ -210,7 +208,7 @@ extern "x86-interrupt" fn page_fault_handler(stack_frame: InterruptStackFrame, e

WRITER.lock().print_colored(
format!(
"\nKERNEL CRASHED\nEX: PAGE FAULT\nAccessed address: {:?}\nError code: {:?}\n\n{:#?}\n\n",
"\nEX: PAGE FAULT\nAccessed address: {:?}\nError code: {:?}\n\n{:#?}\n\n",
Cr2::read(),
error_code,
stack_frame
Expand Down
6 changes: 2 additions & 4 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ pub fn init_kernel(boot_info: &'static BootInfo) {
#[cfg(debug_assertions)]
println!("Initializing...\n");

hlkernel::init();

let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset);
let mut mapper = unsafe { mem::init(phys_mem_offset) };
let mut frame_allocator = unsafe { BootInfoFrameAlloc::init(&boot_info.memory_map) };

allocator::init_heap(&mut mapper, &mut frame_allocator).expect("Heap initialization failed");

hlkernel::init();

#[cfg(debug_assertions)]
print!("\nHighlightOS v{} DEBUG\n\nhls < ", env!("CARGO_PKG_VERSION"));

Expand Down Expand Up @@ -99,8 +99,6 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
print!("hls < ");
}
}

// hlkernel::hlt_loop();
}

const RTR_LIST: &[RtrType] = &[
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ unsafe fn active_lvl_4_table(ph_memory_offset: VirtAddr) -> &'static mut PageTab
let virt = ph_memory_offset + phys.as_u64();
let page_table_ptr: *mut PageTable = virt.as_mut_ptr();

&mut *page_table_ptr // unsafe return
&mut *page_table_ptr // FIXME: unsafe return
}

pub fn create_example_mapping(
Expand Down

0 comments on commit 72686a0

Please sign in to comment.