Mouse PS2 USB emulation on real hardware

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
YDeeps1
Member
Member
Posts: 69
Joined: Tue Aug 31, 2021 7:25 am
Discord: speedy.dev
Contact:

Mouse PS2 USB emulation on real hardware

Post by YDeeps1 »

So I followed the steps in the mouse forum post to initialise the mouse and enable IRQs but my question is how do I get those interrupts/irqs from USB mice? Emulators work fine however testing it on my machine yields no input. I do see it says I must receive such data streams from the "USB bus" but is there any general guidance towards specifically getting that work for USB mice? I'd rather avoid writing a full fledged USB driver until I really have to. Thanks.
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: Mouse PS2 USB emulation on real hardware

Post by BenLunt »

YDeeps1 wrote:So I followed the steps in the mouse forum post to initialise the mouse and enable IRQs but my question is how do I get those interrupts/irqs from USB mice? Emulators work fine however testing it on my machine yields no input. I do see it says I must receive such data streams from the "USB bus" but is there any general guidance towards specifically getting that work for USB mice? I'd rather avoid writing a full fledged USB driver until I really have to. Thanks.
Well, it depends. Are you still in real-mode? If so, getting mouse movements from a USB mouse is emulated and programmed just like getting mouse movements from a PS2 mouse, as long as the hardware emulates the mouse. Most, if not all modern machines do this.

If you have moved to protected mode, you probably don't want to hear it, but you will have to write a (mostly) <quote>full fledged USB driver until I really have to.</quote>

What hardware do you have, which of the four controllers do you wish to use, and how much effort do you wish to put into USB? Depending on your answer, I have different recommendations.

If you don't want to put much effort into USB, stick with the xHCI controller and forget about the other three. If you wish to learn about USB, I would start with UHCI (and possibly OHCI), skip EHCI altogether, and then go to xHCI.

I have written a book that describes all four controllers and one of the chapters is specifically for USB mice.

Whether you read my book or not, I try to help with every USB question on this forum. After reading other documentation, the wiki for this site for instance, and other resources, start building your base, and when you have a question, feel free to ask.

Ben
- http://www.fysnet.net/the_universal_serial_bus.htm
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Mouse PS2 USB emulation on real hardware

Post by Octocontrabass »

YDeeps1 wrote:the mouse forum post
Which forum post?

Does the emulated PS/2 controller act like a mouse is attached when you initialize it? Does it act like a mouse is attached when you poll for input without using IRQ12?

Have you checked the firmware settings to make sure USB legacy support is enabled? There may be a separate option for mouse support.

