OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 8:10 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: PS2 mouse IRQ
PostPosted: Mon Jun 02, 2003 11:13 am 
Hello

I'm trying to manage how IRQ12 works, is that the same like IRQ1 or IRQ0. When I'm trying to put code (in IRQ12), that puts pixel at coordinate, but when I press button or move mouse, nothing hapens.

Thanks for help.


Top
  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Mon Jun 02, 2003 11:36 am 
You need to initialize the keyboard controller and the attached PS/2 mouse for this to work. http://osdev.neopages.net/ has some information on this. Also, the only mice that uses IRQ 12 are PS/2 mice (not serial or USB).


Top
  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Mon Jun 02, 2003 3:09 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
hmm ... a few things ...
1. the PS2 mouse links at Bona Fide are especially hard to follow: it took me about 2 weeks to get something else than "server did not respond" ... maybe it's just my ISP.

2. those links talk about mouse protocols (between the mouse and the controller), but very little info about programming the PS/2 (or serial :-& -- but i guess this one can be reduced to programming the COMx UART once you know the protocol about bytes etc.).

So if one of you want to make a tutorial about mouse programming and post it at Bona Fide (i won't do it myself: i haven't programmed the mouse yet :p)

So far, i collected a few info, including ISR code from Tim Robinson and PS2 mouse initialisation sequence.

The SearchBot also found several links posted by frank one year ago.

Also remind that prior to receive IRQ12, you must enable this interrupt at the slave PIC (will be #4, iirc) and the cascade interrupt at master PIC (#2).
You must also send a "end of interrupt" to both PICs at the end of your ISR (i.e. "mov al, 20h; out 20h,al; out 0a0h, al").

Note that despites the "mouse packet" is multi-byte, you can only read bytes one by one at the i8042. Thus, it will take 3 mouse interrupts before you actually can decode the message the mouse sent.

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Tue Jun 03, 2003 1:48 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
btw, Tim, there is a comment in your PS2mouse code that says
Code:
/* These strings nicked from gpm (I_imps2): I don't know how they work... */
    static uint8_t s1[] = { 0xF3, 0xC8, 0xF3, 0x64, 0xF3, 0x50, 0 };
    static uint8_t s2[] = { 0xF6, 0xE6, 0xF4, 0xF3, 0x64, 0xE8, 0x03, 0 };


according to PS2 mouse resource from Adam Chapweske, they are settings for sampling rate.

after having set the sampling rate for the 3rd axis (wheel), the Micros0ft Intellimouse enables extension (4th byte for wheel).

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Tue Jun 03, 2003 3:37 am 
The problem was, that pefore using ps2 aux commands use first outportb(0x64,0xD4) and then command. :D
Now in www.stormos.ten.lt Storm OS PS2 mouse works.


Top
  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Tue Jun 03, 2003 3:47 am 
Maybe it would be a good idea to write understandable tutorial about PS2 mouse.


Top
  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Wed Jun 04, 2003 6:18 pm 
Anyone know why only two scancodes are going through during a mouse interrupt? THe interrupt itself seems to be working fine (borrowed a lot of ideas from linux to get it to work), but i only get two bytes of scancodes per interrupt before the "mouse buffer full" flag isnt set anymore, and everything i read says it should be three bytes... Any ideas?

Thanks!


Top
  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Thu Jun 05, 2003 1:03 am 
Maybe you haven't good initialized mouse...
Before taking byte try to check first 2 lower bytes from 0x64, and if ok THEN read byte from 0x60.

For me is the problem that on VMware mouse works fine, but on real PC seems to respond to moves but on screen thust puts the same values x and y ???

Maybe we could solve this problem both ;)


Top
  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Thu Jun 05, 2003 1:41 am 
Brandon: you only get one scancode byte from the mouse per interrupt, not two or three. You've got to queue them up and only process them in multiples of 3.


Top
  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Thu Jun 05, 2003 7:47 am 
That's weird, because I'm getting two, and both seem valid...should I just ignore the second one?

