接下來就要先初始化中斷向量。如書上所說,intel默認保留使用了0~31箇中斷給自己使用。這些中斷目前不想處理。所以這些中斷的處理函數只是打印一下就可以。
traps.c源代碼:
#include <io.h>
#include <start32.h>
#include <system.h>
void default_handle(void);
void do_default_handle()
{
/*do nothing by now.*/
printk("default handle\n");
return;
}
void trap_init(void)
{
int i;
//32箇中斷爲intel保留使用, 8259-1使用8箇中斷,8259-2使用8箇中斷,所以總共要加48箇中斷處理函數。
for( i = 0; i < 48; i++ )
{
set_trap_gate(i, &default_handle);
}
}
//start32.h 拷貝自linux源代碼中的head.h
-------
#ifndef __START32_H__
#define __START32_H__
/*copy from linux source code: head.h*/
typedef struct desc_struct {
unsigned long a,b;
} desc_table[256];
extern desc_table idt,gdt;
#define GDT_NUL 0
#define GDT_CODE 1
#define GDT_DATA 2
#define GDT_TMP 3
#define LDT_NUL 0
#define LDT_CODE 1
#define LDT_DATA 2
#endif