diff --git a/src/sys/include/ubixos/sched.h b/src/sys/include/ubixos/sched.h index 779c0a9..50b4641 100644 --- a/src/sys/include/ubixos/sched.h +++ b/src/sys/include/ubixos/sched.h @@ -55,20 +55,22 @@ }; typedef struct taskStruct { - pidType id; + pidType id; struct taskStruct *prev; struct taskStruct *next; - 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; + struct i387Struct i387; + struct i386_frame *iframe; + struct osInfo oInfo; + uInt32 cr3; + char kernelStack[0x2000]; + fileDescriptor *imageFd; + tState state; + uInt32 gid; + uInt32 uid; + uInt16 usedMath; + uInt16 nice; + uInt32 timeSlice; + tty_term *term; } kTask_t; typedef struct prioQueue { @@ -102,6 +104,9 @@ /*** $Log$ + Revision 1.20 2004/08/09 12:58:05 reddawg + let me know when you got the surce + Revision 1.19 2004/08/06 22:43:04 reddawg ok diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 26ec1a5..bf55f0c 100644 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -70,6 +70,10 @@ union descriptorTableUnion *gdt __attribute__ ((packed)); } loadGDT = { (9 * sizeof(union descriptorTableUnion) - 1), ubixGDT }; +void test_thread() { + kprintf("HOLLER\n"); + while (1); + } /***************************************************************************************** Functoin: int main() @@ -103,7 +107,7 @@ } */ initHardDisk(); - execThread(systemTask,(uInt32)(kmalloc(0x2000)+0x2000),0x0); + execThread(test_thread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); execFile("sys:/init",0x0,0x0,0x1); //execFile("sys:/login",0x0,0x0,0x1); @@ -114,13 +118,17 @@ kprintf("Free Pages: [%i]\n",systemVitals->freePages); kprintf("MemoryMap: [0x%X]\n",vmmMemoryMap); kprintf("Starting Os\n"); - irqEnable(0x0); + /* irqEnable(0x0); */ sched(); + while (1); return(0x0); } /*** $Log$ + Revision 1.73 2004/08/15 00:33:02 reddawg + Wow the ide driver works again + Revision 1.72 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. diff --git a/src/sys/kernel/bioscall.c b/src/sys/kernel/bioscall.c index 8121d85..1f540d7 100644 --- a/src/sys/kernel/bioscall.c +++ b/src/sys/kernel/bioscall.c @@ -58,6 +58,7 @@ newProcess = schedNewTask(); assert(newProcess); + /* newProcess->tss.back_link = 0x0; newProcess->tss.esp0 = (uInt32)kmalloc(0x2000)+0x2000; newProcess->tss.ss0 = 0x10; @@ -87,6 +88,7 @@ newProcess->tss.io_map = 0x0 & 0xFFFF; newProcess->tss.io_map = sizeof(struct tssStruct)-8192; newProcess->oInfo.v86Task = 0x1; + */ newProcess->state = READY; while (newProcess->state > 0); @@ -96,6 +98,11 @@ /*** $Log$ + Revision 1.5 2004/07/17 15:54:52 reddawg + kmalloc: added assert() + bioscall: fixed some potential problem by not making 16bit code + paging: added assert() + Revision 1.4 2004/06/15 12:24:07 reddawg Cleaned Up diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 651b73a..245e524 100644 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -58,6 +58,7 @@ kpanic("exec: stack not in valid area: [0x%X]\n",stack); /* Set All The Correct Thread Attributes */ + /* Old newProcess->tss.back_link = 0x0; newProcess->tss.esp0 = 0x0; newProcess->tss.ss0 = 0x0; @@ -84,6 +85,16 @@ newProcess->tss.trace_bitmap = 0x0000; newProcess->tss.io_map = 0x8000; newProcess->oInfo.vmStart = 0x6400000; + */ + + newProcess->cr3 = (uInt32)kernelPageDirectory; + newProcess->iframe->eip = (uInt32)tproc; + newProcess->iframe->flags = 0x206; + newProcess->iframe->esp = stack; + newProcess->iframe->ebp = stack; + newProcess->iframe->user_esp = stack; + newProcess->iframe->user_ss = 0x10; + newProcess->iframe->cs = 0x08; /* Set up default stack for thread here filled with arg list 3 times */ asm volatile( @@ -99,7 +110,7 @@ "movl %%ecx,%%esp \n" "popa \n" : - : "b" (arg),"m" (newProcess->tss.esp) + : "b" (arg),"m" (newProcess->iframe->esp) ); /* Put new thread into the READY state */ @@ -147,13 +158,13 @@ _current->term->owner = _current->id; /* Now We Must Create A Virtual Space For This Proccess To Run In */ - _current->tss.cr3 = (uInt32)vmmCreateVirtualSpace(_current->id); + _current->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->tss.cr3)) + : : "d" ((uInt32 *)(_current->cr3)) ); /* Lets Find The File */ @@ -238,6 +249,7 @@ 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; @@ -251,8 +263,9 @@ _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; @@ -263,6 +276,15 @@ _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 = 0x5DD000 - 12; + _current->iframe->ebp = 0x5DD000; + _current->iframe->user_esp = 0x5DD000 - 12; + _current->iframe->user_ss = 0x30 + 3; + _current->iframe->cs = 0x28 + 3; sched_setStatus(_current->id,READY); @@ -407,13 +429,18 @@ } /* 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 */ kfree(binaryHeader); kfree(programHeader); @@ -423,6 +450,9 @@ /*** $Log$ + Revision 1.62 2004/08/14 11:23:02 reddawg + Changes + Revision 1.61 2004/08/09 12:58:05 reddawg let me know when you got the surce diff --git a/src/sys/kernel/fork.c b/src/sys/kernel/fork.c index 2e027c7..51c4041 100644 --- a/src/sys/kernel/fork.c +++ b/src/sys/kernel/fork.c @@ -70,6 +70,7 @@ assert(_current); /* Set Up New Tasks Information */ + /* newProcess->tss.eip = eip; sprintf(newProcess->oInfo.cwd,_current->oInfo.cwd); newProcess->oInfo.vmStart = _current->oInfo.vmStart; @@ -102,11 +103,31 @@ newProcess->tss.ldt = 0x18; newProcess->tss.trace_bitmap = 0x0000; newProcess->tss.io_map = 0x8000; + */ + newProcess->iframe->gs = _current->iframe->gs; + newProcess->iframe->fs = _current->iframe->fs; + newProcess->iframe->es = _current->iframe->es; + newProcess->iframe->ds = _current->iframe->ds; + newProcess->iframe->ss = ss; + newProcess->iframe->edi = edi; + newProcess->iframe->esi = esi; + newProcess->iframe->ebp = ebp; + newProcess->iframe->esp = esp; + 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; /* Create A Copy Of The VM Space For New Task */ - newProcess->tss.cr3 = (uInt32)vmmCopyVirtualSpace(newProcess->id); + newProcess->cr3 = (uInt32)vmmCopyVirtualSpace(newProcess->id); newProcess->state = FORK; - while (newProcess->state == FORK); + while (newProcess->state == FORK) + sched_yield(); /* Return Id of Proccess */ return(newProcess->id); @@ -114,6 +135,9 @@ /*** $Log$ + Revision 1.22 2004/08/09 12:58:05 reddawg + let me know when you got the surce + Revision 1.21 2004/08/06 22:32:16 reddawg Ubix Works Again diff --git a/src/sys/kernel/sched.c b/src/sys/kernel/sched.c index dd6b179..b36cac4 100644 --- a/src/sys/kernel/sched.c +++ b/src/sys/kernel/sched.c @@ -123,26 +123,27 @@ kpanic("malloc: Failed File: %s, Line: %i\n",__FILE__,__LINE__); /* sched_tss.esp0 = 0x5CC000; */ - sched_tss.ss0 = 0x10; - sched_tss.esp1 = 0x0; + sched_tss->ss0 = 0x10; /* sched_tss.eip = (long)binaryHeader->eEntry; */ - sched_tss.eflags = 0x206; - sched_tss.esp = 0x5DD000-12; - sched_tss.ebp = 0x5DD000; - sched_tss.esi = 0x0; - sched_tss.edi = 0x0; + sched_tss->eflags = 0x206; /* Set these up to be ring 3 tasks */ - sched_tss.es = 0x30+3; - sched_tss.cs = 0x28+3; - sched_tss.ss = 0x30+3; - sched_tss.ds = 0x30+3; - sched_tss.fs = 0x30+3; - sched_tss.gs = 0x30+3; + sched_tss->es = 0x30+3; + sched_tss->cs = 0x28+3; + sched_tss->ss = 0x30+3; + sched_tss->ds = 0x30+3; + sched_tss->fs = 0x30+3; + sched_tss->gs = 0x30+3; + + /* 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'; - sched_tss.ldt = 0x18; - sched_tss.trace_bitmap = 0x0000; - sched_tss.io_map = 0x8000; + sched_tss->ldt = 0x18; + sched_tss->trace_bitmap = 0x0000; + sched_tss->io_map = 0x8000; tmpTask->prev = 0x0; tmpTask->next = 0x0; @@ -154,7 +155,7 @@ _current = runList; nextID++; - kprintf("sched0 - Address: [0x%X]\n", runList); + kprintf("sched0 - Address: [0x%X:0x%X]\n",sched_tss,runList); /* Return so we know everything went well */ return(0x0); @@ -178,15 +179,31 @@ irqDisable(0x0); /* Update our TSS to new task info */ + /* old 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'; + */ /* Jump to task */ + /* old asm("ljmp $0x20,$0\n"); + */ + /* Switch Tasks */ + sched_tss->esp0 = _current->kernelStack + 0x2000; + asm volatile( + "mov %0,%%eax \n" + "mov %1,%%esp \n" + "mov %%eax,%%cr3 \n" + "popa \n" + "iret \n" + : + : "g" (_current->cr3), "g" (_current->iframe) + ); + /* Return */ return; } @@ -215,7 +232,7 @@ runList->prev = tmpTask; runList = tmpTask; - + tmpTask->iframe = tmpTask->kernelStack - sizeof(struct i386_frame); spinUnlock(&sched_spinLock); return(tmpTask); } @@ -327,6 +344,9 @@ /*** $Log$ + 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 *** diff --git a/src/sys/sys/idt.c b/src/sys/sys/idt.c index 2f01150..2566cfa 100644 --- a/src/sys/sys/idt.c +++ b/src/sys/sys/idt.c @@ -288,9 +288,9 @@ gpfTSS->ebp = 0x1D000; gpfTSS->eflags = 0x206; - ip = FP_TO_LINEAR(_current->tss.cs, _current->tss.eip); + ip = FP_TO_LINEAR(_current->iframe->cs, _current->iframe->eip); ivt = (uInt16 *) 0x0; - stack = (uInt16 *) FP_TO_LINEAR(_current->tss.ss,_current->tss.esp); + stack = (uInt16 *) FP_TO_LINEAR(_current->iframe->ss,_current->iframe->esp); stack32 = (uInt32 *) stack; gpfStart: @@ -307,105 +307,105 @@ break; default: stack -= 3; - _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; + _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; if (_current->oInfo.v86If) stack[2] |= EFLAG_IF; else stack[2] &= ~EFLAG_IF; - _current->tss.cs = ivt[ip[1] * 2 + 1] & 0xFFFF; - _current->tss.eip = ivt[ip[1] * 2] & 0xFFFF; + _current->iframe->cs = ivt[ip[1] * 2 + 1] & 0xFFFF; + _current->iframe->eip = ivt[ip[1] * 2] & 0xFFFF; break; } break; case 0x66: isOperand32 = TRUE; ip++; - _current->tss.eip = (uInt16) (_current->tss.eip + 1); + _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); goto gpfStart; break; case 0x67: isAddress32 = TRUE; ip++; - _current->tss.eip = (uInt16) (_current->tss.eip + 1); + _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); goto gpfStart; break; case 0xF0: - _current->tss.eip = (uInt16) (_current->tss.eip + 1); + _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); kpanic("GPF OP 0xF0\n"); break; case 0x9C: if (isOperand32 == TRUE) { - _current->tss.esp = ((_current->tss.esp & 0xffff) - 4) & 0xffff; + _current->iframe->esp = ((_current->iframe->esp & 0xffff) - 4) & 0xffff; stack32--; - stack32[0] = _current->tss.eflags & 0xDFF; + stack32[0] = _current->iframe->flags & 0xDFF; if (_current->oInfo.v86If == TRUE) stack32[0] |= EFLAG_IF; else stack32[0] &= ~EFLAG_IF; } else { - _current->tss.esp = ((_current->tss.esp & 0xffff) - 2) & 0xffff; + _current->iframe->esp = ((_current->iframe->esp & 0xffff) - 2) & 0xffff; stack--; - stack[0] = (uInt16) _current->tss.eflags; + stack[0] = (uInt16) _current->iframe->flags; if (_current->oInfo.v86If == TRUE) stack[0] |= EFLAG_IF; else stack[0] &= ~EFLAG_IF; - _current->tss.eip = (uInt16) (_current->tss.eip + 1); + _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); } break; case 0x9D: if (isOperand32 == TRUE) { - _current->tss.eflags = EFLAG_IF | EFLAG_VM | (stack32[0] & 0xDFF); + _current->iframe->flags = EFLAG_IF | EFLAG_VM | (stack32[0] & 0xDFF); _current->oInfo.v86If = (stack32[0] & EFLAG_IF) != 0; - _current->tss.esp = ((_current->tss.esp & 0xffff) + 4) & 0xffff; + _current->iframe->esp = ((_current->iframe->esp & 0xffff) + 4) & 0xffff; } else { - _current->tss.eflags = EFLAG_IF | EFLAG_VM | stack[0]; + _current->iframe->flags = EFLAG_IF | EFLAG_VM | stack[0]; _current->oInfo.v86If = (stack[0] & EFLAG_IF) != 0; - _current->tss.esp = ((_current->tss.esp & 0xffff) + 2) & 0xffff; + _current->iframe->esp = ((_current->iframe->esp & 0xffff) + 2) & 0xffff; } - _current->tss.eip = (uInt16) (_current->tss.eip + 1); + _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); /* kprintf("popf [0x%X]\n",_current->id); */ break; case 0xFA: _current->oInfo.v86If = FALSE; - _current->tss.eflags &= ~EFLAG_IF; - _current->tss.eip = (uInt16) (_current->tss.eip + 1); + _current->iframe->flags &= ~EFLAG_IF; + _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); _current->oInfo.timer = 0x1; break; case 0xFB: _current->oInfo.v86If = TRUE; - _current->tss.eflags |= EFLAG_IF; - _current->tss.eip = (uInt16) (_current->tss.eip + 1); + _current->iframe->flags |= EFLAG_IF; + _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); _current->oInfo.timer = 0x0; /* kprintf("sti [0x%X]\n",_current->id); */ break; case 0xCF: - _current->tss.eip = stack[0]; - _current->tss.cs = stack[1]; - _current->tss.eflags = EFLAG_IF | EFLAG_VM | stack[2]; + _current->iframe->eip = stack[0]; + _current->iframe->cs = stack[1]; + _current->iframe->flags = EFLAG_IF | EFLAG_VM | stack[2]; _current->oInfo.v86If = (stack[2] & EFLAG_IF) != 0; - _current->tss.esp = ((_current->tss.esp & 0xffff) + 6) & 0xffff; + _current->iframe->esp = ((_current->iframe->esp & 0xffff) + 6) & 0xffff; /* kprintf("iret [0x%X]\n",_current->id); */ break; case 0xEC: /* IN AL,DX */ - _current->tss.eax = (_current->tss.eax & ~0xFF) | inportByte(_current->tss.edx); - _current->tss.eip = (uInt16) (_current->tss.eip + 1); + _current->iframe->eax = (_current->iframe->eax & ~0xFF) | inportByte(_current->iframe->edx); + _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); 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); + _current->iframe->eax = (_current->iframe->eax & ~0xFFFF) | inportWord(_current->iframe->edx); + _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); break; case 0xEE: /* OUT DX,AL */ - outportByte(_current->tss.edx, _current->tss.eax & 0xFF); - _current->tss.eip = (uInt16) (_current->tss.eip + 1); + outportByte(_current->iframe->edx, _current->iframe->eax & 0xFF); + _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); break; case 0xEF: - outportWord(_current->tss.edx, _current->tss.eax); - _current->tss.eip = (uInt16) (_current->tss.eip + 1); + outportWord(_current->iframe->edx, _current->iframe->eax); + _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); break; case 0xF4: - _current->tss.eip = (uInt16) (_current->tss.eip + 1); + _current->iframe->eip = (uInt16) (_current->iframe->eip + 1); break; default: /* something wrong */ kprintf("NonHandled OpCode [0x%X:0x%X]\n",_current->id,ip[0]); @@ -458,6 +458,9 @@ /*** $Log$ + Revision 1.31 2004/08/14 11:23:02 reddawg + Changes + Revision 1.30 2004/08/06 22:43:04 reddawg ok diff --git a/src/sys/vfs/file.c b/src/sys/vfs/file.c index b8894ca..61279a2 100644 --- a/src/sys/vfs/file.c +++ b/src/sys/vfs/file.c @@ -32,12 +32,15 @@ #include #include #include +#include #include #include #include #include #include +static spinLock_t fopen_lock = SPIN_LOCK_INITIALIZER; + /************************************************************************ Function: int fclose(fileDescriptor *fd); @@ -166,6 +169,8 @@ fileDescriptor *tmpFd = 0x0; char *path = 0x0,*mountPoint = 0x0; + spinLock(&fopen_lock); + /* Allocate Memory For File Descriptor */ if ((tmpFd = (fileDescriptor *)kmalloc(sizeof(fileDescriptor))) == 0x0) { kprintf("Error: tmpFd == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); @@ -200,6 +205,7 @@ } if (tmpFd->mp == 0x0) { kprintf("Mount Point Bad\n"); + spinUnlock(&fopen_lock); return(0x0); } /* This Will Set Up The Descriptor Modes */ @@ -255,6 +261,7 @@ systemVitals->openFiles++; /* Return The FD */ + spinUnlock(&fopen_lock); return(fdTable); } else { @@ -263,11 +270,15 @@ } /* Return NULL */ + spinUnlock(&fopen_lock); return(0x0); } /*** $Log$ + Revision 1.20 2004/08/14 11:23:02 reddawg + Changes + Revision 1.19 2004/08/09 12:58:05 reddawg let me know when you got the surce diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index 12203f3..5843b4b 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->tss.cr3,0x5A00000,KERNEL_PAGE_DEFAULT); + vmm_remapPage(child->cr3,0x5A00000,KERNEL_PAGE_DEFAULT); for (i=0;i<0x1000;i++) { vmm_remapPage(childPageDir[i],0x5A01000 + (i * 0x1000),KERNEL_PAGE_DEFAULT); } @@ -425,6 +425,12 @@ /*** $Log$ + Revision 1.16 2004/07/28 15:05:43 reddawg + Major: + Pages now have strict security enforcement. + Many null dereferences have been resolved. + When apps loaded permissions set for pages rw and ro + Revision 1.15 2004/07/28 00:17:05 reddawg Major: Disconnected page 0x0 from the system... Unfortunately this broke many things