The first one I get is has bit 4 set (like i've read should always be set in the status byte) plus another bit depending on which way I'm moving the mouse (or if i'm clicking one of the mouse buttons), so i'm guessing this is the correct first byte that i've read about that describes the mouse buttons and direction and any overflow that may have happened.

And the second byte I get has a number that's around 1 or 2 usually, but higher if I move the mouse quickly. However, this number is only non-zero if i'm moving the mouse horizontally. So this seems to be the X translation information.

So the only thing I'm missing is the Y translation information, and that never comes across. I have the interrupt routine display what it reads every time it is called, and it is only called once per mouse move, and it only can read two bytes of information. If I queued the bytes and translated in groups of three, then I would be using the status byte of one movement as the status, the X translation of that same movement as the X translation, and then the status byte of the next movement as the Y translation. This doesn't seem right?

I keep checking the mouse buffer full flag and output buffer full flag between reading scancodes, and there are definitely two valid scancodes for me to read per movement, but there is never a third one, and the first one of the next interrupt is definitely the status byte, so I have no idea what to do.

Thanks for any help anyone can offer!

- Brandon

P.S. I'm using bochs for testing, i dont know if that makes a difference.


Top
  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Thu Jun 05, 2003 9:14 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
well, so far, this is just speculation, but it could occur that BOCHS only detects *a posteriori* that you read 2 bytes from the 8042 instead of one, and then discards the transmission of the 3rd one ... What does it give if you just read one byte per interrupt ?

btw, what version of BOCHS is it ? did you made sure it has complete support of PS/2 mouse ?

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Thu Jun 05, 2003 9:23 am 
I figured it out. I'm sorry for the trouble, turned out it was my fault (of course ;) ). Before, I was having trouble with only one interrupt going through, and then no more mouse or keyboard interrupts would go through. It turns out, I was only resetting the master PIC, not the slave PIC as well, which was causing this problem. However, while trying to fix it, one of the things I added was code to reset the mouse after every interrupt. This didn't fix that problem of course, but I forgot to remove it, and it was causing this one. As soon as I removed the reset code, i started getting all three interrupts (as it turns out, at least in bochs, i get two scancodes on the first interrupt and one on the second).

Thanks for all your help.

- Brandon


Top
  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Thu Jun 05, 2003 10:29 am 
I'm confused, Pype sais, that just one byte can be received per interrupt, Brandon sais, that 2 and in secont int 1 more.

I'm using VMware workstation 4.0, I get per ONE interrupt all 3 bytesa and it works fine, but when I'm restarting computer and starting my OS it seems not to working... ???

Then how it really is?
Bye


Top
  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Thu Jun 05, 2003 11:11 am 
Before you read a byte, you should check the keyboard controller's status register, to make sure that there's a byte available to read:
Code:
bool ps2Isr(device_t *dev, uint8_t irq)
{
    if ((in(KEYB_CTRL) & 0x01) != 0)
    {
        Ps2Mouse *mouse;
        mouse = (Ps2Mouse*) dev;
        mouse->data[mouse->bytes++] = in(KEYB_PORT);
        if (mouse->bytes >= 3 + mouse->has_wheel)
        {
            ps2StartIo(mouse);
            mouse->bytes = 0;
        }

        return true;
    }

    return false;
}


Top
  
 
 Post subject: Re:PS2 mouse IRQ
PostPosted: Thu Jun 05, 2003 12:03 pm 
I think that if I were to only read one scancode at a time it would still work fine. It's just that there happen to be two ready by the time the interrupt is called (maybe because of bochs), and my code reads both of them. I was having trouble getting my code to work (because of the PIC resetting problem), so I tried to mimic linux and see if that helped. Here's my interrupt code:

Code:
{
    unsigned char status = inportb(0x64);

    printf("Mouse handler, status = 0x%X", status);
    while (status & KBD_STAT_OUT_BUFF_FULL)
    {
        unsigned char scancode = inportb(0x60);

        if (status & KBD_STAT_MOUSE_OUT_BUFF_FULL)
            printf(", received scancode 0x%X", scancode);

        status = inportb(0x64);
    }
   
    printf(", status = 0x%X\n", status);
}


Here's an example output for moving the mouse right one pixel:

Code:
Mouse handler, status = 0x35, received scancode 0x8, received scancode 0x1, status = 0x14
Mouse handler, status = 0x35, received scancode 0x0, status = 0x14


This is because I'm reading the scancodes as long as there is one available, instead of just an if to test if one is available, so I can read more than one if it is available.
If this were run on a computer that only fed one per interrupt, it *should* output something like the following:

Code:
Mouse handler, status = 0x35, received scancode 0x8, status = 0x14
Mouse handler, status = 0x35, received scancode 0x1, status = 0x14
Mouse handler, status = 0x35, received scancode 0x0, status = 0x14


So this way, it should work if there is only one, or even if all threee are available per interrupt (btw, i modified my code with just an if instead of a while, and it DID read just one scancode per interrupt correctly)

Also, this code will be merged with the keyboard interrupt handler, and if the mouse outbuffer full flag is set the scancode will be sent to the mouse queue, otherwise it will be sent to the keyboard queue, that is why the check for mouse output buffer full is inside the while loop for the keyboard buffer being full.

- Brandon


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 584 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group