structures and definitions:
Code: Select all
// structures
typedef struct {
WORD offset15_0;
WORD selector;
WORD DPL;
WORD offset31_16;
} IDT_t;
typedef struct {
WORD limit_lo;
WORD base_lo;
BYTE base_hi;
BYTE type;
BYTE limit_hi;
BYTE base_vhi;
} GDT_desc_t;
typedef struct {
GDT_desc_t desc_NULL;
GDT_desc_t desc_unused;
GDT_desc_t desc_datasel;
GDT_desc_t desc_codesel;
} GDT_t;
// definitions
IDT_t IDT[256]; // the IDT-table
GDT_t GDT;
Code: Select all
void pic_init (address_t pic1, address_t pic2) { // initialize PIC, 0x20 and 0x28 are used
/* send ICW1 */
p_outb(PIC1, ICW1);
p_outb(PIC2, ICW1);
/* send ICW2 */
p_outb(PIC1 + 1, pic1); /* remap */
p_outb(PIC2 + 1, pic2); /* pics */
/* send ICW3 */
p_outb(PIC1 + 1, 4); /* IRQ2 -> connection to slave */
p_outb(PIC2 + 1, 2);
/* send ICW4 */
p_outb(PIC1 + 1, ICW4);
p_outb(PIC2 + 1, ICW4);
/* enable keyboard */
p_outb(0x21,0xfd);
p_outb(0xa1,0xff);
}
void lidt(void *base, unsigned int limit) { // this one came from this site
unsigned int i[2];
i[0] = limit << 16;
i[1] = (unsigned int) base;
asm ("lidt (%0)": :"p" (((char *) i)+2));
}
void lgdt(void *base, unsigned int limit) { // for the gdt..not sure this is right
unsigned int i[2];
i[0] = limit << 16;
i[1] = (unsigned int) base;
asm ("lgdt (%0)": :"p" (((char *) i)+2));
}
void intr_init (void) { // initialize the interrupts
int i;
GDT_fill_in(&GDT); // Fill in GDT
lgdt(&GDT, sizeof(GDT));
lidt(&IDT, sizeof(IDT)); // Link the IDT to the CPU
/* Init the exceptions and the traps */
for (i = 0; i < 17; i++) set_vector((unsigned int) exception, 0x8E, i);
for (i = 17; i < 256; i++) set_vector((unsigned int) trap, 0x8E, i);
}
void set_vector (unsigned int addr, unsigned int access_byte, unsigned vect_num) { // set a new isr
IDT[vect_num].offset15_0 = addr >> 16;
IDT[vect_num].offset31_16 = addr;
IDT[vect_num].selector = 0x10;
IDT[vect_num].DPL = access_byte;
}
void GDT_fill_in (GDT_t *gdt) { // fill in the GDT
// NULL descriptor
gdt->desc_NULL.limit_lo = 0;
gdt->desc_NULL.base_lo = 0;
gdt->desc_NULL.base_hi = 0;
gdt->desc_NULL.type = 0;
gdt->desc_NULL.limit_hi = 0;
gdt->desc_NULL.base_vhi = 0;
// unused descriptor
gdt->desc_unused.limit_lo = 0;
gdt->desc_unused.base_lo = 0;
gdt->desc_unused.base_hi = 0;
gdt->desc_unused.type = 0;
gdt->desc_unused.limit_hi = 0;
gdt->desc_unused.base_vhi = 0;
// Linear Data Selector descriptor
gdt->desc_datasel.limit_lo = 0xFFFF;
gdt->desc_datasel.base_lo = 0;
gdt->desc_datasel.base_hi = 0;
gdt->desc_datasel.type = 0x92;
gdt->desc_datasel.limit_hi = 0x0CF;
gdt->desc_datasel.base_vhi = 0;
// Linear Code Selector descriptor
gdt->desc_codesel.limit_lo = 0xFFFF;
gdt->desc_codesel.base_lo = 0;
gdt->desc_codesel.base_hi = 0;
gdt->desc_codesel.type = 0x9A;
gdt->desc_codesel.limit_hi = 0x0CF;
gdt->desc_codesel.base_vhi = 0;
}
// this to assign keyboard routine: set_vector((unsigned int) kbd_irq, 0x8E, 0x21);
i just can't find the error.. i would be really really grateful if someone could pick out my mistakes..
thanx in advance