System reboots after interrupt handler

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
Qeroq
Member
Member
Posts: 52
Joined: Wed Aug 25, 2010 6:35 am
Location: Bonn, Germany

System reboots after interrupt handler

Post 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.
https://github.com/qero/Hydrogen (Loader for AMD64 kernels running on top of GRUB2)
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: System reboots after interrupt handler

Post by Candy »

Guessing: use iretd/iretl/iretq instead of iret?
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: System reboots after interrupt handler

Post by Gigasoft »

Check that isr_handler uses the __stdcall calling convention.
Qeroq
Member
Member
Posts: 52
Joined: Wed Aug 25, 2010 6:35 am
Location: Bonn, Germany

Re: System reboots after interrupt handler

Post by Qeroq »

Problem solved, it was a simple typo (0x0F instead of 0xF0) in GDT code...
Thank you for your answers.
https://github.com/qero/Hydrogen (Loader for AMD64 kernels running on top of GRUB2)
Post Reply