Hi, I've been working on a very simple bootloader that should run off a usb flash drive or similar attached device. All it does is load the next 1024 bytes off an unformatted disk into ram, and jump to it.
The issue I'm having is that I can't get it to run on real hardware. I make the image, flash it to the thumb drive with flashnul, and can then boot the flash drive in QEMU and it works fine. However, if I reboot and try it for real, The bootloader boots, copies the data (i think), and then hangs.
I have used both INT 13h AH=02h (read sectors) and INT 13h AH=42h (extended read sectors), and can't get either to work on real hardware. Any advice would be most helpful.
Here's my bootloader code (it's not really my code, its more or less lots of copy pastas from a bunch of other forums). The rest of the project should be attached.
I am using NASM for my assembly (should work with YASM aswell)
At the moment on real HW it prints A and stops. No indication of failure - it just halts.
Code:
[bits 16]
[org 0x7C00]
; Prepare Stack Segment
mov sp, 0x7A00 ; Move Stack into SP
mov bp, sp ; Store current Stack Base
; print an A to make sure the bootloader actually loaded
mov ah, 0x0E ; Print Character to Screen
mov bh, 0x00 ; No Page Numbering
mov bl, 0x07 ; White Text, Black Background
mov al, 65 ; Print Letter A
int 0x10
; Check if INT0x13 Extentions are Supported
mov ah, 0x41 ; Set Function 0x41
mov word bx, 0x55AA
push dx ; Save old Drive Identifier
;mov dl, 0x80 ; Load 'Active' ID Into dl, commented out to keep bios setting of dl (should be active drive)
int 0x13 ; Call Interupt
jc short unsupported ; If Extentions aren't Supported, Jump
xor ax, ax
add ax, 1 ; clear carry flag
mov si, DAPS ; Load DAPS Struct to DS:SI
mov ah, 0x42 ; Read Functions (AL Ignored)
;mov dl, 0x80 ; Active Boot Drive
int 0x13
jc short unsupported ; If something goes wrong...
;
mov dx, 0
mov bx,0x0080 ; set up the memory offset so DS:DX is 0x0080:0x0000 (so the next program can run from org 0x0000)
push bx
pop ds ; sets the offset for the program just read, so it runs from org 0x0000
jmp 0x0080:0x0000 ; hopefully jump to the code we just loaded into ram
;
unsupported:
mov ah, 0x0E ; Print Letter F, Gives Indication of Failure
mov bh, 0x00
mov bl, 0x07
mov al, 70
int 0x10
jmp $ ; hang on error
; Disk Address Packet Structure (for extended read)
DAPS: db 0x10 ; Size of Structure (16 bytes, always this for DAPS)
db 0 ; Always 0
db 2 ; Number of Sectors to Read (2x512)
db 0 ; Always 0
dw 0x0800 ; Target Location for Reading To (0x0800 = 0x0080:0x0000)
dw 0 ; Page Table (0, Disabled)
dd 1 ; Read from 2nd block (code I want to load)
dd 0 ; Large LBAs, dunno what this does
times 510-($-$$) db 0 ; fill rest of bootloader with 0s
db 0x55, 0xAA ; Add Boot Record Signature
; Code that I want to run is stuck on here after compilation (compiled as separate image and added with copy /b)
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.