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]
how to read from USB flash memory using BIOS
-
- Posts: 2
- Joined: Fri Nov 01, 2013 2:51 pm
how to read from USB flash memory using BIOS
Last edited by abdulmughn on Sat Nov 02, 2013 3:57 am, edited 1 time in total.
Re: how to read from USB flash memory using BIOS
Use code tags.
What architecture are you using?
Stack too small.
Code: Select all
mov cs, ax
Code: Select all
;setup the stack
mov bp,0x8000
mov sp,bp
If you have seen bad English in my words, tell me what's wrong, please.
-
- Posts: 2
- Joined: Fri Nov 01, 2013 2:51 pm
Re: how to read from USB flash memory using BIOS
thanks egos. my pc architecture is x86_64
Re: how to read from USB flash memory using BIOS
It was sarcasm meaning that there is no such command.
If you have seen bad English in my words, tell me what's wrong, please.
Re: how to read from USB flash memory using BIOS
1) As egos pointed out your stack may be a problem. Why not setting it to 0x7c00?
2) You should retry loading sector(s) a number of times before giving up.
3) Finally: Are you sure that your pc actually boots from usb device?
From my experience some quite modern pc's simply fail to boot from usb.
regards
M2004
2) You should retry loading sector(s) a number of times before giving up.
3) Finally: Are you sure that your pc actually boots from usb device?
From my experience some quite modern pc's simply fail to boot from usb.
regards
M2004