diff --git a/src/sys/Makefile b/src/sys/Makefile index 4591575..22f591f 100644 --- a/src/sys/Makefile +++ b/src/sys/Makefile @@ -1,7 +1,7 @@ # $Id$ # Kernel Makefile (C) 2002 The UbixOS Project -all: net-code mm-code sde-code pci-code ufs-code mpi-code ubixfs-code vfs-code isa-code kernel-code lib-code vmm-code sys-code boot-code init-code devfs-code generic-code kmods-code kernel-img +all: net-code mm-code pci-code ufs-code mpi-code ubixfs-code vfs-code isa-code kernel-code lib-code sys-code boot-code init-code devfs-code generic-code kmods-code kernel-img mm-code mm-code: mm (cd mm;make) diff --git a/src/sys/compile/Makefile b/src/sys/compile/Makefile index e8a8a89..9b07b51 100644 --- a/src/sys/compile/Makefile +++ b/src/sys/compile/Makefile @@ -9,7 +9,7 @@ OBJS = null.o #Kernel Parts -KPARTS = ../init/*.o ../sys/*.o ../vmm/*.o ../lib/*.o ../kernel/*.o ../mpi/*.o ../isa/*.o ../vfs/*.o ../ubixfs/*.o ../pci/*.o ../sde/*.o ../devfs/*.o ../ufs/*.o ../generic/*.o ../kmods/*.o +KPARTS = ../init/*.o ../sys/*.o ../mm/*.o ../lib/*.o ../kernel/*.o ../mpi/*.o ../isa/*.o ../vfs/*.o ../ubixfs/*.o ../pci/*.o ../devfs/*.o ../ufs/*.o ../generic/*.o ../kmods/*.o #../graphics/*.o ../ld/*.o -Ttext 0x30000 -Tdata 0x34000 # Link the kernel statically with fixed text+data address @1M diff --git a/src/sys/include/mm/paging.h b/src/sys/include/mm/paging.h index 1817f1a..75b3283 100644 --- a/src/sys/include/mm/paging.h +++ b/src/sys/include/mm/paging.h @@ -17,4 +17,6 @@ #define PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE|PAGE_USER) #define KERNEL_PAGE_DEFAULT (PAGE_PRESENT|PAGE_WRITE) +void _vmm_pageFault(); + #endif diff --git a/src/sys/include/mm/vmm.h b/src/sys/include/mm/vmm.h index d2d9e90..e115269 100644 --- a/src/sys/include/mm/vmm.h +++ b/src/sys/include/mm/vmm.h @@ -20,5 +20,9 @@ uInt32 freePages; uInt32 usedPages; mMap *mmFreePages; - +uInt32 kernelPageDirectory; +void _vmm_pageFault(); +int vmm_init(); +int vmmMemMapInit(); + #endif diff --git a/src/sys/include/ubixos/init.h b/src/sys/include/ubixos/init.h index 0d7849d..0a14886 100644 --- a/src/sys/include/ubixos/init.h +++ b/src/sys/include/ubixos/init.h @@ -30,7 +30,7 @@ #ifndef _INIT_H #define _INIT_H -#include +#include #include #include #include diff --git a/src/sys/include/ubixos/syscalls.h b/src/sys/include/ubixos/syscalls.h index a8339ad..2d3cef2 100644 --- a/src/sys/include/ubixos/syscalls.h +++ b/src/sys/include/ubixos/syscalls.h @@ -39,10 +39,10 @@ void sysRmModule(); void sysGetpid(); void sysExit(); -void sysExec(); +//void sysExec(); void sysFork(); void sysCheckPid(); -void sysGetFreePage(); +//void sysGetFreePage(); void sysFeof(); void sysFwrite(); @@ -58,13 +58,13 @@ void sysGetGid(); void sysSetUid(); void sysSetGid(); -void sysSDE(); +//void sysSDE(); void sysGetDrives(); void sysGetCwd(); void sysChDir(); void sysGetUptime(); void sysGetTime(); -void sysStartSDE(); +//void sysStartSDE(); void sysUnlink(); void sysMpiCreateMbox(); void sysMpiDestroyMbox(); @@ -78,11 +78,13 @@ invalidCall, /** 0 **/ sysGetpid, /** 1 **/ sysExit, /** 2 **/ - sysExec, /** 3 **/ + invalidCall, /** 3 **/ + //sysExec, /** 3 **/ sysFork, /** 4 **/ sysFgetc, /** 5 **/ sysCheckPid, /** 6 **/ - sysGetFreePage, /** 7 **/ + invalidCall, /** 7 **/ + //sysGetFreePage, /** 7 **/ sysFopen, /** 8 **/ sysFeof, /** 9 **/ sysFclose, /** 10 **/ @@ -115,7 +117,8 @@ sysAddModule, /** 37 Add Kernel Module **/ sysRmModule, /** 38 Remove Kernel Module **/ invalidCall, /** 39 **/ - sysSDE, /** 40 SDE Kernel Interface **/ + invalidCall, /** 40 SDE Kernel Interface **/ + //sysSDE, /** 40 SDE Kernel Interface **/ invalidCall, /** 41 **/ invalidCall, /** 42 **/ invalidCall, /** 43 **/ @@ -123,7 +126,8 @@ sysGetDrives, /** 45 Get Drives **/ sysGetUptime, /** 46 Get Uptime **/ sysGetTime, /** 47 Get Time **/ - sysStartSDE, /** 48 start SDE **/ + invalidCall, /** 48 start SDE **/ + //sysStartSDE, /** 48 start SDE **/ invalidCall, /** 49 **/ sysMpiCreateMbox, /** 50 mpiCreateMbox **/ sysMpiDestroyMbox, /** 51 mpiDestroyMbox **/ @@ -138,6 +142,10 @@ /*** $Log$ + Revision 1.6 2005/08/05 09:43:57 fsdfs + + code clean up, performance tuning + Revision 1.5 2005/08/04 22:48:39 fsdfs added 4 new syscalls: sysAuth(), sysPasswd(), sysAddModule(), sysRmModule() diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 51de4a9..b1fc4ca 100644 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -36,7 +36,6 @@ #include #include #include -#include /***************************************************************************************** Desc: The Kernels Descriptor table: @@ -103,7 +102,7 @@ /* Initialize the system */ kprintf("Free Pages: [%i]\n",systemVitals->freePages); - kprintf("MemoryMap: [0x%X]\n",vmmMemoryMap); +// kprintf("MemoryMap: [0x%X]\n",vmmMemoryMap); kprintf("Starting OS\n"); @@ -113,7 +112,7 @@ //sysExec("sys:/init", 0x0, 0x0, 0x0); execThread(systemTask, (uInt32)sysTask+0x2000,0x0); - execFile("sys:/init",0x0,0x0,0x0); + //execFile("sys:/init",0x0,0x0,0x0); /* start the scheduler */ //irqEnable(0x0); diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 254ec38..c08c8e9 100644 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -127,6 +127,7 @@ The Freshly Allocated Pages With The Correct Permissions *****************************************************************************************/ +/* void execFile(char *file,int argc,char **argv,int console) { int i = 0x0; @@ -136,7 +137,7 @@ elfHeader *binaryHeader = 0x0; elfProgramHeader *programHeader = 0x0; - /* Get A New Task For This Proccess */ + // Get A New Task For This Proccess _current = schedNewTask(); assert(_current); _current->gid = 0x0; @@ -145,23 +146,23 @@ if (_current->term == 0x0) kpanic("Error: invalid console\n"); - /* Set tty ownership */ + // Set tty ownership _current->term->owner = _current->id; - /* Now We Must Create A Virtual Space For This Proccess To Run In */ + // Now We Must Create A Virtual Space For This Proccess To Run In _current->tss.cr3 = (uInt32)vmmCreateVirtualSpace(_current->id); - /* To Better Load This Application We Will Switch Over To Its VM Space */ + // 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)) ); - /* Lets Find The File */ + // Lets Find The File tmpFd = fopen(file,"r"); - /* If We Dont Find the File Return */ + // If We Dont Find the File Return if (tmpFd == 0x0) { // kprintf("Exec Format Error: Binary File Not Executable.\n"); fclose(tmpFd); @@ -173,13 +174,13 @@ return; } - /* Load ELF Header */ + // 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); //kprintf(">b<"); - /* Check If App Is A Real Application */ + // Check If App Is A Real Application if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { //kprintf("Exec Format Error: Binary File Not Executable.\n"); kfree(binaryHeader); @@ -199,28 +200,28 @@ return; } - /* Load The Program Header(s) */ + // Load The Program Header(s) programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum); fseek(tmpFd,binaryHeader->ePhoff,0); //kprintf(">c:%i:0x%X:0x%X<",sizeof(elfProgramHeader)*binaryHeader->ePhnum,programHeader,tmpFd); fread(programHeader,(sizeof(elfProgramHeader)*binaryHeader->ePhnum),1,tmpFd); //kprintf(">d<"); - /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + // Loop Through The Header And Load Sections Which Need To Be Loaded for (i=0;iePhnum;i++) { if (programHeader[i].phType == 1) { - /* - Allocate Memory Im Going To Have To Make This Load Memory With Correct - Settings so it helps us in the future - */ + // + //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+4095);x += 0x1000) { - /* Make readonly and read/write !!! */ + // Make readonly and read/write !!! if (vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x),PAGE_DEFAULT) == 0x0) kpanic("Error: vmmFindFreePage Failed\n"); memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); } _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); - /* Now Load Section To Memory */ + // 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) { @@ -232,18 +233,18 @@ } } - /* Set Virtual Memory Start */ + // Set Virtual Memory Start _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); - /* Task Stack 0x2000 bytes long */ + // Task Stack 0x2000 bytes long vmm_remapPage(vmmFindFreePage(_current->id),0x5DC000,PAGE_DEFAULT | PAGE_STACK); vmm_remapPage(vmmFindFreePage(_current->id),0x5DB000,PAGE_DEFAULT | PAGE_STACK); - /* Kernel Stack 0x2000 bytes long */ + // Kernel Stack 0x2000 bytes long vmm_remapPage(vmmFindFreePage(_current->id),0x5CC000,KERNEL_PAGE_DEFAULT | PAGE_STACK); vmm_remapPage(vmmFindFreePage(_current->id),0x5CB000,KERNEL_PAGE_DEFAULT | PAGE_STACK); - /* Set All The Proper Information For The Task */ + // Set All The Proper Information For The Task _current->tss.back_link = 0x0; _current->tss.esp0 = 0x5CC000; _current->tss.ss0 = 0x10; @@ -258,7 +259,7 @@ _current->tss.esi = 0x0; _current->tss.edi = 0x0; - /* Set these up to be ring 3 tasks */ + // Set these up to be ring 3 tasks _current->tss.es = 0x30+3; _current->tss.cs = 0x28+3; _current->tss.ss = 0x30+3; @@ -276,17 +277,17 @@ kfree(programHeader); fclose(tmpFd); - /* Switch Back To The Kernels VM Space */ + // Switch Back To The Kernels VM Space asm volatile( "movl %0,%%eax \n" "movl %%eax,%%cr3 \n" : : "d" ((uInt32 *)(kernelPageDirectory)) ); - /* Finally Return */ + // Finally Return return; } - +*/ /***************************************************************************************** Function: void sysExec(); @@ -296,6 +297,7 @@ 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; @@ -310,7 +312,7 @@ tmpFd = fopen(file,"r"); _current->imageFd = tmpFd; - /* If We Dont Find the File Return */ + // If We Dont Find the File Return if (tmpFd == 0x0) { kprintf("Couldn't open file %s\n",file); return; @@ -321,16 +323,16 @@ return; } - /* Load ELF Header */ + // Load ELF Header if ((binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader))) == 0x0) endTask(_current->id); //kprintf("A"); fread(binaryHeader,sizeof(elfHeader),1,tmpFd); //kprintf("B"); - /* Set sectionHeader To Point To Loaded Binary To We Can Gather Info */ + // Set sectionHeader To Point To Loaded Binary To We Can Gather Info - /* Check If App Is A Real Application */ + // Check If App Is A Real Application if ((binaryHeader->eIdent[1] != 'E') && (binaryHeader->eIdent[2] != 'L') && (binaryHeader->eIdent[3] != 'F')) { //kprintf("Exec Format Error: Binary File Not Executable.\n"); kfree(binaryHeader); @@ -350,7 +352,7 @@ return; } - /* Load The Program Header(s) */ + // Load The Program Header(s) if ((programHeader = (elfProgramHeader *)kmalloc(sizeof(elfProgramHeader)*binaryHeader->ePhnum)) == 0x0) endTask(_current->id); @@ -365,21 +367,21 @@ fseek(tmpFd,binaryHeader->eShoff,0); fread(sectionHeader,sizeof(elfSectionHeader)*binaryHeader->eShnum,1,tmpFd); - /* Loop Through The Header And Load Sections Which Need To Be Loaded */ + // Loop Through The Header And Load Sections Which Need To Be Loaded for (i=0;iePhnum;i++) { if (programHeader[i].phType == 1) { - /* - Allocate Memory Im Going To Have To Make This Load Memory With Correct - Settings so it helps us in the future - */ + // + //Allocate Memory Im Going To Have To Make This Load Memory With Correct + //Settings so it helps us in the future + for (x=0;x<(programHeader[i].phMemsz+4095);x += 0x1000) { - /* Make readonly and read/write !!! */ + // Make readonly and read/write !!! if (vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x),PAGE_DEFAULT) == 0x0) kpanic("Error: vmmFindFreePage Failed\n"); memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x),0x0,0x1000); } _current->oInfo.vmStart = ((programHeader[i].phVaddr & 0xFFFFF000) + 0x1900000); - /* Now Load Section To Memory */ + // 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) { @@ -413,7 +415,7 @@ } } - /* Adjust iframe */ + // Adjust iframe tmp = (uInt32 *)_current->tss.esp0 - 5; tmp[0] = binaryHeader->eEntry; tmp[3] = 0x5DD000-12; @@ -421,13 +423,13 @@ tmp[0] = argc; tmp[1] = (uInt32)argv; - /* Now That We Relocated The Binary We Can Unmap And Free Header Info */ + // Now That We Relocated The Binary We Can Unmap And Free Header Info kfree(binaryHeader); kfree(programHeader); return; } - +*/ /*** END ***/ diff --git a/src/sys/kernel/fork.c b/src/sys/kernel/fork.c index 8687fc2..60e0c59 100644 --- a/src/sys/kernel/fork.c +++ b/src/sys/kernel/fork.c @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include @@ -85,7 +85,7 @@ newProcess->tss.trace_bitmap = 0x0000; newProcess->tss.io_map = 0x8000; /* Create A Copy Of The VM Space For New Task */ - newProcess->tss.cr3 = (uInt32)vmmCopyVirtualSpace(newProcess->id); +// newProcess->tss.cr3 = (uInt32)vmmCopyVirtualSpace(newProcess->id); newProcess->state = FORK; /* Return Id of Proccess */ diff --git a/src/sys/kernel/ld.c b/src/sys/kernel/ld.c index a10f9dd..a981d6e 100644 --- a/src/sys/kernel/ld.c +++ b/src/sys/kernel/ld.c @@ -38,7 +38,7 @@ #include #include #include - +/* uInt32 ldEnable() { int i = 0x0; int x = 0x0; @@ -55,7 +55,7 @@ elfDynSym *relSymTab = 0x0; elfPltInfo *elfRel = 0x0; - /* Open our dynamic linker */ + // Open our dynamic linker ldFd = fopen("sys:/ld.so","rb"); if (ldFd == 0x0) { @@ -86,26 +86,26 @@ case PT_LOAD: case PT_DYNAMIC: newLoc = (char *)programHeader[i].phVaddr + LD_START; - /* - Allocate Memory Im Going To Have To Make This Load Memory With Correct - Settings so it helps us in the future - */ + // + //Allocate Memory Im Going To Have To Make This Load Memory With Correct + //Settings so it helps us in the future + for (x=0;x < ((programHeader[i].phMemsz)+4095);x += 0x1000) { - /* make r/w or ro */ + // make r/w or ro if ((vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),PAGE_DEFAULT)) == 0x0) kpanic("vmmRemapPage: ld\n"); memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),0x0,0x1000); } - /* Now Load Section To Memory */ + // Now Load Section To Memory fseek(ldFd,programHeader[i].phOffset,0x0); fread(newLoc,programHeader[i].phFilesz,1,ldFd); break; case PT_GNU_STACK: - /* Tells us if the stack should be executable. Failsafe to executable - until we add checking */ + // Tells us if the stack should be executable. Failsafe to executable + // until we add checking break; case PT_PAX_FLAGS: - /* Not sure... */ + // Not sure... break; default: kprintf("Unhandled Header : %08x\n", programHeader[i].phType); @@ -169,7 +169,7 @@ return((uInt32)i); } - +*/ /*** END ***/ diff --git a/src/sys/kernel/syscall.c b/src/sys/kernel/syscall.c index bfe5ea4..6fac13e 100644 --- a/src/sys/kernel/syscall.c +++ b/src/sys/kernel/syscall.c @@ -38,16 +38,18 @@ #include #include #include -#include +#include #include #include #include #include #include -#include #include -void sdeTestThread(); + +//#include + +//void sdeTestThread(); asm( ".globl _sysCallNew \n" @@ -197,13 +199,14 @@ Notes: ************************************************************************/ +/* void sysGetFreePage(long *ptr,int count) { if (ptr) *ptr = (long) vmmGetFreeVirtualPage(_current->id,count); return; } - +*/ void sysGetDrives(uInt32 *ptr) { if (ptr) @@ -238,7 +241,7 @@ //sched_yield(); return; } - +/* void sysStartSDE() { int i = 0x0; @@ -252,7 +255,7 @@ return; } - +*/ /*** END ***/ diff --git a/src/sys/kmods/kmod.c b/src/sys/kmods/kmod.c index 10e0fcb..0dab084 100644 --- a/src/sys/kmods/kmod.c +++ b/src/sys/kmods/kmod.c @@ -50,7 +50,7 @@ kmod_t *kmods; - addr = kmod_load(kmod_file); +// addr = kmod_load(kmod_file); if (addr == 0x0) return 0x0; @@ -71,7 +71,7 @@ return 0x0; } - +/* uInt32 kmod_load(const char *kmod_file) { int i = 0x0; int x = 0x0; @@ -88,14 +88,14 @@ elfDynSym *relSymTab = 0x0; elfPltInfo *elfRel = 0x0; - /* Open kernel module */ + // Open kernel module kmod_fd = fopen(kmod_file,"rb"); if (kmod_fd == 0x0) { kprintf("Can not open %s\n",kmod_file); return 0x0; } - /* load module header */ + // load module header fseek(kmod_fd,0x0,0x0); binaryHeader = (elfHeader *)kmalloc(sizeof(elfHeader)); if(binaryHeader == 0x0) @@ -126,26 +126,26 @@ case PT_LOAD: case PT_DYNAMIC: newLoc = (char *)programHeader[i].phVaddr + LD_START; - /* - Allocate Memory Im Going To Have To Make This Load Memory With Correct - Settings so it helps us in the future - */ + // + //Allocate Memory Im Going To Have To Make This Load Memory With Correct + //Settings so it helps us in the future + for (x=0;x < ((programHeader[i].phMemsz)+4095);x += 0x1000) { - /* make r/w or ro */ + // make r/w or ro if ((vmm_remapPage(vmmFindFreePage(_current->id),((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),PAGE_DEFAULT)) == 0x0) kpanic("vmmRemapPage: ld\n"); memset((void *)((programHeader[i].phVaddr & 0xFFFFF000) + x + LD_START),0x0,0x1000); } - /* Now Load Section To Memory */ + // Now Load Section To Memory fseek(kmod_fd,programHeader[i].phOffset,0x0); fread(newLoc,programHeader[i].phFilesz,1,kmod_fd); break; case PT_GNU_STACK: - /* Tells us if the stack should be executable. Failsafe to executable - until we add checking */ + // Tells us if the stack should be executable. Failsafe to executable + // until we add checking break; case PT_PAX_FLAGS: - /* Not sure... */ + // Not sure... break; default: kprintf("Unhandled Header : %08x\n", programHeader[i].phType); @@ -209,7 +209,7 @@ return((uInt32)i); } - +*/ /*** END ***/ diff --git a/src/sys/lib/Makefile b/src/sys/lib/Makefile index a3a1422..21dc51e 100644 --- a/src/sys/lib/Makefile +++ b/src/sys/lib/Makefile @@ -8,7 +8,7 @@ INCLUDES += -I../../lib/objgfx40/ # Objects -OBJS = memset.o assert.o ogprintf.o sqrt.o atan.o divdi3.o libcpp.o strtok.o kmalloc.o kprintf.o vsprintf.o string.o net.o strtol.o +OBJS = memset.o assert.o sqrt.o atan.o divdi3.o libcpp.o strtok.o kprintf.o vsprintf.o string.o net.o strtol.o all: $(OBJS) diff --git a/src/sys/lib/kprintf.c b/src/sys/lib/kprintf.c index 122c970..374dff9 100644 --- a/src/sys/lib/kprintf.c +++ b/src/sys/lib/kprintf.c @@ -45,9 +45,11 @@ if (printOff == 0x0) { kprint(buf); } +/* if (ogprintOff == 0x0) { ogPrintf(buf); } +*/ return(i); } @@ -62,6 +64,18 @@ /*** $Log$ + Revision 1.7 2004/07/21 10:02:09 reddawg + devfs: renamed functions + device system: renamed functions + fdc: fixed a few potential bugs and cleaned up some unused variables + strol: fixed definition + endtask: made it print out freepage debug info + kmalloc: fixed a huge memory leak we had some unhandled descriptor insertion so some descriptors were lost + ld: fixed a pointer conversion + file: cleaned up a few unused variables + sched: broke task deletion + kprintf: fixed ogPrintf definition + Revision 1.6 2004/07/20 22:58:33 reddawg retiring to the laptop for the night must sync in work to resume from there diff --git a/src/sys/mm/Makefile b/src/sys/mm/Makefile index 9ceae56..b14b74f 100644 --- a/src/sys/mm/Makefile +++ b/src/sys/mm/Makefile @@ -6,7 +6,7 @@ include ../Makefile.inc # Objects -OBJS = page_fault.o pagefault.o copyvirtualspace.o getfreepage.o memory.o kmalloc.o kfree.o +OBJS = page_fault.o pagefault.o copyvirtualspace.o getfreepage.o memory.o kmalloc.o kfree.o vmminit.o all: $(OBJS) diff --git a/src/sys/mm/getfreepage.c b/src/sys/mm/getfreepage.c index 3dbcf17..b163ea6 100644 --- a/src/sys/mm/getfreepage.c +++ b/src/sys/mm/getfreepage.c @@ -4,22 +4,23 @@ mMap *mmFreePages; mMap *mmUsedPages; +/* void * mmGetFreeVirtualPage(kTask_t *task) { mMap *tmp; - /* remove the first free entry from the free pages list */ + // remove the first free entry from the free pages list tmp = mmFreePages->First; mmFreePages->First = mmFreePages->First->Next; mmFreePages->First->Previous = NULL; - /* add the free entry to the task's pages list */ + // add the free entry to the task's pages list tmp->Next = NULL; tmp->Previous = task->LastPage; - /* TODO: assign virtual addresses */ + // TODO: assign virtual addresses task->LastPage = tmp; return tmp; } - +*/ diff --git a/src/sys/mm/kmalloc.c b/src/sys/mm/kmalloc.c index 6e5508a..2382e40 100644 --- a/src/sys/mm/kmalloc.c +++ b/src/sys/mm/kmalloc.c @@ -26,5 +26,5 @@ retAddr = tmp->pageAddr; tmp2 = tmp; } - return retAddr; + return (void *)retAddr; } diff --git a/src/sys/mm/memory.c b/src/sys/mm/memory.c index 84d45bd..f4739a6 100644 --- a/src/sys/mm/memory.c +++ b/src/sys/mm/memory.c @@ -10,6 +10,8 @@ int numPages = 0; mMap *mmUsedPages; +uInt32 freePages = 0, usedPages = 0; +uInt32 z = 0, memStart = 0; uInt32 countMemory(); void @@ -38,6 +40,7 @@ { if(tmp->pageAddr == memAddr) { + freePages++; /* remove the page from the task's used list */ if(tmp == task->FirstPage) { @@ -79,15 +82,32 @@ void * mmGetFreeVirtualPage(kTask_t *task) { - mMap *tmp; + mMap *tmp, *tmpMap; + z++; + freePages--; + kprintf("%d:%d - [%x]\n", z, numPages, tmpMap->pageAddr); - if(mmFreePages == NULL) - { - kprintf("Out of memory\n"); - return NULL; + if(mmFreePages == NULL) + { + mmFreePages = (mMap *)(z * 4096); + mmFreePages->First = mmFreePages; + mmFreePages->Last = mmFreePages; + mmFreePages->Next = NULL; + mmFreePages->Previous = NULL; + mmFreePages->pageAddr = z * 4096; + mmFreePages->physicalAddr = z * 4096; } + else + { + tmpMap = (mMap *)(z * 4096); + mmFreePages->Last->Next = tmpMap; + tmpMap->Previous = mmFreePages->Last; + mmFreePages->Last = tmpMap; + tmpMap->pageAddr = z * 4096; + tmpMap->physicalAddr = z * 4096; + } - /* remove the first page from the list and return it */ + // remove the first page from the list and return it // tmp = mmFreePages->First; mmFreePages->First = mmFreePages->First->Next; mmFreePages->First->Previous = NULL; @@ -95,64 +115,47 @@ } int -mmMemMapInit() +vmmMemMapInit() { - uInt32 memStart, z; + uInt32 memStart; mMap *tmpMap; /* Count System Memory */ numPages = countMemory(); - + freePages = numPages; /* calculate the start of memory */ memStart = 0x101; memStart += (((sizeof(mMap) * numPages) + (sizeof(mMap) - 1)) / 0x1000); /* initialize free pages */ - for(z = memStart ; z < numPages; z++) - { - if(mmFreePages == NULL) - { - //UBU: replace this with static location + offset - mmFreePages = kmalloc(sizeof(mMap)); - mmFreePages->First = mmFreePages; - mmFreePages->Last = mmFreePages; - mmFreePages->Next = NULL; - mmFreePages->Previous = NULL; - mmFreePages->pageAddr = z * 4096; - } - else - { - //UBU: replace this with static location + offset - tmpMap = kmalloc(sizeof(mMap)); - mmFreePages->Last->Next = tmpMap; - tmpMap->Previous = mmFreePages->Last; - mmFreePages->Last = tmpMap; - tmpMap->pageAddr = z * 4096; - } - } + kprintf("Initializing memory memStart = [%x]\n", memStart); /* initialize used pages (kernel space) */ for(z = 0 ; z < memStart; z++) { if(mmUsedPages == NULL) { - mmUsedPages = kmalloc(sizeof(mMap)); + mmUsedPages = (mMap *)(z * 4096); mmUsedPages->First = mmUsedPages; mmUsedPages->Last = mmUsedPages; mmUsedPages->Next = NULL; mmUsedPages->Previous = NULL; mmUsedPages->pageAddr = z * 4096; + mmUsedPages->physicalAddr = z * 4096; } else { - tmpMap = kmalloc(sizeof(mMap)); + mmUsedPages = (mMap *)(z * 4096); mmUsedPages->Last->Next = tmpMap; tmpMap->Previous = mmUsedPages->Last; mmUsedPages->Last = tmpMap; tmpMap->pageAddr = z * 4096; + tmpMap->physicalAddr = z * 4096; } + freePages--; + usedPages++; } - + z++; /* Print Out Memory Information */ kprintf("Real Memory: %iMB\n", ((numPages * 4096) / 1024) / 1024 ); kprintf("Available Memory: %iMB\n", ((freePages * 4096) / 1024) / 1024 ); diff --git a/src/sys/mm/pagefault.c b/src/sys/mm/pagefault.c index 8b9c04f..4904137 100644 --- a/src/sys/mm/pagefault.c +++ b/src/sys/mm/pagefault.c @@ -4,7 +4,7 @@ void LoadPageIntoMemory(mMap *page); -void vmm_pageFault2(uInt32 memAddr, uInt32 eip, uInt32 esp) +void mm_pageFault(uInt32 memAddr, uInt32 eip, uInt32 esp) { /* WARNING: this is not SMP safe to use _current! */ kTask_t *tmp = _current; @@ -24,5 +24,6 @@ void LoadPageIntoMemory(mMap *page) { + /* Load page->physicalAddr */ return; } diff --git a/src/sys/sys/idt.c b/src/sys/sys/idt.c index 14915eb..428756b 100644 --- a/src/sys/sys/idt.c +++ b/src/sys/sys/idt.c @@ -33,8 +33,7 @@ #include #include #include -#include -#include +#include #include #include #include diff --git a/src/sys/vmm/memory.c b/src/sys/vmm/memory.c index 3f83008..41a8202 100644 --- a/src/sys/vmm/memory.c +++ b/src/sys/vmm/memory.c @@ -93,7 +93,7 @@ kprintf("Real Memory: %iMB\n", ((numPages * 4096) / 1024) / 1024 ); kprintf("Available Memory: %iMB\n", ((freePages * 4096) / 1024) / 1024 ); kprintf("Used Memory: %iMB\n", ((usedPages * 4096) / 1024) / 1024 ); - + kprintf("hmm\n"); /* Return */ return (0); } @@ -340,6 +340,9 @@ /*** $Log$ + Revision 1.22 2005/08/11 01:23:37 fsdfs + begun conversion to new synchronization + Revision 1.21 2005/08/10 09:47:41 fsdfs updates + kmalloc() and kfree() stubs diff --git a/src/sys/vmm/vmminit.c b/src/sys/vmm/vmminit.c index 6c97a6d..3e94f36 100644 --- a/src/sys/vmm/vmminit.c +++ b/src/sys/vmm/vmminit.c @@ -41,14 +41,18 @@ if (vmmMemMapInit() != 0x0) { return (0x1); } - if (vmm_pagingInit() != 0x0) { - return (0x1); - } +// if (vmm_pagingInit() != 0x0) { + // return (0x1); + // } return (0x0); } /*** $Log$ + Revision 1.8 2005/08/10 06:01:59 fsdfs + cleaned up dependencies. rewrote vmmCopyVirtualSpace. does not compile + CVSn: ---------------------------------------------------------------------- + Revision 1.7 2005/08/09 08:45:40 fsdfs reverting to old vmm. i may have modified something accidently when i wasted time indenting the code.