Skip to content

Commit b195335

Browse files
committed
Merge branch 'main' into arrow_keys
2 parents f5f7cf5 + 688eef4 commit b195335

File tree

7 files changed

+36
-73
lines changed

7 files changed

+36
-73
lines changed

kernel/rustfmt.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
max_width = 120
2+
tab_spaces = 4
3+
reorder_imports = true
4+
reorder_modules = true

kernel/src/allocator.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use alloc::alloc::{GlobalAlloc, Layout};
22
use core::ptr::null_mut;
33
use fixed_size_block::FixedSizeBlockAllocator;
44
use x86_64::{
5-
structures::paging::{
6-
mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB,
7-
},
5+
structures::paging::{mapper::MapToError, FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB},
86
VirtAddr,
97
};
108

kernel/src/allocator/linked_list.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ pub struct LinkedListAllocator {
2929
#[allow(clippy::missing_safety_doc)]
3030
impl LinkedListAllocator {
3131
pub const fn new() -> Self {
32-
Self {
33-
head: ListNode::new(0),
34-
}
32+
Self { head: ListNode::new(0) }
3533
}
3634

3735
pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) {

kernel/src/cmd/mod.rs

+10-19
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,15 @@ fn document(_args: Vec<&str>) -> i32 {
9191
println!("{} >> {}", command.name, command.doc);
9292
0
9393
} else {
94-
WRITER.lock().print_colored(
95-
"Command not found.\n".to_string(),
96-
Color::LightRed,
97-
Color::Black,
98-
);
94+
WRITER
95+
.lock()
96+
.print_colored("Command not found.\n".to_string(), Color::LightRed, Color::Black);
9997
3
10098
}
10199
} else {
102-
WRITER.lock().print_colored(
103-
"No command specified.\n".to_string(),
104-
Color::LightRed,
105-
Color::Black,
106-
);
100+
WRITER
101+
.lock()
102+
.print_colored("No command specified.\n".to_string(), Color::LightRed, Color::Black);
107103
4
108104
}
109105
}
@@ -113,17 +109,12 @@ fn chcolor(_args: Vec<&str>) -> i32 {
113109
let mut new_colors: vec::Vec<Color> = vec![];
114110

115111
for arg in _args {
116-
if let Some(color) = STR_COLORS
117-
.iter()
118-
.find(|&col| col.name == arg.replace("\n", ""))
119-
{
112+
if let Some(color) = STR_COLORS.iter().find(|&col| col.name == arg.replace("\n", "")) {
120113
new_colors.push(color.color);
121114
} else {
122-
WRITER.lock().print_colored(
123-
format!("Color not found: {}\n", arg),
124-
Color::LightRed,
125-
Color::Black,
126-
);
115+
WRITER
116+
.lock()
117+
.print_colored(format!("Color not found: {}\n", arg), Color::LightRed, Color::Black);
127118
return 4;
128119
}
129120
}

kernel/src/interrupts.rs

+12-28
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ lazy_static! {
3838
pub const PIC_0_OFFSET: u8 = 32;
3939
pub const PIC_1_OFFSET: u8 = PIC_0_OFFSET + 8;
4040

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

4443
#[derive(Debug, Clone, Copy)]
4544
#[repr(u8)]
@@ -70,17 +69,13 @@ extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
7069
);
7170
}
7271

73-
extern "x86-interrupt" fn double_fault_handler(
74-
stack_frame: InterruptStackFrame,
75-
_error_code: u64,
76-
) -> ! {
72+
extern "x86-interrupt" fn double_fault_handler(stack_frame: InterruptStackFrame, _error_code: u64) -> ! {
7773
panic!("\nKERNEL CRASHED\nEX: DOUBLE FAULT\n{:#?}\n", stack_frame);
7874
}
7975

8076
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
8177
unsafe {
82-
PICS.lock()
83-
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
78+
PICS.lock().notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
8479
}
8580
}
8681

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

9287
lazy_static! {
93-
static ref KEYBOARD: Mutex<Keyboard<layouts::Us104Key, ScancodeSet1>> =
94-
Mutex::new(Keyboard::new(
95-
ScancodeSet1::new(),
96-
layouts::Us104Key,
97-
HandleControl::Ignore
98-
));
88+
static ref KEYBOARD: Mutex<Keyboard<layouts::Us104Key, ScancodeSet1>> = Mutex::new(Keyboard::new(
89+
ScancodeSet1::new(),
90+
layouts::Us104Key,
91+
HandleControl::Ignore
92+
));
9993
}
10094

10195
if unsafe { BUFFER_INDEX } < BUFFER_SIZE {
@@ -153,10 +147,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
153147
}
154148
}
155149

