Re:Some IDT Code...in C
Posted: Sun Dec 15, 2002 4:19 pm
okay, the best thing to do would be to post your setup code and you IDT code for us to find the problem.
The Place to Start for Operating System Developers
http://f.osdev.org/
Code: Select all
#include <osdefs.h>
#include <string.h>
#include <ia32_hal.h>
#include "screen.h"
#include "memory.h"
#include "idt.h"
#include "defines.h"
#include "irq.h"
#define TRAP_STUB(name, exc) \
void _exception_##name() { guru_meditation(exc); while(1); }
#define TRAP_NAME(name) (UINT32)(void*)&_exception_##name
extern void hi_irq(void);
extern void low_irq(void);
extern void dead_isr(void);
extern void fpu_isr(void);
void add_gate(int sel, UINT16 gdt, UINT16 type);
void setup_gate(int sel, UINT32 phys_off, UINT16 type);
void init_idt(void);
void load_idt(int num_idt, GATE* idt_offs);
void guru_meditation(int num);
char *guru[]=
{
"Divide by Zero",
"Debug",
"Non Maskable Interrupt",
"Breakpoint",
"Interrupt on Overflow",
"Array Bounds Error",
"Illegal Opcode",
"Math not available",
"Double Fault",
"Math segment overflow",
"Invalid TSS",
"Segment not present",
"Stack Fault",
"General Protection Error",
"Page Fault",
"na",
"Math Error",
"Alignment Error",
"Machine Check"
};
GATE *idt;
int num_idts;
TRAP_STUB(divide, 0);
TRAP_STUB(debug, 1);
TRAP_STUB(nmi, 2);
TRAP_STUB(breakpoint, 3);
TRAP_STUB(overflow, 4);
TRAP_STUB(bounds, 5);
TRAP_STUB(opcode, 6);
TRAP_STUB(mathgone, 7);
TRAP_STUB(double, 8);
TRAP_STUB(mathover, 9);
TRAP_STUB(tss, 10);
TRAP_STUB(segment, 11);
TRAP_STUB(stack, 12);
TRAP_STUB(general, 13);
TRAP_STUB(page, 14);
TRAP_STUB(matherr, 16);
TRAP_STUB(align, 17);
TRAP_STUB(mce, 18);
void setup_gate(int sel, UINT32 phys_off, UINT16 type)
{
idt[sel].offset_0=(phys_off&0xFFFF);
idt[sel].offset_16=(phys_off>>16);
idt[sel].selector=0x08; // code32
idt[sel].type=type;
}
void add_gate(int sel, UINT16 gdt, UINT16 type)
{
idt[sel].offset_0=0;
idt[sel].offset_16=0;
idt[sel].selector=gdt;
idt[sel].type=type;
}
void init_idt(void)
{
int c;
num_idts=256;
idt=(GATE*)__flat_alloc(sizeof(GATE)*256);
memset(idt, 0x0, sizeof(GATE)*256);
/* flush all IDT entries to a null ISR */
for(c=0; c<256; c++)
setup_gate(c, (UINT32)(void*)&dead_isr, CPL0_TRAP_GATE);
/* setup the first 8 IRQ's */
for(c=IRQ0; c<=IRQ7; c++)
setup_gate(c, (UINT32)(void*)&low_irq, CPL0_IRQ_GATE);
/* setup the second 8 IRQ's */
for(c=IRQ8; c<=IRQ15; c++)
setup_gate(c, (UINT32)(void*)&hi_irq, CPL0_IRQ_GATE);
/* mask the IDT entries for the TRAPS */
setup_gate(0, TRAP_NAME(divide), CPL0_TRAP_GATE);
setup_gate(1, TRAP_NAME(debug), CPL0_TRAP_GATE);
setup_gate(2, TRAP_NAME(nmi), CPL0_TRAP_GATE);
setup_gate(3, TRAP_NAME(breakpoint), CPL0_TRAP_GATE);
setup_gate(4, TRAP_NAME(overflow), CPL0_TRAP_GATE);
setup_gate(5, TRAP_NAME(bounds), CPL0_TRAP_GATE);
setup_gate(6, TRAP_NAME(opcode), CPL0_TRAP_GATE);
setup_gate(7, TRAP_NAME(mathgone), CPL0_TRAP_GATE);
setup_gate(8, TRAP_NAME(double), CPL0_TRAP_GATE);
setup_gate(9, TRAP_NAME(mathover), CPL0_TRAP_GATE);
setup_gate(10, TRAP_NAME(tss), CPL0_TRAP_GATE);
setup_gate(11, TRAP_NAME(segment), CPL0_TRAP_GATE);
setup_gate(12, TRAP_NAME(stack), CPL0_TRAP_GATE);
setup_gate(13, TRAP_NAME(general), CPL0_TRAP_GATE);
setup_gate(14, TRAP_NAME(page), CPL0_TRAP_GATE);
setup_gate(16, TRAP_NAME(matherr), CPL0_TRAP_GATE);
setup_gate(17, TRAP_NAME(align), CPL0_TRAP_GATE);
setup_gate(18, TRAP_NAME(mce), CPL0_TRAP_GATE);
/* init the IDT into the CPU */
load_idt(num_idts, idt);
}
void load_idt(int num_idt, GATE* idt_offs)
{
UINT32 x[2];
x[0]=((num_idt*sizeof(GATE))-1)<<16;
x[1]=(UINT32)idt_offs;
__asm__ __volatile__ ("lidt (%0)"::"d"((int)((unsigned char*)x)+2):"memory");
io_wait();
}
void guru_meditation(int num)
{
disable_ints();
//irqs=0xFFFF;
//refresh_irqs();
kprintf("\n\nGuru Meditation :: %i %s\n\n", num, guru[num]);
while(1);
}
hmm well I know my code works. right now i'm at work (start of my day, 8am), so i cant look over your gdt stuff here... but my guess is (obviously) something else is wrongTom wrote: Ok, DF's won't work either...i'm going back to Code Slashers...