Strange bug
Posted: Sat Nov 19, 2005 12:04 pm
I discovered a very strange bug in my kernel...
It's with my keyboard driver
When I press any key, it is working (when you press 'p', then 'p' is written on the screen) but not if you press enter, even if both are handled exactly the same...
When a key is pressed, a function is called (for the shell to write the key on screen)
Here is its content:
This function should be called when any event occurs (including a key press).
If I remove the "if (chr == '\r' || chr == '\n')" part (but keeping the "if (chr == keyboard_del) {"), it is working (nothing happens when pressing enter)
If I put a breakpoint at the beginning of the function, no crash
If I put a breakpoint just before the "if (chr == '\r' || chr == '\n') {" no crash
If I put a breakpoint just after the "if (chr == '\r' || chr == '\n') {" it crashes
If I replace "if (chr == '\r' || chr == '\n') {" by "if (chr == 'p') {" it also crashes
If I rename my keyboard driver from "keyboard.c" to "aaakeyboard.c" which places it at the beginning of the alphabet and consequently places it lower in the compiled file, everything is working fine
Note that the called function is lower in the compiled file (than the driver)
I was thinking of a problem with my bootloader (I can't manage getting grub working, it always says "wrong file type" even with elf) what would lead to a part of the keyboard driver not being loaded (I was thinking of that because of the "aaakeyboard.c"), but it doesn't explain why it doesn't crash when I put a breakpoint for example...
Note: sorry for my bad english
It's with my keyboard driver
When I press any key, it is working (when you press 'p', then 'p' is written on the screen) but not if you press enter, even if both are handled exactly the same...
When a key is pressed, a function is called (for the shell to write the key on screen)
Here is its content:
Code: Select all
void shell__sendmsg(unsigned int id, unsigned int msg, unsigned int p1, unsigned int p2) {
if (id) return;
char chr;
unsigned short x, y, x2, y2;
switch (msg) {
case message_key_pressed:
chr = p1;
if (chr == '\r' || chr == '\n') {
shell_buffer[shell_last_id] = '\0';
shell_last_id = 0;
if (shell_buffer[0]) {
display_console_put_char('\r');
display_console_put_char('\r');
shell__command(shell_buffer);
}
display_console_print("\r> ");
} else if (chr == keyboard_del) {
if (shell_last_id) {
display_get_resolution(&x2, &y2);
display_console_get_cursor_position(&x, &y);
if (!x) { x = x2 - 1; --y; }
else --x;
display_console_move_cursor(x, y);
display_console_put_char(' ');
display_console_move_cursor(x, y);
--shell_last_id;
}
} else {
display_console_put_char(chr);
shell_buffer[shell_last_id++] = chr;
}
break;
}
}
If I remove the "if (chr == '\r' || chr == '\n')" part (but keeping the "if (chr == keyboard_del) {"), it is working (nothing happens when pressing enter)
If I put a breakpoint at the beginning of the function, no crash
If I put a breakpoint just before the "if (chr == '\r' || chr == '\n') {" no crash
If I put a breakpoint just after the "if (chr == '\r' || chr == '\n') {" it crashes
If I replace "if (chr == '\r' || chr == '\n') {" by "if (chr == 'p') {" it also crashes
If I rename my keyboard driver from "keyboard.c" to "aaakeyboard.c" which places it at the beginning of the alphabet and consequently places it lower in the compiled file, everything is working fine
Note that the called function is lower in the compiled file (than the driver)
I was thinking of a problem with my bootloader (I can't manage getting grub working, it always says "wrong file type" even with elf) what would lead to a part of the keyboard driver not being loaded (I was thinking of that because of the "aaakeyboard.c"), but it doesn't explain why it doesn't crash when I put a breakpoint for example...
Note: sorry for my bad english