summaryrefslogtreecommitdiff
path: root/bootloader/src/main.rs
blob: d26ba0804eeebf79cc7dbc7e9a5a23e5bd36be2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#![no_main]
#![no_std]

use core::time::Duration;
use log::info;
use uefi::CString16;
use uefi::Result;
use uefi::Status;
use uefi::boot::{self, ScopedProtocol};
use uefi::fs::{FileSystem, FileSystemResult};
use uefi::prelude::*;
use uefi::print;
use uefi::proto::media::fs::SimpleFileSystem;

extern crate alloc;
use alloc::vec::Vec;

#[entry]
fn main() -> Status {
    uefi::helpers::init().unwrap();
    info!("Hello from bootloader!");
    load_kernel().unwrap();
    info!("Entry fuction regained control!");
    boot::stall(Duration::from_secs(10));
    info!("exiting!");
    Status::SUCCESS
}

fn load_kernel() -> Result {
    info!("Entered load_kernel function");
    let kernel = read_file(r"\EFI\BOOT\kernel.elf").unwrap();
    info!("Read kernel into memory!");
    print!("{:x?}", kernel[..10].to_vec());
    info!("I printed my dump");
    return Ok(());
}

fn read_file(path: &str) -> FileSystemResult<Vec<u8>> {
    let path: CString16 = CString16::try_from(path).unwrap();
    let fs: ScopedProtocol<SimpleFileSystem> =
        boot::get_image_file_system(boot::image_handle()).unwrap();
    let mut fs = FileSystem::new(fs);
    fs.read(path.as_ref())
}