Did a bunch of work, multiboot2 header is now correct, added some scripts and started work on grub

This commit is contained in:
Arthur Beck 2025-01-23 16:51:01 -06:00
parent 69855525cb
commit 0b87ccb219
10 changed files with 78 additions and 1093 deletions

View file

@ -1,26 +1,25 @@
use std::{fs, io::Write};
static MULTIBOOT_HEADER: [u16; 14] = [
static MULTIBOOT_HEADER: [u32; 6] = [
// Magic fields
0xE852, 0x50D6, // Magic number
0x0000, 0x0000, // Architecture, 0=i386
0x0000, 0x000E, // length of MULTIBOOT_HEADER
0x17AD, 0xAF1C, // checksum=all magic field excluding this+this=0
// Framebuffer tag- empty flags, no preference for width, height, or bit depth
0x0005, 0x0000,
0x0014, 0x0000,
0x0000, 0x0000
0xE85250D6, // Magic number
0x00000000, // Architecture, 0=i386
0x00000018, // length of MULTIBOOT_HEADER
0x17ADAF12, // checksum=all magic field excluding this+this=0
// Ending tag- empty flags, size 8
0x00000000,
0x00000008
];
fn from_u16(from: &mut [u16]) -> &[u8] {
if cfg!(target_endian = "little") {
fn from_u32(from: &mut [u32]) -> &[u8] {
if cfg!(target_endian = "big") {
for byte in from.iter_mut() {
*byte = byte.to_be();
*byte = byte.to_le();
}
}
let len = from.len().checked_mul(2).unwrap();
let len = from.len().checked_mul(4).unwrap();
let ptr: *const u8 = from.as_ptr().cast();
unsafe { std::slice::from_raw_parts(ptr, len) }
}
@ -29,7 +28,12 @@ fn main() {
let path = "./kernel.flat";
let mut buf = fs::read(path).unwrap();
buf = [
from_u16(&mut (MULTIBOOT_HEADER.clone())).to_vec(),
from_u32(&mut (MULTIBOOT_HEADER.clone())).to_vec(),
vec![ // jump past patch text
0xE9, 0x55, 0x00, 0x00, 0x00
],
b"Multiboot2 header patched by Aphrodite ".to_vec(),
b"APHROKERN: OSS at github.com/AverseABFun/Aphrodite".to_vec(),
buf
].concat();
fs::OpenOptions::new()