Page 1 of 1
Keyboard doesn't work on a real machine
Posted: Tue Jul 25, 2006 2:18 pm
by ed_tait
I finaly got arround to testing my os on a real computer...
I booted from a floppy emmulation eltoito cd, everything goes fine exept for one thing: the code should dump key presses to the screen but it dosen't. I remap the pic and enable the A20 line (could this be the problem?) and wait in an infinite loop:
I explicitly enable interrupts and the code works fine in bochs. Any ideas as to whats wrong?
Thankyou.
Re:Keyboard doesn't work on a real machine
Posted: Tue Jul 25, 2006 2:34 pm
by bluecode
So what _exactly_ goes wrong and especially when go things wrong?
Re:Keyboard doesn't work on a real machine
Posted: Tue Jul 25, 2006 3:15 pm
by ed_tait
Sorry I forgot to say.
the problem is that no keys are printed to th screen but everything previous to that has worked fine.
Re:Keyboard doesn't work on a real machine
Posted: Wed Jul 26, 2006 12:39 am
by viral
Hello...
Can we see your Keyboard Interrupt Service Routine.. Untill we see the code we cant say anything...
This is a wild guess. but you may not giving EOI command to your PIC. (i.e have you put outportb(0x20,0x20); or something like that?)
Re:Keyboard doesn't work on a real machine
Posted: Wed Jul 26, 2006 2:02 am
by ed_tait
here's the code:
Code: Select all
ikbd:
push eax
push ebx
push esi
mov eax,0
in al, 60h ;get the key scan code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; start using shift keymap ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cmp al, 42
jz is_shift
;there are two shift keys
cmp al, 54
jz is_shift
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; stop using shift keymap ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cmp al,170
jz is_shift_up
cmp al, 182
jz is_shift_up
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov bl, al ;
or bl, 01111111b ; if the high bit is set this sets
xor bl, 01111111b ; bl to 80h - this indictes a key up event
; we don't want to do anything in this case
; ...yet!
; in these situations
;we don't want to display anything
;;;;;;;;;;;;;;;;;;;;;;;;;;
cmp bl, 80h ; key up, we don't want to print anything
jz return_from_kbd ;
;;;;;;;;;;;;;;;;;;;;;;;;;;
inc byte [key_count]
mov ebx, 0
mov bl, [cursor_caps] ; are we using the shifted keymap?
;
mov esi, [keymaps + 4*ebx] ;calculate our ofset into the keymap
add esi, eax ;
mov al, [esi] ; get the character from the keymap
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; store the key ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov [key], al
inc byte [kbd_int_count]
cmp byte [cursor_write], 0 ; if we dont want to print the key
jz return_from_kbd ;
call putc ;output the character
return_from_kbd:
mov al, 20h ;end of int
out 20h, al
pop esi
pop ebx ;restore the registries we used
pop eax
iret
is_shift:
mov byte [cursor_caps], 1
jmp return_from_kbd
is_shift_up:
mov byte [cursor_caps], 0
jmp return_from_kbd
keymaps dd keymap, keymap_caps
keymap db 0,0,'1234567890-=',7,0,'qwertyuiop[]',13,0,'asdfghjkl;``',0,'#zxcvbnm,./*',0, ' '
keymap_caps db 0,0,'!"?$%^&*()_+',7,0,'QWERTYUIOP{}',13,0,'ASDFGHJKL:@?',0,'~ZXCVBNM<>?*', 0 , ' '
key_count db 0
wait_key:
mov byte [key_count], 0
wait_key_loop:
hlt
cmp byte [key_count], 0
jz wait_key_loop
ret
getc:
mov byte [kbd_int_count], 0
sti
wait_key_int:
hlt
cmp byte [kbd_int_count], 0
jz wait_key_int
mov al, [key]
ret
cursor_write db 1
cursor_caps db 0
key db 0
kbd_int_count db 0
sorry about the size of the post. Ed.
Re:Keyboard doesn't work on a real machine
Posted: Thu Jul 27, 2006 8:03 am
by ed_tait
Hello again.
I've tracked down the bug. it's in the printing code. i dont think that the computer i tested on was in 80x25 text(is this posible?) mode when it gave controll to my kernel and as a resault putc routine didn't work.
sorry.
Re:Keyboard doesn't work on a real machine
Posted: Thu Jul 27, 2006 5:16 pm
by blip
It is possible that the BIOS was not using page 0 of the text memory but your code assumed it, assuming your code does assume this and the BIOS was indeed using 80x25.
Re:Keyboard doesn't work on a real machine
Posted: Fri Jul 28, 2006 1:25 am
by ed_tait
Hello again. This just gets more confusing...
I set the video mode to 80x25 in my boot sector. Additionaly, to make sure it wasn't the vidio hardware, I created a boot cd of the "brans tutorial kernel" that worked fine. it uses the same "pointer to video memory" method of printing to the screen.
whats even stranger is that my screen clearing code seems to work:
Code: Select all
cls:
pusha
mov ebx, 0b8000h
mov ecx, 2000 ;80*25, the dimensions of the screen
clear_loop:
mov byte [ds:ebx], 0 ;null character
inc ebx
mov byte [ds:ebx], 03bh ;blue (01h) on white (0fh)
inc ebx
loop clear_loop
mov word [cursor_pos], 0 ; set cursor to top left corner.
call update_cursor
popa
ret
scince changing the attribute witten to video memory changes the colour on the screen but I still don't see why my character output code doesn't work; considering it uses the same method a cls.
I think today i'm just going to load my code with debuging statements like:
and hope that with 80x25 mode set by my boot sector they work.
EDIT:
i think i want to cry :'(
i've pused the system just after it jumps to my boot sector. so i can read what the bios boot message is. its just general abuot emmulating 1.44 meg floppy.
when i press a key my code continuse to execute and it switches to 80x25 mode using int 10h (still in real mode).
but then the screen goes aqua blue with a cursor in the corner and i cant see any of my boot messages which are writen directly into video memory as shown above. Do you think i should give up using my own boot loader and use GRUB inted? bran's tutorial kernel uses GRUB and that works fine.
I'm just not sure what to do. i might stom using asm and go back to c. try following some of the tutorials on osdever to retore my self confidence.
please. if you've got any ideas whats going on and if i should try GRUB please reply.
Thankyou
Ed Tait
Re:Keyboard doesn't work on a real machine
Posted: Fri Jul 28, 2006 1:58 pm
by blip
mov byte [ds:ebx], 03bh ;blue (01h) on white (0fh)
This should be encoded as 0F1h as 3Bh is light cyan on dark cyan, but you must set the MSb of the attribute byte to be interpreted as intensity and not blinking. As for your printing routine, it sounds like you should go over it again. Maybe you used a base offset of 0B800h instead of 0B8000h or something as simple.
Re:Keyboard doesn't work on a real machine
Posted: Fri Jul 28, 2006 2:27 pm
by ed_tait
I changed the attrbutes to cyan to test if my code was getting that far. in the latest version I don't even clear the screen. I just set the text mode to 80x25. I still get a cyan screen though. useing the bios int 16 interrupt in the boot sector to pause before i set the video mode and the screen is cleared shows noe bios error messages.
The code works as expected in bochs. All I can wonder is if my code is crashing verry early on due to some fault bochs can't detect.
The fact that it works in bochs should rule out most simple erros but i'll check again.
would blinking vs intensity make a big differance?
thakyou.
Ed Tait
Re:Keyboard doesn't work on a real machine
Posted: Fri Jul 28, 2006 4:23 pm
by blip
Well if you have the attribute all over the screen it makes all of the text blink which is hard to read. If you don't want to bother with the background intensity/blink then use light gray instead, otherwise use
int 10h function 10h, subfunction 3 in real mode.
I just noticed your cls routine pushes all 16-bit registers but the high portion of EBX is modified. Plus in your keyboard handler you can use AND BL,10000000b instead of:
Code: Select all
or bl, 01111111b ; if the high bit is set this sets
xor bl, 01111111b ; bl to 80h - this indictes a key up event
; we don't want to do anything in this case
; ...yet!
This is running in protected mode right? I'm getting the feeling that this is a test bootsector code.
Re:Keyboard doesn't work on a real machine
Posted: Sat Jul 29, 2006 3:11 pm
by edtait
sorry. i know i'm posting as a guest. I rather stupidly asked for a new password and havent recived the email yet.
I wrote some code that uses the same output method and booted it with grub. it worked fine. I can only assume that the problem was the my self coded boot sector wasn't initialiseing something correctly.
thank you for the advice on the isr. i think that i'm going to spend some time this summer giving my code a complete over-haul.
I'm not sure if i'll switch to grub but it has several good points. ill proberbly sleep on it. well good night and thankyou for all the help.
Edward Tait