Page 1 of 3

OS -->USB ?

Posted: Mon Nov 03, 2008 6:31 pm
by Sam111
I have a simply OS I developed using some of your code on OS developer.
What I don't get is their is no interupts for the usb that I have found.

I have went thru all of the interrupt tables on many sites but I cann't seem to find any for usb. Serial/Com is int 14 . I have interrupts for the mouse, RTC, int 13 bios , int 10 VGA ,
etc etc...

What I want to know is their away to incorporate usb support into your own os?
I have written usb stuff on windows but you always have to include windows.h or some other header file. When writing an os you have to use only the standard's not the os specific lib's

I don't mind take my time to write a driver program from in/out commands in inline asm (c programing). However I have never been able to find a port list that specifies where to write what (control registers ,...ect etc ) .

I have seen on your site the direct memory address for the VGA monitor stuff.
Also you did explain how to write bytes to the harddrive thru out 0x60 or something

What I want to know is how you figured this stuff out. Or where did you look to get the spec's on what ports go to what and what to write to them / read from them?

So far I can only use devices I can access thru int commands or direct memory (thru pointers)

I have looked at the spec's for usb version 1.0 but their is not much telling me how to read and write to an external hardrive or such. Thru in/out port's.
And all programs that I have seen use some of the win32 or linux dependent libraries . I need I driver program that would work for my OS. Don't mind to take a year in writing it from scratch (in/out) because this is my hobby.

Same question but for cd/dvd.

I was able to eject my cd player using int 13 ah 81h.
But I am not sure on to read / write sectors because their is the whole LBA to CHS thing.
And I am not sure if device 81h is always going to be my cd/dvd player?

Also I would be set if the external harddrive shows up as device 82h or something.
But I am not sure what happens to external usb devices does the Bios reconginze this as a device and assign it a device number between 80h to ffh?

Assuming the BIOS supports booting from usb then does the external usb harddrive have to have 55AA on the first sector to get a device number assigned to it? Or does everything connected get assigned a device letter?

Please help I am stuck.

Re: OS -->USB ?

Posted: Tue Nov 04, 2008 12:43 am
by Jabus
I assume you're currently in real mode. As far as I know I don't think there are any real mode interrupts that can help you with USB just like there are no real mode interrupts that can send packets over a network. If you are booting from the USB when the boot loader starts being executed the value of DL that you have to use for all the int 13h functions is stored in DL. I would suggest that instead of trying to use real mode interrupts to help you would look at Dex's OS witch iirc has USB support.

About the cd/dvd problem I would say the same thing. If you know that you are booting from that device then the device number will be stored in DL at the start of execution of your bootloader.

Re: OS -->USB ?

Posted: Tue Nov 04, 2008 2:11 am
by djmauretto
Ciao,
to HW spec about USB google for UHCI/EHCI controller by INTEL and USB2.0 spec.
For CD/DVD google for ATAPI spec (T13.org) :wink:

Re: OS -->USB ?

Posted: Tue Nov 04, 2008 4:57 am
by Love4Boobies
http://www.usb.org/
http://www.t13.org/

Mind you that USB drivers are very hard to program.

Re: OS -->USB ?

Posted: Tue Nov 04, 2008 5:07 am
by Love4Boobies
Sam111 wrote:What I want to know is how you figured this stuff out. Or where did you look to get the spec's on what ports go to what and what to write to them / read from them?
The VGA spec isn't available anymore AFAIK. You could phone IBM and ask for it but you may have to pay for it (assuming they still have it); However, if you want it, I have the description of the VGA direct hardware programming model that IBM made (PM me). It's all there. If not, there's still plenty on the net.
Or does everything connected get assigned a device letter?
No letters are assigned to anything, ever. That's just what Microsoft does.

Re: OS -->USB ?

Posted: Tue Nov 04, 2008 7:25 am
by djmauretto
Complete IBM manual reference,contain VGA,FLOPPY,KEYBOARD,DMA,BIOS,TIMER and so on....
http://www.mcamafia.de/pdf/pdfref.htm

Re: OS -->USB ?

Posted: Tue Nov 04, 2008 9:51 am
by Sam111
Ok when I do my loader I put my self into protected mode.
Then how would I access the usb and cd/rom devices.
Is their new int commands that you get in 32 bit mode?
Because all I know is that int commands can take 00h to ffh values.
And the IDT is the first segment in memory.

