problem in ps\2 mouse driver

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
shahzad

problem in ps\2 mouse driver

Post by shahzad »

I'm trying to write a ps2 mouse driver.Ps\2 mouse uses IRQ 12.So i need to reprograme slave pic chip .In the following code i've tried to reprograme master and slave pic chips
so that 70h is for irq 0 on master pic and 08h is for irq 0 on slave pic.
Has i set everything correctly in the following code?

Code: Select all

;;;;;icw1;;;;;;;
mov al,00010001b 
out 20h,al       
out 0A0h,al      
;;;;;;;icw2;;;;;;;
mov al,70h    
out 21h,al    
mov al,08h   
out 0A1h,al  

;;;;;;;icw3;;;;;;;;
mov al,00000100b    
out 21h,al          
mov al,2h     
out 0A1h,al   

;;;;;;icw4;;;;;;;
mov al,00000001b    
out 21h,al          
out 0A1h,al         

;;;;ocw1;;;;
mov al,11111111b
out 21h,al
mov al,11110111b
out 0A1h,al
  
After reprogramming pic ,i've initialized the ps\2 mouse and set the handler so that a character 'm' is printed when it recieves the interrupt from mouse.
But nothing is printed .
Please tell me where i'm making mistake.

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;ps\2 mouse;;;;;
mov bl,0x60
call write_controller
mov bl,0x3
call write_command
mov bl,0xa8
call write_controller
mov bl,0xd4
call write_controller
mov bl,0xfa
call write_command
hang:

jmp hang

;;;;;;;;;;;;;;;;;;;;
write_controller:
wait1:  
    in al,0x64
    and al,0x02
    cmp al,0
    jne wait1 
          mov al,bl
          mov dx,0x64
          out dx,al
ret
;;;;;;;;;;;;;;;;;;;
write_command:
wait2:  
        in al,0x64
        and al,0x02
        cmp al,0
        jne wait2 

         mov al,bl
         mov dx,0x60
         out dx,al
ret


;;;;;;;;handler;;;;;;;;;;;

mouse:

            mov ax,LINEAR_SEL
??????mov gs,ax
??????mov byte[gs:0xB8000],'M'


mov dx,0xa0
mov al,0x20
out dx,al
mov dx,0x20
mov al,0x20
out dx,al

iret

i've attached the complete source code so that you can identify if i'm making mistake anywhere else. [attachment deleted by admin]
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:problem in ps\2 mouse driver

Post by Candy »

default error: you mask the interrupt.

Always remember interrupts are cascaded, so if you mask the slave chip you mask all their interrupts. Check your code for the mask for the master chip (hint: it's mask all)
shahzad

Re:problem in ps\2 mouse driver

Post by shahzad »

you r right in pointing out that i masked the slave pic chip.
So i changed ocw1 to enable slave pic chip

Code: Select all

;;;;ocw1;;;;
mov al,11111011b
out 21h,al
mov al,11110111b
out 0A1h,al

But still no response from mouse.
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Re:problem in ps\2 mouse driver

Post by gaf »

Hi
I don't think it's a good idea to remap the mouse IRQ to int 12. Normally interrupts 0-15 are for exceptions and 16-31 are intel reserved.

I attached my PIC-Code and the IDT; it will map IRQ0 to int 0x20 an IRQ8 to int 0x28.

regards,
gaf

[attachment deleted by admin]
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:problem in ps\2 mouse driver

Post by Candy »

gaf wrote: I don't think it's a good idea to remap the mouse IRQ to int 12. Normally interrupts 0-15 are for exceptions and 16-31 are intel reserved.
well, 0-8, 10-14 and 16-19 are defined exceptions. 9, 15 and 20-31 are reserved.

Still, the point holds, use 32-47 for the external interrupts (or any other place, but NOT below 32d).

Also note that irq12 is decimal, and that it is mapped to, in the new mapping, 44.

Did you map the correct interrupt?
shahzad

Re:problem in ps\2 mouse driver

Post by shahzad »

infact i was enabling the wrong irq in slave pic.It should be

Code: Select all

;;;;ocw1;;;;
mov al,11111011b
out 21h,al
mov al,11101111b
out 0A1h,al
Now i get 'm' printed once and nothing after that.I've changed the code to print 'm' so that it is printed at different position to previous.
Please tell why mouse interrupt is generated only once.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:problem in ps\2 mouse driver

Post by Candy »

shahzad wrote: Now i get 'm' printed once and nothing after that.I've changed the code to print 'm' so that it is printed at different position to previous.
Please tell why mouse interrupt is generated only once.
Again, one of the very frequently asked questions. Do you send an EOI to both the slave & master PIC?
shahzad

Re:problem in ps\2 mouse driver

Post by shahzad »

i was sending EOI to both master and slave pic chips.
Infact i was making two errors.
One was that i was not reading data from port 0x60 and if you don't read it ,further interrupts will not be generated.
the other error was that i was sending wrong value to mouse.
the last command that i send to mouse should be

Code: Select all

mov bl,0xf4
call write_command
and i was sending 0xfa.
now i'm getting all interrupts on all mouse events.
It is true that 0 to 31 are reserved for exceptions but if you are sure that your code is not generating any exception you can use those vectors for short term use.
Post Reply