|
| 1 | +mod gdt; |
| 2 | +mod page_tables; |
| 3 | +mod stack; |
| 4 | + |
| 5 | +use core::sync::atomic::{AtomicU32, Ordering}; |
| 6 | + |
| 7 | +use hermit_entry::boot_info::{BootInfo, HardwareInfo, LoadInfo, PlatformInfo, SerialPortBase}; |
| 8 | +use pvh::start_info::reader::{IdentityMap, StartInfoReader}; |
| 9 | + |
| 10 | +use self::stack::{STACK, Stack}; |
| 11 | +use crate::env::setboot_info2; |
| 12 | +use crate::kernel::pre_init; |
| 13 | + |
| 14 | +/// The PVH entry point. |
| 15 | +#[unsafe(naked)] |
| 16 | +pub(crate) unsafe extern "C" fn pvh_start32() -> ! { |
| 17 | + core::arch::naked_asm!( |
| 18 | + ".code32", |
| 19 | + include_str!("pvh_start32.s"), |
| 20 | + ".code64", |
| 21 | + |
| 22 | + level_4_table = sym page_tables::LEVEL_4_TABLE, |
| 23 | + gdt_ptr = sym gdt::GDT_PTR, |
| 24 | + kernel_data_selector = const gdt::Gdt::kernel_data_selector().0, |
| 25 | + |
| 26 | + stack = sym STACK, |
| 27 | + stack_size = const size_of::<Stack>(), |
| 28 | + kernel_code_selector = const gdt::Gdt::kernel_code_selector().0, |
| 29 | + rust_start = sym rust_start, |
| 30 | + ); |
| 31 | +} |
| 32 | + |
| 33 | +pvh::xen_elfnote_phys32_entry!(pvh_start32); |
| 34 | + |
| 35 | +/// The native ELF entry point. |
| 36 | +#[unsafe(no_mangle)] |
| 37 | +#[unsafe(naked)] |
| 38 | +unsafe extern "C" fn _start() -> ! { |
| 39 | + core::arch::naked_asm!("2: jmp 2b"); |
| 40 | +} |
| 41 | + |
| 42 | +static START_INFO_PADDR: AtomicU32 = AtomicU32::new(0); |
| 43 | + |
| 44 | +pub fn start_info<'a>() -> StartInfoReader<'a, IdentityMap> { |
| 45 | + let paddr = START_INFO_PADDR.load(Ordering::Relaxed); |
| 46 | + unsafe { StartInfoReader::from_paddr_identity(paddr).unwrap() } |
| 47 | +} |
| 48 | + |
| 49 | +/// The Rust entry point. |
| 50 | +unsafe extern "C" fn rust_start(start_info_paddr: u32) -> ! { |
| 51 | + START_INFO_PADDR.store(start_info_paddr, Ordering::Relaxed); |
| 52 | + |
| 53 | + let start_info = start_info(); |
| 54 | + |
| 55 | + println!("Start info:\n{start_info:#?}"); |
| 56 | + |
| 57 | + let boot_info = BootInfo { |
| 58 | + hardware_info: HardwareInfo { |
| 59 | + phys_addr_range: 0..0, |
| 60 | + serial_port_base: SerialPortBase::new(0x3f8), |
| 61 | + device_tree: None, |
| 62 | + }, |
| 63 | + // This is not used by the kernel anymore. |
| 64 | + load_info: LoadInfo { |
| 65 | + kernel_image_addr_range: 0..0, |
| 66 | + tls_info: None, |
| 67 | + }, |
| 68 | + platform_info: PlatformInfo::Fdt, |
| 69 | + }; |
| 70 | + |
| 71 | + println!("boot_info = {boot_info:#x?}"); |
| 72 | + |
| 73 | + setboot_info2(boot_info); |
| 74 | + |
| 75 | + unsafe { pre_init(None, 0) } |
| 76 | +} |
0 commit comments