Page 1 of 1

System reboots after interrupt handler

Posted: Fri Aug 27, 2010 5:55 am
by Qeroq
Hello,
after having set up the IDT for my kernel, I wanted to try it out with both an

Code: Select all

int a = 7 / 0; // For interrupt 0x00
and an

Code: Select all

asm volatile("int $0x01");
My interrupt handler is successfully called (debugging using videomem and infinite loops *g*) but after that the system (emulated in qemu) reboots.

I am using

Code: Select all

isr_common_stub:
    pusha               ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
    
    push ds             ; Save the data segment descriptor
    
    mov ax, 0x10        ; Load the kernel data segment descriptor
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    
    xor ebp, ebp        ; Create new stackframe
    
    mov eax, esp
    push eax
    
    call _isr_handler
    
    pop ax             ; Restore original data segment descriptor
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    
    popa                ; Pops edi,esi,ebp,esp,ebx,edx,ecx,eax
    add esp, 0x08       ; Cleans up the pushed error code and pushed ISR number
    sti
    iret                ; Pops 5 things at once: CS, EIP, EFLAGS; SS and ESPclear
called by interrupt methods defined by macros

Code: Select all

%macro ISR_NOERRCODE 1
    [GLOBAL isr%1]
    isr%1:
        cli
        push byte 0
        push byte %1
        jmp isr_common_stub
%endmacro
and

Code: Select all

%macro ISR_ERRCODE 1
    [GLOBAL isr%1]
    isr%1:
        cli
        push byte %1
        jmp isr_common_stub
%endmacro
registered with selector 0x08 and flags 0x8E.

Works neither with protected nor real mode, no userspace code is executed. Grub is used as the bootmanager.

Is this the defined behavior, or should the system be able to return to normal execution?

Edit:
Also, if I call

Code: Select all

Console::getInstance()->write(str);
in my interrupt handler, nothing is written at all. I'm currently debugging what fails.

Re: System reboots after interrupt handler

Posted: Fri Aug 27, 2010 6:32 am
by Candy
Guessing: use iretd/iretl/iretq instead of iret?

Re: System reboots after interrupt handler

Posted: Fri Aug 27, 2010 8:42 am
by Gigasoft
Check that isr_handler uses the __stdcall calling convention.

Re: System reboots after interrupt handler

Posted: Fri Aug 27, 2010 10:15 am
by Qeroq
Problem solved, it was a simple typo (0x0F instead of 0xF0) in GDT code...
Thank you for your answers.