w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to transfer the control from my boot loader to the application located in hard drive

If you have access to the Logical Block Addressing extensions, then loading a sector into memory is much easier. You'd still be using the INT 0x13 interrupt, but with AH set to 0x42. You simply specify the starting sector index and the number of consecutive sectors you want to load and where.

Without implementing a file system, you must place the application at some known offset from the start of your disk image. Once loaded, you simply jump to the address you loaded the sectors to.

Getting a single detail wrong will triple fault the emulated CPU, so make sure you have a working print string function at hand.

The BIOS will load your boot loader from sector 0 to 0x7c00. You could simply place your application at some multiple of the sector size. Assuming a sector size of 512 bytes, then it should look something like this:

  • Sector 0 (offset 0): boot loader -> 0x7c00
  • Sector 1 (offset 512): application -> 0x7e00 or any address of your choosing

If you load your application to 0x7e00, then you just do jmp 0x0:0x7e00 to run it.

I don't know any tools for Windows to create the disk image, but you could always use the assembler to pad the offsets correctly if you want everything in the same file.

Since I have code from a boot loader I wrote some time ago, I might as well share some examples (NASM syntax):


ORG 0x7c00

    mov ah, 0x42 ; set to lba extended read
    mov dl, 0x80 ; first hard drive
    mov si, dap  ; address of disk address package

    int 0x13     ; execute

    jc .load_failed ; do something on failure

    jmp 0x0:0x7e00 ; jump to the destination address


; this is the disk address package used by the lba extensions
db 0x10   ; size of this package
db 0x0    ; reserved
dw 0x1    ; number of sectors to load
dd 0x7e00 ; destination address
dq 0x1    ; sector index to load

; pad to assumed sector size. this will overwrite the partition table
TIMES 510 - ($ - $$) db 0

; boot signature
dw 0xaa55

; either write your app here or concatenate a separate .bin file

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.