/* Simple OS header file */

/* Boolean values */
#define FALSE 0
#define TRUE 1

/* Hardware constants (determined by hardware, we cannot change) */
#define DISK_BLOCK_SIZE 4096
#define NUMBER_OF_REGISTERS 32

/* system constants (we can change these constants to tune the OS) */
#define SYSTEM_STACK_SIZE 4096	/* bytes */
#define PROCESS_SIZE 512 * 1024	/* bytes */
#define TIME_QUANTUM 100000	/* in microseconds */
#define MESSAGE_SIZE 8		/* words, 1 word = 4 bytes */
#define INIT_PROCESS_DISK_BLOCK 4341 /* disk block number */
#define END_OF_FREE_LIST -1

/* System limits (we can change these) */
#define MAX_PROCESSES 20
#define NUMBER_OF_MESSAGE_QUEUES 20
#define NUMBER_OF_MESSAGE_BUFFERS 100 /* for all queues */

/* Event handler offsets (determined by hardware) */
#define CreateProcessSystemCall 1
#define ExitProcessSystemCall 2
#define CreateMessageQueueSystemCall 3
#define SendMessageSystemCall 4
#define ReceiveMessageSystemCall 5
#define DiskReadSystemCall 6
#define DiskWriteSystemCall 7

/* A save area allocates space to save all the hardware registers. */
struct SaveArea {
    int ia;			/* instruction address */
    int psw;			/* program status word */
    int base;			/* base address in memory */
    int bound;			/* upper limit on address */
    int reg[NUMBER_OF_REGISTERS]; /* register values */
};

/* The process descriptor is the data structure that records the
state of the process.  It includes the register state and the proces state */
struct ProcessDescriptor {
    int     slotAllocated;	/* True or False */
    int     timeLeft;		/* time left since last time slice (ms) */
    enum    ProcessState state;	/* ready, running or blocked */
    struct  SaveArea sa;	/* hardware state to save */
};

/* Process states */
enum ProcessState { READY, RUNNING, BLOCKED };

/* The current process is the one currently running.  0 means none running */
int current_process;

/* This reserves space for the stack used when in the system */
int SystemStack[SYSTEM_STACK_SIZE];

/* The OS keeps an array of PCB's */
struct ProcessDescriptor pd[MAX_PROCESSES];/* pd[0] is the OS */

/* Interrupt vectors. Four procedures that will act as interrupt handlers. */
char *SystemCallVector = &SystemCallInterruptHandler;
char *TimerVector = &TimerInterruptHandler;
char *DiskVector = &DiskInterruptHandler;
char *ProgremErrorVector = &ProgramErrorInterruptHandler;

