diff --git a/Cargo.lock b/Cargo.lock index c58981e641..2fc9961773 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -581,7 +581,7 @@ dependencies = [ "trapframe", "uart_16550", "x86", - "x86_64", + "x86_64 0.15.0", "zerocopy", ] @@ -1310,7 +1310,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f287ee70169f5bfddba441baf901b620e3655f16fa7815f48a7e100ec6d86a8f" dependencies = [ "raw-cpuid", - "x86_64", + "x86_64 0.14.12", ] [[package]] @@ -1605,6 +1605,18 @@ dependencies = [ "volatile", ] +[[package]] +name = "x86_64" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd9b58dbbd61248db1d7d5b7068fbe91b042e889361fe79fb4fd16a12daa66d3" +dependencies = [ + "bit_field", + "bitflags 2.4.2", + "rustversion", + "volatile", +] + [[package]] name = "xshell" version = "0.2.5" diff --git a/Cargo.toml b/Cargo.toml index a2eec32ab9..a8bc472657 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -126,7 +126,7 @@ features = [ multiboot = "0.8" uart_16550 = "0.3" x86 = { version = "0.52", default-features = false } -x86_64 = "0.14" +x86_64 = "0.15" qemu-exit = "3.0" [target.'cfg(target_arch = "aarch64")'.dependencies] diff --git a/src/arch/x86_64/kernel/apic.rs b/src/arch/x86_64/kernel/apic.rs index e16cfe16ec..5f2425cb80 100644 --- a/src/arch/x86_64/kernel/apic.rs +++ b/src/arch/x86_64/kernel/apic.rs @@ -477,19 +477,19 @@ pub fn init() { // Set gates to ISRs for the APIC interrupts we are going to enable. unsafe { let mut idt = IDT.lock(); - idt[ERROR_INTERRUPT_NUMBER as usize] + idt[ERROR_INTERRUPT_NUMBER] .set_handler_fn(error_interrupt_handler) .set_stack_index(0); - idt[SPURIOUS_INTERRUPT_NUMBER as usize] + idt[SPURIOUS_INTERRUPT_NUMBER] .set_handler_fn(spurious_interrupt_handler) .set_stack_index(0); #[cfg(feature = "smp")] { - idt[TLB_FLUSH_INTERRUPT_NUMBER as usize] + idt[TLB_FLUSH_INTERRUPT_NUMBER] .set_handler_fn(tlb_flush_handler) .set_stack_index(0); interrupts::add_irq_name(TLB_FLUSH_INTERRUPT_NUMBER - 32, "TLB flush"); - idt[WAKEUP_INTERRUPT_NUMBER as usize] + idt[WAKEUP_INTERRUPT_NUMBER] .set_handler_fn(wakeup_handler) .set_stack_index(0); interrupts::add_irq_name(WAKEUP_INTERRUPT_NUMBER - 32, "Wakeup"); diff --git a/src/arch/x86_64/kernel/gdt.rs b/src/arch/x86_64/kernel/gdt.rs index bd0a6dfdfe..43b72685be 100644 --- a/src/arch/x86_64/kernel/gdt.rs +++ b/src/arch/x86_64/kernel/gdt.rs @@ -18,14 +18,14 @@ use crate::config::KERNEL_STACK_SIZE; pub fn add_current_core() { let gdt: &mut GlobalDescriptorTable = Box::leak(Box::new(GlobalDescriptorTable::new())); - let kernel_code_selector = gdt.add_entry(Descriptor::kernel_code_segment()); - let kernel_data_selector = gdt.add_entry(Descriptor::kernel_data_segment()); + let kernel_code_selector = gdt.append(Descriptor::kernel_code_segment()); + let kernel_data_selector = gdt.append(Descriptor::kernel_data_segment()); #[cfg(feature = "common-os")] { let _user_code32_selector = - gdt.add_entry(Descriptor::UserSegment(DescriptorFlags::USER_CODE32.bits())); - let _user_data64_selector = gdt.add_entry(Descriptor::user_data_segment()); - let _user_code64_selector = gdt.add_entry(Descriptor::user_code_segment()); + gdt.append(Descriptor::UserSegment(DescriptorFlags::USER_CODE32.bits())); + let _user_data64_selector = gdt.append(Descriptor::user_data_segment()); + let _user_code64_selector = gdt.append(Descriptor::user_code_segment()); } // Dynamically allocate memory for a Task-State Segment (TSS) for this core. @@ -53,7 +53,7 @@ pub fn add_current_core() { } CoreLocal::get().tss.set(tss); - let tss_selector = gdt.add_entry(Descriptor::tss_segment(tss)); + let tss_selector = gdt.append(Descriptor::tss_segment(tss)); // Load the GDT for the current core. gdt.load(); diff --git a/src/arch/x86_64/kernel/interrupts.rs b/src/arch/x86_64/kernel/interrupts.rs index ed310a97bf..fd170b0f58 100644 --- a/src/arch/x86_64/kernel/interrupts.rs +++ b/src/arch/x86_64/kernel/interrupts.rs @@ -40,7 +40,7 @@ pub(crate) fn install() { set_general_handler!(&mut *idt, unknown, 64..); unsafe { - for i in 32..256 { + for i in 32..=255 { let addr = idt[i].handler_addr(); idt[i].set_handler_addr(addr).set_stack_index(0); } @@ -117,7 +117,7 @@ pub extern "C" fn irq_install_handler( let mut idt = IDT.lock(); unsafe { - idt[(32 + irq_number) as usize] + idt[32 + irq_number] .set_handler_addr(x86_64::VirtAddr::new( u64::try_from(handler as usize).unwrap(), )) diff --git a/src/arch/x86_64/kernel/pic.rs b/src/arch/x86_64/kernel/pic.rs index 96c9503e84..2fc5a3cd7b 100644 --- a/src/arch/x86_64/kernel/pic.rs +++ b/src/arch/x86_64/kernel/pic.rs @@ -34,10 +34,10 @@ pub fn init() { // This is especially true for real hardware. So provide a handler for them. unsafe { let mut idt = IDT.lock(); - idt[(PIC1_INTERRUPT_OFFSET + SPURIOUS_IRQ_NUMBER) as usize] + idt[PIC1_INTERRUPT_OFFSET + SPURIOUS_IRQ_NUMBER] .set_handler_fn(spurious_interrupt_on_master) .set_stack_index(0); - idt[(PIC2_INTERRUPT_OFFSET + SPURIOUS_IRQ_NUMBER) as usize] + idt[PIC2_INTERRUPT_OFFSET + SPURIOUS_IRQ_NUMBER] .set_handler_fn(spurious_interrupt_on_slave) .set_stack_index(0); diff --git a/src/arch/x86_64/kernel/processor.rs b/src/arch/x86_64/kernel/processor.rs index dafbdf1f5d..526862a4e7 100644 --- a/src/arch/x86_64/kernel/processor.rs +++ b/src/arch/x86_64/kernel/processor.rs @@ -416,7 +416,7 @@ impl CpuFrequency { // system timer with a known constant frequency. unsafe { let mut idt = IDT.lock(); - idt[pit::PIT_INTERRUPT_NUMBER as usize] + idt[pit::PIT_INTERRUPT_NUMBER] .set_handler_fn(Self::measure_frequency_timer_handler) .set_stack_index(0); } diff --git a/src/arch/x86_64/kernel/scheduler.rs b/src/arch/x86_64/kernel/scheduler.rs index 369b7512f3..f6d39ea40d 100644 --- a/src/arch/x86_64/kernel/scheduler.rs +++ b/src/arch/x86_64/kernel/scheduler.rs @@ -388,7 +388,7 @@ extern "x86-interrupt" fn timer_handler(_stack_frame: interrupts::ExceptionStack pub fn install_timer_handler() { unsafe { let mut idt = IDT.lock(); - idt[apic::TIMER_INTERRUPT_NUMBER as usize] + idt[apic::TIMER_INTERRUPT_NUMBER] .set_handler_fn(timer_handler) .set_stack_index(0); } diff --git a/src/arch/x86_64/kernel/serial.rs b/src/arch/x86_64/kernel/serial.rs index 53361f7fc3..5db44653ca 100644 --- a/src/arch/x86_64/kernel/serial.rs +++ b/src/arch/x86_64/kernel/serial.rs @@ -92,7 +92,7 @@ extern "x86-interrupt" fn serial_interrupt(_stack_frame: crate::interrupts::Exce pub(crate) fn install_serial_interrupt() { unsafe { let mut idt = IDT.lock(); - idt[SERIAL_IRQ.into()] + idt[SERIAL_IRQ] .set_handler_fn(serial_interrupt) .set_stack_index(0); } diff --git a/src/arch/x86_64/mm/paging.rs b/src/arch/x86_64/mm/paging.rs index ea38d22ff3..0748b5dc42 100644 --- a/src/arch/x86_64/mm/paging.rs +++ b/src/arch/x86_64/mm/paging.rs @@ -3,6 +3,8 @@ use core::ptr; use x86_64::instructions::tlb; use x86_64::registers::control::Cr2; +#[cfg(feature = "common-os")] +use x86_64::registers::segmentation::SegmentSelector; pub use x86_64::structures::idt::InterruptStackFrame as ExceptionStackFrame; use x86_64::structures::idt::PageFaultErrorCode; use x86_64::structures::paging::mapper::{TranslateResult, UnmapError}; @@ -268,7 +270,7 @@ pub(crate) extern "x86-interrupt" fn page_fault_handler( error_code: PageFaultErrorCode, ) { error!("Page fault (#PF)!"); - error!("page_fault_linear_address = {:p}", Cr2::read()); + error!("page_fault_linear_address = {:p}", Cr2::read().unwrap()); error!("error_code = {error_code:?}"); error!("fs = {:#X}", processor::readfs()); error!("gs = {:#X}", processor::readgs()); @@ -282,12 +284,12 @@ pub(crate) extern "x86-interrupt" fn page_fault_handler( error_code: PageFaultErrorCode, ) { unsafe { - if stack_frame.as_mut().read().code_segment != 0x08 { + if stack_frame.as_mut().read().code_segment != SegmentSelector(0x08) { core::arch::asm!("swapgs", options(nostack)); } } error!("Page fault (#PF)!"); - error!("page_fault_linear_address = {:p}", Cr2::read()); + error!("page_fault_linear_address = {:p}", Cr2::read().unwrap()); error!("error_code = {error_code:?}"); error!("fs = {:#X}", processor::readfs()); error!("gs = {:#X}", processor::readgs()); @@ -397,7 +399,7 @@ pub(crate) unsafe fn print_page_tables(levels: usize) { } // Recursive - let mut recursive_page_table = unsafe { recursive_page_table() }; + let recursive_page_table = unsafe { recursive_page_table() }; let pt = recursive_page_table.level_4_table(); // Identity mapped diff --git a/src/arch/x86_64/mod.rs b/src/arch/x86_64/mod.rs index e4ccd0eb34..2998938989 100644 --- a/src/arch/x86_64/mod.rs +++ b/src/arch/x86_64/mod.rs @@ -1,6 +1,9 @@ pub mod kernel; pub mod mm; +#[cfg(feature = "common-os")] +use x86_64::registers::segmentation::SegmentSelector; + use crate::arch::mm::paging::ExceptionStackFrame; /// Helper function to swap the GS register, if the user-space is @@ -9,7 +12,7 @@ use crate::arch::mm::paging::ExceptionStackFrame; #[inline(always)] pub(crate) fn swapgs(stack_frame: &ExceptionStackFrame) { use core::arch::asm; - if stack_frame.code_segment != 8 { + if stack_frame.code_segment != SegmentSelector(8) { unsafe { asm!("swapgs", options(nomem, nostack, preserves_flags)); }