X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=blobdiff_plain;f=misc%2Ftest_vm%2Fsrc%2Fgeekos%2Fidt.c;fp=misc%2Ftest_vm%2Fsrc%2Fgeekos%2Fidt.c;h=5e2398961b6a56630cd5bb2d4aacf6f734bebaa5;hp=0000000000000000000000000000000000000000;hb=ddc16b0737cf58f7aa90a69c6652cdf4090aec51;hpb=626595465a2c6987606a6bc697df65130ad8c2d3 diff --git a/misc/test_vm/src/geekos/idt.c b/misc/test_vm/src/geekos/idt.c new file mode 100644 index 0000000..5e23989 --- /dev/null +++ b/misc/test_vm/src/geekos/idt.c @@ -0,0 +1,172 @@ +/* + * GeekOS IDT initialization code + * Copyright (c) 2001, David H. Hovemeyer + * $Revision: 1.1 $ + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "COPYING". + */ + +#include +#include +#include +#include + +/* ---------------------------------------------------------------------- + * Private data and functions + * ---------------------------------------------------------------------- */ + +/* + * Allocated + */ +static union IDT_Descriptor s_IDT[ NUM_IDT_ENTRIES ]; + +// JRL: why??? Should just call Alloc_Page(), otherwise we have dependencies all over the place +//static union IDT_Descriptor *s_IDT = (union IDT_Descriptor *)IDT_LOCATION; + +/* + * These symbols are defined in lowlevel.asm, and define the + * size of the interrupt entry point table and the sizes + * of the individual entry points. This gives us sufficient + * information to build the IDT. + */ +extern char g_entryPointTableStart, g_entryPointTableEnd; +extern int g_handlerSizeNoErr, g_handlerSizeErr; + +/* + * Table of C interrupt handler functions. + * Note that this is public only because it is used + * in lowlevel.asm. Other code should not refer to it. + */ +Interrupt_Handler g_interruptTable[ NUM_IDT_ENTRIES ]; + + + +void DumpIDT() +{ + int i; + Print("IDT Contents:\n"); + + for (i=0;i> 16; + + /* Install the new table in the IDTR. */ + Load_IDTR(limitAndBase); +} + +/* + * Initialize an interrupt gate with given handler address + * and descriptor privilege level. + */ +void Init_Interrupt_Gate(union IDT_Descriptor* desc, ulong_t addr, + int dpl) +{ + desc->ig.offsetLow = addr & 0xffff; + desc->ig.segmentSelector = KERNEL_CS; + desc->ig.reserved = 0; + desc->ig.signature = 0x70; /* == 01110000b */ + desc->ig.dpl = dpl; + desc->ig.present = 1; + desc->ig.offsetHigh = addr >> 16; +} + +/* + * Install a C handler function for given interrupt. + * This is a lower-level notion than an "IRQ", which specifically + * means an interrupt triggered by external hardware. + * This function can install a handler for ANY interrupt. + */ +void Install_Interrupt_Handler(int interrupt, Interrupt_Handler handler) +{ + KASSERT(interrupt >= 0 && interrupt < NUM_IDT_ENTRIES); + g_interruptTable[interrupt] = handler; +}