概要
wslで、kernel.elfのコンパイル、やってみた。
IDTを作りたい。
IDTとは。
サンプルコード
#include <stdio.h>
#define D_LDT 0x200 /* LDT segment */
#define D_TASK 0x500 /* Task gate */
#define D_TSS 0x900 /* TSS */
#define D_CALL 0x0C00 /* 386 call gate */
#define D_INT 0x0E00 /* 386 interrupt gate */
#define D_TRAP 0x0F00 /* 386 trap gate */
#define D_DATA 0x1000 /* Data segment */
#define D_CODE 0x1800 /* Code segment */
#define D_DPL3 0x6000 /* DPL3 or mask for DPL */
#define D_DPL2 0x4000 /* DPL2 or mask for DPL */
#define D_DPL1 0x2000 /* DPL1 or mask for DPL */
#define D_PRESENT 0x8000 /* Present */
#define D_NOT_PRESENT 0x8000 /* Not Present */
#define D_ACC 0x100 /* Accessed (Data or Code) */
#define D_WRITE 0x200 /* Writable (Data segments only) */
#define D_READ 0x200 /* Readable (Code segments only) */
#define D_BUSY 0x200 /* Busy (TSS only) */
#define D_EXDOWN 0x400 /* Expand down (Data segments only) */
#define D_CONFORM 0x400 /* Conforming (Code segments only) */
#define D_BIG 0x40 /* Default to 32 bit mode */
#define D_BIG_LIM 0x80 /* Limit is in 4K units */
struct x86_desc {
unsigned short limit_low; /* limit 0..15 */
unsigned short base_low; /* base 0..15 */
unsigned char base_med; /* base 16..23 */
unsigned char access; /* access byte */
unsigned int limit_high:4; /* limit 16..19 */
unsigned int granularity:4; /* granularity */
unsigned char base_high; /* base 24..31 */
} __attribute__ ((packed));
struct x86_gate {
unsigned short offset_low; /* offset 0..15 */
unsigned short selector; /* selector */
unsigned short access; /* access flags */
unsigned short offset_high; /* offset 16..31 */
} __attribute__ ((packed));
union DT_entry {
struct x86_desc desc; /* Normal descriptor */
struct x86_gate gate; /* Gate descriptor */
unsigned long long dummy; /* Any other info */
};
#define desc_table(name, length) union DT_entry name[length] =
#define stnd_desc(base, limit, control) {desc: {(limit & 0xffff), (base & 0xffff), ((base >> 16) & 0xff), ((control+D_PRESENT) >> 8), (limit >> 16), ((control & 0xff) >> 4), (base >> 24)}}
desc_table(IDT, 256) {
};
struct {
unsigned short limit __attribute__ ((packed));
union DT_entry * idt __attribute__ ((packed));
} loadidt = { (256 * sizeof(union DT_entry) - 1), IDT };
int main(void) {
printf("ok");
}
以上。