Computer Differences

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
Ferrarius
Member
Member
Posts: 69
Joined: Sun Oct 28, 2007 4:10 pm

Computer Differences

Post 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.
Modular Interface Kernel With a lot of bugs ;)
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: Computer Differences

Post 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)
"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 ]
Ferrarius
Member
Member
Posts: 69
Joined: Sun Oct 28, 2007 4:10 pm

Re: Computer Differences

Post 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
Modular Interface Kernel With a lot of bugs ;)
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Computer Differences

Post 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):
Attachments
ints.zip
You must run this program under MS-DOS in your PC or Bochs. If you don't want to assemble the source code, just run the file INTS.COM
(5.64 KiB) Downloaded 56 times
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Computer Differences

Post 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.
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Computer Differences

Post 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.
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: Computer Differences

Post 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).
"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 ]
Ferrarius
Member
Member
Posts: 69
Joined: Sun Oct 28, 2007 4:10 pm

Re: Computer Differences

Post 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.
Modular Interface Kernel With a lot of bugs ;)
Post Reply