Show
Ignore:
Timestamp:
05/24/08 09:54:46 (6 months ago)
Author:
mwhitworth
Message:

Create startup module.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/hybrid/kernel/sched.c

    r491 r538  
    1717 */ 
    1818 
     19/* TODO: Clean up these includes. */ 
    1920#include <sched.h> 
    2021#include <error.h> 
     
    2526#include <malloc.h> 
    2627#include <fs/vfs.h> 
     28#include <init.h> 
    2729#include <task.h> 
    2830#include <panic.h> 
     
    3133#include <net/socket.h> 
    3234#include <module.h> 
     35#include <imports.h> 
     36#include <sys.h> 
    3337 
    3438/* List heads */ 
     
    5559 
    5660/* Used when a thread is exiting */ 
    57 DWORD exitStack[PAGE_SIZE]; 
     61BYTE exitStack[PAGE_SIZE/4]; 
    5862 
    5963/*********************************************************************** 
     
    141145        SpinLockIrq(&procListLock); 
    142146 
    143         process=(struct Process*)MemCacheAlloc(processCache); 
     147        process=(struct Process*)memCacheAlloc(processCache); 
    144148        if (!process) 
    145149                return NULL; 
     
    147151        if (VirtMemManagerSetup(process)) 
    148152        { 
    149                 MemCacheFree(processCache,process); 
     153                memCacheFree(processCache,process); 
    150154                SpinUnlockIrq(&procListLock); 
    151155                return NULL; 
     
    153157 
    154158        /* Allocate the process's name - used when listing processes or when faulting. */ 
    155         process->name=(char*)malloc(strlen(name)+1); 
    156         strcpy(process->name,name); 
     159        process->name=(char*)MemAlloc(strlen(name)+1); 
     160        strcpy(process->name, name); 
    157161         
    158162        /* Add to parent's children list */ 
     
    168172        process->state=THR_RUNNING; 
    169173 
    170         process->files=NULL; 
     174        process->files=NULL; /* FIXME */ 
    171175 
    172176        ListAddTail(&process->next,&processList); 
     
    176180        return process; 
    177181} 
     182 
     183SYMBOL_EXPORT(ThrCreateProcess); 
    178184 
    179185/*********************************************************************** 
     
    200206        ListRemove(&process->next); 
    201207         
    202         free(process->name); 
    203         MemCacheFree(processCache,process); 
     208        MemFree(process->name); 
     209        memCacheFree(processCache,process); 
    204210 
    205211        IrqRestoreFlags(flags); 
    206212} 
     213 
     214SYMBOL_EXPORT(ThrFreeProcess); 
    207215 
    208216/*********************************************************************** 
     
    251259        SpinLockIrq(&thrListLock); 
    252260 
    253         ret=(struct Thread*)MemCacheAlloc(threadCache); 
     261        ret=(struct Thread*)memCacheAlloc(threadCache); 
    254262        if (!ret) 
    255263                return NULL; 
     
    272280} 
    273281 
     282SYMBOL_EXPORT(ThrCreateThread); 
     283 
    274284/*********************************************************************** 
    275285 * 
     
    295305} 
    296306 
     307SYMBOL_EXPORT(ThrSetPriority); 
     308 
    297309/*********************************************************************** 
    298310 * 
     
    310322void _ThrFreeThread(struct Thread* thread) 
    311323{ 
    312         free((void*)thread->currStack); 
     324        MemFree((void*)thread->currStack); 
    313325        currThread=NULL; 
    314         MemCacheFree(threadCache, thread); 
     326        memCacheFree(threadCache, thread); 
    315327        ThrSchedule(); 
    316328} 
     
    350362 
    351363        if (thread == currThread) 
    352                 ArchSwitchStackCall(exitStack+PAGE_SIZE,_ThrFreeThread,thread); 
     364                ArchSwitchStackCall(exitStack+PAGE_SIZE/4,_ThrFreeThread,thread); 
    353365        else{ 
    354                 free((void*)(thread->currStack)); 
    355                 MemCacheFree(threadCache,thread); 
     366                MemFree((void*)(thread->currStack)); 
     367                memCacheFree(threadCache,thread); 
    356368        } 
    357369         
     
    401413        } 
    402414} 
     415 
     416SYMBOL_EXPORT(ThrStartThread); 
    403417 
    404418/*********************************************************************** 
     
    467481 ***********************************************************************/ 
    468482 
     483/* TODO: Move to filesystem code. */ 
     484 
    469485static void ThrReleaseFsContext() 
    470486{ 
     
    473489        /* Now release the filesystem context */ 
    474490 
    475         if (current->files) 
     491//      if (current->files) 
    476492                /* Close all files associated with the process */ 
    477                 for (i=0; i<current->numFds; i++) 
    478                         DoCloseFile(&current->files[i]); 
     493//              for (i=0; i<current->numFds; i++) 
     494//                      DoCloseFile(&current->files[i]); 
    479495 
    480496        /* Does not apply to the KernelLoading process */ 
    481         if (current->exec) 
    482                 VNodeRelease(current->exec); 
    483  
    484         VNodeRelease(current->cwd); 
    485         VNodeRelease(current->root); 
    486  
    487         free(current->files); 
    488         free(current->sCwd); 
     497//      if (current->exec) 
     498//              VNodeRelease(current->exec); 
     499 
     500//      VNodeRelease(current->cwd); 
     501//      VNodeRelease(current->root); 
     502 
     503//      free(current->files); 
     504//      free(current->sCwd); 
    489505} 
    490506 
     
    511527 
    512528        /* Release all vmm areas */ 
    513         MmapProcessRemove(current); 
     529//      MmapProcessRemove(current); 
    514530        ThrReleaseFsContext(); 
    515531 
     
    548564} 
    549565 
     566SYMBOL_EXPORT(ThrProcessExit); 
     567 
    550568/*********************************************************************** 
    551569 * 
     
    599617        } 
    600618} 
     619 
     620SYMBOL_EXPORT(ThrResumeThread); 
    601621 
    602622/*********************************************************************** 
     
    751771int SysExitThread(int threadId) 
    752772{ 
    753 //      printf("SysExitThread(%d)\n", threadId); 
    754773        if (threadId == -1) /* Exit current thread. */ 
    755774                ThrDoExitThread(); 
     
    803822        waitEntry.thread=currThread; 
    804823         
    805         if (finishStatus) 
    806                 if (VirtCheckArea(finishStatus,sizeof(int),VER_WRITE)) 
    807                         return -EFAULT; 
     824//      if (finishStatus) 
     825//              if (VirtCheckArea(finishStatus,sizeof(int),VER_WRITE)) 
     826//                      return -EFAULT; 
    808827 
    809828        if (pid >= 0) 
     
    903922 ***********************************************************************/ 
    904923 
    905 int ThrInit() 
     924int ThrEarlyInit() 
    906925{ 
    907926        ThrArchInit(); /* Set up arch-specific data structures for multitasking here */ 
    908  
    909         /* Allocate the general scheduling caches */ 
    910         processCache=MemCacheCreate("Process Cache", sizeof(struct Process), ThrProcessConstructor, NULL, 0); 
    911         threadCache=MemCacheCreate("Thread Cache", sizeof(struct Thread), NULL, NULL, 0); 
    912927 
    913928        currThread=idleTask; 
     
    919934        return 0; 
    920935} 
     936 
     937#define SYS_SCHED_BASE          34 
     938 
     939struct SysCall schedSysCallTable[]= 
     940{ 
     941        { SysCreateThread,                      12 }, 
     942        { SysGetCurrentThreadId,        0  }, 
     943        { SysGetCurrentProcessId,       0  }, 
     944        { SysExitThread,                        4  }, 
     945        { SysExit,                                      4  }, 
     946        { SysWaitForProcessFinish,      8  }, 
     947        { SysYield,                                     0  }, 
     948        { 0,                                            0  }, 
     949}; 
     950 
     951int ThrInit() 
     952{ 
     953        /* Allocate the general scheduling caches */ 
     954        processCache=memCacheCreate("Process Cache", sizeof(struct Process), ThrProcessConstructor, NULL, 0); 
     955        threadCache=memCacheCreate("Thread Cache", sizeof(struct Thread), NULL, NULL, 0); 
     956 
     957        /* Register the threading system calls. */ 
     958        SysRegisterRange(SYS_SCHED_BASE, schedSysCallTable); 
     959 
     960        return 0; 
     961} 
     962 
     963CoreInit(ThrInit);