comparison src/gpf2/osl/os_pro_ir.c @ 487:91e8dac34ada

src/gpf2/osl: initial import from old freecalypso-sw tree
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 22 Jun 2018 05:56:16 +0000
parents
children dfa8771e84b1
comparison
equal deleted inserted replaced
486:c433cca731a3 487:91e8dac34ada
1 /*
2 * This C module is a reconstruction based on the disassembly of
3 * os_pro.obj in frame_na7_db_ir.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 "gpfconf.h" /* FreeCalypso addition */
10 #include "../../nucleus/nucleus.h"
11 #include "typedefs.h"
12 #include "os.h"
13 #include "gdi.h"
14 #include "os_types.h"
15 #include "os_glob.h"
16
17 extern VOID *TCD_Current_Thread;
18 extern T_OS_TASK_TABLE_ENTRY TaskTable[];
19 extern unsigned os_time_to_tick_multiplier;
20
21 #define OS_NU_TASK_MAGIC 0xdeafbeef
22
23 VOID
24 os_TaskEntry(UNSIGNED TaskHandle, VOID *argv)
25 {
26 TaskTable[TaskHandle].TaskEntry(TaskHandle, 0);
27 }
28
29 GLOBAL LONG
30 os_SuspendTask(OS_HANDLE Caller, ULONG Time)
31 {
32 UNSIGNED SuspendTicks;
33
34 SuspendTicks = TIME_TO_SYSTEM_TICKS(Time);
35 if (!SuspendTicks)
36 SuspendTicks = 1;
37 NU_Sleep(SuspendTicks);
38 return (OS_OK);
39 }
40
41 GLOBAL LONG
42 os_ResumeTask(OS_HANDLE task_handle)
43 {
44 if (NU_Resume_Task(&TaskTable[task_handle].TaskCB.TCB) == NU_SUCCESS)
45 return(OS_OK);
46 else
47 return(OS_ERROR);
48 }
49
50 GLOBAL LONG
51 os_Relinquish(void)
52 {
53 NU_Relinquish();
54 return(OS_OK);
55 }
56
57 GLOBAL OS_HANDLE
58 os_MyHandle(void)
59 {
60 OS_NU_TASK *os_nu_task = (OS_NU_TASK *) TCD_Current_Thread;
61
62 if (os_nu_task && os_nu_task->magic_nr == OS_NU_TASK_MAGIC)
63 return(os_nu_task->handle);
64 else
65 return(OS_NOTASK);
66 }
67
68 GLOBAL LONG
69 os_GetTaskName(OS_HANDLE Caller, OS_HANDLE TaskHandle, char *Name)
70 {
71 if (TaskHandle) {
72 if (TaskHandle > MaxTasks || !TaskTable[TaskHandle].Name[0])
73 return(OS_ERROR);
74 strcpy(Name, TaskTable[TaskHandle].Name);
75 } else if (TCD_Current_Thread) {
76 NU_TASK *curtask = TCD_Current_Thread;
77 strcpy(Name, curtask->tc_name);
78 } else
79 strcpy(Name, "ROOT");
80 return(OS_OK);
81 }
82
83 GLOBAL LONG
84 os_DeferTask(OS_HANDLE task_handle, OS_TIME time)
85 {
86 if (NU_Suspend_Task(&TaskTable[task_handle].TaskCB.TCB) == NU_SUCCESS)
87 return(OS_OK);
88 else
89 return(OS_ERROR);
90 }
91
92 GLOBAL LONG
93 os_CheckTaskStack(OS_HANDLE Handle)
94 {
95 register void *sp asm("sp");
96
97 if (*TaskTable[Handle].Stack != GUARD_PATTERN)
98 return(OS_ERROR);
99 if (TCD_Current_Thread) {
100 NU_TASK *curtask = TCD_Current_Thread;
101 if (sp < curtask->tc_stack_start)
102 return(OS_ERROR);
103 }
104 return(OS_OK);
105 }