Can't get keyboard working when booting with GRUB

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
KSMb
Posts: 7
Joined: Tue Sep 11, 2018 9:42 am

Can't get keyboard working when booting with GRUB

Post by KSMb »

Hi!
I'm trying to get my toy-os working with GRUB since i want to use it on real hardware.
For this reason i implemented a multiboot header (as described here) and a minimal grub.cfg file.

All seems to works fine(IRSs and IRQs are correctly loaded) except for the keyboard driver:
for some reason i can't type nothing into the console.
The weird thing is that, without GRUB(loading the bootsector as a floppy image in QEMU), the keyboard driver works and i can type things on it.

Here on the forum i read that this can be a problem related with the GDT, but i've implemented it and it is loaded successfully before actually loading the kernel, and,as i said before,it works without QEMU.

What could be the cause of this problem?

If it can be helpful i post the source code of the GDT:

Code: Select all

gdt_start:
    dd 0x0
    dd 0x0

; code segment descriptor
gdt_code:
    dw 0xffff 
    dw 0x0
    db 0x0 
    db 10011010b 
    db 11001111b 
    db 0x0

; data segment descriptor
gdt_data:
    dw 0xffff
    dw 0x0
    db 0x0 
    db 10010010b 
    db 11001111b 
    db 0x0 )

gdt_end: 


gdt_descriptor:
    dw gdt_end - gdt_start - 1 ; the size

    dd gdt_start ; start address of the gdt

CODE_SEG equ gdt_code - gdt_start
DATA_SEG equ gdt_data - gdt_start
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Can't get keyboard working when booting with GRUB

Post by iansjack »

You really need to provide a link to an online repository of sour source code before anyone can make sensible suggestions. Posting random selections is unlikely to pinpoint the problem.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Can't get keyboard working when booting with GRUB

Post by Brendan »

Hi,
KSMb wrote:All seems to works fine(IRSs and IRQs are correctly loaded) except for the keyboard driver:
for some reason i can't type nothing into the console.
The weird thing is that, without GRUB(loading the bootsector as a floppy image in QEMU), the keyboard driver works and i can type things on it.
Consider this:
  • Computer starts, GRUB displays a menu to select which OS to boot
  • User presses the enter key to start booting something
  • GRUB loads the kernel and disables IRQs with CLI
  • The user takes their finger off of the enter key, causing PS/2 controller to send an IRQ that remains "pending" because IRQs were disabled with CLI
  • The OS reconfigures the PIC chip, causing that pending IRQ to be forgotten
The end result is that the PS/2 controller is left in a "one-byte buffer full" state waiting for an IRQ handler to read from its buffer, where the IRQ was lost so nothing will read the buffer, and where the PS/2 controller can't accept any more bytes from the keyboard because that buffer is full.

To work around this; you can do a few dummy "in al,0x60" instructions to clear the buffer (the "Step 4" mentioned here).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
KSMb
Posts: 7
Joined: Tue Sep 11, 2018 9:42 am

Re: Can't get keyboard working when booting with GRUB

Post by KSMb »

To work around this; you can do a few dummy "in al,0x60" instructions to clear the buffer (the "Step 4" mentioned here).
Thanks for your reply.

I've just tried to clear the buffer on the port 0x60 but the situation still the same...from the wiki page about the PS/2 Controller i also tried to implement the Cpu Reset but without any success.
Post Reply