diff --git a/src/sys/Makefile.inc b/src/sys/Makefile.inc index d5729ab..695dc16 100644 --- a/src/sys/Makefile.inc +++ b/src/sys/Makefile.inc @@ -1,5 +1,5 @@ # $Id: # global 'sys' options -CFLAGS = -fno-builtin +CFLAGS = -fno-builtin -O2 KERNEL = ubix.elf diff --git a/src/sys/include/ubixos/exec.h b/src/sys/include/ubixos/exec.h index 008a5a0..d52a0e4 100644 --- a/src/sys/include/ubixos/exec.h +++ b/src/sys/include/ubixos/exec.h @@ -27,7 +27,7 @@ #include #include -uInt32 execThread(void (* tproc)(void),int stack,char *arg); +uInt32 execThread(void (* tproc)(void),int,char *); void execFile(char *file,int argc,char **argv,int console); #endif diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 8b592b9..0e85bb8 100644 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -34,6 +34,17 @@ #include #include +/***************************************************************************************** + + Function: execThread(void (*)(void),int,char *); + Description: This function will create a thread from code in the current memory space + + Notes: + + 05/19/04 - This does not work the way I want it to it still makes a copy of kernel space + so do not use out side of kernel space + +*****************************************************************************************/ uInt32 execThread(void (* tproc)(void),int stack,char *arg) { kTask_t * newProcess; /* Find A New Thread */ @@ -47,7 +58,7 @@ newProcess->tss.ss1 = 0x0; newProcess->tss.esp2 = 0x0; newProcess->tss.ss2 = 0x0; - newProcess->tss.cr3 = (unsigned int)vmmCopyVirtualSpace(kernelPageDirectory); + newProcess->tss.cr3 = (unsigned int)kernelPageDirectory; newProcess->tss.eip = (unsigned int)tproc; newProcess->tss.eflags = 0x206; newProcess->tss.esp = stack; @@ -67,54 +78,57 @@ 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 %%ebx\n" - "pushl %%ebx\n" - "pushl %%ebx\n" - "movl %%esp,%%eax\n" - "movl %%eax,%1 \n" - "movl %%ecx,%%esp\n" - "popa \n" + "pusha \n" + "movl %%esp,%%ecx \n" + "movl %1,%%eax \n" + "movl %%eax,%%esp \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->tss.esp) ); - + /* Put new thread into the READY state */ newProcess->state = READY; - /* Return */ + + /* Return with the new process ID */ return((uInt32)newProcess); } -/************************************************************************ +/***************************************************************************************** -Function: void execFile(char *file); -Description: This Function Executes A Kile Into A New VM Space With Out - Having To Fork -Notes: + Function: void execFile(char *file); + Description: This Function Executes A Kile Into A New VM Space With Out + Having To Fork + Notes: -07/30/02 - I Have Made Some Heavy Changes To This As Well As Fixed A Few - Memory Leaks The Memory Allocated To Load The Binary Into Is - Now Unmapped So It Can Be Used Again And Not Held Onto Until - The Program Exits + 07/30/02 - I Have Made Some Heavy Changes To This As Well As Fixed A Few + Memory Leaks The Memory Allocated To Load The Binary Into Is + Now Unmapped So It Can Be Used Again And Not Held Onto Until + The Program Exits -07/30/02 - Now I Have To Make A Better Memory Allocator So We Can Set Up - The Freshly Allocated Pages With The Correct Permissions + 07/30/02 - Now I Have To Make A Better Memory Allocator So We Can Set Up + The Freshly Allocated Pages With The Correct Permissions -************************************************************************/ +*****************************************************************************************/ void execFile(char *file,int argc,char **argv,int console) { + int i=0,x=0,eStart=0; char *binarySpace = (char *)0x7C0000; char *newLoc; fileDescriptor *tmpFd = 0x0; elfHeader *binaryHeader = (elfHeader *)0x7C0000; elfProgramheader *programHeader; + /* Get A New Task For This Proccess */ _current = schedNewTask(); - /* _current->oInfo.terminal = findConsole(console); */ _current->gid = 0; _current->uid = 0; /* Now We Must Create A Virtual Space For This Proccess To Run In */ @@ -206,6 +220,7 @@ _current->tss.esi = 0x0; _current->tss.edi = 0x0; + /* Set these up to be ring 3 tasks */ _current->tss.es = 0x30+3; _current->tss.cs = 0x28+3; _current->tss.ss = 0x30+3; @@ -213,43 +228,36 @@ _current->tss.fs = 0x30+3; _current->tss.gs = 0x30+3; - /* - _current->tss.es = 0x10; - _current->tss.cs = 0x08; - _current->tss.ss = 0x10; - _current->tss.ds = 0x10; - _current->tss.fs = 0x10; - _current->tss.gs = 0x10; - */ - _current->tss.ldt = 0x18; _current->tss.trace_bitmap = 0x0000; _current->tss.io_map = 0x8000; _current->state = READY; - + /* Set up the defaault stack to be used by this new process */ /* + + Some bug here let me figure it out 05/19/2004 + asm volatile( - "pusha \n" - "movl %%esp,%%edx\n" - "movl %2,%%ecx \n" - "movl %%ecx,%%esp\n" - "pushl $0x0\n" - "pushl $0x0\n" - "pushl $0x0\n" - "pushl $0x0\n" - "pushl %%ebx\n" - "pushl %%eax\n" - "movl %%esp,%%ecx\n" - "movl %%ecx,%2 \n" - "movl %%edx,%%esp\n" - "popa \n" + "pusha \n" + "movl %%esp,%%edx \n" + "movl %2,%%ecx \n" + "movl %%ecx,%%esp \n" + "pushl $0x0 \n" + "pushl $0x0 \n" + "pushl $0x0 \n" + "pushl $0x0 \n" + "pushl %%ebx \n" + "pushl %%eax \n" + "movl %%esp,%%ecx \n" + "movl %%ecx,%2 \n" + "movl %%edx,%%esp \n" + "popa \n" : : "a" (argc), "b" (argv), "m" (_current->tss.esp) ); */ - /* Switch Back To The Kernels VM Space */ asm( "movl %0,%%eax \n" @@ -260,15 +268,15 @@ return; } -/************************************************************************ +/***************************************************************************************** -Function: void sysExec(); -Description: This Is The System Call To Execute A New Task + Function: void sysExec(); + Description: This Is The System Call To Execute A New Task -Notes: - 04-22-03 - It Now Loads Sections Not The Full File + Notes: + 04-22-03 - It Now Loads Sections Not The Full File -************************************************************************/ +*****************************************************************************************/ void sysExec(char *file,int argc,char **argv) { int i = 0x0; int x = 0x0; @@ -288,11 +296,9 @@ /* If We Dont Find the File Return */ if (tmpFd == 0x0) { - //*status = 0; return; } if (tmpFd->perms == 0) { - //*status = -2; kprintf("Exec Format Error: Binary File Not Executable.\n"); fclose(tmpFd); return; @@ -306,21 +312,18 @@ /* Check If App Is A Real Application */ if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { - //*status = -1; kprintf("Exec Format Error: Binary File Not Executable.\n"); kfree(binaryHeader); fclose(tmpFd); return; } else if (binaryHeader->eType != 2) { - //*status = -2; kprintf("Exec Format Error: Binary File Not Executable.\n"); kfree(binaryHeader); fclose(tmpFd); return; } else if (binaryHeader->eEntry == 0x300000) { - //*status = -2; kprintf("Exec Format Error: Binary File Not Executable.\n"); kfree(binaryHeader); fclose(tmpFd); @@ -362,7 +365,6 @@ linker = (char *)kmalloc(programHeader[i].phMemsz); fseek(tmpFd,programHeader[i].phOffset,0); fread(linker,programHeader[i].phFilesz,1,tmpFd); - //kprintf("Linker: [%s]\n",linker); } } _current->oInfo.shstrtab = (char *)kmalloc(sectionHeader[binaryHeader->eShstrndx].shSize); @@ -390,9 +392,9 @@ fclose(tmpFd); /* Jump To Start Of New Binary */ asm volatile( - "pushl %1\n" - "pushl %%eax\n" - "call *%0\n" + "pushl %1 \n" + "pushl %%eax \n" + "call *%0 \n" : : "g" (eStart),"g" (argv),"a" (argc) ); @@ -400,6 +402,9 @@ /*** $Log$ + Revision 1.6 2004/05/19 04:07:42 reddawg + kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been + Revision 1.5 2004/05/19 01:21:29 reddawg Tweaked