comparison src/gpf/osl/os_isr.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_isr.obj in frame_na7_db_fl.lib from the Leonardo package.
4 */
5
6 /* set of included headers from COFF symtab: */
7 #include <string.h>
8 #include "nucleus.h"
9 #include "typedefs.h"
10 #include "os.h"
11 #include "gdi.h"
12 #include "os_types.h"
13 #include "os_glob.h"
14
15 typedef unsigned char u_char;
16
17 extern T_OS_OSISR_TABLE_ENTRY OSISRTable[];
18 extern OS_HANDLE os_int_pool_handle;
19
20 GLOBAL LONG
21 os_isr_init(void)
22 {
23 USHORT i;
24
25 for (i = 1; i <= MaxOSISRs; i++)
26 OSISRTable[i].name[0] = 0;
27 return(OS_OK);
28 }
29
30 GLOBAL LONG
31 os_SetInterruptState(OS_INT_STATE new_state, OS_INT_STATE *old_state)
32 {
33 INT state;
34
35 if (new_state)
36 state = NU_ENABLE_INTERRUPTS;
37 else
38 state = NU_DISABLE_INTERRUPTS;
39 state = NU_Control_Interrupts(state);
40 if (state & 0xFF)
41 *old_state = 0;
42 else
43 *old_state = 1;
44 return(OS_OK);
45 }
46
47 GLOBAL LONG
48 os_EnableInterrupts(OS_INT_STATE *old_state)
49 {
50 INT state;
51
52 state = NU_Control_Interrupts(NU_ENABLE_INTERRUPTS);
53 if (state & 0xFF)
54 *old_state = 0;
55 else
56 *old_state = 1;
57 return(OS_OK);
58 }
59
60 GLOBAL LONG
61 os_DisableInterrupts(OS_INT_STATE *old_state)
62 {
63 INT state;
64
65 state = NU_Control_Interrupts(NU_DISABLE_INTERRUPTS);
66 if (state & 0xFF)
67 *old_state = 0;
68 else
69 *old_state = 1;
70 return(OS_OK);
71 }
72
73 GLOBAL LONG
74 os_DeleteOSISR(OS_HANDLE hisr_handle)
75 {
76 OS_INT_STATE old_state, state;
77
78 if (hisr_handle <= 0 || hisr_handle > MaxOSISRs)
79 return(OS_ERROR);
80 if (OSISRTable[hisr_handle].hisr_cb.tc_activation_count)
81 return(OS_ERROR);
82 os_DisableInterrupts(&old_state);
83 if (os_DeallocateMemory(os_MyHandle(), OSISRTable[hisr_handle].stack)
84 == OS_ERROR) {
85 error: os_SetInterruptState(old_state, &state);
86 return(OS_ERROR);
87 }
88 if (NU_Delete_HISR(&OSISRTable[hisr_handle].hisr_cb) != NU_SUCCESS)
89 goto error;
90 OSISRTable[hisr_handle].name[0] = 0;
91 os_SetInterruptState(old_state, &state);
92 return(OS_OK);
93 }
94
95 GLOBAL LONG
96 os_CreateOSISR(char *name, void (*OSISR_entry)(void),
97 int stacksize, int priority,
98 int flags, OS_HANDLE *hisr_handle)
99 {
100 OS_HANDLE handle;
101 T_VOID_STRUCT *hisr_stack;
102 OS_INT_STATE old_state, state;
103
104 if (priority < 0 || priority > 2)
105 return(OS_ERROR);
106 priority = 2 - priority;
107 os_DisableInterrupts(&old_state);
108 for (handle = 1; handle <= MaxOSISRs; handle++)
109 if (!strncmp(OSISRTable[handle].name, name,
110 RESOURCE_NAMELEN - 1)) {
111 error: os_SetInterruptState(old_state, &state);
112 return(OS_ERROR);
113 }
114 for (handle = 1; handle <= MaxOSISRs; handle++)
115 if (!OSISRTable[handle].name[0])
116 break;
117 if (handle > MaxOSISRs)
118 goto error;
119 if (os_AllocateMemory(os_MyHandle(), &hisr_stack, stacksize,
120 0xFFFFFFFF, os_int_pool_handle) == OS_ERROR)
121 goto error;
122 memset((u_char *)hisr_stack, INITIAL_STACK_VALUE, stacksize);
123 *hisr_stack = GUARD_PATTERN;
124 if (NU_Create_HISR(&OSISRTable[handle].hisr_cb, name, OSISR_entry,
125 priority, (VOID *)hisr_stack, stacksize)
126 != NU_SUCCESS)
127 goto error;
128 strncpy(OSISRTable[handle].name, name, RESOURCE_NAMELEN);
129 OSISRTable[handle].name[RESOURCE_NAMELEN-1] = 0;
130 OSISRTable[handle].stack = hisr_stack;
131 *hisr_handle = handle;
132 os_SetInterruptState(old_state, &state);
133 return(OS_OK);
134 }
135
136 GLOBAL LONG
137 os_ActivateOSISR(OS_HANDLE hisr_handle)
138 {
139 if (hisr_handle <= 0 || hisr_handle > MaxOSISRs)
140 return(OS_ERROR);
141 if (NU_Activate_HISR(&OSISRTable[hisr_handle].hisr_cb) == NU_SUCCESS)
142 return(OS_OK);
143 else
144 return(OS_ERROR);
145 }