sched.c
ubixos/sched.h
ubixos/kpanic.h
ubixos/spinlock.h
ubixos/endtask.h
vfs/mount.h
lib/kmalloc.h
lib/kprintf.h
vmm/vmm.h
sys/gdt.h
sys/idt.h
sys/kern_descrip.h
isa/8259.h
string.h
assert.h
sys/thread.h
ubixos/kpanic.h
ubixos/sched.h
ubixos/endtask.h
ubixos/spinlock.h
ubixos/types.h
sys/_types.h
vmm/paging.h
string.h
vfs/file.h
sys/tss.h
lib/kmalloc.h
vmm/vmm.h
src/sys/kernel/sched.c
sys/idt.h
vfs/mount.h
lib/kprintf.h
sys/kern_descrip.h
sys/gdt.h
assert.h
ubixfs/dirCache.h
sys/sysproto.h
sys/signal.h
ubixos/tty.h
isa/8259.h
void void sched () sched _current DEAD FORK taskStruct::id taskStruct::next READY sched_addDelTask sched_deleteTask schedulerSpinLock spinTryLock taskStruct::state sched_yield
int int sched_addDelTask (kTask_t *tmpTask) sched_addDelTask kTask_t * tmpTask delList taskStruct::next taskStruct::prev sched
int int sched_deleteTask (pidType id) sched_deleteTask pidType id taskStruct::id taskStruct::next taskStruct::prev taskList sched
kTask_t * kTask_t* sched_getDelTask () sched_getDelTask delList taskStruct::next systemTask
int int sched_init () sched_init taskStruct::id kmalloc kpanic kprintf nextID taskList
int int sched_setStatus (pidType pid, tState state) sched_setStatus pidType pid tState state schedFindTask taskStruct::state x1 endTask execFile execThread
void void sched_yield () sched_yield sched _int0 _int1 _int10 _int11 _int12 _int2 _int3 _int4 _int5 _int6 _int9 endTask fork_copyProcess schedEndTask spinLock sysFgetc sysSchedYield systemTask ubthread_cond_timedwait ubthread_cond_wait
void void schedEndTask (pidType pid) schedEndTask pidType pid _current endTask taskStruct::id sched_yield
kTask_t * kTask_t* schedFindTask (uInt32 id) schedFindTask uInt32 id taskStruct::id taskStruct::next taskList sched_setStatus sysCheckPid systemTask vmmMapFromTask
kTask_t * kTask_t* schedNewTask () schedNewTask file::f_flag taskStruct::id kmalloc kpanic memset NEW taskStruct::next nextID thread::o_files taskStruct::prev schedulerSpinLock spinLock spinUnlock taskStruct::state taskList taskStruct::td taskStruct::usedMath biosCall execFile execThread
kTask_t * kTask_t* _current _current 0x0 __sysctl _int0 _int1 _int10 _int11 _int12 _int13 _int2 _int3 _int4 _int5 _int6 _int8 _int9 biosCall elf_loadfile endTask execFile fork_copyProcess fstat getgid getpid getuid intNull kmod_load ldEnable mathStateRestore mmap mpi_createMbox mpi_destroyMbox mpi_fetchMessage mpi_postMessage obreak sched schedEndTask sys_exec syscall sysChDir sysExec sysExit sysFgetc sysFwrite sysGetCwd sysGetFreePage sysGetGid sysGetpid sysGetUid sysMkDir sysPasswd sysSetGid sysSetUid ubthread_mutex_lock ubthread_mutex_unlock ubthread_self vmm_pageFault vmm_remapPage vmmGetFreeVirtualPage vmmMapFromTask
kTask_t * kTask_t* _usedMath _usedMath 0x0 mathStateRestore
kTask_t * kTask_t* delList delList 0x0 sched_addDelTask sched_getDelTask
uInt32 uInt32 nextID nextID -1 sched_init schedNewTask
spinLock_t spinLock_t schedulerSpinLock schedulerSpinLock SPIN_LOCK_INITIALIZER sched schedNewTask
kTask_t * kTask_t* taskList taskList 0x0 sched_deleteTask sched_init schedFindTask schedNewTask

    /*****************************************************************************************
    Copyright(c)2002-2004TheUbixOSProject
    Allrightsreserved.

    Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,are
    permittedprovidedthatthefollowingconditionsaremet:

    Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistof
    conditions,thefollowingdisclaimerandthelistofauthors.Redistributionsinbinary
    formmustreproducetheabovecopyrightnotice,thislistofconditions,thefollowing
    disclaimerandthelistofauthorsinthedocumentationand/orothermaterialsprovided
    withthedistribution.NeitherthenameoftheUbixOSProjectnorthenamesofits
    contributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftware
    withoutspecificpriorwrittenpermission.

    THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANY
    EXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOF
    MERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALL
    THECOPYRIGHTOWNERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,
    SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENT
    OFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,OR
    TORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHIS
    SOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.

    $Id: sched_8c.xml 88 2016-01-12 00:11:29Z reddawg $

    *****************************************************************************************/

    #include<ubixos/sched.h>
    #include<ubixos/kpanic.h>
    #include<ubixos/spinlock.h>
    #include<ubixos/endtask.h>
    #include<vfs/mount.h>
    #include<lib/kmalloc.h>
    #include<lib/kprintf.h>
    #include<vmm/vmm.h>
    #include<sys/gdt.h>
    #include<sys/idt.h>
    #include<sys/kern_descrip.h>
    #include<isa/8259.h>
    #include<string.h>
    #include<assert.h>

    #include<ubixos/spinlock.h>

    statickTask_t*taskList=0x0;
    statickTask_t*delList=0x0;
    staticuInt32nextID=-1;

    kTask_t*_current=0x0;
    kTask_t*_usedMath=0x0;

    staticspinLock_tschedulerSpinLock=SPIN_LOCK_INITIALIZER;

    /************************************************************************

    Function:intsched_init()

    Description:Thisfunctionisusedtoenablethekernelscheduler

    Notes:

    02/20/2004-Approvedforquality

    ************************************************************************/

    intsched_init(){
    taskList=(kTask_t*)kmalloc(sizeof(kTask_t));
    if(taskList==0x0)
    kpanic("Unabletocreatetasklist");

    taskList->id=nextID++;

    /*Printoutinformationonscheduler*/
    kprintf("sched0-Address:[0x%X]\n",taskList);

    /*Returnsoweknoweverythingwentwell*/
    return(0x0);
    }

    voidsched(){
    uInt32memAddr=0x0;
    kTask_t*tmpTask=0x0;
    kTask_t*delTask=0x0;

    if(!spinTryLock(&schedulerSpinLock))
    return;

    tmpTask=_current->next;
    //outportByte(0xE9,_current->id+'0');
    schedStart:

    /*Yieldthenexttaskfromthecurrentprioqueue*/
    for(;tmpTask!=0x0;tmpTask=tmpTask->next){
    if(tmpTask->state>0x0){
    _current=tmpTask;
    if(_current->state==FORK)
    _current->state=READY;
    break;
    }
    elseif(tmpTask->state==DEAD)
    {
    delTask=tmpTask;
    tmpTask=tmpTask->next;
    sched_deleteTask(delTask->id);
    sched_addDelTask(delTask);
    gotoschedStart;
    }
    }

    /*Finishedallthetasks,restartingthelist*/
    if(0x0==tmpTask){
    tmpTask=taskList;
    gotoschedStart;
    }

    if(_current->state>0x0){
    if(_current->oInfo.v86Task==0x1)
    irqDisable(0x0);
    asm("cli");
    memAddr=(uInt32)&(_current->tss);
    ubixGDT[4].descriptor.baseLow=(memAddr&0xFFFF);
    ubixGDT[4].descriptor.baseMed=((memAddr>>16)&0xFF);
    ubixGDT[4].descriptor.baseHigh=(memAddr>>24);
    ubixGDT[4].descriptor.access='\x89';
    spinUnlock(&schedulerSpinLock);
    asm("sti");
    asm("ljmp$0x20,$0\n");
    }
    else
    {
    spinUnlock(&schedulerSpinLock);
    }

    return;
    }

    kTask_t*schedNewTask(){
    inti=0;
    kTask_t*tmpTask=(kTask_t*)kmalloc(sizeof(kTask_t));
    structfile*fp=0x0;
    if(tmpTask==0x0)
    kpanic("Error:schedNewTask()-kmallocfailedtryingtoinitializeanewtaskstruct\n");

    memset(tmpTask,0x0,sizeof(kTask_t));
    /*Fillingintasksattrs*/
    tmpTask->usedMath=0x0;
    tmpTask->state=NEW;

    /*HACK*/
    for(i=0;i<3;i++){
    fp=kmalloc(sizeof(structfile));
    tmpTask->td.o_files[i]=(u_int32_t)fp;
    fp->f_flag=0x4;
    }

    spinLock(&schedulerSpinLock);
    tmpTask->id=nextID++;
    tmpTask->next=taskList;
    tmpTask->prev=0x0;
    taskList->prev=tmpTask;
    taskList=tmpTask;

    spinUnlock(&schedulerSpinLock);

    return(tmpTask);
    }

    intsched_deleteTask(pidTypeid){
    kTask_t*tmpTask=0x0;

    /*Checkingeachtaskfromtheprioqueue*/
    for(tmpTask=taskList;tmpTask!=0x0;tmpTask=tmpTask->next){
    if(tmpTask->id==id){
    if(tmpTask->prev!=0x0)
    tmpTask->prev->next=tmpTask->next;
    if(tmpTask->next!=0x0)
    tmpTask->next->prev=tmpTask->prev;
    if(taskList==tmpTask)
    taskList=tmpTask->next;

    return(0x0);
    }
    }
    return(0x1);
    }

    intsched_addDelTask(kTask_t*tmpTask){
    tmpTask->next=delList;
    tmpTask->prev=0x0;
    if(delList!=0x0)
    delList->prev=tmpTask;
    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(uInt32id)
    {
    kTask_t*tmpTask=0x0;

    for(tmpTask=taskList;tmpTask;tmpTask=tmpTask->next){
    if(tmpTask->id==id)
    return(tmpTask);
    }

    return(0x0);
    }

    /************************************************************************

    Function:voidschedEndTask()

    Description:Thisfunctionwillendatask

    Notes:

    02/20/2004-Approvedforquality

    ************************************************************************/
    void
    schedEndTask(pidTypepid){
    endTask(_current->id);
    sched_yield();
    }

    /************************************************************************

    Function:intschedEndTask()

    Description:Thisfunctionwillyieldatask

    Notes:

    02/20/2004-Approvedforquality

    ************************************************************************/

    void
    sched_yield(){
    sched();
    }

    /*
    asm(
    ".globlsched_yield\n"
    "sched_yield:\n"
    "cli\n"
    "callsched\n"
    );
    */

    /************************************************************************

    Function:intsched_setStatus(pidTypepid,tStatestate)

    Description:Changethetasksstatus

    Notes:

    ************************************************************************/
    intsched_setStatus(pidTypepid,tStatestate){
    kTask_t*tmpTask=schedFindTask(pid);
    if(tmpTask==0x0)
    return(0x1);
    tmpTask->state=state;
    return(0x0);
    }

    /***
    END
    ***/