2007年11月14日水曜日

IDTの設定

(1) GDTの設定
(2) IDTの設定 <- 今日はここ
(3) 割込み制御
(4) Global Constructor の呼び出し
(5) メモリ管理

ヘッダはこれ。

#ifndef __IDT_H__
#define __IDT_H__

#include "types.h"
#include "descripter.h"

struct IdtEntry{
uint16 offset_low;
uint16 selector;
uint16 copy :8;
uint16 type :8;
uint16 offset_hi;
} __attribute__ ((packed));

class Idt{
public:
static const int NUM = 256;
void init(void);

void set(int index, uint32 offset, uint16 selector, uint8 copy, uint8 type);
void load(void) const;

private:
DescripterTable table __attribute__((aligned(8)));
IdtEntry entry[NUM] __attribute__((aligned(8)));
};

#endif /* __IDT_H__ */


で、こっちが本体。
とりあえず、Timer と Keyboard の割り込みにハンドラを設定しました。


#include "idt.h"
#include "gdt.h"

extern "C" {
extern void asm_int_handler0(void);
extern void asm_int_handler1(void);
}

void Idt::init(void) {
table.limit = Idt::NUM * sizeof(IdtEntry) - 1;
table.offset = (uint32)entry;

for (int i = 0; i
set(i, 0, 0, 0, 0);
}

set(0x20, (uint32)asm_int_handler0,
Gdt::KERNEL_CS * sizeof(GdtEntry), 0, 0x8E);
set(0x21, (uint32)asm_int_handler1,
Gdt::KERNEL_CS * sizeof(GdtEntry), 0, 0x8E);
load();
}

void Idt::set(int index, uint32 offset, uint16 selector, uint8 copy, uint8 type) {
IdtEntry& desc = entry[index];

desc.offset_low = offset & 0xFFFF;
desc.offset_hi = (offset >> 16) & 0xFFFF;
desc.selector = selector;
desc.copy = copy;
desc.type = type;
}

void Idt::load(void) const {
__asm__ __volatile__("lidt %0" :: "m" (table));
}

0 件のコメント: