Page 1 of 1
Read Usb from Mbr
Posted: Mon Jan 18, 2010 10:26 pm
by paulqddinh
Hi all,
I'm trying to write an OS booting from USB.
My MBR is loaded fine but I don't know how to
load the kernel from Usb.
I tried to use int 13h but it didn't work.
Any other way to read USB content from MBR?
(x86 assembly code pls)
Many thanks
Re: Read Usb from Mbr
Posted: Tue Jan 19, 2010 5:15 am
by XanClic
paulqddinh wrote:I tried to use int 13h but it didn't work.
What do you mean with that? int 13h works well for me. The BIOS emulates the USB device as a floppy disk or a hard disk via int 13h (depending on the size, I think).
And I don't think there's another easy way to boot from USB. Of course you could reserve some sectors after the MBR and write a full USB driver there but I don't suggest this at all. Check your int 13h code first because that works well for me (and for GRUB, too).
Re: Read Usb from Mbr
Posted: Tue Jan 19, 2010 7:18 am
by paulqddinh
tkx xanclic, i agree that usb driver cant be < 512byte
help me check whether my code below is ok?
Code: Select all
mov ah,2 ;to read sector
mov al,1 ;read 1 sector
mov dl,80h ;first hard disk
mov dh,0 ;head 0
mov ch,0 ;cylinder 0
mov cl,1 ;sector 1 (1 of 1 to 63)
mov ax,1000h ;read to 1000:0000, second 64K segment
mov es,ax
xor bx,bx
int 13h
my signature is my PC features.
Re: Read Usb from Mbr
Posted: Tue Jan 19, 2010 7:35 am
by Combuster
load the kernel from Usb.
Do you see what I see?
Oh and, you may want to use the value in DL that you get when your bootloader is called. The bios provides the right drive number for you.
Re: Read Usb from Mbr
Posted: Tue Jan 19, 2010 8:26 pm
by paulqddinh
tkx for the tip of value of DL
when my Mbr (on Usb) is loaded by Bios, DL = 80h (already checked on real machine)
that means my Usb is considered as first HDD (80h)
now I read by int 13h func 42h, but i dont know if this DAP is correct?
Code: Select all
dap: db 10h ;size of Dap
db 0 ;0
dw 1 ;1 sector
dw 0 ;offset 0000h
dw 1000h ;segment 1000h
dq 0 ;start from sector 0 (re-read Mbr, just to verify)
Re: Read Usb from Mbr
Posted: Wed Jan 20, 2010 6:41 am
by egos
paulqddinh wrote:help me check whether my code below is ok?
Code: Select all
mov ah,2 ;to read sector
mov al,1 ;read 1 sector
...
mov ax,1000h ;read to 1000:0000, second 64K segment
mov es,ax
xor bx,bx
int 13h
Do you really want to call subfunction 10h?
Try this:
mov bx,1000h / mov es,bx
now I read by int 13h func 42h, but i dont know if this DAP is correct?
See EDD Spec.
Re: Read Usb from Mbr
Posted: Wed Jan 20, 2010 7:21 am
by paulqddinh
oh YESS egos,
my terrible mistake
, i changed function number AH in AX
hm
tkx tkx
i can load my kernel now, thx guys