Skip to content

Commit

Permalink
dynamic number of sectors to load
Browse files Browse the repository at this point in the history
  • Loading branch information
metavee committed Jul 30, 2024
1 parent 7d0ec65 commit f895b97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ blinken: unpadded-bootable

build: build-dos padded-bootable

unpadded-bootable: build-bootloader build-stage2
unpadded-bootable: build-bootloader
cat {{bootloader_out}} {{stage2_out}} > {{boot_out}}

build-dos:
nasm -f bin -D DOS -o {{dos_out}} {{infile}} -l {{listing_out}}

build-bootloader:
nasm -f bin -o {{bootloader_out}} {{bootloader_in}}
build-bootloader: build-stage2
#!/bin/bash
SECTOR_SIZE=512
file_size=$(wc -c < "{{stage2_out}}")
num_sectors=$(( (file_size + SECTOR_SIZE - 1) / SECTOR_SIZE ))

nasm -f bin -DNUM_SECTORS=$num_sectors -o {{bootloader_out}} {{bootloader_in}}

build-stage2:
nasm -f bin -D BOOT -o {{stage2_out}} {{infile}} -l {{listing_out}}
Expand Down
2 changes: 1 addition & 1 deletion bootloader.asm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ start:
; Load the second sector from the disk
; Use the drive number in 'boot_drive'
mov ah, 0x02 ; BIOS read sector function
mov al, 0x02 ; Number of sectors to read
mov al, NUM_SECTORS ; Number of sectors to read (from preprocessor arg)
mov ch, 0x00 ; Cylinder number (0)
mov cl, 0x02 ; Sector number (1-based, so 2 means second sector)
mov dh, 0x00 ; Head number (0)
Expand Down

0 comments on commit f895b97

Please sign in to comment.