This code triple faults bochs when I sti:
extern "C" long SYS_CODE_SEL;
void err()
{
panic( "Fault",1 );
}
typedef struct
{
unsigned short limit; /*16 bits*/
unsigned short base_low;
unsigned char base_mid; /*8 bits*/
unsigned char access;
unsigned char attribute;
unsigned short base_hi;
} __attribute__ ((packed)) gdt_entry;
typedef struct
{
unsigned short offset_low;
unsigned short selector;
unsigned char param_count;
unsigned char access;
unsigned short offset_high;
} __attribute__ ((packed)) idt_entry;
typedef struct
{
unsigned short limit; /*16 bits*/
unsigned long base; /*32 bits*/
} __attribute__ ((packed)) descriptor_reg;
descriptor_reg idt,gdt;
/* in my kernel initialization funtion idt is set up as follows
same idea applies when you want to change the initial boot to Pmode gdt
idt.limit=8*256-1;
idt.base=0x00000600;
*/
int set_idt_entry(unsigned long num,void (*funct)(void))
{
/*KERNEL_CODE_SEL is my kernel code selector in the GDT */
/*read INTEL MANUAL for explaination of each value and its meaning*/
idt_entry* idt_temp;
idt_temp=(idt_entry *)(idt.base+(num *
);
idt_temp->offset_low=(unsigned short) (((unsigned long)funct & 0xffff));
idt_temp->selector=(unsigned short)SYS_CODE_SEL;
idt_temp->access=(unsigned char)0x8e;
idt_temp->param_count=(unsigned char)0;
idt_temp->offset_high=(unsigned short)(((unsigned long)funct >> 16));
return 0;
}
extern "C" void loadidt(descriptor_reg *idt_ptr);
void init_idt(void) {
idt.limit=32*8-1;
idt.base=0x00000600;
set_idt_entry( 0x0, err );
set_idt_entry( 0x1, err );
set_idt_entry( 0x2, err );
set_idt_entry( 0x3, err );
set_idt_entry( 0x4, err );
set_idt_entry( 0x5, err );
set_idt_entry( 0x6, err );
set_idt_entry( 0x7, err );
set_idt_entry( 0x8, err );
set_idt_entry( 0x9, err );
set_idt_entry( 0xA, err );
set_idt_entry( 0xB, err );
set_idt_entry( 0xC, err );
set_idt_entry( 0xD, err );
set_idt_entry( 0xE, err );
set_idt_entry( 0xF, err );
set_idt_entry( 0x10, err );
set_idt_entry( 0x11, err );
set_idt_entry( 0x12, err );
set_idt_entry( 0x13, err );
set_idt_entry( 0x14, err );
set_idt_entry( 0x15, err );
set_idt_entry( 0x16, err );
set_idt_entry( 0x17, err );
set_idt_entry( 0x18, err );
set_idt_entry( 0x19, err );
set_idt_entry( 0x1A, err );
set_idt_entry( 0x1B, err );
set_idt_entry( 0x1C, err );
set_idt_entry( 0x1D, err );
set_idt_entry( 0x1E, err );
set_idt_entry( 0x1F, err );
}
start(){ init_idt();
loadidt( &idt );
getch();
sti();}