After some searching, somehow I found some ASM code and I tried to translate it to C, but I am very green. Can someone help me with this:
video.c: In function 'IOHandler': video.c:78: error: 'KeyboardIsr' undeclared (first use in this function) video.c:78: error: (Each undeclared identifier is reported only once video.c:78: error: for each function it appears in.) video.c:79: error: 'cs' undeclared (first use in this function)
My in() and out() functions:
Code: Select all
unsigned char in(unsigned short _port) //input a byte
{
// "=a" (result) means: put AL register in variable result when finished
// "d" (_port) means: load EDX with _port
unsigned char result;
__asm__ __volatile__("in %%dx, %%al" : "=a" (result) : "d" (_port));
return result;
}
void out(unsigned short _port, unsigned char _data) //output a byte to a port
{
// "a" (_data) means: load EAX with _data
// "d" (_port) means: load EDX with _port
__asm__ __volatile__("out %%al, %%dx" : :"a" (_data), "d" (_port));
}
My Attempt:
Code: Select all
void IOHandler()
{
// Install keyboard handler
in("push ds");
in("push word 0");
in("pop ds");
in("cli");
out(4 * 0x09, KeyboardIsr); // line 78
out(4 *0x09 + 2, cs); // line 79
in("sti");
in("pop ds");
}
void KeyboardIsr()
{
char key = in(0x60); //get key press
if(key==0x5a) //enter key
{
cls(0x70);
printf(0x70, "Test", 1, 2);
} else {
cls(0x70);
printf(0x70, "Not Enter", 1, 2);
}
out(0x20,0x20);
}
Here is the code I translated, or tried to translate is more like it: (in fact the only thing I think I successfully translated was the comment line)
Code: Select all
; Install keyboard handler
push ds
push word 0
pop ds
cli
mov [4 * KEYBOARD_INTERRUPT], word keyboardHandler
mov [4 * KEYBOARD_INTERRUPT + 2], cs
sti
pop ds
Link:
keyboard_kernel.asm
As you can see, I am very desperate to make this work.