-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcb.c
191 lines (151 loc) · 3.71 KB
/
pcb.c
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "pcb.h"
BOOL pcb_is_i_process(pcb* in_pcb) {
if(in_pcb == NULL) {
return RTX_ERROR;
}
return in_pcb->i_process;
}
// me: many of these set functions should only be called in init, or by system processes
int pcb_set_state(pcb* in_pcb, PROCESS_STATE in_state) {
if(!is_valid_state(in_state)) {
return RTX_ERROR;
}
if(in_pcb == NULL) {
return RTX_ERROR;
}
in_pcb->state = in_state;
return RTX_SUCCESS;
}
int pcb_set_priority(pcb* in_pcb, PRIORITY_LEVEL in_plvl) {
if(in_pcb == NULL || !is_valid_priority(in_plvl)) {
return RTX_ERROR;
}
in_pcb->priority = in_plvl;
return RTX_SUCCESS;
}
int pcb_set_stack_pointer(pcb* in_pcb, void* in_sp) {
if(in_pcb == NULL) {
return RTX_ERROR;
}
in_pcb->stack_pointer = in_sp;
return RTX_SUCCESS;
}
int pcb_set_stack_start_addr(pcb* in_pcb, void* in_sp) {
if(in_pcb == NULL) {
return NULL;
}
in_pcb->stack_start_addr = in_sp;
return RTX_SUCCESS;
}
int pcb_set_stack_end_addr(pcb* in_pcb, void* in_sp) {
if(in_pcb == NULL) {
return NULL;
}
in_pcb->stack_end_addr = in_sp;
return RTX_SUCCESS;
}
int pcb_set_code_pointer(pcb* in_pcb, void* in_sp) {
if(in_pcb == NULL) {
return NULL;
}
in_pcb->code_pointer = in_sp;
return RTX_SUCCESS;
}
PROCESS_STATE pcb_get_state(pcb* in_pcb) {
if(in_pcb == NULL) {
return RTX_ERROR;
}
return in_pcb->state;
}
PROCESS_ID pcb_get_pid(pcb* in_pcb) {
if(in_pcb == NULL) {
return RTX_ERROR;
}
return in_pcb->pid;
}
char* pcb_get_name(pcb* in_pcb) {
if(in_pcb == NULL) {
return "NULL";
}
return in_pcb->name;
}
PRIORITY_LEVEL pcb_get_priority(pcb* in_pcb) {
if(in_pcb == NULL) {
return RTX_ERROR;
}
return in_pcb->priority;
}
envl_deque* pcb_get_message_queue(pcb* in_pcb) {
if(in_pcb == NULL) {
return NULL;
}
return &(in_pcb->messages);
}
void* pcb_get_code_pointer(pcb* in_pcb) {
if(in_pcb == NULL) {
return NULL;
}
return in_pcb->code_pointer;
}
void* pcb_get_stack_pointer(pcb* in_pcb) {
if(in_pcb == NULL) {
return NULL;
}
return in_pcb->stack_pointer;
}
void* pcb_get_stack_start_addr(pcb* in_pcb) {
if(in_pcb == NULL) {
return NULL;
}
return in_pcb->stack_start_addr;
}
void* pcb_get_stack_end_addr(pcb* in_pcb) {
if(in_pcb == NULL) {
return NULL;
}
return in_pcb->stack_end_addr;
}
/*
int enque_envl(pcb* in_pcb, envl* in_msgenv) {
if(in_pcb == NULL || in_msgenv == NULL) {
return RTX_ERROR;
}
envl_enque(in_msgenv, pcb_get_message_queue(in_pcb));
return RTX_SUCCESS;
}
envl* dequeue_envl(pcb* in_pcb) {
// should return NULL if nothing to dequeue
return envl_dequeue(pcb_get_message_queue(in_pcb));
}
*/
int pcb_print(pcb* in_pcb) {
if(in_pcb == NULL) {
return RTX_ERROR;
}
/*
rtx_dbug_outs("in_pcb: ");
rtx_dbug_out_int16((UINT32)in_pcb);
rtx_dbug_outs("\n\r");
rtx_dbug_outs("next: ");
rtx_dbug_out_int16((UINT32)in_pcb->next);
rtx_dbug_outs("\n\r");
rtx_dbug_outs("prev: ");
rtx_dbug_out_int16((UINT32)in_pcb->prev);
rtx_dbug_outs("\n\r");
rtx_dbug_outs("pid: ");
rtx_dbug_out_int16(in_pcb->pid);
rtx_dbug_outs("\n\r");
*/
rtx_dbug_outs("name: ");
rtx_dbug_outs(in_pcb->name);
//rtx_dbug_outs("\n\r");
rtx_dbug_outs("; ");
rtx_dbug_outs("priority: ");
rtx_dbug_out_int16(in_pcb->priority);
//rtx_dbug_outs("\n\r");
rtx_dbug_outs("; ");
rtx_dbug_outs("state: ");
rtx_dbug_outs(get_process_state_name(in_pcb->state));
rtx_dbug_outs("\n\r");
return RTX_SUCCESS;
}