Read Usb from Mbr

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
paulqddinh
Posts: 9
Joined: Thu Jan 14, 2010 9:12 am
Location: Hanoi, VN

Read Usb from Mbr

Post 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
Asus EeePC 1000H/XP Pro
x86 Intel Atom N270 1.6GHz -- 1GB RAM
User avatar
XanClic
Member
Member
Posts: 138
Joined: Wed Feb 13, 2008 9:38 am

Re: Read Usb from Mbr

Post 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). :wink:
User avatar
paulqddinh
Posts: 9
Joined: Thu Jan 14, 2010 9:12 am
Location: Hanoi, VN

Re: Read Usb from Mbr

Post by paulqddinh »

tkx xanclic, i agree that usb driver cant be < 512byte #-o
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.
Asus EeePC 1000H/XP Pro
x86 Intel Atom N270 1.6GHz -- 1GB RAM
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Read Usb from Mbr

Post by Combuster »

Code: Select all

mov     dl,80h      ;first *hard disk*
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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
paulqddinh
Posts: 9
Joined: Thu Jan 14, 2010 9:12 am
Location: Hanoi, VN

Re: Read Usb from Mbr

Post 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)
Asus EeePC 1000H/XP Pro
x86 Intel Atom N270 1.6GHz -- 1GB RAM
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Read Usb from Mbr

Post 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.
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
paulqddinh
Posts: 9
Joined: Thu Jan 14, 2010 9:12 am
Location: Hanoi, VN

Re: Read Usb from Mbr

Post by paulqddinh »

oh YESS egos,
my terrible mistake :? , i changed function number AH in AX
hm
tkx tkx :P

i can load my kernel now, thx guys :P :P :P
Asus EeePC 1000H/XP Pro
x86 Intel Atom N270 1.6GHz -- 1GB RAM
Post Reply