From 8b810a009f8d29ba61a3c377fdeac06a3bbb151d Mon Sep 17 00:00:00 2001 From: NatrixAeria Date: Thu, 15 Apr 2021 00:05:07 +0200 Subject: Fix most warnings and tidy up --- kernel/src/interrupts/apic.rs | 3 +-- kernel/src/interrupts/exception_handlers.rs | 8 ++++---- kernel/src/interrupts/idt.rs | 2 +- kernel/src/interrupts/interrupt_handlers.rs | 12 +++++------- kernel/src/interrupts/mod.rs | 2 +- kernel/src/io/panic_screen.rs | 27 ++++++++++----------------- kernel/src/io/vga_text.rs | 13 ++++++------- kernel/src/testing/panic.rs | 14 +++++--------- 8 files changed, 33 insertions(+), 48 deletions(-) diff --git a/kernel/src/interrupts/apic.rs b/kernel/src/interrupts/apic.rs index 2761fb9..0e89943 100644 --- a/kernel/src/interrupts/apic.rs +++ b/kernel/src/interrupts/apic.rs @@ -7,7 +7,6 @@ const APIC_BASE_MSR: u32 = 0x001b; // APIC constant register values const APIC_DISABLE: u32 = 0x0001_0000; const APIC_NMI: u32 = 0x0000_0400; -const APIC_SW_ENABLE: u32 = 0x0000_0100; pub fn is_x2apic() -> bool { let info: u32; @@ -98,7 +97,7 @@ impl Apic { return None; } Self::disable_pic(); - let mut base_apic = unsafe { Msr::new(APIC_BASE_MSR).read() }; + let base_apic = unsafe { Msr::new(APIC_BASE_MSR).read() }; let mut apic = Self::from_base_apic(base_apic); apic.set(ApicRegister::LogicalDst, 0); diff --git a/kernel/src/interrupts/exception_handlers.rs b/kernel/src/interrupts/exception_handlers.rs index c689501..ce8f6c0 100644 --- a/kernel/src/interrupts/exception_handlers.rs +++ b/kernel/src/interrupts/exception_handlers.rs @@ -13,16 +13,16 @@ macro_rules! exception_default { }; } -static mut expected_fault: InterruptType = InterruptType::None; +static mut EXPECTED_FAULT: InterruptType = InterruptType::None; pub unsafe fn expect_fault(int: InterruptType) { - if expected_fault == InterruptType::None { - expected_fault = int; + if EXPECTED_FAULT == InterruptType::None { + EXPECTED_FAULT = int; } } fn get_expected_fault() -> InterruptType { - unsafe { expected_fault } + unsafe { EXPECTED_FAULT } } pub extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStackFrame) { diff --git a/kernel/src/interrupts/idt.rs b/kernel/src/interrupts/idt.rs index 641e44e..4e5dd77 100644 --- a/kernel/src/interrupts/idt.rs +++ b/kernel/src/interrupts/idt.rs @@ -34,7 +34,7 @@ lazy_static! { } pub extern "x86-interrupt" fn dummy_handler( - stack_frame: &mut x86_64::structures::idt::InterruptStackFrame, + _stack_frame: &mut x86_64::structures::idt::InterruptStackFrame, ) { panic!("unhandled interrupt recieved"); } diff --git a/kernel/src/interrupts/interrupt_handlers.rs b/kernel/src/interrupts/interrupt_handlers.rs index e7af0e1..831211b 100644 --- a/kernel/src/interrupts/interrupt_handlers.rs +++ b/kernel/src/interrupts/interrupt_handlers.rs @@ -1,20 +1,18 @@ -use super::InterruptType; -use crate::io::qemu; use core::fmt::Write; -use x86_64::structures::idt::{InterruptStackFrame, PageFaultErrorCode}; +use x86_64::structures::idt::InterruptStackFrame; use x86_64::structures::port; -pub extern "x86-interrupt" fn timer_handler(stack_frame: &mut InterruptStackFrame) { - write!(crate::io::vga_text::OStream::new(), "Timer"); +pub extern "x86-interrupt" fn timer_handler(_stack_frame: &mut InterruptStackFrame) { + crate::io::vga_text::OStream::new().print(b"Timer"); if let Some(apic) = unsafe { super::apic::get_local_apic() } { apic.end_of_interrupt() } } -pub extern "x86-interrupt" fn keyboard_handler(stack_frame: &mut InterruptStackFrame) { +pub extern "x86-interrupt" fn keyboard_handler(_stack_frame: &mut InterruptStackFrame) { let code: u8 = unsafe { port::PortRead::read_from_port(0x60) }; - write!(crate::io::vga_text::OStream::new(), "{}", code); + let _ = write!(crate::io::vga_text::OStream::new(), "{}", code); if let Some(apic) = unsafe { super::apic::get_local_apic() } { apic.end_of_interrupt() } diff --git a/kernel/src/interrupts/mod.rs b/kernel/src/interrupts/mod.rs index 6a92c3f..3f5e09a 100644 --- a/kernel/src/interrupts/mod.rs +++ b/kernel/src/interrupts/mod.rs @@ -24,7 +24,7 @@ pub enum InterruptType { StackSegmentFault, GeneralProtectionFault, PageFault, - x87Floating = 16, + X87Floating = 16, AlignmentCheck, MachineCheck, SIMD, diff --git a/kernel/src/io/panic_screen.rs b/kernel/src/io/panic_screen.rs index ce2c118..7b81676 100644 --- a/kernel/src/io/panic_screen.rs +++ b/kernel/src/io/panic_screen.rs @@ -1,11 +1,10 @@ -use core::fmt::Write; -use crate::io::vga_text::{OStream, CharState, Color}; +use crate::io::vga_text::{CharState, Color, OStream}; const PANIC_SCREEN_MESSAGE_BUFFER_SIZE: usize = 2048; struct TextBuffer<'a> { dst: &'a mut [u8], - len: usize + len: usize, } impl<'a> TextBuffer<'a> { @@ -23,7 +22,7 @@ impl<'a> core::fmt::Write for TextBuffer<'a> { Err(core::fmt::Error) } else { let s = s.as_bytes(); - (&mut self.dst[self.len..self.len+s.len()]).clone_from_slice(s); + (&mut self.dst[self.len..self.len + s.len()]).clone_from_slice(s); Ok(self.len += s.len()) } } @@ -31,27 +30,21 @@ impl<'a> core::fmt::Write for TextBuffer<'a> { pub fn show(args: Option<&core::fmt::Arguments>) { let mut stderr = OStream::new(); - stderr.set_state(CharState::from_colors( - Color::LightRed, - Color::Red, - )); + stderr.set_state(CharState::from_colors(Color::LightRed, Color::Red)); stderr.clear(); stderr.print(b"uff-os"); stderr.set_row(10); - stderr.set_state(CharState::from_colors( - Color::White, - Color::Red, - )); + stderr.set_state(CharState::from_colors(Color::White, Color::Red)); stderr.print_centered(b""); stderr.set_row(14); - stderr.set_state(CharState::from_colors( - Color::Cyan, - Color::Red, - )); + stderr.set_state(CharState::from_colors(Color::Cyan, Color::Red)); stderr.set_centered(true); let buffer: &mut [u8] = &mut [b' '; PANIC_SCREEN_MESSAGE_BUFFER_SIZE]; let mut tbuffer = TextBuffer::new(buffer); - let _ = core::fmt::write(&mut tbuffer, *args.unwrap_or(&format_args!("no panic information obtainable"))); + let _ = core::fmt::write( + &mut tbuffer, + *args.unwrap_or(&format_args!("no panic information obtainable")), + ); stderr.print(tbuffer.get()); stderr.set_centered(false); } diff --git a/kernel/src/io/vga_text.rs b/kernel/src/io/vga_text.rs index 277db73..72c4d85 100644 --- a/kernel/src/io/vga_text.rs +++ b/kernel/src/io/vga_text.rs @@ -23,7 +23,7 @@ pub const WIDTH: usize = 80; pub const HEIGHT: usize = 25; #[derive(Clone, Copy)] -#[repr(C)] +#[repr(C, packed)] pub struct CharState(pub u8); impl CharState { @@ -40,9 +40,8 @@ impl CharState { } } -#[no_mangle] #[derive(Clone, Copy)] -#[repr(C)] +#[repr(C, packed)] pub struct VgaChar { pub byte: u8, pub state: CharState, @@ -58,7 +57,7 @@ pub struct OStream { pos: (usize, usize), cursor: *mut VgaChar, state: CharState, - centered_mode: bool + centered_mode: bool, } impl OStream { @@ -158,10 +157,10 @@ impl OStream { } pub fn print_centered(&mut self, s: &[u8]) { - let mut line_start = 0; - let mut line_len = 0; for line in s.split(|&c| c == b'\n') { - if line.is_empty() { self.new_line() } + if line.is_empty() { + self.new_line() + } for chunk in line.chunks(WIDTH) { self.set_col((WIDTH - chunk.len()) >> 1); self.put_bytes(chunk); diff --git a/kernel/src/testing/panic.rs b/kernel/src/testing/panic.rs index de07ba8..11469f2 100644 --- a/kernel/src/testing/panic.rs +++ b/kernel/src/testing/panic.rs @@ -1,17 +1,15 @@ -use crate::io::{qemu, serial, vga_text}; +use crate::io::{qemu, serial}; use core::fmt::Write; use core::panic::PanicInfo; use qemu::{exit_qemu, QemuExitCode}; use serial::SerialStream; -use vga_text::OStream; use x86_64::instructions::interrupts; -pub fn serial_should_panic(info: &PanicInfo) -> ! { +pub fn serial_should_panic(_info: &PanicInfo) -> ! { interrupts::disable(); let mut stdout = SerialStream::new(); write!(stdout, "\nOK\nsuccessfully panicked\n").unwrap(); - exit_qemu(QemuExitCode::Success); - loop {} + exit_qemu(QemuExitCode::Success) } pub fn serial_panic(info: &PanicInfo) -> ! { @@ -24,14 +22,12 @@ pub fn serial_panic(info: &PanicInfo) -> ! { info ) .unwrap(); - exit_qemu(QemuExitCode::Failed); - loop {} + exit_qemu(QemuExitCode::Failed) } pub fn should_panic(_info: &PanicInfo) -> ! { interrupts::disable(); - exit_qemu(QemuExitCode::Success); - loop {} + exit_qemu(QemuExitCode::Success) } pub fn panic(info: &PanicInfo) -> ! { -- cgit v1.2.3-70-g09d2