OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:51 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: PS/2 device detection strange output on Bochs
PostPosted: Sat Jan 21, 2017 11:32 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
I suggest you follow the suggestions in the last two posts and re-write your IRQ handling. When you do, please note that the IRQ Handler should do as little as possible, if only setting a flag to wake up a sleeping task.

As for the PS2 controller and hot-plugging. I would not suggest that anyone unplug a device from their PS2 port while it is powered. Some older hardware would actually become damaged due to a hot-unplug. The hardware may be in an unknown state and can't be restored correctly to allow the new plug-in until a complete power cycle.

Anyway, I suggest you follow Octocontrabass's and Brendan's suggestions. My PS2 controller, PS2 Keyboard, and PS2 Mouse source code, including support for three Scan Code Sets, numerous mouse packet sizes and types, and IRQ handling is less than 1,000 lines of heavily commented C code. Might I suggest that you take a look at your current code, divide the keyboard code from the mouse code as Brendan suggests, and re-write your IRQ handling.

The only way you can tell if the byte read from the Output Buffer came from the mouse or the keyboard (port 0 or port 1) is via the IRQ it fired. Period.

Ben
http://www.fysnet.net/input_and_output_devices.htm


Top
 Profile  
 
 Post subject: Re: PS/2 device detection strange output on Bochs
PostPosted: Sun Jan 22, 2017 10:11 am 
Offline
Member
Member
User avatar

Joined: Mon Dec 28, 2015 11:11 am
Posts: 401
Brendan wrote:
Hi,

Lukand wrote:
It seems I could not get input from mouse now. What does happens is that keyboard interferes mouse, eg. input from keyboard has interference with mouse input. Through moving mouse and clicking on it does nothing, but typing keys does.
Sadly there's no way to seperate keyboard input with mouse input except using semaphores as used in multithreading...


I told you that would happen (that the drivers would interfere with each other) and how to avoid the problem last month.

Mostly; there are 3 different devices, so you need 3 separate drivers (one for the PS/2 controller itself, and one for each type of device that could be plugged into a PS/2 port) in the same way that you'd have multiple drivers for USB (one for the USB controller, and one for each type of device that could be plugged into a USB port).

Note: By "3 separate drivers" I don't necessarily mean (e.g.) 3 separate processes (for micro-kernel) or 3 separate "kernel modules" (for monolithic). It could just be "logical separation" (where the source code is split into 3 separate directories, but it's all assembled/compiled/linked together and becomes a single executable/process/kernel module).

The "PS/2 controller driver" would initialise (and test) the controller, determine if there are any devices plugged into the PS/2 ports and get their "device ID", then use the "device ID" to determine which drivers are needed and start the right driver (note that you can have 2 keyboards and no mouse, or 2 mouse and no keyboards, or a bar-code scanner and a touch-pad and no keyboards and no mouse, or...).

The drivers for devices plugged into a PS/2 port (e.g. the keyboard driver and mouse driver) would ask the "PS/2 controller driver" to send bytes to whichever port it's connected to, and the "PS/2 controller driver" would tell the driver for a PS/2 port about any bytes received. The drivers for devices plugged into a PS/2 port would never use any IO ports or IRQs themselves. If you port your OS to a different type of computer (with a different type of PS/2 controller - e.g. the PL050 on some ARM SoCs) you only need to write a new "PS/2 controller driver" and (assuming C source code or something) will not need to change any driver for a PS/2 device (the keyboard, mouse, bar-code, touch-pad, touch-screen, .... drivers).

Another thing the "PS/2 controller driver" would do is handle "hot-plug" - if the user unplugs a device it'd tell (terminate?) whichever driver was using that PS/2 port, and if a user plugs a device into a previously empty PS/2 port the "PS/2 controller driver" would figure out the type of device that was plugged in and start an appropriate driver. The "PS/2 controller driver" could also (optionally) monitor the other drivers - e.g. if your keyboard driver crashes then "PS/2 controller driver" might notice and start another keyboard driver; and if you install a newer keyboard driver then "PS/2 controller driver" might notice and terminate the old driver and start the new one.

