comparison src/gpf/frame/cust_os/osx.c @ 6:8b2a9a374324

src/gpf: addition of Magnetite src/gpf2
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 08:15:49 +0000
parents
children
comparison
equal deleted inserted replaced
5:1ea54a97e831 6:8b2a9a374324
1 /*
2 * This C module is a reconstruction based on the disassembly of
3 * osx.obj in osx_na7_db.lib from the Leonardo package.
4 */
5
6 /* reconstructed set of included headers from COFF symtab: */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include "typedefs.h"
11 #include "vsi.h"
12 #include "cust_os.h"
13
14 int osx_config = 2;
15 int _caller;
16 T_OSX_REGISTER _osx_registry[MAX_OSX_QUEUE];
17
18 void
19 int_osx_send_sig(int caller, unsigned long opc, void *signal_ptr,
20 int queue_handle)
21 {
22 T_QMSG Message;
23 int status;
24
25 TRACE_ASSERT(queue_handle != 0);
26 Message.MsgType = MSG_SIGNAL;
27 Message.Msg.Signal.SigOPC = opc;
28 Message.Msg.Signal.SigBuffer = signal_ptr;
29 Message.Msg.Signal.SigLen = sizeof(xSignalHeaderRec);
30 status = vsi_c_send(caller, queue_handle, &Message FILE_LINE_MACRO);
31 TRACE_ASSERT(status == VSI_OK);
32 }
33
34 void
35 osx_send_sig(unsigned long opc, void *signal_ptr, T_ENUM_OS_QUEUE queue_type)
36 {
37 int caller, queue_handle;
38
39 caller = _osx_registry[queue_type].caller;
40 queue_handle = _osx_registry[queue_type].queue_handle;
41 TRACE_ASSERT(queue_handle != 0);
42 int_osx_send_sig(caller, opc, signal_ptr, queue_handle);
43 }
44
45 void
46 int_osx_free_prim(int caller, xSignalHeaderRec *prim_ptr)
47 {
48 vsi_c_free(caller, (T_VOID_STRUCT **) &prim_ptr FILE_LINE_MACRO);
49 }
50
51 void
52 int_osx_send_prim(int caller, xSignalHeaderRec *prim_ptr, int queue_handle)
53 {
54 T_QMSG Message;
55 int status;
56
57 if (osx_config & 1 && prim_ptr->SignalCode == 0x7D) {
58 vsi_c_free(caller, (T_VOID_STRUCT **) &prim_ptr
59 FILE_LINE_MACRO);
60 return;
61 }
62 TRACE_ASSERT(queue_handle != 0);
63 Message.MsgType = MSG_PRIMITIVE;
64 Message.Msg.Primitive.Prim = (T_VOID_STRUCT *) prim_ptr;
65 Message.Msg.Primitive.PrimLen = sizeof(xSignalHeaderRec);
66 status = vsi_c_send(caller, queue_handle, &Message FILE_LINE_MACRO);
67 TRACE_ASSERT(status == VSI_OK);
68 }
69
70 void
71 osx_send_prim(xSignalHeaderRec *prim_ptr, T_ENUM_OS_QUEUE queue_type)
72 {
73 int_osx_send_prim(_osx_registry[queue_type].caller, prim_ptr,
74 _osx_registry[queue_type].queue_handle);
75 }
76
77 xSignalHeaderRec *
78 int_osx_receive_prim(int caller, int queue_handle)
79 {
80 T_QMSG Message;
81 unsigned opc;
82 xSignalHeaderRec *message;
83 int status;
84
85 TRACE_ASSERT(queue_handle != OSX_ERROR);
86 for (;;) {
87 status = vsi_c_await(caller, queue_handle, &Message,
88 0xFFFFFFFF);
89 TRACE_ASSERT(status == VSI_OK);
90 /*
91 * Disassembly reveals that the original code expects
92 * the received message to be a primitive, rather than
93 * a signal or a timeout. If one of the latter comes
94 * in, the original code would go haywire. Hence the
95 * following TRACE_ASSERT is a FreeCalypso addition.
96 */
97 TRACE_ASSERT(Message.MsgType == MSG_PRIMITIVE);
98 message = (xSignalHeaderRec *) Message.Msg.Primitive.Prim;
99 opc = message->SignalCode & 0xFFFF;
100 if (opc == 11 && osx_config & 2)
101 message->SigP = *(DummyStruct **)(message + 1);
102 else
103 message->SigP = (DummyStruct *)(message + 1);
104 if (opc != 0x8000)
105 return(message);
106 vsi_c_primitive(caller, message);
107 }
108 }
109
110 xSignalHeaderRec *
111 osx_receive_prim(T_ENUM_OS_QUEUE queue_type)
112 {
113 return int_osx_receive_prim(_osx_registry[queue_type].caller,
114 _osx_registry[queue_type].queue_handle);
115 }
116
117 void
118 osx_free_prim(xSignalHeaderRec *prim_ptr)
119 {
120 vsi_c_free(_caller, (T_VOID_STRUCT **) &prim_ptr FILE_LINE_MACRO);
121 }
122
123 void
124 int_osx_free_mem(int caller, void *mem_ptr)
125 {
126 int status;
127
128 TRACE_ASSERT(mem_ptr != 0);
129 status = D_FREE(mem_ptr);
130 TRACE_ASSERT(status == VSI_OK);
131 }
132
133 void
134 osx_free_mem(void *mem_ptr)
135 {
136 int_osx_free_mem(_caller, mem_ptr);
137 }
138
139 xSignalHeaderRec *
140 int_osx_alloc_prim(int caller, unsigned long len, int pool_group_handle)
141 {
142 xSignalHeaderRec *prim_ptr;
143
144 prim_ptr = (xSignalHeaderRec *) vsi_c_new(caller,
145 (len & 0xFFFF) + sizeof(xSignalHeaderRec), 0
146 FILE_LINE_MACRO);
147 /* This check is a FreeCalypso addition */
148 TRACE_ASSERT(prim_ptr != 0);
149 prim_ptr->SigP = (DummyStruct *)(prim_ptr + 1);
150 return(prim_ptr);
151 }
152
153 xSignalHeaderRec *
154 osx_alloc_prim(unsigned long len)
155 {
156 xSignalHeaderRec *prim_ptr;
157
158 prim_ptr = (xSignalHeaderRec *) vsi_c_new(_caller,
159 (len & 0xFFFF) + sizeof(xSignalHeaderRec), 0
160 FILE_LINE_MACRO);
161 /* This check is a FreeCalypso addition */
162 TRACE_ASSERT(prim_ptr != 0);
163 prim_ptr->SigP = (DummyStruct *)(prim_ptr + 1);
164 return(prim_ptr);
165 }
166
167 void *
168 int_osx_alloc_mem(int caller, unsigned long len)
169 {
170 void *mem_ptr;
171
172 DMALLOC(mem_ptr, len);
173 TRACE_ASSERT(mem_ptr != 0);
174 return(mem_ptr);
175 }
176
177 void *
178 osx_alloc_mem(unsigned long len)
179 {
180 return int_osx_alloc_mem(_caller, len);
181 }
182
183 int
184 _osx_open(int caller, unsigned short queue_type, int queue_handle)
185 {
186 if (!queue_type && !queue_handle) {
187 _caller = caller;
188 return(OSX_ERROR);
189 }
190 if (queue_type >= MAX_OSX_QUEUE)
191 return(OSX_ERROR);
192 if (_osx_registry[queue_type].queue_handle != queue_handle &&
193 _osx_registry[queue_type].queue_handle != -1)
194 return(OSX_ERROR);
195 _osx_registry[queue_type].queue_handle = queue_handle;
196 _osx_registry[queue_type].caller = caller;
197 return(OSX_OK);
198 }
199
200 void
201 _osx_init(void)
202 {
203 USHORT i;
204
205 for (i = 0; i < MAX_OSX_QUEUE; i++)
206 _osx_registry[i].queue_handle = -1;
207 }
208
209 int
210 _osx_config(const char *config)
211 {
212 if (!strcmp(config, L1S_TRACE_DISABLE)) {
213 osx_config |= 1;
214 return(OSX_OK);
215 }
216 if (!strcmp(config, L1S_TRACE_ENABLE)) {
217 osx_config &= ~1;
218 return(OSX_OK);
219 }
220 if (!strcmp(config, NO_SPECIAL_MPHC_RXLEV_REQ)) {
221 osx_config &= ~2;
222 return(OSX_OK);
223 }
224 return(OSX_ERROR);
225 }