OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:28 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: [SOLVED] Weird bug with IRQ
PostPosted: Fri May 07, 2021 10:50 am 
Offline

Joined: Wed May 05, 2021 10:40 am
Posts: 5
Hey everyone !
This is my first post on this forum, and that might be a stupid question, but a cannot find the bug.

I am trying to developp a very small kernel.

I want to have at least the keyboard working, but i cannot make it work correctly.

It seems there is 2 problems in 1:

The irq event triggered depend of the text written on screen (wtf ?)

Which i think is the cause why keyboard 'pressed' event is sent twice while clicking once.

Here is my the code of my main:

Code:
void k_main(void)
{
   terminal_initialize();
   init_gdt();
   init_idt();
   //terminal_writestr("42\n");

   asm volatile ("sti");
   init_kbd();
   terminal_writestr("a");

   for(;;) {
      asm("hlt");
   }
}


As i said, the irq fired depend on the string lenght of this
Code:
terminal_writestr("a");
string.
One letter -> Irq 1, 2 letters irq 2, etc...

I am thinking of the way of handling irqs, but i cannot find my mistake

Here is the asm code for irqs:
Code:
%macro IRQ 2                    ; We need 2 parameters for our macro
  global irq%1                  ; First declare the name (irq0, irq1 etc...) as global
  irq%1:                        ; Declare our function with the name (irq0, irq1 etc...)
    cli                         ; Disable interrupts
    push byte 0                 ; push 0 on the stack
    push byte %2                ; Push irqcode into the stack (second parameter)
    jmp irq_common_stub         ; call irq_common_stub function
%endmacro

IRQ 0, 32
IRQ 1, 33
IRQ 2, 34
IRQ 3, 35
IRQ 4, 36
IRQ 5, 37
IRQ 6, 38
IRQ 7, 39
IRQ 8, 40
IRQ 9, 41
IRQ 10,42
IRQ 11,43
IRQ 12,44
IRQ 13,45
IRQ 14,46
IRQ 15,47

irq_common_stub:
    pusha           ; push everything on the stack
    push ds
    push es
    push fs
    push gs
    mov ax, 0x10
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov eax, esp
    push eax
    mov eax, irq_handler
    call eax
    pop eax
    pop gs
    pop fs
    pop es
    pop ds
    popa
    add esp, 8
    iret


Here is the full url of my project:
https://github.com/lubenard/kfs-1

Thanks !


Last edited by lubenard on Thu May 13, 2021 7:57 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Weird bug with IRQ
PostPosted: Sun May 09, 2021 10:32 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Your registers_t struct doesn't match the data being passed to your interrupt handler.

Once you fix that, you'll need to do something about how you're accessing beyond the end of this array.


Top
 Profile  
 
 Post subject: Re: Weird bug with IRQ
PostPosted: Mon May 10, 2021 2:07 pm 
Offline

Joined: Wed May 05, 2021 10:40 am
Posts: 5
Thanks !
Okay, so i think i fixed it, BUT, i am getting a invalid opcode when trying to type keyboard touch.
It is happening when calling the keyboard_handler in the irq handler.
It seems the address are the same, so i'll keep investigate with bochs
Thank's for helping !


Top
 Profile  
 
 Post subject: Re: Weird bug with IRQ
PostPosted: Thu May 13, 2021 7:57 am 
Offline

Joined: Wed May 05, 2021 10:40 am
Posts: 5
Okay, i fixed it !
I was getting a invalid opcode because SSE instructions were not enabled.
I followed this link: https://stackoverflow.com/questions/66510507/invalid-op-code-exception-when-implementing-irqs
and https://wiki.osdev.org/SSE


Top
 Profile  
 
 Post subject: Re: [SOLVED] Weird bug with IRQ
PostPosted: Thu May 13, 2021 11:08 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Don't forget, your IRQ handlers need to save and restore SSE registers if your kernel is using them.

Or you can pass the -mgeneral-regs-only flag to your compiler to tell it not to use SSE registers in your kernel.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 55 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group