how to read from USB flash memory using BIOS
Posted: Fri Nov 01, 2013 4:43 pm
Hi, every one
excuse me, I need your help . since a week, I've been trying to write a simple boot-loader that would read some sectors from USB drive rather than boot sector(assuming these sectors contain the kernel), into somewhere in memory then print a word to indicate that it have successfully loading the kernel . i know the BIOS routine that could help me to read from HD is 13h after setting the required parameters. i have tried this way to read from USB flash memory but it failed. i don't know what's the problem . bellow i accompany may code. any help from you would be appreciated .
org 0x7c00
entry:
; zero out all segments registers
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov cs, ax
;setup the stack
mov bp,0x8000
mov sp,bp
mov [BOOT_DRIVE],dl
mov dh,2; number of sectors
mov bx,0x9000;es:bx is where the disk will be loaded
mov dl,[BOOT_DRIVE]
call diskLoad
mov bl,[0x9000]
call printHexa ;to print bl in order to ensure the correct loading
jmp $
diskLoad:
push dx
; prepare paramaters for " int 13h "
mov ah,0x02;
mov al,dh
mov ch,0x00
mov dh,0x00
mov cl,0x02
;call BIOS disk read interrupt
int 0x13
;check whether the disk got loaded
jc DISK_ERROR
pop dx
cmp dh,al
jne DISK_ERROR
ret
DISK_ERROR:
mov bx , DISK_ERROR_MSG
call printString
jmp $
BOOT_DRIVE db 0
DISK_ERROR_MSG db "Disk read error!",0
%include "diskload.asm"
%include "printHexa.asm"
%include "printString.asm"
;padding boot sector
size equ $ - entry
%if size+2 > 512
%error "code is too large for boot sector"
%endif
times (512 - size - 2) db 0
db 0x55, 0xAA
;fill the next two sectors
times 1024 db 0xAB[/color]
excuse me, I need your help . since a week, I've been trying to write a simple boot-loader that would read some sectors from USB drive rather than boot sector(assuming these sectors contain the kernel), into somewhere in memory then print a word to indicate that it have successfully loading the kernel . i know the BIOS routine that could help me to read from HD is 13h after setting the required parameters. i have tried this way to read from USB flash memory but it failed. i don't know what's the problem . bellow i accompany may code. any help from you would be appreciated .
org 0x7c00
entry:
; zero out all segments registers
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov cs, ax
;setup the stack
mov bp,0x8000
mov sp,bp
mov [BOOT_DRIVE],dl
mov dh,2; number of sectors
mov bx,0x9000;es:bx is where the disk will be loaded
mov dl,[BOOT_DRIVE]
call diskLoad
mov bl,[0x9000]
call printHexa ;to print bl in order to ensure the correct loading
jmp $
diskLoad:
push dx
; prepare paramaters for " int 13h "
mov ah,0x02;
mov al,dh
mov ch,0x00
mov dh,0x00
mov cl,0x02
;call BIOS disk read interrupt
int 0x13
;check whether the disk got loaded
jc DISK_ERROR
pop dx
cmp dh,al
jne DISK_ERROR
ret
DISK_ERROR:
mov bx , DISK_ERROR_MSG
call printString
jmp $
BOOT_DRIVE db 0
DISK_ERROR_MSG db "Disk read error!",0
%include "diskload.asm"
%include "printHexa.asm"
%include "printString.asm"
;padding boot sector
size equ $ - entry
%if size+2 > 512
%error "code is too large for boot sector"
%endif
times (512 - size - 2) db 0
db 0x55, 0xAA
;fill the next two sectors
times 1024 db 0xAB[/color]