Page 1 of 1
Computer Differences
Posted: Fri Oct 31, 2008 3:54 am
by Ferrarius
Hello,
I've lately been busy writing a basic keyboard driver for my OS project. Yesterday I got as far as to get it to display the pressed key on screen. When tested in bochs this worked perfectly. It also worked perfectly on my main computer (Q6600, Asus P5B). However it does not work correctly on my testbed computer (Celeron 433 MHz). What happens is it takes the first key (sometimes) I press on the keyboard and then won't display any new key. I wonder if anyone else ever encountered problems alike. I include my code:
Code: Select all
key_board:
pushad
push ds
push es
push gs
call kbdriver
mov ax,0x10
mov ds,ax
mov byte[ds:0x000B8100],'K'
mov al,0x20
out 0xA0,al
out 0x20,al
pop gs
pop es
pop ds
popad
iret
Code: Select all
kbdriver:
cld
xor eax,eax
in al,0x60 ;Read Keyboard Input
cmp al,0x80 ;Is bit 7 low?
jae .keyr ;There was a key release
mov eax,[eax + keymap.standard + CORE] ;Convert to ASCII
jmp .movebuffer
.movebuffer:
mov byte[ds:0x000B8070],al
ret
.keyr:
ret
;-------------------------;
;Data Area ;
;-------------------------;
SHIFT db 0
CAPS db 0
CTRL db 0
ALT db 0
LED db 0
SCROLL db 0
NUM db 0
Thanks in advance for any help.
Re: Computer Differences
Posted: Fri Oct 31, 2008 4:26 am
by Combuster
pendancy: move the DS (and ES) load before the call.
Are you may also want to be sure you haven't missed out on interrupts (i.e. you have multiple keypresses to deal with when you handle the first)
Re: Computer Differences
Posted: Fri Oct 31, 2008 11:16 am
by Ferrarius
It seems to be more than just a simple driver problem. When running on the Celeron 700 MHz (excuse my mistake earlier. My previous now testbed (RIP) was a celeron 433) the computer runs into a GP. The darndest thing is my main pc and an old HP laptop (AMD, not really sure which one though) run the code just fine. Not a single interrupt that shouldn't be there. Nevertheless I don't exclude the possibility there is an error in my code that some processors are do run into and others don't. Before I throw away a processor I'd like to be sure. Therefore I'd like to ask you to take a quick glance at my code. It gets all the way to the hang on all computers and bochs.
the code:
http://rapidshare.com/files/159387185/MIK.rar.html
Excuse the many amount of seemingly useless video memory writes, I used them to see where the computer got.
Kind regards
Re: Computer Differences
Posted: Fri Oct 31, 2008 1:08 pm
by ~
I am sure that all of your PC's are perfectly OK. I've never had a single machine that were damaged in such a way.
Now, Is this what your keyboard code does overall?:
- On keyboard press/release, key_board is called.
- key_board then calls kbdriver.
- kbdriver reads 1 byte, does some processing, and FINALLY send EOI.
Is that correct?
Also, I think you should only send the EOI to the master PIC at 0x20, and remove the code to send it to the slave PIC at 0xA0, since the keyboard IRQ is IRQ 1 and it is controlled by the master PIC at 0x20 and so the slave PIC has nothing to do here.
Remember also that there are several scan codes that have more than 1 only byte, like PrnScr (PrInt Screen).
If you have MS-DOS, you can download, assemble and run the following attached program, which shows the last scan code byte in hex. You will notice it change when you run it (the other, most active byte that changes even when there's no keyboard activity just represents the timer interrupt at IRQ 0):
Re: Computer Differences
Posted: Fri Oct 31, 2008 6:28 pm
by bewing
The problem may be that the Celeron machine contains an APIC, and the other machines only have PICs. An APIC requires modified drivers, AFAIK.
Re: Computer Differences
Posted: Fri Oct 31, 2008 10:03 pm
by ~
bewing wrote:The problem may be that the Celeron machine contains an APIC, and the other machines only have PICs. An APIC requires modified drivers, AFAIK.
Wouldn't that mean that the sample kernels like the ones at
http://osdever.net would crash in a Celeron?
Ferrarius wrote:...I don't exclude the possibility there is an error in my code that some processors are do run into and others don't. Before I throw away a processor I'd like to be sure. Therefore I'd like to ask you to take a quick glance at my code...
Could you post a a bootable disk image (floppy?) of your current work? I would be glad to test it in my machines (they are 6, ranging from 1996, 2000, 2002 and 2005, but no Celerons).
Also, I'd like you to let me know if the attached program I posted earlier works in your machine. If it works, then it's almost certain that your source code has bugs somewhere.
Re: Computer Differences
Posted: Sat Nov 01, 2008 6:02 am
by Combuster
You can still use the PIC in APIC-based machines. I have several dual-socket and dual-core computers that just work with PIC code. The reason you can is just for backwards compatibility.
My Celeron has always worked before I even started with multiple processing units (and hence, APICs).
Re: Computer Differences
Posted: Sun Nov 02, 2008 9:20 am
by Ferrarius
I'm sorry for the late reaction. About apic in celeron, it would suprise me if it wasn't there. It's been in the x86 architecture since the first pentium. But given I've tested it on a machine with a quad core, which usually requires an IO apic as well, and it worked perfectly on that machine this couldn't possibly be the problem. I'll locate an image of the work as it was on my laptop machine which I haven't here atm.