Page 1 of 1

Strange bug

Posted: Sat Nov 19, 2005 12:04 pm
by CyberP1708
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:

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;
   }
}
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

Re:Strange bug

Posted: Sun Nov 20, 2005 7:30 am
by Solar
I would suggest figuring out why GRUB is complaining about your binary format, first. Chances are your toolchain and/or linker script is borked somewhere. Threads on the subject are legion in this forum; try the search function.

Re:Strange bug

Posted: Wed Nov 23, 2005 9:55 am
by Pype.Clicker
especially considering that code doing line return contains a string constant ... if .rodata (or friends) are not properly linked, that may explain many things ...

I suggest you have a hexviewer and check everything's in place as expected ;)

Re:Strange bug

Posted: Thu Nov 24, 2005 11:59 am
by CyberP1708
Yes I check out and everything seemed to be in its right place...

Whatever it is too late as I've restarted my os seeing nobody was answering me (I've had this bug for about 2 months)