Does your firmware support mouse emulation? (I don't know how you would check this!)
YDeeps1
Member
Member
Posts: 69
Joined: Tue Aug 31, 2021 7:25 am
Discord: speedy.dev
Contact:

Re: Mouse PS2 USB emulation on real hardware

Post by YDeeps1 »

Octocontrabass wrote:
YDeeps1 wrote:the mouse forum post
Which forum post?

Does the emulated PS/2 controller act like a mouse is attached when you initialize it? Does it act like a mouse is attached when you poll for input without using IRQ12?

Have you checked the firmware settings to make sure USB legacy support is enabled? There may be a separate option for mouse support.

Does your firmware support mouse emulation? (I don't know how you would check this!)
Which forum post?
https://wiki.osdev.org/Mouse_Input
Does the emulated PS/2 controller act like a mouse is attached when you initialize it? Does it act like a mouse is attached when you poll for input without using IRQ12?
I tried polling it for input but that too returned nothing. Looks like there is no emulation going on with the mouse.
Have you checked the firmware settings to make sure USB legacy support is enabled? There may be a separate option for mouse support.
Checked the BIOS and there is a "USB legacy" option which is turned on but does not mention the mouse.
Does your firmware support mouse emulation? (I don't know how you would check this!)
Your guess is as good as mine :lol: but from the information here it does not look like it.
YDeeps1
Member
Member
Posts: 69
Joined: Tue Aug 31, 2021 7:25 am
Discord: speedy.dev
Contact:

Re: Mouse PS2 USB emulation on real hardware

Post by YDeeps1 »

BenLunt wrote:
YDeeps1 wrote:So I followed the steps in the mouse forum post to initialise the mouse and enable IRQs but my question is how do I get those interrupts/irqs from USB mice? Emulators work fine however testing it on my machine yields no input. I do see it says I must receive such data streams from the "USB bus" but is there any general guidance towards specifically getting that work for USB mice? I'd rather avoid writing a full fledged USB driver until I really have to. Thanks.
Well, it depends. Are you still in real-mode? If so, getting mouse movements from a USB mouse is emulated and programmed just like getting mouse movements from a PS2 mouse, as long as the hardware emulates the mouse. Most, if not all modern machines do this.

If you have moved to protected mode, you probably don't want to hear it, but you will have to write a (mostly) <quote>full fledged USB driver until I really have to.</quote>

What hardware do you have, which of the four controllers do you wish to use, and how much effort do you wish to put into USB? Depending on your answer, I have different recommendations.

If you don't want to put much effort into USB, stick with the xHCI controller and forget about the other three. If you wish to learn about USB, I would start with UHCI (and possibly OHCI), skip EHCI altogether, and then go to xHCI.

I have written a book that describes all four controllers and one of the chapters is specifically for USB mice.

Whether you read my book or not, I try to help with every USB question on this forum. After reading other documentation, the wiki for this site for instance, and other resources, start building your base, and when you have a question, feel free to ask.

Ben
- http://www.fysnet.net/the_universal_serial_bus.htm
I am in fact in protected mode.
What hardware do you have, which of the four controllers do you wish to use, and how much effort do you wish to put into USB?
Haha I haven't even begun with USB barebone basics since I wasn't expecting I'd mess with the USB quite early (well not so early) so I don't know (still would like to exhaust all other available options).
But if I had to pick an approach I'd go with the most basic since I don't think I'll be making use of the USB outside of this instance.
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: Mouse PS2 USB emulation on real hardware

Post by BenLunt »

YDeeps1 wrote:Haha I haven't even begun with USB barebone basics since I wasn't expecting I'd mess with the USB quite early (well not so early) so I don't know (still would like to exhaust all other available options).
But if I had to pick an approach I'd go with the most basic since I don't think I'll be making use of the USB outside of this instance.
Depending on the BIOS, and more importantly, the System Management Firmware, the PS2 emulation may or may not continue to work after the move to protected mode. It is assumed that if your software is capable of protected mode code, it is capable of loading a USB driver. :-)

Good luck,
Ben
YDeeps1
Member
Member
Posts: 69
Joined: Tue Aug 31, 2021 7:25 am
Discord: speedy.dev
Contact:

Re: Mouse PS2 USB emulation on real hardware

Post by YDeeps1 »

BenLunt wrote:
YDeeps1 wrote:Haha I haven't even begun with USB barebone basics since I wasn't expecting I'd mess with the USB quite early (well not so early) so I don't know (still would like to exhaust all other available options).
But if I had to pick an approach I'd go with the most basic since I don't think I'll be making use of the USB outside of this instance.
Depending on the BIOS, and more importantly, the System Management Firmware, the PS2 emulation may or may not continue to work after the move to protected mode. It is assumed that if your software is capable of protected mode code, it is capable of loading a USB driver. :-)

Good luck,
Ben
I'll give it a shot. Do you mind giving me a vague list of steps in getting this to work? From my little USB knowledge I believe I need to first establish a connection with a version both the host and device support and then somehow get an interrupt transfer in place in order to receive data from the mouse in real time.
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: Mouse PS2 USB emulation on real hardware

Post by BenLunt »

YDeeps1 wrote:I'll give it a shot. Do you mind giving me a vague list of steps in getting this to work? From my little USB knowledge I believe I need to first establish a connection with a version both the host and device support and then somehow get an interrupt transfer in place in order to receive data from the mouse in real time.
Hi,

I am sorry to say, there is no vague list of steps to get USB working. You must setup the controller, create a periodic stack, send and then receive descriptor requests, initialize the mouse, etc, before you can even think of receiving mouse packets.

On top of that, a mouse movement will not trigger an interrupt as you think it will. i.e.: it won't fire an interrupt to the PIC on every movement like you expect the PS2 would. Your stack contains a flag that will tell the controller to generate an interrupt at the end of the frame. This frame could have had 100 or more packets from various devices, some not at all related to the mouse. Your code then has to determine which packet has been received and which has yet to be received.

All of that doesn't even mention enumerating the PCI(e) to find the USB controller(s).

I am sorry, but there is no vague list of steps to take. You step in to USB and you better be ready to swim. :-)

So, to answer your question, you either need to build a USB driver or forget about the USB mouse. One or the other.

Sorry,
Ben
Post Reply