There is no magic to booting from usb drives, it very simple.
But you must understand one or two things or you will not get it to boot. that is unlike any other method of booting USB does check what its booting.
Eg: normaly the MBR or boot sector is just load into memory at a set address and jump to.
But in the case of USB boot, it checks for BPB, if it users hdd emulation it will boot with or without BPB, if it users floppy emulation and you do not have a BPB, it will NOT boot.
Here are two examples, the one with BPB should work with any emulation, if placed on the disk right (assemble with fasm)
With BPB
Code:
;************************************
; By Dex
; Assemble with fasm
; c:\fasm USB1.asm USB1.bin
;
;************************************
org 0x7C00
use16
Boot: jmp start
nop
;------------------------------------------;
; Standard BIOS Parameter Block, "BPB". ;
;------------------------------------------;
bpbOEM db 'MSDOS5.0'
bpbSectSize dw 512
bpbClustSize db 1
bpbReservedSec dw 1
bpbFats db 2
bpbRootSize dw 224
bpbTotalSect dw 2880
bpbMedia db 240
bpbFatSize dw 9
bpbTrackSect dw 18
bpbHeads dw 2
bpbHiddenSect dd 0
bpbLargeSect dd 0
;---------------------------------;
; extended BPB for FAT12/FAT16 ;
;---------------------------------;
bpbDriveNo db 0
bpbReserved db 0
bpbSignature db 41
bpbID dd 1
bpbVolumeLabel db 'BOOT FLOPPY'
bpbFileSystem db 'FAT12 '
;****************************
; Realmode startup code.
;****************************
start:
xor ax,ax
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0x7C00
mov si,Mesage1
call print
jmp $
;****************************
; print.
;****************************
print:
mov ah,0Eh
again1:
lodsb
or al,al
jz done1
int 10h
jmp again1
done1:
ret
Mesage1: db 'USB, with BPB works OK',0
;*************************************
; Make program 510 byte's + 0xaa55
;*************************************
times 510- ($-Boot) db 0
dw 0xaa55
Without BPB
Code:
;************************************
; By Dex
; Assemble with fasm
; c:\fasm USB2.asm USB2.bin
;
;************************************
org 0x7C00
use16
;****************************
; Realmode startup code.
;****************************
start:
xor ax,ax
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0x7C00
mov si,Mesage1
call print
jmp $
;****************************
; print.
;****************************
print:
mov ah,0Eh
again1:
lodsb
or al,al
jz done1
int 10h
jmp again1
done1:
ret
Mesage1: db 'USB, without BPB works OK',0
;*************************************
; Make program 510 byte's + 0xaa55
;*************************************
times 510- ($-start) db 0
dw 0xaa55