(If you don't know just press Ctrl+Alt+2 on QEMU and enter the command xp /1c 0x7E00)
Code: Select all
[bits 16]
[org 0x7c00]
jmp 0:start
start:
mov ax, 0
mov ds, ax
mov es, ax
mov ss, ax
mov [driveNum], dl
mov sp, 0x7c00
jmp 0:clearCS
clearCS:
mov bx, 0x7e00
mov ax, 1
mov cx, 1
call loadSector
jmp $
;;; ======================================================================= ;;;
;;; IN:
;;; es:bx - buffer address
;;; ax - logical sector number (0 based)
;;; cx - number of sectors
;;;
loadSector:
pusha
;; reset floppy
push ax
.reset:
mov ah, 0
mov dl, [driveNum]
stc
int 0x13
jc .reset
pop ax
push cx ; save counter
;; get CHS args, ax has the logical sector number
call LBAToCHS
pop ax ; put counter in al
mov ah, 2
mov dl, [driveNum]
stc
clc
int 0x13
jc .reset
popa
ret
;;; ======================================================================= ;;;
;;; IN:
;;; ax - logical sector number
;;;
;;; OUT:
;;; ch - cylinder
;;; dh - head
;;; cl - sector
;;;
LBAToCHS:
push di
push bx
push dx
mov di, ax ;save lba number
;; store sector number in cl
mov dx, 0
mov bx, 18
div bx
inc dx
mov cl, dl
;; store cylinder number in ch
mov ax, 18
mov bx, 2
mul bx
mov bx, ax
mov dx, 0
mov ax, di
div bx
mov ch, al
;; store head number in dh
mov dx, 0
mov ax, di
mov bx, 18
div bx
mov dx, 0
mov bx, 2
div bx
mov dh, dl
pop bx
mov dl, bl
pop bx
pop di
ret
;;; ======================================================================= ;;;
driveNum: db 0
times 510-($-$$) db 0
db 0x55, 0xaa
db 'A'
and here is the code to build it on Linux:
Code: Select all
nasm -f bin boot.asm -o boot.bin || exit
dd if=/dev/zero of=boot.flp bs=1024 count=1440
dd conv=notrunc if=boot.bin of=boot.flp
qemu -fda boot.flp