Page 1 of 3

port 60h wonder

Posted: Mon Mar 17, 2008 11:52 pm
by Philip
after my kernel switch to protected mode
and try to read port 60h to print out the keyboard input to screen but
the result is always AAh
i really wonder why? :?

Posted: Tue Mar 18, 2008 12:23 am
by Stevo14
AFAIK, In protected mode, the keyboard will send you an interrupt when it has data for you to read. It should be interrupt request number one. (number zero is the timer's interrupt.)

Re: port 60h wonder

Posted: Tue Mar 18, 2008 12:42 am
by egos
Adam wrote:At power-on or software reset (see the "Reset" command) the keyboard performs a diagnostic self-test referred to as BAT (Basic Assurance Test) and loads the following default values:
Typematic delay 500 ms.
Typematic rate 10.9 cps.
Scan code set 2.
Set all keys typematic/make/break.
When entering BAT, the keyboard enables its three LED indicators, and turns them off when BAT has completed. At this time, a BAT completion code of either 0xAA (BAT successful) or 0xFC (Error) is sent to the host.
Source: Computer-Engineering.org

Posted: Tue Mar 18, 2008 12:50 am
by Philip
Stevo14 wrote:AFAIK, In protected mode, the keyboard will send you an interrupt when it has data for you to read. It should be interrupt request number one. (number zero is the timer's interrupt.)
i already used CLI before entering protected mode
so do i have to write all interrupts myself including the int 9?
(my building kernal hasnt an interrupt descriptor table yet)

Re: port 60h wonder

Posted: Tue Mar 18, 2008 12:54 am
by Philip
egos wrote:
Adam wrote:At power-on or software reset (see the "Reset" command) the keyboard performs a diagnostic self-test referred to as BAT (Basic Assurance Test) and loads the following default values:
Typematic delay 500 ms.
Typematic rate 10.9 cps.
Scan code set 2.
Set all keys typematic/make/break.
When entering BAT, the keyboard enables its three LED indicators, and turns them off when BAT has completed. At this time, a BAT completion code of either 0xAA (BAT successful) or 0xFC (Error) is sent to the host.
Source: Computer-Engineering.org
but how does that AAh from BAT relate to the AAh i receive from port 60h?

Posted: Tue Mar 18, 2008 12:58 am
by Stevo14
Philip wrote: so do i have to write all interrupts myself including the int 9?
(my building kernal hasnt an interrupt descriptor table yet)
Again, according to my limited knowledge, the answer is yes. In protected mode you have the privilege (or responsibility or whatever) to handle all interrupts yourself. I would suggest looking through some basic kernel tutorials as most of them give a good walk-through of getting interrupts (and other goodies that rely on interrupts like timers and of course the keyboard) setup.

Posted: Tue Mar 18, 2008 1:09 am
by egos
Philip wrote:i already used CLI before entering protected mode
so do i have to write all interrupts myself including the int 9?
(my building kernal hasnt an interrupt descriptor table yet)
IRQ1 handler??? Firstly you have to reprogram the PIC.

Posted: Tue Mar 18, 2008 1:29 am
by Philip
but port 60h is the keyboard port
what the hck why i can't read from this port?

Posted: Tue Mar 18, 2008 1:44 am
by Dex
To poll the keyboard you do not need IDT set up in pmode.
Something like this should work

Code: Select all

;************************************
; Test key input.
; By Dex
;************************************
; Assemble with fasm
; c:\fasm TestKey.asm TestKey.bin
;
; Keys = (UpArrow)
; Keys = (DownArrow)
; Keys = (Enter)
;************************************
org 0x7C00

use16
;****************************
; Realmode startup code.
;****************************
start:
        xor   ax,ax
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   sp,0x7C00
;*****************************
; Setting up, to enter pmode.
;*****************************
        cli
        lgdt  [gdtr]

        mov   eax, cr0
        or    al,0x1
        mov   cr0,eax

        jmp   0x10: protected
;*****************************
; Pmode. ;-)
;*****************************
use32
protected:
        mov   ax,0x8 
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   esp,0x7C00
;*****************************
; Turn floppy off
;*****************************
        mov   dx,3F2h
        mov   al,0
        out   dx,al
;*********************************
; Main keyboard loop.
;*********************************
NoKey:
        xor   eax,eax
        in    al,60h
        cmp   al,0x50
        jne   TryNext1
        mov   byte [es:0xB8000], "D"
	     jmp   NoKey
TryNext1:
        cmp   al,0x48
        jne   TryNext2
        mov   byte [es:0xB8000], "U"
	     jmp   NoKey
TryNext2:
        cmp   al,0x1c
        jne   NoKey
        mov   byte [es:0xB8000], "E"
	     jmp   NoKey

;*************************************
; GDT.
;*************************************

gdt:        dw    0x0000, 0x0000, 0x0000, 0x0000
sys_data:   dw    0xFFFF, 0x0000, 0x9200, 0x00CF
sys_code:   dw    0xFFFF, 0x0000, 0x9800, 0x00CF
gdt_end:

gdtr:	    dw gdt_end - gdt - 1	                                  
	    dd gdt

;*************************************
; Make program 510 byte's + 0xaa55
;*************************************

times 510- ($-start)  db 0
dw 0xaa55
Use the ArrowUp, ArrowDown, Enter key to print U, D, or E on screen in pmode, use rawrite to put on a floppy.

Posted: Tue Mar 18, 2008 2:12 am
by egos
Philip, what you want to read from this port? If 0x60 isn't changing its state, when keyboard must send the data, perhaps keyboard interface disabled (see Command Byte, bit 4).

Posted: Tue Mar 18, 2008 2:16 am
by egos
Pooling mode... It's cool :lol:

Posted: Tue Mar 18, 2008 7:05 am
by Philip
oh Dex, you're great
you must be a very good system programmer :)
but wait, my code is the same

in al,60h
call printHexAL

but it just doesnt work -- all the time is a certain value

Posted: Tue Mar 18, 2008 7:34 am
by Zenith
Do you even understand how Dex's code works?

If you copy it word for word, then it'll only print out the letters 'D', 'U' or 'E' (but i have to say, the compared values don't seem right...) when you press them.

Other than that, maybe show us your printHexAL function?

Posted: Tue Mar 18, 2008 8:06 am
by Dex
I can not say why your code does not work (maybe your print hex ?), but the demo i made works fine on all my test PC.
As for the good sys programmer, it's just i have been though the same problem's as you, many times.

Posted: Tue Mar 18, 2008 8:19 am
by Philip
i found out the problem,
it is because of my tablet pc compaq tc1000
port 60h is not the keyboard port as i tried
to write a small program in real mode and run under dos to check but
the value from port 60h is also always AAh

i wonder which port is the keyboard port on compaq tc1000?


the keyboard buffer is set by int 9, but not available once
tune in to protected mode
i tried to trace int 16h function 0 but can not find out the port

anybody knows which port should it be?