diff --git a/src/sys/include/sys/idt.h b/src/sys/include/sys/idt.h index 2673e21..eac5bc6 100644 --- a/src/sys/include/sys/idt.h +++ b/src/sys/include/sys/idt.h @@ -38,10 +38,25 @@ #define EFLAG_IOPL3 0x3000 #define EFLAG_VM 0x20000 -int idt_init(); -void idt_setVector(void *handler, unsigned char interrupt, unsigned short controlMajor); -void idt_setTaskVector(uInt8 interrupt,uInt16 controlMajor,uInt8 selector); +int idt_init(); +void setVector(void *handler, unsigned char interrupt, unsigned short controlMajor); +void setTaskVector(uInt8 interrupt,uInt16 controlMajor,uInt8 selector); +void intNull(); +void _int0(); +void _int1(); +void _int2(); +void _int3(); +void _int4(); +void _int5(); +void _int6(); +void _int7(); +void _int8(); +void _int9(); +void _int10(); +void _int11(); +void _int12(); +void _int13(); void timerInt(); #endif diff --git a/src/sys/include/ubixos/init.h b/src/sys/include/ubixos/init.h index 0272333..21f1f80 100644 --- a/src/sys/include/ubixos/init.h +++ b/src/sys/include/ubixos/init.h @@ -59,8 +59,8 @@ pit_init, atkbd_init, time_init, - net_init, - ne2k_init, + /* net_init, */ + /* ne2k_init, */ devfs_init, pci_init, ubixfs_init, @@ -74,6 +74,9 @@ /*** $Log$ + Revision 1.29 2004/09/07 20:58:35 reddawg + time to roll back i can't think straight by friday + Revision 1.28 2004/08/20 16:49:11 reddawg PCI Updates - More to follow as PCI system gets revamped diff --git a/src/sys/include/ubixos/sched.h b/src/sys/include/ubixos/sched.h index 915c2e5..aff65db 100644 --- a/src/sys/include/ubixos/sched.h +++ b/src/sys/include/ubixos/sched.h @@ -30,6 +30,9 @@ #ifndef _SCHED_H #define _SCHED_H +#ifdef __cplusplus +extern "C" { +#endif #include #include @@ -38,8 +41,8 @@ #include -//typedef enum { PLACEHOLDER=-2,DEAD=-1,NEW=0,READY=1,RUNNING=2,IDLE=3,FORK=4,WAIT=5 } tState; -typedef enum { PLACEHOLDER = -2,DEAD,NEW,READY,RUNNING,IDLE,FORK,WAIT } tState; +typedef enum { PLACEHOLDER=-2,DEAD=-1,NEW=0,READY=1,RUNNING=2,IDLE=3,FORK=4,WAIT=5 } tState; + struct osInfo { uInt8 timer; uInt8 v86Task; @@ -52,23 +55,20 @@ }; typedef struct taskStruct { + pidType id; struct taskStruct *prev; struct taskStruct *next; - struct i387Struct i387; - struct i386_frame *iframe; - pidType id; - pidType parentPid; - struct osInfo oInfo; - uInt32 cr3; - char kernelStack[0x2000]; - fileDescriptor *imageFd; - tState state; - uInt32 gid; - uInt32 uid; - uInt32 timeSlice; - uInt16 usedMath; - uInt16 nice; - tty_term *term; + struct tssStruct tss; + struct i387Struct i387; + struct osInfo oInfo; + fileDescriptor *imageFd; + tState state; + uInt32 gid; + uInt32 uid; + uInt16 usedMath; + uInt16 nice; + uInt32 timeSlice; + tty_term *term; } kTask_t; typedef struct prioQueue { @@ -81,12 +81,10 @@ #define MAXPRIOLEVELS 11 -int sched_init(); -int sched_setStatus(pidType,tState); -uInt32 sched(struct i386_frame); -void sched_yield(); -int sched_addDelTask(kTask_t *); -kTask_t *sched_getDelTask(); +int sched_init(); +int sched_setStatus(pidType,tState); +void sched(); +void sched_yield(); void schedEndTask(pidType pid); kTask_t *schedNewTask(); @@ -95,40 +93,15 @@ extern kTask_t *_current; extern kTask_t *_usedMath; -extern kTask_t *delList; -extern kTask_t *runList; + +#ifdef __cplusplus +} +#endif #endif /*** $Log$ - Revision 1.24 2004/09/06 21:39:21 reddawg - Fixes: Changed the order in which tasks are deleted from the queues. Also fixed backspace to work in the virtual ttys.... - - Revision 1.23 2004/08/26 22:51:18 reddawg - TCA touched me :( i think he likes men.... - - - sched.h: kTask_t added parentPid - endtask.c: fixed term back to parentPid - exec.c: cleaned warnings - fork.c: fixed term to childPid - sched.c: clean up for dead tasks - systemtask.c: clean up dead tasks - kmalloc.c: cleaned up warnings - udp.c: cleaned up warnings - bot.c: cleaned up warnings - shell.c: cleaned up warnings - tcpdump.c: took a dump - hd.c: cleaned up warnings - ubixfs.c: stopped prning debug info - - Revision 1.22 2004/08/21 23:47:50 reddawg - *** empty log message *** - - Revision 1.21 2004/08/21 17:36:57 reddawg - updates: converted to software task switching however it is not working yet - Revision 1.20 2004/08/09 12:58:05 reddawg let me know when you got the surce diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 1659d1c..059562e 100644 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -109,17 +109,17 @@ /* initHardDisk(); */ /* Initialize the system */ - execThread(systemTask,0x0,0x0); + execThread(systemTask,(kmalloc(0x2000)+0x2000),0x0); - //execFile("sys:/init",0x0,0x0,0x1); + execFile("sys:/init",0x0,0x0,0x1); /* execFile("sys:/login",0x0,0x0,0x1); */ - //execFile("sys:/login",0x0,0x0,0x2); - //execFile("sys:/login",0x0,0x0,0x3); - //execFile("sys:/login",0x0,0x0,0x4); + execFile("sys:/login",0x0,0x0,0x2); + execFile("sys:/login",0x0,0x0,0x3); + execFile("sys:/login",0x0,0x0,0x4); kprintf("Free Pages: [%i]\n",systemVitals->freePages); kprintf("MemoryMap: [0x%X]\n",vmmMemoryMap); @@ -134,6 +134,9 @@ /*** $Log$ + Revision 1.81 2004/09/07 20:58:35 reddawg + time to roll back i can't think straight by friday + Revision 1.80 2004/09/06 15:13:25 reddawg Last commit before FreeBSD 6.0 diff --git a/src/sys/isa/atkbd.c b/src/sys/isa/atkbd.c index 8d3a57c..6696f95 100644 --- a/src/sys/isa/atkbd.c +++ b/src/sys/isa/atkbd.c @@ -150,7 +150,7 @@ ************************************************************************/ int atkbd_init() { /* Insert the IDT vector for the keyboard handler */ - idt_setVector(&atkbd_isr, mVec+0x1, dPresent + dInt + dDpl0); + setVector(&atkbd_isr, mVec+0x1, dPresent + dInt + dDpl0); /* Set the LEDS to their defaults */ setLED(); @@ -339,6 +339,9 @@ /*** $Log$ + Revision 1.26 2004/09/06 22:18:52 reddawg + ok bed time + Revision 1.25 2004/09/06 22:11:29 reddawg tty: now each tty has a stdin.... diff --git a/src/sys/isa/fdc.c b/src/sys/isa/fdc.c index 4867383..f49a15e 100644 --- a/src/sys/isa/fdc.c +++ b/src/sys/isa/fdc.c @@ -62,7 +62,7 @@ int fdc_init() { struct device_interface *devInfo = (struct device_interface *)kmalloc(sizeof(struct device_interface)); - idt_setVector(floppyIsr, mVec+6, (dInt+dPresent)); + setVector(floppyIsr, mVec+6, (dInt+dPresent)); irqEnable(6); reset(); devInfo->major = 0x0; @@ -314,6 +314,9 @@ /*** $Log$ + Revision 1.23 2004/09/06 15:13:25 reddawg + Last commit before FreeBSD 6.0 + Revision 1.22 2004/08/21 20:06:28 reddawg ok check out exec.c diff --git a/src/sys/isa/mouse.c b/src/sys/isa/mouse.c index 2f23d3d..c4e5d29 100644 --- a/src/sys/isa/mouse.c +++ b/src/sys/isa/mouse.c @@ -115,7 +115,7 @@ kbdWrite(0x64, 0xD4); kbdWriteRead(0x60, 0xF4,"\xFA"); - idt_setVector(&mouseISR, mVec+12, dPresent + dInt + dDpl3); + setVector(&mouseISR, mVec+12, dPresent + dInt + dDpl3); outportByte(mPic, eoi); outportByte(sPic, eoi); @@ -149,6 +149,9 @@ /*** $Log$ + Revision 1.2 2004/09/06 15:13:25 reddawg + Last commit before FreeBSD 6.0 + Revision 1.1 2004/06/04 10:20:53 reddawg mouse drive: fixed a few bugs works a bit better now diff --git a/src/sys/isa/ne2k.c b/src/sys/isa/ne2k.c index d7edcba..92bb645 100644 --- a/src/sys/isa/ne2k.c +++ b/src/sys/isa/ne2k.c @@ -68,7 +68,7 @@ mDev = (struct device *)kmalloc(sizeof(struct device)); mDev->ioAddr = 0x280; mDev->irq = 10; - idt_setVector(&ne2kISR, mVec+10, dPresent + dInt + dDpl3); + setVector(&ne2kISR, mVec+10, dPresent + dInt + dDpl3); irqEnable(10); // kprintf("ne0 - irq: %i, ioAddr: 0x%X MAC: %X:%X:%X:%X:%X:%X\n",dev->irq,dev->ioAddr,dev->net->mac[0] & 0xFF,dev->net->mac[1] & 0xFF,dev->net->mac[2] & 0xFF,dev->net->mac[3] & 0xFF,dev->net->mac[4] & 0xFF,dev->net->mac[5] & 0xFF); @@ -343,6 +343,9 @@ /*** $Log$ + Revision 1.18 2004/09/06 15:13:25 reddawg + Last commit before FreeBSD 6.0 + Revision 1.17 2004/08/01 20:40:45 reddawg Net related fixes diff --git a/src/sys/kernel/endtask.c b/src/sys/kernel/endtask.c index 4f4009e..aacb9be 100644 --- a/src/sys/kernel/endtask.c +++ b/src/sys/kernel/endtask.c @@ -46,25 +46,11 @@ void endTask(pidType pid) { kTask_t *tmpTask = 0x0; - irqDisable(0x1); tmpTask = schedFindTask(pid); tmpTask->state = DEAD; - tmpTask->term->owner = tmpTask->parentPid; - - /* Remove task from run queue */ - if (tmpTask->prev != 0x0) - tmpTask->prev->next = tmpTask->next; - if (tmpTask->next != 0x0) - tmpTask->next->prev = tmpTask->prev; - if (tmpTask == runList) - runList = tmpTask->next; - - irqEnable(0x1); - - /* Add task to del queue */ - sched_addDelTask(tmpTask); + //tmpTask->term->owner = tmpTask->parentPid; while (1); @@ -73,6 +59,9 @@ /*** $Log$ + Revision 1.19 2004/09/06 22:01:28 reddawg + Created functions sched_addDelTask and sched_getDelTask so we can lock the delete task list to prevent corruption of pointers.... a very random case but possible none the less + Revision 1.18 2004/09/06 21:39:21 reddawg Fixes: Changed the order in which tasks are deleted from the queues. Also fixed backspace to work in the virtual ttys.... diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 8180569..4da787e 100644 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -54,45 +54,54 @@ /* Find A New Thread */ newProcess = schedNewTask(); assert(newProcess); + if (stack < 0x100000) + kpanic("exec: stack not in valid area: [0x%X]\n",stack); /* Set All The Correct Thread Attributes */ + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = 0x0; + newProcess->tss.ss0 = 0x0; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.cr3 = (unsigned int)kernelPageDirectory; + newProcess->tss.eip = (unsigned int)tproc; + newProcess->tss.eflags = 0x206; + newProcess->tss.esp = stack; + newProcess->tss.ebp = stack; + newProcess->tss.esi = 0x0; + newProcess->tss.edi = 0x0; - newProcess->cr3 = (uInt32)kernelPageDirectory; - newProcess->iframe = newProcess->kernelStack + 0x1000; - newProcess->iframe->eip = (uInt32)tproc; - newProcess->iframe->flags = 0x206; - newProcess->iframe->esp = (uInt32)newProcess->kernelStack + 0x1008 - sizeof(struct i386_frame); - newProcess->iframe->ebp = newProcess->iframe->esp;//stack; - newProcess->iframe->user_esp = newProcess->iframe->esp;//stack; - newProcess->iframe->user_ss = 0x10; - newProcess->iframe->cs = 0x08; - newProcess->iframe->es = 0x10; - newProcess->iframe->ss = 0x10; - newProcess->iframe->ds = 0x10; - newProcess->iframe->fs = 0x10; - newProcess->iframe->gs = 0x10; - kprintf("ESP: [0x%X:0x%X:0x%X:0x%X]\n", newProcess->iframe->user_esp, newProcess->iframe,newProcess->kernelStack,&newProcess->kernelStack); + newProcess->tss.es = 0x10; + newProcess->tss.cs = 0x08; + newProcess->tss.ss = 0x10; + newProcess->tss.ds = 0x10; + newProcess->tss.fs = 0x10; + newProcess->tss.gs = 0x10; + newProcess->tss.ldt = 0x18; + + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; + newProcess->oInfo.vmStart = 0x6400000; + /* Set up default stack for thread here filled with arg list 3 times */ asm volatile( "pusha \n" "movl %%esp,%%ecx \n" "movl %1,%%eax \n" "movl %%eax,%%esp \n" - "pushl %0 \n" - "pushl %0 \n" - "pushl %0 \n" + "pushl %%ebx \n" + "pushl %%ebx \n" + "pushl %%ebx \n" "movl %%esp,%%eax \n" "movl %%eax,%1 \n" "movl %%ecx,%%esp \n" "popa \n" : - : "b" (arg),"m" (newProcess->iframe->user_esp) - : "eax" + : "b" (arg),"m" (newProcess->tss.esp) ); - newProcess->iframe->esp = newProcess->iframe->user_esp; - kprintf("ESP: [0x%X:0x%X]\n", newProcess->iframe->esp, newProcess->iframe); - /* Put new thread into the READY state */ sched_setStatus(newProcess->id,READY); @@ -120,16 +129,12 @@ int i = 0x0; int x = 0x0; - - kTask_t *tmpTask = 0x0; fileDescriptor *tmpFd = 0x0; elfHeader *binaryHeader = 0x0; elfProgramHeader *programHeader = 0x0; - /* Get A New Task For This Proccess */ - tmpTask = _current; _current = schedNewTask(); assert(_current); _current->gid = 0x0; @@ -142,13 +147,13 @@ _current->term->owner = _current->id; /* Now We Must Create A Virtual Space For This Proccess To Run In */ - _current->cr3 = (uInt32)vmmCreateVirtualSpace(_current->id); + _current->tss.cr3 = (uInt32)vmmCreateVirtualSpace(_current->id); /* To Better Load This Application We Will Switch Over To Its VM Space */ asm volatile( "movl %0,%%eax \n" "movl %%eax,%%cr3 \n" - : : "d" ((uInt32 *)(_current->cr3)) + : : "d" ((uInt32 *)(_current->tss.cr3)) ); /* Lets Find The File */ @@ -233,7 +238,6 @@ vmm_remapPage(vmmFindFreePage(_current->id),0x5CB000,KERNEL_PAGE_DEFAULT | PAGE_STACK); /* Set All The Proper Information For The Task */ - /* old _current->tss.back_link = 0x0; _current->tss.esp0 = 0x5CC000; _current->tss.ss0 = 0x10; @@ -247,9 +251,8 @@ _current->tss.ebp = 0x5DD000; _current->tss.esi = 0x0; _current->tss.edi = 0x0; - */ + /* Set these up to be ring 3 tasks */ - /* old _current->tss.es = 0x30+3; _current->tss.cs = 0x28+3; _current->tss.ss = 0x30+3; @@ -260,20 +263,6 @@ _current->tss.ldt = 0x18; _current->tss.trace_bitmap = 0x0000; _current->tss.io_map = 0x8000; - */ - - _current->iframe->eip = (uInt32)binaryHeader->eEntry; - _current->iframe->flags = 0x206; - _current->iframe->esp = (uInt32)&_current->kernelStack + 0x2000 - sizeof(struct i386_frame); - _current->iframe->ebp = 0x5DD000; - _current->iframe->user_esp = 0x5DD000 - 12; - _current->iframe->user_ss = 0x30 + 3; - _current->iframe->cs = 0x28 + 3; - _current->iframe->es = 0x30 + 3; - _current->iframe->ss = 0x10 + 0; - _current->iframe->ds = 0x30 + 3; - _current->iframe->fs = 0x30 + 3; - _current->iframe->gs = 0x30 + 3; sched_setStatus(_current->id,READY); @@ -287,7 +276,7 @@ "movl %%eax,%%cr3 \n" : : "d" ((uInt32 *)(kernelPageDirectory)) ); - _current = tmpTask; + /* Finally Return */ return; } @@ -312,8 +301,6 @@ elfProgramHeader *programHeader = 0x0; elfSectionHeader *sectionHeader = 0x0; elfDynamic *elfDynamicS = 0x0; - - struct i386_frame *iframe = 0x0; tmpFd = fopen(file,"r"); _current->imageFd = tmpFd; @@ -420,94 +407,22 @@ } /* Adjust iframe */ - /* old tmp = (uInt32 *)_current->tss.esp0 - 5; tmp[0] = binaryHeader->eEntry; tmp[3] = 0x5DD000-12; - */ - _current->iframe->eip = binaryHeader->eEntry; - _current->iframe->user_esp = 0x5DD000-12; tmp = (uInt32 *)0x5DD000 - 2; tmp[0] = argc; tmp[1] = (uInt32)argv; - - /* Now That We Relocated The Binary We Can Unmap And Free Header Info */ - - iframe = (struct i386_frame *)_current->kernelStack;//(_current->kernelStack + 0x1000) - sizeof(struct i386_frame); - memset(iframe,0x0,sizeof(struct i386_frame)); - iframe->eip = (uInt32)binaryHeader->eEntry; - iframe->flags = 0x206; - iframe->esp = (uInt32)&_current->kernelStack + 0x2000 - sizeof(struct i386_frame); - iframe->ebp = 0x5DD000; - iframe->user_esp = 0x5DD000 - 12; - iframe->user_ss = 0x30 + 3; - iframe->cs = 0x28 + 3; - iframe->es = 0x30 + 3; - iframe->ss = 0x10 + 0; - iframe->ds = 0x30 + 3; - iframe->fs = 0x30 + 3; - iframe->gs = 0x30 + 3; + /* Now That We Relocated The Binary We Can Unmap And Free Header Info */ kfree(binaryHeader); kfree(programHeader); - asm( - "mov %0,%%esp\n" - "pop %%gs \n" - "pop %%fs \n" - "pop %%es \n" - "pop %%ds \n" - "pop %%ss \n" - "popa \n" - "iret \n" - : - : "g" (iframe) - ); - return; } /*** $Log$ - Revision 1.70 2004/09/07 20:58:35 reddawg - time to roll back i can't think straight by friday - - Revision 1.69 2004/08/26 22:51:18 reddawg - TCA touched me :( i think he likes men.... - - - sched.h: kTask_t added parentPid - endtask.c: fixed term back to parentPid - exec.c: cleaned warnings - fork.c: fixed term to childPid - sched.c: clean up for dead tasks - systemtask.c: clean up dead tasks - kmalloc.c: cleaned up warnings - udp.c: cleaned up warnings - bot.c: cleaned up warnings - shell.c: cleaned up warnings - tcpdump.c: took a dump - hd.c: cleaned up warnings - ubixfs.c: stopped prning debug info - - Revision 1.68 2004/08/25 22:02:41 reddawg - task switching - We now are using software switching to be consistant with the rest of the world because all of this open source freaks gave me a hard time about something I liked. There doesn't seem to be any gain in performance but it is working fine and flawlessly - - Revision 1.67 2004/08/24 05:24:37 reddawg - TCA Is A BONER!!!! - - Revision 1.66 2004/08/21 23:47:50 reddawg - *** empty log message *** - - Revision 1.65 2004/08/21 20:21:20 reddawg - *** empty log message *** - - Revision 1.64 2004/08/21 20:06:28 reddawg - ok check out exec.c - - Revision 1.63 2004/08/21 17:36:57 reddawg - updates: converted to software task switching however it is not working yet - Revision 1.62 2004/08/14 11:23:02 reddawg Changes diff --git a/src/sys/kernel/fork.c b/src/sys/kernel/fork.c index f3492f7..4ddfc2e 100644 --- a/src/sys/kernel/fork.c +++ b/src/sys/kernel/fork.c @@ -64,85 +64,56 @@ "1: \n" " ret \n" ); - + int forkCopyProcess(struct taskStruct *newProcess,long ebp,long edi,long esi,long none,long ebx,long ecx,long edx,long eip,long cs,long eflags,long esp,long ss) { - + assert(newProcess); + assert(_current); + + /* Set Up New Tasks Information */ + newProcess->tss.eip = eip; sprintf(newProcess->oInfo.cwd,_current->oInfo.cwd); newProcess->oInfo.vmStart = _current->oInfo.vmStart; newProcess->term = _current->term; + newProcess->term->owner = newProcess->id; newProcess->uid = _current->uid; newProcess->gid = _current->gid; - newProcess->parentPid = _current->id; - newProcess->term->owner = newProcess->id; - newProcess->iframe->gs = 0x33; - newProcess->iframe->fs = 0x33; - newProcess->iframe->es = 0x33; - newProcess->iframe->ds = 0x33; - newProcess->iframe->ss = 0x10; - newProcess->iframe->edi = edi; - newProcess->iframe->esi = esi; - newProcess->iframe->ebp = ebp; - newProcess->iframe->esp = (uInt32)(newProcess->kernelStack + 0x2000) - sizeof(struct i386_frame); - newProcess->iframe->ebx = ebx; - newProcess->iframe->edx = edx; - newProcess->iframe->ecx = ecx; - newProcess->iframe->eax = 0x0; - newProcess->iframe->eip = eip; - newProcess->iframe->cs = cs; - newProcess->iframe->flags = eflags; - newProcess->iframe->user_esp = esp; - newProcess->iframe->user_ss = ss; - + newProcess->tss.back_link = 0x0; + newProcess->tss.esp0 = _current->tss.esp0; + newProcess->tss.ss0 = 0x10; + newProcess->tss.esp1 = 0x0; + newProcess->tss.ss1 = 0x0; + newProcess->tss.esp2 = 0x0; + newProcess->tss.ss2 = 0x0; + newProcess->tss.eflags = eflags; + newProcess->tss.eax = 0x0; + newProcess->tss.ebx = ebx; + newProcess->tss.ecx = ecx; + newProcess->tss.edx = edx; + newProcess->tss.esi = esi; + newProcess->tss.edi = edi; + newProcess->tss.ebp = ebp; + newProcess->tss.esp = esp; + newProcess->tss.cs = cs & 0xFF; + newProcess->tss.ss = ss & 0xFF; + newProcess->tss.ds = _current->tss.ds & 0xFF; + newProcess->tss.fs = _current->tss.fs & 0xFF; + newProcess->tss.gs = _current->tss.gs & 0xFF; + newProcess->tss.es = _current->tss.es & 0xFF; + newProcess->tss.ldt = 0x18; + newProcess->tss.trace_bitmap = 0x0000; + newProcess->tss.io_map = 0x8000; /* Create A Copy Of The VM Space For New Task */ - newProcess->cr3 = (uInt32)vmmCopyVirtualSpace(newProcess->id); - + newProcess->tss.cr3 = (uInt32)vmmCopyVirtualSpace(newProcess->id); newProcess->state = FORK; - - while (newProcess->state == FORK) - sched_yield(); - + + while (newProcess->state == FORK); + /* Return Id of Proccess */ return(newProcess->id); } /*** $Log$ - Revision 1.29 2004/08/26 22:51:18 reddawg - TCA touched me :( i think he likes men.... - - - sched.h: kTask_t added parentPid - endtask.c: fixed term back to parentPid - exec.c: cleaned warnings - fork.c: fixed term to childPid - sched.c: clean up for dead tasks - systemtask.c: clean up dead tasks - kmalloc.c: cleaned up warnings - udp.c: cleaned up warnings - bot.c: cleaned up warnings - shell.c: cleaned up warnings - tcpdump.c: took a dump - hd.c: cleaned up warnings - ubixfs.c: stopped prning debug info - - Revision 1.28 2004/08/25 22:02:41 reddawg - task switching - We now are using software switching to be consistant with the rest of the world because all of this open source freaks gave me a hard time about something I liked. There doesn't seem to be any gain in performance but it is working fine and flawlessly - - Revision 1.27 2004/08/24 23:33:45 reddawg - Fixed - - Revision 1.26 2004/08/24 05:24:37 reddawg - TCA Is A BONER!!!! - - Revision 1.25 2004/08/21 23:47:50 reddawg - *** empty log message *** - - Revision 1.24 2004/08/21 20:21:20 reddawg - *** empty log message *** - - Revision 1.23 2004/08/21 17:36:57 reddawg - updates: converted to software task switching however it is not working yet - Revision 1.22 2004/08/09 12:58:05 reddawg let me know when you got the surce diff --git a/src/sys/kernel/sched.c b/src/sys/kernel/sched.c index 9c0d487..301ee05 100644 --- a/src/sys/kernel/sched.c +++ b/src/sys/kernel/sched.c @@ -32,52 +32,30 @@ #include #include #include +#include #include #include #include #include +#include #include #include -static spinLock_t sched_spinLock = SPIN_LOCK_INITIALIZER; -static spinLock_t sched_delTaskLock = SPIN_LOCK_INITIALIZER; -static uInt32 nextID = -1; +static spinLock_t schedSpinLock = SPIN_LOCK_INITIALIZER; +static spinLock_t schedTaskSpinLock = SPIN_LOCK_INITIALIZER; -kTask_t *_current = 0x0; -kTask_t *_usedMath = 0x0; -kTask_t *delList = 0x0; -kTask_t *runList = 0x0; +static prioQueue_t *prioLevels[MAXPRIOLEVELS - 1]; +static prioQueue_t *prioQStart = 0x0; +static prioQueue_t *prioQEnd = 0x0; +static prioQueue_t *_currentQueue = 0x0; -static struct tssStruct *sched_tss = 0x0; +static kTask_t *taskList = 0x0; +static uInt32 nextID = -1; -static kTask_t *sched_getRunableTask() { - kTask_t *tmpTask = 0x0; - kTask_t *delTask = 0x0; +kTask_t *_current = 0x0; +kTask_t *_usedMath = 0x0; - tmpTask = _current->next; - - schedStart: - - for (;tmpTask != 0x0; tmpTask = tmpTask->next) { - - if (tmpTask->state == FORK) - tmpTask->state = READY; - - /* Return ready task */ - if (tmpTask->state == READY) - return(tmpTask); - - } - - /* Finished all the tasks, restarting the list */ - if (0x0 == tmpTask) { - tmpTask = runList; - goto schedStart; - } - - return(0x0); - } /************************************************************************ @@ -93,124 +71,199 @@ ************************************************************************/ -int sched_init() { - kTask_t *tmpTask = 0x0; +int +sched_init() +{ + int i; + + for (i = 0; i < MAXPRIOLEVELS; i++) { + prioQueue_t *tmpPrioQ; + kTask_t *tmpTask; - if ((tmpTask = (kTask_t *)kmalloc(sizeof(kTask_t))) == 0x0) - kpanic("malloc: Failed File: %s, Line: %i\n",__FILE__,__LINE__); - - if ((sched_tss = (struct tssStruct *)kmalloc(sizeof(struct tssStruct))) == 0x0) - kpanic("malloc: Failed File: %s, Line: %i\n",__FILE__,__LINE__); + tmpPrioQ = (prioQueue_t *)kmalloc(sizeof(prioQueue_t)); + tmpTask = (kTask_t *)kmalloc(sizeof(kTask_t)); - sched_tss->ss0 = 0x10; - sched_tss->eflags = 0x206; - - /* Adjust the GDT to reflect our new TSS */ - ubixGDT[4].descriptor.baseLow = ((uInt32)sched_tss & 0xFFFF); - ubixGDT[4].descriptor.baseMed = (((uInt32)sched_tss >> 16) & 0xFF); - ubixGDT[4].descriptor.baseHigh = ((uInt32)sched_tss >> 24); - ubixGDT[4].descriptor.access = '\x89'; - asm( - "push %eax\n" - "mov $0x20,%ax\n" - "ltr %ax\n" - "pop %eax\n" - ); + if (tmpPrioQ == 0x0) { + kpanic("Error: schedInit() - kmalloc failed trying to initialize a prioQueue_t struct\n"); + return(0x1); + } + + if (tmpTask == 0x0) { + kpanic("Error: schedInit() - kmalloc failed trying to initialize a kTask_t struct\n"); + return(0x1); + } + + tmpPrioQ->start = tmpTask; + tmpPrioQ->end = tmpTask; + tmpPrioQ->prio = i; + prioLevels[i] = tmpPrioQ; - sched_tss->ldt = 0x18; - sched_tss->trace_bitmap = 0x0000; - sched_tss->io_map = 0x8000; - - tmpTask->prev = 0x0; - tmpTask->next = 0x0; - tmpTask->id = -1; - tmpTask->state = PLACEHOLDER; - tmpTask->timeSlice = systemVitals->dQuantum; + tmpTask->prev = 0x0; + tmpTask->next = 0x0; + tmpTask->id = -1; + tmpTask->state = PLACEHOLDER; + tmpTask->nice = i; + tmpTask->timeSlice = systemVitals->dQuantum; - runList = tmpTask; - _current = tmpTask; - nextID++; - kprintf("_current: [0x%X:0x%X]\n",_current,_current->id); - kprintf("sched0 - Address: [0x%X:0x%X]\n",sched_tss,runList); + /* Linking the previous placeholder with the current one */ + if (i > 0) { + prioLevels[i - 1]->start->next = tmpTask; + tmpTask->prev = prioLevels[i - 1]->end; + } + + if (0x0 == prioQStart) { + tmpPrioQ->next = 0x0; + tmpPrioQ->prev = 0x0; + prioQStart = prioQEnd = tmpPrioQ; + } else { + tmpPrioQ->prev = prioQEnd; + prioQEnd->next = tmpPrioQ; + tmpPrioQ->next = 0x0; + prioQEnd = tmpPrioQ; + } + } + + taskList = prioLevels[0]->start; + _current = prioLevels[MAXPRIOLEVELS/2]->start; + _currentQueue = prioLevels[0]; + + nextID++; + + /* Print out information on scheduler */ + kprintf("sched0 solar 0.2.1 - Address: [0x%X]\n", prioQStart); - /* Return so we know everything went well */ - return(0x0); - } + /* Return so we know everything went well */ + return(0x0); +} -uInt32 sched(struct i386_frame iframe) { + +void sched(){ + uInt32 memAddr = 0x0; kTask_t *tmpTask = 0x0; - - _current->iframe = &iframe; - - tmpTask = sched_getRunableTask(); - if (tmpTask == 0x0) - kpanic("Error: sched_getRunableTask == 0x0\n"); - /* Make this our now current task */ + schedStart: + /* Yield the next task from the current prio queue */ + for (tmpTask = _current->next; tmpTask; tmpTask = tmpTask->next) { + if (tmpTask->state > 0x0) { + _current = tmpTask; + if (_current->state == FORK) + _current->state = READY; - _current = tmpTask; - - /* Test if it is a 16 bit task */ + break; + } + } - if (_current->oInfo.v86Task == 0x1) - irqDisable(0x0); - - /* Switch Tasks */ + /* Finished all the tasks, restarting the list */ + if (0x0 == tmpTask) { + _current = taskList; + goto schedStart; + } - sched_tss->esp0 = (uInt32)_current->kernelStack + 0x2000; - - asm volatile( - "mov %0,%%eax \n" - "mov %%eax,%%cr3 \n" - : - : "a" (_current->cr3) - ); - - /* Return IFRAME */ - return ((uInt32)_current->iframe); - } - -kTask_t *schedNewTask() { - kTask_t *tmpTask = (kTask_t *)kmalloc(sizeof(kTask_t)); - - if (tmpTask == 0x0) - kpanic("Error: schedNewTask() - kmalloc failed trying to initialize a new task struct\n"); - - spinLock(&sched_spinLock); + /* Setting the timeslice this task is allowed to run */ + systemVitals->quantum = _current->timeSlice; - tmpTask->usedMath = 0x0; - tmpTask->id = ++nextID; - tmpTask->state = NEW; - tmpTask->nice = _current->nice; + + if (_current->state > 0x0) { + if (_current->oInfo.v86Task == 0x1) + irqDisable(0x0); + asm("cli"); + memAddr = (uInt32)&(_current->tss); + ubixGDT[4].descriptor.baseLow = (memAddr & 0xFFFF); + ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF); + ubixGDT[4].descriptor.baseHigh = (memAddr >> 24); + ubixGDT[4].descriptor.access = '\x89'; + asm("ljmp $0x20,$0\n"); + } - tmpTask->timeSlice = systemVitals->dQuantum * tmpTask->nice; - tmpTask->oInfo.cwd = (char *)kmalloc(1024); - assert(tmpTask->oInfo.cwd); - - tmpTask->prev = 0x0; - tmpTask->next = runList; - if (runList != 0x0) - runList->prev = tmpTask; - - runList = tmpTask; - tmpTask->iframe = (struct i386_frame *)(tmpTask->kernelStack + 0x2000) - sizeof(struct i386_frame); - spinUnlock(&sched_spinLock); - return(tmpTask); - } + return; +} -kTask_t *schedFindTask(uInt32 id) { +kTask_t * +schedNewTask() +{ + kTask_t *tmpTask = (kTask_t *)kmalloc(sizeof(kTask_t)); + + if (tmpTask == 0x0) { + kpanic("Error: schedNewTask() - kmalloc failed trying to initialize a new task struct\n"); + return(0x0); + } + + //spinLock(&schedTaskSpinLock); + + /* Filling in tasks attrs */ + tmpTask->usedMath = 0x0; + tmpTask->id = ++nextID; + tmpTask->state = NEW; + tmpTask->nice = _current->nice; + + tmpTask->timeSlice = systemVitals->dQuantum * tmpTask->nice; + tmpTask->oInfo.cwd = (char *)kmalloc(1024); + assert(tmpTask->oInfo.cwd); + + /* Are we adding a task at the end of the last prio queue? */ + if (0x0 == prioLevels[_current->nice]->next) + tmpTask->next = 0x0; + else + tmpTask->next = prioLevels[_current->nice + 1]->start; + + tmpTask->prev = prioLevels[_current->nice]->end; + + /* + * Inserting the task at the end of the proper prio queue; + * this gives me the feeling of O(1) for task insertion + */ + prioLevels[_current->nice]->end->next = tmpTask; + prioLevels[_current->nice]->end = tmpTask; + + //spinUnlock(&schedTaskSpinLock); + return(tmpTask); +} + + +/* + * This is at least O(N)... it was written to + * have it functional; soon it will be changed to O(1). + */ + +int +schedDeleteTask(uInt32 id) { kTask_t *tmpTask = 0x0; - for (tmpTask = runList;tmpTask != 0x0;tmpTask = tmpTask->next) { - if (tmpTask->id == id) - return(tmpTask); - } - - return(0x0); + /* Checking each task from the prio queue */ + for (tmpTask = taskList; tmpTask != 0x0; tmpTask = tmpTask->next) { + if (tmpTask->id == id) { + if (_current == tmpTask) + kpanic("you can not delete yourself!!!\n"); + if (tmpTask == taskList) + kpanic("Whoa"); + if (tmpTask->prev) + tmpTask->prev->next = tmpTask->next; + if (tmpTask->next) + tmpTask->next->prev = tmpTask->prev; + kfree(tmpTask->oInfo.cwd); + kfree(tmpTask); + return(0x0); + } + } + return(0x1); } +kTask_t * +schedFindTask(uInt32 id) +{ + kTask_t *tmpTask = 0x0; + + for (tmpTask = taskList; tmpTask; tmpTask = tmpTask->next) { + if (tmpTask->id == id) + return(tmpTask); + } + + return(0x0); +} + + /************************************************************************ Function: void schedEndTask() @@ -224,9 +277,9 @@ ************************************************************************/ void schedEndTask(pidType pid) { - endTask(_current->id); - sched_yield(); - } + endTask(_current->id); + sched_yield(); +} /************************************************************************ @@ -240,12 +293,20 @@ ************************************************************************/ -void sched_yield() { - //sched(); - //asm("int $0x69"); +void +sched_yield() { asm("hlt"); + //sched(); } +/* +asm( + ".globl sched_yield \n" + "sched_yield: \n" + " cli \n" + " call sched \n" + ); +*/ /************************************************************************ @@ -263,106 +324,9 @@ tmpTask->state = state; return(0x0); } - -int sched_addDelTask(kTask_t *task) { - - spinLock(&sched_delTaskLock); - - task->next = delList; - task->prev = 0x0; - - if (delList != 0x0) - delList->prev = task; - - delList = task; - - spinUnlock(&sched_delTaskLock); - return(0x0); - } - -kTask_t *sched_getDelTask() { - kTask_t *tmpTask = 0x0; - spinLock(&sched_delTaskLock); - - if (delList != 0x0) { - tmpTask = delList; - delList = delList->next; - spinUnlock(&sched_delTaskLock); - return(tmpTask); - } - - spinUnlock(&sched_delTaskLock); - return(0x0); - } /*** $Log$ - Revision 1.46 2004/09/06 21:39:21 reddawg - Fixes: Changed the order in which tasks are deleted from the queues. Also fixed backspace to work in the virtual ttys.... - - Revision 1.45 2004/08/29 21:43:06 reddawg - sched: we now yeild almost propper - syscall: it still uses ebx,ecx,edx - - Boys don't cry - - Revision 1.44 2004/08/26 22:51:18 reddawg - TCA touched me :( i think he likes men.... - - - sched.h: kTask_t added parentPid - endtask.c: fixed term back to parentPid - exec.c: cleaned warnings - fork.c: fixed term to childPid - sched.c: clean up for dead tasks - systemtask.c: clean up dead tasks - kmalloc.c: cleaned up warnings - udp.c: cleaned up warnings - bot.c: cleaned up warnings - shell.c: cleaned up warnings - tcpdump.c: took a dump - hd.c: cleaned up warnings - ubixfs.c: stopped prning debug info - - Revision 1.43 2004/08/25 22:02:41 reddawg - task switching - We now are using software switching to be consistant with the rest of the world because all of this open source freaks gave me a hard time about something I liked. There doesn't seem to be any gain in performance but it is working fine and flawlessly - - Revision 1.42 2004/08/24 23:33:45 reddawg - Fixed - - Revision 1.41 2004/08/24 05:24:37 reddawg - TCA Is A BONER!!!! - - Revision 1.40 2004/08/21 23:57:53 reddawg - *** empty log message *** - - Revision 1.39 2004/08/21 23:47:50 reddawg - *** empty log message *** - - Revision 1.38 2004/08/21 20:21:20 reddawg - *** empty log message *** - - Revision 1.37 2004/08/21 20:06:28 reddawg - ok check out exec.c - - Revision 1.36 2004/08/21 17:36:57 reddawg - updates: converted to software task switching however it is not working yet - - Revision 1.35 2004/08/21 16:49:14 reddawg - tj check out sched_init does it look well to you? - - Revision 1.34 2004/08/15 20:52:29 reddawg - *** empty log message *** - - Revision 1.33 2004/08/15 16:47:49 reddawg - Fixed - - Revision 1.32 2004/08/14 21:56:44 reddawg - Added initialized byte to the device system to make it easy to add child devices which use parent hardware. - - Revision 1.31 2004/08/14 11:23:02 reddawg - Changes - Revision 1.30 2004/08/09 12:58:05 reddawg let me know when you got the surce diff --git a/src/sys/kernel/systemtask.c b/src/sys/kernel/systemtask.c index 5d4da36..3bda3c3 100644 --- a/src/sys/kernel/systemtask.c +++ b/src/sys/kernel/systemtask.c @@ -94,18 +94,18 @@ break; } } - tmpTask = sched_getDelTask(); + //tmpTask = sched_getDelTask(); if (tmpTask != 0x0) { - vmmFreeProcessPages(tmpTask->id); + //vmmFreeProcessPages(tmpTask->id); /* if (_current->imageFd) fclose(_current->imageFd); */ - kfree(tmpTask->oInfo.cwd); - kfree(tmpTask); + //kfree(tmpTask->oInfo.cwd); + //kfree(tmpTask); } sched_yield(); @@ -116,6 +116,9 @@ /*** $Log$ + Revision 1.18 2004/09/06 22:01:28 reddawg + Created functions sched_addDelTask and sched_getDelTask so we can lock the delete task list to prevent corruption of pointers.... a very random case but possible none the less + Revision 1.17 2004/09/06 21:39:21 reddawg Fixes: Changed the order in which tasks are deleted from the queues. Also fixed backspace to work in the virtual ttys.... diff --git a/src/sys/kernel/timer.S b/src/sys/kernel/timer.S index b82e5ab..f77f344 100644 --- a/src/sys/kernel/timer.S +++ b/src/sys/kernel/timer.S @@ -30,60 +30,34 @@ .globl timerInt .text .code32 -timerInt: +timerInt: pusha /* Save all of the registers */ - push %ss - push %ds - push %es - push %fs - push %gs + mov $0x20,%dx /* The Following Sends Our EOI To The MPIC */ + mov $0x20,%ax + outb %al,%dx movl systemVitals,%ecx /* Put Location Of System Vitals Into ECX */ - incl 0x4(%ecx) /* Increment sysTicks our 1000ms counter */ - movl 0x4(%ecx),%eax /* Increment our sysUptime by 1S if 1000MS */ + incl 4(%ecx) /* Increment sysTicks our 1000ms counter */ + movl 4(%ecx),%eax /* Increment our sysUptime by 1S if 1000MS */ movl $200,%ebx /* Have Passed */ xor %edx,%edx div %ebx test %edx,%edx - jnz timer_next - incl 0x8(%ecx) -timer_next: - movl 0x4(%ecx),%eax /* Test If quantum Has Passed If So Then */ - movl 0xC(%ecx),%ebx /* We Can CALL sched */ + jnz next + incl 8(%ecx) +next: + movl 4(%ecx),%eax /* Test If quantum Has Passed If So Then */ + movl 12(%ecx),%ebx /* We Can CALL sched */ xor %edx,%edx div %ebx test %edx,%edx - jnz timer_done - call sched - mov %eax,%esp -timer_done: - mov $0x20,%dx /* The Following Sends Our EOI To The MPIC */ - mov $0x20,%ax - outb %al,%dx - pop %gs - pop %fs - pop %es - pop %ds - pop %ss + jnz done + call sched +done: popa /* Restore Registers */ iret /*** $Log$ - Revision 1.10 2004/08/29 21:43:06 reddawg - sched: we now yeild almost propper - syscall: it still uses ebx,ecx,edx - - Boys don't cry - - Revision 1.9 2004/08/24 05:24:37 reddawg - TCA Is A BONER!!!! - - Revision 1.8 2004/08/21 23:47:50 reddawg - *** empty log message *** - - Revision 1.7 2004/08/21 20:06:28 reddawg - ok check out exec.c - Revision 1.6 2004/08/14 11:23:02 reddawg Changes diff --git a/src/sys/kernel/ubthread.c b/src/sys/kernel/ubthread.c index b052312..b648d21 100644 --- a/src/sys/kernel/ubthread.c +++ b/src/sys/kernel/ubthread.c @@ -73,7 +73,7 @@ } int ubthread_create(kTask_t **thread,const uInt32 *attr,void (* tproc)(void), void *arg) { - *thread = (void *)execThread(tproc,0x0,arg); + *thread = (void *)execThread(tproc,(kmalloc(0x2000)+0x2000),arg); return(0x0); } @@ -129,6 +129,9 @@ /*** $Log$ + Revision 1.11 2004/09/07 20:58:35 reddawg + time to roll back i can't think straight by friday + Revision 1.10 2004/08/06 22:43:04 reddawg ok diff --git a/src/sys/sys/idt.c b/src/sys/sys/idt.c index ccf472e..5f8b6b9 100644 --- a/src/sys/sys/idt.c +++ b/src/sys/sys/idt.c @@ -51,72 +51,188 @@ (256 * sizeof(union descriptorTableUnion) - 1), ubixIDT }; -void sched_yield_new(); +/************************************************************************ + +Function: int idtInit() +Description: This function is used to enable our IDT subsystem +Notes: + +02/20/2004 - Approved for quality + +************************************************************************/ +int idt_init() { + int i = 0x0; + + struct tssStruct *sfTSS = (struct tssStruct *)0x6200; + 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); + } + + /* Load the IDT into the system */ + asm volatile( + "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 + dInt + dDpl0); + setVector(_int1, 1, dPresent + dInt + dDpl0); + setVector(_int2, 2, dPresent + dInt + dDpl0); + setVector(_int3, 3, dPresent + dInt + dDpl0); + setVector(_int4, 4, dPresent + dInt + dDpl0); + setVector(_int5, 5, dPresent + dInt + dDpl0); + setVector(_int6, 6, dPresent + dInt + dDpl0); + setVector(_int7,7,dPresent + dInt + dDpl0); + setTaskVector(8,dPresent + dTask + dDpl0, 0x40); + setVector(_int9, 9, dPresent + dInt + dDpl0); + setVector(_int10, 10, dPresent + dInt + dDpl0); + setVector(_int11, 11, dPresent + dInt + dDpl0); + setVector(_int12, 12, dPresent + dInt + dDpl0); + setTaskVector(13, dPresent + dTask + dDpl0, 0x38); + setVector(_vmm_pageFault, 14, dPresent + dInt + dDpl0); + setVector(_sysCall, 128, dPresent + dTrap + dDpl3); + setVector(_sysCallNew, 0x90, dPresent + dTrap + dDpl3); + setVector(timerInt, 0x68, (dInt + dPresent + dDpl0)); + + + gpfTSS->back_link = 0x0; + gpfTSS->esp0 = 0x0; + gpfTSS->ss0 = 0x0; + gpfTSS->esp1 = 0x0; + gpfTSS->ss1 = 0x0; + gpfTSS->esp2 = 0x0; + gpfTSS->ss2 = 0x0; + gpfTSS->cr3 = (unsigned int)kernelPageDirectory; + gpfTSS->eip = (unsigned int)&_int13; + gpfTSS->eflags = 0x206; + gpfTSS->esp = 0x1D000; + gpfTSS->ebp = 0x1D000; + gpfTSS->esi = 0x0; + gpfTSS->edi = 0x0; + gpfTSS->es = 0x10; + gpfTSS->cs = 0x08; + gpfTSS->ss = 0x10; + gpfTSS->ds = 0x10; + gpfTSS->fs = 0x10; + gpfTSS->gs = 0x10; + gpfTSS->ldt = 0x0; + gpfTSS->trace_bitmap = 0x0000; + gpfTSS->io_map = 0x8000; + + memset(sfTSS,0x0,sizeof(struct tssStruct)); + sfTSS->cr3 = (unsigned int)kernelPageDirectory; + sfTSS->eip = (unsigned int)&_int8; + sfTSS->eflags = 0x206; + sfTSS->esp = 0x1C000; + sfTSS->ebp = 0x1C000; + sfTSS->es = 0x10; + sfTSS->cs = 0x08; + sfTSS->ss = 0x10; + sfTSS->ds = 0x10; + sfTSS->fs = 0x10; + sfTSS->gs = 0x10; + sfTSS->io_map = 0x8000; + + /* Print out information for the IDT */ + kprintf("idt0 - Address: [0x%X]\n", &ubixIDT); + + /* Return so we know all went well */ + return (0x0); + } + + +/* Sets Up IDT Vector */ +void setVector(void *handler, unsigned char interrupt, unsigned short controlMajor) { + unsigned short codesegment = 0x08; + asm volatile ("movw %%cs,%0":"=g" (codesegment)); + + ubixIDT[interrupt].gate.offsetLow = (unsigned short)(((unsigned long)handler) & 0xffff); + ubixIDT[interrupt].gate.selector = codesegment; + ubixIDT[interrupt].gate.access = controlMajor; + ubixIDT[interrupt].gate.offsetHigh = (unsigned short)(((unsigned long)handler) >> 16); +} + +/************************************************************************ + +Function: void setTaskVector(uInt8,uInt16,uInt8); +Description: This Function Sets Up An IDT Task Vector +Notes: + +************************************************************************/ +void +setTaskVector(uInt8 interrupt, uInt16 controlMajor, uInt8 selector) +{ + uInt16 codesegment = 0x08; + asm volatile ("movw %%cs,%0":"=g" (codesegment)); + + ubixIDT[interrupt].gate.offsetLow = 0x0; + ubixIDT[interrupt].gate.selector = selector; + ubixIDT[interrupt].gate.access = controlMajor; + ubixIDT[interrupt].gate.offsetHigh = 0x0; +} + /* Null Intterupt Descriptor */ -static void intNull() { +void intNull() { kpanic("Invalid Interrupt[%i]\n",_current->id); + while (1); endTask(_current->id); sched_yield(); } -static void _int0() { +void _int0() { kpanic("int0: Divide-by-Zero [%i]\n",_current->id); endTask(_current->id); sched_yield(); } -static void _int1() { +void _int1() { kpanic("int1: Debug exception [%i]\n",_current->id); endTask(_current->id); sched_yield(); } -static void _int2() { +void _int2() { kpanic("int2: unknown error [%i]\n",_current->id); endTask(_current->id); sched_yield(); } -static void _int3() { +void _int3() { kpanic("int3: Breakpoint [%i]\n",_current->id); endTask(_current->id); sched_yield(); } -static void _int4(){ +void _int4(){ kpanic("int4: Overflow [%i]\n",_current->id); endTask(_current->id); sched_yield(); } -static void _int5() { +void _int5() { kpanic("int5: Bounds check [%i]\n",_current->id); endTask(_current->id); sched_yield(); } -static void _int6() { +void _int6() { kpanic("int6: Invalid opcode! [%i]\n",_current->id); endTask(_current->id); sched_yield(); } - -static void _int7(); -asm( - "_int7: \n" - " pushl %eax \n" - " clts \n" - " movl _current,%eax \n" - " cmpl _usedMath,%eax \n" - " je mathDone \n" - " call mathStateRestore \n" - "mathDone: \n" - " popl %eax \n" - " iret \n" - ); -static void _int8() { +void _int8() { struct tssStruct *sfTSS = (struct tssStruct *)0x6200; kpanic("int8: Double Fault! [%i]\n",_current->id); sfTSS->cr3 = (unsigned int)kernelPageDirectory; @@ -134,38 +250,36 @@ while (1); } -static void _int9() { +void _int9() { kpanic("int9: Coprocessor Segment Overrun! [%i]\n",_current->id); endTask(_current->id); sched_yield(); } -static void _int10() { +void _int10() { kpanic("int10: Invalid TSS! [%i]\n",_current->id); endTask(_current->id); sched_yield(); } -static void _int11() { +void _int11() { kpanic("int11: Segment Not Present! [%i]\n",_current->id); endTask(_current->id); sched_yield(); } -static void _int12() { +void _int12() { kpanic("int12: Stack-Segment Fault! [%i]\n",_current->id); endTask(_current->id); sched_yield(); } -static void _int13() { +void _int13() { uInt8 *ip = 0x0; uInt16 *stack = 0x0, *ivt = 0x0; uInt32 *stack32 = 0x0; bool isOperand32 = FALSE, isAddress32 = FALSE; struct tssStruct *gpfTSS = (struct tssStruct *)0x4200; - - kpanic("GPF!!! %i\n",_current->id); irqDisable(0x0); @@ -174,9 +288,9 @@ gpfTSS->ebp = 0x1D000; gpfTSS->eflags = 0x206; - ip = FP_TO_LINEAR(_current->iframe->cs, _current->iframe->eip); + ip = FP_TO_LINEAR(_current->tss.cs, _current->tss.eip); ivt = (uInt16 *) 0x0; - stack = (uInt16 *) FP_TO_LINEAR(_current->iframe->ss,_current->iframe->esp); + stack = (uInt16 *) FP_TO_LINEAR(_current->tss.ss,_current->tss.esp); stack32 = (uInt32 *) stack; gpfStart: @@ -193,105 +307,105 @@ break; default: stack -= 3; - _current->iframe->esp = ((_current->iframe->esp & 0xffff) - 6) & 0xffff; - stack[0] = (uInt16) (_current->iframe->eip + 2); - stack[1] = _current->iframe->cs; stack[2] = (uInt16) _current->iframe->flags; + _current->tss.esp = ((_current->tss.esp & 0xffff) - 6) & 0xffff; + stack[0] = (uInt16) (_current->tss.eip + 2); + stack[1] = _current->tss.cs; stack[2] = (uInt16) _current->tss.eflags; if (_current->oInfo.v86If) stack[2] |= EFLAG_IF; else stack[2] &= ~EFLAG_IF; - _current->iframe->cs = ivt[ip[1] * 2 + 1] & 0xFFFF; - _current->iframe->eip = ivt[ip[1] * 2] & 0xFFFF; + _current->tss.cs = ivt[ip[1] * 2 + 1] & 0xFFFF; + _current->tss.eip = ivt[ip[1] * 2] & 0xFFFF; break; } break; case 0x66: isOperand32 = TRUE; ip++; - _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); goto gpfStart; break; case 0x67: isAddress32 = TRUE; ip++; - _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); goto gpfStart; break; case 0xF0: - _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); kpanic("GPF OP 0xF0\n"); break; case 0x9C: if (isOperand32 == TRUE) { - _current->iframe->esp = ((_current->iframe->esp & 0xffff) - 4) & 0xffff; + _current->tss.esp = ((_current->tss.esp & 0xffff) - 4) & 0xffff; stack32--; - stack32[0] = _current->iframe->flags & 0xDFF; + stack32[0] = _current->tss.eflags & 0xDFF; if (_current->oInfo.v86If == TRUE) stack32[0] |= EFLAG_IF; else stack32[0] &= ~EFLAG_IF; } else { - _current->iframe->esp = ((_current->iframe->esp & 0xffff) - 2) & 0xffff; + _current->tss.esp = ((_current->tss.esp & 0xffff) - 2) & 0xffff; stack--; - stack[0] = (uInt16) _current->iframe->flags; + stack[0] = (uInt16) _current->tss.eflags; if (_current->oInfo.v86If == TRUE) stack[0] |= EFLAG_IF; else stack[0] &= ~EFLAG_IF; - _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); } break; case 0x9D: if (isOperand32 == TRUE) { - _current->iframe->flags = EFLAG_IF | EFLAG_VM | (stack32[0] & 0xDFF); + _current->tss.eflags = EFLAG_IF | EFLAG_VM | (stack32[0] & 0xDFF); _current->oInfo.v86If = (stack32[0] & EFLAG_IF) != 0; - _current->iframe->esp = ((_current->iframe->esp & 0xffff) + 4) & 0xffff; + _current->tss.esp = ((_current->tss.esp & 0xffff) + 4) & 0xffff; } else { - _current->iframe->flags = EFLAG_IF | EFLAG_VM | stack[0]; + _current->tss.eflags = EFLAG_IF | EFLAG_VM | stack[0]; _current->oInfo.v86If = (stack[0] & EFLAG_IF) != 0; - _current->iframe->esp = ((_current->iframe->esp & 0xffff) + 2) & 0xffff; + _current->tss.esp = ((_current->tss.esp & 0xffff) + 2) & 0xffff; } - _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); /* kprintf("popf [0x%X]\n",_current->id); */ break; case 0xFA: _current->oInfo.v86If = FALSE; - _current->iframe->flags &= ~EFLAG_IF; - _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); + _current->tss.eflags &= ~EFLAG_IF; + _current->tss.eip = (uInt16) (_current->tss.eip + 1); _current->oInfo.timer = 0x1; break; case 0xFB: _current->oInfo.v86If = TRUE; - _current->iframe->flags |= EFLAG_IF; - _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); + _current->tss.eflags |= EFLAG_IF; + _current->tss.eip = (uInt16) (_current->tss.eip + 1); _current->oInfo.timer = 0x0; /* kprintf("sti [0x%X]\n",_current->id); */ break; case 0xCF: - _current->iframe->eip = stack[0]; - _current->iframe->cs = stack[1]; - _current->iframe->flags = EFLAG_IF | EFLAG_VM | stack[2]; + _current->tss.eip = stack[0]; + _current->tss.cs = stack[1]; + _current->tss.eflags = EFLAG_IF | EFLAG_VM | stack[2]; _current->oInfo.v86If = (stack[2] & EFLAG_IF) != 0; - _current->iframe->esp = ((_current->iframe->esp & 0xffff) + 6) & 0xffff; + _current->tss.esp = ((_current->tss.esp & 0xffff) + 6) & 0xffff; /* kprintf("iret [0x%X]\n",_current->id); */ break; case 0xEC: /* IN AL,DX */ - _current->iframe->eax = (_current->iframe->eax & ~0xFF) | inportByte(_current->iframe->edx); - _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); + _current->tss.eax = (_current->tss.eax & ~0xFF) | inportByte(_current->tss.edx); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); break; case 0xED: /* IN AX,DX */ - _current->iframe->eax = (_current->iframe->eax & ~0xFFFF) | inportWord(_current->iframe->edx); - _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); + _current->tss.eax = (_current->tss.eax & ~0xFFFF) | inportWord(_current->tss.edx); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); break; case 0xEE: /* OUT DX,AL */ - outportByte(_current->iframe->edx, _current->iframe->eax & 0xFF); - _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); + outportByte(_current->tss.edx, _current->tss.eax & 0xFF); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); break; case 0xEF: - outportWord(_current->iframe->edx, _current->iframe->eax); - _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); + outportWord(_current->tss.edx, _current->tss.eax); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); break; case 0xF4: - _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); + _current->tss.eip = (uInt16) (_current->tss.eip + 1); break; default: /* something wrong */ kprintf("NonHandled OpCode [0x%X:0x%X]\n",_current->id,ip[0]); @@ -326,153 +440,24 @@ //Return } - -/***************************************************************************************** - Functoin: int idt_init() - - Desc: This function is used to initialize our IDT - Notes: - -*****************************************************************************************/ -int idt_init() { - int i = 0x0; - - struct tssStruct *sfTSS = (struct tssStruct *)0x6200; - struct tssStruct *gpfTSS = (struct tssStruct *)0x4200; - - /* Set up default vector table for all possible 256 interrupts */ - - for (i = 0x0; i < 256; i++) { - idt_setVector(intNull, i, dPresent + dInt + dDpl3); - } - - /* Load the IDT into the system */ - asm volatile( - "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 */ - idt_setVector(_int0, 0, dPresent + dInt + dDpl0); - idt_setVector(_int1, 1, dPresent + dInt + dDpl0); - idt_setVector(_int2, 2, dPresent + dInt + dDpl0); - idt_setVector(_int3, 3, dPresent + dInt + dDpl0); - idt_setVector(_int4, 4, dPresent + dInt + dDpl0); - idt_setVector(_int5, 5, dPresent + dInt + dDpl0); - idt_setVector(_int6, 6, dPresent + dInt + dDpl0); - idt_setVector(_int7,7,dPresent + dInt + dDpl0); - idt_setTaskVector(8,dPresent + dTask + dDpl0, 0x40); - idt_setVector(_int9, 9, dPresent + dInt + dDpl0); - idt_setVector(_int10, 10, dPresent + dInt + dDpl0); - idt_setVector(_int11, 11, dPresent + dInt + dDpl0); - idt_setVector(_int12, 12, dPresent + dInt + dDpl0); - idt_setTaskVector(13, dPresent + dTask + dDpl0, 0x38); - idt_setVector(_vmm_pageFault, 14, dPresent + dInt + dDpl0); - idt_setVector(sched_yield_new,0x69,dPresent + dInt + dDpl3); - idt_setVector(_sysCall, 128, dPresent + dTrap + dDpl3); - idt_setVector(_sysCallNew, 0x90, dPresent + dTrap + dDpl3); - idt_setVector(timerInt, 0x68, (dInt + dPresent + dDpl0)); - - /* Build our GPF TSS */ - memset(gpfTSS,0x0,sizeof(struct tssStruct)); - gpfTSS->cr3 = (unsigned int)kernelPageDirectory; - gpfTSS->eip = (unsigned int)&_int13; - gpfTSS->eflags = 0x206; - gpfTSS->esp = 0x1D000; - gpfTSS->ebp = 0x1D000; - gpfTSS->es = 0x10; - gpfTSS->cs = 0x08; - gpfTSS->ss = 0x10; - gpfTSS->ds = 0x10; - gpfTSS->fs = 0x10; - gpfTSS->gs = 0x10; - gpfTSS->trace_bitmap = 0x0000; - gpfTSS->io_map = 0x8000; - - /* Build our SF TFF */ - memset(sfTSS,0x0,sizeof(struct tssStruct)); - sfTSS->cr3 = (unsigned int)kernelPageDirectory; - sfTSS->eip = (unsigned int)&_int8; - sfTSS->eflags = 0x206; - sfTSS->esp = 0x1C000; - sfTSS->ebp = 0x1C000; - sfTSS->es = 0x10; - sfTSS->cs = 0x08; - sfTSS->ss = 0x10; - sfTSS->ds = 0x10; - sfTSS->fs = 0x10; - sfTSS->gs = 0x10; - sfTSS->io_map = 0x8000; - - /* Print out information for the IDT */ - kprintf("idt0 - Address: [0x%X]\n", &ubixIDT); - - /* Return so we know all went well */ - return (0x0); - } - -/***************************************************************************************** - Functoin: int idt_setVector(handler,interrupt,controlMajor) - - Desc: This function is used to set up a vector in the IDT - - Notes: - -*****************************************************************************************/ -void idt_setVector(void *handler, unsigned char interrupt, unsigned short controlMajor) { - unsigned short codesegment = 0x08; - - asm volatile( - "movw %%cs,%0" - : "=g" (codesegment) - ); - - ubixIDT[interrupt].gate.offsetLow = (unsigned short)(((unsigned long)handler) & 0xffff); - ubixIDT[interrupt].gate.selector = codesegment; - ubixIDT[interrupt].gate.access = controlMajor; - ubixIDT[interrupt].gate.offsetHigh = (unsigned short)(((unsigned long)handler) >> 16); - } - -/***************************************************************************************** - Functoin: int idt_setTaskVector(interrupt,controlMajor,selector) - - Desc: This function is used to set up a task vector in the IDT - - Notes: - -*****************************************************************************************/ -void idt_setTaskVector(uInt8 interrupt, uInt16 controlMajor, uInt8 selector) { - uInt16 codesegment = 0x08; - - asm volatile( - "movw %%cs,%0" - : "=g" (codesegment) - ); - - ubixIDT[interrupt].gate.offsetLow = 0x0; - ubixIDT[interrupt].gate.selector = selector; - ubixIDT[interrupt].gate.access = controlMajor; - ubixIDT[interrupt].gate.offsetHigh = 0x0; - } +void _int7(); +asm( + ".globl _int7 \n" + "_int7: \n" + " pushl %eax \n" + " clts \n" + " movl _current,%eax \n" + " cmpl _usedMath,%eax \n" + " je mathDone \n" + " call mathStateRestore \n" + "mathDone: \n" + " popl %eax \n" + " iret \n" + ); /*** $Log$ - Revision 1.34 2004/08/25 22:02:41 reddawg - task switching - We now are using software switching to be consistant with the rest of the world because all of this open source freaks gave me a hard time about something I liked. There doesn't seem to be any gain in performance but it is working fine and flawlessly - - Revision 1.33 2004/08/24 23:33:45 reddawg - Fixed - - Revision 1.32 2004/08/21 17:36:57 reddawg - updates: converted to software task switching however it is not working yet - Revision 1.31 2004/08/14 11:23:02 reddawg Changes diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index 5843b4b..30b110d 100644 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -327,7 +327,7 @@ //Calculate The Page Table Index And Page Directory Index dI = (baseAddr/(1024*4096)); tI = ((baseAddr-(dI*(1024*4096)))/4096); - vmm_remapPage(child->cr3,0x5A00000,KERNEL_PAGE_DEFAULT); + vmm_remapPage(child->tss.cr3,0x5A00000,KERNEL_PAGE_DEFAULT); for (i=0;i<0x1000;i++) { vmm_remapPage(childPageDir[i],0x5A01000 + (i * 0x1000),KERNEL_PAGE_DEFAULT); }