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,10 +1,29 @@
#!/bin/bash
DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
. "$DIR/functions"
get_version
cd ../patcher
cargo build --release
cd ../kernel
RUSTFLAGS='-Clink-arg=--script=link.x' cargo build --target i686-unknown-none.json --release -Zbuild-std --bin entrypoint
# build the kernel's entrypoint
cp target/i686-unknown-none/release/entrypoint kernel.flat
# copy it out
/home/arthur/aphrodite/patcher/target/release/patcher
../patcher/target/release/patcher
# run the custom patching program to add the multiboot2 header
rm -rf grub
cp -r ./grub_template ./grub
cp kernel.flat ./grub/boot/aphrodite.kernel
sed -i "s@%{VERSION}@$VERSION@g" ./grub/boot/grub/grub.cfg

14
kernel/check Executable file
View file

@ -0,0 +1,14 @@
#!/bin/bash
# Build the file
./build
if grub-file --is-x86-multiboot2 kernel.flat; then
echo "Multiboot2 header valid" > ./check_results
else
echo "Multiboot2 header INVALID!" > ./check_results
fi
echo
cat check_results

1
kernel/check_results Normal file
View file

@ -0,0 +1 @@
Multiboot2 header valid

File diff suppressed because it is too large Load diff

13
kernel/functions Normal file
View file

@ -0,0 +1,13 @@
function get_version() {
local TEMP_SUFFIX
if [[ ! $(git diff-index --quiet HEAD --) ]]; then
TEMP_SUFFIX="-out-of-tree"
fi
SUFFIX="${SUFFIX:-$TEMP_SUFFIX}"
VERSION="${VERSION:-devel-$(git rev-parse --short HEAD)$SUFFIX}"
}
function reset_version_vars() {
unset TEMP_SUFFIX SUFFIX VERSION
}

BIN
kernel/grub/boot/aphrodite.kernel Executable file

Binary file not shown.

View file

@ -0,0 +1,5 @@
menuentry "Aphrodite" --class aphrodite --class kernel --class os $menuentry_id_option 'aphrodite-basic-devel-6985552-out-of-tree' {
set root='hd1,gpt2'
echo 'Loading Aphrodite aphrodite-devel-6985552-out-of-tree ...'
multiboot2 /boot/aphrodite.kernel
}

View file

@ -0,0 +1,5 @@
menuentry "Aphrodite" --class aphrodite --class kernel --class os $menuentry_id_option 'aphrodite-basic-%{VERSION}' {
set root='hd1,gpt2'
echo 'Loading Aphrodite aphrodite-%{VERSION} ...'
multiboot2 /boot/aphrodite.kernel
}

Binary file not shown.

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
0xE85250D6, // Magic number
0x00000000, // Architecture, 0=i386
0x00000018, // length of MULTIBOOT_HEADER
0x17ADAF12, // 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
// 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()