Bootsector FATAL: INT18 BOOT ERROR

0

Cannot get my FAT32 boot sector to work. Please help me. I have tried everything from looking through the code to testing it in virtualbox. When I run it in virtualbox I get this error: FATAL: INT18 BOOT ERROR. Here is the code:

BITS 16
ORG 0x7C00
jmp START

OEM_ID db “PARADIGM"
BytesPerSector dw 0x0200
SectorsPerCluster db 0x08
ReservedSectors dw 0x0021
TotalFATs db 0x02
MaxRootEntries dw 0x0000
TotalSectorsSmall dw 0x0000
MediaDescriptor db 0xF8
SectorsPerTrack dw 0x003F
SectorsPerHead dw 0x0080
HiddenSectors dd 0x0000003F
TotalSectorsBig dd 0x0040994
BigSectorsPerFAT dd 0x00000778
SectorsPerFAT dd 0x0000101F
Flags dw 0x0000
FSVersion dw 0x0000
RootDirectoryStart dd 0x00000002
FSInfoSector dw 0x0001
BackupBootSector dw 0x0006
times 13 db 0x00
DriveNumber db 0x00
db 0x00
Signature db 0x29
VolumeID dd 0x1F040FD5
VolumeLabel db "PARADIGM_BOOT"
SystemID db "FAT32"

START:
cli
mov ax, 0x0000
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ax, 0x0000
mov ss, ax
mov sp, 0x0000
sti
mov si, msgLoading
call DisplayMessage
mov cx,  WORD[SectorsPerCluster]
xor ax, ax
mov al, BYTE [TotalFATs]
mul WORD[BigSectorsPerFAT]
add ax, WORD [ReservedSectors]
mov WORD [datasector], ax
xor ax, ax
mov ax, WORD [RootDirectoryStart]
call ClusterLBA
mov bx, 0x0200
call ReadSectors
mov cx, WORD [0x0080]
mov di, 0x0200
.LOOP:
push cx
mov cx, 0x000C
mov si, ImageName
push di
rep cmpsb
pop di
je LOAD_FILE
pop cx
add di, 0x0020
loop .LOOP
jmp FAILURE

LOAD_FILE:
mov si, msgCRLF
call DisplayMessage
mov dx, WORD [di + 0x001A]
mov WORD [cluster], dx
mov ax, 0x0100
mov es, ax
mov bx, 0
xor cx, cx
mov cl, BYTE[SectorsPerCluster]
mov ax, WORD[cluster]
call ClusterLBA
call ReadSectors
jmp DONE

DONE:
mov si, msgCRLF
call DisplayMessage
push WORD 0x0200
push WORD 0x0000
retf

FAILURE:
mov si, msgFailure
call DisplayMessage
mov ah, 0x00
int 0x16
int 0x19

DisplayMessage:
lodsb
or al, al
jz .DONE
mov ah, 0x0E
mov bh, 0x00
mov bl, 0x07
int 0x10
jmp DisplayMessage
.DONE:
ret

ReadSectors:
.MAIN:
mov di, 5
.SECTORLOOP:
push ax
push bx
push cx
call LBACHS
mov ah, 0x02
mov al, 0x01
mov ch, BYTE [absoluteTrack]
mov cl, BYTE [absoluteSector]
mov dh, BYTE [absoluteHead]
mov dl, BYTE [DriveNumber]
int 0x13
jnc .SUCCESS
xor ax, ax
int 0x13
dec di
pop cx
pop bx
pop ax
jnz .SECTORLOOP
int 0x18
.SUCCESS:
mov si, msgProgress
call DisplayMessage
pop cx
pop bx
pop ax
add bx, WORD [BytesPerSector]
inc ax
loop .MAIN
ret

ClusterLBA:
sub ax, 0x0002
xor cx, cx
mov cl, BYTE [SectorsPerCluster]
mul cx
add ax, WORD [datasector]
ret

LBACHS:
xor dx, dx
div WORD [SectorsPerTrack]
inc dl
mov BYTE [absoluteSector], dl
xor dx, dx
div WORD [SectorsPerHead]
mov BYTE [absoluteHead], dl
mov BYTE [absoluteTrack], al
ret

absoluteSector db 0x00
absoluteHead db 0x00
absoluteTrack db 0x00

datasector dw 0x0000
cluster dw 0x0000
ImageName dw "BOOTLOAD.BIN"
msgLoading db 0x0D, 0x0A, "Loading Boot Image", 0x0D, 0x0A, 0x00
msgCRLF db 0x0D, 0x0A, 0x00
msgProgress db ".", 0x00
msgFailure db 0x0D, 0x0A, "ERROR: Press Any Key to Reboot", 0x00

times 510-($-$$) db 0
dw 0xAA55´

I am using an iso specification. It seems as if it is not reading the sectors properly. I got the code from Amila Surendra

assembly
bootstrapper
asked on Stack Overflow Oct 5, 2012 by gabemai • edited Oct 6, 2012 by gabemai

1 Answer

2

"Int 0x18" is normally used when the BIOS can't find anything to boot. Once upon a time it used to start a BASIC interpreter in ROM, but now it just displays a message.

The BIOS checks to see if the first sector of the device can be read and if it contains the magic signature 0xAA55 at offset 0x01FE in the sector. There are no other requirements - the rest of the sector could be full of random bytes that causes the computer to crash and the BIOS won't care and will execute it (and won't display the "Int 0x18" message).

Your code does include the magic signature at offset 0x01FE; therefore the problem is not your code. The problem is likely to be how you've installed your boot sector into a disk image or how you've configured the emulator.

Things to check:

1) The emulator is being told where to find the disk image (e.g. and isn't trying to boot something completely different or isn't being told to boot from a disk that doesn't exist)

2) The emulator is being told to boot from whichever disk drive you set the disk image up as (e.g. your not trying to boot from a floppy when the boot sector is on a hard disk or something)

3) The disk image is in the format that the emulator is expecting. Most emulators support several different disk image formats (VDI, VHD, etc). If the disk image is in one format (e.g. a fixed size image containing raw sector data only) but the emulator thinks it's in a different format (e.g. VDI) then it can cause problems.

4) The boot sector is installed correctly in the disk image (maybe consider using a tool like "hexdump" to check the first sector of the disk image). This might include installing your code as the first sector of a partition where there is nothing in the first sector of the disk (see partitioning info below).

Future Notes:

Your BPB ("BIOS Parameter Block") looks like it's intended for a hard disk (not a floppy disk). Hard disks come in different sizes (normally you can't hard-code things like "sectorsPerCylinder") which means that normally you need to write a special utility to detect the correct values, adjust the values in the BPB, then install the modified boot sector.

In addition, hard disks are normally partitioned. The BIOS (which doesn't know anything about partitions) loads and starts the first sector on the disk, and the first sector (typically called an MBR or Master Boot Record) contains code that checks the partition table for an "active" partition and loads the first sector of that partition (your boot sector). Also note that a partition may be split into more partitions; which means that all boot sectors for hard drives should have a partition table at offset 0x01BE (not just the MBR). Of course because the BIOS doesn't know about partitions it is technically possible to have an unpartitioned hard disk.

answered on Stack Overflow Oct 6, 2012 by Brendan

User contributions licensed under CC BY-SA 3.0