156-
for i in cmd_history.history
157-
[cmd_history.history.len() - cmd_history.last - 1]
158-
.chars()
159-
{
150+
for i in cmd_history.history[cmd_history.history.len() - cmd_history.last - 1].chars() {
160151
unsafe {
161152
BUFFER[BUFFER_INDEX] = i;
162153
BUFFER_INDEX += 1;
@@ -182,10 +173,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
182173

183174
cmd_history.last -= 1;
184175

185-
for i in cmd_history.history
186-
[cmd_history.history.len() - cmd_history.last]
187-
.chars()
188-
{
176+
for i in cmd_history.history[cmd_history.history.len() - cmd_history.last].chars() {
189177
unsafe {
190178
BUFFER[BUFFER_INDEX] = i;
191179
BUFFER_INDEX += 1;
@@ -215,15 +203,11 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
215203
}
216204

217205
unsafe {
218-
PICS.lock()
219-
.notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8());
206+
PICS.lock().notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8());
220207
}
221208
}
222209

223-
extern "x86-interrupt" fn page_fault_handler(
224-
stack_frame: InterruptStackFrame,
225-
error_code: PageFaultErrorCode,
226-
) {
210+
extern "x86-interrupt" fn page_fault_handler(stack_frame: InterruptStackFrame, error_code: PageFaultErrorCode) {
227211
use x86_64::registers::control::Cr2;
228212

229213
WRITER.lock().print_colored(

kernel/src/main.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ pub fn init_kernel(boot_info: &'static BootInfo) {
4343
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("Heap initialization failed");
4444

4545
#[cfg(debug_assertions)]
46-
print!(
47-
"\nHighlightOS v{} DEBUG\n\nhls < ",
48-
env!("CARGO_PKG_VERSION")
49-
);
46+
print!("\nHighlightOS v{} DEBUG\n\nhls < ", env!("CARGO_PKG_VERSION"));
5047

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

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

9389
let mut cmd_history = CMD_HISTORY.lock();
9490
if !cmd_history.history.is_empty() {
95-
if cmd_history.history[cmd_history.history.len() - 1] != input.replace("\n", "")
96-
{
91+
if cmd_history.history[cmd_history.history.len() - 1] != input.replace("\n", "") {
9792
cmd_history.history.push(input.replace("\n", ""));
9893
}
9994
} else {
@@ -129,10 +124,8 @@ const RTR_LIST: &[RtrType] = &[
129124

130125
#[panic_handler]
131126
fn panic(info: &PanicInfo) -> ! {
132-
WRITER.lock().print_colored(
133-
format!("KERNEL CRASHED\n{}\n", info),
134-
Color::Red,
135-
Color::Black,
136-
);
127+
WRITER
128+
.lock()
129+
.print_colored(format!("KERNEL CRASHED\n{}\n", info), Color::Red, Color::Black);
137130
hlkernel::hlt_loop();
138131
}

kernel/src/mem.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
22
use x86_64::{
3-
structures::paging::{
4-
FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB,
5-
},
3+
structures::paging::{FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB},
64
PhysAddr, VirtAddr,
75
};
86

@@ -58,10 +56,7 @@ pub struct BootInfoFrameAlloc {
5856
#[allow(clippy::missing_safety_doc)]
5957
impl BootInfoFrameAlloc {
6058
pub unsafe fn init(memory_map: &'static MemoryMap) -> Self {
61-
BootInfoFrameAlloc {
62-
memory_map,
63-
next: 0,
64-
}
59+
BootInfoFrameAlloc { memory_map, next: 0 }
6560
}
6661
fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> {
6762
let regions = self.memory_map.iter();

0 commit comments

Comments
 (0)