diff --git a/src/sys/sys/idt.c b/src/sys/sys/idt.c index b3b99ed..d57165d 100644 --- a/src/sys/sys/idt.c +++ b/src/sys/sys/idt.c @@ -24,6 +24,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. $Log$ + Revision 1.3 2004/04/30 13:40:35 reddawg + Just doing spring cleaning for the new members + Revision 1.1.1.1 2004/04/15 12:07:17 reddawg UbixOS v1.0 @@ -44,6 +47,7 @@ #include #include #include +#include #define FP_TO_LINEAR(seg, off) ((void*) ((((uInt16) (seg)) << 4) + ((uInt16) (off)))) @@ -67,52 +71,50 @@ 02/20/2004 - Approved for quality ************************************************************************/ -int -idtInit() -{ - int i = 0x0; +int idtInit() { + int i = 0x0; - struct tssStruct *gpfTSS = (struct tssStruct *)0x4200; + struct tssStruct *gpfTSS = (struct tssStruct *)0x4200; /* Set up default vector table for all possible 256 interrupts */ for (i = 0x0; i < 256; i++) { - setVector(&intNull, i, dPresent + dInt + dDpl3); - } + setVector(intNull, i, dPresent + dInt + dDpl3); + } /* Load the IDT into the system */ asm( - "cli\n" - "lidt (%0) \n" /* Load the IDT */ - "pushfl \n" /* Clear the NT flag */ - "andl $0xffffbfff,(%%esp) \n" - "popfl \n" - "sti \n" -: -: "r"((char *)&loadidt) + "cli \n" + "lidt (%0) \n" /* Load the IDT */ + "pushfl \n" /* Clear the NT flag */ + "andl $0xffffbfff,(%%esp) \n" + "popfl \n" + "sti \n" + : + : "r" ((char *)&loadidt) ); /* Set up the basic vectors for the reserved ints */ - setVector(&_int0, 0, dPresent + dTrap + dDpl3); - setVector(&_int1, 1, dPresent + dTrap + dDpl3); - setVector(&_int2, 2, dPresent + dTrap + dDpl3); - setVector(&_int3, 3, dPresent + dTrap + dDpl3); - setVector(&_int4, 4, dPresent + dTrap + dDpl3); - setVector(&_int5, 5, dPresent + dTrap + dDpl3); - setVector(&_int6, 6, dPresent + dTrap + dDpl3); - setVector(&_int7,7,dPresent + dTrap + dDpl3); - setVector(&_int9, 9, dPresent + dTrap + dDpl3); - setVector(&_int10, 10, dPresent + dTrap + dDpl3); - setVector(&_int11, 11, dPresent + dTrap + dDpl3); - setVector(&_int12, 12, dPresent + dTrap + dDpl3); + setVector(_int0, 0, dPresent + dTrap + dDpl3); + setVector(_int1, 1, dPresent + dTrap + dDpl3); + setVector(_int2, 2, dPresent + dTrap + dDpl3); + setVector(_int3, 3, dPresent + dTrap + dDpl3); + setVector(_int4, 4, dPresent + dTrap + dDpl3); + setVector(_int5, 5, dPresent + dTrap + dDpl3); + setVector(_int6, 6, dPresent + dTrap + dDpl3); + setVector(_int7,7,dPresent + dTrap + dDpl3); + setVector(_int9, 9, dPresent + dTrap + dDpl3); + setVector(_int10, 10, dPresent + dTrap + dDpl3); + setVector(_int11, 11, dPresent + dTrap + dDpl3); + setVector(_int12, 12, dPresent + dTrap + dDpl3); setTaskVector(13, dPresent + dTask + dDpl3, 0x38); - setVector(&_vmmPageFault, 14, dPresent + dTrap + dDpl3); - setVector(&_sysCall, 128, dPresent + dTrap + dDpl3); - setVector(&timerInt, 0x68, (dInt + dPresent + dDpl3)); + setVector(_vmmPageFault, 14, dPresent + dTrap + dDpl3); + setVector(_sysCall, 128, dPresent + dTrap + dDpl3); + setVector(timerInt, 0x68, (dInt + dPresent + dDpl3)); gpfTSS->back_link = 0x0; - gpfTSS->esp0 = 0x0;//(uInt32)kmalloc(4096,sysID)+4096; - gpfTSS->ss0 = 0x0;//0x10; + gpfTSS->esp0 = 0x0; + gpfTSS->ss0 = 0x0; gpfTSS->esp1 = 0x0; gpfTSS->ss1 = 0x0; gpfTSS->esp2 = 0x0; @@ -140,13 +142,11 @@ /* Return so we know all went well */ return (0x0); -} + } /* Sets Up IDT Vector */ -void -setVector(void *handler, unsigned char interrupt, unsigned short controlMajor) -{ +void setVector(void *handler, unsigned char interrupt, unsigned short controlMajor) { unsigned short codesegment = 0x08; asm volatile ("movw %%cs,%0":"=g" (codesegment)); @@ -310,9 +310,7 @@ * kprintf("Task Id: [%i]\n",_current->id); while(1); } */ -void -_int13() -{ +void _int13() { uInt8 *ip = 0x0; uInt16 *stack = 0x0, *ivt = 0x0; uInt32 *stack32 = 0x0; @@ -325,13 +323,7 @@ stack = (uInt16 *) FP_TO_LINEAR(_current->tss.ss,_current->tss.esp); stack32 = (uInt32 *) stack; - //kprintf("_current->tss.cs: [0x%X:0x%X:0x%X:0x%X]\n",_current->tss.cs,_current->tss.eip,_current->id,_current->tss.ss); - //kprintf("\n\nSS: [0x%X]\n",_current->tss.eflags); - gpfStart: - - //kprintf("ip[0]: 0x%X:0x%X\n",ip,ip[0]); - //kprintf("IP: [0x%X][0x%X][0x%X][0x%X][0x%X]\n",ip,ip[0],ip[1],ip[2],ip[3]); switch (ip[0]) { case 0xCD: /* INT n */ switch (ip[1]) { @@ -341,8 +333,7 @@ break; case 0x20: case 0x21: - kprintf("Help!!!\n"); - while (1); + kpanic("GPF OP 0x20/0x21\n"); break; default: stack -= 3; @@ -355,8 +346,6 @@ stack[2] &= ~EFLAG_IF; _current->tss.cs = ivt[ip[1] * 2 + 1] & 0xFFFF; _current->tss.eip = ivt[ip[1] * 2] & 0xFFFF; - //kprintf("New Int [0x%X][0x%X][0x%X][0x%X]\n",ip[1],_current->tss.cs,_current->tss.eip,_current->id); - //while(1); break; } break; @@ -374,8 +363,7 @@ break; case 0xF0: _current->tss.eip = (uInt16) (_current->tss.eip + 1); - kprintf("No!!!\n"); - while (1); + kpanic("GPF OP 0xF0\n"); break; case 0x9C: if (isOperand32 == TRUE) { @@ -414,7 +402,6 @@ _current->tss.eflags &= ~EFLAG_IF; _current->tss.eip = (uInt16) (_current->tss.eip + 1); _current->oInfo.timer = 0x1; - /* kprintf("cli [0x%X]\n",_current->id); */ break; case 0xFB: _current->oInfo.v86If = TRUE; @@ -434,57 +421,30 @@ case 0xEC: /* IN AL,DX */ _current->tss.eax = (_current->tss.eax & ~0xFF) | inportByte(_current->tss.edx); _current->tss.eip = (uInt16) (_current->tss.eip + 1); - - /* - * kprintf("IN DX[0x%X],AL[0x%X] - * [0x%X]\n",_current->tss.edx,_current->tss.eax & 0xFF,_current->id); - */ break; case 0xED: /* IN AX,DX */ _current->tss.eax = (_current->tss.eax & ~0xFFFF) | inportWord(_current->tss.edx); _current->tss.eip = (uInt16) (_current->tss.eip + 1); - - /* - * kprintf("IN DX[0x%X],AX[0x%X] - * [0x%X]\n",_current->tss.edx,_current->tss.eax & 0xFFFF,_current->id); - */ break; case 0xEE: /* OUT DX,AL */ outportByte(_current->tss.edx, _current->tss.eax & 0xFF); _current->tss.eip = (uInt16) (_current->tss.eip + 1); - - /* - * kprintf("OUT DX[0x%X],AL[0x%X] - * [0x%X]\n",_current->tss.edx,_current->tss.eax & 0xFF,_current->id); - */ break; case 0xEF: outportWord(_current->tss.edx, _current->tss.eax); _current->tss.eip = (uInt16) (_current->tss.eip + 1); - - /* - * kprintf("OUT DX[0x%X],AX[0x%X] - * [0x%X]\n",_current->tss.edx,_current->tss.eax,_current->id); - */ break; case 0xF4: _current->tss.eip = (uInt16) (_current->tss.eip + 1); - /* kprintf("HLT [0x%X]\n",_current->id); */ break; default: /* something wrong */ kprintf("NonHandled OpCode [0x%X:0x%X]\n",_current->id,ip[0]); _current->state = DEAD; - /* - * kprintf("Non Handled OpCode [0x%X]\n",_current->id); - * setTaskStatus(_current->id,EXITING); Temp Reboot For Now - * while(inportByte(0x64) & 0x02); outportByte(0x64, 0xfe); - */ break; - } - //kprintf("\nEFLAGS: [0x%X]\n",_current->tss.eflags); + } irqEnable(0); while (1); -} + } /* Timer Interupt */ __asm__( @@ -538,15 +498,27 @@ ); void mathStateRestore() { - if (_usedMath != 0x0) - __asm__("fnsave %0"::"m" (_usedMath->i387)); - if (_current->usedMath != 0x0) - __asm__("frstor %0"::"m" (_current->i387)); - else { - __asm__("fninit"::); - _current->usedMath=1; + if (_usedMath != 0x0) { + asm( + "fnsave %0" + : + : "m" (_usedMath->i387) + ); } - _usedMath=_current; + if (_current->usedMath != 0x0) { + asm( + "frstor %0" + : + : "m" (_current->i387) + ); + } + else { + asm("fninit"); + _current->usedMath = 0x1; + } + + _usedMath=_current; + //Return }