Assembly bootloader
Posted: Sun Dec 01, 2013 6:40 am
So I'm trying to get a FAT32 bootloader to work but it doesn't go as planned.
One of the problems is that when i try to read the directory entries, it doesn't really work it reads all zeros.
here is the read code ( BTW I just started programming in assembly => I'm no good ) :
Which I'm calling with this code:
But with this code I ( think ) tested that it read all zeros into memory:
The output of that is: 0
But as stupid as I'm I think that a part of the problems is how i execute it:
1. Convert an iso that contains the bootloader, and one file ( the 2:nd stage bootloader I want to load ), to a virtualbox .vdi file.
2. Make that .vdi file as the hard drive for the virtual machine.
3. Boot from hard drive.
So my question: Why is it reading all zeros? Is the way I'm taking it to virtualbox that is the problem?
One of the problems is that when i try to read the directory entries, it doesn't really work it reads all zeros.
here is the read code ( BTW I just started programming in assembly => I'm no good ) :
Code: Select all
;*************************************************************************
; PROCEDURE ReadSectors
; Input: Valid Disk Address Packet
;*************************************************************************
ReadSectors:
.MAIN:
mov di, 0x0005 ; five retries for error
.SECTORLOOP:
pusha
mov ax, 0x0000
mov ds, ax
mov si, DAP.SIZE
mov dl, byte[DriveNumber]
mov ah, 0x42
xor al, al
int 0x13
jnc .SUCCESS
xor ax, ax
int 0x13
popa
dec di
jnz .SECTORLOOP
int 0x18
.SUCCESS:
popa
ret
Code: Select all
; compute location of the begining of the Data area and store in ax
mov al, BYTE [TotalFATs] ; Total number of FATs
mul WORD[BigSectorsPerFAT] ; Number of sectors for a FAT
add ax, WORD [ReservedSectors] ; Find the start of the Data area
mov WORD [datasector], ax ; Store the begining of the Data area
; read 1st data cluster into memory
mov ax, WORD[datasector]
mov Word[DAP.START], ax
mov Word[DAP.OFFSET], 0x7E00
mov Word[DAP.SEGMENT], 0x0000
mov Word[DAP.AMOUNT], 0x0001
call ReadSectors
Code: Select all
mov di, 0x7E00 + 0x20
mov ah, 0x0E
mov al, Byte[di]
add al, 48
int 0x10
hlt
jmp short $
Code: Select all
int 0x10
But as stupid as I'm I think that a part of the problems is how i execute it:
1. Convert an iso that contains the bootloader, and one file ( the 2:nd stage bootloader I want to load ), to a virtualbox .vdi file.
2. Make that .vdi file as the hard drive for the virtual machine.
3. Boot from hard drive.
So my question: Why is it reading all zeros? Is the way I'm taking it to virtualbox that is the problem?