↑ Back to main site.

EPOS

Experimental Protected-mode Operating System

process.h
/*
EPOS
http://www.atanaslaskov.com/epos/

FILE:        process.h
DESCRIPTION: EPOS Process Manger

The prefixes "tm" stand for "task manager",
the old name of this part of the kernel.
 
BSD LICENSE
Copyright (c) 2006, Atanas Laskov
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
   1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.
   2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#ifndef PROCESS_H
#define PROCESS_H

// Maximal process count
// NOTE: Changing this must also be applied in processa.asm
//
#define MAX_PROCESS_CNT 40

// Process ID
//
#define PID         unsigned long
#define PID_INVALID MAX_PROCESS_CNT

// Process state
//
#define T_STATE__DEAD       0x0 // no longer included in scheduler
#define T_STATE__SELECTED   0x1 // data can be loaded into process memory
#define T_STATE__ALIVE      0x2 // process is in execution
#define T_STATE__ASLEEP     0X4 // process execution is temporally stopped

// Return values
//
#define TRET                    unsigned char
#define T_RET_OK                0
#define T_RET_INVALIDPID        1
#define T_RET_INBOXFULL         2
#define T_RET_INBOXEMPTY        3
#define T_RET_TOOMANYPROCESSES  4
#define T_RET_OUTOFMEMORY       5

// Structure for storing processor registers
//
struct ProcessState {                  
    unsigned long eax, ebx, ecx, edx, eflags;
    unsigned long ebp, edi, esi, esp, eip;
};

// Structure for storing complete process state
//
struct Process{
    unsigned short      bState;
    struct ProcessState tsState;
    HMEMORY             hMemory;
    unsigned long       hKernelLine;
    PID                 dwPID_Parent;
    char                strModule[41];
};

// Return execution to process
// NOTE: This is defined in processa.asm
void tmIRetToProcess(unsigned long nldt, struct ProcessState *pRecoveryState);

// Initialize task manager
void tmInit();

// Create a new process
TRET tmCreateProcess(PID *ph, unsigned long dwBytes, char* strModule);

// Kill a process
TRET tmKillProcess(PID h);

// Set process state to executing
void tmLiveProcess(PID h);

// Set process status to sleeping or executing
//
unsigned char tmSleep(PID h);
unsigned char tmWakeUp(PID h);

// Get PID of current process
//
PID tmGetCrProcessID();
void  tmSetCrProcesID_NoSwitch(unsigned long dwPID);

// Get the state of a porcess
unsigned short tmGetProcessState(PID h);

// Get process IPC line
unsigned long  tmGetProcessLine(PID h);

// Get process memory handler, base and size
HMEMORY        tmGetProcessMemory(PID h);
unsigned long  tmGetProcessMembase(PID h);
unsigned long  tmGetProcessMemSize(PID h);

// Get parent process
PID            tmGetProcessParent(PID h);

// Get name of the file used to create a process
char*          tmGetProcessModule(PID h);

// Call a function defined in the process
void tmCallLocalFunction(PID h, unsigned long dwEntryPoint);


unsigned long  tmGetCharge();
void           tmAddCharge();

#endif //#ifndef PROCESS_H