Before addressing the possible cause of the problem, I would like to recommend using the
.set or
.equ directives to give names to all the magic numbers you are using now. Her are the relevant ones I used in Verbum (my own practice boot loader) converted to AT&T syntax (at least, I hope I did that correctly):
Code: Select all
.equ stage2_base, 0x2000 # the segment:offset to load
.equ stage2_offset, 0x0000 # the second stage into
.equ DBIOS, 0x13 # BIOS interrupt vector for disk services
.equ disk_reset, 0x00 # disk reset service
.equ disk_read, 0x02 # disk read service
.equ tries, 0x03 # number of times to attempt to access the FDD
.equ reset_failure, 0x01 # error code returned on disk reset failure
.equ read_failure, 0x02 # error code returned on disk read failure
.equ stage2_cyl , 0x00 # cylinder to read from
.equ stage2_head, 0x00 # head to read from
.equ start_sector, 0x02 # sector to start reading at
.equ num_sectors, 0x01 # number of sectors to read
When applied to your code, it would be:
Code: Select all
# Reading sector...
mov $disk_read, %ah # Second sector.
mov $num_sectors, %al
mov $stage2_cyl, %ch
mov $start_sector, %cl
mov $stage2_head, %dh
mov $0x00, %dl
mov $stage2_base, %bx # Address where sector will be loaded.
mov %bx, %es
mov $stage2_offset, %bx
readsector:
int $DBIOS
jc error
mov $stage2_base, %ax
mov %ax, %es
As for the error, I suspect it is because you are hard-coding the drive identifier rather than getting it from the initial value that the BIOS put into %dl on loading - you can't say for certain which drive it will be, but AFAIK that ID number will
never be zero. If you can't be certain that the value of DL hasn't been changed before you use it, you should save the value in a temporary data address for retrieval.
Code: Select all
# in your start-up code after you have your
# seg registers set but before anything else
movb $dl, (bootdrv)
# then replace
# mov $0x00, %dl
# with
movb (bootdrv), %dl
# add this after the end of the code to define some storage
.section .bss
.lcomm bootdrv, 1
.section
I can't say for certain if this will fix it or not, but I think it would be advisable.