Strange Interrupt Code
Strange Interrupt Code
I am writing a basic kernel following JamesM's tutorial with slightly modified code. I was testing the Exception Handler by dividing by zero and I end up with an endless chain of isr_handler with r->int_code = 0xc00000e6 unless I add an "asm volatile ("hlt")" at the end of my isr_handler statement, at which point I still get one interrupt code 0xc00000e6 instead of the expected 0x0000000. Any idea as to what might be causing this? I am running the kernel on bochs running in ubuntu within VMWare on top of WinXP
Dead serious
The assembly looks fine to me... here is what I have:
No Error Code Macro:
Using the macro:
jump to isr_common_stub:
EDIT - Almost forgot:
The assembly looks fine to me... here is what I have:
No Error Code Macro:
Code: Select all
%macro ISR_NOERRCODE 1
global isr%1
isr%1:
cli ; Disable interrupts firstly.
push byte 0 ; Push a dummy error code.
push byte %1 ; Push the interrupt number.
jmp isr_common_stub ; Go to our common handler code.
%endmacro
Code: Select all
ISR_NOERRCODE 0
Code: Select all
isr_common_stub:
pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
mov ax, ds ; Lower 16-bits of eax = ds.
push eax ; 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
call isr_handler
pop ebx ; reload the original data segment descriptor
mov ds, bx
mov es, bx
mov fs, bx
mov gs, bx
popa ; Pops edi,esi,ebp...
add esp, 8 ; Cleans up the pushed error code and pushed ISR number
sti
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
Code: Select all
void isr_handler(struct regs *r)
{
printf("Handling ISR!\n");
printf("%h",r->int_no);
/* Is this a fault whose number is from 0 to 31? */
if (r->int_no < 32)
{
/* Display the description for the Exception that occurred.
* In this tutorial, we will simply halt the system using an
* infinite loop */
PANIC(exception_messages[r->int_no]);
}
//asm volatile ("hlt");
}
Code: Select all
struct regs
{
u32int gs, fs, es, ds;
u32int edi, esi, ebp, esp, ebx, edx, ecx, eax;
u32int int_no, err_code;
u32int eip, cs, eflags, useresp, ss;
};
- os.hacker64
- Member
- Posts: 149
- Joined: Mon Feb 11, 2008 4:43 pm
- Location: Limbo City,Afterlife
Hi,
Hope this helps.
James
This is wrong. gs, fs and es are never pushed. Look at your code. It *should* be:Code: Select all
struct regs { u32int gs, fs, es, ds; u32int edi, esi, ebp, esp, ebx, edx, ecx, eax; u32int int_no, err_code; u32int eip, cs, eflags, useresp, ss; };
Code: Select all
struct regs
{
u32int ds;
u32int edi, esi, ebp, esp, ebx, edx, ecx, eax;
u32int int_no, err_code;
u32int eip, cs, eflags, useresp, ss;
};
James