From 8cb2e9b344230227fe5f3ab3ebeb2522f1c5e289 Mon Sep 17 00:00:00 2001 From: LoGin Date: Thu, 21 Mar 2024 19:19:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99SMP=E6=A8=A1=E5=9D=97=20(#633?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复cpumask的迭代器的错误。 * 能进系统(AP核心还没有初始化自身) * 初始化ap core * 修改percpu * 删除无用的cpu.c * riscv64编译通过 --- kernel/src/Makefile | 2 +- kernel/src/arch/riscv64/smp/mod.rs | 7 +- kernel/src/arch/riscv64/time.rs | 4 + kernel/src/arch/x86_64/asm/apu_boot.S | 2 +- kernel/src/arch/x86_64/c_adapter.rs | 25 -- kernel/src/arch/x86_64/cpu.rs | 6 +- kernel/src/arch/x86_64/init/main.c | 11 - kernel/src/arch/x86_64/init/mod.rs | 7 - kernel/src/arch/x86_64/interrupt/c_adapter.rs | 17 -- kernel/src/arch/x86_64/interrupt/ipi.rs | 3 +- kernel/src/arch/x86_64/interrupt/mod.rs | 9 +- kernel/src/arch/x86_64/mm/c_adapter.rs | 7 - kernel/src/arch/x86_64/mm/mod.rs | 20 +- kernel/src/arch/x86_64/mod.rs | 1 - kernel/src/arch/x86_64/smp/mod.rs | 156 +++++++++-- kernel/src/arch/x86_64/time.rs | 6 + kernel/src/common/cpu.h | 61 ----- kernel/src/driver/keyboard/ps2_keyboard.rs | 2 +- kernel/src/driver/tty/virtual_terminal/mod.rs | 1 - kernel/src/exception/mod.rs | 5 + kernel/src/include/bindings/wrapper.h | 2 - kernel/src/init/init.rs | 6 +- kernel/src/init/initial_kthread.rs | 3 + kernel/src/libs/cpu.c | 109 -------- kernel/src/libs/cpumask.rs | 30 +- kernel/src/libs/wait_queue.rs | 4 +- kernel/src/mm/mod.rs | 18 +- kernel/src/mm/percpu.rs | 21 +- kernel/src/process/idle.rs | 4 +- kernel/src/process/mod.rs | 4 +- kernel/src/process/process.h | 1 - kernel/src/sched/cfs.rs | 4 +- kernel/src/sched/rt.rs | 6 +- kernel/src/smp/Makefile | 8 - kernel/src/smp/c_adapter.rs | 13 - kernel/src/smp/cpu/c_adapter.rs | 79 ------ kernel/src/smp/cpu/mod.rs | 256 +++++++++++++++++- kernel/src/smp/init.rs | 27 ++ kernel/src/smp/mod.rs | 24 +- kernel/src/smp/smp.c | 182 ------------- kernel/src/smp/smp.h | 23 -- kernel/src/time/mod.rs | 11 + kernel/src/time/sleep.rs | 9 +- kernel/src/time/timer.rs | 2 + 44 files changed, 544 insertions(+), 654 deletions(-) delete mode 100644 kernel/src/arch/x86_64/c_adapter.rs delete mode 100644 kernel/src/arch/x86_64/init/main.c delete mode 100644 kernel/src/arch/x86_64/interrupt/c_adapter.rs delete mode 100644 kernel/src/arch/x86_64/mm/c_adapter.rs delete mode 100644 kernel/src/common/cpu.h delete mode 100644 kernel/src/libs/cpu.c delete mode 100644 kernel/src/smp/Makefile delete mode 100644 kernel/src/smp/c_adapter.rs delete mode 100644 kernel/src/smp/cpu/c_adapter.rs create mode 100644 kernel/src/smp/init.rs delete mode 100644 kernel/src/smp/smp.c delete mode 100644 kernel/src/smp/smp.h diff --git a/kernel/src/Makefile b/kernel/src/Makefile index 204f63fd..4b28062c 100644 --- a/kernel/src/Makefile +++ b/kernel/src/Makefile @@ -36,7 +36,7 @@ export ASFLAGS := --64 LD_LIST := "" -kernel_subdirs := common driver debug smp syscall libs time +kernel_subdirs := common driver debug syscall libs time kernel_rust: diff --git a/kernel/src/arch/riscv64/smp/mod.rs b/kernel/src/arch/riscv64/smp/mod.rs index 5cc93a1a..42f75185 100644 --- a/kernel/src/arch/riscv64/smp/mod.rs +++ b/kernel/src/arch/riscv64/smp/mod.rs @@ -1,6 +1,9 @@ use system_error::SystemError; -use crate::smp::SMPArch; +use crate::smp::{ + cpu::{CpuHpCpuState, ProcessorId}, + SMPArch, +}; pub struct RiscV64SMPArch; @@ -10,7 +13,7 @@ impl SMPArch for RiscV64SMPArch { todo!() } - fn init() -> Result<(), SystemError> { + fn start_cpu(cpu_id: ProcessorId, hp_state: &CpuHpCpuState) -> Result<(), SystemError> { todo!() } } diff --git a/kernel/src/arch/riscv64/time.rs b/kernel/src/arch/riscv64/time.rs index 248f003e..5e876498 100644 --- a/kernel/src/arch/riscv64/time.rs +++ b/kernel/src/arch/riscv64/time.rs @@ -5,4 +5,8 @@ impl TimeArch for RiscV64TimeArch { fn get_cycles() -> usize { riscv::register::cycle::read() } + + fn cal_expire_cycles(ns: usize) -> usize { + todo!() + } } diff --git a/kernel/src/arch/x86_64/asm/apu_boot.S b/kernel/src/arch/x86_64/asm/apu_boot.S index a00fafb1..7716e680 100644 --- a/kernel/src/arch/x86_64/asm/apu_boot.S +++ b/kernel/src/arch/x86_64/asm/apu_boot.S @@ -20,7 +20,7 @@ _apu_boot_base = . // 设置栈指针 movl $(_apu_boot_tmp_stack_end - _apu_boot_base), %esp - + // 计算ap处理器引导程序的基地址 mov %cs, %ax movzx %ax, %esi diff --git a/kernel/src/arch/x86_64/c_adapter.rs b/kernel/src/arch/x86_64/c_adapter.rs deleted file mode 100644 index 3cffb50e..00000000 --- a/kernel/src/arch/x86_64/c_adapter.rs +++ /dev/null @@ -1,25 +0,0 @@ -use crate::{sched::SchedArch, time::TimeArch}; - -use super::{driver::tsc::TSCManager, syscall::init_syscall_64, CurrentSchedArch, CurrentTimeArch}; - -/// 获取当前的时间戳 -#[no_mangle] -unsafe extern "C" fn rs_get_cycles() -> u64 { - return CurrentTimeArch::get_cycles() as u64; -} - -#[no_mangle] -unsafe extern "C" fn rs_tsc_get_cpu_khz() -> u64 { - return TSCManager::cpu_khz(); -} - -/// syscall指令初始化 -#[no_mangle] -pub unsafe extern "C" fn rs_init_syscall_64() { - init_syscall_64(); -} - -#[no_mangle] -unsafe extern "C" fn rs_init_current_core_sched() { - CurrentSchedArch::initial_setup_sched_local(); -} diff --git a/kernel/src/arch/x86_64/cpu.rs b/kernel/src/arch/x86_64/cpu.rs index ee1c8478..bf3c9666 100644 --- a/kernel/src/arch/x86_64/cpu.rs +++ b/kernel/src/arch/x86_64/cpu.rs @@ -1,6 +1,6 @@ use x86::cpuid::{cpuid, CpuIdResult}; -use crate::smp::cpu::{ProcessorId, SmpCpuManager}; +use crate::smp::cpu::ProcessorId; /// 获取当前cpu的apic id #[inline] @@ -16,7 +16,3 @@ pub unsafe fn cpu_reset() -> ! { unsafe { x86::io::outb(0x64, 0xfe) }; loop {} } - -impl SmpCpuManager { - pub fn arch_init(_boot_cpu: ProcessorId) {} -} diff --git a/kernel/src/arch/x86_64/init/main.c b/kernel/src/arch/x86_64/init/main.c deleted file mode 100644 index 125e53c5..00000000 --- a/kernel/src/arch/x86_64/init/main.c +++ /dev/null @@ -1,11 +0,0 @@ -// -// Created by longjin on 2022/1/20. -// - -#include - - -void __init_set_cpu_stack_start(uint32_t cpu, uint64_t stack_start) -{ - cpu_core_info[cpu].stack_start = stack_start; -} diff --git a/kernel/src/arch/x86_64/init/mod.rs b/kernel/src/arch/x86_64/init/mod.rs index 95bbf3c2..cf95e35c 100644 --- a/kernel/src/arch/x86_64/init/mod.rs +++ b/kernel/src/arch/x86_64/init/mod.rs @@ -6,7 +6,6 @@ use x86::dtables::DescriptorTablePointer; use crate::{ arch::{interrupt::trap::arch_trap_init, process::table::TSSManager}, driver::pci::pci::pci_init, - include::bindings::bindings::cpu_init, init::init::start_kernel, kdebug, mm::{MemoryManagementArch, PhysAddr}, @@ -33,7 +32,6 @@ extern "C" { fn head_stack_start(); fn multiboot2_init(mb2_info: u64, mb2_magic: u32) -> bool; - fn __init_set_cpu_stack_start(cpu: u32, stack_start: u64); } #[no_mangle] @@ -81,7 +79,6 @@ pub fn early_setup_arch() -> Result<(), SystemError> { set_current_core_tss(stack_start, 0); unsafe { TSSManager::load_tr() }; - unsafe { __init_set_cpu_stack_start(0, stack_start as u64) }; arch_trap_init().expect("arch_trap_init failed"); return Ok(()); @@ -90,10 +87,6 @@ pub fn early_setup_arch() -> Result<(), SystemError> { /// 架构相关的初始化 #[inline(never)] pub fn setup_arch() -> Result<(), SystemError> { - unsafe { - cpu_init(); - } - // todo: 将来pci接入设备驱动模型之后,删掉这里。 pci_init(); return Ok(()); diff --git a/kernel/src/arch/x86_64/interrupt/c_adapter.rs b/kernel/src/arch/x86_64/interrupt/c_adapter.rs deleted file mode 100644 index 461b41b3..00000000 --- a/kernel/src/arch/x86_64/interrupt/c_adapter.rs +++ /dev/null @@ -1,17 +0,0 @@ -use crate::smp::cpu::ProcessorId; - -use super::ipi::{ipi_send_smp_init, ipi_send_smp_startup}; - -#[no_mangle] -unsafe extern "C" fn rs_ipi_send_smp_init() -> i32 { - return ipi_send_smp_init() - .map(|_| 0) - .unwrap_or_else(|e| e.to_posix_errno()); -} - -#[no_mangle] -unsafe extern "C" fn rs_ipi_send_smp_startup(target_cpu: u32) -> i32 { - return ipi_send_smp_startup(ProcessorId::new(target_cpu)) - .map(|_| 0) - .unwrap_or_else(|e| e.to_posix_errno()); -} diff --git a/kernel/src/arch/x86_64/interrupt/ipi.rs b/kernel/src/arch/x86_64/interrupt/ipi.rs index 3995171c..df25b821 100644 --- a/kernel/src/arch/x86_64/interrupt/ipi.rs +++ b/kernel/src/arch/x86_64/interrupt/ipi.rs @@ -160,7 +160,7 @@ pub fn send_ipi(kind: IpiKind, target: IpiTarget) { } /// 发送smp初始化IPI -pub fn ipi_send_smp_init() -> Result<(), SystemError> { +pub fn ipi_send_smp_init() { let target = ArchIpiTarget::Other; let icr = if CurrentApic.x2apic_enabled() { x86::apic::Icr::for_x2apic( @@ -186,7 +186,6 @@ pub fn ipi_send_smp_init() -> Result<(), SystemError> { ) }; CurrentApic.write_icr(icr); - return Ok(()); } /// 发送smp启动IPI diff --git a/kernel/src/arch/x86_64/interrupt/mod.rs b/kernel/src/arch/x86_64/interrupt/mod.rs index 69334718..b5ae9787 100644 --- a/kernel/src/arch/x86_64/interrupt/mod.rs +++ b/kernel/src/arch/x86_64/interrupt/mod.rs @@ -1,4 +1,3 @@ -mod c_adapter; pub(super) mod entry; mod handle; pub mod ipi; @@ -93,6 +92,14 @@ impl InterruptArch for X86_64InterruptArch { fn arch_early_irq_init() -> Result<(), SystemError> { arch_early_irq_init() } + + fn arch_ap_early_irq_init() -> Result<(), SystemError> { + if !CurrentApic.init_current_cpu() { + return Err(SystemError::ENODEV); + } + + Ok(()) + } } /// 中断栈帧结构体 diff --git a/kernel/src/arch/x86_64/mm/c_adapter.rs b/kernel/src/arch/x86_64/mm/c_adapter.rs deleted file mode 100644 index 90926ea9..00000000 --- a/kernel/src/arch/x86_64/mm/c_adapter.rs +++ /dev/null @@ -1,7 +0,0 @@ -use super::LowAddressRemapping; - -#[no_mangle] -unsafe extern "C" fn rs_unmap_at_low_addr() -> usize { - LowAddressRemapping::unmap_at_low_address(true); - return 0; -} diff --git a/kernel/src/arch/x86_64/mm/mod.rs b/kernel/src/arch/x86_64/mm/mod.rs index c76fa52d..b13619fe 100644 --- a/kernel/src/arch/x86_64/mm/mod.rs +++ b/kernel/src/arch/x86_64/mm/mod.rs @@ -1,6 +1,5 @@ pub mod barrier; pub mod bump; -mod c_adapter; use alloc::vec::Vec; use hashbrown::HashSet; @@ -159,6 +158,7 @@ impl MemoryManagementArch for X86_64MMArch { // 初始化内存管理器 unsafe { allocator_init() }; + send_to_default_serial8250_port("x86 64 init done\n\0".as_bytes()); } @@ -181,11 +181,10 @@ impl MemoryManagementArch for X86_64MMArch { unsafe fn table(table_kind: PageTableKind) -> PhysAddr { match table_kind { PageTableKind::Kernel | PageTableKind::User => { - let paddr: usize; compiler_fence(Ordering::SeqCst); - asm!("mov {}, cr3", out(reg) paddr, options(nomem, nostack, preserves_flags)); + let cr3 = x86::controlregs::cr3() as usize; compiler_fence(Ordering::SeqCst); - return PhysAddr::new(paddr); + return PhysAddr::new(cr3); } PageTableKind::EPT => { let eptp = @@ -461,9 +460,6 @@ unsafe fn allocator_init() { flusher.ignore(); } } - - // 添加低地址的映射(在smp完成初始化之前,需要使用低地址的映射.初始化之后需要取消这一段映射) - LowAddressRemapping::remap_at_low_address(&mut mapper); } unsafe { @@ -659,9 +655,7 @@ impl LowAddressRemapping { // 映射64M const REMAP_SIZE: usize = 64 * 1024 * 1024; - pub unsafe fn remap_at_low_address( - mapper: &mut crate::mm::page::PageMapper>, - ) { + pub unsafe fn remap_at_low_address(mapper: &mut PageMapper) { for i in 0..(Self::REMAP_SIZE / MMArch::PAGE_SIZE) { let paddr = PhysAddr::new(i * MMArch::PAGE_SIZE); let vaddr = VirtAddr::new(i * MMArch::PAGE_SIZE); @@ -676,14 +670,10 @@ impl LowAddressRemapping { } /// 取消低地址的映射 - pub unsafe fn unmap_at_low_address(flush: bool) { - let mut mapper = KernelMapper::lock(); - assert!(mapper.as_mut().is_some()); + pub unsafe fn unmap_at_low_address(mapper: &mut PageMapper, flush: bool) { for i in 0..(Self::REMAP_SIZE / MMArch::PAGE_SIZE) { let vaddr = VirtAddr::new(i * MMArch::PAGE_SIZE); let (_, _, flusher) = mapper - .as_mut() - .unwrap() .unmap_phys(vaddr, true) .expect("Failed to unmap frame"); if flush == false { diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index 8b768f96..b2069f08 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -1,7 +1,6 @@ #[macro_use] pub mod asm; mod acpi; -mod c_adapter; pub mod cpu; pub mod driver; pub mod elf; diff --git a/kernel/src/arch/x86_64/smp/mod.rs b/kernel/src/arch/x86_64/smp/mod.rs index 15630f5e..59d5938f 100644 --- a/kernel/src/arch/x86_64/smp/mod.rs +++ b/kernel/src/arch/x86_64/smp/mod.rs @@ -1,27 +1,38 @@ use core::{ arch::asm, hint::spin_loop, - sync::atomic::{compiler_fence, AtomicBool, Ordering}, + sync::atomic::{compiler_fence, fence, AtomicBool, Ordering}, }; use kdepends::memoffset::offset_of; use system_error::SystemError; use crate::{ - arch::process::table::TSSManager, + arch::{mm::LowAddressRemapping, process::table::TSSManager, MMArch}, exception::InterruptArch, - include::bindings::bindings::{cpu_core_info, smp_init}, kdebug, - libs::rwlock::RwLock, - mm::percpu::PerCpu, + libs::{cpumask::CpuMask, rwlock::RwLock}, + mm::{percpu::PerCpu, MemoryManagementArch, PhysAddr, VirtAddr, IDLE_PROCESS_ADDRESS_SPACE}, process::ProcessManager, - smp::{core::smp_get_processor_id, cpu::ProcessorId, SMPArch}, + smp::{ + core::smp_get_processor_id, + cpu::{smp_cpu_manager, CpuHpCpuState, ProcessorId, SmpCpuManager}, + init::smp_ap_start_stage2, + SMPArch, + }, }; -use super::{acpi::early_acpi_boot_init, CurrentIrqArch}; +use super::{ + acpi::early_acpi_boot_init, + interrupt::ipi::{ipi_send_smp_init, ipi_send_smp_startup}, + CurrentIrqArch, +}; extern "C" { - fn smp_ap_start_stage2(); + /// AP处理器启动时,会将CR3设置为这个值 + pub static mut __APU_START_CR3: u64; + fn _apu_boot_start(); + fn _apu_boot_end(); } pub(super) static X86_64_SMP_MANAGER: X86_64SmpManager = X86_64SmpManager::new(); @@ -35,7 +46,17 @@ struct ApStartStackInfo { #[no_mangle] unsafe extern "C" fn smp_ap_start() -> ! { CurrentIrqArch::interrupt_disable(); - let vaddr = cpu_core_info[smp_get_processor_id().data() as usize].stack_start as usize; + let vaddr = if let Some(t) = smp_cpu_manager() + .cpuhp_state(smp_get_processor_id()) + .thread() + { + t.kernel_stack().stack_max_address().data() - 16 + } else { + // 没有设置ap核心的栈,那么就进入死循环。 + loop { + spin_loop(); + } + }; compiler_fence(core::sync::atomic::Ordering::SeqCst); let v = ApStartStackInfo { vaddr }; smp_init_switch_stack(&v); @@ -49,7 +70,7 @@ unsafe extern "sysv64" fn smp_init_switch_stack(st: &ApStartStackInfo) -> ! { jmp {stage1} "), off_rsp = const(offset_of!(ApStartStackInfo, vaddr)), - stage1 = sym smp_ap_start_stage1, + stage1 = sym smp_ap_start_stage1, options(noreturn)); } @@ -66,10 +87,9 @@ unsafe extern "C" fn smp_ap_start_stage1() -> ! { ); TSSManager::load_tr(); + CurrentIrqArch::arch_ap_early_irq_init().expect("arch_ap_early_irq_init failed"); + smp_ap_start_stage2(); - loop { - spin_loop(); - } } /// 多核的数据 @@ -141,10 +161,34 @@ impl X86_64SmpManager { pub fn build_cpu_map(&self) -> Result<(), SystemError> { // 参考:https://code.dragonos.org.cn/xref/linux-6.1.9/arch/ia64/kernel/smpboot.c?fi=smp_build_cpu_map#496 // todo!("build_cpu_map") + unsafe { + smp_cpu_manager().set_possible_cpu(ProcessorId::new(0), true); + smp_cpu_manager().set_present_cpu(ProcessorId::new(0), true); + smp_cpu_manager().set_online_cpu(ProcessorId::new(0)); + } + + for cpu in 1..SMP_BOOT_DATA.cpu_count() { + unsafe { + smp_cpu_manager().set_possible_cpu(ProcessorId::new(cpu as u32), true); + smp_cpu_manager().set_present_cpu(ProcessorId::new(cpu as u32), true); + } + } + + print_cpus("possible", smp_cpu_manager().possible_cpus()); + print_cpus("present", smp_cpu_manager().present_cpus()); return Ok(()); } } +fn print_cpus(s: &str, mask: &CpuMask) { + let mut v = vec![]; + for cpu in mask.iter_cpu() { + v.push(cpu.data()); + } + + kdebug!("{s}: cpus: {v:?}\n"); +} + pub struct X86_64SMPArch; impl SMPArch for X86_64SMPArch { @@ -155,11 +199,87 @@ impl SMPArch for X86_64SMPArch { return Ok(()); } - #[inline(never)] - fn init() -> Result<(), SystemError> { - x86::fence::mfence(); - unsafe { smp_init() }; - x86::fence::mfence(); + fn post_init() -> Result<(), SystemError> { + // AP核心启动完毕,取消低地址映射 + unsafe { + LowAddressRemapping::unmap_at_low_address( + &mut IDLE_PROCESS_ADDRESS_SPACE() + .write_irqsave() + .user_mapper + .utable, + true, + ) + } + return Ok(()); + } + + fn start_cpu(cpu_id: ProcessorId, _cpu_hpstate: &CpuHpCpuState) -> Result<(), SystemError> { + kdebug!("start_cpu: cpu_id: {:#x}\n", cpu_id.data()); + + Self::copy_smp_start_code(); + + ipi_send_smp_init(); + fence(Ordering::SeqCst); + ipi_send_smp_startup(cpu_id)?; + fence(Ordering::SeqCst); + ipi_send_smp_startup(cpu_id)?; + fence(Ordering::SeqCst); + return Ok(()); } } + +impl X86_64SMPArch { + const SMP_CODE_START: usize = 0x20000; + /// 复制SMP启动代码到0x20000处 + fn copy_smp_start_code() -> (VirtAddr, usize) { + let apu_boot_size = Self::start_code_size(); + + fence(Ordering::SeqCst); + unsafe { + core::ptr::copy( + _apu_boot_start as *const u8, + Self::SMP_CODE_START as *mut u8, + apu_boot_size, + ) + }; + fence(Ordering::SeqCst); + + return (VirtAddr::new(Self::SMP_CODE_START), apu_boot_size); + } + + fn start_code_size() -> usize { + let apu_boot_start = _apu_boot_start as usize; + let apu_boot_end = _apu_boot_end as usize; + let apu_boot_size = apu_boot_end - apu_boot_start; + return apu_boot_size; + } +} + +impl SmpCpuManager { + pub fn arch_init(_boot_cpu: ProcessorId) { + assert!(smp_get_processor_id().data() == 0); + // 写入APU_START_CR3,这个值会在AP处理器启动时设置到CR3寄存器 + let addr = IDLE_PROCESS_ADDRESS_SPACE() + .read_irqsave() + .user_mapper + .utable + .table() + .phys(); + let vaddr = unsafe { + MMArch::phys_2_virt(PhysAddr::new(&mut __APU_START_CR3 as *mut u64 as usize)).unwrap() + }; + let ptr = vaddr.data() as *mut u64; + unsafe { *ptr = addr.data() as u64 }; + + // 添加低地址映射 + unsafe { + LowAddressRemapping::remap_at_low_address( + &mut IDLE_PROCESS_ADDRESS_SPACE() + .write_irqsave() + .user_mapper + .utable, + ) + }; + } +} diff --git a/kernel/src/arch/x86_64/time.rs b/kernel/src/arch/x86_64/time.rs index 6bc977e1..4edd6483 100644 --- a/kernel/src/arch/x86_64/time.rs +++ b/kernel/src/arch/x86_64/time.rs @@ -1,9 +1,15 @@ use crate::time::TimeArch; +use super::driver::tsc::TSCManager; + pub struct X86_64TimeArch; impl TimeArch for X86_64TimeArch { fn get_cycles() -> usize { unsafe { x86::time::rdtsc() as usize } } + + fn cal_expire_cycles(ns: usize) -> usize { + Self::get_cycles() + ns * TSCManager::cpu_khz() as usize / 1000000 + } } diff --git a/kernel/src/common/cpu.h b/kernel/src/common/cpu.h deleted file mode 100644 index 0fa33c51..00000000 --- a/kernel/src/common/cpu.h +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once - -#include "glib.h" - -#define MAX_CPU_NUM 32 // 操作系统支持的最大处理器数量 - -// cpu支持的最大cpuid指令的基础主功能号 -extern uint32_t Cpu_cpuid_max_Basic_mop; -// cpu支持的最大cpuid指令的扩展主功能号 -extern uint32_t Cpu_cpuid_max_Extended_mop; -// cpu制造商信息 -extern char Cpu_Manufacturer_Name[17]; -// 处理器名称信息 -extern char Cpu_BrandName[49]; -// 处理器家族ID -extern uint32_t Cpu_Family_ID; -// 处理器扩展家族ID -extern uint32_t Cpu_Extended_Family_ID; -// 处理器模式ID -extern uint32_t Cpu_Model_ID; -// 处理器扩展模式ID -extern uint32_t Cpu_Extended_Model_ID; -// 处理器步进ID -extern uint32_t Cpu_Stepping_ID; -// 处理器类型 -extern uint32_t Cpu_Processor_Type; -// 处理器支持的最大物理地址可寻址地址线宽度 -extern uint32_t Cpu_max_phys_addrline_size; -// 处理器支持的最大线性地址可寻址地址线宽度 -extern uint32_t Cpu_max_linear_addrline_size; - -// 处理器的tsc频率(单位:hz)(HPET定时器在测定apic频率时,顺便测定了这个值) -extern uint64_t Cpu_tsc_freq; - -/** - * @brief 执行cpuid指令 - * - * @param mop 主功能号 - * @param sop 子功能号 - * @param eax 结果的eax值 - * @param ebx 结果的ebx值 - * @param ecx 结果的ecx值 - * @param edx 结果的edx值 - * - * cpuid指令参考英特尔开发手册卷2A Chapter3 3.2 Instruction - */ -void cpu_cpuid(uint32_t mop, uint32_t sop, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx); - -/** - * @brief 初始化获取处理器信息模块 - * - */ -void cpu_init(void); - -struct cpu_core_info_t -{ - uint64_t stack_start; // 栈基地址 - uint64_t ist_stack_start; // IST栈基地址 -}; - -extern struct cpu_core_info_t cpu_core_info[MAX_CPU_NUM]; diff --git a/kernel/src/driver/keyboard/ps2_keyboard.rs b/kernel/src/driver/keyboard/ps2_keyboard.rs index 3ccda94f..bd4ba49e 100644 --- a/kernel/src/driver/keyboard/ps2_keyboard.rs +++ b/kernel/src/driver/keyboard/ps2_keyboard.rs @@ -181,7 +181,7 @@ impl IrqHandler for Ps2KeyboardIrqHandler { let status = unsafe { CurrentPortIOArch::in8(PORT_PS2_KEYBOARD_STATUS.into()) }; let status = Ps2StatusRegister::from(status); if !status.outbuf_full() { - return Ok(IrqReturn::NotHandled); + return Ok(IrqReturn::Handled); } let input = unsafe { CurrentPortIOArch::in8(PORT_PS2_KEYBOARD_DATA.into()) }; diff --git a/kernel/src/driver/tty/virtual_terminal/mod.rs b/kernel/src/driver/tty/virtual_terminal/mod.rs index b92aeb06..1f8ab8d6 100644 --- a/kernel/src/driver/tty/virtual_terminal/mod.rs +++ b/kernel/src/driver/tty/virtual_terminal/mod.rs @@ -183,7 +183,6 @@ impl TtyOperation for TtyConsoleDriverInner { let mut window_size = window_size.upgrade(); window_size.col = vc_data.cols as u16; window_size.row = vc_data.rows as u16; - kerror!("window_size {:?}", *window_size); } if vc_data.utf { diff --git a/kernel/src/exception/mod.rs b/kernel/src/exception/mod.rs index a483fce3..c7df823e 100644 --- a/kernel/src/exception/mod.rs +++ b/kernel/src/exception/mod.rs @@ -40,6 +40,11 @@ pub trait InterruptArch: Send + Sync { Ok(()) } + /// ap启动时的中断初始化 + fn arch_ap_early_irq_init() -> Result<(), SystemError> { + Ok(()) + } + /// 响应未注册的中断 fn ack_bad_irq(irq: IrqNumber); } diff --git a/kernel/src/include/bindings/wrapper.h b/kernel/src/include/bindings/wrapper.h index 386aa1a8..cff40a6b 100644 --- a/kernel/src/include/bindings/wrapper.h +++ b/kernel/src/include/bindings/wrapper.h @@ -25,8 +25,6 @@ #include #include #include -#include #include