But I would think since their's not a standard interrupt for usb.
(Unlike serial/Com ports --> int 14) The only way to have usb support is by writing a driver program or function thur either DMA or in/out port commands.

Thanks for those spec's it is going to take me some time to read thru them.

I was just wondering if their is a easier way like int commands or a direct address I could use. VGA was pretty easy I had the option of using a pointer to the memory location or an int 10 command. With usb it seems that their is no easy spec for it or good example of using in/out port stuff for usb.

Anyway thank's

Re: OS -->USB ?

Posted: Tue Nov 04, 2008 10:56 am
by Owen
Once in protected mode, all the BIOS interrupts vanish. You talk to the hardware directly. Rather than calling an interrupt to read from the hard disk, you send commands to it (or it's controller). To change graphics mode, you poke some info to the graphics card.

To do USB, you first need to implement support for PCI. This is also a lot of specification reading. And since PCI devices tend to have quite large address space requirements, your gonna need protected mode.

Re: OS -->USB ?

Posted: Tue Nov 04, 2008 11:19 am
by Love4Boobies
djmauretto wrote:Complete IBM manual reference,contain VGA,FLOPPY,KEYBOARD,DMA,BIOS,TIMER and so on....
http://www.mcamafia.de/pdf/pdfref.htm
My BIOS docs are newer :p From '95 :p (SurePath)...

Re: OS -->USB ?

Posted: Tue Nov 04, 2008 1:33 pm
by djmauretto
Only for historical reason, the document more update you'll find
in your chipset spec (INTEL) plus various HW datasheet and so on...(not always available) =D>

Re: OS -->USB ?

Posted: Tue Nov 04, 2008 6:12 pm
by Sam111
Ok then I guess I am not understanding something.

So if you need to be in 32 bit mode (protected mode)
Then how did 16 bit computers support network stuff NCI ...etc etc.

I don't know if their are 16bit os that support usb out their .

But I really don't see why 16bit computers can't support nic , ...usb ,...etc etc.

You have less space but you still have in/out 0 - ffffh

And I don't really get something quote below
Once in protected mode, all the BIOS interrupts vanish. You talk to the hardware directly. Rather than calling an interrupt to read from the hard disk, you send commands to it (or it's controller).
So are you saying 16 bit operating systems never access the hardware directly?
BIOS int vanish uh I can still do an int 13h I would think that would depend on if I overwrote it in the IDT or just left it whatever it was. #-o

Re: OS -->USB ?

Posted: Tue Nov 04, 2008 7:06 pm
by neon
Once in protected mode, all the BIOS interrupts vanish. You talk to the hardware directly. Rather than calling an interrupt to read from the hard disk, you send commands to it (or it's controller).
Incorrect. None of the interrupts vanish unless you overwrite it. Even if you install a IDT, you can still reinstall the original IVT and call the bios from v86 or real mode if needed.

Re: OS -->USB ?

Posted: Tue Nov 04, 2008 7:48 pm
by pcmattman
So are you saying 16 bit operating systems never access the hardware directly?
Do you know what protected mode is? That, or you don't understand the concept of "Once in protected mode".
Then how did 16 bit computers support network stuff NCI ...etc etc.
They wrote drivers that interfaced with the hardware directly (generally using in/out or memory mapped IO), exactly the same you would in protected mode. There aren't interrupts for everything ;)

Re: OS -->USB ?

Posted: Wed Nov 05, 2008 12:13 am
by Sam111
Ok so is their like an example of how to read/write to an external usb harddrive
thru in/out commands I am confused about what I have to do should I try an do it using mmio or thru in/out. And if I choose in/out how do I do it thru control registers.
I am a little fuzzy on how to do this the usb spec's are confusing me with to much info.

Re: OS -->USB ?

Posted: Wed Nov 05, 2008 12:23 am
by pcmattman
The problem is USB is a multilevel system.

At the lowest level you have the host controller (ie, OHCI and UHCI). This is the thing that actually works with USB packets on the line.

You then have a layer of things like the "mass storage" standard (which is what you'd want in an external hard drive) which all devices providing mass storage via a USB interface implement (to avoid needing drivers for every device). These know the commands and instructions to send to/receive from the device over the USB line.

And then you'd need to have a layer over the top of that to abstract out the actual storage mechanism, to make sure that the USB device can seamlessly integrate into the system.

USB is something very few hobby OS systems have, mainly because the spec is incredibly daunting. The ones that do are really set apart from the crowd.

EDIT: Please, correct me if I'm wrong - working off memory here which might be a tad rusty.