Any idea why this IDT code might cause a tripple fault??

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
Madmonky1

Any idea why this IDT code might cause a tripple fault??

Post by Madmonky1 »

Ive attached the idt.h file (you might be able to find some peices from SolarRay's code) here is what one of my IDT's looks like:

Code: Select all

_isr0:
 pusha
 push gs
 push fs
 push ds
 push es

 extern _interrupt_0
 call _interrupt_0

 pop es
 pop ds
 pop fs
 pop gs
 popa
 iret

;and here is my loadidt:

_loadidt:
                push ebp
                mov ebp,esp
                lidt [ebp+8]
                mov esp,ebp
                pop ebp

                ret
AFter I load my IDT and enable ints I get a triple fault, anyone know what's causing it??

EDIT: and here is the PIC remap code:

Code: Select all

#ifndef PIC_H
#define PIC_H
#include "main.h"
#define   PIC1      0x20
#define   PIC2      0xA0
#define   PIC1_COMMAND   PIC1
#define   PIC1_DATA   (PIC1+1)
#define   PIC2_COMMAND   PIC2
#define   PIC2_DATA   (PIC2+1)
#define   PIC_EOI      0x20
#define   ICW1_ICW4   0x01
#define   ICW1_SINGLE   0x02
#define   ICW1_INTERVAL4   0x04
#define   ICW1_LEVEL   0x08
#define   ICW1_INIT   0x10
#define   ICW4_8086   0x01
#define   ICW4_AUTO   0x02
#define   ICW4_BUF_SLAVE   0x08
#define   ICW4_BUF_MASTER   0x0C
#define   ICW4_SFNM   0x10

void remap_pics(int pic1, int pic2)
{
   UCHAR   a1, a2;
   a1=inb(PIC1_DATA);

   a2=inb(PIC2_DATA);
   outb(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4);

   outb(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4);
   outb(PIC1_DATA, pic1);
   outb(PIC2_DATA, pic2);
   outb(PIC1_DATA, 4);
   outb(PIC2_DATA, 2);
   outb(PIC1_DATA, ICW4_8086);
   outb(PIC2_DATA, ICW4_8086);
   outb(PIC1_DATA, a1);

   outb(PIC2_DATA, a2);
}

//Which I call like this:
 remap_pics(0x20, 0x28);
jrfritz

Re:Any idea why this IDT code might cause a tripple fault??

Post by jrfritz »

Ok here is working code...need to have irqs and execs

make err0-err19 and errReserved look like this:

extern void err0();

; in asm
err0:
cli
hlt
ret

make n look just like err0 and err 31 like err0...

   set_idt_entry( 0x0, err0 );
   set_idt_entry( 0x1, err1 );
   set_idt_entry( 0x2, err2 );
   set_idt_entry( 0x3, err3 );
   set_idt_entry( 0x4, err4 );
   set_idt_entry( 0x5, err5 );
   set_idt_entry( 0x6, err6 );
   set_idt_entry( 0x7, err7 );
   set_idt_entry( 0x8, err8 );
   set_idt_entry( 0x9, err9 );
   set_idt_entry( 0xA, err10 );
   set_idt_entry( 0xB, err11 );
   set_idt_entry( 0xC, err12 );
   set_idt_entry( 0xD, err13 );
   set_idt_entry( 0xE, err14 );
   set_idt_entry( 0xF, errReserved );
   set_idt_entry( 0x10, err16 );
   set_idt_entry( 0x11, err17 );
   set_idt_entry( 0x12, err18 );
   set_idt_entry( 0x13, err19 );
   set_idt_entry( 0x14, n );
   set_idt_entry( 0x15, n );
   set_idt_entry( 0x16, n );
   set_idt_entry( 0x17, n );
   set_idt_entry( 0x18, n );
   set_idt_entry( 0x19, n );
   set_idt_entry( 0x1A, n );
   set_idt_entry( 0x1B, n );
   set_idt_entry( 0x1C, n );
   set_idt_entry( 0x1D, n );
   set_idt_entry( 0x1E, n );
   set_idt_entry( 0x1F, n );
   set_idt_entry( 0x20, int20 );
   set_idt_entry( 0x21, int21 );
   set_idt_entry( 0x22, lowisr );
   set_idt_entry( 0x23, lowisr );
   set_idt_entry( 0x24, lowisr );
   set_idt_entry( 0x25, lowisr );
   set_idt_entry( 0x26, lowisr );
   set_idt_entry( 0x27, lowisr );
   set_idt_entry( 0x28, err31 );
   set_idt_entry( 0x29, err31 );
   set_idt_entry( 0x2A, err31 );
   set_idt_entry( 0x2B, err31 );
   set_idt_entry( 0x2C, err31 );
   set_idt_entry( 0x2D, err31 );
   set_idt_entry( 0x2E, err31 );
   set_idt_entry( 0x2F, err31 );
eL JeDi

Re:Any idea why this IDT code might cause a tripple fault??

Post by eL JeDi »

Hi Madmonky1,

Code: Select all

temp->selector = (USHORT) 0x9a;
Here you should have your SYS Code selector, which in most cases are 0x10. why you set it to 0x9a? Can we see your GDT code?
Madmonky1

Re:Any idea why this IDT code might cause a tripple fault??

Post by Madmonky1 »

eL JeDi wrote: Here you should have your SYS Code selector, which in most cases are 0x10. why you set it to 0x9a? Can we see your GDT code?
umm... good point :) its now 0x10, but in SolarRay's source it looks like its pointing to a c++ function instead of assembly, can you do that?
jrfritz

