|
@@ -48,7 +48,7 @@ _start:
|
|
|
mov si, boot_msg
|
|
mov si, boot_msg
|
|
|
call print
|
|
call print
|
|
|
|
|
|
|
|
- call read_it
|
|
|
|
|
|
|
+ call read_sb
|
|
|
|
|
|
|
|
; get e820 memory
|
|
; get e820 memory
|
|
|
|
|
|
|
@@ -104,9 +104,9 @@ print:
|
|
|
ret
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
-; NOTE: QEMU's HD only supports LBA mode. So this MBR can't load it successfully. :-)
|
|
|
|
|
|
|
+; load the first block (4096 bytes)
|
|
|
|
|
|
|
|
-read_it:
|
|
|
|
|
|
|
+read_sb:
|
|
|
; we try LBA first because some disks supports wrong CHS. (bad sector per track)
|
|
; we try LBA first because some disks supports wrong CHS. (bad sector per track)
|
|
|
; if this boot disk doesn't support LBA mode, it should be a floppy.
|
|
; if this boot disk doesn't support LBA mode, it should be a floppy.
|
|
|
mov ax, 0x07e0
|
|
mov ax, 0x07e0
|
|
@@ -118,109 +118,8 @@ read_it:
|
|
|
|
|
|
|
|
call read_lba
|
|
call read_lba
|
|
|
|
|
|
|
|
- jnc using_lba
|
|
|
|
|
-
|
|
|
|
|
- ; so we use CHS to read now.
|
|
|
|
|
-
|
|
|
|
|
- mov ax, 0x07e0
|
|
|
|
|
- mov es, ax
|
|
|
|
|
-
|
|
|
|
|
- xor ax, ax
|
|
|
|
|
-
|
|
|
|
|
-.read_it:
|
|
|
|
|
- xor bx, bx
|
|
|
|
|
-
|
|
|
|
|
- inc ax
|
|
|
|
|
- mov cl, 1
|
|
|
|
|
-
|
|
|
|
|
- push ax
|
|
|
|
|
- push bx
|
|
|
|
|
-
|
|
|
|
|
- call read_chs
|
|
|
|
|
-
|
|
|
|
|
- pop bx
|
|
|
|
|
- pop ax
|
|
|
|
|
-
|
|
|
|
|
- mov bx, es
|
|
|
|
|
- add bx, 512 / 16
|
|
|
|
|
- mov es, bx
|
|
|
|
|
-
|
|
|
|
|
- cmp ax, 1024
|
|
|
|
|
-
|
|
|
|
|
- jb .read_it
|
|
|
|
|
-
|
|
|
|
|
-read_chs:
|
|
|
|
|
- pushaw
|
|
|
|
|
-
|
|
|
|
|
- ; LBA address in AX, and sectors count in CL, buffer in ES:BX
|
|
|
|
|
-
|
|
|
|
|
- ; LBA to CHS:
|
|
|
|
|
- ; TEMP = LBA / SECTORS_PER_TRACK
|
|
|
|
|
- ; SECTOR = (LBA % SECTORS_PER_TRACK) + 1
|
|
|
|
|
- ; CYLINDER = TEMP >> 1
|
|
|
|
|
- ; HEAD = TEMP & 1
|
|
|
|
|
-
|
|
|
|
|
- ; DIV: unsigned divide
|
|
|
|
|
- ; 12345 / 123:
|
|
|
|
|
- ; mov ax, 12345 : dividend
|
|
|
|
|
- ; mov bl, 123 : divisor
|
|
|
|
|
- ; AL: quotient
|
|
|
|
|
- ; AH: remainder
|
|
|
|
|
-
|
|
|
|
|
- ; 18: sectors per track for 1.44M floppy (and for my u-disk)
|
|
|
|
|
-
|
|
|
|
|
- ; save bx first
|
|
|
|
|
- push bx
|
|
|
|
|
-
|
|
|
|
|
- mov bl, 18
|
|
|
|
|
- div bl
|
|
|
|
|
-
|
|
|
|
|
- ; BIOS standard interrupt: 0x13 AH = 0x02: read disk in CHS mode
|
|
|
|
|
- ; AL: sectors count
|
|
|
|
|
- ; CH: cylinder number low
|
|
|
|
|
- ; CL: 0-5b: sector number, 6-7b: cylinder number (disk only)
|
|
|
|
|
- ; DH: head
|
|
|
|
|
- ; DL: driver
|
|
|
|
|
- ; ES:BX: buffer
|
|
|
|
|
-
|
|
|
|
|
- ; SECTOR = AH + 1
|
|
|
|
|
- ; but CL used to save sectors count, so we save it first.
|
|
|
|
|
- push cx
|
|
|
|
|
-
|
|
|
|
|
- ; we inc ah because it's shorter than inc cl
|
|
|
|
|
-
|
|
|
|
|
- inc ah
|
|
|
|
|
- mov cl, ah
|
|
|
|
|
-
|
|
|
|
|
- ; CH: CYLINDER = (LBA / SECTORS_PER_TRACK) >> 1
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- mov dh, al
|
|
|
|
|
- and dh, 1
|
|
|
|
|
-
|
|
|
|
|
- shr al, 1
|
|
|
|
|
- mov ch, al
|
|
|
|
|
-
|
|
|
|
|
- ; for 'push cx'
|
|
|
|
|
- pop ax
|
|
|
|
|
-
|
|
|
|
|
- ; for 'push bx'
|
|
|
|
|
- pop bx
|
|
|
|
|
-
|
|
|
|
|
- mov dl, [BOOTDRIVER]
|
|
|
|
|
-
|
|
|
|
|
- ; okay, now we read it
|
|
|
|
|
-
|
|
|
|
|
- mov ah, 2
|
|
|
|
|
- int 0x13
|
|
|
|
|
-
|
|
|
|
|
jc read_failed
|
|
jc read_failed
|
|
|
|
|
|
|
|
- popaw
|
|
|
|
|
-
|
|
|
|
|
- ret
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
using_lba:
|
|
using_lba:
|
|
|
; put message on screen
|
|
; put message on screen
|
|
|
mov si, lamsg
|
|
mov si, lamsg
|
|
@@ -249,10 +148,9 @@ using_lba:
|
|
|
|
|
|
|
|
call read_lba
|
|
call read_lba
|
|
|
|
|
|
|
|
- ; 1024 sectors = 512 KB,
|
|
|
|
|
- ; I think this is enough anytime for our kernel.
|
|
|
|
|
|
|
+ ; 8 sectors = 4KB
|
|
|
|
|
|
|
|
- cmp ax, 1024
|
|
|
|
|
|
|
+ cmp ax, 8
|
|
|
jb .read_loop
|
|
jb .read_loop
|
|
|
|
|
|
|
|
ret
|
|
ret
|