Skip to content

Commit

Permalink
[Kernel] Compile an AP bootstrap program and include it in the boot i…
Browse files Browse the repository at this point in the history
…mage
  • Loading branch information
codyd51 committed Jan 8, 2023
1 parent a101a13 commit 785ebcf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
25 changes: 16 additions & 9 deletions ap_bootstrap.s.x86_64.arch_specific
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions scripts/build_os_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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"])

Expand Down

0 comments on commit 785ebcf

Please sign in to comment.