sectalign off

; This program expects two external macros:
; STAGE3, a path to the stage3 binary
; STAGE2_SECTOR, the location of stage 2
;   on the disk, in 512-byte sectors.
; On a gpt disk, this is probably 34.

; Stage 1 is MBR code, and should fit in LBA 0
; (512 bytes). Layout is as follows:
; (Format is `offset, length: purpose`)
; 0, 424: x86 boot code
; 440, 4: Unique disk signature
; 444, 2: unknown
; 446, 16*4: Array of four legacy MBR records
; 510, 2: signature 0x55 0xAA
; 512 to end  of logical block: reserved
; 
; See https://uefi.org/specs/UEFI/2.10/05_GUID_Partition_Table_Format.html

ORG 0x7C00
SECTION .text

; stage 1 is sector 0, loaded into memory at 0x7C00
%include "stage1.asm"

; Stage 1 is at most 440 bytes
times 440-($-$$) db 0
db 0xee

; Pad until 512
times 510-($-$$) db 0

; MBR signature.
; This isn't loaded into memory, it's
; only here for debugging.
db 0x55
db 0xaa

stage2:
    %include "stage2.asm"
    align 512, db 0
stage2.end:

; TODO: why? Stage 1 read limit?
; Can we make this smaller?
; The maximum size of stage2 is 4 KiB,
; This fill will throw an error if the subtraction
; is negative.
times (4*1024)-($-stage2) db 0

; LEGACY
; Pad to 0x13000
; This needs to match the value configured
; in the stage3 linker script
times (0x13000 - 0x7c00)-($-$$) db 0

stage3:
    %defstr STAGE3_STR %[STAGE3]
    incbin STAGE3_STR
    align 512, db 0
.end:

; TODO: why? Of the disk, or of memory?
; the maximum size of the boot loader portion is 384 KiB
times (384*1024)-($-$$) db 0