Finally; it'd probably be nice to build support for debugging into your "PS/2 controller driver"; so that anyone writing a driver for any PS/2 device can enable debugging for whichever port the device is connected to and see all bytes received by their driver and see all bytes sent by their driver (without having any code in their driver). This just makes it much easier for people (you) to write drivers for different PS/2 devices.


Cheers,

Brendan


I already do all of that, based on info on PS/2 controller wiki page.


Top
 Profile  
 
 Post subject: Re: PS/2 device detection strange output on Bochs
PostPosted: Sun Jan 22, 2017 10:13 am 
Offline
Member
Member
User avatar

Joined: Mon Dec 28, 2015 11:11 am
Posts: 401
BenLunt wrote:
I suggest you follow the suggestions in the last two posts and re-write your IRQ handling. When you do, please note that the IRQ Handler should do as little as possible, if only setting a flag to wake up a sleeping task.

As for the PS2 controller and hot-plugging. I would not suggest that anyone unplug a device from their PS2 port while it is powered. Some older hardware would actually become damaged due to a hot-unplug. The hardware may be in an unknown state and can't be restored correctly to allow the new plug-in until a complete power cycle.

Anyway, I suggest you follow Octocontrabass's and Brendan's suggestions. My PS2 controller, PS2 Keyboard, and PS2 Mouse source code, including support for three Scan Code Sets, numerous mouse packet sizes and types, and IRQ handling is less than 1,000 lines of heavily commented C code. Might I suggest that you take a look at your current code, divide the keyboard code from the mouse code as Brendan suggests, and re-write your IRQ handling.

The only way you can tell if the byte read from the Output Buffer came from the mouse or the keyboard (port 0 or port 1) is via the IRQ it fired. Period.

Ben
http://www.fysnet.net/input_and_output_devices.htm


I already do all of that, my PS/2 driver is 527 lines long without any comments...


Top
 Profile  
 
 Post subject: Re: PS/2 device detection strange output on Bochs
PostPosted: Sun Jan 22, 2017 10:21 am 
Offline
Member
Member
User avatar

Joined: Mon Dec 28, 2015 11:11 am
Posts: 401
Octocontrabass wrote:
Lukand wrote:
I'm trying to avoid overhauling I/O by interrupts.

Why are you trying to avoid it?

The only way to tell which PS/2 device sent the data is using interrupts. If you're not using interrupts, then you can't tell if you're receiving data from the first port or the second port.

Lukand wrote:
Doesn't mouse just send interrupts only when automatic packet interrupts are enabled? Or I'm wrong?

The mouse doesn't send interrupts at all, it send bytes. The PS/2 controller raises an interrupt request when it receives a byte. If you prevent the mouse from sending bytes, or you prevent the PS/2 controller from sending IRQs, then you won't receive any interrupts.

Lukand wrote:
And is it good idea to create semaphores (eg. when waiting for mouse input disable the port where keyboard is located in)?

No. That creates a race condition. The PS/2 controller can receive a byte from the keyboard at the same time you're disabling the keyboard port, so the next byte you receive comes from the keyboard even though you've just disabled it.


So sadly I have to use interrupts to seperate mouse and keyboard (Ich hasse interrupts).

But still problem would continue since I do not get anything from mouse. But, Nutoak provides unique feature which allows you to use mouse by keyboard instead of real mouse! Pressing 'G' on your keyboard simulates mouse moving 13,4 mm up and click of right mouse button! And that is not all! Pressing ';' on your keyboard simulates mouse moving 54,1 mm DOWN! Imagine such great features! Nutoak Developement Team is proud for success of their PS/2 driver! And all of that for 399,99£ + gratis coupon for Second-Hand shops!


