diff --git a/framework/aster-frame/src/arch/x86/console.rs b/framework/aster-frame/src/arch/x86/console.rs index 22e320407..826f59d86 100644 --- a/framework/aster-frame/src/arch/x86/console.rs +++ b/framework/aster-frame/src/arch/x86/console.rs @@ -55,7 +55,7 @@ pub(crate) fn callback_init() { crate::arch::x86::kernel::pic::allocate_irq(4).unwrap() } else { let irq = IrqLine::alloc().unwrap(); - let mut io_apic = IO_APIC.get().unwrap().get(0).unwrap().lock(); + let mut io_apic = IO_APIC.get().unwrap().first().unwrap().lock(); io_apic.enable(4, irq.clone()).unwrap(); irq }; diff --git a/framework/aster-frame/src/arch/x86/timer/apic.rs b/framework/aster-frame/src/arch/x86/timer/apic.rs index a84386150..2707068d6 100644 --- a/framework/aster-frame/src/arch/x86/timer/apic.rs +++ b/framework/aster-frame/src/arch/x86/timer/apic.rs @@ -102,7 +102,7 @@ fn init_periodic_mode() { let mut apic_lock = APIC_INSTANCE.get().unwrap().lock(); let mut irq = IrqLine::alloc_specific(super::TIMER_IRQ_NUM.load(Ordering::Relaxed)).unwrap(); irq.on_active(init_function); - let mut io_apic = IO_APIC.get().unwrap().get(0).unwrap().lock(); + let mut io_apic = IO_APIC.get().unwrap().first().unwrap().lock(); debug_assert_eq!(io_apic.interrupt_base(), 0); io_apic.enable(2, irq.clone()).unwrap(); drop(io_apic); @@ -133,7 +133,7 @@ fn init_periodic_mode() { return; } } - let mut io_apic = IO_APIC.get().unwrap().get(0).unwrap().lock(); + let mut io_apic = IO_APIC.get().unwrap().first().unwrap().lock(); io_apic.disable(2).unwrap(); drop(io_apic); // stop APIC Timer, get the number of tick we need diff --git a/framework/aster-frame/src/bus/mmio/mod.rs b/framework/aster-frame/src/bus/mmio/mod.rs index 252cca282..4c58bd740 100644 --- a/framework/aster-frame/src/bus/mmio/mod.rs +++ b/framework/aster-frame/src/bus/mmio/mod.rs @@ -34,7 +34,7 @@ fn iter_range(range: Range) { let mut io_apic = if is_ioapic2 { io_apics.get(1).unwrap().lock() } else { - io_apics.get(0).unwrap().lock() + io_apics.first().unwrap().lock() }; let mut device_count = 0; while current > range.start { diff --git a/framework/aster-frame/src/bus/pci/device_info.rs b/framework/aster-frame/src/bus/pci/device_info.rs index a17b276b3..c767d742d 100644 --- a/framework/aster-frame/src/bus/pci/device_info.rs +++ b/framework/aster-frame/src/bus/pci/device_info.rs @@ -68,7 +68,7 @@ impl PciDeviceLocation { /// Returns an iterator that enumerates all possible PCI device locations. pub fn all() -> impl Iterator { - iter::from_generator(|| { + iter::from_coroutine(|| { for bus in Self::MIN_BUS..=Self::MAX_BUS { for device in Self::MIN_DEVICE..=Self::MAX_DEVICE { for function in Self::MIN_FUNCTION..=Self::MAX_FUNCTION { diff --git a/framework/aster-frame/src/lib.rs b/framework/aster-frame/src/lib.rs index c20f38bde..1c35b5788 100644 --- a/framework/aster-frame/src/lib.rs +++ b/framework/aster-frame/src/lib.rs @@ -1,13 +1,12 @@ //! The framework part of Asterinas. #![feature(alloc_error_handler)] -#![feature(const_maybe_uninit_zeroed)] #![feature(const_mut_refs)] #![feature(const_ptr_sub_ptr)] #![feature(const_trait_impl)] #![feature(core_intrinsics)] +#![feature(coroutines)] #![feature(fn_traits)] -#![feature(generators)] -#![feature(iter_from_generator)] +#![feature(iter_from_coroutine)] #![feature(let_chains)] #![feature(negative_impls)] #![feature(new_uninit)] diff --git a/framework/aster-frame/src/sync/wait.rs b/framework/aster-frame/src/sync/wait.rs index 66b3ff3ff..0d042e2c7 100644 --- a/framework/aster-frame/src/sync/wait.rs +++ b/framework/aster-frame/src/sync/wait.rs @@ -96,7 +96,9 @@ impl WaitQueue { return Some(res); }; - if let Some(ref timer_callback) = timer_callback && timer_callback.is_expired() { + if let Some(ref timer_callback) = timer_callback + && timer_callback.is_expired() + { return None; } diff --git a/framework/aster-frame/src/util/mod.rs b/framework/aster-frame/src/util/mod.rs index 767ea5e05..d5b1738f4 100644 --- a/framework/aster-frame/src/util/mod.rs +++ b/framework/aster-frame/src/util/mod.rs @@ -1,4 +1 @@ pub mod recycle_allocator; -mod type_map; - -pub use self::type_map::TypeMap; diff --git a/framework/aster-frame/src/util/type_map.rs b/framework/aster-frame/src/util/type_map.rs deleted file mode 100644 index e998fb5fe..000000000 --- a/framework/aster-frame/src/util/type_map.rs +++ /dev/null @@ -1,26 +0,0 @@ -/// A type map is a collection whose keys are types, rather than values. -pub struct TypeMap {} - -pub trait Any: core::any::Any + Send + Sync {} - -impl TypeMap { - /// Creates an empty typed map. - pub fn new() -> Self { - todo!() - } - - /// Inserts a new item of type `T`. - pub fn insert(&mut self, val: T) -> Option { - todo!() - } - - /// Gets an item of type `T`. - pub fn get(&self) -> Option<&T> { - todo!() - } - - /// Gets an item of type `T`. - pub fn remove(&self) -> Option { - todo!() - } -} diff --git a/framework/libs/boot-trojan/builder/Cargo.toml b/framework/libs/boot-trojan/builder/Cargo.toml index 7ebdd461a..86cb3cd30 100644 --- a/framework/libs/boot-trojan/builder/Cargo.toml +++ b/framework/libs/boot-trojan/builder/Cargo.toml @@ -12,5 +12,5 @@ serde = { version = "1.0.192", features = ["derive"] } xmas-elf = "0.9.1" [features] -default = [] +default = ["trojan64"] trojan64 = [] diff --git a/framework/libs/boot-trojan/builder/src/lib.rs b/framework/libs/boot-trojan/builder/src/lib.rs index 2577b7367..f8f1afe66 100644 --- a/framework/libs/boot-trojan/builder/src/lib.rs +++ b/framework/libs/boot-trojan/builder/src/lib.rs @@ -158,7 +158,7 @@ fn build_trojan_with_arch(source_dir: &Path, out_dir: &Path, arch: &TrojanBuildA let out_dir = std::fs::canonicalize(out_dir).unwrap(); // Relocations are fewer in release mode. But with release mode it crashes. - let profile = "debug"; + let profile = "release"; let cargo = std::env::var("CARGO").unwrap(); let mut cmd = std::process::Command::new(cargo); diff --git a/framework/libs/boot-trojan/trojan/src/x86/amd64_efi/efi.rs b/framework/libs/boot-trojan/trojan/src/x86/amd64_efi/efi.rs index 60c78a261..84b6eec15 100644 --- a/framework/libs/boot-trojan/trojan/src/x86/amd64_efi/efi.rs +++ b/framework/libs/boot-trojan/trojan/src/x86/amd64_efi/efi.rs @@ -120,5 +120,12 @@ fn efi_phase_runtime( } } + unsafe { + use crate::console::{print_hex, print_str}; + print_str("[EFI stub] Entering Jinux entrypoint at "); + print_hex(super::JINUX_ENTRY_POINT as u64); + print_str("\n"); + } + unsafe { super::call_jinux_entrypoint(super::JINUX_ENTRY_POINT, boot_params_ptr as u64) } } diff --git a/framework/libs/boot-trojan/trojan/src/x86/legacy_i386/mod.rs b/framework/libs/boot-trojan/trojan/src/x86/legacy_i386/mod.rs index 8854bde52..38b528b8a 100644 --- a/framework/libs/boot-trojan/trojan/src/x86/legacy_i386/mod.rs +++ b/framework/libs/boot-trojan/trojan/src/x86/legacy_i386/mod.rs @@ -8,6 +8,8 @@ global_asm!(include_str!("setup.S")); use crate::console::{print_hex, print_str}; +pub const JINUX_ENTRY_POINT: u32 = 0x8001000; + #[export_name = "_trojan_entry_32"] extern "cdecl" fn trojan_entry(boot_params_ptr: u32) -> ! { // Safety: this init function is only called once. @@ -27,12 +29,7 @@ extern "cdecl" fn trojan_entry(boot_params_ptr: u32) -> ! { crate::loader::load_elf(payload); // Safety: the entrypoint and the ptr is valid. - unsafe { - call_jinux_entrypoint( - super::JINUX_ENTRY_POINT, - boot_params_ptr.try_into().unwrap(), - ) - }; + unsafe { call_jinux_entrypoint(JINUX_ENTRY_POINT, boot_params_ptr.try_into().unwrap()) }; } pub const ASTER_ENTRY_POINT: u32 = 0x8001000; diff --git a/framework/libs/boot-trojan/trojan/src/x86/mod.rs b/framework/libs/boot-trojan/trojan/src/x86/mod.rs index bedef4144..6e66f05f2 100644 --- a/framework/libs/boot-trojan/trojan/src/x86/mod.rs +++ b/framework/libs/boot-trojan/trojan/src/x86/mod.rs @@ -1,10 +1,8 @@ cfg_if::cfg_if! { if #[cfg(target_arch = "x86_64")] { mod amd64_efi; - pub use amd64_efi::*; } else if #[cfg(target_arch = "x86")] { mod legacy_i386; - pub use legacy_i386::*; } else { compile_error!("Unsupported target_arch"); } diff --git a/framework/libs/boot-trojan/trojan/src/x86/relocation.rs b/framework/libs/boot-trojan/trojan/src/x86/relocation.rs index 535f91f36..cada51331 100644 --- a/framework/libs/boot-trojan/trojan/src/x86/relocation.rs +++ b/framework/libs/boot-trojan/trojan/src/x86/relocation.rs @@ -28,10 +28,21 @@ fn get_rela_array() -> &'static [Elf64Rela] { let end = __rela_dyn_end as *const Elf64Rela; // FIXME: 2023/11/29 // There should be a Rust compiler bug that makes the calculation of len incorrect. - // The current implementation only works in debug mode. - // To do it in release mode, a workaround is to use inline asm. But that crashes - // in debug mode. QaQ - let len = unsafe { end.offset_from(start) } as usize; + // The most sound implementation only works in debug mode. + // let len = unsafe { end.offset_from(start) } as usize; + // The inline asm solution is a workaround. + let len = unsafe { + let len: usize; + core::arch::asm!(" + mov {len}, {end} + sub {len}, {start} + ", + len = out(reg) len, + end = in(reg) end, + start = in(reg) start, + ); + len / core::mem::size_of::() as usize + }; #[cfg(feature = "debug_print")] unsafe { use crate::console::{print_hex, print_str}; diff --git a/runner/src/machine/qemu_grub_efi.rs b/runner/src/machine/qemu_grub_efi.rs index 3c4438d4e..6a4f1d1ba 100644 --- a/runner/src/machine/qemu_grub_efi.rs +++ b/runner/src/machine/qemu_grub_efi.rs @@ -64,7 +64,9 @@ pub const IOMMU_DEVICE_ARGS: &[&str] = &[ "ioh3420,id=pcie.0,chassis=1", ]; -pub const GRUB_PREFIX: &str = "/usr/local/grub"; +// To test legacy boot, use the following: +// pub const GRUB_PREFIX: &str = "/usr/local/grub"; +pub const GRUB_PREFIX: &str = "/usr"; pub const GRUB_VERSION: &str = "x86_64-efi"; pub fn create_bootdev_image( diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 32a937f89..437cf4be9 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-10-05" +channel = "nightly-2023-12-01" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/services/libs/aster-std/src/lib.rs b/services/libs/aster-std/src/lib.rs index 0186ece53..3fc1b917e 100644 --- a/services/libs/aster-std/src/lib.rs +++ b/services/libs/aster-std/src/lib.rs @@ -17,7 +17,6 @@ #![feature(linked_list_remove)] #![feature(trait_alias)] #![feature(register_tool)] -#![feature(trait_upcasting)] #![feature(format_args_nl)] #![feature(int_roundings)] #![feature(step_trait)] diff --git a/services/libs/aster-std/src/process/process/process_group.rs b/services/libs/aster-std/src/process/process/process_group.rs index 9090cbd62..9a69d5752 100644 --- a/services/libs/aster-std/src/process/process/process_group.rs +++ b/services/libs/aster-std/src/process/process/process_group.rs @@ -21,7 +21,9 @@ impl Inner { return; }; - if let Some(leader) = &self.leader && Arc::ptr_eq(leader, &process) { + if let Some(leader) = &self.leader + && Arc::ptr_eq(leader, &process) + { self.leader = None; } } diff --git a/services/libs/aster-std/src/process/process/session.rs b/services/libs/aster-std/src/process/process/session.rs index 18ff44c4f..66ce097d1 100644 --- a/services/libs/aster-std/src/process/process/session.rs +++ b/services/libs/aster-std/src/process/process/session.rs @@ -28,7 +28,9 @@ impl Inner { } pub(in crate::process) fn remove_process(&mut self, process: &Arc) { - if let Some(leader) = &self.leader && Arc::ptr_eq(leader, process) { + if let Some(leader) = &self.leader + && Arc::ptr_eq(leader, process) + { self.leader = None; } } diff --git a/services/libs/aster-std/src/process/program_loader/elf/elf_file.rs b/services/libs/aster-std/src/process/program_loader/elf/elf_file.rs index e2b8fd9f0..499f93d03 100644 --- a/services/libs/aster-std/src/process/program_loader/elf/elf_file.rs +++ b/services/libs/aster-std/src/process/program_loader/elf/elf_file.rs @@ -111,7 +111,7 @@ impl Elf { // An offset to be subtracted from ELF vaddr for PIE pub fn base_load_address_offset(&self) -> u64 { - let phdr = self.program_headers.get(0).unwrap(); + let phdr = self.program_headers.first().unwrap(); phdr.virtual_addr - phdr.offset } } diff --git a/services/libs/aster-std/src/process/program_loader/elf/load_elf.rs b/services/libs/aster-std/src/process/program_loader/elf/load_elf.rs index af4fdbb69..f1cc047cb 100644 --- a/services/libs/aster-std/src/process/program_loader/elf/load_elf.rs +++ b/services/libs/aster-std/src/process/program_loader/elf/load_elf.rs @@ -199,12 +199,14 @@ fn base_map_addr(elf: &Elf, root_vmar: &Vmar) -> Result { .program_headers .iter() .filter_map(|program_header| { - if let Ok(type_) = program_header.get_type() && type_ == program::Type::Load { - let ph_max_addr = program_header.virtual_addr + program_header.mem_size; - Some(ph_max_addr as usize) - } else { - None - } + if let Ok(type_) = program_header.get_type() + && type_ == program::Type::Load + { + let ph_max_addr = program_header.virtual_addr + program_header.mem_size; + Some(ph_max_addr as usize) + } else { + None + } }) .max() .ok_or(Error::with_message( diff --git a/services/libs/aster-std/src/syscall/select.rs b/services/libs/aster-std/src/syscall/select.rs index 48171d640..ddeb243f4 100644 --- a/services/libs/aster-std/src/syscall/select.rs +++ b/services/libs/aster-std/src/syscall/select.rs @@ -122,15 +122,21 @@ fn do_select( let fd = poll_fd.fd().unwrap(); let revents = poll_fd.revents().get(); let (readable, writable, except) = convert_events_to_rwe(&revents); - if let Some(ref mut fds) = readfds && readable { + if let Some(ref mut fds) = readfds + && readable + { fds.set(fd)?; total_revents += 1; } - if let Some(ref mut fds) = writefds && writable { + if let Some(ref mut fds) = writefds + && writable + { fds.set(fd)?; total_revents += 1; } - if let Some(ref mut fds) = exceptfds && except { + if let Some(ref mut fds) = exceptfds + && except + { fds.set(fd)?; total_revents += 1; } diff --git a/services/libs/aster-std/src/util/net/mod.rs b/services/libs/aster-std/src/util/net/mod.rs index 3abaf11bd..571cfc939 100644 --- a/services/libs/aster-std/src/util/net/mod.rs +++ b/services/libs/aster-std/src/util/net/mod.rs @@ -1,10 +1,7 @@ mod addr; mod socket; -pub use addr::{ - read_socket_addr_from_user, write_socket_addr_to_user, InetAddr, SaFamily, SockAddr, - SockAddrInet, SockAddrInet6, SockAddrUnix, -}; +pub use addr::{read_socket_addr_from_user, write_socket_addr_to_user, SaFamily}; pub use socket::{Protocol, SockFlags, SockType, SOCK_TYPE_MASK}; #[macro_export] diff --git a/tools/docker/Dockerfile.ubuntu22.04 b/tools/docker/Dockerfile.ubuntu22.04 index 99ee9114f..8af048e76 100644 --- a/tools/docker/Dockerfile.ubuntu22.04 +++ b/tools/docker/Dockerfile.ubuntu22.04 @@ -121,7 +121,7 @@ FROM build-ovmf as ovmf # Fetch and build OVMF from the EDK2 official source WORKDIR /root -RUN git clone --depth 1 --branch edk2-stable202308 --recurse-submodules --shallow-submodules https://github.com/tianocore/edk2.git +RUN git clone --depth 1 --branch edk2-stable202311 --recurse-submodules --shallow-submodules https://github.com/tianocore/edk2.git WORKDIR /root/edk2 RUN source ./edksetup.sh \ && make -C BaseTools \ @@ -208,7 +208,9 @@ RUN apt update && apt-get install -y --no-install-recommends \ cpuid \ file \ gdb \ + grub-efi-amd64 \ grub-efi-amd64-bin \ + grub-efi-amd64-dbg \ libpixman-1-dev `# running dependency for QEMU` \ mtools `# used by grub-mkrescue` \ net-tools \