Skip to content

Commit de7b9e1

Browse files
committed
Move all use statements to the beginning of the file
Signed-off-by: SlyMarbo <[email protected]>
1 parent 7a4bf8f commit de7b9e1

File tree

6 files changed

+9
-15
lines changed

6 files changed

+9
-15
lines changed

kernel/src/interrupts.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{gdt, halt_loop, println, time};
22
use lazy_static::lazy_static;
33
use pic8259::ChainedPics;
4+
use x86_64::registers::control::Cr2;
45
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode};
56

67
pub fn init() {
@@ -33,8 +34,6 @@ extern "x86-interrupt" fn page_fault_handler(
3334
stack_frame: InterruptStackFrame,
3435
error_code: PageFaultErrorCode,
3536
) {
36-
use x86_64::registers::control::Cr2;
37-
3837
println!("EXCEPTION: PAGE FAULT");
3938
println!("Accessed Address: {:?}", Cr2::read());
4039
println!("Error Code: {:?}", error_code);

kernel/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
extern crate alloc;
1111

1212
use core::panic::PanicInfo;
13+
use x86_64::instructions::port::Port;
1314

1415
pub mod allocator;
1516
pub mod gdt;
@@ -114,8 +115,6 @@ pub enum QemuExitCode {
114115
/// exit code.
115116
///
116117
pub fn exit_qemu(exit_code: QemuExitCode) {
117-
use x86_64::instructions::port::Port;
118-
119118
unsafe {
120119
let mut port = Port::new(0xf4);
121120
port.write(exit_code as u32);

kernel/src/memory.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
2+
use x86_64::registers::control::Cr3;
23
use x86_64::structures::paging::{FrameAllocator, OffsetPageTable, PageTable, PhysFrame, Size4KiB};
34
use x86_64::{PhysAddr, VirtAddr};
45

@@ -30,8 +31,6 @@ pub unsafe fn init(physical_memory_offset: VirtAddr) -> OffsetPageTable<'static>
3031
/// behavior).
3132
///
3233
unsafe fn active_level_4_table(physical_memory_offset: VirtAddr) -> &'static mut PageTable {
33-
use x86_64::registers::control::Cr3;
34-
3534
let (level_4_table_frame, _) = Cr3::read();
3635

3736
let phys = level_4_table_frame.start_address();

kernel/src/serial.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use core::fmt::Write;
12
use lazy_static::lazy_static;
23
use spin::Mutex;
34
use uart_16550::SerialPort;
5+
use x86_64::instructions::interrupts;
46

57
lazy_static! {
68
pub static ref SERIAL1: Mutex<SerialPort> = {
@@ -15,9 +17,6 @@ lazy_static! {
1517
///
1618
#[doc(hidden)]
1719
pub fn _print(args: ::core::fmt::Arguments) {
18-
use core::fmt::Write;
19-
use x86_64::instructions::interrupts;
20-
2120
interrupts::without_interrupts(|| {
2221
SERIAL1
2322
.lock()

kernel/src/time.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{print, Locked};
22
use lazy_static::lazy_static;
3+
use x86_64::instructions::port::Port;
34

45
pub fn init() {
56
set_ticker_frequency(TICKS_PER_SECOND);
@@ -18,8 +19,6 @@ const MIN_FREQUENCY: usize = 18; // See https://wiki.osdev.org/Programmable_Inte
1819
const MAX_FREQUENCY: usize = 1193181;
1920

2021
pub fn set_ticker_frequency(mut freq: usize) {
21-
use x86_64::instructions::port::Port;
22-
2322
if freq < MIN_FREQUENCY {
2423
freq = MIN_FREQUENCY;
2524
}

kernel/tests/heap_allocation.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ extern crate alloc;
99
use alloc::{boxed::Box, vec::Vec};
1010
use bootloader::{entry_point, BootInfo};
1111
use core::panic::PanicInfo;
12+
use kernel::allocator;
1213
use kernel::allocator::HEAP_SIZE;
14+
use kernel::memory::{self, BootInfoFrameAllocator};
15+
use x86_64::VirtAddr;
1316

1417
entry_point!(main);
1518

1619
fn main(boot_info: &'static BootInfo) -> ! {
17-
use kernel::allocator;
18-
use kernel::memory::{self, BootInfoFrameAllocator};
19-
use x86_64::VirtAddr;
20-
2120
kernel::init();
2221
let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset);
2322
let mut mapper = unsafe { memory::init(phys_mem_offset) };

0 commit comments

Comments
 (0)