Skip to content

Commit

Permalink
rustfmt.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
adamperkowski committed Sep 6, 2024
1 parent 6f3457d commit 688eef4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 73 deletions.
4 changes: 4 additions & 0 deletions kernel/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
max_width = 120
tab_spaces = 4
reorder_imports = true
reorder_modules = true
4 changes: 1 addition & 3 deletions kernel/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use alloc::alloc::{GlobalAlloc, Layout};
use core::ptr::null_mut;
use fixed_size_block::FixedSizeBlockAllocator;
use x86_64::{
structures::paging::{
mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB,
},
structures::paging::{mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB},
VirtAddr,
};

Expand Down
4 changes: 1 addition & 3 deletions kernel/src/allocator/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ pub struct LinkedListAllocator {
#[allow(clippy::missing_safety_doc)]
impl LinkedListAllocator {
pub const fn new() -> Self {
Self {
head: ListNode::new(0),
}
Self { head: ListNode::new(0) }
}

pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) {
Expand Down
29 changes: 10 additions & 19 deletions kernel/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,15 @@ fn document(_args: Vec<&str>) -> i32 {
println!("{} >> {}", command.name, command.doc);
0
} else {
WRITER.lock().print_colored(
"Command not found.\n".to_string(),
Color::LightRed,
Color::Black,
);
WRITER
.lock()
.print_colored("Command not found.\n".to_string(), Color::LightRed, Color::Black);
3
}
} else {
WRITER.lock().print_colored(
"No command specified.\n".to_string(),
Color::LightRed,
Color::Black,
);
WRITER
.lock()
.print_colored("No command specified.\n".to_string(), Color::LightRed, Color::Black);
4
}
}
Expand All @@ -113,17 +109,12 @@ fn chcolor(_args: Vec<&str>) -> i32 {
let mut new_colors: vec::Vec<Color> = vec![];

for arg in _args {
if let Some(color) = STR_COLORS
.iter()
.find(|&col| col.name == arg.replace("\n", ""))
{
if let Some(color) = STR_COLORS.iter().find(|&col| col.name == arg.replace("\n", "")) {
new_colors.push(color.color);
} else {
WRITER.lock().print_colored(
format!("Color not found: {}\n", arg),
Color::LightRed,
Color::Black,
);
WRITER
.lock()
.print_colored(format!("Color not found: {}\n", arg), Color::LightRed, Color::Black);
return 4;
}
}
Expand Down
40 changes: 12 additions & 28 deletions kernel/src/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ lazy_static! {
pub const PIC_0_OFFSET: u8 = 32;
pub const PIC_1_OFFSET: u8 = PIC_0_OFFSET + 8;

pub static PICS: spin::Mutex<ChainedPics> =
spin::Mutex::new(unsafe { ChainedPics::new(PIC_0_OFFSET, PIC_1_OFFSET) });
pub static PICS: spin::Mutex<ChainedPics> = spin::Mutex::new(unsafe { ChainedPics::new(PIC_0_OFFSET, PIC_1_OFFSET) });

#[derive(Debug, Clone, Copy)]
#[repr(u8)]
Expand Down Expand Up @@ -70,17 +69,13 @@ extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
);
}

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

extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
unsafe {
PICS.lock()
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
PICS.lock().notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
}
}

Expand All @@ -90,12 +85,11 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
use x86_64::instructions::port::Port;

lazy_static! {
static ref KEYBOARD: Mutex<Keyboard<layouts::Us104Key, ScancodeSet1>> =
Mutex::new(Keyboard::new(
ScancodeSet1::new(),
layouts::Us104Key,
HandleControl::Ignore
));
static ref KEYBOARD: Mutex<Keyboard<layouts::Us104Key, ScancodeSet1>> = Mutex::new(Keyboard::new(
ScancodeSet1::new(),
layouts::Us104Key,
HandleControl::Ignore
));
}

if unsafe { BUFFER_INDEX } < BUFFER_SIZE {
Expand Down Expand Up @@ -153,10 +147,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
}
}

for i in cmd_history.history
[cmd_history.history.len() - cmd_history.last - 1]
.chars()
{
for i in cmd_history.history[cmd_history.history.len() - cmd_history.last - 1].chars() {
unsafe {
BUFFER[BUFFER_INDEX] = i;
BUFFER_INDEX += 1;
Expand All @@ -182,10 +173,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac

cmd_history.last -= 1;

for i in cmd_history.history
[cmd_history.history.len() - cmd_history.last]
.chars()
{
for i in cmd_history.history[cmd_history.history.len() - cmd_history.last].chars() {
unsafe {
BUFFER[BUFFER_INDEX] = i;
BUFFER_INDEX += 1;
Expand Down Expand Up @@ -213,15 +201,11 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
}

unsafe {
PICS.lock()
.notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8());
PICS.lock().notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8());
}
}

extern "x86-interrupt" fn page_fault_handler(
stack_frame: InterruptStackFrame,
error_code: PageFaultErrorCode,
) {
extern "x86-interrupt" fn page_fault_handler(stack_frame: InterruptStackFrame, error_code: PageFaultErrorCode) {
use x86_64::registers::control::Cr2;

WRITER.lock().print_colored(
Expand Down
19 changes: 6 additions & 13 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ pub fn init_kernel(boot_info: &'static BootInfo) {
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("Heap initialization failed");

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

#[cfg(not(debug_assertions))]
print!("\nHighlightOS v{}\n\nhls < ", env!("CARGO_PKG_VERSION"));
Expand Down Expand Up @@ -75,8 +72,7 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
let rtr = (command.fun)(args);

if rtr != 1 {
if let Some(return_code) = RTR_LIST.iter().find(|&rtr_t| rtr_t.code == &rtr)
{
if let Some(return_code) = RTR_LIST.iter().find(|&rtr_t| rtr_t.code == &rtr) {
println!("\n > {}\n{} : {}\n", req_com, rtr, return_code.info);
} else {
println!("\n > {}\nreturned : {}\n", req_com, rtr);
Expand All @@ -92,8 +88,7 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {

let mut cmd_history = CMD_HISTORY.lock();
if !cmd_history.history.is_empty() {
if cmd_history.history[cmd_history.history.len() - 1] != input.replace("\n", "")
{
if cmd_history.history[cmd_history.history.len() - 1] != input.replace("\n", "") {
cmd_history.history.push(input.replace("\n", ""));
}
} else {
Expand Down Expand Up @@ -129,10 +124,8 @@ const RTR_LIST: &[RtrType] = &[

#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
WRITER.lock().print_colored(
format!("KERNEL CRASHED\n{}\n", info),
Color::Red,
Color::Black,
);
WRITER
.lock()
.print_colored(format!("KERNEL CRASHED\n{}\n", info), Color::Red, Color::Black);
hlkernel::hlt_loop();
}
9 changes: 2 additions & 7 deletions kernel/src/mem.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
use x86_64::{
structures::paging::{
FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB,
},
structures::paging::{FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB},
PhysAddr, VirtAddr,
};

Expand Down Expand Up @@ -58,10 +56,7 @@ pub struct BootInfoFrameAlloc {
#[allow(clippy::missing_safety_doc)]
impl BootInfoFrameAlloc {
pub unsafe fn init(memory_map: &'static MemoryMap) -> Self {
BootInfoFrameAlloc {
memory_map,
next: 0,
}
BootInfoFrameAlloc { memory_map, next: 0 }
}
fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> {
let regions = self.memory_map.iter();
Expand Down

0 comments on commit 688eef4

Please sign in to comment.