I have a few questions regarding my bootloader, that I've put together.
Code: Select all
BITS 16
ORG 0x7C00
jmp Skip
nop
;****************************************;
; ----- OEM Parameter block, FAT32 ----- ;
;****************************************;
BS_OEMName db "MSDOS5.0" ; Must be 8 bytes
; ----- FAT32 Bios Parameter Block ----- ;
BPB_BytsPerSec dw 512
BPB_SecPerClus db 8
BPB_RsvdSecCnt dw 496
BPB_NumFATs db 2
BPB_RootEntCnt dw 0
BPB_TotSec16 dw 0
BPB_Media db 248
BPB_FATSz16 dw 0
BPB_SecPerTrk dw 6
BPB_NumHeads dw 255
BPB_HiddSec dd 128 ; lHiddenSecs
BPB_TotSec32 dd 3948288
;*******************************************;
; ----- Extended BIOS Parameter Block ----- ;
;*******************************************;
BPB_FATSz32 dd 3848
BPB_ExtFlags dw 0 ; Bits 0-3 = Active FAT, 7 = !FAT
BPB_FSVer dw 0
BPB_RootClus dd 2
BPB_FSInfo dw 1
BPB_BkBootSec dw 6
; Next three values are represented as "BPB_Reserved" - 12bytes in length
BytesPerCluster dd 0 ;Reserved 1
CurrentCluster dd 0 ;Reserved 2
lDataSector dd 0 ;Reserved 3
;END Re-check
BS_DrvNum db 128
BS_Reserved1 db 0
BS_BootSig db 41
BS_VolID dd 304085088
BS_VolLab db "NO NAME "
BS_FilSysType db "COPYHERE"
; Booting process
Skip:
; ----- Adjust registers ----- ;
cli
xor ax, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
; Clears the screen!
mov ah, 0Fh
int 10h
mov ah, 00h
int 10h
; ----- Display load message ----- ;
mov si, msgStart
call print_s
call print_nl
; Calculate start of DATA region - FirstDataSector
mov ax, [BPB_NumFATs]
mul WORD[BPB_FATSz32]
add ax, [BPB_RsvdSecCnt]
; RootDirSectors on FAT32 is always 0! No need, to include it in calculations ...
mov WORD[FirstDataSector], ax ; Stores calculated value to FirstDataSector for later use
call LBACHS ; Run function to calculate CHS for disk reading
; print calculated values
; prints cylinder
mov si, msgCylinder
call print_s
mov ax, WORD[aCylinder]
call print_int
call print_nl
; prints head
mov si, msgHead
call print_s
xor ax, ax
mov al, BYTE[aHead]
call print_int
call print_nl
; prints track
mov si, msgTrack
call print_s
xor ax, ax
mov al, BYTE[aTrack]
call print_int
call print_nl
; prints sector
mov si, msgSector
call print_s
xor ax, ax
mov al, BYTE[aSector]
call print_int
call print_nl
; Reads a single testing sector from disk
call dReset
mov ax, 0x8c00 ; We can't set es register directly
mov es, ax ; Therefore we set it in ax first
xor ax, ax
xor bx, bx
xor cx, cx
xor dx, dx
mov ah, 02h
mov al, 1
mov ch, BYTE[aTrack]
mov cl, BYTE[aSector]
mov dh, BYTE[aHead]
mov dl, [BOOT_DRIVE]
jc .error
mov ax, [0x8c00]
call print_int
call print_nl
; Print reboot message... Freeze the system.
call reboot
jmp $
hlt
.error:
mov si, napakaBranja
call print_s
call print_nl
call reboot
jmp $
hlt
napakaBranja db "Napaka branja!", 0
LBACHS:
xor dx, dx ; prepare dx for division (has to be cleaned - remainder is stored here)
div WORD [BPB_SecPerTrk] ; calculates ax / SectorsPerTrack
inc dl ; adjust for sector 0
mov BYTE [aSector], dl ; store SectorToRead
xor dx, dx ; prepare dx for another division
div WORD [BPB_NumHeads] ; divides ax with number of heads
mov BYTE [aHead], dl ; stores with which head to read choosen sector
mov BYTE [aTrack], al ; stores on which track selected sector is located.
xor dx, dx
mov ax, [FirstDataSector]
div WORD[BPB_NumHeads]
xor dx, dx
div WORD[BPB_SecPerTrk]
mov WORD[aCylinder], ax
ret
;*********************************
;*** Preveri kej je s headi!! ***
;*********************************
msgHead db "Head: ", 0
msgTrack db "Track: ", 0
msgSector db "Sector: ", 0
msgCylinder db "Cylinder: ",0
aHead db 0x00
aTrack db 0x00
aSector db 0x00
aCylinder dw 0x00
;**********************************;
; ----- Predefined functions ----- ;
;**********************************;
; Printing functions
print_s:
lodsb ; get next character
or al, al ; check, if null-terminator
jz f_end ; yes? -> printing done
call print_char ; Print character function
jmp print_s ; repeat until null-terminator found
print_nl:
mov si, msgNewLine
call print_s
ret
print_int: ; Breaks the number in ax register for printing
mov bx,10
xor cx,cx
@a:
xor dx,dx
div bx
inc cx
push dx
and ax,ax
jnz short @a ; Jumps to previous @
@b:
pop ax
add al,"0"
call print_char
loop @b ; Jumps to previous @
ret
print_char: ; Function to print single character on screen
mov ah, 0eh ; Prepare registers for character printing
push bx
xor bh, bh
mov bl, 0fh
int 10h ; Call BIOS interrupt
pop bx
ret
f_end: ; Return back upon function completion
ret
; Other function
press_any_key:
mov ah, 0 ; wait for key
int 016h
ret
reboot:
mov si, msgRestart
call print_s
call press_any_key
db 0EAh ; Jump to FFFF:0000 (reboot)
dw 0000h
dw 0FFFFh
; Disk reading functions
dReset:
mov ah, 0 ; reset storage device
mov dl, [BOOT_DRIVE] ; drive 0 is active storage
int 0x13 ; call BIOS reset interrupt
jc dReset ; If CF (carry flag) carries error, try to reset again.
ret
; ----- Data ----- ;
BOOT_DRIVE db 80h ; 80h for 1st HDD, 00h for 1st floppy
msgStart db "Boot sequence started...", 0x00
msgRestart db "Reboot...", 0x00
msgProgress db ".", 0x00
msgNewLine db 0Dh, 0Ah
FirstDataSector dw 0x0000
TIMES 510-($-$$) db 0
DW 0xAA55
Well, I'm lost. Any help appreciated.