How to implement a PS/2 keyboard driver?
How to implement a PS/2 keyboard driver?
Hello all,
I am trying to implement a PS/2 keyboard driver in my operating system. The wiki page on PS/2 keyboards leaves out two important things for a noob like me:
1. What port should I use to interact with the keyboard?
2. After sending 0xF4, how to I listen for scan codes?
I did try searching the web and the wiki and I found nothing on this. Could anybody please help me?
I am trying to implement a PS/2 keyboard driver in my operating system. The wiki page on PS/2 keyboards leaves out two important things for a noob like me:
1. What port should I use to interact with the keyboard?
2. After sending 0xF4, how to I listen for scan codes?
I did try searching the web and the wiki and I found nothing on this. Could anybody please help me?
Re: How to implement a PS/2 keyboard driver?
Trinix (written in D) https://github.com/Rikarin/Trinix
Streaming OS development https://www.livecoding.tv/satoshi/
Streaming OS development https://www.livecoding.tv/satoshi/
Re: How to implement a PS/2 keyboard driver?
Thank you, I'll update once I have this implemented in my kernel.
Re: How to implement a PS/2 keyboard driver?
jhunterd: [Edit: A post has been removed, so disregard this. Please relax and remember that all forums have their trolls. You should report the post to the operators if you find it offensive rather than responding in anger. If you feel offended by a post, I can recommend taking a break and returning later when you are level-headed.]
I can see you are new here, welcome!
If you managed to write a keyboard driver, feel free to update the wiki article such that it would have helped you. I can recommend reading the CPU documentation sooner than later. Despite being heavy documents, it is crucial to learn to search them for the proper information. You can often find some basic keyboard drivers in various kernel tutorials, you can easily find some using google.
I can see you are new here, welcome!
If you managed to write a keyboard driver, feel free to update the wiki article such that it would have helped you. I can recommend reading the CPU documentation sooner than later. Despite being heavy documents, it is crucial to learn to search them for the proper information. You can often find some basic keyboard drivers in various kernel tutorials, you can easily find some using google.
Last edited by sortie on Wed May 15, 2013 3:27 am, edited 1 time in total.
Re: How to implement a PS/2 keyboard driver?
Offended or not, spend a little bit more effort next time.
PS/2 keyboard driver is probably one of the most overdocumented things on the internets.
PS/2 keyboard driver is probably one of the most overdocumented things on the internets.
Learn to read.
Re: How to implement a PS/2 keyboard driver?
You never reset escaped to false, is that intentional?Bloodman wrote:try this https://github.com/Bloodmanovski/System ... yboard.cpp
Learn to read.
Re: How to implement a PS/2 keyboard driver?
The basic steps are:
1) wait for an interrupt
2) report to the driver to read the scan code
3] read scan code, and convert to something for OS use
4] return the character code
5) report to whatever program
A list of scancodes can be found at http://wiki.osdev.org/PS/2_Keyboard#Scan_Code_Sets
The easiest method is to use a lookup table, but this probably isn't the best method.
1) wait for an interrupt
2) report to the driver to read the scan code
3] read scan code, and convert to something for OS use
4] return the character code
5) report to whatever program
A list of scancodes can be found at http://wiki.osdev.org/PS/2_Keyboard#Scan_Code_Sets
The easiest method is to use a lookup table, but this probably isn't the best method.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
If you're new, check this out.
Re: How to implement a PS/2 keyboard driver?
jhunterd, I feel your pain a little bit. I just finished a PS/2 driver for my OS.
The wiki articles try to describe a proper PS/2 driver that actually manages the PS/2 controller and the things attached to it. If you are just starting out and doing something simple then it may not be necessary yet.
The link that dozniak provided is excellent.
Bloodman's code will likely work. It takes advantage of the fact that the the Bios probably leaves the hardware in a particular state that you might find useful. It will not work on all hardware (in fact it will lock up or crash some machines) and will present issues when you try to get a PS/2 mouse working but it is probably a useful starting point.
So in answer to your questions.
1. 0x60
2. If everything is enabled correctly you will get an interrupt when there is something to read. And you read the data on port 0x60.
The wiki articles try to describe a proper PS/2 driver that actually manages the PS/2 controller and the things attached to it. If you are just starting out and doing something simple then it may not be necessary yet.
The link that dozniak provided is excellent.
Bloodman's code will likely work. It takes advantage of the fact that the the Bios probably leaves the hardware in a particular state that you might find useful. It will not work on all hardware (in fact it will lock up or crash some machines) and will present issues when you try to get a PS/2 mouse working but it is probably a useful starting point.
So in answer to your questions.
1. 0x60
2. If everything is enabled correctly you will get an interrupt when there is something to read. And you read the data on port 0x60.
If a trainstation is where trains stop, what is a workstation ?
Re: How to implement a PS/2 keyboard driver?
Thanks to everybody for all the help. One other question: how exactly would I check for an interrupt?
Re: How to implement a PS/2 keyboard driver?
You don't check for interrupts, they happen. You set up the IDT such that the relevant IRQ triggers your interrupt handler, which performs the keyboard access, and then returns to whatever the CPU was doing before it was interrupted. I recommend you look up some kernel development tutorials, they describe all this information. Then when you get a grasp of what is supposed to happen, I recommend you get the Intel/AMD manuals and look up the topics in the System Programming (or what it is called) volumes.
Re: How to implement a PS/2 keyboard driver?
Okay. Thank you everybody for all of the help. I really appreciate it.