Keyboard

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.
Stephen

Keyboard

Post by Stephen »

Hi!
Can anyone tell me how to make the keyboard work in an OS, using C and compiling it with DJGPP?? I am using Proteced mode, with A20 Enabled.

Thanx, :) ;D 8)
Legend

Re:Keyboard

Post by Legend »

First thing: Get your interrupt handling working (set up PIC and IDT) ...
Adek336

Re:Keyboard

Post by Adek336 »

Stephen, Legend: Feel free to register ;)

http://osdever.net/documents.php?cat=8&sort=1 is your friend. So much docs you won't probably need in your whole life :) If you want a serious keyboard driver, you'll need interrupt support. http://osdever.net/tutorials.php?cat=5&sort=1

However you can toy with a non-interrupt driver for a while by reading from port 0x60.

Cheers
Whatever5k

Re:Keyboard

Post by Whatever5k »

Adek336 wrote: However you can toy with a non-interrupt driver for a while by reading from port 0x60.
Argh, ugly ;)
Being you, I would directly implement interrupt service routines. Do not go the long way.
srg_13

Re:Keyboard

Post by srg_13 »

I have tried those webpages, but I still can't understand any of it....
Adek336

Re:Keyboard

Post by Adek336 »

What did you start to code from, how much did you implement it and where are you stuck?
srg_13

Re:Keyboard

Post by srg_13 »

Adek336 wrote: What did you start to code from, how much did you implement it and where are you stuck?
I started my OS from tutorials, and I implemented most of it. I only have a little knoledge of coding in C, but not bios stuff. All the code I have found on the internet is either for dos programming or in assembly.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Keyboard

Post by Brendan »

Hi,
Stephen wrote:
Adek336 wrote: What did you start to code from, how much did you implement it and where are you stuck?
I started my OS from tutorials, and I implemented most of it. I only have a little knoledge of coding in C, but not bios stuff. All the code I have found on the internet is either for dos programming or in assembly.
I think what Adek336 is asking is:
- does your OS use 16 bit real mode or is the BIOS useless
- does your OS have support for interrupts, IRQs and IO ports yet
- how much of the keyboard code have you already done
- where exactly in the keyboard code are you stuck

Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
srg_13

Re:Keyboard

Post by srg_13 »

Hello!
I am using 32 bit Protected Mode, I dont have support for ICQs or for interrupts (I tried enabling them with the codes on the websites (http://osdever.net/tutorials.php?cat=5&sort=1) but i got heaps of errors when I tried to link the compiled C and ASM Files) and I dont have any keyboard code.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Keyboard

Post by Pype.Clicker »

You'll have to enable interrupts sooner or later... what kind of "compile error" do you encounter ? could that come from the fact you're trying to compile something that was MS-targetted (e.g. pre-pending underscores) on a non-MS platform ?

what tools do you use for compiling ?
srg_13

Re:Keyboard

Post by srg_13 »

I use DJGPP to compile the C part of my OS, NASM to compile the ASM part, and ld to link the two files. When I try to link the two files, I get this error.

kernel_c.o(.text+0x12):kernel_c.c: undefined reference to `_outb'
kernel_c.o(.text+0x20):kernel_c.c: undefined reference to `_outb'
kernel_c.o(.text+0x2a):kernel_c.c: undefined reference to `_outb'
kernel_c.o(.text+0x37):kernel_c.c: undefined reference to `_outb'
kernel_c.o(.text+0x42):kernel_c.c: undefined reference to `_outb'
kernel_c.o(.text+0x50):kernel_c.c: more undefined references to `_outb' follow

These errors are all from the code to remap the PICS as follows:

#define PIC1 0x20
#define PIC2 0xA0

#define ICW1 0x11
#define ICW4 0x01

void init_pics(int pic1, int pic2)
{
   /* send ICW1 */
   outb(PIC1, ICW1);
   outb(PIC2, ICW1);

   /* send ICW2 */
   outb(PIC1 + 1, pic1);   
   outb(PIC2 + 1, pic2);   

   /* send ICW3 */
   outb(PIC1 + 1, 4);   
   outb(PIC2 + 1, 2);

   /* send ICW4 */
   outb(PIC1 + 1, ICW4);
   outb(PIC2 + 1, ICW4);

   /* disable all IRQs */
   outb(PIC1 + 1, 0xFF);
}
srg_13

Re:Keyboard

Post by srg_13 »

These errors are all from the code to remap the PICS as follows:
All this code is in my C kernel.

The code that calls the function:

init_pics(0x20, 0x28);

is in the main function
DennisCGc

Re:Keyboard

Post by DennisCGc »

Seems like you didn't implement the outb function ::)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Keyboard

Post by Pype.Clicker »

Where do i get inb, outb etc ?

Seems like the FAQ is there for you once again :P
srg_13

Re:Keyboard

Post by srg_13 »

Ok, I fixed that one up and now the interupts are set up, but I have no keyboard code. How yould you write this?? :)
Post Reply