-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswi.c
222 lines (178 loc) · 6.56 KB
/
swi.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include "swi.h"
void swi_handler() {
// mask interrupts (enable atomic) NOT NECESSARY (Done in trap_entry.s)
asm("move.w #0x2700,%SR");
#ifdef DEBUG
/*
rtx_dbug_outs("swi_handler_param1 = ");
rtx_dbug_out_int16((UINT32)swi_handler_param1);
rtx_dbug_outs("\n\r");
rtx_dbug_outs("swi_handler_param2 = ");
rtx_dbug_out_int16((UINT32)swi_handler_param2);
rtx_dbug_outs("\n\r");
rtx_dbug_outs("swi_handler_param3 = ");
rtx_dbug_out_int16((UINT32)swi_handler_param3);
rtx_dbug_outs("\n\r");
rtx_dbug_outs("swi_handler_env = ");
rtx_dbug_out_int16((UINT32)swi_handler_env);
rtx_dbug_outs("\n\r");
*/
/*
if(swi_handler_param1 != NULL){
rtx_dbug_outs("swi_handler_param1 = ");
rtx_dbug_out_int10(swi_handler_param1);
rtx_dbug_outs("\n\r");
}
else {
rtx_dbug_outs("swi_handler_param1 = NULL\n\r");
}
if(swi_handler_param2 != NULL){
rtx_dbug_outs("swi_handler_param2 = ");
rtx_dbug_out_int10(swi_handler_param2);
rtx_dbug_outs("\n\r");
}
else {
rtx_dbug_outs("swi_handler_param2 = NULL\n\r");
}
if(swi_handler_param3 != NULL){
rtx_dbug_outs("swi_handler_param3 = ");
rtx_dbug_out_int10(swi_handler_param3);
rtx_dbug_outs("\n\r");
}
else {
rtx_dbug_outs("swi_handler_param3 = NULL\n\r");
}
if(swi_handler_env != NULL){
rtx_dbug_outs("swi_handler_env = ");
rtx_dbug_out_int16((UINT32)swi_handler_env);
rtx_dbug_outs("\n\r");
}
else {
rtx_dbug_outs("swi_handler_env = NULL\n\r");
}
*/
#endif
/*
// "Passing" parameters from a primitive to swi_handler()
// This is probably unsafe, but as long as it works, it's safe
int current_primitive;
UINT32 swi_handler_param1;
UINT32 swi_handler_param2;
UINT32 swi_handler_param3;
int swi_handler_int_ret;
void* swi_handler_voidp_ret;
*/
switch(current_primitive) {
case SEND_MESSAGE_PRIMITIVE:
// int send_message_handler(int process_ID, void* MessageEnvelope);
current_process->swi_handler_int_ret = send_message_handler((int)swi_handler_param1, swi_handler_env);
// Should be done with param so clearing it. This should still be atomic so should be fine.
swi_handler_param1 = 0;
break;
case RECEIVE_MESSAGE_PRIMITIVE:
// void* receive_message_handler(int* sender_ID);
current_process->swi_handler_voidp_ret = receive_message_handler((int*)swi_handler_param1);
// Should be done with param so clearing it. This should still be atomic so should be fine.
swi_handler_param1 = 0;
break;
case REQUEST_MEMORY_BLOCK_PRIMITIVE:
// void* request_memory_block_handler();
current_process->swi_handler_voidp_ret = request_memory_block_handler();
break;
case RELEASE_MEMORY_BLOCK_PRIMITIVE:
// int release_memory_block_handler(void* MemoryBlock);
current_process->swi_handler_int_ret = release_memory_block_handler((void*)swi_handler_param1);
// Should be done with param so clearing it. This should still be atomic so should be fine.
swi_handler_param1 = 0;
break;
case RELEASE_PROCESSOR_PRIMITIVE:
// int release_processor();
current_process->swi_handler_int_ret = release_processor_handler();
break;
case DELAYED_SEND_PRIMITIVE:
// int delayed_send_handler(int process_ID, void* MessageEnvelope, int delay);
current_process->swi_handler_int_ret = delayed_send_handler((int)swi_handler_param1, (void*)swi_handler_param2, (int)swi_handler_param3);
// Should be done with param so clearing it. This should still be atomic so should be fine.
swi_handler_param1 = 0;
swi_handler_param2 = 0;
swi_handler_param3 = 0;
break;
case SET_PROCESS_PRIORITY_PRIMITIVE:
// int set_process_priority_handler(int process_ID, int priority);
current_process->swi_handler_int_ret = set_process_priority_handler((int)swi_handler_param1, (int)swi_handler_param2);
// Should be done with param so clearing it. This should still be atomic so should be fine.
swi_handler_param1 = 0;
swi_handler_param2 = 0;
break;
case GET_PROCESS_PRIORITY_PRIMITIVE:
// int get_process_priority_handler(int process_ID);
current_process->swi_handler_int_ret = get_process_priority_handler((int)swi_handler_param1);
// Should be done with param so clearing it. This should still be atomic so should be fine.
swi_handler_param1 = 0;
break;
case RTX_NORMAL:
#ifdef DEBUG
rtx_dbug_outs("[RTX_NORMAL]\n\r");
#endif
current_process = NULL;
// asm("move.w #0x2000, %SR");
check_schedule();
break;
case RTX_INIT:
check_schedule();
//asm("move.w #0x2000, %SR");
break;
case CONTEXT_SWITCH_UART:
#ifdef DEBUG
//rtx_dbug_outs("Supposed to context switch to UART\n\r");
#endif
// current_process should not be an i-process
process_switch(get_pcb(UART_I_PID));
// uart_i_process();
//check_schedule();
break;
case CONTEXT_SWITCH_TIMER:
#ifdef DEBUG
//rtx_dbug_outs("Supposed to context switch to timer\n\r");
#endif
// current_process should not be an i-process
process_switch(get_pcb(TIMER_I_PID));
//timer_i_process();
//check_schedule();
break;
default:
// todo: give functionality here
break;
}
if(pcb_is_i_process(current_process) == TRUE) {
return;
} else {
check_schedule();
return;
}
/*
if((pcb_is_i_process(current_process) == FALSE
|| pcb_is_i_process(current_process) == RTX_ERROR)
#ifdef KINSON
&& current_primitive != GET_PROCESS_PRIORITY_PRIMITIVE
#endif
) {
// If current_process == NULL or NOT I-PROCESS
#ifdef DEBUG
rtx_dbug_outs("[SWI_HANDLER] Calling check_schedule()\n\r");
#endif
// unmask interrupts (disable atomic)
//asm("move.w #0x2000,%SR");
check_schedule();
} else if (pcb_is_i_process(current_process) == TRUE) {
// ELSE we are in an I-process
#ifdef DEBUG
rtx_dbug_outs("[SWI_HANDLER] Leaving swi_handler to I-Process\n\r");
#endif
// unmask interrupts (disable atomic)
//asm("move.w #0x2000,%SR");
return;
}
*/
return;
}