Page 1 of 3
Keyboard IRQ
Posted: Tue Oct 29, 2002 10:04 am
by Tom
Hello, I have a working IDT
and I know how to get keys in the polling manner. How would I send the keys to the IRQ ( 1 )?
How would I get keys from that IRQ?
Thank you,
Re:Keyboard IRQ
Posted: Tue Oct 29, 2002 10:28 am
by paul
You said you have a working IDT. Does that mean you have also remapped all of the IRQ's to higher interrupts (since the first 32 are system interrupts). Most people
remap the PIC so that IRQ0-7 go to 0x20 - 0x27
and IRQ8-15 go to 0x28 - 0x2f. If you have done that,
and re-enabled interrupts (STI), you should already be getting signals on your 0x21 routine (for IRQ 1.)
Just remember to do this at the end of your ISR for the keyboard interrupt:
mov al,0x20
out 0x20,al
...or your keyboard ineterrupt will fire only once!
Hope this helps.
Paul
Re:Keyboard IRQ
Posted: Tue Oct 29, 2002 10:29 am
by Tom
COOL! I found out how to make my own interrupt ( 30h ) that prints whatever I want?
Are hardware interrupts slow?
If not, could I make my OS based ( verysmall partly ) on ints?
Thank you,
Re:Keyboard IRQ
Posted: Tue Oct 29, 2002 10:35 am
by Tom
I didn't remap the irqs, they are set up in a way to work the way the BIOS puts them. I think......
Re:Keyboard IRQ
Posted: Tue Oct 29, 2002 11:57 am
by Paul
Ok, just do this before your STI and you will be
all set. Whichever function you put in your IDT for interrupt 0x21 will get the keyboard events!
;REMAP INTERRUPTS 0-15 --> 0x20 - 0x2f
in al,0x21
mov ah,al
in al,0xA1
mov cx,ax
mov al,0x11
out 0x20,al
out 0xEB,al
out 0xA0,al
out 0xEB,al
mov al,0x20
out 0x21,al
out 0xEB,al
add al,0x8
out 0xA1,al
out 0xEB,al
mov al,0x04
out 0x21,al
out 0xEB,al
shr al,1
out 0xA1,al
out 0xEB,al
shr al,1
out 0x21,al
out 0xEB,al
out 0xA1,al
out 0xEB,al
mov ax,cx
out 0xA1,al
mov al,ah
out 0x21,al
mov ecx,0x1000
cld
picl1: out 0xEB,al
loop picl1
That's all there is to it!
Paul
Re:Keyboard IRQ
Posted: Tue Oct 29, 2002 12:05 pm
by Paul
I forgot to mention.... Within your interrupt service routine, just do a "in al,60h" to get the scancode just like you did with the polling method.
Paul
Re:Keyboard IRQ
Posted: Tue Oct 29, 2002 2:11 pm
by Tom
I don't need to remap the IRQ's, my sti works fine.
Re:Keyboard IRQ
Posted: Tue Oct 29, 2002 2:29 pm
by Whatever5k
If you're in Protected Mode, you will need to remap the PICs because otherwise there will be a conflict between IRQs and CPU exceptions...
Re:Keyboard IRQ
Posted: Tue Oct 29, 2002 6:16 pm
by Tom
Does some one have any keyboard IRQ code examples?
Thank you,
Re:Keyboard IRQ
Posted: Wed Oct 30, 2002 8:28 am
by Pype.Clicker
Tom wrote:
COOL! I found out how to make my own interrupt ( 30h ) that prints whatever I want?
Are hardware interrupts slow?
If not, could I make my OS based ( verysmall partly ) on ints?
Thank you,
if you're in pmode, an interrupt is *really* slower than a function pointer. you should avoid interrupt calling as long as you remains in kernel mode (thus, having kernel-to-kernel interrupts is imho a bad idea).
for user-to-kernel, the only alternative is the call gate.
an INT instruction through an interrupt gate is about 99 cycles, and i guess the call gate will be roughly the same.
perhaps you can consider using SYSCALL extension (processor-specific: not the same code under AMD and Intel, unfortunately -- has a lot of context constraints, too
Re:Keyboard IRQ
Posted: Wed Oct 30, 2002 10:00 am
by Paul
That's interesting because I was just thinking about this very same topic last night when I was trying to sleep. I was thinking how user programs would call the kernel. All of my kernel functions can be triggered with INT 40h but I was thinking of a faster way.
My kernel always resides at 0x100000 so couldn't user programs just call kernel functions directly? Their entry point would always be predictable. Of course, there should be a KERNEL.H file or something that assigns function names so you aren't just calling NUMBERS. So, I would do something like this:
fillscreen(0xffffff)
And kernel.h defines 'fillscreen' as being a function, with one integer parameter that points to 0x107324 (for example.)
You might want a JUMP table instead so that if you change your kernel code, you don't have to regenerate your function header file. (not to mention corrupting any user programs you already wrote.) And if this jump table came at the BEGINNING of your kernel, the jump table itself will not get moved when you add/delete kernel code. Of course, you would need a jump PAST the jump table at the beginning.
What do you think?
Re:Keyboard IRQ
Posted: Wed Oct 30, 2002 11:09 am
by Tom
sorry but...This is going abit off topic now...now I know ints are slow, so I won't use them but...
Is there a keyboard IRQ tutorial/code?
Re:Keyboard IRQ
Posted: Wed Oct 30, 2002 12:40 pm
by Tim
My kernel always resides at 0x100000 so couldn't user programs just call kernel functions directly?
No, don't do this. Provide a way of calling kernel functions through interrupts.
The reason for this is that the kernel code will want to run in ring 0 (privileged) whereas user code needs to be in ring 3 (unprivileged). If ring 3 code tries to call ring 0 code the CPU will trigger a page fault or general protection fault.
Interrupts are slower than normal function calls but the protection is worth it. If you're worried about the speed decrease, consider putting more code into the kernel. For example, instead of calling the kernel once per graphics command, why not batch commands in a memory block then trigger a kernel interrupt and pass that block? Then the kernel can run through each command in the block before returning.
Re:Keyboard IRQ
Posted: Wed Oct 30, 2002 12:45 pm
by Tom
:'(
ok, but i'm not at the point but I would really like a keyboard IRQ code/tutorial.........
Re:Keyboard IRQ
Posted: Wed Oct 30, 2002 4:27 pm
by elias
wow. ive onyl written a boto loader and a test kjernerl, but havnt goten to test it yet cuz i dont have a working floppy drive.