foo
[eightysix] / boot / boot.asm
index 5b82c2d..96506de 100644 (file)
@@ -3,10 +3,9 @@
        bits 16
        section .bootsect
 
-extern _stage2_start
-extern _stage2_end
+extern _stage2_start_seg
+extern _stage2_size
 
-stacktop       equ 7b00h
 boot_driveno   equ 7b00h
 num_read_tries equ 7b06h       ; 2 bytes
 sect_pending   equ 7b08h       ; 2 bytes
@@ -28,21 +27,29 @@ cur_cyl             equ 7b14h       ; 2 bytes - current cylinder
 %%end: popf
 %endmacro
 
+; 5.25" 360K floppy
+BPB_DISK_SECTORS       equ 720
+BPB_TRACK_SECTORS      equ 9
+BPB_MEDIA_TYPE         equ 0fdh
+; 3.5" 1.44M floppy
+;BPB_DISK_SECTORS      equ 2880
+;BPB_TRACK_SECTORS     equ 18
+;BPB_MEDIA_TYPE                equ 0f0h
 
 bios_param_block:
        jmp start       ; 2 bytes
        nop             ; 1 byte
        ; start of BPB at offset 3
-       db "BSPL 0.1"   ; 03h: OEM ident, 8 bytes
+       db "86BOOT00"   ; 03h: OEM ident, 8 bytes
        dw 512          ; 0bh: bytes per sector
        db 1            ; 0dh: sectors per cluster
        dw 1            ; 0eh: reserved sectors (including boot record)
        db 2            ; 10h: number of FATs
        dw 224          ; 11h: number of dir entries
-       dw 2880         ; 13h: number of sectors in volume
-       db 0fh          ; 15h: media descriptor type (f = 3.5" HD floppy)
+       dw BPB_DISK_SECTORS     ; 13h: number of sectors in volume
+       db BPB_MEDIA_TYPE       ; 15h: media descriptor type (f0 = 3.5" HD floppy)
        dw 9            ; 16h: number of sectors per FAT
-       dw 18           ; 18h: number of sectors per track
+       dw BPB_TRACK_SECTORS    ; 18h: number of sectors per track
        dw 2            ; 1ah: number of heads
        dd 0            ; 1ch: number of hidden sectors
        dd 0            ; 20h: high bits of sector count
@@ -58,12 +65,12 @@ start:
        xor ax, ax
        mov ds, ax
        mov es, ax
-       mov ss, ax
-       mov gs, ax
-       mov fs, ax
        jmp 00:.setcs
 .setcs:
-       mov sp, stacktop
+       ; put the stack high
+       mov ax, 0x7f00
+       mov ss, ax
+       xor sp, sp
        mov [boot_driveno], dl
 
        ; query sectors per track
@@ -84,20 +91,15 @@ start:
        mov word [num_heads], 2
 .querydone:
 
-; load the rest of the code at 7e00h
-       mov ax, _stage2_end
-       sub ax, _stage2_start
+       ; load the rest of the code high
+       mov ax, _stage2_size
        add ax, 511
        mov cl, 9
        shr ax, cl
        inc ax
        mov [sect_pending], ax
-       mov ax, _stage2_start
-       shr ax, 1
-       shr ax, 1
-       shr ax, 1
-       shr ax, 1
-       mov es, ax      ; destination segment 7e0h to allow loading up to 64k
+       mov ax, _stage2_start_seg
+       mov es, ax      ; destination segment
        mov word [destptr], 0
        mov word [start_sect], 1        ; start from sector 1 to skip boot sector
        mov word [cur_cyl], 0
@@ -170,10 +172,15 @@ start:
        add [destptr], ax
        jnz .rdloop
 
-       ; loaded sucessfully, reset es back to 0 and jump
-.done: xor ax, ax
+       ; loaded sucessfully, load segment registers and jump
+.done: mov ax, _stage2_start_seg
+       mov ds, ax
        mov es, ax
-       jmp _stage2_start
+       push ax
+       xor ax, ax
+       push ax
+       retf
+
 
 .fail: add sp, 2       ; clear num_sect off the stack
        dec word [num_read_tries]