I quickly looked over your code a bit. You have a lot of redundant code as well as other minor errors.
For example, you pusha/popa before you call the disk code, which also pusha/popa as well.
Anyway, I think you need to eliminate the use of CHS and use LBA addressing. This way, you only have to increment a single 16-bit (32-bit) value for each sector. Then, and only then, at the time you call the INT 13h service, if needed, you convert LBA to CHS. Besides, if you are on a hard drive, you can eliminate the CHS altogether.
Code:
mov cur_lba, 2 ; starting LBA of (2nd stage) boot code
...
...
call load_boot_code
...
...
load_boot_code:
mov ax,cur_lba
cmp dl,80h
jae load_use_ext_services
call convert_ax_to_chs
mov es, ... address_to_load ...
jmp do_call_the_call
load_use_ext_services:
mov ah,42h
mov si, ... packet ...
do_call_the_call:
int 13h
Get the idea? I think this will help you eliminate errors and problems.
For another point, a boot sector gets written to the media once, and never changes until a clean format. Either way, it will always be for that format; floppy, hard drive, etc., and will always know that it is a floppy, hard drive, etc. Therefore, write your boot sector for that specific media type only. Then write another for the other media types.
Now, before someone gets all out of shape, you can write all of the media independent code in one file, then use %if/#if/.if directives to assembly the boot sector for a specific media.
For example:
Code:
... media independent code here ....
...
mov ax,starting_lba
call load_sectors
...
...
#ifdef FOR_FLOPPY
load_sectors:
; write code for floppy media here
ret
#endif
#ifdef FOR_HARD_DRIVE
load_sectors:
; write code for floppy media here
ret
#endif
This is what all of my boot sectors do. I have a single (some times two) file(s) for each file system format, but a single file for each media format. If I change how the floppy is read, all I have to do is re-assemble all other files...i.e.: re-build the project.
For an older version of my boot code, go to
https://github.com/fysnet/FYSOS/tree/master/boot for an example.
Ben
-
http://www.fysnet.net/osdesign_book_series.htm