aboutsummaryrefslogtreecommitdiff
path: root/include/process.h
blob: 3723ad6784c3489e576248e7fbaba9f04a5f6574 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* @file process.h
* @author Paul Oliver
*
* This module allows access to Salis processes, or procs. Procs are the actual
* organisms in the simulation. They consist of a virtual CPU with 4 registers
* and a stack of 8. The instruction pointer (IP) and seeker pointer (SP)
* coordinate the execution of all instructions. Organisms get rewarded or
* punished, depending on certain conditions.
*/

#ifndef SALIS_PROCESS_H
#define SALIS_PROCESS_H

/** The Process data-structure. The 'SALIS_PROC_ELEMENT' macro helps python
* parse the struct, so don't change it!
*/
struct Process
{
	SALIS_PROC_ELEMENT uint32 mb1a;
	SALIS_PROC_ELEMENT uint32 mb1s;
	SALIS_PROC_ELEMENT uint32 mb2a;
	SALIS_PROC_ELEMENT uint32 mb2s;
	SALIS_PROC_ELEMENT uint32 reward;
	SALIS_PROC_ELEMENT uint32 punish;
	SALIS_PROC_ELEMENT uint32 ip;
	SALIS_PROC_ELEMENT uint32 sp;
	SALIS_PROC_ELEMENT uint32 rax;
	SALIS_PROC_ELEMENT uint32 rbx;
	SALIS_PROC_ELEMENT uint32 rcx;
	SALIS_PROC_ELEMENT uint32 rdx;
	SALIS_PROC_ELEMENT uint32 stack[8];
};

typedef struct Process Process;

void _sal_proc_init(void);
void _sal_proc_quit(void);
void _sal_proc_load_from(FILE *file);
void _sal_proc_save_into(FILE *file);

/** Get process count.
* @return Amount of running (living) processes
*/
SALIS_API uint32 sal_proc_get_count(void);

/** Get reaper queue capacity.
* @return Currently allocated size of reaper queue
*/
SALIS_API uint32 sal_proc_get_capacity(void);

/** Get first process.
* @return Process currently on top of reaper queue
*/
SALIS_API uint32 sal_proc_get_first(void);

/** Get last process.
* @return Process currently on bottom of reaper queue (closest to death)
*/
SALIS_API uint32 sal_proc_get_last(void);

/** Get instructions executed on last cycle.
* @return Amount of executed instructions during the last cycle
*/
SALIS_API uint32 sal_proc_get_instructions_executed(void);

/** Check if process is currently free.
* @param proc_id ID of process whose status we want to check
* @return Status (either free or running) of the process with the given ID
*/
SALIS_API boolean sal_proc_is_free(uint32 proc_id);

/** Get process.
* @param proc_id ID of Process being queried
* @return A copy of the process with the given ID
*/
SALIS_API Process sal_proc_get_proc(uint32 proc_id);

/** Get process data.
* @param proc_id ID of Process being queried
* @param buffer Pre-allocated buffer to store data on [ > sizeof(Process)]
*/
SALIS_API void sal_proc_get_proc_data(uint32 proc_id, uint32_p buffer);

/** Create new process.
* @param address Address we want to allocate our process into
* @param mb1_size Size of the memory block we want to allocate for our process
*/
SALIS_API void sal_proc_create(uint32 address, uint32 mb1_size);

/** Kill process on bottom of reaper queue.
*/
SALIS_API void sal_proc_kill(void);

void _sal_proc_cycle(void);

#endif