; vi:filetype=nasm ts=8 sts=8 sw=8:
bits 16
- org 7c00h
+ section .boot
-STACKTOP equ 7c00h
+STACKTOP equ 7b00h
+DRIVENO_ADDR equ 7bf0h
LOADADDR equ 7e00h
+ extern _boot2_size
+
start:
cli
; setup stack and the rest of the segment registers
mov gs, ax
; dl: drive number, save it
- mov [driveno], dl
+ mov [DRIVENO_ADDR], dl
call get_drive_chs
mov si, newline_str
call putstr
- ; load main program
+ ; load the second stage boot loader and jump there
mov bx, LOADADDR ; es:bx <- destination
- mov cx, BINSIZE
+ mov cx, _boot2_size
add cx, 511
shr cx, 9 ; cx <- binsize in sectors
mov [binsize_sect], cx
get_drive_chs:
push es
mov ah, 8
- mov dl, [driveno]
+ mov dl, [DRIVENO_ADDR]
xor di, di
int 13h
pop es
; read_sector expects a linear sector number in cx, converts it to CHS
; and loads the sector at es:bx
read_sector:
+ push bx ; save dest offset
mov byte [read_retries], 3
.read_try:
push cx ; save linear sector number
; ah = 2 (read), al = 1 sectors
mov ax, 0201h
- mov byte dl, [driveno]
+ mov byte dl, [DRIVENO_ADDR]
int 13h
jnc .success
call putchar
pop cx
+ pop bx
ret
abort_read:
ret
+ global sect_per_track
sect_per_track: dw 18
+ global num_cylinders
num_cylinders: dw 80
+ global num_heads
num_heads: dw 2
+ global heads_mask
heads_mask: db 1
read_retries: db 0
-driveno: db 0
binsize_sect: dw 0
rderr_str: db 'read error',13,10,0