How to access a pen drive *directly* using ports like HDs?

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
lup0
Posts: 5
Joined: Fri Mar 25, 2011 4:01 am
Location: India
Contact:

How to access a pen drive *directly* using ports like HDs?

Post by lup0 »

Hi all! :)

I have been recently working on my little hobbyist OS "wind". I have developed a simple bootloader using nasm (that initializes into protected mode before jumping to kernel) and using GCC toolchain to program the rest of my kernel and other drivers. I wrote it on a floppy image (an HD image later) and tested it on BOCHS emulator. Now the floppy option is only temporary and HD is too much yet #-o .
Since i have a couple of pendrives and my BIOS can boot from a pendrive i am thinking of writing the image to my pendrive and access the entire **8 GB** space there to keep all kernel and drivers stuff. I want to access and use all the space like on a hard disk!

Now the problem is that i have googled and searched the web about how to access the pendrive space using ports from a protected mode OS code like mine. But i didn't find even a single one! :( The ralf brown's interrupt requests ref (i think) provides a USB interrupts list but i am doing everything from protected mode code (i have setup protected mode interface for some vesa display in my code instead of using troublesome virtual mode or something!). So real mode interrupts as you can see are useless to me IN ALL WAYS. The only option from protected mode is using ports!

Someone please advice me on this problem. I have a Celeron D (Pentium 5 series) processor and note that **i am not using GRUB**. I use my own bootloader and it works perfectly. Also please tell me if i need to setup an MBR or something on the pendrive to access all the space..

regards
Everyday schedule: wake up >> eat >> write OS >> eat >> sleep ;-)
M2004
Member
Member
Posts: 65
Joined: Sun Mar 07, 2010 2:12 am

Re: How to access a pen drive *directly* using ports like HD

Post by M2004 »

You need to write an ehci driver in order to access usb from protected / long mode.

OS wiki provides good assistance:
http://wiki.osdev.org/USB

Regards
Mac2004
User avatar
lup0
Posts: 5
Joined: Fri Mar 25, 2011 4:01 am
Location: India
Contact:

Re: How to access a pen drive *directly* using ports like HD

Post by lup0 »

Hey thanks a lot! :) You like pointed me to a treasure!

Please don't think that I am asking to be spoon-fed but that wiki doc is **complete ref** including hardware stuff. I only wanted to know about the ports :|

I will surely read the doc and EHCI ref though; because I am going to need it eventually. Please tell me one thing more: Is EHCI driver the only way to access flash storage from protected mode?

thanks again
regards
Everyday schedule: wake up >> eat >> write OS >> eat >> sleep ;-)
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: How to access a pen drive *directly* using ports like HD

Post by NickJohnson »

lup0 wrote:Please don't think that I am asking to be spoon-fed but that wiki doc is **complete ref** including hardware stuff. I only wanted to know about the ports :|
The stuff on the wiki is what you need to write a complete USB driver; a simple list of port names won't do you much good. The USB interface is simply more sophisticated than the ATA interface, and requires a more complex driver. There also aren't any standard port numbers (iirc), because you have to find them using PCI.
lup0 wrote:Is EHCI driver the only way to access flash storage from protected mode?
In theory, you could use virtual 8086 mode to make the BIOS do the transfers for you, but it would be slow and less flexible; that's the only other method that I can think of. A proper USB driver is probably the way to go, in the long run.
User avatar
lup0
Posts: 5
Joined: Fri Mar 25, 2011 4:01 am
Location: India
Contact:

Re: How to access a pen drive *directly* using ports like HD

Post by lup0 »

first of all thanks nick for replying!

i completely agree with you (as i have earlier also expressed); strongly against using virtual 8086 mode for doing things that can be achieved directly in pm. though the *simplicity* of v8086 is tempting :wink: .

anyway I'll write a usb driver then. Let me post the link of EHCI ref pdf in case someone needs it like me: http://www.intel.com/technology/usb/dow ... ci-r10.pdf

see you guys!
regards
Everyday schedule: wake up >> eat >> write OS >> eat >> sleep ;-)
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: How to access a pen drive *directly* using ports like HD

Post by Combuster »

The bios still expects to be alone. v8086 might not work, and becomes increasingly more difficult if the BIOS thinks that polling is a bad idea, or worse, when it needs protected mode to access the hardware in question.

If you want to use the BIOS for storage, load a ramdisk at boot. Otherwise, it's better not to.
"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 ]
Post Reply