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