Iterface Keyboard - IRQ1

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
User avatar
prajwal
Member
Member
Posts: 154
Joined: Sat Oct 23, 2004 11:00 pm
Contact:

Iterface Keyboard - IRQ1

Post by prajwal »

I'm a using bochs emulator, on which i'm testing my tiny test 32bit OS

As per my knowledge goes PIC init is correct, Handler for IRQ1 = int 0x09
is correct... but even then i'm unable to interface KeyBoard...
when bochs boots the OS the KB doesn't function...

Right now the function of int 0x09 (IRQ1) handler is just to display
letter 'K' for any key press i.e, for every int 0x09 (IRQ1) received....

If I manually (in the code) call int 0x09... Handler works as expected...
But KeyBoard button press has no response...

Is there any bochs settings for KB to be enabled?

The KB type is set to mf in .bochsrc

I tried with remap enabled and disabled in .bochsrc..... but no use...

can someone help me......
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Re: Iterface Keyboard - IRQ1

Post by gaf »

Hi,
Bochs should emulate a keyboard by default. Since you can call the IRQ handler in software, I suppose that it might really be your PIC code.
Maybe you could post it ?

regards,
gaf
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Iterface Keyboard - IRQ1

Post by JAAman »

also you really should remap the pic to 0x20 (or higher) so that it doesnt overlap the CPU exceptions -- but this prob wont fix your problem
User avatar
prajwal
Member
Member
Posts: 154
Joined: Sat Oct 23, 2004 11:00 pm
Contact:

Re: Iterface Keyboard - IRQ1

Post by prajwal »

Here's the PIC init code
NOTE: Calling int 0x09 in software works...... But KB press has no response.....

;Sending ICW1 to master and slave PIC
mov al,00010001b
out 0x20,al
out 0xA0,al

;Sending base vector number of master and slave PIC
mov al,20h ;base vector number of master PIC
out 0x21,al
mov al,28h ;base vector number of slave PIC
out 0xA1,al

;Sending connection parameters between the PICs to the PICs
mov al,00000100b ;IRQ2 is connected to slave PIC
out 0x21,al
mov al,2h ;IRQ2 of master PIC is used for the slave PIC
out 0xA1,al

;Sending ICW4 to master and slave PIC
mov al,00000001b ;Intel environment, manual EOI
out 0x21,al
out 0xA1,al

;This ends the initialization of the PICs

------------------------------------------------------------------------

;The KB Handler -- Sample Handler, just to check it is invoked or not
KB_HANDLER:

pusha
push gs
mov ax,LINEAR_SEL
mov gs,ax

mov ebx, [KB_LOC] ; KB_LOC is a Double word initialzed to 0xb8000
INC ebx
INC ebx ; Every IRQ1 causes a 'K' to be displayed at consecutive location

mov byte[gs:ebx],'K'

mov al,20h ;EOI command
out 020h,al ;Sending the command to the slave PIC
pop gs
popa
iret
theubu
Member
Member
Posts: 38
Joined: Wed Dec 01, 2004 12:00 am
Location: New York
Contact:

Re: Iterface Keyboard - IRQ1

Post by theubu »

srinivasa,

Hey... I just looked over it quickly but it looks like you're masking your PIC to offset 0x20 which means IRQ is firing at 0x21...

Also I didn't see you masked all your ints at the end of your pic initialization outbyte to 0x21 and 0xA1 0xFF to make sure everything is in the correct state

I also didn't see anywhere in which you were turning on IRQ 1

-Christopher
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Re: Iterface Keyboard - IRQ1

Post by gaf »

You can mask the IRQs like this:

mov al,0xFD ; IRQ #0-7
out 0x21,al
mov al,0xFF ; IRQ #8-15
out 0xA1,al

Every bit stands for an IRQ...
11111111 - all IRQ masked
00011110 - IRQs 0, 5, 6, 7 not masked
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Iterface Keyboard - IRQ1

Post by JAAman »

do you have your ISR registered to INT9? because as theubu said it looks like your mapping the IRQs to 20 instead of 8 which makes IRQ1 INT 0x21 not 0x09
User avatar
prajwal
Member
Member
Posts: 154
Joined: Sat Oct 23, 2004 11:00 pm
Contact:

Re: Iterface Keyboard - IRQ1

Post by prajwal »

I'm extremely sorry for that wrong ICW2 code.....
Base vector init code ---- ICW2 is as follows:-

mov al,08h ;08h as interrupt number for IRQ0 of the master PIC
mov 21h,al ;sending ICW2 to the master PIC
mov al,70h ;70h as interrupt number for IRQ0 of the slave PIC
mov 0A1h,al ;sending ICW2 to the slave PIC

I missed the masking code to post..... I'v masked all interrupts
except IRQ1....

Please Note That int 0x09 in software (i.e, when called in code) works
as expected.....


NOTE:- I'M USING USB KEYBOARD..... DOES BOCHS SUPPORT IT...
IS THAT AN ISSUE HERE.....
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Iterface Keyboard - IRQ1

Post by JAAman »

shouldnt be a prob with the keyboard(though i dont know for sure)

do you have a reason for putting it at int9? because that can cause serious problems later actualy int9 shouldnt be a prob since its reserved on sys later than 386 but your others will:
int8 (your clock) will be called with any double-fault
int14 (your floppy) will be called on every page-fault
other devices are usually assigned to IRQ5 which maps to int13: your GPF -- the most important exception that there is

just a warning mabey you have a reason for mapping it where you do but mabey you just didnt realise the dangers of this mapping (its typical to map them to 0x20 and 0x28 in pm)
User avatar
prajwal
Member
Member
Posts: 154
Joined: Sat Oct 23, 2004 11:00 pm
Contact:

Re: Iterface Keyboard - IRQ1

Post by prajwal »

Thanks JAAman.....

I'll try ur suggestion today..... I didn't know this. I'm entirely new to this
field.....
Last edited by prajwal on Fri Nov 27, 2020 11:14 pm, edited 1 time in total.
aymanmadkour
Posts: 11
Joined: Sat Feb 05, 2005 12:00 am

Re: Iterface Keyboard - IRQ1

Post by aymanmadkour »

Hi...

There is an important note about keyboard ISR:

For the keyboard ISR to function properly, you MUST read one byte (scancode) from port 60h (keyboard port) , because the keyboard will not send any more interrupt signals until the data is read.
User avatar
prajwal
Member
Member
Posts: 154
Joined: Sat Oct 23, 2004 11:00 pm
Contact:

Re: Iterface Keyboard - IRQ1

Post by prajwal »

Yes aymanmadkour.... I tried it..... it worked....
Post Reply