FreeCalypso > hg > fc-tourmaline
comparison src/gpf/osl/os_pro_fl.c @ 0:4e78acac3d88
src/{condat,cs,gpf,nucleus}: import from Selenite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Oct 2020 06:23:26 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4e78acac3d88 |
---|---|
1 /* | |
2 * This C module is a reconstruction based on the disassembly of | |
3 * os_pro.obj in frame_na7_db_fl.lib from the Leonardo package. | |
4 */ | |
5 | |
6 /* set of included headers from COFF symtab: */ | |
7 #include <stdio.h> | |
8 #include <string.h> | |
9 #include "nucleus.h" | |
10 #include "typedefs.h" | |
11 #include "os.h" | |
12 #include "gdi.h" | |
13 #include "os_types.h" | |
14 #include "os_glob.h" | |
15 | |
16 typedef unsigned char u_char; | |
17 | |
18 extern VOID *TCD_Current_Thread; | |
19 extern T_OS_TASK_TABLE_ENTRY TaskTable[]; | |
20 extern VOID os_TaskEntry(UNSIGNED, VOID *); | |
21 | |
22 static NU_SEMAPHORE ProSemCB; | |
23 | |
24 #define OS_NU_TASK_MAGIC 0xdeafbeef | |
25 | |
26 static int | |
27 os_GetTaskEntry(USHORT Index, OS_HANDLE *Handle) | |
28 { | |
29 static USHORT Idx; | |
30 | |
31 if (Index == FIRST_ENTRY) | |
32 Idx = 0; | |
33 if (Index == FIRST_ENTRY || Index == NEXT_ENTRY) { | |
34 while (++Idx <= MaxTasks && !TaskTable[Idx].Name[0]) | |
35 ; | |
36 } else | |
37 Idx = Index; | |
38 if (Idx <= MaxTasks && TaskTable[Idx].Name[0]) { | |
39 *Handle = Idx; | |
40 return(0); | |
41 } else | |
42 return(-1); | |
43 } | |
44 | |
45 GLOBAL LONG | |
46 os_TaskInformation(USHORT Index, char *Buffer) | |
47 { | |
48 DATA_ELEMENT TaskStatus; | |
49 OPTION Prio, Preempt; | |
50 UNSIGNED Count, TimeSlice, Size, MinStack; | |
51 OS_HANDLE Handle; | |
52 CHAR Name[NU_MAX_NAME]; | |
53 u_char *StackBase, *sp; | |
54 USHORT Untouched; | |
55 | |
56 if (os_GetTaskEntry(Index, &Handle) < 0) | |
57 return(OS_ERROR); | |
58 if (NU_Task_Information(&TaskTable[Handle].TaskCB.TCB, Name, | |
59 &TaskStatus, &Count, &Prio, &Preempt, | |
60 &TimeSlice, (VOID **) &StackBase, | |
61 &Size, &MinStack) != NU_SUCCESS) | |
62 return(OS_ERROR); | |
63 Untouched = 0; | |
64 for (sp = StackBase; sp < StackBase + Size; sp++) { | |
65 if (*sp != INITIAL_STACK_VALUE) | |
66 break; | |
67 Untouched++; | |
68 } | |
69 sprintf(Buffer, | |
70 "Name:%s Stat:%d Count:%ld Prio:%d Stack:%lx Size:%ld Untouched:%d", | |
71 Name, TaskStatus, Count, 255 - Prio, (ULONG) StackBase, | |
72 (LONG) Size, Untouched); | |
73 return(OS_OK); | |
74 } | |
75 | |
76 GLOBAL LONG | |
77 os_StopTask(OS_HANDLE Caller, OS_HANDLE TaskHandle) | |
78 { | |
79 if (NU_Suspend_Task(&TaskTable[TaskHandle].TaskCB.TCB) == NU_SUCCESS) | |
80 return(OS_OK); | |
81 else | |
82 return(OS_ERROR); | |
83 } | |
84 | |
85 GLOBAL LONG | |
86 os_StartTask(OS_HANDLE Caller, OS_HANDLE TaskHandle, ULONG Value) | |
87 { | |
88 if (NU_Resume_Task(&TaskTable[TaskHandle].TaskCB.TCB) == NU_SUCCESS) | |
89 return(OS_OK); | |
90 else | |
91 return(OS_ERROR); | |
92 } | |
93 | |
94 GLOBAL LONG | |
95 os_ProInit(void) | |
96 { | |
97 USHORT i; | |
98 | |
99 if (NU_Create_Semaphore(&ProSemCB, "PROSEM", 1, NU_PRIORITY) | |
100 != NU_SUCCESS) | |
101 return(OS_ERROR); | |
102 for (i = 1; i <= MaxTasks; i++) | |
103 memset(&TaskTable[i], 0, sizeof(T_OS_TASK_TABLE_ENTRY)); | |
104 return(OS_OK); | |
105 } | |
106 | |
107 GLOBAL unsigned char | |
108 os_GetTaskState(OS_HANDLE Caller, OS_HANDLE Handle) | |
109 { | |
110 if (TaskTable[Handle].Name[0]) | |
111 return(TaskTable[Handle].TaskCB.TCB.tc_status); | |
112 else | |
113 return(255); | |
114 } | |
115 | |
116 GLOBAL LONG | |
117 os_GetTaskHandle(OS_HANDLE Caller, char *Name, OS_HANDLE *TaskHandle) | |
118 { | |
119 USHORT i; | |
120 | |
121 if (!Name) { | |
122 OS_NU_TASK *os_nu_task = (OS_NU_TASK *) TCD_Current_Thread; | |
123 | |
124 if (os_nu_task && os_nu_task->magic_nr == OS_NU_TASK_MAGIC) | |
125 *TaskHandle = os_nu_task->handle; | |
126 else | |
127 *TaskHandle = OS_NOTASK; | |
128 return(OS_OK); | |
129 } | |
130 for (i = 1; i <= MaxTasks; i++) | |
131 if (TaskTable[i].Name[0] && | |
132 !strncmp(Name, TaskTable[i].Name, RESOURCE_NAMELEN - 1)) { | |
133 *TaskHandle = i; | |
134 return(OS_OK); | |
135 } | |
136 return(OS_ERROR); | |
137 } | |
138 | |
139 GLOBAL LONG | |
140 os_GetTaskData(OS_HANDLE Handle, unsigned **tcb, | |
141 u_char **stackbegin, u_char **stackend) | |
142 { | |
143 NU_TASK *task; | |
144 | |
145 if (!TaskTable[Handle].Name[0]) | |
146 return(OS_ERROR); | |
147 task = &TaskTable[Handle].TaskCB.TCB; | |
148 *tcb = (unsigned *) task; | |
149 *stackbegin = (u_char *) task->tc_stack_start; | |
150 *stackend = (u_char *) task->tc_stack_end; | |
151 return(OS_OK); | |
152 } | |
153 | |
154 GLOBAL LONG | |
155 os_GetScheduleCount(OS_HANDLE task_handle, int *schedule_count) | |
156 { | |
157 NU_TASK *task_cb; | |
158 | |
159 if (task_handle > MaxTasks) | |
160 return(OS_ERROR); | |
161 if (!TaskTable[task_handle].Name[0]) | |
162 return(OS_ERROR); | |
163 if (task_handle == OS_NOTASK) | |
164 task_cb = (NU_TASK *) TCD_Current_Thread; | |
165 else | |
166 task_cb = &TaskTable[task_handle].TaskCB.TCB; | |
167 *schedule_count = task_cb->tc_scheduled; | |
168 return(OS_OK); | |
169 } | |
170 | |
171 GLOBAL LONG | |
172 os_DestroyTask(OS_HANDLE Caller, OS_HANDLE TaskHandle) | |
173 { | |
174 STATUS sts; | |
175 | |
176 if (NU_Terminate_Task(&TaskTable[TaskHandle].TaskCB.TCB) != NU_SUCCESS) | |
177 return(OS_ERROR); | |
178 if (NU_Delete_Task(&TaskTable[TaskHandle].TaskCB.TCB) != NU_SUCCESS) | |
179 return(OS_ERROR); | |
180 if (os_DeallocateMemory(Caller, TaskTable[TaskHandle].Stack) != OS_OK) | |
181 return(OS_ERROR); | |
182 sts = NU_Obtain_Semaphore(&ProSemCB, NU_SUSPEND); | |
183 TaskTable[TaskHandle].Name[0] = 0; | |
184 if (sts == NU_SUCCESS) | |
185 NU_Release_Semaphore(&ProSemCB); | |
186 return(OS_OK); | |
187 } | |
188 | |
189 GLOBAL LONG | |
190 os_CreateTask(OS_HANDLE Caller, char *Name, | |
191 void (*TaskEntry)(OS_HANDLE, ULONG), ULONG StackSize, | |
192 USHORT Priority, OS_HANDLE *TaskHandle, OS_HANDLE MemPoolHandle) | |
193 { | |
194 STATUS sem_sts; | |
195 USHORT Handle; | |
196 u_char *stack; | |
197 | |
198 sem_sts = NU_Obtain_Semaphore(&ProSemCB, NU_SUSPEND); | |
199 for (Handle = 1; Handle <= MaxTasks; Handle++) | |
200 if (!TaskTable[Handle].Name[0]) | |
201 break; | |
202 if (Handle > MaxTasks) { | |
203 return_error: if (sem_sts == NU_SUCCESS) | |
204 NU_Release_Semaphore(&ProSemCB); | |
205 return(OS_ERROR); | |
206 } | |
207 if (os_AllocateMemory(Handle, &TaskTable[Handle].Stack, StackSize + 4, | |
208 0, MemPoolHandle) != OS_OK) | |
209 goto return_error; | |
210 stack = (u_char *)TaskTable[Handle].Stack + 4; | |
211 memset(stack, INITIAL_STACK_VALUE, StackSize); | |
212 *TaskTable[Handle].Stack = GUARD_PATTERN; | |
213 if (NU_Create_Task(&TaskTable[Handle].TaskCB.TCB, Name, os_TaskEntry, | |
214 Handle, 0, stack, StackSize, | |
215 255 - Priority, 0, NU_PREEMPT, NU_NO_START) | |
216 != NU_SUCCESS) | |
217 goto return_error; | |
218 strncpy(TaskTable[Handle].Name, Name, RESOURCE_NAMELEN); | |
219 TaskTable[Handle].Name[RESOURCE_NAMELEN-1] = 0; | |
220 TaskTable[Handle].TaskEntry = TaskEntry; | |
221 TaskTable[Handle].TaskCB.magic_nr = OS_NU_TASK_MAGIC; | |
222 TaskTable[Handle].TaskCB.handle = Handle; | |
223 *TaskHandle = Handle; | |
224 if (sem_sts == NU_SUCCESS) | |
225 NU_Release_Semaphore(&ProSemCB); | |
226 return(OS_OK); | |
227 } | |
228 | |
229 GLOBAL LONG | |
230 os_ChangePreemption(char preempt) | |
231 { | |
232 if (NU_Change_Preemption(preempt) == NU_SUCCESS) | |
233 return(OS_OK); | |
234 else | |
235 return(OS_ERROR); | |
236 } |