Top
 Profile  
 
 Post subject: Re: PS/2 device detection strange output on Bochs
PostPosted: Sun Jan 22, 2017 10:51 am 
Offline
Member
Member

Joined: Wed Oct 12, 2016 11:32 am
Posts: 34
Location: At my PC
Lukand wrote:
Octocontrabass wrote:
Lukand wrote:
I'm trying to avoid overhauling I/O by interrupts.

Why are you trying to avoid it?

The only way to tell which PS/2 device sent the data is using interrupts. If you're not using interrupts, then you can't tell if you're receiving data from the first port or the second port.

Lukand wrote:
Doesn't mouse just send interrupts only when automatic packet interrupts are enabled? Or I'm wrong?

The mouse doesn't send interrupts at all, it send bytes. The PS/2 controller raises an interrupt request when it receives a byte. If you prevent the mouse from sending bytes, or you prevent the PS/2 controller from sending IRQs, then you won't receive any interrupts.

Lukand wrote:
And is it good idea to create semaphores (eg. when waiting for mouse input disable the port where keyboard is located in)?

No. That creates a race condition. The PS/2 controller can receive a byte from the keyboard at the same time you're disabling the keyboard port, so the next byte you receive comes from the keyboard even though you've just disabled it.


So sadly I have to use interrupts to seperate mouse and keyboard (Ich hasse interrupts).

But still problem would continue since I do not get anything from mouse. But, Nutoak provides unique feature which allows you to use mouse by keyboard instead of real mouse! Pressing 'G' on your keyboard simulates mouse moving 13,4 mm up and click of right mouse button! And that is not all! Pressing ';' on your keyboard simulates mouse moving 54,1 mm DOWN! Imagine such great features! Nutoak Developement Team is proud for success of their PS/2 driver! And all of that for 399,99£ + gratis coupon for Second-Hand shops!

I certainly don't hope your serious.
Also, your website seems to have reached it's CPU limit. Github link?


Top
 Profile  
 
 Post subject: Re: PS/2 device detection strange output on Bochs
PostPosted: Thu Feb 02, 2017 3:01 pm 
Offline
Member
Member
User avatar

Joined: Mon Dec 28, 2015 11:11 am
Posts: 401
hannah wrote:
I certainly don't hope your serious.
Also, your website seems to have reached it's CPU limit. Github link?

Of course I'm not serious.
It constantly reaches. Because I have a lot of people visiting this forum and very expensive host which could not handle that much visitors. (Sarcastic)

I rarely update GitHub. Instead of commiting after every change, I commit after "lot" of changes. It is little bit outdated.
If you want to look at old code then search "Nutoak Github" on Google. If it does not help then just https://github.com/lukaandjelkovic/Nutoak
I really do not know what to do since I could not find any damn problem.


Top
 Profile  
 
 Post subject: Re: PS/2 device detection strange output on Bochs
PostPosted: Fri Feb 03, 2017 4:06 am 
Offline
Member
Member

Joined: Wed Sep 19, 2012 3:43 am
Posts: 91
Location: The Netherlands
This might be a bit offtopic but I think it's important to note.
You should commit early and often, making sure only "atomic" (e.g. "complete and working") changes are committed.
What this means is that you shouldn't create one (or several) huge feature(s) and then commit the changes but instead split the work up into logical chunks that, in itself, don't break any other code and commit once one of these chunks is completed.
That way you can always fall back to an earlier version and/or review where you made a breaking change and what that change was.

Remember, git is not a backup tool, it's version control. Use it what it is intended for.


Top
 Profile  
 
 Post subject: Re: PS/2 device detection strange output on Bochs
PostPosted: Fri Feb 03, 2017 6:29 am 
Offline
Member
Member
User avatar

Joined: Mon Dec 28, 2015 11:11 am
Posts: 401
Maybe I should stop working pointlessly on PS/2 and continue on multithreading...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 57 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group