12b7818e8SLoGin use system_error::SystemError;
22b7818e8SLoGin
3*db7c782aSLoGin use crate::arch::init::multiboot::early_multiboot_init;
4*db7c782aSLoGin
52b7818e8SLoGin use super::multiboot2::early_multiboot2_init;
62b7818e8SLoGin
72b7818e8SLoGin const BOOT_ENTRY_TYPE_MULTIBOOT: u64 = 1;
82b7818e8SLoGin const BOOT_ENTRY_TYPE_MULTIBOOT2: u64 = 2;
92b7818e8SLoGin const BOOT_ENTRY_TYPE_LINUX_32: u64 = 3;
102b7818e8SLoGin const BOOT_ENTRY_TYPE_LINUX_64: u64 = 4;
112b7818e8SLoGin
122b7818e8SLoGin #[derive(Debug)]
132b7818e8SLoGin #[repr(u64)]
142b7818e8SLoGin enum BootProtocol {
152b7818e8SLoGin Multiboot = 1,
162b7818e8SLoGin Multiboot2,
172b7818e8SLoGin Linux32,
182b7818e8SLoGin Linux64,
192b7818e8SLoGin }
202b7818e8SLoGin
212b7818e8SLoGin impl TryFrom<u64> for BootProtocol {
222b7818e8SLoGin type Error = SystemError;
232b7818e8SLoGin
try_from(value: u64) -> Result<Self, Self::Error>242b7818e8SLoGin fn try_from(value: u64) -> Result<Self, Self::Error> {
252b7818e8SLoGin match value {
262b7818e8SLoGin BOOT_ENTRY_TYPE_MULTIBOOT => Ok(BootProtocol::Multiboot),
272b7818e8SLoGin BOOT_ENTRY_TYPE_MULTIBOOT2 => Ok(BootProtocol::Multiboot2),
282b7818e8SLoGin BOOT_ENTRY_TYPE_LINUX_32 => Ok(BootProtocol::Linux32),
292b7818e8SLoGin BOOT_ENTRY_TYPE_LINUX_64 => Ok(BootProtocol::Linux64),
302b7818e8SLoGin _ => Err(SystemError::EINVAL),
312b7818e8SLoGin }
322b7818e8SLoGin }
332b7818e8SLoGin }
342b7818e8SLoGin
352b7818e8SLoGin #[inline(never)]
early_boot_init( boot_entry_type: u64, arg1: u64, arg2: u64, ) -> Result<(), SystemError>362b7818e8SLoGin pub(super) fn early_boot_init(
372b7818e8SLoGin boot_entry_type: u64,
382b7818e8SLoGin arg1: u64,
392b7818e8SLoGin arg2: u64,
402b7818e8SLoGin ) -> Result<(), SystemError> {
412b7818e8SLoGin let boot_protocol = BootProtocol::try_from(boot_entry_type)?;
422b7818e8SLoGin match boot_protocol {
43*db7c782aSLoGin BootProtocol::Multiboot => early_multiboot_init(arg1 as u32, arg2),
442b7818e8SLoGin BootProtocol::Multiboot2 => early_multiboot2_init(arg1 as u32, arg2),
452b7818e8SLoGin BootProtocol::Linux32 => {
462b7818e8SLoGin // linux32_init(arg1, arg2);
472b7818e8SLoGin unimplemented!();
482b7818e8SLoGin }
492b7818e8SLoGin BootProtocol::Linux64 => {
502b7818e8SLoGin // linux64_init(arg1, arg2);
512b7818e8SLoGin unimplemented!();
522b7818e8SLoGin }
532b7818e8SLoGin }
542b7818e8SLoGin }
55