Posted: Fri Feb 22, 2008 1:46 am
How about prompting "If you are using a keyboard, press ENTER now, or please hold.." and count down 3 seconds.
The Place to Start for Operating System Developers
http://f.osdev.org/
Code: Select all
keybdpre: xor eax,eax;
mov al,0xAA; //(Controller self-test) - Returns 0x55 if okay.
out 64h,al;
ewait:
mov cx,0x100; // delay
dec cx;
jnz ewait;
in al,60h;
cmp al,55h; // comparing to check if o/p is 55
jz print;
jnz areho;
print: mov ax,0x00
ret
areho: mov ax,0x01
ret
yup rightly said but it does not return 0 or 1 ..your code should not return any values other than eax=0 or eax=1, which you can't really call "garbage". If it doesn't, then there must be something wrong with the way you're calling your code and/or checking the returned value.
Code: Select all
;Disable INT's before test:
;Disable INT's before test:
cli
;Send RESET command to the keyboard itself:
;Send RESET command to the keyboard itself:
mov al,0xFF
out 0x60,al
;Set a delay loop:
;Set a delay loop:
.outPort60_1: ;wait ready for command
in al,0x64
test al,00000010b
jnz .outPort60_1
;Now read the answer. If OK, it's 0xAA, otherwise it's 0xFC:
;Now read the answer. If OK, it's 0xAA, otherwise it's 0xFC:
in al,0x60
cmp al,0xAA ;See if OK, or 0xAA
jnz .errork ;If not, skip "setup" code
;;Here there should be code in case the keyboard is present.
;;Finally, we skip the rest of code in case of no keyboard:
;;Finally, we skip the rest of code in case of no keyboard:
jmp .kend
.errork:
;;Here there should be code in case the keybard is NOT present.
.kend:
;;Nothing more about that here
Code: Select all
kbc.read_date_byte.timeout = 20 ; 0.2 Sec.
;IN: -/-
;OUT: al=byte; ebx=result (0=ok; 1=parity error; 4=timeout(pit))
kbc.read_date_byte:
mov ebx, [pit.timer_count]
add ebx, kbc.read_date_byte.timeout
.wait_for_recv:
cmp ebx, [pit.timer_count]
jb .pit_timeout_error
in al, 0x64
test al, 10000000b
jnz .parity_error
test al, 00000001b
jz .wait_for_recv
in al, 0x60
xor ebx, ebx
ret
.parity_error:
xor eax, eax
mov ebx, 1
ret
.kbc_timeout_error:
xor eax, eax
mov ebx, 2
ret
.pit_timeout_error:
xor eax, eax
mov ebx, 4
ret
kbc.wait_for_send:
push eax
.waitloop:
in al, 0x64
test al, 00000010b
jne .waitloop
pop eax
ret
;IN: al = command byte
kbc.send_command:
call kbc.wait_for_send
out 0x64, al
ret
;IN: al = byte
kbc.send:
kbc.psaux0.send:
call kbc.wait_for_send
out 0x60, al
ret
;IN: al = byte
kbc.psaux1.send:
push eax
mov al, 0xD4
call kbc.send_command
pop eax
call kbc.send
ret
;IN: eax = sample rate (Valid sample rates are 10, 20, 40, 60, 80, 100, and 200 samples/sec.)
;ebx = @kbc.psaux0.send OR @kbc.psaux1.send
;OUT: eax=result (0=ok; 1=error)
kbc.set_mouse_sample_rate:
pushad
mov edx, ebx ;save "kbc.psauxX.send"
mov ecx, eax ;save "sample rate"
mov ax, 0xF3 ;"set samplerate command"
call edx ;kbc.psauxX.send
call kbc.read_date_byte
cmp ebx, 0
jne .error
cmp al, 0xFA
jne .error
mov eax, ecx ;=the new samplerate
call edx ;kbc.psauxX.send
call kbc.read_date_byte
cmp ebx, 0
jne .error
cmp al, 0xFA
jne .error
mov eax, 0 ;ok
jmp .end
.error:
mov eax, 1 ;error
.end:
popad
ret
Code: Select all
;Disable data reporting /dev/psaux0
mov al, 0xF5 ;disable data reporting
call kbc.psaux0.send
call kbc.read_date_byte ;0xFA (ACK)
Code: Select all
;Enable psaux0 clock line (clear bit 4 of the Command byte)
;just to make sure psaux0 is enabled (CRAZY mainboards!!!)
mov al, 0xAE
call kbc.send_command
call kbc.read_date_byte ;0xFA (ACK)
Code: Select all
mov al, 0xF2 ;get device ID
call kbc.psaux0.send
call kbc.read_date_byte
test ebx, 110b ;Timeout?
jnz kbc.init.detect_psaux0_nothing ;Timeout!
call crt.byte.write
cmp al, 0xFE ;Some Motherboards return 0xFE (resend) if no device is pluged in
je kbc.init.detect_psaux0_nothing
cmp al, 0xFA ;ack?
jne kbc.init.detect_psaux0_unknownError ;no ack!
call kbc.read_date_byte
test ebx, 110b ;Timeout?
jnz kbc.init.detect_psaux0_0byte ;Timeout!
;we have 1 byte
push eax ;push al
call kbc.read_date_byte
test ebx, 110b ;Timeout?
jnz kbc.init.detect_psaux0_1byte ;Timeout!
;we have 2 byte
push eax ;push al
call kbc.read_date_byte
test ebx, 110b ;Timeout?
jnz kbc.init.detect_psaux0_2byte ;Timeout!
;remove trash from the stack
pop eax
pop eax
;3 byte or more id? I dont know what that could be. O_o
jmp kbc.init.detect_psaux0_unknownDevice
kbc.init.detect_psaux0_0byte: ;0 byte id, seems to be a at-keyboard
;-->We have a AT-Keyboard!
jmp kbc.init.detect_psaux0_end
kbc.init.detect_psaux0_1byte: ;1 byte id could be a mouse, do we know the mouse type?
pop eax
and eax, 0xFF
cmp eax, 0x03 ;3=Intellimouse (This ID will return if the mouse was already initialized and the PC rebooted)
je kbc.init.detect_psaux0_1byte.detect_intelli
cmp eax, 0 ;<> 0 oder 3
jne kbc.init.detect_psaux0_unknownDevice ;it is a unknown device!
;it is at last a standard mouse!
;now test for extensions:
;set samplerate to 200, 100, 80
mov ebx, kbc.psaux0.send
mov eax, 200
call kbc.set_mouse_sample_rate
mov eax, 100
call kbc.set_mouse_sample_rate
mov eax, 80
call kbc.set_mouse_sample_rate
;then getid
mov al, 0xF2 ;get device ID
call kbc.psaux0.send
call kbc.read_date_byte ;0xFA (ACK)
call kbc.read_date_byte ;0 = standard mouse; 3=Intellimouse (scroll)
cmp al, 3
je kbc.init.detect_psaux0_1byte.detect_intelli
;-->We have a standard Mouse!
jmp kbc.init.detect_psaux0_end
kbc.init.detect_psaux0_1byte.detect_intelli:
;-->We have a mouse with intelli extension!
jmp kbc.init.detect_psaux0_end
kbc.init.detect_psaux0_2byte: ;2 byte id could be a mf2-keyboard, do we know the keyboard type?
pop ebx
pop eax
shl eax, 8
or eax, ebx
and eax, 0xFFFF
cmp eax, 0xAB83
je kbc.init.detect_psaux0_2byte.its_standard_mf2
cmp eax, 0xAB41 ;some kbc "translate" the byte from the keyboard to Scancode1 (0x83=0x41)
je kbc.init.detect_psaux0_2byte.its_standard_mf2
jmp kbc.init.detect_psaux0_unknownDevice
kbc.init.detect_psaux0_2byte.its_standard_mf2:
;-->We have a MF2 Keyboard!
jmp kbc.init.detect_psaux0_end
kbc.init.detect_psaux0_nothing:
;-->We have a unknown device or no device at all!
jmp kbc.init.detect_psaux0_end
kbc.init.detect_psaux0_unknownError:
;-->We have a unknown device or no device at all!
jmp kbc.init.detect_psaux0_end
kbc.init.detect_psaux0_unknownDevice:
;-->We have a unknown device or no device at all!
jmp kbc.init.detect_psaux0_end
kbc.init.detect_psaux0_end: