From 0be28ca762e07afaeef1eeddaf311df4c683e272 Mon Sep 17 00:00:00 2001 From: Solicey Date: Wed, 26 Nov 2025 18:35:59 +0800 Subject: [PATCH 1/9] support x86 platform ecx-2300f-peg, fix pci enumerate bugs --- platform/x86_64/ecx-2300f-peg/board.rs | 167 ++++++++++++++++++ .../ecx-2300f-peg/cargo/config.template.toml | 10 ++ platform/x86_64/ecx-2300f-peg/cargo/features | 2 + .../ecx-2300f-peg/image/bootloader/boot.S | 41 +++++ .../ecx-2300f-peg/image/bootloader/boot.ld | 15 ++ .../ecx-2300f-peg/image/bootloader/boot.mk | 36 ++++ .../image/font/solarize-12x29.psf | Bin 0 -> 29728 bytes .../ecx-2300f-peg/image/font/spleen-6x12.psf | Bin 0 -> 7859 bytes .../image/iso/boot/grub/grub.cfg | 27 +++ platform/x86_64/ecx-2300f-peg/linker.ld | 53 ++++++ platform/x86_64/ecx-2300f-peg/platform.mk | 51 ++++++ platform/x86_64/ecx-2300f-peg/test/runner.sh | 0 12 files changed, 402 insertions(+) create mode 100644 platform/x86_64/ecx-2300f-peg/board.rs create mode 100644 platform/x86_64/ecx-2300f-peg/cargo/config.template.toml create mode 100644 platform/x86_64/ecx-2300f-peg/cargo/features create mode 100644 platform/x86_64/ecx-2300f-peg/image/bootloader/boot.S create mode 100644 platform/x86_64/ecx-2300f-peg/image/bootloader/boot.ld create mode 100644 platform/x86_64/ecx-2300f-peg/image/bootloader/boot.mk create mode 100644 platform/x86_64/ecx-2300f-peg/image/font/solarize-12x29.psf create mode 100644 platform/x86_64/ecx-2300f-peg/image/font/spleen-6x12.psf create mode 100644 platform/x86_64/ecx-2300f-peg/image/iso/boot/grub/grub.cfg create mode 100644 platform/x86_64/ecx-2300f-peg/linker.ld create mode 100644 platform/x86_64/ecx-2300f-peg/platform.mk create mode 100644 platform/x86_64/ecx-2300f-peg/test/runner.sh diff --git a/platform/x86_64/ecx-2300f-peg/board.rs b/platform/x86_64/ecx-2300f-peg/board.rs new file mode 100644 index 00000000..262e6eeb --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/board.rs @@ -0,0 +1,167 @@ +// Copyright (c) 2025 Syswonder +// hvisor is licensed under Mulan PSL v2. +// You can use this software according to the terms and conditions of the Mulan PSL v2. +// You may obtain a copy of Mulan PSL v2 at: +// http://license.coscl.org.cn/MulanPSL2 +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR +// FIT FOR A PARTICULAR PURPOSE. +// See the Mulan PSL v2 for more details. +// +// Syswonder Website: +// https://www.syswonder.org +// +// Authors: +// +use crate::pci_dev; +use crate::{arch::zone::HvArchZoneConfig, config::*, memory::GuestPhysAddr}; + +pub const MEM_TYPE_RESERVED: u32 = 5; + +pub const BOARD_NCPUS: usize = 16; + +pub const ROOT_ZONE_DTB_ADDR: u64 = 0x00000000; +pub const ROOT_ZONE_BOOT_STACK: GuestPhysAddr = 0x7000; +pub const ROOT_ZONE_ENTRY: u64 = 0x8000; +pub const ROOT_ZONE_KERNEL_ADDR: u64 = 0x500_0000; // hpa +pub const ROOT_ZONE_CPUS: u64 = + (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7); + +const ROOT_ZONE_RSDP_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x50e_0000, + virtual_start: 0xe_0000, + size: 0x2_0000, +}; + +const ROOT_ZONE_ACPI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x3a30_0000, // hpa + virtual_start: 0x3530_0000, // gpa + size: 0x10_0000, // modify size accordingly +}; + +pub const ROOT_ZONE_NAME: &str = "root-linux"; +pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=tty0 nointremap no_timer_check pci=pcie_scan_all root=/dev/sdb2 rw init=/init rootwait\0"; +// pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=ttyS0 earlyprintk=serial nointremap no_timer_check pci=pcie_scan_all root=/dev/vda rw init=/init\0"; +//"console=ttyS0 earlyprintk=serial rdinit=/init nokaslr nointremap\0"; // noapic +// video=vesafb + +pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 10] = [ + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x500_0000, + virtual_start: 0x0, + size: 0xe_0000, + }, // ram + ROOT_ZONE_RSDP_REGION, // rsdp + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x510_0000, + virtual_start: 0x10_0000, + size: 0x14f0_0000, + }, // ram + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x1a00_0000, + virtual_start: 0x1500_0000, + size: 0x30_0000, + }, // ram + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x1a30_0000, + virtual_start: 0x1530_0000, + size: 0x2000_0000, + }, // ram + ROOT_ZONE_ACPI_REGION, // acpi + HvConfigMemoryRegion { + mem_type: MEM_TYPE_IO, + physical_start: 0xfed0_0000, + virtual_start: 0xfed0_0000, + size: 0x1000, + }, // hpet + // TODO: e820 mem space probe + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RESERVED, + physical_start: 0x1_0000_0000, + virtual_start: 0x1_0000_0000, + size: 0x2000_0000, + }, // zone 1 + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RESERVED, + physical_start: 0xfd00_0000, + virtual_start: 0xfd00_0000, + size: 0x100_0000, + }, // reserved + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RESERVED, + physical_start: 0x9000_0000, + virtual_start: 0x9000_0000, + size: 0x1000_0000, + }, // reserved +]; + +const ROOT_ZONE_CMDLINE_ADDR: GuestPhysAddr = 0x9000; +const ROOT_ZONE_SETUP_ADDR: GuestPhysAddr = 0xa000; +const ROOT_ZONE_VMLINUX_ENTRY_ADDR: GuestPhysAddr = 0x10_0000; +const ROOT_ZONE_SCREEN_BASE_ADDR: GuestPhysAddr = 0x8000_0000; + +pub const ROOT_ZONE_IRQS: [u32; 32] = [0; 32]; +pub const ROOT_ZONE_IOAPIC_BASE: usize = 0xfec0_0000; +pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig { + ioapic_base: ROOT_ZONE_IOAPIC_BASE, + ioapic_size: 0x1000, + kernel_entry_gpa: ROOT_ZONE_VMLINUX_ENTRY_ADDR, + cmdline_load_gpa: ROOT_ZONE_CMDLINE_ADDR, + setup_load_gpa: ROOT_ZONE_SETUP_ADDR, + initrd_load_gpa: 0, // 0x1500_0000, + initrd_size: 0, // 0x26_b000, + rsdp_memory_region_id: 0x1, + acpi_memory_region_id: 0x5, + // not longer than 32 bits + screen_base: ROOT_ZONE_SCREEN_BASE_ADDR, +}; + +pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [HvPciConfig { + ecam_base: 0xe0000000, + ecam_size: 0x400000, + io_base: 0x0, + io_size: 0x0, + pci_io_base: 0x0, + mem32_base: 0x0, + mem32_size: 0x0, + pci_mem32_base: 0x0, + mem64_base: 0x0, + mem64_size: 0x0, + pci_mem64_base: 0x0, +}]; + +pub const ROOT_PCI_MAX_BUS: usize = 3; +pub const ROOT_PCI_DEVS: [HvPciDevConfig; 21] = [ + pci_dev!(0x0, 0x0, 0x0), // host bridge + pci_dev!(0x0, 0x1, 0x0), // PCI bridge + pci_dev!(0x0, 0x1, 0x1), // PCI bridge + // pci_dev!(0x0, 0x2, 0x0), // display controller + pci_dev!(0x0, 0x8, 0x0), // system peripheral + pci_dev!(0x0, 0x12, 0x0), // signal processing controller + pci_dev!(0x0, 0x14, 0x0), // USB controller + pci_dev!(0x0, 0x14, 0x2), // RAM memory + pci_dev!(0x0, 0x14, 0x5), // SD host controller + pci_dev!(0x0, 0x15, 0x0), // serial bus controller + pci_dev!(0x0, 0x16, 0x0), // communication controller + pci_dev!(0x0, 0x16, 0x3), // serial controller + pci_dev!(0x0, 0x17, 0x0), // SATA controller + pci_dev!(0x0, 0x1d, 0x0), // PCI bridge + pci_dev!(0x0, 0x1f, 0x0), // ISA bridge + pci_dev!(0x0, 0x1f, 0x3), // audio device + pci_dev!(0x0, 0x1f, 0x4), // SMBus + pci_dev!(0x0, 0x1f, 0x5), // serial bus controller + pci_dev!(0x0, 0x1f, 0x6), // ethernet controller + pci_dev!(0x2, 0x0, 0x0), // VGA controller + pci_dev!(0x2, 0x0, 0x1), // audio device + pci_dev!(0x3, 0x0, 0x0), // ethernet controller +]; + +#[cfg(all(feature = "graphics"))] +pub const GRAPHICS_FONT: &[u8] = + include_bytes!("../../platform/x86_64/qemu/image/font/spleen-6x12.psf"); diff --git a/platform/x86_64/ecx-2300f-peg/cargo/config.template.toml b/platform/x86_64/ecx-2300f-peg/cargo/config.template.toml new file mode 100644 index 00000000..a454e986 --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/cargo/config.template.toml @@ -0,0 +1,10 @@ +[target.x86_64-unknown-none] +linker = "rust-lld" +rustflags = [ + "-Clink-arg=-Tplatform/__ARCH__/__BOARD__/linker.ld", + "-Clink-arg=-no-pie", + "-Clinker-flavor=ld.lld", + "-Cforce-frame-pointers=yes", + "-Ctarget-feature=-mmx,-sse,+soft-float", + "-Cno-redzone=yes", +] \ No newline at end of file diff --git a/platform/x86_64/ecx-2300f-peg/cargo/features b/platform/x86_64/ecx-2300f-peg/cargo/features new file mode 100644 index 00000000..ac3b7f71 --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/cargo/features @@ -0,0 +1,2 @@ +pci +uart16550a \ No newline at end of file diff --git a/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.S b/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.S new file mode 100644 index 00000000..9b979b63 --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.S @@ -0,0 +1,41 @@ +.section .text +.code16 +.global entry16 +entry16: + cli + cld + + mov ecx, eax + xor ax, ax + mov ds, ax + mov es, ax + mov ss, ax + + lgdt [prot_gdt_desc] + mov eax, cr0 + or eax, 0x1 + mov cr0, eax + + ljmp 0x8, entry32 + +.code32 +.global entry32 +entry32: + mov ax, 0x10 + mov ds, ax + mov es, ax + mov ss, ax + mov fs, ax + mov gs, ax + + jmp ecx + +.balign 16 +prot_gdt: + .quad 0x0000000000000000 # 0x00: null + .quad 0x00cf9b000000ffff # 0x08: code segment (base=0, limit=0xfffff, type=32bit code exec/read, DPL=0, 4k) + .quad 0x00cf93000000ffff # 0x10: data segment (base=0, limit=0xfffff, type=32bit data read/write, DPL=0, 4k) + +prot_gdt_desc: + .short prot_gdt_desc - prot_gdt - 1 # limit + .long prot_gdt # base diff --git a/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.ld b/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.ld new file mode 100644 index 00000000..3f96b209 --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.ld @@ -0,0 +1,15 @@ +OUTPUT_ARCH(i386) +BASE_ADDRESS = 0x8000; + +ENTRY(entry16) +SECTIONS +{ + . = BASE_ADDRESS; + .text : { + *(.text .text.*) + } + + /DISCARD/ : { + *(.eh_frame) *(.eh_frame_hdr) + } +} diff --git a/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.mk b/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.mk new file mode 100644 index 00000000..e23e4540 --- /dev/null +++ b/platform/x86_64/ecx-2300f-peg/image/bootloader/boot.mk @@ -0,0 +1,36 @@ +boot_dir := $(image_dir)/bootloader +boot_out_dir := $(image_dir)/bootloader/out + +boot_src := $(boot_dir)/boot.S +boot_lds := $(boot_dir)/boot.ld + +boot_o := $(boot_out_dir)/boot.o +boot_elf := $(boot_out_dir)/boot.elf +boot_bin := $(boot_out_dir)/boot.bin +boot_disa := $(boot_out_dir)/boot.asm + +AS ?= as +LD ?= ld +OBJCOPY ?= objcopy +OBJDUMP ?= objdump + +boot: mkout $(boot_bin) + +disasm: + $(OBJDUMP) -d -m i8086 -M intel $(boot_elf) | less + +mkout: + rm -rf $(boot_out_dir) + mkdir -p $(boot_out_dir) + +$(boot_o): $(boot_src) + $(AS) --32 -msyntax=intel -mnaked-reg $< -o $@ + +$(boot_elf): $(boot_o) $(boot_lds) + $(LD) -T$(boot_lds) $< -o $@ + $(OBJDUMP) -d -m i8086 -M intel $@ > $(boot_disa) + +$(boot_bin): $(boot_elf) + $(OBJCOPY) $< --strip-all -O binary $@ + +.PHONY: all disasm \ No newline at end of file diff --git a/platform/x86_64/ecx-2300f-peg/image/font/solarize-12x29.psf b/platform/x86_64/ecx-2300f-peg/image/font/solarize-12x29.psf new file mode 100644 index 0000000000000000000000000000000000000000..071330e9e585e79ebcd2079e1daf51e0f8e572c7 GIT binary patch literal 29728 zcmcIt&yO6(b*|;CcPMGOGlXDeNUnB@q(EJJxCXh5C`}Vom?%~v`<9$kt5tTBfRKhU zAT1GvQ$T6a1 zHA?DXr>nc`t5-i>y?XVdYya#Ye)q2goa7&NXN34oT%O0@Cg0b(4bc-9bV5ocbV2vT z#!|?Ce6lL7i~m3Rbxqt$iLbb=LpGHHpRS(TUsork#nZZcp3YXK*W{{HpWHDOsXnCtW&^EpsBh3UIuvtCZ_rTl^Lp3Q z+ccnoV0r|yzJYi}PR%~mxd@TrL(4=CPIl*jXzuyu_w1x zS2rQw6pB(MOh-@6mYAA7F%i&4ruR6E?1RI1L_h88^U!tQNS{j2r&rRuMx>yiTSC&) zvM(jwfzs@l5HJzHBhHE>J*!_6*P}S*v7QxuXz5g(&Qe_ah_8)X7hB?+;syO`>bJM` zHc*6F6GDTfM9XH@8uzVSk=Lu~3;LT#M~JIZlXOoH^?8y;&7J?GnQgJ1}_hw+q27 z$tP}Qt~I-Bbxa98G!M-{4bV?ZT^*+GX(wUYP{Y}9wn>}l=P&3fO=&mNDs?D+&h39p zhvrZnidW$8(uO)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U4 zv*>fNR$aFQ+X76OMWbuzZ|9WWNZof;P4i(qmtQ34TLo%#4!K9rmKm*?Mo<>um*$X) zG^Lf1EmQkQyq;-#r{}lSrItLM4Be;qvQ)oEKQ--A>vX--^V=9_w?htv;u4+f`IPn> zb-auB=X7Y^R&UD>(zVM+b}YHD!rHe_ zj)BqbTedqV;*bvLfqsXSVkOJeXh_Yo{+V#6*dD3_^#J40BNd22@~MP=%kurL?4eYk z$MsR{Z$i$pJaM{?#6#_R-FAKU1o1Q76t{FPLG@ORlYrI7pDu=F>y1aRWr_2jj7^`a z=)))b4btagDcM6$K59U^p2(JJZqsBl5wu3lCv&ft&xkl{%UzX$gIXcWvlVYFKWux&4jK#x^giL1!j1uzR&(&gWz?1 literal 0 HcmV?d00001 diff --git a/platform/x86_64/ecx-2300f-peg/image/font/spleen-6x12.psf b/platform/x86_64/ecx-2300f-peg/image/font/spleen-6x12.psf new file mode 100644 index 0000000000000000000000000000000000000000..892d085c647255d9d284c87fe956027e85f3970b GIT binary patch literal 7859 zcmeHJheH#|_m5`-+XWF7Yg82FP!Ku69>vp$1;h$A5F08Qv4M(2MF=36WOwOcKuQFp z2uP7;77^6TCD^dTob9Z5ipCRtzu8RyzyHJU!R~(M&6_vxedf(fdBN9v zIGkSi!#v%XHisjy7T|vjcv#xr9A~DhU7WRAAy41p3EQx5AeoX<5a`Qv_y!ha6=dnK zP;be6tOZ;HfwfM-%*Lt5*i2x}GLF&D!p_8F*NWrp?A+1iti??& zqu}|<Zm1kPOESOFhHoQuHPofPk5F!sZI7#Yapv%(w5;ka`RSmC;}T>|UY z_8@pXZO0hg%dCn{wED09!^2+#11=XE@I@lr5Q?J}wYuDO>!{-p>kSNqA`v?rV`~Eg zmLHBtB#}t8TrM8U(cUDv$Mi7`91r%-j>lMBTwKi741?S1jnga^<9{(58!jJ4e3`L~@+Unm zH=SNrVk{+0xfNp@)*gSE5@u>xUp~4@*Od~liqVV3l17Q%hMh_8Q{13cw2c+l)+!Xy z(K{7H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(`NP^GC;Koba>AkYMZMhuz|(1d~}3^b=enFpG1 i&_sadG-z Date: Sun, 14 Dec 2025 19:08:32 +0800 Subject: [PATCH 2/9] support UEFI for zone0 linux --- Cargo.lock | 145 +++++++++++++++++++----------- Cargo.toml | 2 + platform/x86_64/nuc14mnk/board.rs | 26 ++++-- platform/x86_64/qemu/board.rs | 26 ++++-- src/arch/x86_64/boot.rs | 140 +++++++++++++++++++++++++++-- src/arch/x86_64/cpu.rs | 1 - src/arch/x86_64/zone.rs | 1 + 7 files changed, 267 insertions(+), 74 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4b904038..43a258fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,26 +17,20 @@ version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94476c7ef97af4c4d998b3f422c1b01d5211aad57c80ed200baf148d1f1efab6" dependencies = [ - "bit_field 0.10.2", - "bitflags 2.9.1", + "bit_field 0.10.3", + "bitflags 2.10.0", "log", ] [[package]] name = "aho-corasick" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" dependencies = [ "memchr", ] -[[package]] -name = "autocfg" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" - [[package]] name = "bare-metal" version = "0.2.5" @@ -60,9 +54,9 @@ checksum = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56" [[package]] name = "bit_field" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" +checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6" [[package]] name = "bitflags" @@ -72,9 +66,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.9.1" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "bitmap-allocator" @@ -113,9 +107,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "cortex-a" @@ -169,8 +163,8 @@ version = "0.1.0" dependencies = [ "aarch64-cpu", "acpi", - "bit_field 0.10.2", - "bitflags 2.9.1", + "bit_field 0.10.3", + "bitflags 2.10.0", "bitmap-allocator", "bitvec", "buddy_system_allocator", @@ -193,6 +187,8 @@ dependencies = [ "sbi-spec 0.0.8", "spin 0.10.0", "tock-registers", + "uefi-raw", + "uguid", "x2apic", "x86", "x86_64", @@ -209,19 +205,18 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.12" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" dependencies = [ - "autocfg", "scopeguard", ] [[package]] name = "log" -version = "0.4.27" +version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" [[package]] name = "loongArch64" @@ -229,15 +224,15 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c9f0d275c70310e2a9d2fc23250c5ac826a73fa828a5f256401f85c5c554283" dependencies = [ - "bit_field 0.10.2", - "bitflags 2.9.1", + "bit_field 0.10.3", + "bitflags 2.10.0", ] [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" [[package]] name = "numeric-enum-macro" @@ -253,9 +248,9 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "proc-macro2" -version = "1.0.94" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" dependencies = [ "unicode-ident", ] @@ -266,6 +261,26 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b6fb7be1022539b1ea394ff4bcbad807a55c93841bb12c733f0be1048ea3e53" +[[package]] +name = "ptr_meta" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcada80daa06c42ed5f48c9a043865edea5dc44cbf9ac009fda3b89526e28607" +dependencies = [ + "ptr_meta_derive", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bca9224df2e20e7c5548aeb5f110a0f3b77ef05f8585139b7148b59056168ed2" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "qemu-exit" version = "3.0.2" @@ -274,9 +289,9 @@ checksum = "8bb0fd6580eeed0103c054e3fba2c2618ff476943762f28a645b63b8692b21c9" [[package]] name = "quote" -version = "1.0.40" +version = "1.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" dependencies = [ "proc-macro2", ] @@ -298,9 +313,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.1" +version = "1.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" dependencies = [ "aho-corasick", "memchr", @@ -310,9 +325,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.9" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" dependencies = [ "aho-corasick", "memchr", @@ -321,9 +336,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.5" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" [[package]] name = "riscv" @@ -331,7 +346,7 @@ version = "0.6.0" source = "git+https://github.com/rcore-os/riscv#11d43cf7cccb3b62a3caaf3e07a1db7449588f9a" dependencies = [ "bare-metal", - "bit_field 0.10.2", + "bit_field 0.10.3", "bitflags 1.3.2", "log", "riscv-target", @@ -352,9 +367,9 @@ dependencies = [ [[package]] name = "riscv-decode" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf8b4cfb0da0528321d22daee4299a23a8c5ac8848623d716e898d2a9eec0694" +checksum = "68b59d645e392e041ad18f5e529ed13242d8405c66bb192f59703ea2137017d0" [[package]] name = "riscv-macros" @@ -364,7 +379,7 @@ checksum = "e8c4aa1ea1af6dcc83a61be12e8189f9b293c3ba5a487778a4cd89fb060fdbbc" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.111", ] [[package]] @@ -405,9 +420,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.20" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "sbi-rt" @@ -474,15 +489,26 @@ dependencies = [ [[package]] name = "stable_deref_trait" -version = "1.2.0" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "syn" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] [[package]] name = "syn" -version = "2.0.100" +version = "2.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" dependencies = [ "proc-macro2", "quote", @@ -501,11 +527,28 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "696941a0aee7e276a165a978b37918fd5d22c55c3d6bda197813070ca9c0f21c" +[[package]] +name = "uefi-raw" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6d465de2c918779dafb769a5a4fe8d6e4fb7cc4cc6cb1a735f2f6ec68beea4" +dependencies = [ + "bitflags 2.10.0", + "ptr_meta", + "uguid", +] + +[[package]] +name = "uguid" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab14ea9660d240e7865ce9d54ecdbd1cd9fa5802ae6f4512f093c7907e921533" + [[package]] name = "unicode-ident" -version = "1.0.18" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "volatile" @@ -541,7 +584,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2781db97787217ad2a2845c396a5efe286f87467a5810836db6d74926e94a385" dependencies = [ - "bit_field 0.10.2", + "bit_field 0.10.3", "bitflags 1.3.2", "raw-cpuid", ] @@ -552,7 +595,7 @@ version = "0.14.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "100555a863c0092238c2e0e814c1096c1e5cf066a309c696a87e907b5f8c5d69" dependencies = [ - "bit_field 0.10.2", + "bit_field 0.10.3", "bitflags 1.3.2", "rustversion", "volatile", diff --git a/Cargo.toml b/Cargo.toml index 20fc9ef3..83fe42e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,8 @@ x86_64 = "=0.14.10" x2apic = "=0.4.3" raw-cpuid = "=10.7.0" acpi = "=5.2.0" +uguid = "=2.2.0" +uefi-raw = "=0.9.0" [features] ############# general ############## diff --git a/platform/x86_64/nuc14mnk/board.rs b/platform/x86_64/nuc14mnk/board.rs index 8cf71387..8a30d21c 100644 --- a/platform/x86_64/nuc14mnk/board.rs +++ b/platform/x86_64/nuc14mnk/board.rs @@ -32,6 +32,7 @@ const ROOT_ZONE_RSDP_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { virtual_start: 0xe_0000, size: 0x2_0000, }; +const ROOT_ZONE_RSDP_REGION_ID: usize = 0x1; const ROOT_ZONE_ACPI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, @@ -39,14 +40,23 @@ const ROOT_ZONE_ACPI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { virtual_start: 0x3530_0000, // gpa size: 0x10_0000, // modify size accordingly }; +const ROOT_ZONE_ACPI_REGION_ID: usize = 0x6; + +const ROOT_ZONE_UEFI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x1a00_0000, + virtual_start: 0x1500_0000, + size: 0x1_0000, +}; +const ROOT_ZONE_UEFI_REGION_ID: usize = 0x3; pub const ROOT_ZONE_NAME: &str = "root-linux"; -pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=tty0 nointremap no_timer_check pci=pcie_scan_all root=/dev/sda2 rw init=/init rootwait\0"; +pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=tty0 nointremap no_timer_check efi=noruntime pci=pcie_scan_all root=/dev/sda2 rw init=/init rootwait\0"; // pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=ttyS0 earlyprintk=serial nointremap no_timer_check pci=pcie_scan_all root=/dev/vda rw init=/init\0"; //"console=ttyS0 earlyprintk=serial rdinit=/init nokaslr nointremap\0"; // noapic // video=vesafb -pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 14] = [ +pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 15] = [ HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, physical_start: 0x500_0000, @@ -60,11 +70,12 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 14] = [ virtual_start: 0x10_0000, size: 0x14f0_0000, }, // ram + ROOT_ZONE_UEFI_REGION, // uefi HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, - physical_start: 0x1a00_0000, - virtual_start: 0x1500_0000, - size: 0x30_0000, + physical_start: 0x1a01_0000, + virtual_start: 0x1501_0000, + size: 0x2f_0000, }, // ram HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, @@ -140,8 +151,9 @@ pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig { setup_load_gpa: ROOT_ZONE_SETUP_ADDR, initrd_load_gpa: 0, // 0x1500_0000, initrd_size: 0, // 0x26_b000, - rsdp_memory_region_id: 0x1, - acpi_memory_region_id: 0x5, + rsdp_memory_region_id: ROOT_ZONE_RSDP_REGION_ID, + acpi_memory_region_id: ROOT_ZONE_ACPI_REGION_ID, + uefi_memory_region_id: ROOT_ZONE_UEFI_REGION_ID, // not longer than 32 bits screen_base: ROOT_ZONE_SCREEN_BASE_ADDR, }; diff --git a/platform/x86_64/qemu/board.rs b/platform/x86_64/qemu/board.rs index 08e48eca..74d9739a 100644 --- a/platform/x86_64/qemu/board.rs +++ b/platform/x86_64/qemu/board.rs @@ -32,6 +32,7 @@ const ROOT_ZONE_RSDP_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { virtual_start: 0xe_0000, size: 0x2_0000, }; +const ROOT_ZONE_RSDP_REGION_ID: usize = 0x1; const ROOT_ZONE_ACPI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, @@ -39,14 +40,23 @@ const ROOT_ZONE_ACPI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { virtual_start: 0x3530_0000, // gpa size: 0xf000, // modify size accordingly }; +const ROOT_ZONE_ACPI_REGION_ID: usize = 0x6; + +const ROOT_ZONE_UEFI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x1a00_0000, + virtual_start: 0x1500_0000, + size: 0x1_0000, +}; +const ROOT_ZONE_UEFI_REGION_ID: usize = 0x3; pub const ROOT_ZONE_NAME: &str = "root-linux"; pub const ROOT_ZONE_CMDLINE: &str = - "console=ttyS0 earlyprintk=serial nointremap no_timer_check pci=pcie_scan_all,lastbus=1 root=/dev/vda rw init=/init\0"; + "console=ttyS0 earlyprintk=serial nointremap no_timer_check efi=noruntime pci=pcie_scan_all,lastbus=1 root=/dev/vda rw init=/init\0"; //"console=ttyS0 earlyprintk=serial rdinit=/init nokaslr nointremap\0"; // noapic // video=vesafb -pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 8] = [ +pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 9] = [ HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, physical_start: 0x500_0000, @@ -60,11 +70,12 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 8] = [ virtual_start: 0x10_0000, size: 0x14f0_0000, }, // ram + ROOT_ZONE_UEFI_REGION, // uefi HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, - physical_start: 0x1a00_0000, - virtual_start: 0x1500_0000, - size: 0x30_0000, + physical_start: 0x1a01_0000, + virtual_start: 0x1501_0000, + size: 0x2f_0000, }, // ram HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, @@ -104,8 +115,9 @@ pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig { setup_load_gpa: ROOT_ZONE_SETUP_ADDR, initrd_load_gpa: 0, // 0x1500_0000, initrd_size: 0, //0x26_b000, - rsdp_memory_region_id: 0x1, - acpi_memory_region_id: 0x5, + rsdp_memory_region_id: ROOT_ZONE_RSDP_REGION_ID, + acpi_memory_region_id: ROOT_ZONE_ACPI_REGION_ID, + uefi_memory_region_id: ROOT_ZONE_UEFI_REGION_ID, // not longer than 32 bits screen_base: ROOT_ZONE_SCREEN_BASE_ADDR, }; diff --git a/src/arch/x86_64/boot.rs b/src/arch/x86_64/boot.rs index 14d92a08..35bbc397 100644 --- a/src/arch/x86_64/boot.rs +++ b/src/arch/x86_64/boot.rs @@ -16,13 +16,15 @@ use crate::{ arch::{zone::HvArchZoneConfig, Stage2PageTable}, - config::{root_zone_config, HvPciConfig, HvZoneConfig, MEM_TYPE_RAM}, + config::{root_zone_config, HvConfigMemoryRegion, HvPciConfig, HvZoneConfig, MEM_TYPE_RAM}, + consts::PAGE_SIZE, error::HvResult, memory::{GuestPhysAddr, HostPhysAddr, MemFlags, MemoryRegion, MemorySet}, percpu::this_zone, platform::MEM_TYPE_RESERVED, }; use alloc::string::{String, ToString}; +use bit_field::BitField; use core::{ arch::{self, global_asm}, ffi::{c_char, CStr}, @@ -31,6 +33,15 @@ use core::{ }; use multiboot_tag::{Modules, MultibootTags}; use spin::{Mutex, Once}; +use uefi_raw::table::{ + boot::{MemoryAttribute, MemoryDescriptor, MemoryType}, + configuration::ConfigurationTable, + system::SystemTable, + Header, Revision, +}; +use uguid::{guid, Guid}; + +const ACPI_20_TABLE_GUID: Guid = guid!("8868E871-E4F1-11D3-BC22-0080C73C8881"); mod multiboot_tag { pub const END: u32 = 0; @@ -92,6 +103,8 @@ static MULTIBOOT_TAGS: Once = Once::new(); const E820_MAX_ENTRIES_ZEROPAGE: usize = 128; +const EFI64_LOADER_SIGNATURE: u32 = 0x34364c45; // EL64 + bitflags::bitflags! { #[derive(Clone, Copy, Debug)] /// https://www.kernel.org/doc/html/latest/arch/x86/boot.html @@ -123,7 +136,9 @@ pub enum E820Type { /// The so-called "zeropage" pub struct BootParams { screen_info: ScreenInfo, - pad0: [u8; 0x1a8], + pad9: [u8; 0x180], + efi_info: EfiInfo, + pad0: [u8; 0x8], e820_entries: u8, pad1: [u8; 0x8], setup_sects: u8, @@ -213,26 +228,27 @@ impl BootParams { boot_params.set_screen_info(config, gpm); } + // set efi_info + boot_params.set_uefi_info(config); + Ok(()) } fn set_e820_entries(&mut self, config: &HvZoneConfig) { let mut index = 0; for i in 0..config.memory_regions().len() { - let mem_region = config.memory_regions()[i]; + let mem_region = &config.memory_regions()[i]; let mut e820_type = E820Type::E820_DEFAULT; if i == config.arch_config.rsdp_memory_region_id || i == config.arch_config.acpi_memory_region_id { e820_type = E820Type::E820_ACPI; + } else if i == config.arch_config.uefi_memory_region_id { + e820_type = E820Type::E820_RESERVED; } else if mem_region.mem_type == MEM_TYPE_RAM { e820_type = E820Type::E820_RAM; - } /* - else if config.arch_config.initrd_load_gpa != 0 - && i == config.arch_config.initrd_memory_region_id - { - } */ + } if e820_type != E820Type::E820_DEFAULT { self.e820_table[index] = BootE820Entry { @@ -254,12 +270,120 @@ impl BootParams { self.e820_entries = index as _; } + fn set_efi_mem_map(&mut self, config: &HvZoneConfig, paddr: usize) -> usize { + let mut cnt = 0; + let mem_map_cnt = config.memory_regions().len(); + let mut mem_map = unsafe { paddr as *mut MemoryDescriptor }; + for i in 0..mem_map_cnt { + let mem_region = &config.memory_regions()[i]; + let mem_desc = unsafe { &mut *mem_map }; + + let mut mem_desc_type = MemoryType::RESERVED; + + if i == config.arch_config.rsdp_memory_region_id + || i == config.arch_config.acpi_memory_region_id + { + mem_desc_type = MemoryType::ACPI_RECLAIM; + } else if i == config.arch_config.uefi_memory_region_id { + mem_desc_type = MemoryType::RUNTIME_SERVICES_DATA; + } else if mem_region.mem_type == MEM_TYPE_RAM { + mem_desc_type = MemoryType::CONVENTIONAL; + } + + if mem_desc_type != MemoryType::RESERVED { + *mem_desc = MemoryDescriptor { + ty: mem_desc_type, + phys_start: mem_region.virtual_start, + virt_start: mem_region.virtual_start, + page_count: mem_region.size / (PAGE_SIZE as u64), + att: MemoryAttribute::WRITE_BACK, + }; + cnt += 1; + mem_map = mem_map.wrapping_add(1); + } + } + + let mem_desc = unsafe { &mut *mem_map }; + *mem_desc = MemoryDescriptor { + ty: MemoryType::MMIO, + phys_start: config.pci_config[0].ecam_base, + virt_start: config.pci_config[0].ecam_base, + page_count: config.pci_config[0].ecam_size / (PAGE_SIZE as u64), + att: MemoryAttribute::UNCACHEABLE, + }; + cnt += 1; + + cnt + } + fn set_initrd(&mut self, ramdisk_image: u32, ramdisk_size: u32) { self.ramdisk_image = ramdisk_image; self.ramdisk_size = ramdisk_size; info!("initrd size: {}", self.ramdisk_size); } + fn set_uefi_info(&mut self, config: &HvZoneConfig) { + self.efi_info.loader_signature = EFI64_LOADER_SIGNATURE; + + let uefi_region = &config.memory_regions()[config.arch_config.uefi_memory_region_id]; + let mut vaddr = uefi_region.virtual_start as usize; + let mut paddr = uefi_region.physical_start as usize; + + // set system table + self.efi_info.systab = vaddr.get_bits(0..32) as _; + self.efi_info.systab_hi = vaddr.get_bits(32..64) as _; + let system_table = unsafe { &mut *(paddr as usize as *mut SystemTable) }; + + let system_table_header = Header { + signature: SystemTable::SIGNATURE, + revision: Revision::EFI_2_90, + size: size_of::() as u32, + crc: 0, + reserved: 0, + }; + + // start of the efi memmap + vaddr += size_of::(); + paddr += size_of::(); + + let mem_desc_cnt = self.set_efi_mem_map(config, paddr); + let mem_map_tot_size = size_of::() * mem_desc_cnt; + self.efi_info.memmap = vaddr.get_bits(0..32) as _; + self.efi_info.memmap_hi = vaddr.get_bits(32..64) as _; + self.efi_info.memdesc_size = size_of::() as _; + self.efi_info.memmap_size = mem_map_tot_size as _; + self.efi_info.memdesc_version = MemoryDescriptor::VERSION; + + // start of the config table + vaddr += size_of::() * mem_desc_cnt; + paddr += size_of::() * mem_desc_cnt; + + const CONFIG_TABLE_ENTRIES: usize = 1; + let config_table = + unsafe { &mut *(paddr as *mut [ConfigurationTable; CONFIG_TABLE_ENTRIES]) }; + + // ACPI_20_TABLE_GUID + let rsdp_region = &config.memory_regions()[config.arch_config.rsdp_memory_region_id]; + config_table[0].vendor_guid = ACPI_20_TABLE_GUID; + config_table[0].vendor_table = unsafe { rsdp_region.virtual_start as _ }; + + *system_table = SystemTable { + header: system_table_header, + firmware_vendor: core::ptr::null_mut(), + firmware_revision: 0, + stdin_handle: core::ptr::null_mut(), + stdin: core::ptr::null_mut(), + stdout_handle: core::ptr::null_mut(), + stdout: core::ptr::null_mut(), + stderr_handle: core::ptr::null_mut(), + stderr: core::ptr::null_mut(), + runtime_services: core::ptr::null_mut(), + boot_services: core::ptr::null_mut(), + number_of_configuration_table_entries: CONFIG_TABLE_ENTRIES, + configuration_table: unsafe { vaddr as *mut ConfigurationTable }, + }; + } + fn set_screen_info(&mut self, config: &HvZoneConfig, gpm: &mut MemorySet) { let fb_info = &get_multiboot_tags().framebuffer; diff --git a/src/arch/x86_64/cpu.rs b/src/arch/x86_64/cpu.rs index 25f3653d..4610cc5f 100644 --- a/src/arch/x86_64/cpu.rs +++ b/src/arch/x86_64/cpu.rs @@ -254,7 +254,6 @@ impl ArchCpu { unsafe { PARKING_MEMORY_SET.get().unwrap().activate(); - info!("before vmx launch"); self.vmx_launch(); } } diff --git a/src/arch/x86_64/zone.rs b/src/arch/x86_64/zone.rs index f69f4eac..8c808718 100644 --- a/src/arch/x86_64/zone.rs +++ b/src/arch/x86_64/zone.rs @@ -54,6 +54,7 @@ pub struct HvArchZoneConfig { /// no restriction on start gpa and size, but its type should be MEM_TYPE_RAM as well. /// Usually, the DSDT table is large, so the size of this region should be large enough. pub acpi_memory_region_id: usize, + pub uefi_memory_region_id: usize, /// If you want to use a graphical console, set screen_base to a preferred gpa /// as the start of the framebuffer. Otherwise, leave it as zero. /// No need to add a memory region for the framebuffer, From 88b2272cf458c79648d8b3032a79a03f3430a705 Mon Sep 17 00:00:00 2001 From: Solicey Date: Wed, 14 Jan 2026 23:40:47 +0800 Subject: [PATCH 3/9] add ecx-2300f-peg --- Cargo.toml | 2 +- platform/x86_64/ecx-2300f-peg/board.rs | 42 +++++++++++++------- platform/x86_64/ecx-2300f-peg/cargo/features | 2 +- platform/x86_64/nuc14mnk/board.rs | 10 ++++- platform/x86_64/nuc14mnk/cargo/features | 4 +- platform/x86_64/qemu/board.rs | 9 ++++- src/arch/x86_64/boot.rs | 6 +++ src/arch/x86_64/graphics.rs | 13 ++++++ src/arch/x86_64/pio.rs | 8 ++-- 9 files changed, 71 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 83fe42e6..949a646c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,7 +94,7 @@ loongson_3a6000 = [] ############# x86_64 ############### graphics = [] - +split_screen = [] [profile.dev] # panic = "abort" # avoid cargo test failure, this is a bug of cargo diff --git a/platform/x86_64/ecx-2300f-peg/board.rs b/platform/x86_64/ecx-2300f-peg/board.rs index 262e6eeb..59e338f7 100644 --- a/platform/x86_64/ecx-2300f-peg/board.rs +++ b/platform/x86_64/ecx-2300f-peg/board.rs @@ -33,6 +33,7 @@ const ROOT_ZONE_RSDP_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { virtual_start: 0xe_0000, size: 0x2_0000, }; +const ROOT_ZONE_RSDP_REGION_ID: usize = 0x1; const ROOT_ZONE_ACPI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, @@ -40,14 +41,23 @@ const ROOT_ZONE_ACPI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { virtual_start: 0x3530_0000, // gpa size: 0x10_0000, // modify size accordingly }; +const ROOT_ZONE_ACPI_REGION_ID: usize = 0x6; + +const ROOT_ZONE_UEFI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { + mem_type: MEM_TYPE_RAM, + physical_start: 0x1a00_0000, + virtual_start: 0x1500_0000, + size: 0x1_0000, +}; +const ROOT_ZONE_UEFI_REGION_ID: usize = 0x3; pub const ROOT_ZONE_NAME: &str = "root-linux"; -pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=tty0 nointremap no_timer_check pci=pcie_scan_all root=/dev/sdb2 rw init=/init rootwait\0"; +pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=tty0 nointremap no_timer_check pci=pcie_scan_all efi=noruntime root=/dev/sda2 rw init=/init rootwait\0"; // pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=ttyS0 earlyprintk=serial nointremap no_timer_check pci=pcie_scan_all root=/dev/vda rw init=/init\0"; //"console=ttyS0 earlyprintk=serial rdinit=/init nokaslr nointremap\0"; // noapic // video=vesafb -pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 10] = [ +pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 11] = [ HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, physical_start: 0x500_0000, @@ -61,12 +71,13 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 10] = [ virtual_start: 0x10_0000, size: 0x14f0_0000, }, // ram + ROOT_ZONE_UEFI_REGION, // uefi HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, - physical_start: 0x1a00_0000, - virtual_start: 0x1500_0000, - size: 0x30_0000, - }, // ram + physical_start: 0x1a01_0000, + virtual_start: 0x1501_0000, + size: 0x2f_0000, + }, HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, physical_start: 0x1a30_0000, @@ -85,7 +96,7 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 10] = [ mem_type: MEM_TYPE_RESERVED, physical_start: 0x1_0000_0000, virtual_start: 0x1_0000_0000, - size: 0x2000_0000, + size: 0x7_0000_0000, }, // zone 1 HvConfigMemoryRegion { mem_type: MEM_TYPE_RESERVED, @@ -116,8 +127,9 @@ pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig { setup_load_gpa: ROOT_ZONE_SETUP_ADDR, initrd_load_gpa: 0, // 0x1500_0000, initrd_size: 0, // 0x26_b000, - rsdp_memory_region_id: 0x1, - acpi_memory_region_id: 0x5, + rsdp_memory_region_id: ROOT_ZONE_RSDP_REGION_ID, + acpi_memory_region_id: ROOT_ZONE_ACPI_REGION_ID, + uefi_memory_region_id: ROOT_ZONE_UEFI_REGION_ID, // not longer than 32 bits screen_base: ROOT_ZONE_SCREEN_BASE_ADDR, }; @@ -137,7 +149,7 @@ pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [HvPciConfig { }]; pub const ROOT_PCI_MAX_BUS: usize = 3; -pub const ROOT_PCI_DEVS: [HvPciDevConfig; 21] = [ +pub const ROOT_PCI_DEVS: [HvPciDevConfig; 19] = [ pci_dev!(0x0, 0x0, 0x0), // host bridge pci_dev!(0x0, 0x1, 0x0), // PCI bridge pci_dev!(0x0, 0x1, 0x1), // PCI bridge @@ -152,14 +164,14 @@ pub const ROOT_PCI_DEVS: [HvPciDevConfig; 21] = [ pci_dev!(0x0, 0x16, 0x3), // serial controller pci_dev!(0x0, 0x17, 0x0), // SATA controller pci_dev!(0x0, 0x1d, 0x0), // PCI bridge - pci_dev!(0x0, 0x1f, 0x0), // ISA bridge + // pci_dev!(0x0, 0x1f, 0x0), // ISA bridge pci_dev!(0x0, 0x1f, 0x3), // audio device pci_dev!(0x0, 0x1f, 0x4), // SMBus pci_dev!(0x0, 0x1f, 0x5), // serial bus controller - pci_dev!(0x0, 0x1f, 0x6), // ethernet controller - pci_dev!(0x2, 0x0, 0x0), // VGA controller - pci_dev!(0x2, 0x0, 0x1), // audio device - pci_dev!(0x3, 0x0, 0x0), // ethernet controller + // pci_dev!(0x0, 0x1f, 0x6), // ethernet controller + pci_dev!(0x2, 0x0, 0x0), // VGA controller + pci_dev!(0x2, 0x0, 0x1), // audio device + pci_dev!(0x3, 0x0, 0x0), // ethernet controller ]; #[cfg(all(feature = "graphics"))] diff --git a/platform/x86_64/ecx-2300f-peg/cargo/features b/platform/x86_64/ecx-2300f-peg/cargo/features index ac3b7f71..e4ad1c13 100644 --- a/platform/x86_64/ecx-2300f-peg/cargo/features +++ b/platform/x86_64/ecx-2300f-peg/cargo/features @@ -1,2 +1,2 @@ pci -uart16550a \ No newline at end of file +uart16550a diff --git a/platform/x86_64/nuc14mnk/board.rs b/platform/x86_64/nuc14mnk/board.rs index 8a30d21c..1f3f8319 100644 --- a/platform/x86_64/nuc14mnk/board.rs +++ b/platform/x86_64/nuc14mnk/board.rs @@ -51,7 +51,7 @@ const ROOT_ZONE_UEFI_REGION: HvConfigMemoryRegion = HvConfigMemoryRegion { const ROOT_ZONE_UEFI_REGION_ID: usize = 0x3; pub const ROOT_ZONE_NAME: &str = "root-linux"; -pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=tty0 nointremap no_timer_check efi=noruntime pci=pcie_scan_all root=/dev/sda2 rw init=/init rootwait\0"; +pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=tty0 nointremap no_timer_check efi=noruntime pci=pcie_scan_all root=/dev/nvme0n1p5 rw init=/init rootwait\0"; // pub const ROOT_ZONE_CMDLINE: &str = "video=vesafb console=ttyS0 earlyprintk=serial nointremap no_timer_check pci=pcie_scan_all root=/dev/vda rw init=/init\0"; //"console=ttyS0 earlyprintk=serial rdinit=/init nokaslr nointremap\0"; // noapic // video=vesafb @@ -95,7 +95,7 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 15] = [ mem_type: MEM_TYPE_RESERVED, physical_start: 0x1_0000_0000, virtual_start: 0x1_0000_0000, - size: 0x2000_0000, + size: 0x2_0000_0000, }, // zone 1 HvConfigMemoryRegion { mem_type: MEM_TYPE_RESERVED, @@ -173,6 +173,12 @@ pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [HvPciConfig { }]; pub const ROOT_PCI_MAX_BUS: usize = 2; +pub const ROOT_PCI_DEVS: [HvPciDevConfig; 17] = [ + pci_dev!(0x0, 0x0, 0x0), // host bridge + pci_dev!(0x0, 0x2, 0x0), // VGA controller + pci_dev!(0x0, 0x4, 0x0), + pci_dev!(0x0, 0x8, 0x0), + pci_dev!(0x0, 0xa, 0x0), pub const ROOT_PCI_DEVS: [HvPciDevConfig; 18] = [ pci_dev!(0x0, 0x0, 0x0, VpciDevType::Physical), // host bridge pci_dev!(0x0, 0x2, 0x0, VpciDevType::Physical), // VGA controller diff --git a/platform/x86_64/nuc14mnk/cargo/features b/platform/x86_64/nuc14mnk/cargo/features index f8ee525a..69fb95c9 100644 --- a/platform/x86_64/nuc14mnk/cargo/features +++ b/platform/x86_64/nuc14mnk/cargo/features @@ -1,4 +1,6 @@ pci ecam_pcie no_pcie_bar_realloc -uart16550a \ No newline at end of file +uart16550a +graphics +split_screen \ No newline at end of file diff --git a/platform/x86_64/qemu/board.rs b/platform/x86_64/qemu/board.rs index 74d9739a..81885502 100644 --- a/platform/x86_64/qemu/board.rs +++ b/platform/x86_64/qemu/board.rs @@ -55,8 +55,9 @@ pub const ROOT_ZONE_CMDLINE: &str = "console=ttyS0 earlyprintk=serial nointremap no_timer_check efi=noruntime pci=pcie_scan_all,lastbus=1 root=/dev/vda rw init=/init\0"; //"console=ttyS0 earlyprintk=serial rdinit=/init nokaslr nointremap\0"; // noapic // video=vesafb +// /lib/systemd/systemd -pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 9] = [ +pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 10] = [ HvConfigMemoryRegion { mem_type: MEM_TYPE_RAM, physical_start: 0x500_0000, @@ -97,6 +98,12 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 9] = [ virtual_start: 0x4030_0000, size: 0x2000_0000, }, // zone 1 + HvConfigMemoryRegion { + mem_type: MEM_TYPE_RESERVED, + physical_start: 0x1_0000_0000, + virtual_start: 0x1_0000_0000, + size: 0x7000_0000, + }, // zone 1 ]; const ROOT_ZONE_CMDLINE_ADDR: GuestPhysAddr = 0x9000; diff --git a/src/arch/x86_64/boot.rs b/src/arch/x86_64/boot.rs index 35bbc397..8e8c90b2 100644 --- a/src/arch/x86_64/boot.rs +++ b/src/arch/x86_64/boot.rs @@ -229,7 +229,9 @@ impl BootParams { } // set efi_info + // if (config.zone_id == 0) { boot_params.set_uefi_info(config); + // } Ok(()) } @@ -389,7 +391,11 @@ impl BootParams { let bytes_per_pixel = (fb_info.bpp as usize) / 8; let width = fb_info.width as usize; + + #[cfg(not(feature = "split_screen"))] let height = fb_info.height as usize; + #[cfg(all(feature = "split_screen"))] + let height = (fb_info.height / 2) as usize; self.screen_info.lfb_base = config.arch_config.screen_base as _; self.screen_info.lfb_width = width as _; diff --git a/src/arch/x86_64/graphics.rs b/src/arch/x86_64/graphics.rs index af5453d8..2097e401 100644 --- a/src/arch/x86_64/graphics.rs +++ b/src/arch/x86_64/graphics.rs @@ -85,15 +85,28 @@ pub fn font_init(psf: &'static [u8]) { }); let framebuffer = &get_multiboot_tags().framebuffer; + let mid_addr = framebuffer.addr + + (framebuffer.width as u64) + * ((framebuffer.height as u64) / 2) + * ((framebuffer.bpp as u64) / 8); FRAMEBUFFER_INFO.call_once(|| { Mutex::new(FramebufferInfo { cursor_x: 0, cursor_y: 0, max_char_nr_x: (framebuffer.width / font_width) as _, + #[cfg(not(feature = "split_screen"))] max_char_nr_y: (framebuffer.height / psf_header.height) as _, + #[cfg(all(feature = "split_screen"))] + max_char_nr_y: (framebuffer.height / 2 / psf_header.height) as _, + #[cfg(not(feature = "split_screen"))] addr: framebuffer.addr as _, + #[cfg(all(feature = "split_screen"))] + addr: mid_addr as _, width: framebuffer.width as _, + #[cfg(not(feature = "split_screen"))] height: framebuffer.height as _, + #[cfg(all(feature = "split_screen"))] + height: (framebuffer.height / 2) as _, }) }); diff --git a/src/arch/x86_64/pio.rs b/src/arch/x86_64/pio.rs index feee7537..f89a5564 100644 --- a/src/arch/x86_64/pio.rs +++ b/src/arch/x86_64/pio.rs @@ -88,10 +88,10 @@ impl PortIoBitmap { bitmap.set_range_intercept(PCI_CONFIG_ADDR_PORT, true); bitmap.set_range_intercept(PCI_CONFIG_DATA_PORT, true); - if zone_id == 0 { - #[cfg(feature = "graphics")] - bitmap.set_range_intercept(UART_COM1_PORT, true); - } + // if zone_id == 0 { + #[cfg(feature = "graphics")] + bitmap.set_range_intercept(UART_COM1_PORT, true); + // } // i8042, we won't use it, but intercept its ports might block linux init bitmap.set_range_intercept(0x60..0x65, false); From 3f8c1daf5f5d65c2346e32172c24fefeb0924c73 Mon Sep 17 00:00:00 2001 From: Solicey Date: Tue, 20 Jan 2026 23:07:45 +0800 Subject: [PATCH 4/9] Merge branch 'new_pcie' into dev-x86_64 --- platform/aarch64/rk3568/board.rs | 30 ++++--- platform/loongarch64/ls3a5000/board.rs | 76 +++++++++-------- platform/loongarch64/ls3a6000/board.rs | 81 +++++++++---------- platform/riscv64/hifive-premier-p550/board.rs | 8 +- platform/riscv64/qemu-aia/board.rs | 3 +- platform/x86_64/qemu/board.rs | 14 ++-- platform/x86_64/qemu/cargo/features | 3 +- src/pci/pci_access.rs | 2 +- 8 files changed, 106 insertions(+), 111 deletions(-) diff --git a/platform/aarch64/rk3568/board.rs b/platform/aarch64/rk3568/board.rs index 120370f3..32ed5d3c 100644 --- a/platform/aarch64/rk3568/board.rs +++ b/platform/aarch64/rk3568/board.rs @@ -14,6 +14,7 @@ // Authors: // +use crate::pci_dev; use crate::{ arch::{ mmu::MemoryType, @@ -22,7 +23,6 @@ use crate::{ config::*, pci::vpci_dev::VpciDevType, }; -use crate::pci_dev; pub const BOARD_NAME: &str = "rk3568"; @@ -50,8 +50,8 @@ pub const BOARD_PHYSMEM_LIST: &[(u64, u64, MemoryType)] = &[ ]; pub const ROOT_ZONE_DTB_ADDR: u64 = 0xa0000000; -pub const ROOT_ZONE_KERNEL_ADDR: u64 = 0x00280000 ; -pub const ROOT_ZONE_ENTRY: u64 = 0x00280000 ; +pub const ROOT_ZONE_KERNEL_ADDR: u64 = 0x00280000; +pub const ROOT_ZONE_ENTRY: u64 = 0x00280000; //pub const ROOT_ZONE_CPUS: u64 = (1 << 0) ; pub const ROOT_ZONE_CPUS: u64 = (1 << 0) | (1 << 1); @@ -339,20 +339,18 @@ pub const ROOT_PCI_CONFIG: &[HvPciConfig] = &[ pub const ROOT_ZONE_IVC_CONFIG: [HvIvcConfig; 0] = []; -pub const ROOT_DWC_ATU_CONFIG: &[HvDwcAtuConfig] = &[ - HvDwcAtuConfig { - ecam_base: 0x3c0400000, - dbi_base: 0x3c0400000, - dbi_size: 0x10000, - apb_base: 0xfe270000, - apb_size: 0x10000, - cfg_base: 0xf2000000, - cfg_size: 0x80000*2, - io_cfg_atu_shared: 0, - }, -]; +pub const ROOT_DWC_ATU_CONFIG: &[HvDwcAtuConfig] = &[HvDwcAtuConfig { + ecam_base: 0x3c0400000, + dbi_base: 0x3c0400000, + dbi_size: 0x10000, + apb_base: 0xfe270000, + apb_size: 0x10000, + cfg_base: 0xf2000000, + cfg_size: 0x80000 * 2, + io_cfg_atu_shared: 0, +}]; pub const ROOT_PCI_DEVS: [HvPciDevConfig; 2] = [ pci_dev!(0x0, 0x00, 0x0, 0x0, VpciDevType::Physical), pci_dev!(0x0, 0x01, 0x0, 0x0, VpciDevType::Physical), -]; \ No newline at end of file +]; diff --git a/platform/loongarch64/ls3a5000/board.rs b/platform/loongarch64/ls3a5000/board.rs index b373f9b7..541d73a8 100644 --- a/platform/loongarch64/ls3a5000/board.rs +++ b/platform/loongarch64/ls3a5000/board.rs @@ -14,8 +14,8 @@ // Authors: // Yulong Han // -use crate::{arch::zone::HvArchZoneConfig, config::*, pci::vpci_dev::VpciDevType}; use crate::pci_dev; +use crate::{arch::zone::HvArchZoneConfig, config::*, pci::vpci_dev::VpciDevType}; pub const BOARD_NAME: &str = "ls3a5000"; @@ -156,24 +156,22 @@ pub const ROOT_ZONE_IRQS_BITMAP: &[BitmapWord] = &get_irqs_bitmap(&[]); pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig { dummy: 0 }; pub const ROOT_ZONE_IVC_CONFIG: [HvIvcConfig; 0] = []; -pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [ - HvPciConfig { - ecam_base: 0xfe00000000, - ecam_size: 0x20000000, - io_base: 0x18408000, - io_size: 0x8000, - pci_io_base: 0x00008000, - mem32_base: 0x0, - mem32_size: 0x0, - pci_mem32_base: 0x0, - mem64_base: 0x60000000, - mem64_size: 0x30000000, - pci_mem64_base: 0x60000000, - bus_range_begin: 0, - bus_range_end: 0xff, - domain: 0x0, - } -]; +pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [HvPciConfig { + ecam_base: 0xfe00000000, + ecam_size: 0x20000000, + io_base: 0x18408000, + io_size: 0x8000, + pci_io_base: 0x00008000, + mem32_base: 0x0, + mem32_size: 0x0, + pci_mem32_base: 0x0, + mem64_base: 0x60000000, + mem64_size: 0x30000000, + pci_mem64_base: 0x60000000, + bus_range_begin: 0, + bus_range_end: 0xff, + domain: 0x0, +}]; /* 00:00.0, 00:00.1, 00:00.2, 00:00.3, 00:04.0, 00:04.1*/ /* 00:05.0, 00:05.1, 00:06.0, 00:06.1, 00:06.2 */ @@ -185,36 +183,34 @@ pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [ /* BUS 6 on X4 slot */ /* 06:00.0, 06:00.1, 06:00.2, 06:00.3 net */ pub const ROOT_PCI_DEVS: &[HvPciDevConfig] = &[ - pci_dev!(0x0, 0x0, 0x0, 0x0, VpciDevType::Physical), // 00:00.0 - pci_dev!(0x0, 0x0, 0x0, 0x1, VpciDevType::Physical), // 00:00.1 - pci_dev!(0x0, 0x0, 0x0, 0x2, VpciDevType::Physical), // 00:00.2 - pci_dev!(0x0, 0x0, 0x0, 0x3, VpciDevType::Physical), // 00:00.3 - pci_dev!(0x0, 0x0, 0x4, 0x0, VpciDevType::Physical), // 00:04.0 - pci_dev!(0x0, 0x0, 0x4, 0x1, VpciDevType::Physical), // 00:04.1 - pci_dev!(0x0, 0x0, 0x5, 0x0, VpciDevType::Physical), // 00:05.0 - pci_dev!(0x0, 0x0, 0x5, 0x1, VpciDevType::Physical), // 00:05.1 + pci_dev!(0x0, 0x0, 0x0, 0x0, VpciDevType::Physical), // 00:00.0 + pci_dev!(0x0, 0x0, 0x0, 0x1, VpciDevType::Physical), // 00:00.1 + pci_dev!(0x0, 0x0, 0x0, 0x2, VpciDevType::Physical), // 00:00.2 + pci_dev!(0x0, 0x0, 0x0, 0x3, VpciDevType::Physical), // 00:00.3 + pci_dev!(0x0, 0x0, 0x4, 0x0, VpciDevType::Physical), // 00:04.0 + pci_dev!(0x0, 0x0, 0x4, 0x1, VpciDevType::Physical), // 00:04.1 + pci_dev!(0x0, 0x0, 0x5, 0x0, VpciDevType::Physical), // 00:05.0 + pci_dev!(0x0, 0x0, 0x5, 0x1, VpciDevType::Physical), // 00:05.1 // pci_dev!(0x0, 0x0, 0x6, 0x0, VpciDevType::Physical), // 00:06.0 // pci_dev!(0x0, 0x0, 0x6, 0x1, VpciDevType::Physical), // 00:06.1 // pci_dev!(0x0, 0x0, 0x6, 0x2, VpciDevType::Physical), // 00:06.2 - pci_dev!(0x0, 0x0, 0x7, 0x0, VpciDevType::Physical), // 00:07.0 - pci_dev!(0x0, 0x0, 0x8, 0x0, VpciDevType::Physical), // 00:08.0 - pci_dev!(0x0, 0x0, 0x9, 0x0, VpciDevType::Physical), // 00:09.0 - pci_dev!(0x0, 0x0, 0xa, 0x0, VpciDevType::Physical), // 00:0a.0 - pci_dev!(0x0, 0x0, 0xb, 0x0, VpciDevType::Physical), // 00:0b.0 - pci_dev!(0x0, 0x0, 0xc, 0x0, VpciDevType::Physical), // 00:0c.0 - pci_dev!(0x0, 0x0, 0xd, 0x0, VpciDevType::Physical), // 00:0d.0 - pci_dev!(0x0, 0x0, 0xf, 0x0, VpciDevType::Physical), // 00:0f.0 + pci_dev!(0x0, 0x0, 0x7, 0x0, VpciDevType::Physical), // 00:07.0 + pci_dev!(0x0, 0x0, 0x8, 0x0, VpciDevType::Physical), // 00:08.0 + pci_dev!(0x0, 0x0, 0x9, 0x0, VpciDevType::Physical), // 00:09.0 + pci_dev!(0x0, 0x0, 0xa, 0x0, VpciDevType::Physical), // 00:0a.0 + pci_dev!(0x0, 0x0, 0xb, 0x0, VpciDevType::Physical), // 00:0b.0 + pci_dev!(0x0, 0x0, 0xc, 0x0, VpciDevType::Physical), // 00:0c.0 + pci_dev!(0x0, 0x0, 0xd, 0x0, VpciDevType::Physical), // 00:0d.0 + pci_dev!(0x0, 0x0, 0xf, 0x0, VpciDevType::Physical), // 00:0f.0 pci_dev!(0x0, 0x0, 0x10, 0x0, VpciDevType::Physical), // 00:10.0 pci_dev!(0x0, 0x0, 0x13, 0x0, VpciDevType::Physical), // 00:13.0 pci_dev!(0x0, 0x0, 0x16, 0x0, VpciDevType::Physical), // 00:16.0 pci_dev!(0x0, 0x0, 0x19, 0x0, VpciDevType::Physical), // 00:19.0 - pci_dev!(0x0, 0x2, 0x0, 0x0, VpciDevType::Physical), // 02:00.0 - pci_dev!(0x0, 0x5, 0x0, 0x0, VpciDevType::Physical), // 05:00.0 - pci_dev!(0x0, 0x6, 0x0, 0x0, VpciDevType::Physical), // 06:00.0 + pci_dev!(0x0, 0x2, 0x0, 0x0, VpciDevType::Physical), // 02:00.0 + pci_dev!(0x0, 0x5, 0x0, 0x0, VpciDevType::Physical), // 05:00.0 + pci_dev!(0x0, 0x6, 0x0, 0x0, VpciDevType::Physical), // 06:00.0 ]; - - // bus << 8 | dev << 5 | func << 3 // pub const ROOT_PCI_DEVS: [u64; 0] = []; diff --git a/platform/loongarch64/ls3a6000/board.rs b/platform/loongarch64/ls3a6000/board.rs index 8e99e9fa..6bd74afa 100644 --- a/platform/loongarch64/ls3a6000/board.rs +++ b/platform/loongarch64/ls3a6000/board.rs @@ -14,8 +14,8 @@ // Authors: // Yulong Han // -use crate::{arch::zone::HvArchZoneConfig, config::*, pci::vpci_dev::VpciDevType}; use crate::pci_dev; +use crate::{arch::zone::HvArchZoneConfig, config::*, pci::vpci_dev::VpciDevType}; pub const BOARD_NAME: &str = "ls3a5000"; @@ -156,24 +156,22 @@ pub const ROOT_ZONE_IRQS_BITMAP: &[BitmapWord] = &get_irqs_bitmap(&[]); pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig { dummy: 0 }; pub const ROOT_ZONE_IVC_CONFIG: [HvIvcConfig; 0] = []; -pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [ - HvPciConfig { - bus_range_begin: 0x0, - bus_range_end: 0x1f, - ecam_base: 0xfe00000000, - ecam_size: 0x20000000, - io_base: 0x18408000, - io_size: 0x8000, - pci_io_base: 0x00008000, - mem32_base: 0x0, - mem32_size: 0x0, - pci_mem32_base: 0x0, - mem64_base: 0x60000000, - mem64_size: 0x20000000, - pci_mem64_base: 0x60000000, - domain: 0x0, - } -]; +pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [HvPciConfig { + bus_range_begin: 0x0, + bus_range_end: 0x1f, + ecam_base: 0xfe00000000, + ecam_size: 0x20000000, + io_base: 0x18408000, + io_size: 0x8000, + pci_io_base: 0x00008000, + mem32_base: 0x0, + mem32_size: 0x0, + pci_mem32_base: 0x0, + mem64_base: 0x60000000, + mem64_size: 0x20000000, + pci_mem64_base: 0x60000000, + domain: 0x0, +}]; /* 00:00.0, 00:00.1, 00:00.2, 00:00.3, 00:04.0, 00:04.1*/ /* 00:05.0, 00:05.1, 00:06.0, 00:06.1, 00:06.2 */ @@ -185,35 +183,34 @@ pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [ /* BUS 6 on X4 slot */ /* 06:00.0, 06:00.1, 06:00.2, 06:00.3 net */ pub const ROOT_PCI_DEVS: [HvPciDevConfig; 26] = [ - pci_dev!(0x0, 0x0, 0x0, 0x0, VpciDevType::Physical), // 00:00.0 - pci_dev!(0x0, 0x0, 0x0, 0x1, VpciDevType::Physical), // 00:00.1 - pci_dev!(0x0, 0x0, 0x0, 0x2, VpciDevType::Physical), // 00:00.2 - pci_dev!(0x0, 0x0, 0x0, 0x3, VpciDevType::Physical), // 00:00.3 - pci_dev!(0x0, 0x0, 0x4, 0x0, VpciDevType::Physical), // 00:04.0 - pci_dev!(0x0, 0x0, 0x4, 0x1, VpciDevType::Physical), // 00:04.1 - pci_dev!(0x0, 0x0, 0x5, 0x0, VpciDevType::Physical), // 00:05.0 - pci_dev!(0x0, 0x0, 0x5, 0x1, VpciDevType::Physical), // 00:05.1 - pci_dev!(0x0, 0x0, 0x6, 0x0, VpciDevType::Physical), // 00:06.0 - pci_dev!(0x0, 0x0, 0x6, 0x1, VpciDevType::Physical), // 00:06.1 - pci_dev!(0x0, 0x0, 0x6, 0x2, VpciDevType::Physical), // 00:06.2 - pci_dev!(0x0, 0x0, 0x7, 0x0, VpciDevType::Physical), // 00:07.0 - pci_dev!(0x0, 0x0, 0x8, 0x0, VpciDevType::Physical), // 00:08.0 - pci_dev!(0x0, 0x0, 0x9, 0x0, VpciDevType::Physical), // 00:09.0 - pci_dev!(0x0, 0x0, 0xa, 0x0, VpciDevType::Physical), // 00:0a.0 - pci_dev!(0x0, 0x0, 0xb, 0x0, VpciDevType::Physical), // 00:0b.0 - pci_dev!(0x0, 0x0, 0xc, 0x0, VpciDevType::Physical), // 00:0c.0 - pci_dev!(0x0, 0x0, 0xd, 0x0, VpciDevType::Physical), // 00:0d.0 - pci_dev!(0x0, 0x0, 0xf, 0x0, VpciDevType::Physical), // 00:0f.0 + pci_dev!(0x0, 0x0, 0x0, 0x0, VpciDevType::Physical), // 00:00.0 + pci_dev!(0x0, 0x0, 0x0, 0x1, VpciDevType::Physical), // 00:00.1 + pci_dev!(0x0, 0x0, 0x0, 0x2, VpciDevType::Physical), // 00:00.2 + pci_dev!(0x0, 0x0, 0x0, 0x3, VpciDevType::Physical), // 00:00.3 + pci_dev!(0x0, 0x0, 0x4, 0x0, VpciDevType::Physical), // 00:04.0 + pci_dev!(0x0, 0x0, 0x4, 0x1, VpciDevType::Physical), // 00:04.1 + pci_dev!(0x0, 0x0, 0x5, 0x0, VpciDevType::Physical), // 00:05.0 + pci_dev!(0x0, 0x0, 0x5, 0x1, VpciDevType::Physical), // 00:05.1 + pci_dev!(0x0, 0x0, 0x6, 0x0, VpciDevType::Physical), // 00:06.0 + pci_dev!(0x0, 0x0, 0x6, 0x1, VpciDevType::Physical), // 00:06.1 + pci_dev!(0x0, 0x0, 0x6, 0x2, VpciDevType::Physical), // 00:06.2 + pci_dev!(0x0, 0x0, 0x7, 0x0, VpciDevType::Physical), // 00:07.0 + pci_dev!(0x0, 0x0, 0x8, 0x0, VpciDevType::Physical), // 00:08.0 + pci_dev!(0x0, 0x0, 0x9, 0x0, VpciDevType::Physical), // 00:09.0 + pci_dev!(0x0, 0x0, 0xa, 0x0, VpciDevType::Physical), // 00:0a.0 + pci_dev!(0x0, 0x0, 0xb, 0x0, VpciDevType::Physical), // 00:0b.0 + pci_dev!(0x0, 0x0, 0xc, 0x0, VpciDevType::Physical), // 00:0c.0 + pci_dev!(0x0, 0x0, 0xd, 0x0, VpciDevType::Physical), // 00:0d.0 + pci_dev!(0x0, 0x0, 0xf, 0x0, VpciDevType::Physical), // 00:0f.0 pci_dev!(0x0, 0x0, 0x10, 0x0, VpciDevType::Physical), // 00:10.0 pci_dev!(0x0, 0x0, 0x13, 0x0, VpciDevType::Physical), // 00:13.0 pci_dev!(0x0, 0x0, 0x16, 0x0, VpciDevType::Physical), // 00:16.0 pci_dev!(0x0, 0x0, 0x19, 0x0, VpciDevType::Physical), // 00:19.0 - pci_dev!(0x0, 0x2, 0x0, 0x0, VpciDevType::Physical), // 02:00.0 - pci_dev!(0x0, 0x5, 0x0, 0x0, VpciDevType::Physical), // 05:00.0 - pci_dev!(0x0, 0x6, 0x0, 0x0, VpciDevType::Physical), // 06:00.0 + pci_dev!(0x0, 0x2, 0x0, 0x0, VpciDevType::Physical), // 02:00.0 + pci_dev!(0x0, 0x5, 0x0, 0x0, VpciDevType::Physical), // 05:00.0 + pci_dev!(0x0, 0x6, 0x0, 0x0, VpciDevType::Physical), // 06:00.0 ]; - // bus << 8 | dev << 5 | func << 3 // pub const ROOT_PCI_DEVS: [u64; 0] = []; diff --git a/platform/riscv64/hifive-premier-p550/board.rs b/platform/riscv64/hifive-premier-p550/board.rs index 06e6d03c..4424db5d 100644 --- a/platform/riscv64/hifive-premier-p550/board.rs +++ b/platform/riscv64/hifive-premier-p550/board.rs @@ -155,7 +155,7 @@ pub const IRQ_WAKEUP_VIRTIO_DEVICE: usize = 0x20; // Note: all here's irqs are hardware irqs, // only these irq can be transferred to the physical PLIC. pub const HW_IRQS: [u32; 21] = [ - 0x1, 0x2, 0x3, 0x4, // cache controller + 0x1, 0x2, 0x3, 0x4, // cache controller 0x4f, // emmc 0x51, // sd-card 0x64, // uart0 @@ -163,17 +163,17 @@ pub const HW_IRQS: [u32; 21] = [ 0x183, // npu 0x75, 0x77, 0x79, 0x7b, 0x7d, 0x7f, 0x81, 0x83, // mailbox 0x123, // i2c - // 0x01, 0x03, 0x04, 0x02, // cache controller + // 0x01, 0x03, 0x04, 0x02, // cache controller ]; // irqs belong to the root zone. pub const ROOT_ZONE_IRQS_BITMAP: &[BitmapWord] = &get_irqs_bitmap(&[ - 0x1, 0x2, 0x3, 0x4, // cache controller + 0x1, 0x2, 0x3, 0x4, // cache controller 0x51, // sd-card 0x64, // uart0 0x164, 0x168, 0x165, 0x166, // iommu 0x183, // npu - 0x75, 0x77, 0x79, 0x7b, 0x7d, 0x7f, 0x81, 0x83, // mailbox + 0x75, 0x77, 0x79, 0x7b, 0x7d, 0x7f, 0x81, 0x83, // mailbox 0x123, // i2c ]); diff --git a/platform/riscv64/qemu-aia/board.rs b/platform/riscv64/qemu-aia/board.rs index 61bab9d6..951d93a6 100644 --- a/platform/riscv64/qemu-aia/board.rs +++ b/platform/riscv64/qemu-aia/board.rs @@ -102,7 +102,8 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 9] = [ pub const IRQ_WAKEUP_VIRTIO_DEVICE: usize = 0x20; pub const HW_IRQS: [u32; 11] = [1, 2, 3, 4, 5, 8, 10, 33, 34, 35, 36]; -pub const ROOT_ZONE_IRQS_BITMAP: &[BitmapWord] = &get_irqs_bitmap(&[1, 2, 3, 4, 5, 8, 10, 33, 34, 35, 36]); // ARCH= riscv .It doesn't matter temporarily. +pub const ROOT_ZONE_IRQS_BITMAP: &[BitmapWord] = + &get_irqs_bitmap(&[1, 2, 3, 4, 5, 8, 10, 33, 34, 35, 36]); // ARCH= riscv .It doesn't matter temporarily. pub const ROOT_ARCH_ZONE_CONFIG: HvArchZoneConfig = HvArchZoneConfig { plic_base: 0x0, diff --git a/platform/x86_64/qemu/board.rs b/platform/x86_64/qemu/board.rs index 81885502..8020834a 100644 --- a/platform/x86_64/qemu/board.rs +++ b/platform/x86_64/qemu/board.rs @@ -14,7 +14,9 @@ // Authors: // use crate::pci_dev; -use crate::{arch::zone::HvArchZoneConfig, config::*, memory::GuestPhysAddr, pci::vpci_dev::VpciDevType}; +use crate::{ + arch::zone::HvArchZoneConfig, config::*, memory::GuestPhysAddr, pci::vpci_dev::VpciDevType, +}; pub const MEM_TYPE_RESERVED: u32 = 5; @@ -148,14 +150,14 @@ pub const ROOT_PCI_CONFIG: [HvPciConfig; 1] = [HvPciConfig { pub const ROOT_PCI_MAX_BUS: usize = 1; pub const ROOT_PCI_DEVS: [HvPciDevConfig; 8] = [ - pci_dev!(0x0, 0x0, 0x0, 0x0, VpciDevType::Physical), // host bridge - pci_dev!(0x0, 0x0, 0x1, 0x0, VpciDevType::Physical), // VGA controller - pci_dev!(0x0, 0x0, 0x2, 0x0, VpciDevType::Physical), // Ethernet controller - pci_dev!(0x0, 0x0, 0x3, 0x0, VpciDevType::Physical), // PCI bridge + pci_dev!(0x0, 0x0, 0x0, 0x0, VpciDevType::Physical), // host bridge + pci_dev!(0x0, 0x0, 0x1, 0x0, VpciDevType::Physical), // VGA controller + pci_dev!(0x0, 0x0, 0x2, 0x0, VpciDevType::Physical), // Ethernet controller + pci_dev!(0x0, 0x0, 0x3, 0x0, VpciDevType::Physical), // PCI bridge pci_dev!(0x0, 0x0, 0x1f, 0x0, VpciDevType::Physical), // ISA bridge pci_dev!(0x0, 0x0, 0x1f, 0x2, VpciDevType::Physical), // SATA controller pci_dev!(0x0, 0x0, 0x1f, 0x3, VpciDevType::Physical), // SMBus - pci_dev!(0x0, 0x1, 0x0, 0x0, VpciDevType::Physical), // SCSI controller + pci_dev!(0x0, 0x1, 0x0, 0x0, VpciDevType::Physical), // SCSI controller ]; #[cfg(all(feature = "graphics"))] diff --git a/platform/x86_64/qemu/cargo/features b/platform/x86_64/qemu/cargo/features index f8ee525a..1c961621 100644 --- a/platform/x86_64/qemu/cargo/features +++ b/platform/x86_64/qemu/cargo/features @@ -1,4 +1,5 @@ pci ecam_pcie no_pcie_bar_realloc -uart16550a \ No newline at end of file +uart16550a +iommu \ No newline at end of file diff --git a/src/pci/pci_access.rs b/src/pci/pci_access.rs index dc891bd9..2646d3c8 100644 --- a/src/pci/pci_access.rs +++ b/src/pci/pci_access.rs @@ -624,7 +624,7 @@ pub trait PciBarRW: PciRWBase { 1u64 << ((readback_high.trailing_zeros() + 32) as u64) } }; - let value64 = (value as u64) | ((value_high as u64) << 32); + // let value64 = (value as u64) | ((value_high as u64) << 32); bararr[slot as usize] = PciMem::new_bar(PciMemType::Mem64Low, value64, size, pre); From 7b161b76ab37744dc16d0abab99f00c3049d379e Mon Sep 17 00:00:00 2001 From: Solicey Date: Thu, 22 Jan 2026 00:36:12 +0800 Subject: [PATCH 5/9] Merge branch 'percpu-local' into dev-x86_64 --- Cargo.lock | 27 +++++ Cargo.toml | 1 + platform/aarch64/imx8mp/linker.ld | 12 ++ platform/aarch64/ok6254-c/linker.ld | 12 ++ platform/aarch64/phytium-pi/linker.ld | 12 ++ platform/aarch64/qemu-gicv2/linker.ld | 12 ++ platform/aarch64/qemu-gicv3/linker.ld | 12 ++ platform/aarch64/rk3568/linker.ld | 14 ++- platform/aarch64/rk3588/linker.ld | 12 ++ platform/aarch64/zcu102/linker.ld | 12 ++ platform/loongarch64/ls3a5000/linker.ld | 12 ++ platform/loongarch64/ls3a6000/linker.ld | 12 ++ .../riscv64/hifive-premier-p550/linker.ld | 12 ++ platform/riscv64/megrez/linker.ld | 12 ++ platform/riscv64/qemu-aia/linker.ld | 12 ++ platform/riscv64/qemu-plic/linker.ld | 12 ++ platform/x86_64/nuc14mnk/linker.ld | 12 ++ platform/x86_64/qemu/linker.ld | 12 ++ src/arch/aarch64/cpu.rs | 2 +- src/arch/aarch64/hypercall.rs | 2 +- src/arch/aarch64/trap.rs | 2 +- src/arch/loongarch64/cpu.rs | 2 +- src/arch/loongarch64/trap.rs | 2 +- src/arch/riscv64/sbi.rs | 4 +- src/arch/riscv64/trap.rs | 2 + src/arch/riscv64/zone.rs | 4 +- src/arch/x86_64/acpi.rs | 2 +- src/arch/x86_64/boot.rs | 2 +- src/arch/x86_64/cpu.rs | 4 +- src/arch/x86_64/hypercall.rs | 2 +- src/arch/x86_64/ipi.rs | 2 +- src/arch/x86_64/mmio.rs | 2 +- src/arch/x86_64/pci.rs | 2 +- src/arch/x86_64/s2pt.rs | 2 +- src/arch/x86_64/trap.rs | 2 +- src/arch/x86_64/zone.rs | 2 +- src/{percpu.rs => cpu_data.rs} | 0 src/device/irqchip/aia/aplic.rs | 2 +- src/device/irqchip/aia/mod.rs | 2 +- src/device/irqchip/aia/vaplic.rs | 2 +- src/device/irqchip/gicv2/vgic.rs | 2 +- src/device/irqchip/gicv3/gits.rs | 2 +- src/device/irqchip/gicv3/vgic.rs | 2 +- src/device/irqchip/pic/lapic.rs | 2 +- src/event.rs | 104 ++++++------------ src/hypercall/mod.rs | 1 - src/logging.rs | 2 +- src/main.rs | 7 +- src/memory/mmio.rs | 2 +- src/pci/pci_handler.rs | 2 +- src/pci/pci_test.rs | 2 +- src/pci/vpci_dev/standard.rs | 2 +- src/zone.rs | 2 +- 53 files changed, 295 insertions(+), 107 deletions(-) rename src/{percpu.rs => cpu_data.rs} (100%) diff --git a/Cargo.lock b/Cargo.lock index 43a258fc..98b19c05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,6 +175,7 @@ dependencies = [ "log", "loongArch64", "numeric-enum-macro", + "percpu", "psci", "qemu-exit", "raw-cpuid", @@ -246,6 +247,29 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "percpu" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01e56c0c558952222967b592899f98765b48590e7bd7403bfd7075f73afc6ed6" +dependencies = [ + "cfg-if", + "percpu_macros", + "spin 0.9.8", + "x86", +] + +[[package]] +name = "percpu_macros" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9f4cc54a2e471ff72f1499461ba381ad4eae9cbd60d29c258545b995e406e0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.111", +] + [[package]] name = "proc-macro2" version = "1.0.103" @@ -477,6 +501,9 @@ name = "spin" version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] [[package]] name = "spin" diff --git a/Cargo.toml b/Cargo.toml index 949a646c..978406c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ cortex-a = "8.1.1" cfg-if = "1.0" bitvec = { version="1.0.1", default-features = false, features = ["atomic", "alloc"] } heapless = { version = "0.8.0 "} +percpu = { package = "percpu", version="0.2", features=["arm-el2"]} [target.'cfg(target_arch = "aarch64")'.dependencies] aarch64-cpu = "9.4.0" diff --git a/platform/aarch64/imx8mp/linker.ld b/platform/aarch64/imx8mp/linker.ld index 0f5e41f3..f8c4a9eb 100644 --- a/platform/aarch64/imx8mp/linker.ld +++ b/platform/aarch64/imx8mp/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0x40400000; +CPU_NUM = 4; SECTIONS { @@ -37,6 +38,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; ekernel = .; diff --git a/platform/aarch64/ok6254-c/linker.ld b/platform/aarch64/ok6254-c/linker.ld index c3c0b34a..4da975bb 100644 --- a/platform/aarch64/ok6254-c/linker.ld +++ b/platform/aarch64/ok6254-c/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0x80400000; +CPU_NUM = 4; SECTIONS { @@ -37,6 +38,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; ekernel = .; diff --git a/platform/aarch64/phytium-pi/linker.ld b/platform/aarch64/phytium-pi/linker.ld index bc718226..1438cfec 100644 --- a/platform/aarch64/phytium-pi/linker.ld +++ b/platform/aarch64/phytium-pi/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0x90100000; +CPU_NUM = 4; SECTIONS { @@ -37,6 +38,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; ekernel = .; diff --git a/platform/aarch64/qemu-gicv2/linker.ld b/platform/aarch64/qemu-gicv2/linker.ld index 0f5e41f3..f8c4a9eb 100644 --- a/platform/aarch64/qemu-gicv2/linker.ld +++ b/platform/aarch64/qemu-gicv2/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0x40400000; +CPU_NUM = 4; SECTIONS { @@ -37,6 +38,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; ekernel = .; diff --git a/platform/aarch64/qemu-gicv3/linker.ld b/platform/aarch64/qemu-gicv3/linker.ld index 0f5e41f3..f8c4a9eb 100644 --- a/platform/aarch64/qemu-gicv3/linker.ld +++ b/platform/aarch64/qemu-gicv3/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0x40400000; +CPU_NUM = 4; SECTIONS { @@ -37,6 +38,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; ekernel = .; diff --git a/platform/aarch64/rk3568/linker.ld b/platform/aarch64/rk3568/linker.ld index 26e135cd..0c741e0c 100644 --- a/platform/aarch64/rk3568/linker.ld +++ b/platform/aarch64/rk3568/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) -BASE_ADDRESS = 0x60080000; +BASE_ADDRESS = 0x00480000; +CPU_NUM = 4; SECTIONS { @@ -42,6 +43,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; ekernel = .; diff --git a/platform/aarch64/rk3588/linker.ld b/platform/aarch64/rk3588/linker.ld index 40a2ee2a..b287362b 100644 --- a/platform/aarch64/rk3588/linker.ld +++ b/platform/aarch64/rk3588/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0x500000; +CPU_NUM = 8; SECTIONS { @@ -41,6 +42,17 @@ SECTIONS *(.bss .bss.*) *(.sbss .sbss.*) } + + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; . = ALIGN(4K); ebss = .; diff --git a/platform/aarch64/zcu102/linker.ld b/platform/aarch64/zcu102/linker.ld index 0f5e41f3..f8c4a9eb 100644 --- a/platform/aarch64/zcu102/linker.ld +++ b/platform/aarch64/zcu102/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0x40400000; +CPU_NUM = 4; SECTIONS { @@ -37,6 +38,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; ekernel = .; diff --git a/platform/loongarch64/ls3a5000/linker.ld b/platform/loongarch64/ls3a5000/linker.ld index 6ca259e4..a226494f 100644 --- a/platform/loongarch64/ls3a5000/linker.ld +++ b/platform/loongarch64/ls3a5000/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0x90000001f0000000; +CPU_NUM = 4; SECTIONS @@ -46,6 +47,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; diff --git a/platform/loongarch64/ls3a6000/linker.ld b/platform/loongarch64/ls3a6000/linker.ld index 6ca259e4..a226494f 100644 --- a/platform/loongarch64/ls3a6000/linker.ld +++ b/platform/loongarch64/ls3a6000/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0x90000001f0000000; +CPU_NUM = 4; SECTIONS @@ -46,6 +47,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; diff --git a/platform/riscv64/hifive-premier-p550/linker.ld b/platform/riscv64/hifive-premier-p550/linker.ld index b1ec2354..6f2d2083 100644 --- a/platform/riscv64/hifive-premier-p550/linker.ld +++ b/platform/riscv64/hifive-premier-p550/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0x80200000; +CPU_NUM = 4; SECTIONS @@ -38,6 +39,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; ekernel = .; diff --git a/platform/riscv64/megrez/linker.ld b/platform/riscv64/megrez/linker.ld index b1ec2354..6f2d2083 100644 --- a/platform/riscv64/megrez/linker.ld +++ b/platform/riscv64/megrez/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0x80200000; +CPU_NUM = 4; SECTIONS @@ -38,6 +39,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; ekernel = .; diff --git a/platform/riscv64/qemu-aia/linker.ld b/platform/riscv64/qemu-aia/linker.ld index b1ec2354..6f2d2083 100644 --- a/platform/riscv64/qemu-aia/linker.ld +++ b/platform/riscv64/qemu-aia/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0x80200000; +CPU_NUM = 4; SECTIONS @@ -38,6 +39,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; ekernel = .; diff --git a/platform/riscv64/qemu-plic/linker.ld b/platform/riscv64/qemu-plic/linker.ld index b1ec2354..6f2d2083 100644 --- a/platform/riscv64/qemu-plic/linker.ld +++ b/platform/riscv64/qemu-plic/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0x80200000; +CPU_NUM = 4; SECTIONS @@ -38,6 +39,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; ekernel = .; diff --git a/platform/x86_64/nuc14mnk/linker.ld b/platform/x86_64/nuc14mnk/linker.ld index 11ae57fd..3fc54b77 100644 --- a/platform/x86_64/nuc14mnk/linker.ld +++ b/platform/x86_64/nuc14mnk/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0xffffff8000200000; +CPU_NUM = 4; SECTIONS { @@ -41,6 +42,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; ekernel = .; diff --git a/platform/x86_64/qemu/linker.ld b/platform/x86_64/qemu/linker.ld index 11ae57fd..3fc54b77 100644 --- a/platform/x86_64/qemu/linker.ld +++ b/platform/x86_64/qemu/linker.ld @@ -1,5 +1,6 @@ ENTRY(arch_entry) BASE_ADDRESS = 0xffffff8000200000; +CPU_NUM = 4; SECTIONS { @@ -41,6 +42,17 @@ SECTIONS *(.sbss .sbss.*) } + . = ALIGN(4K); + _percpu_start = .; + _percpu_end = _percpu_start + SIZEOF(.percpu); + .percpu 0x0 (NOLOAD) : AT(_percpu_start) { + _percpu_load_start = .; + *(.percpu .percpu.*) + _percpu_load_end = .; + . = _percpu_load_start + ALIGN(64) * CPU_NUM; + } + . = _percpu_end; + . = ALIGN(4K); ebss = .; ekernel = .; diff --git a/src/arch/aarch64/cpu.rs b/src/arch/aarch64/cpu.rs index 3f7e3676..9dc5357b 100644 --- a/src/arch/aarch64/cpu.rs +++ b/src/arch/aarch64/cpu.rs @@ -20,7 +20,7 @@ use crate::{ addr::PHYS_VIRT_OFFSET, mm::PARKING_MEMORY_SET, GuestPhysAddr, HostPhysAddr, MemFlags, MemoryRegion, VirtAddr, PARKING_INST_PAGE, }, - percpu::this_cpu_data, + cpu_data::this_cpu_data, platform::BOARD_MPIDR_MAPPINGS, zone::find_zone, }; diff --git a/src/arch/aarch64/hypercall.rs b/src/arch/aarch64/hypercall.rs index 91e59485..99bdfcbc 100644 --- a/src/arch/aarch64/hypercall.rs +++ b/src/arch/aarch64/hypercall.rs @@ -20,7 +20,7 @@ use crate::config::{HvZoneConfig, CONFIG_MAGIC_VERSION}; use crate::device::virtio_trampoline::MAX_DEVS; use crate::hypercall::HyperCall; use crate::hypercall::HyperCallResult; -use crate::percpu::this_zone; +use crate::cpu_data::this_zone; use crate::zone::this_zone_id; impl<'a> HyperCall<'a> { diff --git a/src/arch/aarch64/trap.rs b/src/arch/aarch64/trap.rs index e49146e0..8d25527e 100644 --- a/src/arch/aarch64/trap.rs +++ b/src/arch/aarch64/trap.rs @@ -28,7 +28,7 @@ use crate::{ event::{send_event, IPI_EVENT_SHUTDOWN, IPI_EVENT_WAKEUP}, hypercall::{HyperCall, SGI_IPI_ID}, memory::{mmio_handle_access, MMIOAccess}, - percpu::{get_cpu_data, this_cpu_data, this_zone}, + cpu_data::{get_cpu_data, this_cpu_data, this_zone}, zone::{is_this_root_zone, remove_zone}, }; diff --git a/src/arch/loongarch64/cpu.rs b/src/arch/loongarch64/cpu.rs index 625e43c4..3e00ec1d 100644 --- a/src/arch/loongarch64/cpu.rs +++ b/src/arch/loongarch64/cpu.rs @@ -18,7 +18,7 @@ use super::ipi::*; use super::zone::ZoneContext; use crate::arch::zone::disable_hwi_through; use crate::device::common::MMIODerefWrapper; -use crate::percpu::this_cpu_data; +use crate::cpu_data::this_cpu_data; use crate::zone::find_zone; use core::arch::asm; use core::fmt::{self, Debug, Formatter}; diff --git a/src/arch/loongarch64/trap.rs b/src/arch/loongarch64/trap.rs index d16e1c81..a748c2e2 100644 --- a/src/arch/loongarch64/trap.rs +++ b/src/arch/loongarch64/trap.rs @@ -25,7 +25,7 @@ use crate::device::irqchip::ls7a2000::chip::*; use crate::event::{check_events, dump_cpu_events, dump_events}; use crate::hypercall::{SGI_IPI_ID, *}; use crate::memory::{addr, mmio_handle_access, MMIOAccess}; -use crate::percpu::this_cpu_data; +use crate::cpu_data::this_cpu_data; use crate::zone::Zone; use crate::PHY_TO_DMW_UNCACHED; use core::arch; diff --git a/src/arch/riscv64/sbi.rs b/src/arch/riscv64/sbi.rs index 04492318..9f00f93b 100644 --- a/src/arch/riscv64/sbi.rs +++ b/src/arch/riscv64/sbi.rs @@ -19,10 +19,10 @@ use super::cpu::ArchCpu; use crate::arch::cpu::hartid_to_cpuid; use crate::arch::csr::*; use crate::consts::IPI_EVENT_SEND_IPI; +use crate::cpu_data::{get_cpu_data, this_cpu_data}; use crate::event::{send_event, IPI_EVENT_WAKEUP}; use crate::hypercall::HyperCall; -use crate::percpu::{get_cpu_data, this_cpu_data}; -use core::sync::atomic; +use core::sync::atomic::{self, Ordering}; use riscv::register::sie; use riscv_h::register::hvip; use sbi_rt::{HartMask, SbiRet}; diff --git a/src/arch/riscv64/trap.rs b/src/arch/riscv64/trap.rs index 99277f72..96ea3e60 100644 --- a/src/arch/riscv64/trap.rs +++ b/src/arch/riscv64/trap.rs @@ -20,6 +20,8 @@ use crate::device::irqchip::plic::{inject_irq, plic_get_hwirq}; use crate::event::check_events; use crate::memory::GuestPhysAddr; use crate::memory::{mmio_handle_access, MMIOAccess}; +use crate::memory::{GuestPhysAddr, HostPhysAddr}; +use crate::platform::__board::*; use core::arch::{asm, global_asm}; use riscv::register::stvec::TrapMode; use riscv::register::{sie, stvec}; diff --git a/src/arch/riscv64/zone.rs b/src/arch/riscv64/zone.rs index 1f53e97d..55f9d99f 100644 --- a/src/arch/riscv64/zone.rs +++ b/src/arch/riscv64/zone.rs @@ -15,9 +15,11 @@ // use crate::{ config::*, + cpu_data::get_cpu_data, device::virtio_trampoline::mmio_virtio_handler, error::HvResult, - memory::{GuestPhysAddr, HostPhysAddr, MemFlags, MemoryRegion}, + memory::{addr::align_up, GuestPhysAddr, HostPhysAddr, MemFlags, MemoryRegion, MemorySet}, + pci::pcibar::BarRegion, zone::Zone, }; impl Zone { diff --git a/src/arch/x86_64/acpi.rs b/src/arch/x86_64/acpi.rs index 4bfdc530..701b5dff 100644 --- a/src/arch/x86_64/acpi.rs +++ b/src/arch/x86_64/acpi.rs @@ -17,8 +17,8 @@ use crate::{ arch::boot, config::{HvConfigMemoryRegion, HvZoneConfig}, + cpu_data::{this_zone, CpuSet}, error::HvResult, - percpu::{this_zone, CpuSet}, platform::ROOT_PCI_MAX_BUS, }; use acpi::{ diff --git a/src/arch/x86_64/boot.rs b/src/arch/x86_64/boot.rs index 8e8c90b2..631b7749 100644 --- a/src/arch/x86_64/boot.rs +++ b/src/arch/x86_64/boot.rs @@ -20,7 +20,7 @@ use crate::{ consts::PAGE_SIZE, error::HvResult, memory::{GuestPhysAddr, HostPhysAddr, MemFlags, MemoryRegion, MemorySet}, - percpu::this_zone, + cpu_data::this_zone, platform::MEM_TYPE_RESERVED, }; use alloc::string::{String, ToString}; diff --git a/src/arch/x86_64/cpu.rs b/src/arch/x86_64/cpu.rs index 4610cc5f..57a6ffaa 100644 --- a/src/arch/x86_64/cpu.rs +++ b/src/arch/x86_64/cpu.rs @@ -30,6 +30,7 @@ use crate::{ vmx::*, }, consts::{self, core_end, PER_CPU_SIZE}, + cpu_data::{this_cpu_data, this_zone}, device::irqchip::pic::{check_pending_vectors, clear_vectors, ioapic, lapic::VirtLocalApic}, error::{HvError, HvResult}, memory::{ @@ -38,8 +39,7 @@ use crate::{ Frame, GuestPhysAddr, HostPhysAddr, MemFlags, MemoryRegion, PhysAddr, PAGE_SIZE, PARKING_INST_PAGE, }, - percpu::{this_cpu_data, this_zone}, - platform::ROOT_ZONE_BOOT_STACK, + platform::{ROOT_ZONE_BOOT_STACK, ROOT_ZONE_CMDLINE}, zone::{find_zone, this_zone_id}, }; use alloc::boxed::Box; diff --git a/src/arch/x86_64/hypercall.rs b/src/arch/x86_64/hypercall.rs index cb5517f1..598a8147 100644 --- a/src/arch/x86_64/hypercall.rs +++ b/src/arch/x86_64/hypercall.rs @@ -19,7 +19,7 @@ use crate::{ config::CONFIG_MAGIC_VERSION, device::virtio_trampoline::MAX_DEVS, hypercall::{HyperCall, HyperCallResult}, - percpu::this_zone, + cpu_data::this_zone, zone::{Zone, ZoneInfo}, }; use spin::RwLock; diff --git a/src/arch/x86_64/ipi.rs b/src/arch/x86_64/ipi.rs index b8c20de5..e8aba3e6 100644 --- a/src/arch/x86_64/ipi.rs +++ b/src/arch/x86_64/ipi.rs @@ -24,7 +24,7 @@ use crate::{ error::HvResult, event, hypercall::SGI_IPI_ID, - percpu::{this_cpu_data, this_zone, CpuSet}, + cpu_data::{this_cpu_data, this_zone, CpuSet}, }; use alloc::{collections::vec_deque::VecDeque, vec::Vec}; use bit_field::BitField; diff --git a/src/arch/x86_64/mmio.rs b/src/arch/x86_64/mmio.rs index 2b7681c4..abeb2ad1 100644 --- a/src/arch/x86_64/mmio.rs +++ b/src/arch/x86_64/mmio.rs @@ -24,7 +24,7 @@ use crate::{ addr::{GuestPhysAddr, GuestVirtAddr, HostPhysAddr}, MMIOAccess, MMIOHandler, }, - percpu::{this_cpu_data, this_zone}, + cpu_data::{this_cpu_data, this_zone}, }; use alloc::{sync::Arc, vec::Vec}; use bit_field::BitField; diff --git a/src/arch/x86_64/pci.rs b/src/arch/x86_64/pci.rs index cc05d533..ef173ce8 100644 --- a/src/arch/x86_64/pci.rs +++ b/src/arch/x86_64/pci.rs @@ -16,11 +16,11 @@ use crate::{ arch::{acpi, idt, mmio::MMIoDevice, pio::get_pio_bitmap, zone::HvArchZoneConfig}, + cpu_data::this_zone, error::HvResult, memory::{ mmio_generic_handler, mmio_handle_access, mmio_perform_access, GuestPhysAddr, MMIOAccess, }, - percpu::this_zone, zone::{this_zone_id, Zone}, }; use ::acpi::{mcfg::Mcfg, sdt::Signature}; diff --git a/src/arch/x86_64/s2pt.rs b/src/arch/x86_64/s2pt.rs index 9a4e8e49..2a0377e2 100644 --- a/src/arch/x86_64/s2pt.rs +++ b/src/arch/x86_64/s2pt.rs @@ -26,7 +26,7 @@ use crate::{ addr::{GuestPhysAddr, HostPhysAddr, PhysAddr}, MemFlags, }, - percpu::this_cpu_data, + cpu_data::this_cpu_data, zone::this_zone_id, }; use bit_field::BitField; diff --git a/src/arch/x86_64/trap.rs b/src/arch/x86_64/trap.rs index edfbeee9..88eaa3bc 100644 --- a/src/arch/x86_64/trap.rs +++ b/src/arch/x86_64/trap.rs @@ -36,7 +36,7 @@ use crate::{ error::HvResult, hypercall::HyperCall, memory::{mmio_handle_access, MMIOAccess, MemFlags}, - percpu::{this_cpu_data, this_zone}, + cpu_data::{this_cpu_data, this_zone}, zone::this_zone_id, }; use bit_field::BitField; diff --git a/src/arch/x86_64/zone.rs b/src/arch/x86_64/zone.rs index 8c808718..6a3b5f0c 100644 --- a/src/arch/x86_64/zone.rs +++ b/src/arch/x86_64/zone.rs @@ -17,10 +17,10 @@ use crate::{ arch::{acpi, boot, msr::set_msr_bitmap, pio, pio::set_pio_bitmap, Stage2PageTable}, config::*, + cpu_data::get_cpu_data, device::virtio_trampoline::mmio_virtio_handler, error::HvResult, memory::{GuestPhysAddr, HostPhysAddr, MemFlags, MemoryRegion, MemorySet}, - percpu::get_cpu_data, platform::MEM_TYPE_RESERVED, zone::Zone, }; diff --git a/src/percpu.rs b/src/cpu_data.rs similarity index 100% rename from src/percpu.rs rename to src/cpu_data.rs diff --git a/src/device/irqchip/aia/aplic.rs b/src/device/irqchip/aia/aplic.rs index b92556a3..5c1c967b 100644 --- a/src/device/irqchip/aia/aplic.rs +++ b/src/device/irqchip/aia/aplic.rs @@ -17,7 +17,7 @@ use crate::config::root_zone_config; use crate::device::irqchip::aia::imsic::imsic_trigger; use crate::zone::Zone; -use crate::{arch::cpu::ArchCpu, memory::GuestPhysAddr, percpu::this_cpu_data}; +use crate::{arch::cpu::ArchCpu, memory::GuestPhysAddr, cpu_data::this_cpu_data}; use riscv_decode::Instruction; use spin::Once; use spin::RwLock; diff --git a/src/device/irqchip/aia/mod.rs b/src/device/irqchip/aia/mod.rs index 93b4f5f5..7c5a5337 100644 --- a/src/device/irqchip/aia/mod.rs +++ b/src/device/irqchip/aia/mod.rs @@ -29,7 +29,7 @@ use crate::memory::HostPhysAddr; use crate::memory::MMIOAccess; use crate::memory::MemFlags; use crate::memory::MemoryRegion; -use crate::percpu::this_cpu_data; +use crate::cpu_data::this_cpu_data; use crate::platform::HW_IRQS; use crate::platform::{ BOARD_APLIC_INTERRUPTS_NUM, IMSIC_GUEST_INDEX, IMSIC_GUEST_NUM, IMSIC_S_BASE, diff --git a/src/device/irqchip/aia/vaplic.rs b/src/device/irqchip/aia/vaplic.rs index fdd50405..795b72f1 100644 --- a/src/device/irqchip/aia/vaplic.rs +++ b/src/device/irqchip/aia/vaplic.rs @@ -15,7 +15,7 @@ // use super::*; -use crate::percpu::this_cpu_data; +use crate::cpu_data::this_cpu_data; use alloc::sync::Arc; use alloc::vec::Vec; use bitvec::prelude::*; diff --git a/src/device/irqchip/gicv2/vgic.rs b/src/device/irqchip/gicv2/vgic.rs index 4490ef10..adeead25 100644 --- a/src/device/irqchip/gicv2/vgic.rs +++ b/src/device/irqchip/gicv2/vgic.rs @@ -28,7 +28,7 @@ use crate::device::irqchip::gicv2::gicd::{ use crate::device::irqchip::gicv2::GICV2; use crate::error::HvResult; use crate::memory::{mmio_perform_access, MMIOAccess, MemFlags, MemoryRegion}; -use crate::percpu::this_zone; +use crate::cpu_data::this_zone; /// This file defines and implements the functional functions of virtual gicv2. /// author: ForeverYolo /// reference: diff --git a/src/device/irqchip/gicv3/gits.rs b/src/device/irqchip/gicv3/gits.rs index eb8719f6..4552e281 100644 --- a/src/device/irqchip/gicv3/gits.rs +++ b/src/device/irqchip/gicv3/gits.rs @@ -21,7 +21,7 @@ use spin::{mutex::Mutex, Once, RwLock}; use crate::{ consts::MAX_ZONE_NUM, device::irqchip::gicv3::gicr::enable_one_lpi, memory::Frame, - percpu::this_zone, zone::this_zone_id, + cpu_data::this_zone, zone::this_zone_id, }; use super::host_gits_base; diff --git a/src/device/irqchip/gicv3/vgic.rs b/src/device/irqchip/gicv3/vgic.rs index bd16002b..cfae391b 100644 --- a/src/device/irqchip/gicv3/vgic.rs +++ b/src/device/irqchip/gicv3/vgic.rs @@ -28,7 +28,7 @@ use crate::{ error::HvResult, hypercall::SGI_IPI_ID, memory::{mmio_perform_access, MMIOAccess}, - percpu::{get_cpu_data, this_zone}, + cpu_data::{get_cpu_data, this_zone}, zone::{this_zone_id, Zone}, }; pub fn reg_range(base: usize, n: usize, size: usize) -> core::ops::Range { diff --git a/src/device/irqchip/pic/lapic.rs b/src/device/irqchip/pic/lapic.rs index f5697c3b..97482ada 100644 --- a/src/device/irqchip/pic/lapic.rs +++ b/src/device/irqchip/pic/lapic.rs @@ -24,7 +24,7 @@ use crate::{ device::irqchip::pic::pop_vector, error::HvResult, memory::Frame, - percpu::this_cpu_data, + cpu_data::this_cpu_data, }; use bit_field::BitField; use core::{ops::Range, u32}; diff --git a/src/event.rs b/src/event.rs index 7cec4dee..c7f073d4 100644 --- a/src/event.rs +++ b/src/event.rs @@ -24,92 +24,63 @@ use crate::{ platform::IRQ_WAKEUP_VIRTIO_DEVICE, }; use alloc::{collections::VecDeque, vec::Vec}; -use spin::{Mutex, Once}; +use spin::Mutex; pub const IPI_EVENT_WAKEUP: usize = 0; pub const IPI_EVENT_SHUTDOWN: usize = 1; pub const IPI_EVENT_VIRTIO_INJECT_IRQ: usize = 2; pub const IPI_EVENT_WAKEUP_VIRTIO_DEVICE: usize = 3; -static EVENT_MANAGER: Once = Once::new(); +#[percpu::def_percpu] +static PERCPU_EVENTS: Mutex> = Mutex::new(VecDeque::new()); -struct EventManager { - pub inner: Vec>>, +// The caller ensures the cpu_id is valid +#[inline(always)] +fn get_percpu_events(cpu: usize) -> &'static Mutex> { + unsafe { PERCPU_EVENTS.remote_ref_raw(cpu) } } -impl EventManager { - fn new(max_cpus: usize) -> Self { - let mut vs = vec![]; - for _ in 0..max_cpus { - let v = Mutex::new(VecDeque::new()); - vs.push(v) - } - Self { inner: vs } - } - - fn add_event(&self, cpu: usize, event_id: usize) -> Option<()> { - match self.inner.get(cpu) { - Some(events) => { - let mut e = events.lock(); - if event_id == IPI_EVENT_SHUTDOWN { - e.clear(); - } - e.push_back(event_id); - Some(()) - } - None => None, - } - } - - fn fetch_event(&self, cpu: usize) -> Option { - match self.inner.get(cpu) { - Some(events) => { - let mut e = events.lock(); - e.pop_front() - } - None => None, - } - } - - fn dump(&self) { - for (cpu, events) in self.inner.iter().enumerate() { - let e = events.lock(); - debug!("event manager: cpu: {}, events: {:?}", cpu, e); - } +fn add_event(cpu: usize, event_id: usize) -> Option<()> { + if cpu >= MAX_CPU_NUM { + return None; } - - fn dump_cpu(&self, cpu: usize) -> Vec { - let mut res = Vec::new(); - let e = self.inner[cpu].lock(); - for i in e.iter() { - res.push(*i); - } - res + let mut e = get_percpu_events(cpu).lock(); + if event_id == IPI_EVENT_SHUTDOWN { + // If the event is shutdown, we need to clear all previous events, because shutdown will make cpu idle and won't process any events. + e.clear(); } -} - -fn add_event(cpu: usize, event_id: usize) -> Option<()> { - EVENT_MANAGER.get().unwrap().add_event(cpu, event_id) + e.push_back(event_id); + Some(()) } pub fn fetch_event(cpu: usize) -> Option { - EVENT_MANAGER.get().unwrap().fetch_event(cpu) -} - -pub fn init() { - EVENT_MANAGER.call_once(|| EventManager::new(MAX_CPU_NUM)); + if cpu >= MAX_CPU_NUM { + return None; + } + get_percpu_events(cpu).lock().pop_front() } pub fn dump_events() { - EVENT_MANAGER.get().unwrap().dump(); + for cpu in 0..MAX_CPU_NUM { + let events = get_percpu_events(cpu).lock(); + if !events.is_empty() { + debug!("cpu {} events: {:?}", cpu, *events); + } + } } pub fn dump_cpu_events(cpu: usize) -> Vec { - EVENT_MANAGER.get().unwrap().dump_cpu(cpu) + if cpu >= MAX_CPU_NUM { + return Vec::new(); + } + get_percpu_events(cpu).lock().iter().cloned().collect() } pub fn clear_events(cpu: usize) { - EVENT_MANAGER.get().unwrap().inner[cpu].lock().clear(); + if cpu >= MAX_CPU_NUM { + return; + } + get_percpu_events(cpu).lock().clear(); } pub fn check_events() -> bool { @@ -179,10 +150,3 @@ pub fn send_event(cpu_id: usize, ipi_int_id: usize, event_id: usize) { add_event(cpu_id, event_id); arch_send_event(cpu_id as _, ipi_int_id as _); } - -#[test_case] -fn test_simple_send_event() { - init(); - send_event(0, 0, IPI_EVENT_WAKEUP); - assert_eq!(fetch_event(0), Some(IPI_EVENT_WAKEUP)); -} diff --git a/src/hypercall/mod.rs b/src/hypercall/mod.rs index ec3e3810..d757b561 100644 --- a/src/hypercall/mod.rs +++ b/src/hypercall/mod.rs @@ -21,7 +21,6 @@ use crate::config::HvZoneConfig; use crate::consts::{INVALID_ADDRESS, MAX_CPU_NUM, MAX_WAIT_TIMES, PAGE_SIZE}; use crate::device::virtio_trampoline::{MAX_DEVS, VIRTIO_BRIDGE, VIRTIO_IRQS}; use crate::error::HvResult; -use crate::percpu::{get_cpu_data, PerCpu}; use crate::zone::{ add_zone, all_zones_info, find_zone, is_this_root_zone, remove_zone, zone_create, ZoneInfo, }; diff --git a/src/logging.rs b/src/logging.rs index 128aeffc..fb7f2faf 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -204,7 +204,7 @@ impl Log for SimpleLogger { let level = record.level(); let line = record.line().unwrap_or(0); let target = record.target(); - let cpu_id = crate::percpu::this_cpu_data().id; + let cpu_id = crate::cpu_data::this_cpu_data().id; let level_color = match level { Level::Error => ColorCode::BrightRed, Level::Warn => ColorCode::BrightYellow, diff --git a/src/main.rs b/src/main.rs index b320606a..e03533ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,12 +52,12 @@ mod logging; mod arch; mod config; mod consts; +mod cpu_data; mod device; mod event; mod hypercall; mod memory; mod panic; -mod percpu; mod platform; mod zone; @@ -72,9 +72,9 @@ use crate::consts::{hv_end, mem_pool_start, MAX_CPU_NUM}; use arch::{cpu::cpu_start, entry::arch_entry}; use config::root_zone_config; use core::sync::atomic::{AtomicI32, AtomicU32, Ordering}; +use cpu_data::PerCpu; #[cfg(feature = "pci")] use pci::pci_config::hvisor_pci_init; -use percpu::PerCpu; use zone::{add_zone, zone_create}; static INITED_CPUS: AtomicU32 = AtomicU32::new(0); @@ -128,7 +128,6 @@ fn primary_init_early() { ); memory::frame::init(); memory::frame::test(); - event::init(); arch::stage2_mode_detect(); @@ -197,11 +196,13 @@ fn rust_main(cpuid: usize, host_dtb: usize) { if MASTER_CPU.load(Ordering::Acquire) == -1 { MASTER_CPU.store(cpuid as i32, Ordering::Release); is_primary = true; + percpu::init(); memory::heap::init(); memory::heap::test(); arch::time::init_timebase(); arch_post_heap_init(host_dtb); } + percpu::init_percpu_reg(cpuid); let cpu = PerCpu::new(cpuid); diff --git a/src/memory/mmio.rs b/src/memory/mmio.rs index 5c88ac31..54c7f3a6 100644 --- a/src/memory/mmio.rs +++ b/src/memory/mmio.rs @@ -15,7 +15,7 @@ // use core::{ptr, usize}; -use crate::{error::HvResult, percpu::this_zone, zone::zone_error}; +use crate::{error::HvResult, cpu_data::this_zone, zone::zone_error}; use super::GuestPhysAddr; diff --git a/src/pci/pci_handler.rs b/src/pci/pci_handler.rs index 0d310b8e..bc65d51d 100644 --- a/src/pci/pci_handler.rs +++ b/src/pci/pci_handler.rs @@ -16,10 +16,10 @@ use alloc::string::String; +use crate::cpu_data::this_zone; use crate::error::HvResult; use crate::memory::MMIOAccess; use crate::memory::{GuestPhysAddr, HostPhysAddr, MemFlags, MemoryRegion}; -use crate::percpu::this_zone; use crate::zone::is_this_root_zone; use super::pci_access::{BridgeField, EndpointField, HeaderType, PciField, PciMemType}; diff --git a/src/pci/pci_test.rs b/src/pci/pci_test.rs index 67278065..8cf4fc48 100644 --- a/src/pci/pci_test.rs +++ b/src/pci/pci_test.rs @@ -29,9 +29,9 @@ use super::{ use super::{mem_alloc::BaseAllocator, pci_struct::RootComplex}; use crate::{ + cpu_data::this_zone, memory::{mmio_perform_access, MMIOAccess}, pci::{config_accessors::PciConfigMmio, pci_access::EndpointHeader}, - percpu::this_zone, }; #[cfg(feature = "ecam_pcie")] diff --git a/src/pci/vpci_dev/standard.rs b/src/pci/vpci_dev/standard.rs index 7c3f396e..6a7e3bc8 100644 --- a/src/pci/vpci_dev/standard.rs +++ b/src/pci/vpci_dev/standard.rs @@ -22,12 +22,12 @@ use crate::pci::pci_access::{ use crate::pci::pci_struct::{CapabilityType, PciCapability, VirtualPciConfigSpace}; use crate::pci::PciConfigAddress; // use crate::memory::frame::Frame; +use crate::cpu_data::this_zone; use crate::memory::MMIOAccess; use crate::pci::pci_access::PciMemType; use crate::pci::pci_struct::ArcRwLockVirtualPciConfigSpace; use crate::pci::pci_struct::PciCapabilityRegion; use crate::pci::vpci_dev::VirtMsiXCap; -use crate::percpu::this_zone; use alloc::sync::Arc; use spin::RwLock; diff --git a/src/zone.rs b/src/zone.rs index 9efb5232..b02d079b 100644 --- a/src/zone.rs +++ b/src/zone.rs @@ -32,7 +32,7 @@ use crate::config::{HvZoneConfig, CONFIG_NAME_MAXLEN}; use crate::error::HvResult; use crate::memory::addr::GuestPhysAddr; use crate::memory::{MMIOConfig, MMIOHandler, MMIORegion, MemorySet}; -use crate::percpu::{get_cpu_data, this_zone, CpuSet}; +use crate::cpu_data::{get_cpu_data, this_zone, CpuSet}; use core::panic; #[cfg(feature = "dwc_pcie")] From 5212c17c021fe9f2d54ee02926c32ac90fc907b4 Mon Sep 17 00:00:00 2001 From: Solicey Date: Tue, 27 Jan 2026 23:23:04 +0800 Subject: [PATCH 6/9] change vesafb to efifb --- platform/x86_64/qemu/board.rs | 4 ++-- src/arch/x86_64/boot.rs | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/platform/x86_64/qemu/board.rs b/platform/x86_64/qemu/board.rs index 8020834a..bff9e8f8 100644 --- a/platform/x86_64/qemu/board.rs +++ b/platform/x86_64/qemu/board.rs @@ -54,7 +54,7 @@ const ROOT_ZONE_UEFI_REGION_ID: usize = 0x3; pub const ROOT_ZONE_NAME: &str = "root-linux"; pub const ROOT_ZONE_CMDLINE: &str = - "console=ttyS0 earlyprintk=serial nointremap no_timer_check efi=noruntime pci=pcie_scan_all,lastbus=1 root=/dev/vda rw init=/init\0"; + "console=tty0 console=ttyS0 earlycon=efifb earlyprintk=serial nointremap no_timer_check efi=noruntime pci=pcie_scan_all,lastbus=1 root=/dev/vda rw init=/sbin/init\0"; //"console=ttyS0 earlyprintk=serial rdinit=/init nokaslr nointremap\0"; // noapic // video=vesafb // /lib/systemd/systemd @@ -111,7 +111,7 @@ pub const ROOT_ZONE_MEMORY_REGIONS: [HvConfigMemoryRegion; 10] = [ const ROOT_ZONE_CMDLINE_ADDR: GuestPhysAddr = 0x9000; const ROOT_ZONE_SETUP_ADDR: GuestPhysAddr = 0xa000; const ROOT_ZONE_VMLINUX_ENTRY_ADDR: GuestPhysAddr = 0x10_0000; -const ROOT_ZONE_SCREEN_BASE_ADDR: GuestPhysAddr = 0; +const ROOT_ZONE_SCREEN_BASE_ADDR: GuestPhysAddr = 0x7000_0000; pub const IRQ_WAKEUP_VIRTIO_DEVICE: usize = 0x6; pub const ROOT_ZONE_IRQS_BITMAP: &[BitmapWord] = &get_irqs_bitmap(&[0; 32]); diff --git a/src/arch/x86_64/boot.rs b/src/arch/x86_64/boot.rs index 631b7749..08bf6401 100644 --- a/src/arch/x86_64/boot.rs +++ b/src/arch/x86_64/boot.rs @@ -18,9 +18,9 @@ use crate::{ arch::{zone::HvArchZoneConfig, Stage2PageTable}, config::{root_zone_config, HvConfigMemoryRegion, HvPciConfig, HvZoneConfig, MEM_TYPE_RAM}, consts::PAGE_SIZE, + cpu_data::this_zone, error::HvResult, memory::{GuestPhysAddr, HostPhysAddr, MemFlags, MemoryRegion, MemorySet}, - cpu_data::this_zone, platform::MEM_TYPE_RESERVED, }; use alloc::string::{String, ToString}; @@ -105,6 +105,9 @@ const E820_MAX_ENTRIES_ZEROPAGE: usize = 128; const EFI64_LOADER_SIGNATURE: u32 = 0x34364c45; // EL64 +const VIDEO_TYPE_VLFB: u8 = 0x23; +const VIDEO_TYPE_EFI: u8 = 0x70; + bitflags::bitflags! { #[derive(Clone, Copy, Debug)] /// https://www.kernel.org/doc/html/latest/arch/x86/boot.html @@ -413,7 +416,7 @@ impl BootParams { self.screen_info.red_pos = 16; self.screen_info.alpha_size = 8; self.screen_info.alpha_pos = 24; - self.screen_info.orig_video_is_vga = 0x23; // VESA + self.screen_info.orig_video_is_vga = VIDEO_TYPE_EFI; self.screen_info.capabilities = 0; self.vid_mode = 0xffff; From 253a67fbed9dd01029f838c931c49ef8b5d2c4b2 Mon Sep 17 00:00:00 2001 From: Solicey Date: Wed, 28 Jan 2026 00:25:40 +0800 Subject: [PATCH 7/9] fix headers --- src/event.rs | 3 ++- src/hypercall/mod.rs | 1 + src/pci/pci_access.rs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/event.rs b/src/event.rs index c7f073d4..f31b1159 100644 --- a/src/event.rs +++ b/src/event.rs @@ -19,8 +19,8 @@ use crate::{ consts::{ IPI_EVENT_CLEAR_INJECT_IRQ, IPI_EVENT_SEND_IPI, IPI_EVENT_UPDATE_HART_LINE, MAX_CPU_NUM, }, + cpu_data::this_cpu_data, device::{irqchip::inject_irq, virtio_trampoline::handle_virtio_irq}, - percpu::this_cpu_data, platform::IRQ_WAKEUP_VIRTIO_DEVICE, }; use alloc::{collections::VecDeque, vec::Vec}; @@ -93,6 +93,7 @@ pub fn check_events() -> bool { } Some(IPI_EVENT_SHUTDOWN) => { cpu_data.arch_cpu.idle(); + false } Some(IPI_EVENT_VIRTIO_INJECT_IRQ) => { handle_virtio_irq(); diff --git a/src/hypercall/mod.rs b/src/hypercall/mod.rs index d757b561..55a3b8e1 100644 --- a/src/hypercall/mod.rs +++ b/src/hypercall/mod.rs @@ -19,6 +19,7 @@ use crate::arch::cpu::get_target_cpu; use crate::config::HvZoneConfig; use crate::consts::{INVALID_ADDRESS, MAX_CPU_NUM, MAX_WAIT_TIMES, PAGE_SIZE}; +use crate::cpu_data::{get_cpu_data, PerCpu}; use crate::device::virtio_trampoline::{MAX_DEVS, VIRTIO_BRIDGE, VIRTIO_IRQS}; use crate::error::HvResult; use crate::zone::{ diff --git a/src/pci/pci_access.rs b/src/pci/pci_access.rs index 2646d3c8..dc891bd9 100644 --- a/src/pci/pci_access.rs +++ b/src/pci/pci_access.rs @@ -624,7 +624,7 @@ pub trait PciBarRW: PciRWBase { 1u64 << ((readback_high.trailing_zeros() + 32) as u64) } }; - // let value64 = (value as u64) | ((value_high as u64) << 32); + let value64 = (value as u64) | ((value_high as u64) << 32); bararr[slot as usize] = PciMem::new_bar(PciMemType::Mem64Low, value64, size, pre); From df1f23d35e4efeb4bf60206fc0d6bc56e0006427 Mon Sep 17 00:00:00 2001 From: Solicey <58247189+Solicey@users.noreply.github.com> Date: Wed, 28 Jan 2026 15:48:36 +0800 Subject: [PATCH 8/9] Remove unused import in zone.rs Removed unused import of get_cpu_data from zone.rs. --- src/arch/riscv64/zone.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/arch/riscv64/zone.rs b/src/arch/riscv64/zone.rs index 55f9d99f..1f53e97d 100644 --- a/src/arch/riscv64/zone.rs +++ b/src/arch/riscv64/zone.rs @@ -15,11 +15,9 @@ // use crate::{ config::*, - cpu_data::get_cpu_data, device::virtio_trampoline::mmio_virtio_handler, error::HvResult, - memory::{addr::align_up, GuestPhysAddr, HostPhysAddr, MemFlags, MemoryRegion, MemorySet}, - pci::pcibar::BarRegion, + memory::{GuestPhysAddr, HostPhysAddr, MemFlags, MemoryRegion}, zone::Zone, }; impl Zone { From a0597d5df09a4bf10eaa5d07391abb54170f7f5d Mon Sep 17 00:00:00 2001 From: Solicey <58247189+Solicey@users.noreply.github.com> Date: Wed, 28 Jan 2026 15:49:36 +0800 Subject: [PATCH 9/9] Clean up imports in trap.rs Removed unused imports for HostPhysAddr and __board. --- src/arch/riscv64/trap.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/arch/riscv64/trap.rs b/src/arch/riscv64/trap.rs index 96ea3e60..99277f72 100644 --- a/src/arch/riscv64/trap.rs +++ b/src/arch/riscv64/trap.rs @@ -20,8 +20,6 @@ use crate::device::irqchip::plic::{inject_irq, plic_get_hwirq}; use crate::event::check_events; use crate::memory::GuestPhysAddr; use crate::memory::{mmio_handle_access, MMIOAccess}; -use crate::memory::{GuestPhysAddr, HostPhysAddr}; -use crate::platform::__board::*; use core::arch::{asm, global_asm}; use riscv::register::stvec::TrapMode; use riscv::register::{sie, stvec};