Internal Keyboard Buffer Full Problem with Bochs

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
catcalls
Posts: 5
Joined: Sun Jun 19, 2011 5:53 pm

Internal Keyboard Buffer Full Problem with Bochs

Post by catcalls »

Hi Forum,

I'm developing an OS in 32-bit Assembler. The area being worked on at the moment is the Keyboard driver and Multi-tasking. There seems to be a problem somewhere that causes an error with my kbrd_Driver.

Internal KBRD Buffer Full. Ignoring scan code (ab)

That is basically the problem. I cannot type to the screen when that happens. It seems to happen _after_ I set scan code set 2. That's when it all screws up?

Any ideas?

Thank you in advance,

Cat.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Internal Keyboard Buffer Full Problem with Bochs

Post by thepowersgang »

Well, that seems to me that your are not emptying the buffer on interrupt.
Afaik, Scancode set 2 uses multi-byte scancodes, so you need to remember to read all bytes of the scancode.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
catcalls
Posts: 5
Joined: Sun Jun 19, 2011 5:53 pm

Re: Internal Keyboard Buffer Full Problem with Bochs

Post by catcalls »

Code: Select all

    474 IntKBrd:
    475         pusha
    476 ;       mov ax, ds
    477 ;       push eax
    478 ;       mov ax, 0x10
    479 ;       mov ds, ax
    480 ;       mov es, ax
    481 ;       mov fs, ax
    482 ;       mov gs, ax
    483 
    484 ;.spin:
    485 ;       in al, 0x64
    486 ;       and al, 0x01
    487 ;       jz .spin
    488         in al, 0x60
    489         mov edi, 0x0B8000
    490 ;       mov bl, 'C'
    491         mov bl, al
    492         mov bh, 00011111b
    493         mov word [edi], bx
    494 
    495         mov al, 0x20
    496         out 0x20, al
    497 
    498 ;       pop ebx
    499 ;       mov ds, bx
    500 ;       mov es, bx
    501 ;       mov fs, bx
    502 ;       mov gs, bx
    503 ;
    504         popa
    505 ;       add esp, 8
    506 ;       sti
    507         IRETD
This is the code for my Keyboard Interrupt. Some of it is commented out because it crashed on entry or exit.

As you can see I read the byte from the Keyboard. Do I need to read two bytes or more>?

What do you think?

Kind regards,

Cat
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Internal Keyboard Buffer Full Problem with Bochs

Post by thepowersgang »

Hmm... a look at my (outdated) code seems to say that there is one interrupt per byte. Are you acknowledging the interrupt with the PIC (well, is your handler running more than once?)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
catcalls
Posts: 5
Joined: Sun Jun 19, 2011 5:53 pm

Re: Internal Keyboard Buffer Full Problem with Bochs

Post by catcalls »

thepowersgang wrote:Hmm... a look at my (outdated) code seems to say that there is one interrupt per byte. Are you acknowledging the interrupt with the PIC (well, is your handler running more than once?)
Hi TPG,

the _outb 0x20, al_ supposed to acknowledge the PIC. Is that not right?

I've also modified the code to use;

Code: Select all

outb 0xa0, al
where al = 0x20.

Weird problem, no?
catcalls
Posts: 5
Joined: Sun Jun 19, 2011 5:53 pm

Re: Internal Keyboard Buffer Full Problem with Bochs

Post by catcalls »

What I'm currently thinking right now is this;

When Scan Code Set 2 is set, I do an 'Unmask IRQ 1'.

But, later on in the code, I enable Interrupts, but then set the timer.

I've been commenting out some code, but from what I can gather, it seems interrupts are not enabled.

How do I enable Interrupts!?

Should I insert an STI somewhere in the code, or is it more complicated than that?

Kind regards,

Cat
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Internal Keyboard Buffer Full Problem with Bochs

Post by thepowersgang »

Well, to enable interrupts, STI should be somewhere in your main code path (i.e. not in the interrupt handler).

(Sorry about missing the PIC ACK, it's early in the morning for me)

Probably the best thing to do is to check if the handler is being called, dumping the scancode each time.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
catcalls
Posts: 5
Joined: Sun Jun 19, 2011 5:53 pm

Re: Internal Keyboard Buffer Full Problem with Bochs

Post by catcalls »

Sorted it!

The IntTimer interrupt was being executed, even though I disabled enabling the timer 'tick'.

There fore, I thought to myself, if I _have_ to out to 0xa0 and 0x20 the hex 0x20 for each interrupt, then perhaps I should put that code into the timer as well, eh?

As soon as I did, I noticed that the X (timer output to screen) was flickering when I pressed a key!

So, I commented out the print X code in teh timer, and ran bochs again. I can write to the screen via keyboard now!!!

Yay!

Sure, I need to translate the scancodes to proper characters now. And, move the cursor along and backwards on delete.

But, it's firing! BOY! It's firing!!!
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Internal Keyboard Buffer Full Problem with Bochs

Post by gerryg400 »

if I _have_ to out to 0xa0 and 0x20 the hex 0x20 for each interrupt
Not quite. You need to ack the PIC (or PICs) that interrupted you. Because of the way the second PIC is chained through intr2 on the first PIC, you should

Code: Select all

   if (intr_num is 0 to 7) {
      port 0x20 = 0x20
   }
   elseif (intr_num is 8 to 15) {
      both ports 0x20 and 0xa0 = 0x20
   }
Note, I've never really thought about it before. I'm not sure which PIC should be ACK'd first. I usually ACK port 0x20 then port 0xa0, but that is probably not correct.

Does anyone know which way round it should be ?
If a trainstation is where trains stop, what is a workstation ?
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Internal Keyboard Buffer Full Problem with Bochs

Post by Chandra »

gerryg400 wrote:
if I _have_ to out to 0xa0 and 0x20 the hex 0x20 for each interrupt
Not quite. You need to ack the PIC (or PICs) that interrupted you. Because of the way the second PIC is chained through intr2 on the first PIC, you should

Code: Select all

   if (intr_num is 0 to 7) {
      port 0x20 = 0x20
   }
   elseif (intr_num is 8 to 15) {
      both ports 0x20 and 0xa0 = 0x20
   }
Note, I've never really thought about it before. I'm not sure which PIC should be ACK'd first. I usually ACK port 0x20 then port 0xa0, but that is probably not correct.

Does anyone know which way round it should be ?
I don't think there really is hard and fast rule for acknowledging the PIC. Even then, I acknowledge the Slave Controller(0xA0) and then to the Master Controller(0x20). I believe either way should work, though.

Hmm.... since this is about Keyboard and Timer, it really doesn't count because you got to acknowledge only the Master Controller, afterall.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Internal Keyboard Buffer Full Problem with Bochs

Post by gerryg400 »

Hmm.... since this is about Keyboard and Timer, it really doesn't count because you got to acknowledge only the Master Controller, afterall.
True, that's what I was originally saying but my thoughts wandered. And I now believe that you are correct, it doesn't matter which one is ACK'd first.

I hope catcals got that original point.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Internal Keyboard Buffer Full Problem with Bochs

Post by Combuster »

berkus wrote:I may reason that acknowledging Master controller first is the right thing to do, but this is purely a thought excercise and I believe PIC was made to allow either order.
A similar thought exercise suggests me to ack the slave first to preserve interrupt priority at all times.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply