Over the past week, I have been developing a simple OS for training purposes and ... "fun." VirtualBox and NASM in tow, I really started very well. In the end, I decided that I also wanted to develop a bootloader (after I hit hard on a 512-byte wall) by including the infamous Brokenthorn tutorial , before booting from file systems.
With some HexFiend frauds and some clean FAT16 images, I ended up getting BPB. With some additional assembly assemblers (the basis is the Brokenthorn tutorial, part 6 ), I also got a file upload that works with my bootloader, which downloads an aptly-named βbootβ file from my virtual disk (made using dd if = / dev / zero of = boot.img bs = 512 count = 2880)
So what is the problem? This is what I see when I boot to the actual hardware via a USB drive (in this case, / dev / disk 3, where the compiled file is boot.bin):
dd bs=512 count=1 if=compiled/boot.bin of=/dev/disk3
Here is the expected result (in VirtualBox):
Compared to the actual output (on an old laptop)
'-' indicates a sector is being loaded '_' indicates a sector was loaded '!' indicates all of the desired sectors were loaded properly 'R' indicates a read error 'T' indicates the FAT table is being loaded 'D' indicates the FAT table was loaded properly 'F' means the file is being located (or Found, hence the F) 'L' means the file is being loaded
(I would use actual debug messages, but the 512 byte limit is pretty terrible.)
Thus, the difference is that one is a USB drive and the other is a virtual diskette. They both have the same information uploaded to everyone, including BPB. However, one works and the other does not. Here is the bulk of my code to load the sector (using ah 02h / int 13h, which I heard worked correctly for USB):
ReadSectors: mov di, 0x0005 ; How many times should we retry the read? ReadSectors.loop: ; DEBUG push ax mov ah, 0eh mov al, '-' int 10h pop ax push ax push bx push cx call LBAToCHS mov ah, 02h ; Set the interrupt to the ; 'read sector' function mov al, 1 ; Only read one sector mov ch, byte[chs.track] ; The track to read from mov cl, byte[chs.sector] ; The sector to read from mov dh, byte[chs.head] ; The head to read from mov dl, byte[_bpb.driveNumber] ; The drive to read from int 13h ; Call our 'disk IO' interrupt jnc ReadSectors.success ; If we successfully read the data, ; we don't have to try again mov ah, 00h ; Set the interrupt to the ; 'reset disk' function int 13h ; Call our 'disk IO' interrupt dec di ; Decrement our error counter pop cx pop bx pop ax jnz ReadSectors.loop ; Try again if we've failed jmp ReadSectors.fail ; RED ALERT
(The full source, including BPB, can be found on Pastebin ( http://pastebin.com/SeUm7xu6 )
I have still overcome a number of problems with the Assembly, but I have a dead end. I hope I can get past the bootloader and annotate the IO file as soon as possible.
Any suggestions would be greatly appreciated. Thanks in advance!