keyboard interrupt

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
spaghettios
Posts: 7
Joined: Mon Feb 20, 2012 11:34 am
Location: Italia

keyboard interrupt

Post by spaghettios »

Help! I've a problem with keyboard interrupt. I'm sure that Irq handler is right because the timer interrupt prints its message and when I initialize the keyboard interrupt I can see its message too.
But when I press a key I have nothing. I post files. Thanks.

P.S.: I'm following JamesM tutorial and I'm adding keyboard on his structure.
Attachments
keyboard.c
(1.34 KiB) Downloaded 329 times
descriptor_tables.c
(3.53 KiB) Downloaded 144 times
isr.c
(2.61 KiB) Downloaded 209 times
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: keyboard interrupt

Post by Combuster »

I noticed a rather questionable style of C and stopped searching for the actual bug in question when I noticed functions with different prototypes across files. Use header files for anything not defined locally, and pass -Wall -Wextra -pedantic -Werror to the compiler to get at least something in order.

After that, the interrupt handler has to do little more than reading the scancode and storing it somewhere. You seem to do a lot of things that are not necessary, and your lack of comments and sensible names make it rather unobvious what you are intending to do.
"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 ]
spaghettios
Posts: 7
Joined: Mon Feb 20, 2012 11:34 am
Location: Italia

Re: keyboard interrupt

Post by spaghettios »

Thank for your suggest. I'm working to remove all warning with your options and now I've only:

ISO C90 forbids mixed declarations and code

I'll try the code and if something goes wrong I'll well comment the code before posting it.

Thanks a lot!
spaghettios
Posts: 7
Joined: Mon Feb 20, 2012 11:34 am
Location: Italia

Re: keyboard interrupt

Post by spaghettios »

I always see "keyboard interrupt recieved" only when I enable it. But when I press a key the interrupt isn't sent and bochs gives me:

"internal keyboard buffer full, ignoring scancode"

This time I've added comments.
Attachments
keyboard.c
(1.38 KiB) Downloaded 150 times
keyboard.h
(293 Bytes) Downloaded 89 times
spaghettios
Posts: 7
Joined: Mon Feb 20, 2012 11:34 am
Location: Italia

Re: keyboard interrupt

Post by spaghettios »

I've tried Qemu but is the opposite. It gets a lot of keyboard interrupt and crashes.
spaghettios
Posts: 7
Joined: Mon Feb 20, 2012 11:34 am
Location: Italia

Re: keyboard interrupt

Post by spaghettios »

On qemu keyboard interrupt works right on Bochs not.
Is it possible?

Here is it my .bochrc:


config_interface: textconfig
#display_library: sdl
display_library: x, options="gui_debug"
romimage: file=/usr/share/bochs/BIOS-bochs-latest, #address=0xf0000
megs: 32
vgaromimage: file=/usr/share/vgabios/vgabios.bin
floppya: 1_44=floppy.img, status=inserted
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata1: enabled=0, ioaddr1=0x170, ioaddr2=0x370, irq=15
ata2: enabled=0, ioaddr1=0x1e8, ioaddr2=0x3e0, irq=11
ata3: enabled=0, ioaddr1=0x168, ioaddr2=0x360, irq=9
#ata0-master: type=disk, path="c.img", mode=flat, cylinders=20, heads=16, spt=63
ata0-slave: type=cdrom, path="/dev/cdrom", status=inserted

boot: floppy, disk

cpu: ips=500000
floppy_bootsig_check: disabled=0
log: /dev/stdout
panic: action=ask
error: action=report
info: action=report
debug: action=ignore
debugger_log: -
com1: enabled=1, dev=/dev/ttyS0
#parport1: enabled=1, file="/dev/lp0"
sb16: midimode=1, midi=/dev/midi00, wavemode=1, wave=/dev/dsp, loglevel=2, log=/dev/stdout, dmatimer=600000
vga_update_interval: 300000
keyboard_serial_delay: 250
keyboard_paste_delay: 100000
#floppy_command_delay: 500
mouse: enabled=1
private_colormap: enabled=0
#ne2k: ioaddr=0x240, irq=9, mac=b0:c4:20:00:00:00, ethmod=linux, ethdev=eth0
#keyboard_mapping: enabled=0, map=/usr/share/bochs/keymaps/x11-pc-de.map
#keyboard_type: mf
#user_shortcut: keys=ctrlaltdel
#magic_break: enabled=1
#cmosimage: cmos.img
#load32bitOSImage: os=nullkernel, path=../kernel.img, iolog=../vga_io.log
#load32bitOSImage: os=linux, path=../linux.img, iolog=../vga_io.log, initrd=../initrd.img
#i440fxsupport: enabled=1
#usb_uhci: enabled=1, ioaddr=0xFF80, irq=10
#text_snapshot_check: enable
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: keyboard interrupt

Post by JamesM »

spaghettios wrote:Thank for your suggest. I'm working to remove all warning with your options and now I've only:

ISO C90 forbids mixed declarations and code

I'll try the code and if something goes wrong I'll well comment the code before posting it.

Thanks a lot!
Switch to C99. (-std=c99). Job done.
spaghettios
Posts: 7
Joined: Mon Feb 20, 2012 11:34 am
Location: Italia

Re: keyboard interrupt

Post by spaghettios »

I've moved all declaration up in my functions because I'm tryng to respect more standards and to have a cleaner and more portable code. For exemple SDCC need this convention. So far, after some work I've got a source that compile with -pedantic, -Wall ,-Wextra and -Werror flags.
Another question, now I have my kernel well working both on qemu and my real computer, only bochs seems not to recieve keyboard interrupt. What about it, is it possible? Many people use bochs without troubles so I can't solving the problem by leaving bochs because of a "bug".
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: keyboard interrupt

Post by turdus »

Sometimes irq is fired prior to scancode available, so you should check for that. Also don't forget to acknowledge. This is how I do this:

Code: Select all

int i,scancode;
//get scancode with "timeout"
for(i=1000;i>0;i++) {
    if(inb(0x64)&1==0) continue;   //check if scancode is ready
    scancode=inb(0x60);            //get the scancode
    outb(inb(0x61));               //acknowledge
    break;
}
if(i>0) printf("got scancode=%d\n",scancode); else printf("spuorious irq");
This is the rough C version of what I have in assembly. This the original:

Code: Select all

drv.ps2.event_keyboard:
                xor                     rax, rax
                xor                     rcx, rcx
                mov                     cx, 1000
.waitkey:       in                      al, 64h
                dec                     cx
                jz                      interrupt_irqs.false_irq
                and                     al, 01h
                jz                      .waitkey
                in                      al, 60h
                mov                     cl, al
                in                      al, 61h
                out                     61h, al
                mov                     al, cl
                ;scancode in al
It's tested on qemu, bochs, virtualbox and real hardware, works fine everywhere.
spaghettios
Posts: 7
Joined: Mon Feb 20, 2012 11:34 am
Location: Italia

Re: keyboard interrupt

Post by spaghettios »

I' ll reinstall bochs because also in this way doesn't work.
Thanks for help!
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: keyboard interrupt

Post by Nable »

Just a small note:
was it really what you want: for(i=1000;i>0;i++)
?
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: keyboard interrupt

Post by turdus »

Nable wrote:Just a small note:
was it really what you want: for(i=1000;i>0;i++)
?
Somebody pay attention :-) Yep, it should be i--
Post Reply