Hi all, I hope that someone can help me with a problem writing my little OS. (I personally like the idea to write the most of it in assembly. I'm working in text mode, accessing it by the video RAM, only for debug purposes.
The problem is that, after I switch into protected mode(the IDT is loaded whit all the "now unused" entries pointing to a IRETD instruction), I begin inizialising the PIT (I wrote a clock using IRQ0 (interrupt 20h) that works fine), and then I initialise the PS/2 controller and the keyboard.
Well, at the end of the initialising i enable IRQ1 on keyboard strike in the config byte, then I enable all the interrupts and perform a JMP $ instruction. I've not written a specific interrupt for the keyboard yet but I use a generic one that does nothing(Posted at the end of this post), only to verify if the keyboard is working: i set a breakpoint at 0x00001200 (where the generic interrupt is) using "lb 0x00001200", and then I strike a key to see if IRQ1 is raised (in this case bochs will break). During this process my PIT-based clock works, so I now that CPU is working and there isn't a problem whit the interrupts system. But interrupt 21h (corresponding to IRQ1) is never raised, and the PS/2 data buffer gets full. I've tried lots of changes but none work. Can You help me?
The code is(I will list all the functions used under the code):
Initialize the PS/2 controller:
Code: Select all
CALL K_W_I ;Begin initializing
MOV AL,20h ;
OUT 64h,AL ;Read config byte command
CALL K_W_O ;
IN AL,60h ;Reading config byte
AND AL,10111100b ;Disable interrupt and translation
MOV BL,AL ;
CALL K_W_I ;
MOV AL,60h ;
OUT 64h,AL ;Write config byte command
CALL K_W_I ;
MOV AL,BL ;
OUT 60h,AL ;Ok
CALL K_W_I ;
MOV AL,0AAh ;Controller TEST
OUT 64h,AL ;
CALL K_W_O ;
IN AL,60h ;
CMP AL,55h ;
JNZ RESET ;Done
CALL K_W_I ;
MOV AL,0ABh ;First port test
OUT 64h,AL ;
CALL K_W_O ;
IN AL,60h ;
CMP AL,00h ;
JNZ RESET ;
CALL K_W_I ;
MOV AL,0A9h ;Second port test
OUT 64h,AL ;
CALL K_W_O ;
IN AL,60h ;
CMP AL,00h ;
JNZ RESET ;
CALL K_W_I ;
MOV AL,0AEh ;Enabling keyboard
OUT 64h,AL ;
Code: Select all
RED0: CALL K_W_I ;Keyboard initialize
MOV AL,0F5h ;Stop key scanning
OUT 60h,AL ;
CALL K_W_O ;
IN AL,60h ;
CMP AL,0FAh ;
JNZ RED0 ;
RED1: CALL K_W_I ;Reset keyboard
MOV AL,0FFh ;
OUT 60h,AL ;
CALL K_W_O ;
IN AL,60h ;
CMP AL,0FAh ;
JNZ RED1 ;
CALL K_W_O ;
IN AL,60h ;Ok
CMP AL,0AAh ;
JNZ RESET ;
RED3: CALL K_W_I ;Setting scan code set 2
MOV AL,0F0h ;
OUT 60h,AL ;
CALL K_W_I ;
MOV AL,02h ;
OUT 60h,AL ;
CALL K_W_O ;
IN AL,60h ;
CMP AL,0FAh ;
JNZ RED3 ;Ok
RED4: CALL K_W_I ;Setting typematic byte
MOV AL,0F3h ;
OUT 60h,AL ;
CALL K_W_I ;
MOV AL,00h ;
OUT 60h,AL ;
CALL K_W_O ;
IN AL,60h ;
CMP AL,0FAh ;
JNZ RED4 ;Ok
RED5: CALL K_W_I ;Setting LEDs
MOV AL,0EDh ;
OUT 60h,AL ;
CALL K_W_I ;
MOV AL,02h ;
OUT 60h,AL ;
CALL K_W_O ;
IN AL,60h ;
CMP AL,0FAh ;
JNZ RED5 ;Ok
RED6: CALL K_W_I ;Enabling key scanning
MOV AL,0F4h ;
OUT 60h,AL ;
CALL K_W_O ;
IN AL,60h ;
CMP AL,0FAh ;
JNZ RED6 ;Ok.
CALL K_W_I ;Enabling IRQ1 in the config byte
MOV AL,20h ;
OUT 64h,AL ;
CALL K_W_O ;
IN AL,60h ;
OR AL,00000001b ;
MOV BL,AL ;
CALL K_W_I ;
MOV AL,60h ;
OUT 64h,AL ;
CALL K_W_I ;
MOV AL,BL ;
OUT 60h,AL ;
JMP COXI ;Ok
COXI: ...
Code: Select all
K_W_I: IN AL,64h ;Waiting until the command buffer is clear
AND AL,00000010b ;
CMP AL,02h ;
JZ K_W_I ;
RET ;Ok
K_W_O: IN AL,64h ;Waiting until there is something in the data buffer
AND AL,00000001b ;
CMP AL,01h ;
JNZ K_W_O ;
RET ;Ok
RESET: CALL K_W_I ;
MOV AL,0FEh ;Perform a CPU reset
OUT 64h,AL ;Ok
Bochs debug:
Code: Select all
01608908314i[BIOS ] Booting from 0000:7c00
01681222589i[ ] Ctrl-C detected in signal handler.
Next at t=1681283171
(0) [0x0000000fe869] f000:e869 (unk. ctxt): cli ; fa
<bochs:2> lb 0x00001200
<bochs:3> c
01770989853i[KBD ] keyboard: scan convert turned off
01770989928i[KBD ] reset-disable command received
01770992023i[KBD ] Switched to scancode set 2
01770993016i[KBD ] setting typematic info
01770993024i[KBD ] setting delay to 250 mS (unused)
01770993024i[KBD ] setting repeat rate to 30,0 cps (unused)
27730184000i[KBD ] internal keyboard buffer full, ignoring scancode.(a0)
35670360000i[KBD ] internal keyboard buffer full, ignoring scancode.(1f)
35781548000i[KBD ] internal keyboard buffer full, ignoring scancode.(9f)
EDIT: The generic interrupt that's at 0x00001200 is:
Code: Select all
RETY: PUSHFD ;Here we are at 0x00001200
PUSH EDX ;
PUSH ECX ;
PUSH EBX ;
PUSH EAX ;
JMP EXIT ;Done
.... other interrupts code
EXIT: MOV AL,20h ;Most interrupts jump here at their end
OUT 0A0h,AL ;
OUT 20h,AL ;
POP EAX ;
POP EBX ;
POP ECX ;
POP EDX ;
POPFD ;
IRETD ;Return