Unkown instruction...

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Whatever5k

Unkown instruction...

Post by Whatever5k »

I'm right back from holidays now...
I've changed my kernel a bit, but when I boot it with Bochs, it doesn't work properly (no "counter" message is printed out, as you will see soon)...
bochout.txt sais:

Code: Select all

00023657526i[CPU  ] BxError: instruction with op1=0xfe
00023657526i[CPU  ] nnn was 4
00023657526i[CPU  ] WARNING: Encountered an unknown instruction (signalling illegal instruction):
Hm, I think invalid code is executed (like data or something else)...but I cannot find the error...
That's my code:

Code: Select all

/* setup_interrupts()
 * sets up some IRQ handlers, etc.
 */
void setup_interrupts(void)
{
   disable_ints();   /* no interruptions */

   /* init the PICs and remap them so they start at 0x20 */
   init_pics(0x20, 0x28);

   /* and now set up some interrupt handlers */
   changeISR(0x21, (void *)int_irq1);
   enable_irq(1);
   enable_ints();
   
   printk("Keyboard enabled\n");
   printk("Interrupts enabled\n");
}

void kmain(void)
{
...
...
/* set up interrupt stuff */
            printk("Setting up interrupts...\n");
   setup_interrupts();
   printk("Remapped the PICs: IRQs starting at 0x20\n");
         
   idle();   /* keep doing nothing */
}

/* idle()
 * function does nothing
 */
void idle(void)
{
   printk("\nidling...\n");
   while(1)
   {
      if (counter > 10)
      {
         printk("\ncounter\n");
         counter = 0;
      }
   }
   
}
Ok, this was my C code...and that's the asm (interrupt) code:

Code: Select all

int_irq1:
   EXTERN kbd_handler 
   
   cli   ; disable interrupts while processing
   
   call save   ; save registers
   call kbd_handler   ; call the handler
   call masterEOI   ; send EOI to master
   call restore   ; restore registers
      
   sti   ; reenable interrupts
   iretd

save:
   ; save some registers
   pushad
   push ds
   push es
   push fs
   push gs
   
   mov eax, DS_SELECTOR
   mov ds, eax
   mov es, eax
   mov fs, eax
   mov gs, eax

   ret

restore:
   ; restore saved registers
   pop gs
   pop fs
   pop es
   pop ds
   popad
   
   ret
And kbd_handler:

Code: Select all

int counter = 0;

void kbd_handler(void)
{
   int i;

   i = inb(0x60);
   counter++;
}
Ok, that's it...
So there is no "counter" message printed out in idle...
Why? Can somebody help me please?
Whatever5k

Re:Unkown instruction...

Post by Whatever5k »

I have noticed that the bochsout.txt contains this error message only, if I press very often a key or if I keep a key pressed...
Why?
Whatever5k

Re:Unkown instruction...

Post by Whatever5k »

Hm, the error message always appears...
I do not think that it is a too big problem to solve...perhaps I have forgotten something...
What do you think..can you please help me?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Unkown instruction...

Post by Pype.Clicker »

don't ever expect your save/restore functions to work! you are pushing stuffs you don't pop before calling RET.

remember RET takes back the instruction pointer from the stack while you just pushed your registers overthere. if you want to keep a save/restore abstraction you should better do it with a macro than with a regular function call
Whatever5k

Re:Unkown instruction...

Post by Whatever5k »

You're right!
I forgot!
Post Reply