Re:Any idea why this IDT code might cause a tripple fault??

Post by jrfritz »

Well...you must have gotton old code because I edited mine...

It points to a #define, like this:

#define CodeSel <your code sel num here> // mine is 0x8

and this:

temp->selector = (USHORT) CodeSel;
Madmonky1

Re:Any idea why this IDT code might cause a tripple fault??

Post by Madmonky1 »

I got the most recent, that was just an error I made. BTW how do I know what my CodeSel is? I think mine is 0x8 to though.
eL JeDi

Re:Any idea why this IDT code might cause a tripple fault??

Post by eL JeDi »

Hi,

you can calculate it.

For example, here is my GDT

gdt:         ;our descriptors
; NULL descriptor
   dw 0      ; limit 15:0
   dw 0      ; base 15:0
   db 0      ; base 23:16
   db 0      ; type
   db 0      ; limit 19:16, flags
   db 0      ; base 31:24

[global LINEAR_DATA_SEL]
LINEAR_DATA_SEL   equ   $-gdt
   dw 0FFFFh
   dw 0
   db 0
   db 92h      
   db 0CFh      
   db 0
[global LINEAR_CODE_SEL]
LINEAR_CODE_SEL   equ   $-gdt
   dw 0FFFFh
   dw 0
   db 0
   db 9Ah      
   db 0CFh      
   db 0
gdt_end:

You know that each selector has 8 bytes.
For example:
LINEAR_DATA_SEL   is the second selector so 8x(2-1)=8.
the first selector is 0, second 8 ( 0x8 ), third 16 (0x10 )....etc

So you can make a #define in you C file with this values.

hope it helps
Madmonky1

Re:Any idea why this IDT code might cause a tripple fault??

Post by Madmonky1 »

Did what you said and it still tripple faults :(

should int20/int21/lowisr have something other than cli and hlt in them??
eL JeDi

Re:Any idea why this IDT code might cause a tripple fault??

Post by eL JeDi »

Hi once again,

here you have my ISR routine for int0:

[global int0]
int0:
pusha
push es
push ds
push fs
push gs

mov ax, LINEAR_DATA_SEL
mov ds, eax
mov es, eax
mov eax, 0
mov fs, eax
mov gs, eax

[extern exc0]
call exc0

popa
iret

my LINEA_DATA_SEL is 0x8


If you map your IRQs to int 20,21.. you don't need cli and hlt. You put cli and hlt when you are working with exceptions and faults. IRQ are not faults or execption.

Here is my IRQ1 handler

[EXTERN keybo]
[GLOBAL irq1]
irq1:
   pusha
   call keybo
   mov al, 0x20
   out 0x20, al
   popa
   IRET
jrfritz

Re:Any idea why this IDT code might cause a tripple fault??

Post by jrfritz »

You need to setup the exce ints and irqs...the IRQs should be at int 0x20 ( starting there) NOT 0x0.
Post Reply