%%end: popf
%endmacro
+BPB_NUM_HEADS equ 2
; 5.25" 360K floppy
BPB_DISK_SECTORS equ 720
BPB_TRACK_SECTORS equ 9
db BPB_MEDIA_TYPE ; 15h: media descriptor type (f0 = 3.5" HD floppy)
dw 9 ; 16h: number of sectors per FAT
dw BPB_TRACK_SECTORS ; 18h: number of sectors per track
- dw 2 ; 1ah: number of heads
+ dw BPB_NUM_HEADS ; 1ah: number of heads
dd 0 ; 1ch: number of hidden sectors
dd 0 ; 20h: high bits of sector count
db 0 ; 24h: drive number
.setcs:
mov sp, _bootsect_start ; temp stack below our relocated address
+ test dl, 80h ; if high bit is set, it's a hard disk
+ jz .usebpb
+
; query sectors per track
mov ah, 8 ; get drive parameters call, dl already has the drive
xor di, di
int 13h
- jc .queryfail
+ jc .usebpb
and cx, 3fh
mov [sect_per_track], cx
mov cl, 8
inc dx
mov [num_heads], dx
jmp .querydone
-.queryfail:
- ; in case of failure, try 18 sectors per track, 2 heads
- mov word [sect_per_track], 18
- mov word [num_heads], 2
+.usebpb:
+ ; for hard disks and if the call fails, use the BPB values
+ mov word [sect_per_track], BPB_TRACK_SECTORS
+ mov word [num_heads], BPB_NUM_HEADS
.querydone:
- ; load the rest of the code high
+ ; load the rest of the code high [sect = (_kern_size + 511) / 512]
mov ax, _kern_size
add ax, 511
mov cl, 9
shr ax, cl
- inc ax
mov [sect_pending], ax
mov ax, _kern_start_seg
mov es, ax ; destination segment
push dx
push si
call print_hex_word
- mov ax, str_rdtrack2
+ mov ax, str_colon
call printstr
mov ax, [cur_cyl]
call print_hex_byte
call printstr
mov ax, [start_sect]
call print_hex_byte
+ mov ax, str_rdtrack4
+ call printstr
+ mov ax, es
+ call print_hex_word
+ mov ax, str_colon
+ call printstr
+ mov ax, [destptr]
+ call print_hex_word
mov ax, str_newline
call printstr
pop si
; loaded sucessfully, load segment registers and jump
.done: xor ax, ax
- mov ds, ax
mov es, ax
push ax
mov ax, _kern_start
.hexdig_tab:
db "0123456789abcdef"
-str_rdtrack2 db " from ",0
str_rdtrack3 db "/",0
-str_load_fail db "Failed to load kernel!",0
+str_rdtrack4 db "->",0
+str_colon db ":",0
+str_load_fail db "Failed!"
str_newline db 13,10,0
times 510-($-$$) db 0