How to read data from USB with in/out in pmode?

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
windows8
Member
Member
Posts: 33
Joined: Sat Feb 23, 2013 3:52 am

How to read data from USB with in/out in pmode?

Post by windows8 »

How to read data from USB with in/out in pmode?
I searched Google,but I got few information about that.Then I tried to search osdev forum,there is no results,too!
I found USB class code and subclass in PCI wiki(http://wiki.osdev.org/PCI),so I guess I can get io ports in PCI.If I'm right,how to use the ports?
Can you help me write an example?Thank you very much!
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: How to read data from USB with in/out in pmode?

Post by thepowersgang »

It's a lot harder than you think. USB is essentially a network protocol (except not really, but it's about as complex, and it helps to think of it this way).

If you're really interested, I'd look at the USB page on the wiki, as well as the OHCI/UHCI/EHCI datasheets. I'd guess from the way your post is framed that you're only just starting out, and want to handle USB mass storage and input devices. I would (and did) leave USB support until after my OS was stable with full multithreading and a partial network stack, just so the groundwork is covered.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
sounds
Member
Member
Posts: 112
Joined: Sat Feb 04, 2012 5:03 pm

Re: How to read data from USB with in/out in pmode?

Post by sounds »

windows8 wrote:How to read data from USB with in/out in pmode?
I searched Google,but I got few information about that.Then I tried to search osdev forum,there is no results,too!
I found USB class code and subclass in PCI wiki(http://wiki.osdev.org/PCI),so I guess I can get io ports in PCI.If I'm right,how to use the ports?
Can you help me write an example?Thank you very much!
If you are asking about the x86 instructions "in" and "out," the answer is that you can't.

Although "in" and "out" can be used to configure the USB device's PCI configuration space... what goes there is a physical memory address.

Reads and writes to the USB device are then done using memory access, not "in" and "out."
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: How to read data from USB with in/out in pmode?

Post by ~ »

thepowersgang wrote:It's a lot harder than you think. USB is essentially a network protocol (except not really, but it's about as complex, and it helps to think of it this way).

If you're really interested, I'd look at the USB page on the wiki, as well as the OHCI/UHCI/EHCI datasheets. I'd guess from the way your post is framed that you're only just starting out, and want to handle USB mass storage and input devices. I would (and did) leave USB support until after my OS was stable with full multithreading and a partial network stack, just so the groundwork is covered.
I would also like to know: Why is the reason for the apparently strong insistence about even having multithreading and network stack to implement USB?

I see that the BIOS can handle USB input devices as well as mass storage devices, and it is a 16-bit program with no multithreading and presumably not a network stack, or at least not even required for USB support.

Then I would attempt to implement USB just like the BIOS (first an easy, monotasking version, and then iterate it to naturally adapt it to a multitasking environment over a period of time).
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: How to read data from USB with in/out in pmode?

Post by thepowersgang »

I suggested waiting mostly because of the extra experience it gives you (network particularly, as it's a similar idea), but you're right - USB doesn't require full threading (just some basic timing) but it helps immensely with interrupt handling.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Post Reply