mod.rs 1.51 KB
Newer Older
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
45
46
47
48
49
50
51
52
53
54
55
56
57
pub mod bootinfo;
pub mod entry;
pub mod paging;
pub mod serial;

pub use crate::arch::bootinfo::*;
use crate::arch::paging::*;
use crate::arch::serial::SerialPort;
use goblin::elf;

extern "C" {
	static kernel_end: u8;
}

pub const ELF_ARCH: u16 = elf::header::EM_AARCH64;

const RAM_START: u64 = 0x40000000;
const SERIAL_PORT_ADDRESS: u32 = 0x9000000;

// VARIABLES
pub static mut BOOT_INFO: BootInfo = BootInfo::new();
static COM1: SerialPort = SerialPort::new(SERIAL_PORT_ADDRESS);

pub fn message_output_init() {
	// nothing to do
}

pub fn output_message_byte(byte: u8) {
	COM1.write_byte(byte);
}

pub unsafe fn get_memory(_memory_size: u64) -> u64 {
	align_up!(&kernel_end as *const u8 as u64, LargePageSize::SIZE as u64)
}

pub fn find_kernel() -> &'static [u8] {
	include_bytes!(env!("HERMIT_APP"))
}

pub unsafe fn boot_kernel(virtual_address: u64, mem_size: u64, entry_point: u64) -> ! {
	// Jump to the kernel entry point and provide the Multiboot information to it.
	loaderlog!(
		"Jumping to HermitCore Application Entry Point at 0x{:x}",
		entry_point
	);

	// Supply the parameters to the HermitCore application.
	BOOT_INFO.base = virtual_address;
	BOOT_INFO.limit = 0x40000000 /* start address of the RAM */ + 0x4000000 /* 64 MB */;
	BOOT_INFO.image_size = mem_size;
	BOOT_INFO.current_stack_address = RAM_START;
	//loaderlog!("BOOT_INFO:");
	//loaderlog!("==========");
	//loaderlog!("{:?}", BOOT_INFO);

	let func: extern "C" fn(boot_info: &'static mut BootInfo) -> ! =
		core::mem::transmute(entry_point);
58
	func(&mut BOOT_INFO)
59
}