diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs index 6d2dac7..7347476 100644 --- a/.settings/org.eclipse.cdt.core.prefs +++ b/.settings/org.eclipse.cdt.core.prefs @@ -1,3 +1,9 @@ -#Fri Jun 22 08:01:43 EDT 2007 +#Thu Jun 18 07:39:49 EDT 2009 eclipse.preferences.version=1 +indexer/filesToParseUpFront=stdarg.h, stddef.h, sys/types.h +indexer/indexAllFiles=true +indexer/indexerId=org.eclipse.cdt.core.fastIndexer +indexer/skipMacroReferences=false +indexer/skipReferences=false +indexer/skipTypeReferences=false indexerId=org.eclipse.cdt.core.fastIndexer diff --git a/BUGS b/BUGS index 44a44c7..70bd817 100644 --- a/BUGS +++ b/BUGS @@ -2,6 +2,8 @@ Bugs: +06/17/09 - Need to free pageDir page + 10/27/06 - NEED TO IMPLIMENT ENV!!!! 10/12/06 - diff --git a/src/Makefile.inc b/src/Makefile.inc index 6ab96cc..18373b1 100644 --- a/src/Makefile.inc +++ b/src/Makefile.inc @@ -3,8 +3,8 @@ # allow you to change your default compiler without affecting your other work CFLAGS = -CC = gcc -CXX = g++ +CC = gcc34 +CXX = g++34 LD = ld AR = ar REMOVE = rm -rf diff --git a/src/bin/cat/cat b/src/bin/cat/cat index 160f7cf..56da348 100755 --- a/src/bin/cat/cat +++ b/src/bin/cat/cat Binary files differ diff --git a/src/bin/edit/Makefile b/src/bin/edit/Makefile index 4df4473..0664542 100644 --- a/src/bin/edit/Makefile +++ b/src/bin/edit/Makefile @@ -28,7 +28,7 @@ # Link The Binary $(BINARY) : $(OBJS) $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS) - #strip $(BINARY) + strip $(BINARY) # Compile the source files .cc.o: diff --git a/src/bin/init/main.c b/src/bin/init/main.c index 257d778..9ed4a1f 100644 --- a/src/bin/init/main.c +++ b/src/bin/init/main.c @@ -38,6 +38,8 @@ int i=0x0; mpi_message_t myMsg; + printf("A"); + /* Create a mailbox for this task */ if (mpi_createMbox("init") != 0x0) { printf("Error: Failed to creating mail box: init\n"); diff --git a/src/bin/ls/ls.c b/src/bin/ls/ls.c index 8d515a6..150a9d3 100644 --- a/src/bin/ls/ls.c +++ b/src/bin/ls/ls.c @@ -158,6 +158,9 @@ char *bp = tcapbuf; #endif +//NOTE Fix +return(0x0); + (void)setlocale(LC_ALL, ""); /* Terminal defaults to -Cq, non-terminal defaults to -1. */ diff --git a/src/bin/shell/exec.c b/src/bin/shell/exec.c index d0b6f81..0bfa058 100644 --- a/src/bin/shell/exec.c +++ b/src/bin/shell/exec.c @@ -41,6 +41,7 @@ if (!cPid) { sprintf(file,"%s%s",cwd,argv[1]); + printf("Forked And Ready To Roll: %s\n",file); if (boo == 0) exec(file,data->argv,data->envp); else diff --git a/src/lib/libc/Makefile b/src/lib/libc/Makefile index f60ed5f..bbb6732 100644 --- a/src/lib/libc/Makefile +++ b/src/lib/libc/Makefile @@ -50,9 +50,9 @@ $(CC) -nostdlib -shared -Wl,-x -o $(OUTPUT) -Wl,-soname,$(OUTPUT) `lorder $(OBJS) $(SUBS) | tsort -q` #$(CC) -nostdlib -shared -Wl,-x -o lib-c.so -Wl,-soname,lib-c.so `lorder $(OBJS) $(SUBS) | tsort -q` #(rm -fr pic.a;ar cq pic.a ./i386/*/*.o ./stdio/*.o ./stdlib/*.o ./string/*.o ./sys/*.o ./xdr/*.o ./yp/*.o ./locale/*.o ./gen/*.o ; ranlib ./pic.a) - #(rm pic.a) - #$(AR) cq $(LPIC) `lorder $(OBJS) $(SUBS) | tsort -q` - #ranlib $(LPIC) + (rm -fr pic.a) + $(AR) cq $(LPIC) `lorder $(OBJS) $(SUBS) | tsort -q` + ranlib $(LPIC) lib.a: $(OBJS) # (make clean) diff --git a/src/lib/libc/libc.inc b/src/lib/libc/libc.inc index 99d2040..e7d4cac 100644 --- a/src/lib/libc/libc.inc +++ b/src/lib/libc/libc.inc @@ -1,8 +1,8 @@ -CC = gcc32 +CC = gcc34 REMOVE = rm -fr .if defined(PICA) -CFLAGS = -O2 -fno-strict-aliasing -pipe -D__DBINTERFACE_PRIVATE -DINET6 -DPOSIX_MISTAKE -DBROKEN_DES -DPORTMAP -DDES_BUILTIN -DYP -DHESIOD -Wsystem-headers -Werror -Wall -Wno-format-y2k -Wno-uninitialized -nostdinc -nostdlib #-fpic -DPIC +CFLAGS = -O2 -fno-strict-aliasing -pipe -D__DBINTERFACE_PRIVATE -DINET6 -DPOSIX_MISTAKE -DBROKEN_DES -DPORTMAP -DDES_BUILTIN -DYP -DHESIOD -Wsystem-headers -Werror -Wall -Wno-format-y2k -Wno-uninitialized -nostdinc -nostdlib -fpic -DPIC CFLAGS_UTHREAD = -DPIC -O2 -fno-strict-aliasing -pipe -DPTHREAD_KERNEL -D_LOCK_DEBUG -D_PTHREADS_INVARIANTS .else CFLAGS = -fpic -DPIC -O2 -fno-strict-aliasing -pipe -D__DBINTERFACE_PRIVATE -DINET6 -DPOSIX_MISTAKE -DBROKEN_DES -DPORTMAP -DDES_BUILTIN -DYP -DHESIOD -Wsystem-headers -Wall -Wno-format-y2k -Wno-uninitialized diff --git a/src/sys/Makefile.inc b/src/sys/Makefile.inc index 882e13f..34cbfc7 100644 --- a/src/sys/Makefile.inc +++ b/src/sys/Makefile.inc @@ -2,5 +2,5 @@ # global 'sys' options INCLUDES = -I../include -CFLAGS = -Wall -nostdlib -nostdinc -fno-builtin -fno-exceptions -O -DNOTIMP #-DVFSDEBUG -DDEBUG #-DVMMDEBUG #-DVFSDEBUG +CFLAGS = -Wall -nostdlib -nostdinc -fno-builtin -fno-exceptions -O -DNOTIMP -DLD_DEBUG -D VMMDEBUG #-DVFSDEBUG -DDEBUG #-DVMMDEBUG #-DVFSDEBUG KERNEL = ubix.elf diff --git a/src/sys/include/sys/thread.h b/src/sys/include/sys/thread.h index 376457f..c2effad 100644 --- a/src/sys/include/sys/thread.h +++ b/src/sys/include/sys/thread.h @@ -39,7 +39,7 @@ struct thread { int td_retval[2]; u_int32_t o_files[O_FILES]; - char * vm_daddr; + u_int32_t vm_daddr; int32_t vm_dsize; u_int8_t mode; }; diff --git a/src/sys/include/ubixos/exec.h b/src/sys/include/ubixos/exec.h index a3600a8..d48d56d 100644 --- a/src/sys/include/ubixos/exec.h +++ b/src/sys/include/ubixos/exec.h @@ -35,7 +35,7 @@ uInt32 execThread(void (* tproc)(void),uInt32,char *); void execFile(char *file,int argc,char **argv,int console); -int sys_exec(char *file,char *ap); +void sys_exec(char *file,char *ap); #endif diff --git a/src/sys/include/ubixos/kpanic.h b/src/sys/include/ubixos/kpanic.h index 7905951..f00013a 100644 --- a/src/sys/include/ubixos/kpanic.h +++ b/src/sys/include/ubixos/kpanic.h @@ -30,7 +30,7 @@ #ifndef _KPANIC_H #define _KPANIC_H -#define K_PANIC(msg) kpanic("\nKernel Panic!!!!\nError: (%s), File: %s, Function: %s, Line: %i\n",msg ,__FILE__,__FUNCTION__,__LINE__); +#define K_PANIC(msg) kpanic("\nError: (%s), File: %s, Function: %s, Line: %i\n",msg ,__FILE__,__FUNCTION__,__LINE__); void kpanic(const char *fmt, ...); diff --git a/src/sys/include/ubixos/syscalls.h b/src/sys/include/ubixos/syscalls.h index 0361e82..8d5aacb 100644 --- a/src/sys/include/ubixos/syscalls.h +++ b/src/sys/include/ubixos/syscalls.h @@ -40,7 +40,7 @@ void sysGetpid(); void sysExit(); void sysExec(); -int sys_exec(); +void sys_exec(); void sysFork(); void sysCheckPid(); void sysGetFreePage(); @@ -90,7 +90,7 @@ invalidCall, /** 12 **/ invalidCall, /** 13 **/ invalidCall, /** 14 **/ - sys_exec, /** 15 **/ + sys_exec, /** 15 **/ invalidCall, /** 16 **/ invalidCall, /** 17 **/ invalidCall, /** 18 **/ @@ -139,6 +139,9 @@ /*** $Log$ + Revision 1.2 2008/02/29 14:56:31 reddawg + Sync - Working On Getting It To Boot Again + Revision 1.1.1.1 2007/01/17 03:31:52 reddawg UbixOS diff --git a/src/sys/include/vmm/paging.h b/src/sys/include/vmm/paging.h index 3eb6643..d86f648 100644 --- a/src/sys/include/vmm/paging.h +++ b/src/sys/include/vmm/paging.h @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002-2004 The UbixOS Project + Copyright (c) 2002-2004,2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -38,11 +38,8 @@ #define VM_TASK 1 #define pageLength 0x00000400 -#define pageSize 4096 -#define pageEntries (pageSize/4) -#define tablesBaseAddress 0xBFC00000 -#define parentPageDirAddr 0x100000 -#define PARENT_PAGEDIR_ADDR 0x100000 /* Address at which the page directory is stored */ +#define PAGE_TABLES_BASE_ADDR 0xBFC00000 /* Base address of page tables in virtual area 3GB - 4MB */ +#define PARENT_PAGEDIR_ADDR 0x100000 /* Address at which the page directory is stored */ #define PAGE_COW 0x00000200 #define PAGE_STACK 0x00000400 @@ -56,37 +53,37 @@ #define PAGE_SHIFT 12 /* LOG2(PAGE_SIZE) */ #define PAGE_SIZE (1<> 12) & 0x3FF) +#define PDI(x) (x >> 22) #define trunc_page(x) ((x) & ~PAGE_MASK) #define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK) #define ctob(x) ((x)<>PAGE_SHIFT) -int vmmClearVirtualPage(uInt32 pageAddr); - -void vmmUnmapPage(uInt32,int); -void vmmUnmapPages(void *,uInt32); -void *vmmMapFromTask(pidType,void *,uInt32); +int vmm_zeroVirtualPage(u_int32_t pageAddr); +void vmm_unmapPages(u_int32_t addr,u_int32_t count,u_int16_t flags); +void *vmm_mapFromTask(pidType pid,u_int32_t baseAddr,u_int32_t size); void *vmmCopyVirtualSpace(pidType); -void *vmmGetFreeKernelPage(pidType); -void *vmmGetFreeKernelPage(pidType pid,uInt16 count); void *vmmCreateVirtualSpace(pidType); void *vmmGetFreeVirtualPage(pidType,int,int); -uInt32 vmm_getPhysicalAddr(uInt32); -int vmm_setPageAttributes(uInt32,uInt16); -int vmm_remapPage(uInt32,uInt32,uInt16); +void *vmm_getFreeKernelPage(pidType pid,u_int32_t count); +u_int32_t vmm_getPhysicalAddr(u_int32_t); +void vmm_setPageAttributes(u_int32_t,u_int16_t); +int vmm_remapPage(u_int32_t,u_int32_t,u_int16_t); int vmm_pagingInit(); -void *vmm_getFreeMallocPage(uInt16 count); -void vmm_pageFault(uInt32,uInt32,uInt32); +void *vmm_getFreeMallocPage(u_int16_t count); +void vmm_pageFault(u_int32_t,u_int32_t,u_int32_t); void _vmm_pageFault(); int mmap(struct thread *,struct mmap_args *); int obreak(struct thread *,struct obreak_args *); int munmap(struct thread *,struct munmap_args *); -extern uInt32 *kernelPageDirectory; +extern u_int32_t *kernelPageDirectory; #endif diff --git a/src/sys/include/vmm/vmm.h b/src/sys/include/vmm/vmm.h index dfc8a00..b63a2f2 100644 --- a/src/sys/include/vmm/vmm.h +++ b/src/sys/include/vmm/vmm.h @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002-2004 The UbixOS Project + Copyright (c) 2002-2004, 2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -52,13 +52,15 @@ int vmm_init(); int vmmMemMapInit(); int countMemory(); -u_int32_t vmmFindFreePage(pidType pid); -int freePage(uInt32 pageAddr); -int adjustCowCounter(uInt32 baseAddr,int adjustment); -void vmmFreeProcessPages(pidType pid); +u_int32_t vmm_findFreePage(pidType pid); +void vmm_freePage(u_int32_t pageAddr); +void vmm_adjustCowCounter(u_int32_t pageAddr,int adjustment); +void vmm_freeProcessPages(pidType pid); #endif /*** + $Log$ + END ***/ diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 95b40f0..f806908 100644 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002-2004, 2005, 2007, 2008 The UbixOS Project + Copyright (c) 2002-2004, 2005, 2007, 2008,2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -37,6 +37,7 @@ #include #include #include +#include #define B_ADAPTORSHIFT 24 #define B_ADAPTORMASK 0x0f @@ -62,7 +63,7 @@ Desc: The Kernels Descriptor table: 0x00 - Dummy Entry 0x08 - Ring 0 CS - 0x10 - Ring 0 DS + 0x10 - Ring 0 DS 0x18 - Dummy LDT 0x20 - Scheduler TSS 0x28 - Ring 3 CS @@ -70,7 +71,7 @@ 0x38 - GPF TSS 0x40 - Stack Fault TSS - Notes: + Notes: *****************************************************************************************/ ubixDescriptorTable(ubixGDT,9) { @@ -90,7 +91,7 @@ } loadGDT = { (9 * sizeof(union descriptorTableUnion) - 1), ubixGDT }; /** - * \brief This is the entry point into the os where all of the kernels sub systems are started up. + * \brief This is the entry point into the os where all of the kernels sub systems are started up. * * \param rootdev address of root device structure */ @@ -116,41 +117,44 @@ //#endif //if (vfs_mount(0x1,B_PARTITION(rootdev)+2,0x0,0xAA,"sys","rw") != 0x0) { - if (vfs_mount(0x1,0x1,0x0,0xAA,"sys","rw") != 0x0) { + + /* Mount Root */ + if (vfs_mount(0x1,0x2,0x0,0xAA,"sys","rw") != 0x0) { kprintf("Problem Mounting sys Mount Point\n"); } - /* Do our mounting */ - /* - if (vfs_mount(0x0,0x0,0x0,0x0,"sys","rw") != 0x0) { - kprintf("Problem Mounting sys Mount Point\n"); - } - if (vfs_mount(0x0,0x0,0x1,0x0,"tmp","rw") != 0x0) { - kprintf("Problem Mounting tmp Mount Point\n"); - } - */ - /* Initialize the system */ - kprintf("Free Pages: [%i]\n",systemVitals->freePages); + kprintf("Free Pages: [%i]\n",systemVitals->freePages); kprintf("MemoryMap: [0x%X]\n",vmmMemoryMap); kprintf("Starting UbixOS\n"); - - sysTask = kmalloc(0x2000); - if(sysTask == NULL) - kprintf("OS: Unable to allocate memory\n"); - execThread(systemTask, (uInt32)sysTask+0x2000,0x0); + /* Create Stack Space For System Task */ + sysTask = kmalloc(0x2000); + if(sysTask == NULL) + kprintf("OS: Unable to allocate memory\n"); - execFile("sys:/bin/init",0x0,0x0,0x0); /* OS Initializer */ + kprintf("T"); + + /* Execute System Task */ + // Send stack size to app zero there? + memset(sysTask,0x0,0x2000); + execThread(systemTask, (uInt32)sysTask+0x2000,0x0); + + kprintf("P"); + + /* Execute Init Process */ + execFile("sys:/bin/init",0x0,0x0,0x0); /* OS Initializer */ + + kprintf("BOO\n"); // execFile("sys:/bin/login",0x0,0x0,0x1); // execFile("sys:/bin/login",0x0,0x0,0x2); - + irqEnable(0x0); - + while (0x1) asm("hlt"); /* Keep haulting until the scheduler reacts */ - + /* Return to start however we should never get this far */ return(0x0); } diff --git a/src/sys/kernel/elf.c b/src/sys/kernel/elf.c index d15bb0c..f244e37 100644 --- a/src/sys/kernel/elf.c +++ b/src/sys/kernel/elf.c @@ -30,7 +30,9 @@ #include #include #include +#include #include +#include const struct { char *elfTypeName; @@ -118,11 +120,12 @@ elfProgramHeader *programHeader = 0x0; struct file *exec_fd = 0x0; - exec_fd = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); + exec_fd = (struct file *)kmalloc(sizeof(struct file)); + //exec_fd = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); fopen(exec_fd,file,"r"); if (exec_fd == 0x0) return(-1); -kprintf("MOO"); + /* Load the ELF header */ if ((binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader))) == 0x0) K_PANIC("malloc failed!"); @@ -147,7 +150,6 @@ K_PANIC("malloc failed!"); fseek(exec_fd,binaryHeader->ePhoff,0); fread(programHeader,(sizeof(elfProgramHeader)*binaryHeader->ePhnum),1,exec_fd); -kprintf("MEW: [0x%X]",base); for (i = 0x0;i < binaryHeader->ePhnum;i++) { switch (programHeader[i].phType) { case PT_LOAD: @@ -157,8 +159,9 @@ */ for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { /* Make readonly and read/write */ - if (vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + base),PAGE_DEFAULT) == 0x0) + if (vmm_remapPage(vmm_findFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + base),PAGE_DEFAULT) == 0x0) K_PANIC("Error: Remap Page Failed"); + memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x + base),0x0,0x1000); } @@ -168,8 +171,7 @@ if ((programHeader[i].phFlags & 0x2) != 0x2) { for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { - if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x + base,PAGE_PRESENT | PAGE_USER)) != 0x0) - K_PANIC("vmm_setPageAttributes failed"); + vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x + base,PAGE_PRESENT | PAGE_USER); } } if (numsegs == 0x0) diff --git a/src/sys/kernel/endtask.c b/src/sys/kernel/endtask.c index 493fb08..1297e21 100644 --- a/src/sys/kernel/endtask.c +++ b/src/sys/kernel/endtask.c @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002-2004 The UbixOS Project + Copyright (c) 2002-2004, 2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -33,6 +33,7 @@ #include #include #include +#include /************************************************************************ @@ -42,13 +43,14 @@ Notes: -************************************************************************/ +************************************************************************/ void endTask(pidType pid) { //kTask_t *tmpTask = 0x0; /* Don't mess with scheduler structures from outside the scheduler! */ /* Just set status to dead, and let the scheduler clean up itself */ - sched_setStatus(pid,DEAD); + if (sched_setStatus(pid,DEAD) != 0x0) + kpanic("sched_setStatus: Failed\n"); //tmpTask = schedFindTask(pid); //if (sched_deleteTask(pid) != 0x0) // kpanic("sched_deleteTask: Failed\n"); @@ -57,6 +59,8 @@ //tmpTask->state = DEAD; //tmpTask->term->owner = tmpTask->parentPid; + //kprintf("wtf?"); + //return; if (pid == _current->id) while(1) diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 11f0c01..ae58e16 100644 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002-2004 The UbixOS Project + Copyright (c) 2002-2004,2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -63,7 +63,7 @@ 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 @@ -72,7 +72,7 @@ kTask_t * newProcess = 0x0; /* Find A New Thread */ newProcess = schedNewTask(); - assert(newProcess); + assert(newProcess); if (stack < 0x100000) kpanic("exec: stack not in valid area: [0x%X]\n",stack); @@ -113,7 +113,7 @@ newProcess->tss.trace_bitmap = 0x0000; newProcess->tss.io_map = 0x8000; newProcess->oInfo.vmStart = 0x6400000; - + newProcess->imageFd = 0x0; /* Set up default stack for thread here filled with arg list 3 times */ @@ -158,15 +158,16 @@ *****************************************************************************************/ void execFile(char *file,int argc,char **argv,int console) { - int i = 0x0; - int x = 0x0; - u_int32_t *tmp = 0x0; + int i = 0x0; + int x = 0x0; + u_int32_t *tmp = 0x0; struct file *tmpFd = 0x0; elfHeader *binaryHeader = 0x0; elfProgramHeader *programHeader = 0x0; /* Get A New Task For This Proccess */ + kprintf("execFile: %s",file); _current = schedNewTask(); assert(_current); _current->gid = 0x0; @@ -190,6 +191,8 @@ /* Lets Find The File */ tmpFd = (struct file *)kmalloc(sizeof(struct file)); + //KUBU + memset(tmpFd,0x0,sizeof(struct file)); fopen(tmpFd,file,"r"); /* If We Dont Find the File Return */ @@ -207,10 +210,12 @@ /* Load ELF Header */ binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader)); - //kprintf(">a:%i:0x%X:0x%X<",sizeof(elfHeader),binaryHeader,tmpFd); fread(binaryHeader,sizeof(elfHeader),1,tmpFd); + //UBU + kprintf("2"); + /* Check If App Is A Real Application */ if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { @@ -239,6 +244,7 @@ //kprintf(">c:%i:0x%X:0x%X<",sizeof(elfProgramHeader)*binaryHeader->ePhnum,programHeader,tmpFd); fread(programHeader,(sizeof(elfProgramHeader)*binaryHeader->ePhnum),1,tmpFd); //kprintf(">d<"); + kprintf("1"); /* Loop Through The Header And Load Sections Which Need To Be Loaded */ for (i=0;iePhnum;i++) { @@ -249,13 +255,13 @@ */ for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { /* Make readonly and read/write !!! */ - if (vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x),PAGE_DEFAULT) == 0x0) + if (vmm_remapPage(vmm_findFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x),PAGE_DEFAULT) == 0x0) K_PANIC("Remap Page Failed"); memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); } _current->oInfo.vmStart = 0x80000000; - _current->td.vm_daddr = (char *)(programHeader[i].phVaddr & 0xFFFFF000); + _current->td.vm_daddr = (programHeader[i].phVaddr & 0xFFFFF000); /* Now Load Section To Memory */ fseek(tmpFd,programHeader[i].phOffset,0); fread((void *)programHeader[i].phVaddr,programHeader[i].phFilesz,1,tmpFd); @@ -264,8 +270,7 @@ kprintf("pH: [0x%X]\n",programHeader[i].phMemsz); #endif for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { - if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x,PAGE_PRESENT | PAGE_USER)) != 0x0) - kpanic("Error: vmm_setPageAttributes failed, File: %s, Line: %i\n",__FILE__,__LINE__); + vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x,PAGE_PRESENT | PAGE_USER); } } } @@ -273,16 +278,16 @@ /* Set Virtual Memory Start */ _current->oInfo.vmStart = 0x80000000; - _current->td.vm_daddr = (char *)(programHeader[i].phVaddr & 0xFFFFF000); + _current->td.vm_daddr = (programHeader[i].phVaddr & 0xFFFFF000); /* Set Up Stack Space */ for (x = 1;x < 100;x++) { - vmm_remapPage(vmmFindFreePage(_current->id),STACK_ADDR - (x * 0x1000),PAGE_DEFAULT | PAGE_STACK); + vmm_remapPage(vmm_findFreePage(_current->id),STACK_ADDR - (x * 0x1000),PAGE_DEFAULT | PAGE_STACK); } /* Kernel Stack 0x2000 bytes long */ - vmm_remapPage(vmmFindFreePage(_current->id),0x5BC000,KERNEL_PAGE_DEFAULT | PAGE_STACK); - vmm_remapPage(vmmFindFreePage(_current->id),0x5BB000,KERNEL_PAGE_DEFAULT | PAGE_STACK); + vmm_remapPage(vmm_findFreePage(_current->id),0x5BC000,KERNEL_PAGE_DEFAULT | PAGE_STACK); + vmm_remapPage(vmm_findFreePage(_current->id),0x5BB000,KERNEL_PAGE_DEFAULT | PAGE_STACK); /* Set All The Proper Information For The Task */ _current->tss.back_link = 0x0; @@ -372,33 +377,39 @@ elfDynamic *elfDynamicS = 0x0; struct i386_frame *iFrame = 0x0; - kprint("Sys EXEC\n"); /* Need to rewrite this routine? */ - tmpFd = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); + tmpFd = (struct file *)kmalloc(sizeof(struct file)); if (fopen(tmpFd,file,"r") == 0x0) { //kprintf("[0x%X]\n",tmpFd); //kfree(tmpFd); //We need this but it's being done in fopen right now - return(0x0); + //UBU WHY? + kpanic("WTF!"); + return; _current->imageFd = 0x0; } + + kprintf("Sys EXEC: %i 0x%X 0x%X\n",tmpFd->size,ap,ep); + + /* Set tasks FD for binary */ _current->imageFd = tmpFd; - /* If We Dont Find the File Return */ - if (tmpFd == 0x0) { - return; - } + if (tmpFd->perms == 0) { kprintf("Exec Format Error: Binary File Not Executable.\n"); fclose(tmpFd); return; } + + /* FIX - Putting In Extra Sanity Checks While Kernel Is Buggy */ + /* Load ELF Header */ + if ((binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader))) == 0x0) + K_PANIC("kmalloc: Filed to allocate for elfHeader"); - if ((binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader))) == 0x0) - endTask(_current->id); + if (fread(binaryHeader,sizeof(elfHeader),1,tmpFd) != sizeof(elfHeader)) + K_PANIC("fread: Read more then specified\n"); - fread(binaryHeader,sizeof(elfHeader),1,tmpFd); /* Set sectionHeader To Point To Loaded Binary To We Can Gather Info */ /* Check If App Is A Real Application */ @@ -406,7 +417,6 @@ kprintf("Exec Format Error: Binary File Not Executable.\n"); kfree(binaryHeader); fclose(tmpFd); - return; } else if (binaryHeader->eType != 2) { @@ -424,44 +434,51 @@ /* Load The Program Header(s) */ if ((programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum)) == 0x0) - endTask(_current->id); + K_PANIC("kmalloc: failed to allocate memory"); assert(programHeader); fseek(tmpFd,binaryHeader->ePhoff,0); - fread(programHeader,(sizeof(elfProgramHeader)*binaryHeader->ePhnum),1,tmpFd); + if (fread(programHeader,(sizeof(elfProgramHeader)*binaryHeader->ePhnum),1,tmpFd) != (sizeof(elfProgramHeader)*binaryHeader->ePhnum)) + K_PANIC("fread: Read more than specified"); if ((sectionHeader = (elfSectionHeader *)kmalloc(sizeof(elfSectionHeader)*binaryHeader->eShnum)) == 0x0) - endTask(_current->id); + K_PANIC("kmalloc: failed to allocate memory"); assert(sectionHeader); fseek(tmpFd,binaryHeader->eShoff,0); - fread(sectionHeader,sizeof(elfSectionHeader)*binaryHeader->eShnum,1,tmpFd); + if (fread(sectionHeader,sizeof(elfSectionHeader)*binaryHeader->eShnum,1,tmpFd) != (sizeof(elfSectionHeader)*binaryHeader->eShnum)) + K_PANIC("fread: read more than specified"); + kprintf("This Loop SegFaults HERE: [%i]\n",binaryHeader->ePhnum); /* Loop Through The Header And Load Sections Which Need To Be Loaded */ for (i=0;iePhnum;i++) { + kprintf("phType: 0x%X, PT_LOAD: 0x%X\n",programHeader[i].phType,PT_LOAD); switch (programHeader[i].phType) { case PT_LOAD: seg_addr = trunc_page(programHeader[i].phVaddr); seg_size = round_page(programHeader[i].phMemsz + programHeader[i].phVaddr - seg_addr); + kprintf("seg_addr: 0x%X, seg_size: 0x%X\n",seg_addr,seg_size); /* Allocate Memory Im Going To Have To Make This Load Memory With Correct Settings so it helps us in the future */ - for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { + for (x = 0x0;x < seg_size;x += 0x1000) { /* Make readonly and read/write !!! */ - if (vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x),PAGE_DEFAULT) == 0x0) + if (vmm_remapPage(vmm_findFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x),PAGE_DEFAULT) == 0x0) K_PANIC("Error: Remap Page Failed"); memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); + kprintf("."); } +kprintf("A"); + /* Now Load Section To Memory */ fseek(tmpFd,programHeader[i].phOffset,0); fread((void *)programHeader[i].phVaddr,programHeader[i].phFilesz,1,tmpFd); if ((programHeader[i].phFlags & 0x2) != 0x2) { - for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { - if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x,PAGE_PRESENT | PAGE_USER)) != 0x0) - kpanic("Error: vmm_setPageAttributes failed, File: %s,Line: %i\n",__FILE__,__LINE__); + for (x = 0x0;x < seg_size;x += 0x1000) { + vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x,PAGE_PRESENT | PAGE_USER); } } #ifdef DEBUG @@ -472,7 +489,7 @@ } else { _current->td.vm_dsize = seg_size >> PAGE_SHIFT; - _current->td.vm_daddr = (char *)seg_addr; + _current->td.vm_daddr = seg_addr; } _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0xA900000); @@ -482,11 +499,12 @@ elfDynamicS = (elfDynamic *)programHeader[i].phVaddr; fseek(tmpFd,programHeader[i].phOffset,0); fread((void *)programHeader[i].phVaddr,programHeader[i].phFilesz,1,tmpFd); + kprintf(".DYN.\n"); break; case PT_INTERP: interp = (char *)kmalloc(programHeader[i].phFilesz); fseek(tmpFd,programHeader[i].phOffset,0); - fread((void *)interp,programHeader[i].phFilesz,1,tmpFd); + kprintf("R: %i, %i\n",fread((void *)interp,programHeader[i].phFilesz,1,tmpFd),programHeader[i].phFilesz); #ifdef LD_DEBUG kprintf("Interp: [%s]\n",interp); #endif @@ -497,6 +515,7 @@ } } + kprintf("What is this doing?\n"); /* What is this doing? 11/23/06 */ if (elfDynamicS != 0x0) { for (i=0;i<12;i++) { @@ -517,17 +536,18 @@ } _current->td.vm_dsize = seg_size >> PAGE_SHIFT; - _current->td.vm_daddr = (char *)seg_addr; + _current->td.vm_daddr = seg_addr; kprintf("STATING: [0x%X][0x%X]\n",_current->td.vm_dsize,_current->td.vm_daddr); - argv = ap; - envp = ep; + argv = (char **)ap; + envp = (char **)ep; if ((ep != 0x0) && (envp[0] != 0x0)) kprintf("ENV SIZE: [0x%X]\n",envp[0]); if (argv[1] != 0x0) { - argc = argv[0]; + //UBU + argc = (int)argv[0]; args = (char *)vmmGetFreeVirtualPage(_current->id,1,VM_TASK); //! do we need this? memset(args,0x0,0x1000); @@ -544,11 +564,14 @@ } //! Clean the virtual of COW pages left over from the fork - vmm_cleanVirtualSpace(_current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SIZE)); + + //QUESTION Why did I feel a need to add vm_dsize to vm_daddr + kprintf("First: 0x%X, 0x%X\n",_current->td.vm_dsize,_current->td.vm_daddr); + vmm_cleanVirtualSpace((u_int32_t)_current->td.vm_daddr);// + (_current->td.vm_dsize << PAGE_SIZE)); //! Adjust iframe - iFrame = _current->tss.esp0 - sizeof(struct i386_frame); + iFrame = (struct i386_frame *)(_current->tss.esp0 - sizeof(struct i386_frame)); iFrame->ebp = STACK_ADDR; iFrame->eip = binaryHeader->eEntry; iFrame->user_esp = STACK_ADDR - 12; @@ -556,12 +579,12 @@ //if (_current->id > 3) { iFrame->user_esp = ((u_int32_t)STACK_ADDR) - (sizeof(u_int32_t) * (argc + 3)); - tmp = iFrame->user_esp; + tmp = (u_int32_t *)iFrame->user_esp; //! build argc and argv[] tmp[0] = argc; for (i = 0;i < argc;i++) { - tmp[i + 1] = argv[i]; + tmp[i + 1] = (u_int32_t)argv[i]; } tmp[argc + 1] = 0x0; tmp[argc + 2] = 0x1; @@ -584,7 +607,7 @@ * \brief New exec... * */ -int sys_exec(char *file,char *ap) { +void sys_exec(char *file,char *ap) { int i = 0x0; int x = 0x0; int argc = 0x0; @@ -604,13 +627,13 @@ Elf_Auxargs *auxargs = 0x0; - _current->imageFd = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); + _current->imageFd = (struct file *)kmalloc(sizeof(struct file)); fopen(_current->imageFd,file,"r"); if (_current->imageFd == 0x0) - return(-1); + K_PANIC("sys_exec"); /* Load the ELF header */ - if ((binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader))) == 0x0) + if ((binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader))) == 0x0) K_PANIC("malloc failed!"); fread(binaryHeader,sizeof(elfHeader),1,_current->imageFd); @@ -618,7 +641,7 @@ if (((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) || (binaryHeader->eType != ET_EXEC)) { kfree(binaryHeader); fclose(_current->imageFd); - return(-1); + K_PANIC("sys_exec"); } /* Load The Program Header(s) */ @@ -640,7 +663,7 @@ */ for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { /* Make readonly and read/write !!! */ - if (vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x),PAGE_DEFAULT) == 0x0) + if (vmm_remapPage(vmm_findFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x),PAGE_DEFAULT) == 0x0) K_PANIC("Error: Remap Page Failed"); memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); } @@ -650,8 +673,7 @@ fread((void *)programHeader[i].phVaddr,programHeader[i].phFilesz,1,_current->imageFd); if ((programHeader[i].phFlags & 0x2) != 0x2) { for (x = 0x0;x < (programHeader[i].phMemsz);x += 0x1000) { - if ((vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x,PAGE_PRESENT | PAGE_USER)) != 0x0) - K_PANIC("vmm_setPageAttributes failed"); + vmm_setPageAttributes((programHeader[i].phVaddr & 0xFFFFF000) + x,PAGE_PRESENT | PAGE_USER); } } if (binaryHeader->eEntry >= programHeader[i].phVaddr && binaryHeader->eEntry < (programHeader[i].phVaddr + programHeader[i].phMemsz)) { @@ -659,7 +681,7 @@ } else { _current->td.vm_dsize = seg_size >> PAGE_SHIFT; - _current->td.vm_daddr = (char *)seg_addr; + _current->td.vm_daddr = seg_addr; } _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0xA900000); @@ -677,7 +699,8 @@ //ldAddr = ldEnable(); break; case PT_PHDR: - proghdr = programHeader[i].phVaddr; + proghdr = programHeader[i].phVaddr; + kprintf("proghdr: 0x%X\n",proghdr); break; default: break; @@ -694,7 +717,7 @@ //kprintf("[0x%X][0x%X]\n",eip,addr); _current->td.vm_dsize = seg_size >> PAGE_SHIFT; - _current->td.vm_daddr = (char *)seg_addr; + _current->td.vm_daddr = seg_addr; //! copy in arg strings argv = (char **)ap; @@ -714,7 +737,10 @@ } //! Clean the virtual of COW pages left over from the fork - vmm_cleanVirtualSpace(_current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SIZE)); + + //QUESTION Why did I add dsize to daddr? + kprintf("Second: 0x%X, 0x%X\n",_current->td.vm_dsize,_current->td.vm_daddr); + vmm_cleanVirtualSpace((u_int32_t)_current->td.vm_daddr);// + (_current->td.vm_dsize << PAGE_SIZE)); //! Adjust iframe @@ -775,8 +801,6 @@ #ifdef DEBUG kprintf("AT_BASE: [0x%X]\n",auxargs->base); #endif - - return(0); } /*** diff --git a/src/sys/kernel/kern_descrip.c b/src/sys/kernel/kern_descrip.c index e0815fc..16cbded 100644 --- a/src/sys/kernel/kern_descrip.c +++ b/src/sys/kernel/kern_descrip.c @@ -35,6 +35,7 @@ #include #include #include +#include int fcntl(struct thread *td, struct fcntl_args *uap) { struct file *fp = 0x0; @@ -191,7 +192,7 @@ if (uap->fd == 1) { switch (uap->com) { case 0x40087468: - tmpShort = uap->data; + tmpShort = (short *)uap->data; tmpShort[0] = 0x25; tmpShort[1] = 0x9B; tmpShort[2] = 0x0; diff --git a/src/sys/kernel/kern_sysctl.c b/src/sys/kernel/kern_sysctl.c index a99f0d6..3369593 100644 --- a/src/sys/kernel/kern_sysctl.c +++ b/src/sys/kernel/kern_sysctl.c @@ -138,7 +138,7 @@ tmpCtl->children = 0x0; sprintf(tmpCtl->name,"p1003_1b"); - tmpCtl->next = (struct sysctl_enctry *)kmalloc(sizeof(struct sysctl_entry)); + tmpCtl->next = (struct sysctl_entry *)kmalloc(sizeof(struct sysctl_entry)); tmpCtl->next->prev = tmpCtl; tmpCtl = tmpCtl->next; tmpCtl->id = CTL_UBIX; diff --git a/src/sys/kernel/ld.c b/src/sys/kernel/ld.c index 2d7825c..3fc2147 100644 --- a/src/sys/kernel/ld.c +++ b/src/sys/kernel/ld.c @@ -48,7 +48,7 @@ char *shStr = 0x0; char *dynStr = 0x0; uInt32 *reMap = 0x0; - fileDescriptor *ldFd = 0x0; + struct file *ldFd = 0x0; elfHeader *binaryHeader = 0x0; elfProgramHeader *programHeader = 0x0; elfSectionHeader *sectionHeader = 0x0; @@ -56,12 +56,14 @@ elfPltInfo *elfRel = 0x0; /* Open our dynamic linker */ - ldFd = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); + ldFd = (struct file *)kmalloc(sizeof(struct file)); fopen(ldFd,"sys:/lib/ld.so","rb"); + if (ldFd == 0x0) { kprintf("Can not open ld.so\n"); } + #ifdef LD_DEBUG kprintf("Loading LD\n"); #endif @@ -81,21 +83,28 @@ fseek(ldFd,binaryHeader->eShoff,0); fread(sectionHeader,sizeof(elfSectionHeader),binaryHeader->eShnum,ldFd); + shStr = (char *)kmalloc(sectionHeader[binaryHeader->eShstrndx].shSize); fseek(ldFd,sectionHeader[binaryHeader->eShstrndx].shOffset,0); fread(shStr,sectionHeader[binaryHeader->eShstrndx].shSize,1,ldFd); + for (i = 0x0;i < binaryHeader->ePhnum;i++) { + //kprintf("LD.phType: %i\n",programHeader[i].phType); switch (programHeader[i].phType) { case PT_LOAD: newLoc = (char *)programHeader[i].phVaddr + LD_START; + //kprintf("LD.newLoc: 0x%X\n",newLoc); /* Allocate Memory Im Going To Have To Make This Load Memory With Correct Settings so it helps us in the future */ + //kprintf("LD.phMemsz: 0x%X\n",programHeader[i].phMemsz); for (x=0;x < (programHeader[i].phMemsz);x += 0x1000) { /* make r/w or ro */ - if ((vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),PAGE_DEFAULT)) == 0x0) + if (((programHeader[i].phVaddr & 0xFFFFF00) + x + LD_START) > 0xC0000000) + K_PANIC("OVER 4GB"); + if ((vmm_remapPage(vmm_findFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),PAGE_DEFAULT)) == 0x0) K_PANIC("vmmRemapPage: ld"); memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),0x0,0x1000); } @@ -125,6 +134,7 @@ } } + //assert(_current->id != 4); for (i=0x0;ieShnum;i++) { switch (sectionHeader[i].shType) { case 3: diff --git a/src/sys/kernel/sched.c b/src/sys/kernel/sched.c index cbd4c1a..220e493 100644 --- a/src/sys/kernel/sched.c +++ b/src/sys/kernel/sched.c @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002-2004 The UbixOS Project + Copyright (c) 2002-2004, 2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -66,29 +66,35 @@ ************************************************************************/ -int sched_init() { +int sched_init() { taskList = (kTask_t *)kmalloc(sizeof(kTask_t)); if(taskList == 0x0) kpanic("Unable to create task list"); - + taskList->id = nextID++; /* Print out information on scheduler */ kprintf("sched0 - Address: [0x%X]\n", taskList); - + /* Return so we know everything went well */ - return(0x0); + return(0x0); } +/* + * + * + * Notes + * 06/29/2009 - Problems? + */ void sched(){ - uInt32 memAddr = 0x0; - kTask_t *tmpTask = 0x0; - kTask_t *delTask = 0x0; - + uInt32 memAddr = 0x0; + kTask_t *tmpTask = 0x0; + kTask_t *delTask = 0x0; + if (!spinTryLock(&schedulerSpinLock)) - return; - + return; + tmpTask = _current->next; //outportByte(0xE9,_current->id + '0'); schedStart: @@ -101,8 +107,8 @@ _current->state = READY; break; } - else if (tmpTask->state == DEAD) - { + else if (tmpTask->state == DEAD) { + kprintf("WTF"); delTask = tmpTask; tmpTask = tmpTask->next; sched_deleteTask(delTask->id); @@ -116,8 +122,8 @@ tmpTask = taskList; goto schedStart; } - - + + if (_current->state > 0x0) { if (_current->oInfo.v86Task == 0x1) irqDisable(0x0); @@ -135,7 +141,7 @@ { spinUnlock(&schedulerSpinLock); } - + return; } @@ -147,7 +153,7 @@ if (tmpTask == 0x0) kpanic("Error: schedNewTask() - kmalloc failed trying to initialize a new task struct\n"); - memset(tmpTask,0x0,sizeof(kTask_t)); + memset(tmpTask,0x0,sizeof(kTask_t)); /* Filling in tasks attrs */ tmpTask->usedMath = 0x0; tmpTask->state = NEW; @@ -167,13 +173,13 @@ taskList = tmpTask; spinUnlock(&schedulerSpinLock); - + return(tmpTask); } int sched_deleteTask(pidType id) { - kTask_t *tmpTask = 0x0; + kTask_t *tmpTask = 0x0; /* Checking each task from the prio queue */ for (tmpTask = taskList; tmpTask != 0x0; tmpTask = tmpTask->next) { @@ -184,13 +190,13 @@ tmpTask->next->prev = tmpTask->prev; if (taskList == tmpTask) taskList = tmpTask->next; - + return(0x0); } } return(0x1); } - + int sched_addDelTask(kTask_t *tmpTask) { tmpTask->next = delList; tmpTask->prev = 0x0; @@ -199,23 +205,23 @@ delList = tmpTask; return(0x0); } - + kTask_t *sched_getDelTask() { kTask_t *tmpTask = 0x0; - + if (delList == 0x0) return(0x0); - + tmpTask = delList; delList = delList->next; return(tmpTask); } -kTask_t * -schedFindTask(uInt32 id) +kTask_t * +schedFindTask(uInt32 id) { - kTask_t *tmpTask = 0x0; + kTask_t *tmpTask = 0x0; for (tmpTask = taskList; tmpTask; tmpTask = tmpTask->next) { if (tmpTask->id == id) @@ -237,7 +243,7 @@ 02/20/2004 - Approved for quality ************************************************************************/ -void +void schedEndTask(pidType pid) { endTask(_current->id); sched_yield(); @@ -247,7 +253,7 @@ Function: int schedEndTask() -Description: This function will yield a task +Description: This function will yield a task Notes: @@ -255,7 +261,7 @@ ************************************************************************/ -void +void sched_yield() { sched(); } diff --git a/src/sys/kernel/systemtask.c b/src/sys/kernel/systemtask.c index c647742..ba1a6f9 100644 --- a/src/sys/kernel/systemtask.c +++ b/src/sys/kernel/systemtask.c @@ -77,10 +77,11 @@ break; case 31337: kprintf("system: backdoor opened\n"); - break; + break; case 0x80: if (!strcmp(myMsg.data,"sdeStart")) { - kprintf("Starting SDE\n"); + + kprintf("Starting SDE\n"); //execThread(sdeThread,(uInt32)(kmalloc(0x2000)+0x2000),0x0); } else if (!strcmp(myMsg.data,"freePage")) { @@ -99,9 +100,9 @@ } /* - Here we get the next task from the delete task queue - we first check to see if it has an fd attached for the binary and after that - we free the pages for the process and then free the task + Here we get the next task from the delete task queue + we first check to see if it has an fd attached for the binary and after that + we free the pages for the process and then free the task */ tmpTask = sched_getDelTask(); if (tmpTask != 0x0) { @@ -109,7 +110,7 @@ kprintf("Closing: [0x%X]\n",tmpTask->imageFd); fclose(tmpTask->imageFd); } - vmmFreeProcessPages(tmpTask->id); + vmm_freeProcessPages(tmpTask->id); kfree(tmpTask); } videoBuffer[0] = systemVitals->sysTicks; @@ -122,4 +123,3 @@ /*** END ***/ - diff --git a/src/sys/kernel/time.c b/src/sys/kernel/time.c index 2e76b04..82ee67e 100644 --- a/src/sys/kernel/time.c +++ b/src/sys/kernel/time.c @@ -34,19 +34,19 @@ #include static int month[12] = { - 0, - DAY*(31), - DAY*(31+29), - DAY*(31+29+31), - DAY*(31+29+31+30), - DAY*(31+29+31+30+31), - DAY*(31+29+31+30+31+30), - DAY*(31+29+31+30+31+30+31), - DAY*(31+29+31+30+31+30+31+31), - DAY*(31+29+31+30+31+30+31+31+30), - DAY*(31+29+31+30+31+30+31+31+30+31), - DAY*(31+29+31+30+31+30+31+31+30+31+30) -}; + 0, + DAY*(31), + DAY*(31+29), + DAY*(31+29+31), + DAY*(31+29+31+30), + DAY*(31+29+31+30+31), + DAY*(31+29+31+30+31+30), + DAY*(31+29+31+30+31+30+31), + DAY*(31+29+31+30+31+30+31+31), + DAY*(31+29+31+30+31+30+31+31+30), + DAY*(31+29+31+30+31+30+31+31+30+31), + DAY*(31+29+31+30+31+30+31+31+30+31+30) + }; static int timeCmosRead(int addr) { outportByteP(0x70,addr); @@ -56,7 +56,7 @@ int time_init() { int i; struct timeStruct time; - + for (i = 0 ; i < 1000000 ; i++) { if (!(timeCmosRead(10) & 0x80)) { break; @@ -84,7 +84,7 @@ kprintf("%i/%i/%i %i:%i.%i\n",time.mon,time.day,time.year,time.hour,time.min,time.sec); - + /* Return so we know all went well */ return(0x0); } diff --git a/src/sys/kernel/tty.c b/src/sys/kernel/tty.c index 7470c34..7814fab 100644 --- a/src/sys/kernel/tty.c +++ b/src/sys/kernel/tty.c @@ -35,8 +35,8 @@ #include #include -static tty_term *terms = 0x0; -tty_term *tty_foreground = 0x0; +static tty_term *terms = 0x0; +tty_term *tty_foreground = 0x0; static spinLock_t tty_spinLock = SPIN_LOCK_INITIALIZER; int tty_init() { @@ -98,7 +98,7 @@ memcpy((char *)0xB8000,terms[tty].tty_buffer,(80*60*2)); /* - Set the tty_pointer to the internal buffer so I can continue + Set the tty_pointer to the internal buffer so I can continue writing to what it believes is the screen */ tty_foreground->tty_pointer = tty_foreground->tty_buffer; diff --git a/src/sys/kernel/ubthread.c b/src/sys/kernel/ubthread.c index 8908075..86e2d09 100644 --- a/src/sys/kernel/ubthread.c +++ b/src/sys/kernel/ubthread.c @@ -45,7 +45,7 @@ return(_current); } -int ubthread_cond_init(ubthread_cond_t *cond,const uInt32 attr) { +int ubthread_cond_init(ubthread_cond_t *cond,const uInt32 attr) { ubthread_cond_t ubcond = kmalloc(sizeof(struct ubthread_cond)); ubcond->id = (int)cond; ubcond->locked = UNLOCKED; @@ -53,7 +53,7 @@ return(0x0); } -int ubthread_mutex_init(ubthread_mutex_t *mutex,const uInt32 attr) { +int ubthread_mutex_init(ubthread_mutex_t *mutex,const uInt32 attr) { ubthread_mutex_t ubmutex = kmalloc(sizeof(struct ubthread_mutex)); ubmutex->id = (int)mutex; ubmutex->locked = UNLOCKED; @@ -131,4 +131,3 @@ /*** END ***/ - diff --git a/src/sys/kernel/vitals.c b/src/sys/kernel/vitals.c index fc6a3c5..0d592c9 100644 --- a/src/sys/kernel/vitals.c +++ b/src/sys/kernel/vitals.c @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002-2004 The UbixOS Project + Copyright (c) 2002-2004,2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -46,29 +46,27 @@ ************************************************************************/ int vitals_init() { - /* Initialize Memory For The System Vitals Node */ - systemVitals = (vitalsNode *) kmalloc(sizeof(vitalsNode)); + /* Initialize Memory For The System Vitals Node */ + systemVitals = (vitalsNode *) kmalloc(sizeof(vitalsNode)); - /* If malloc Failed Then Error */ - if (systemVitals == 0x0) - { - kpanic("Error: kmalloc Failed In initVitals\n"); - } + /* If malloc Failed Then Error */ + if (systemVitals == 0x0) { + kpanic("Error: kmalloc Failed In initVitals\n"); + } - /* Set all default values */ - memset(systemVitals,0x0,sizeof(vitalsNode)); - - systemVitals->quantum = 8; - systemVitals->dQuantum = 8; + /* Set all default values */ + memset(systemVitals,0x0,sizeof(vitalsNode)); - /* Print Out Info For Vitals: */ - kprintf("vitals0 - Address: [0x%X]\n",systemVitals); + systemVitals->quantum = 8; + systemVitals->dQuantum = 8; - /* Return so kernel knows that there is no problem */ - return(0x0); -} + /* Print Out Info For Vitals: */ + kprintf("vitals0 - Address: [0x%X]\n",systemVitals); + + /* Return so kernel knows that there is no problem */ + return(0x0); + } /*** END ***/ - diff --git a/src/sys/lib/kmalloc.c b/src/sys/lib/kmalloc.c index 77cabd2..bbe5f46 100644 --- a/src/sys/lib/kmalloc.c +++ b/src/sys/lib/kmalloc.c @@ -295,6 +295,8 @@ spinUnlock(&mallocSpinLock); //kprintf("m1[%i:%i:0x%X]",tmpDesc1->limit,len,tmpDesc1->baseAddr); assert(tmpDesc1->baseAddr); + //UBU + memset(tmpDesc1->baseAddr,0x0,len); return(tmpDesc1->baseAddr); } } @@ -330,6 +332,8 @@ //kprintf("baseAddr2[0x%X:0x%X]",tmpDesc1,tmpDesc1->baseAddr); //kprintf("m2[%i:%i:0x%X]",tmpDesc1->limit,len,tmpDesc1->baseAddr); assert(tmpDesc1->baseAddr); + //UBU + memset(tmpDesc1->baseAddr,0x0,len); return(tmpDesc1->baseAddr); } //Return Null If Unable To Malloc @@ -392,6 +396,9 @@ /*** $Log$ + Revision 1.3 2009/02/14 02:03:24 reddawg + Fixed up vmm_getFreeKernelPage + Revision 1.2 2007/06/29 11:31:47 reddawg Cleaning diff --git a/src/sys/pci/hd.c b/src/sys/pci/hd.c index 151adfd..8809376 100644 --- a/src/sys/pci/hd.c +++ b/src/sys/pci/hd.c @@ -1,5 +1,5 @@ /***************************************************************************************** - Copyright (c) 2002-2004 The UbixOS Project + Copyright (c) 2002-2004,2009 The UbixOS Project All rights reserved. Redistribution and use in source and binary forms, with or without modification, are @@ -35,7 +35,7 @@ #include #include #include - + int initHardDisk() { int i = 0x0; int x = 0x0; @@ -49,8 +49,8 @@ char *data2 = 0x0; char name[16]; struct bsd_disklabel *bsdd = 0x0; - - hdd = (struct driveInfo *)kmalloc(sizeof(struct driveInfo)); + + hdd = (struct driveInfo *)kmalloc(sizeof(struct driveInfo)); hdd->hdPort = 0x1F0; hdd->hdDev = 0x40; hdd->parOffset = 0x0; @@ -67,9 +67,9 @@ devInfo->start = (void *)&hdStart; devInfo->standby = (void *)&hdStandby; devInfo->info = hdd; - + devInfo->major = 0x1; - + data = (char *)kmalloc(512); d = (struct dos_partition *)(data + 0x1BE); @@ -81,7 +81,7 @@ devfs_makeNode("ad0",'b',0x1,0x0); hdRead(devInfo->info,data,0x0,0x1); for (i = 0x0;i < 0x4;i++) { - if (d[i].dp_type != 0x0) { + if (d[i].dp_type != 0x0) { devInfo2 = (struct device_interface *)kmalloc(sizeof(struct device_interface)); hdd2 = (struct driveInfo *)kmalloc(sizeof(struct driveInfo)); memcpy(devInfo2,devInfo,sizeof(struct device_interface)); @@ -89,6 +89,7 @@ hdd2->parOffset = d[i].dp_start; devInfo2->info = hdd2; minor++; + if (device_add(minor,'c',devInfo2) == 0x0) { sprintf(name,"ad0s%i",i + 1); kprintf("%s - Type: [0x%X], Start: [0x%X], Size: [0x%X]\n",name,d[i].dp_type,d[i].dp_start,d[i].dp_size); @@ -108,6 +109,7 @@ hdd2->parOffset = bsdd->d_partitions[x].p_offset; devInfo2->info = hdd2; minor++; + device_add(minor,'c',devInfo2); devfs_makeNode(name,'c',0x1,minor); kprintf("%s - Type: [%s], Start: [0x%X], Size: [0x%X], MM: [%i:%i]\n",name,fstypenames[bsdd->d_partitions[x].p_fstype],bsdd->d_partitions[x].p_offset,bsdd->d_partitions[x].p_size,devInfo->major,minor); @@ -141,7 +143,7 @@ int hdReset() { return(0x0); } - + int hdInit(struct device_node *dev) { char retVal = 0x0; long counter = 0x0; @@ -282,16 +284,18 @@ } void hdRead(struct driveInfo *hdd,void *baseAddr,uInt32 startSector,uInt32 sectorCount) { - long counter = 0x0; - long retVal = 0x0; + long counter = 0x0; + long retVal = 0x0; short transactionCount = 0x0; - short *tmp = (short *)baseAddr; + short *tmp = (short *)baseAddr; + startSector += hdd->parOffset; if (hdd->hdEnable == 0x0) { kprintf("Invalid Drive\n"); return; } + if ((sectorCount >> hdd->hdShift) == 0x0) { hdd->hdCalc = sectorCount; /* hdd->hdMask); */ transactionCount = 1; @@ -300,11 +304,14 @@ hdd->hdCalc = hdd->hdMulti; transactionCount = sectorCount >> hdd->hdShift; } + for (;transactionCount > 0;transactionCount--) { for (counter = 1000000;counter >= 0;counter--) { - retVal = inportByte(hdd->hdPort + hdStat) & 0x80; - if (!retVal) goto ready; + retVal = inportByte(hdd->hdPort + hdStat) & 0x80; + if (!retVal) + goto ready; } + kprintf("Time Out Waiting On Drive\n"); return; ready: @@ -317,22 +324,25 @@ retVal >>= 8; retVal &= 0x0F; retVal |= (hdd->hdDev | 0xA0); //Test as per TJ - //retVal |= hdd->hdDev; //retVal |= (hdd->hdDev | 0xA0); //Test as per TJ outportByte(hdd->hdPort + hdHead,(retVal & 0xFF)); + if (hdd->hdShift > 0) outportByte(hdd->hdPort + hdCmd,0xC4); - else + else outportByte(hdd->hdPort + hdCmd,0x20); + for (counter = 1000000;counter >= 0;counter--) { retVal = inportByte(hdd->hdPort + hdStat); + if ((retVal & 1) != 0x0) { - kprintf("HD Read Error: [%i:0x%X:%i]\n",counter,(uInt32)baseAddr,startSector); + kprintf("HD Read Error: [%i:0x%X:%i(0x%X):0x%X]\n",counter,(uInt32)baseAddr,startSector,startSector,retVal); return; } if ((retVal & 8) != 0x0) { goto go; } } + kprintf("Error: Time Out Waiting On Drive\n"); return; go: @@ -343,10 +353,13 @@ startSector += hdd->hdCalc; } return; - } + } /*** $Log$ + Revision 1.2 2008/02/29 14:56:31 reddawg + Sync - Working On Getting It To Boot Again + Revision 1.1.1.1 2007/01/17 03:31:55 reddawg UbixOS diff --git a/src/sys/sys/device.c b/src/sys/sys/device.c index 06cf2d6..bf443d8 100644 --- a/src/sys/sys/device.c +++ b/src/sys/sys/device.c @@ -31,6 +31,7 @@ #include #include #include +#include #include /* Linked list of drivers loaded in the system accessable by the subsystem only */ @@ -87,7 +88,7 @@ struct device_node *tmpDev = 0x0; if (major == -1) - return(-1); + kprintf("major == -1"); spinLock(&deviceSpinLock); diff --git a/src/sys/ufs/ufs.c b/src/sys/ufs/ufs.c index 3b98fdc..532a52f 100644 --- a/src/sys/ufs/ufs.c +++ b/src/sys/ufs/ufs.c @@ -306,7 +306,7 @@ return(-1); } - /* Quick Hack for file size */ + /* FIX - Quick Hack for file size */ fsread(ufsObj->ino,&tmp,1,fd); fd->offset = 0; /* Return */ @@ -345,7 +345,8 @@ } static int ufs_dummy() { - kprintf("Dummy Func\n"); + K_PANIC("Dummy Func\n"); + return(0x0); } int ufs_init() { diff --git a/src/sys/vfs/file.c b/src/sys/vfs/file.c index 9f86297..c3808fd 100644 --- a/src/sys/vfs/file.c +++ b/src/sys/vfs/file.c @@ -122,7 +122,7 @@ void sysFopen(const char *file,char *flags,userFileDescriptor *userFd) { if (userFd == NULL) kprintf("Error: userFd == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); - userFd->fd = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); + userFd->fd = (struct file *)kmalloc(sizeof(struct file)); fopen(userFd->fd,file,flags); if (userFd->fd != 0x0) { userFd->fdSize = userFd->fd->size; @@ -263,10 +263,11 @@ /************************************************************************ -Function: fileDescriptor *fopen(const char *file,cont char *flags) +Function: struct file *fopen(const char *file,cont char *flags) Description: This Will Open A File And Return A File Descriptor Notes: +06/30/09 - Changed to struct file 08/05/02 - Just Started A Rewrite Of This Function Should Work Out Well ************************************************************************/ @@ -306,6 +307,7 @@ else tmpFd->mp = vfs_findMount(mountPoint); + if (tmpFd->mp == 0x0) { kprintf("Mount Point Bad\n"); return(0x0); @@ -340,7 +342,6 @@ if (tmpFd->mp->fs->vfsOpenFile(tmpFd->path,tmpFd) == 0x1) { /* If The File Is Found Then Set Up The Descriptor */ - /* in order to save resources we will allocate the buffer later when it is needed */ tmpFd->buffer = (char *)kmalloc(4096); @@ -380,7 +381,9 @@ return(tmpFd); } else { - kfree(tmpFd->buffer); + kprintf("File Not Found!"); + //Why did we free this we didn't set it? + /* kfree(tmpFd->buffer); */ kfree(tmpFd); //spinUnlock(&fdTable_lock); #ifdef VFSDEBUG @@ -401,12 +404,14 @@ ************************************************************************/ int fclose(struct file *fd) { - struct file *tmpFd = 0x0; + //struct file *tmpFd = 0x0; assert(fd); + assert((u_int32_t)fd->buffer != 0xBEBEBEBE); //BUG FCLOSE BROKEN!! - if ((fd->buffer != 0x0) || (fd->buffer != 0xBEBEBEBE)) + if ((u_int32_t)fd->buffer != 0x0) kfree(fd->buffer); + kfree(fd); //BUG think i'm missing things //K_PANIC("HMM?"); @@ -471,7 +476,7 @@ } //kprintf("rootPath: [%s]\n",rootPath); - tmpFD = (struct fileDescriptorStruct *)kmalloc(sizeof(struct fileDescriptorStruct)); + tmpFD = (struct file *)kmalloc(sizeof(struct file)); fopen(tmpFD,rootPath,"rb"); if (tmpFD->mp == 0x0) { diff --git a/src/sys/vfs/vfs_syscalls.c b/src/sys/vfs/vfs_syscalls.c index 2c53c96..7c3268e 100644 --- a/src/sys/vfs/vfs_syscalls.c +++ b/src/sys/vfs/vfs_syscalls.c @@ -30,7 +30,9 @@ #include #include #include -#include +#include +#include +#include /*! * \brief entry point for lseek syscall @@ -158,7 +160,7 @@ else if (uap->fd == 1) { buffer = kmalloc(uap->nbyte); memcpy(buffer,uap->buf,uap->nbyte); - kprint(buffer); + kprintf("Buffer: 0x%X\n",buffer); kfree(buffer); td->td_retval[0] = uap->nbyte; } diff --git a/src/sys/vmm/getfreekernelpage.c b/src/sys/vmm/getfreekernelpage.c index 037203d..ee076f2 100644 --- a/src/sys/vmm/getfreekernelpage.c +++ b/src/sys/vmm/getfreekernelpage.c @@ -30,6 +30,7 @@ #include #include #include +#include static spinLock_t vmmGFPlock = SPIN_LOCK_INITIALIZER; @@ -78,7 +79,8 @@ for (c = 0; c < count; c++) { if ((vmm_remapPage((u_int32_t) vmm_findFreePage(pid), ((x * (1024 * 4096)) + ((y + c) * 4096)),KERNEL_PAGE_DEFAULT)) == 0x0) K_PANIC("vmmRemapPage failed: gfkp-1\n"); - vmm_clearVirtualPage((u_int32_t) ((x * (1024 * 4096)) + ((y + c) * 4096))); + if (vmm_zeroVirtualPage((u_int32_t) ((x * (1024 * 4096)) + ((y + c) * 4096))) == 0x1) + K_PANIC("vmm_zeroVirtualPage: failed\n"); } spinUnlock(&vmmGFPlock); @@ -91,7 +93,8 @@ K_PANIC("vmmRemapPage failed: gfkp-2\n"); /* Clear This Page So No Garbage Is There */ - vmm_clearVirtualPage((u_int32_t) ((x * (1024 * 4096)) + (y * 4096))); + if (vmm_zeroVirtualPage((u_int32_t) ((x * (1024 * 4096)) + (y * 4096))) == 0x1) + K_PANIC("vmm_zeroVirtualPage: Failed\n"); /* Return The Address Of The Newly Allocate Page */ spinUnlock(&vmmGFPlock); return ((void *)((x * (1024 * 4096)) + (y * 4096))); @@ -108,6 +111,9 @@ /*** $Log$ + Revision 1.2 2009/07/08 16:05:56 reddawg + Sync + END ***/ diff --git a/src/sys/vmm/getphysicaladdr.c b/src/sys/vmm/getphysicaladdr.c index 7ff9337..fc850e9 100644 --- a/src/sys/vmm/getphysicaladdr.c +++ b/src/sys/vmm/getphysicaladdr.c @@ -28,6 +28,7 @@ *****************************************************************************************/ #include +#include /*! @@ -60,6 +61,9 @@ /*** $Log$ + Revision 1.2 2009/07/08 16:05:56 reddawg + Sync + END ***/ diff --git a/src/sys/vmm/pagefault.c b/src/sys/vmm/pagefault.c index e7c8cf2..42c770d 100644 --- a/src/sys/vmm/pagefault.c +++ b/src/sys/vmm/pagefault.c @@ -91,11 +91,11 @@ /* USE vmInfo */ dst = (u_int32_t *) vmmGetFreeVirtualPage(_current->id,1,0x1); /* Copy Memory */ - for (i=0;itss.cr3,0x5A00000,KERNEL_PAGE_DEFAULT) == 0x0) K_PANIC("vmmFailed"); @@ -361,12 +374,14 @@ return(0x0); } -void *vmm_getFreeMallocPage(uInt16 count) { - uInt16 x = 0x0, y = 0x0; - int c = 0x0; +void *vmm_getFreeMallocPage(u_int16_t count) { + int c = 0x0; u_int32_t *pageTableSrc = 0x0; + u_int16_t x = 0x0; + u_int16_t y = 0x0; spinLock(&fkpSpinLock); + /* Lets Search For A Free Page */ for (x = 960; x < 1024; x++) { /* Set Page Table Address */ @@ -388,7 +403,8 @@ if (vmm_remapPage((u_int32_t) vmm_findFreePage(sysID), ((x * 0x400000) + ((y + c) * 0x1000)),KERNEL_PAGE_DEFAULT) == 0x0) K_PANIC("remap Failed"); - vmm_clearVirtualPage((u_int32_t) ((x * 0x400000) + ((y + c) * 0x1000))); + if (vmm_zeroVirtualPage((u_int32_t) ((x * 0x400000) + ((y + c) * 0x1000))) == 0x1) + K_PANIC("vmm_zeroVirtualPage failed"); } spinUnlock(&fkpSpinLock); @@ -401,7 +417,8 @@ K_PANIC("Failed"); /* Clear This Page So No Garbage Is There */ - vmm_clearVirtualPage((u_int32_t) ((x * 0x400000) + (y * 0x1000))); + if (vmm_zeroVirtualPage((u_int32_t) ((x * 0x400000) + (y * 0x1000))) == 0x1) + K_PANIC("vmm_zeroVirtualPage: Failed"); /* Return The Address Of The Newly Allocate Page */ spinUnlock(&fkpSpinLock); return ((void *)((x * 0x400000) + (y * 0x1000))); diff --git a/src/sys/vmm/setpageattributes.c b/src/sys/vmm/setpageattributes.c index c24855d..0995769 100644 --- a/src/sys/vmm/setpageattributes.c +++ b/src/sys/vmm/setpageattributes.c @@ -29,36 +29,39 @@ #include #include +#include /************************************************************************ -Function: void vmmSetPageAttributes(uInt32 pageAddr,int attributes; +Function: void vmmSetPageAttributes(u_int32_t pageAddr,int attributes; Description: This Function Will Set The Page Attributes Such As A Read Only Page, Stack Page, COW Page, ETC. Notes: ************************************************************************/ -int vmm_setPageAttributes(uInt32 memAddr,uInt16 attributes) { - uInt16 directoryIndex = 0x0, tableIndex = 0x0; - uInt32 *pageTable = 0x0; +void vmm_setPageAttributes(u_int32_t memAddr,u_int16_t attributes) { + u_int16_t directoryIndex = 0x0, tableIndex = 0x0; + u_int32_t *pageTable = 0x0; #ifdef VMMDEBUG kprintf("vmm_getPageAttributes"); #endif /* Calculate The Page Directory Index */ - directoryIndex = (memAddr >> 22); + directoryIndex = PDI(memAddr);; /* Calculate The Page Table Index */ - tableIndex = ((memAddr >> 12) & 0x3FF); + tableIndex = PTI(memAddr); /* Set Table Pointer */ - if ((pageTable = (uInt32 *) (PAGE_TABLES_BASE_ADDR + (0x1000 * directoryIndex))) == 0x0) + if ((pageTable = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (0x1000 * directoryIndex))) == 0x0) kpanic("Error: pageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); /* Set Attribute If Page Is Mapped */ if (pageTable[tableIndex] != 0x0) pageTable[tableIndex] = ((pageTable[tableIndex] & 0xFFFFF000) | attributes); + else + kpanic("WTF NON MAPPED"); /* Reload The Page Table; */ asm volatile( @@ -68,11 +71,13 @@ "pop %eax \n" ); /* Return */ - return(0x0); } /*** $Log$ + Revision 1.2 2009/07/08 16:05:56 reddawg + Sync + Revision 1.1.1.1 2007/01/17 03:31:51 reddawg UbixOS diff --git a/src/sys/vmm/vmm_memory.c b/src/sys/vmm/vmm_memory.c index efc6b7d..3767452 100644 --- a/src/sys/vmm/vmm_memory.c +++ b/src/sys/vmm/vmm_memory.c @@ -229,6 +229,7 @@ void vmm_freePage(u_int32_t pageAddr) { int pageIndex = 0x0; assert((pageAddr & 0xFFF) == 0x0); + spinLock(&vmmSpinLock); /* Find The Page Index To The Memory Map */ @@ -241,13 +242,16 @@ vmmMemoryMap[pageIndex].cowCounter = 0x0; vmmMemoryMap[pageIndex].pid = -2; freePages++; + spinUnlock(&vmmSpinLock); systemVitals->freePages = freePages; } else { + /* Prevent Dead Lock */ + spinUnlock(&vmmSpinLock); + /* Adjust The COW Counter */ - adjustCowCounter(((u_int32_t) vmmMemoryMap[pageIndex].pageAddr), -1); + vmm_adjustCowCounter(((u_int32_t) vmmMemoryMap[pageIndex].pageAddr), -1); } - spinUnlock(&vmmSpinLock); } /************************************************************************ @@ -262,10 +266,11 @@ 08/01/02 - I Think If Counter Gets To 0 I Should Free The Page ************************************************************************/ -int adjustCowCounter(u_int32_t baseAddr, int adjustment) { +void vmm_adjustCowCounter(u_int32_t baseAddr, int adjustment) { int vmmMemoryMapIndex = (baseAddr / 4096); assert((baseAddr & 0xFFF) == 0x0); - spinLock(&vmmCowSpinLock); + spinLock(&vmmSpinLock); + /* Adjust COW Counter */ vmmMemoryMap[vmmMemoryMapIndex].cowCounter += adjustment; @@ -276,14 +281,13 @@ freePages++; systemVitals->freePages = freePages; } - spinUnlock(&vmmCowSpinLock); - /* Return */ - return (0); + + spinUnlock(&vmmSpinLock); } /************************************************************************ - Function: void vmmFreeProcessPages(pid_t pid); + Function: void vmm_freeProcessPages(pid_t pid); Description: This Function Will Free Up Memory For The Exiting Process @@ -292,10 +296,12 @@ 08/04/02 - Added Checking For COW Pages First ************************************************************************/ -void vmmFreeProcessPages(pidType pid) { - int i=0,x=0; +void vmm_freeProcessPages(pidType pid) { + int i=0; + int x=0; u_int32_t *tmpPageTable = 0x0; u_int32_t *tmpPageDir = (uInt32 *)PARENT_PAGEDIR_ADDR; + spinLock(&vmmSpinLock); /* Check Page Directory For An Avail Page Table */ for (i=0;i<=0x300;i++) { @@ -303,10 +309,10 @@ /* Set Up Page Table Pointer */ tmpPageTable = (u_int32_t *)(PAGE_TABLES_BASE_ADDR + (i * 0x1000)); /* Check The Page Table For COW Pages */ - for (x=0;xtd.vm_dsize += btoc(count * 0x1000); @@ -207,7 +207,8 @@ kpanic("vmmRemapPage: getFreeVirtualPage-2\n"); /* Clear This Page So No Garbage Is There */ - vmm_clearVirtualPage((u_int32_t) ((x * (1024 * 4096)) + (y * 4096))); + if (vmm_zeroVirtualPage((u_int32_t) ((x * (1024 * 4096)) + (y * 4096))) == 0x1) + K_PANIC("vmm_zeroVirtualPage Failed"); /* Return The Address Of The Newly Allocate Page */ if (type == VM_THRD) { @@ -275,7 +276,7 @@ } pageTableSrc = (u_int32_t *) (PAGE_TABLES_BASE_ADDR + (0x1000 * x)); if (y != 0x0) { - for (y = 0x0;ytd.vm_dsize += btoc(count * 0x1000); @@ -326,7 +328,8 @@ kpanic("vmmRemapPage: getFreeVirtualPage-2\n"); /* Clear This Page So No Garbage Is There */ - vmm_clearVirtualPage((u_int32_t) ((x * (1024 * 4096)) + (y * 4096))); + if (vmm_zeroVirtualPage((u_int32_t) ((x * (1024 * 4096)) + (y * 4096))) == 0x1) + K_PANIC("vmm_zeroVirtualPage Failed"); /* Return The Address Of The Newly Allocate Page */ if (type == VM_THRD) { @@ -383,10 +386,11 @@ newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((u_int32_t) newPageDirectory); /* First Set Up A Flushed Page Directory */ - memset(newPageDirectory,0x0,0x1000); + if (vmm_zeroVirtualPage((u_int32_t)newPageDirectory) == 0x1) + K_PANIC("ZVP: Failed"); /* Map The Top 1GB Region Of The VM Space */ - for (x = 768; x < pageEntries; x++) { + for (x = 768; x < PAGE_ENTRIES; x++) { newPageDirectory[x] = parentPageDirectory[x]; } @@ -405,7 +409,7 @@ kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); /* Set Parent And New Pages To COW */ - for (i = 0; i < pageEntries; i++) { + for (i = 0; i < PAGE_ENTRIES; i++) { /* If Page Is Mapped */ if ((parentPageTable[i] & 0xFFFFF000) != 0x0) { @@ -419,7 +423,7 @@ parentStackPage = (u_int32_t *) (((1024 * 4096) * x) + (4096 * i)); /* Copy The Tack Byte For Byte (I Should Find A Faster Way) */ - for (s = 0x0; s < pageEntries; s++) { + for (s = 0x0; s < PAGE_ENTRIES; s++) { newStackPage[s] = parentStackPage[s]; } /* Insert New Stack Into Page Table */ @@ -432,10 +436,10 @@ newPageTable[i] = (((u_int32_t) parentPageTable[i] & 0xFFFFF000) | (PAGE_DEFAULT | PAGE_COW)); /* Increment The COW Counter For This Page */ if (((u_int32_t) parentPageTable[i] & PAGE_COW) == PAGE_COW) { - adjustCowCounter(((u_int32_t) parentPageTable[i] & 0xFFFFF000), 1); + vmm_adjustCowCounter(((u_int32_t) parentPageTable[i] & 0xFFFFF000), 1); } else { - adjustCowCounter(((u_int32_t) parentPageTable[i] & 0xFFFFF000), 2); + vmm_adjustCowCounter(((u_int32_t) parentPageTable[i] & 0xFFFFF000), 2); parentPageTable[i] = newPageTable[i]; } } @@ -461,27 +465,28 @@ kpanic("Error: newPageTable == NULL, File: %s, Line: %i\n",__FILE__,__LINE__); /* Flush The Page From Garbage In Memory */ - memset(newPageTable,0x0,0x1000); + if (vmm_zeroVirtualPage((u_int32_t)newPageTable) == 0x1) + K_PANIC("ZPE: Failed"); /* Map This Into The Page Directory */ newPageDirectory[0] = (vmm_getPhysicalAddr((u_int32_t) newPageTable) | PAGE_DEFAULT); /* Set Address Of Parents Page Table */ parentPageTable = (u_int32_t *) PAGE_TABLES_BASE_ADDR; /* Map The First 1MB Worth Of Pages */ - for (x = 0; x < (pageEntries / 4); x++) { + for (x = 0; x < (PAGE_ENTRIES / 4); x++) { newPageTable[x] = parentPageTable[x]; } /* Map The Next 3MB Worth Of Pages But Make Them COW */ - for (x = (pageEntries / 4) + 1; x < pageEntries; x++) { + for (x = (PAGE_ENTRIES / 4) + 1; x < PAGE_ENTRIES; x++) { /* If Page Is Avaiable Map It */ if ((parentPageTable[x] & 0xFFFFF000) != 0x0) { /* Set Pages To COW */ newPageTable[x] = (((u_int32_t) parentPageTable[x] & 0xFFFFF000) | (PAGE_DEFAULT | PAGE_COW)); /* Increment The COW Counter For This Page */ if (((u_int32_t) parentPageTable[x] & PAGE_COW) == PAGE_COW) { - adjustCowCounter(((u_int32_t) parentPageTable[x] & 0xFFFFF000), 1); + vmm_adjustCowCounter(((u_int32_t) parentPageTable[x] & 0xFFFFF000), 1); } else { - adjustCowCounter(((u_int32_t) parentPageTable[x] & 0xFFFFF000), 2); + vmm_adjustCowCounter(((u_int32_t) parentPageTable[x] & 0xFFFFF000), 2); parentPageTable[x] = newPageTable[x]; } } else { @@ -504,7 +509,7 @@ /* First Set Our Page Directory To Contain This */ newPageDirectory[767] = vmm_getPhysicalAddr((u_int32_t) newPageTable) | PAGE_DEFAULT; /* Now Lets Build The Page Table */ - for (x = 0; x < pageEntries; x++) { + for (x = 0; x < PAGE_ENTRIES; x++) { newPageTable[x] = newPageDirectory[x]; } /* Now We Are Done So Lets Unmap This Page */ @@ -557,12 +562,12 @@ newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((u_int32_t) newPageDirectory); /* First Set Up A Flushed Page Directory */ - for (x = 0; x < pageEntries; x++) { + for (x = 0; x < PAGE_ENTRIES; x++) { newPageDirectory[x] = 0x0; } /* Map The Top 1GB Region Of The VM Space */ - for (x = 768; x < pageEntries; x++) { + for (x = 768; x < PAGE_ENTRIES; x++) { newPageDirectory[x] = parentPageDirectory[x]; } @@ -572,7 +577,7 @@ */ newPageTable = (u_int32_t *) vmm_getFreeKernelPage(pid,1); /* Flush The Page From Garbage In Memory */ - for (x = 0; x < pageEntries; x++) { + for (x = 0; x < PAGE_ENTRIES; x++) { newPageTable[x] = 0x0; } /* Map This Into The Page Directory */ @@ -580,7 +585,7 @@ /* Set Address Of Parents Page Table */ parentPageTable = (u_int32_t *) PAGE_TABLES_BASE_ADDR; /* Map The First 1MB Worth Of Pages */ - for (x = 0; x < (pageEntries / 4); x++) { + for (x = 0; x < (PAGE_ENTRIES / 4); x++) { newPageTable[x] = parentPageTable[x]; } /* Set Virtual Mapping For Page Directory */ @@ -598,7 +603,7 @@ /* First Set Our Page Directory To Contain This */ newPageDirectory[767] = vmm_getPhysicalAddr((u_int32_t) newPageTable) | PAGE_DEFAULT; /* Now Lets Build The Page Table */ - for (x = 0; x < pageEntries; x++) { + for (x = 0; x < PAGE_ENTRIES; x++) { newPageTable[x] = newPageDirectory[x]; } /* Now We Are Done So Lets Unmap This Page */ diff --git a/src/tools/Makefile b/src/tools/Makefile index 8a59190..060d81c 100644 --- a/src/tools/Makefile +++ b/src/tools/Makefile @@ -37,27 +37,27 @@ $(REMOVE) $(OBJS) $(BINARY) *.core install-ubix: - (cp ../sys/compile/ubix.elf /mnts/ubix/boot/kernel/kernel) - (cp ../bin/init/init /mnts/ubix/bin) - (cp ../bin/login/login /mnts/ubix/bin) - (cp ../bin/shell/shell /mnts/ubix/bin) - (cp ../bin/clock/clock /mnts/ubix/bin) - (cp ../bin/fdisk/fdisk /mnts/ubix/bin) - (cp ../bin/edit/edit /mnts/ubix/bin) - (cp ../bin/cat/cat /mnts/ubix/bin) - (cp ../bin/ls/ls /mnts/ubix/bin) - (cp ../bin/ld/ld.so /mnts/ubix/lib) - #(cp ../bin/rtld-elf/ld-elf.so.1 /mnts/ubix/libexec) - (cp ../bin/tcc/tcc /mnts/ubix/bin) - (cp ../bin/tcc/libtcc.a /mnts/ubix/tcc) - (cp ../lib/libc_old/libc_old.so /mnts/ubix/lib) - (cp ../lib/libutil/libutil.so /mnts/ubix/lib) - (cp ../lib/libc/libc.so /mnts/ubix/lib) - (cp ../lib/libc/libc.so /mnts/ubix/tcc/lib) - (cp ../lib/libc/pic.a /mnts/ubix/tcc/lib/libc.a) - (cp ../lib/ubix_api/ubix_api.so /mnts/ubix/lib) - (cp ./userdb /mnts/ubix/etc) - (cp ./motd /mnts/ubix/etc) + (cp ../sys/compile/ubix.elf /ubix/boot/kernel/kernel) + (cp ../bin/init/init /ubix/bin) + (cp ../bin/login/login /ubix/bin) + (cp ../bin/shell/shell //ubix/bin) + (cp ../bin/clock/clock /ubix/bin) + (cp ../bin/fdisk/fdisk /ubix/bin) + (cp ../bin/edit/edit /ubix/bin) + (cp ../bin/cat/cat /ubix/bin) + (cp ../bin/ls/ls /ubix/bin) + (cp ../bin/ld/ld.so /ubix/lib) + #(cp ../bin/rtld-elf/ld-elf.so.1 /ubix/libexec) + (cp ../bin/tcc/tcc /ubix/bin) + (cp ../bin/tcc/libtcc.a /ubix/tcc) + (cp ../lib/libc_old/libc_old.so /ubix/lib) + (cp ../lib/libutil/libutil.so /ubix/lib) + (cp ../lib/libc/libc.so /ubix/lib) + (cp ../lib/libc/libc.so /ubix/tcc/lib) + (cp ../lib/libc/pic.a /ubix/tcc/lib/libc.a) + (cp ../lib/ubix_api/ubix_api.so /ubix/lib) + (cp ./userdb /ubix/etc) + (cp ./motd /ubix/etc) format-dsk: (cp ../sys/compile/ubix.elf ./)