diff --git a/ap_bootstrap.s.x86_64.arch_specific b/ap_bootstrap.s.x86_64.arch_specific index 01dec7392..b94711619 100644 --- a/ap_bootstrap.s.x86_64.arch_specific +++ b/ap_bootstrap.s.x86_64.arch_specific @@ -1,18 +1,25 @@ [bits 16] - -[section .ap_bootstrap_section] +[org 0x8000] [global ap_entry] ap_entry: + jmp $ap_boot + +; PT: This is placeholder memory that will be overwritten to contain the 'parameters' passed to the AP +align 8 +param1: dd 0 +param2: dd 0 + +ap_boot: cli - xor ax, ax - mov cs, ax - mov dx, ax - mov ss, ax - mov sp, 0x80 - mov al, 0xff + ; PT: OSDev wiki seems to suggest clearing DF, but I'm not sure why + cld + + ; Set some debug register values and write to memory to ensure this code is running + mov al, 0x7c + mov bl, [$param1] + mov cl, [$param2] mov [0x2000], al - jmp $ .loop: jmp $.loop diff --git a/scripts/build_os_image.py b/scripts/build_os_image.py index 50919cecc..1dce9268a 100644 --- a/scripts/build_os_image.py +++ b/scripts/build_os_image.py @@ -64,6 +64,10 @@ def build_iso() -> Path: if not initrd_path.exists(): raise ValueError(f"initrd missing: {initrd_path}") + ap_bootstrap_path = _REPO_ROOT / ".compiled_ap_bootstrap" + if not ap_bootstrap_path.exists(): + raise ValueError(f"AP bootstrap missing: {ap_bootstrap_path}") + run_and_check(["dd", "if=/dev/zero", f"of={image_name.as_posix()}", "bs=512", "count=262144"]) with _get_mounted_iso(image_name) as mount_point: @@ -75,6 +79,7 @@ def build_iso() -> Path: run_and_check(["mcopy", "-i", image_name.as_posix(), kernel_binary_path.as_posix(), "::/EFI/AXLE/KERNEL.ELF"]) run_and_check(["mcopy", "-i", image_name.as_posix(), fs_server_path.as_posix(), "::/EFI/AXLE/FS_SERVER.ELF"]) run_and_check(["mcopy", "-i", image_name.as_posix(), initrd_path.as_posix(), "::/EFI/AXLE/INITRD.IMG"]) + run_and_check(["mcopy", "-i", image_name.as_posix(), ap_bootstrap_path.as_posix(), "::/EFI/AXLE/AP_BOOTSTRAP.BIN"]) return image_name @@ -167,6 +172,10 @@ def main(): # Build the Rust kernel libraries build_kernel_rust_libs() + # Build the AP bootstrap, which needs to be outside the kernel proper + # TODO(PT): Render this based on the target architecture + run_and_check(["nasm", "-f", "bin", (_REPO_ROOT / "ap_bootstrap.s.x86_64.arch_specific").as_posix(), "-o", (_REPO_ROOT / ".compiled_ap_bootstrap").as_posix()]) + # Build the C and assembly portions of the kernel, and link with the Rust libraries run_and_check(["make"])