74 lines
1.5 KiB
Rust
74 lines
1.5 KiB
Rust
|
use core::arch::global_asm;
|
||
|
|
||
|
use yboot_proto::{
|
||
|
v1::FramebufferOption, LoadProtocolHeader, LoadProtocolV1, KERNEL_MAGIC, LOADER_MAGIC,
|
||
|
PROTOCOL_VERSION_1,
|
||
|
};
|
||
|
|
||
|
pub const KERNEL_VIRT_OFFSET: usize = 0xFFFFFF8000000000;
|
||
|
const BOOT_STACK_SIZE: usize = 65536;
|
||
|
|
||
|
#[repr(C, align(0x20))]
|
||
|
struct BootStack {
|
||
|
data: [u8; BOOT_STACK_SIZE],
|
||
|
}
|
||
|
|
||
|
#[link_section = ".bss"]
|
||
|
static mut BSP_STACK: BootStack = BootStack {
|
||
|
data: [0; BOOT_STACK_SIZE],
|
||
|
};
|
||
|
|
||
|
#[used]
|
||
|
#[link_section = ".data.yboot"]
|
||
|
static mut YBOOT_DATA: LoadProtocolV1 = LoadProtocolV1 {
|
||
|
header: LoadProtocolHeader {
|
||
|
kernel_magic: KERNEL_MAGIC,
|
||
|
version: PROTOCOL_VERSION_1,
|
||
|
},
|
||
|
kernel_virt_offset: KERNEL_VIRT_OFFSET as _,
|
||
|
|
||
|
opt_framebuffer: FramebufferOption {
|
||
|
req_width: 1024,
|
||
|
req_height: 768,
|
||
|
|
||
|
res_width: 0,
|
||
|
res_height: 0,
|
||
|
res_stride: 0,
|
||
|
res_address: 0,
|
||
|
},
|
||
|
};
|
||
|
|
||
|
extern "C" fn __x86_64_upper_entry() -> ! {
|
||
|
loop {}
|
||
|
}
|
||
|
|
||
|
global_asm!(
|
||
|
r#"
|
||
|
.global __x86_64_entry
|
||
|
|
||
|
.section .text.entry
|
||
|
__x86_64_entry:
|
||
|
mov ${yboot_loader_magic}, %edi
|
||
|
cmp %edi, %eax
|
||
|
je 2f
|
||
|
|
||
|
// (Currently) unsupported bootloader
|
||
|
1:
|
||
|
cli
|
||
|
hlt
|
||
|
jmp 1b
|
||
|
|
||
|
2:
|
||
|
// yboot entry method
|
||
|
movabsq ${stack_bottom} + {stack_size}, %rax
|
||
|
movabsq ${entry}, %rcx
|
||
|
mov %rax, %rsp
|
||
|
jmp *%rcx
|
||
|
"#,
|
||
|
yboot_loader_magic = const LOADER_MAGIC,
|
||
|
stack_size = const BOOT_STACK_SIZE,
|
||
|
stack_bottom = sym BSP_STACK,
|
||
|
entry = sym __x86_64_upper_entry,
|
||
|
options(att_syntax)
|
||
|
);
|