]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/29k-share/udi/udi2go32.c
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / 29k-share / udi / udi2go32.c
1 /*
2
3 Interface from UDI calls in 32-bit mode to go32 in 16-bit mode.
4 Communication is done through a single interrupt vector, which passes
5 data through two linear buffers.
6
7 Call:
8 AH = 0xfe
9 AL = UDI function number
10 ECX = IN length
11 ESI = pointer to IN buffer
12 EDI = pointer to OUT buffer
13
14 Return:
15 EAX = return value of UDI function
16
17 Vector:
18 0x21
19
20 */
21 #ifdef __GO32__
22
23 #include <stdlib.h>
24 #include "udiproc.h"
25 #include "udisoc.h"
26
27 char dfe_errmsg[500];
28
29 static char in_buffer[4096];
30 static char out_buffer[4096];
31 static char *in_ptr;
32 static char *out_ptr;
33
34 #define IN_INIT() in_ptr = in_buffer
35 #define IN_VAL(t,v) *((t *)in_ptr)++ = v
36 #define IN_DATA(ptr, cnt) memcpy(in_ptr, ptr, cnt), in_ptr += cnt
37
38 #define OUT_INIT() out_ptr = out_buffer
39 #define OUT_VAL(t) (*((t *)out_ptr)++)
40 #define OUT_DATA(ptr, cnt) memcpy(ptr, out_ptr, cnt), out_ptr += cnt
41
42 static int DO_CALL(int function)
43 {
44 asm("pushl %esi");
45 asm("pushl %edi");
46 asm("movb %0, %%al" : : "g" (function));
47 asm("movl _in_ptr, %ecx");
48 asm("movl $_in_buffer, %esi");
49 asm("subl %esi, %ecx");
50 asm("movl $_out_buffer, %edi");
51 asm("movb $0xfe, %ah");
52 asm("int $0x21");
53 asm("popl %edi");
54 asm("popl %esi");
55 }
56
57 /*----------------------------------------------------------------------*/
58
59 #ifdef TEST_UDI
60 int main()
61 {
62 int r;
63 long p2;
64 short p1;
65 IN_INIT();
66 IN_VAL(long, 11111111);
67 IN_VAL(short, 2222);
68 IN_DATA("Hello, world\n", 17);
69
70 r = DO_CALL(42);
71
72 OUT_INIT();
73 p1 = OUT_VAL(short);
74 p2 = OUT_VAL(long);
75 printf("main: p1=%d p2=%d rv=%d\n", p1, p2, r);
76 return r;
77 }
78 #endif
79
80 /*----------------------------------------------------------------------*/
81
82 unsupported(char *s)
83 {
84 printf("unsupported UDI host call %s\n", s);
85 abort();
86 }
87
88 UDIError UDIConnect (
89 char *Configuration, /* In */
90 UDISessionId *Session /* Out */
91 )
92 {
93 int r;
94 out_buffer[0] = 0; /* DJ - test */
95 IN_INIT();
96 IN_DATA(Configuration, strlen(Configuration)+1);
97
98 r = DO_CALL(UDIConnect_c);
99
100 OUT_INIT();
101 *Session = OUT_VAL(UDISessionId);
102 return r;
103 }
104
105 UDIError UDIDisconnect (
106 UDISessionId Session, /* In */
107 UDIBool Terminate /* In */
108 )
109 {
110 int r;
111 IN_INIT();
112 IN_VAL(UDISessionId, Session);
113 IN_VAL(UDIBool, Terminate);
114
115 return DO_CALL(UDIDisconnect_c);
116 }
117
118 UDIError UDISetCurrentConnection (
119 UDISessionId Session /* In */
120 )
121 {
122 IN_INIT();
123 IN_VAL(UDISessionId, Session);
124
125 return DO_CALL(UDISetCurrentConnection_c);
126 }
127
128 UDIError UDICapabilities (
129 UDIUInt32 *TIPId, /* Out */
130 UDIUInt32 *TargetId, /* Out */
131 UDIUInt32 DFEId, /* In */
132 UDIUInt32 DFE, /* In */
133 UDIUInt32 *TIP, /* Out */
134 UDIUInt32 *DFEIPCId, /* Out */
135 UDIUInt32 *TIPIPCId, /* Out */
136 char *TIPString /* Out */
137 )
138 {
139 int r;
140 IN_INIT();
141 IN_VAL(UDIUInt32, DFEId);
142 IN_VAL(UDIUInt32, DFE);
143 r = DO_CALL(UDICapabilities_c);
144 OUT_INIT();
145 *TIPId = OUT_VAL(UDIUInt32);
146 *TargetId = OUT_VAL(UDIUInt32);
147 *TIP = OUT_VAL(UDIUInt32);
148 *DFEIPCId = OUT_VAL(UDIUInt32);
149 *TIPIPCId = OUT_VAL(UDIUInt32);
150 strcpy(TIPString, out_ptr);
151 return r;
152 }
153
154 UDIError UDIEnumerateTIPs (
155 UDIInt (*UDIETCallback) /* In */
156 ( char *Configuration ) /* In to callback() */
157 )
158 {
159 UDIETCallback("montip.exe");
160 }
161
162 UDIError UDIGetErrorMsg (
163 UDIError ErrorCode, /* In */
164 UDISizeT MsgSize, /* In */
165 char *Msg, /* Out */
166 UDISizeT *CountDone /* Out */
167 )
168 {
169 int r;
170 if (MsgSize > 4000)
171 MsgSize = 4000;
172 IN_INIT();
173 IN_VAL(UDIError, ErrorCode);
174 IN_VAL(UDISizeT, MsgSize);
175
176 r = DO_CALL(UDIGetErrorMsg_c);
177
178 OUT_INIT();
179 *CountDone = OUT_VAL(UDISizeT);
180 OUT_DATA(Msg, *CountDone);
181 return r;
182 }
183
184 UDIError UDIGetTargetConfig (
185 UDIMemoryRange KnownMemory[], /* Out */
186 UDIInt *NumberOfRanges, /* In/Out */
187 UDIUInt32 ChipVersions[], /* Out */
188 UDIInt *NumberOfChips /* In/Out */
189 )
190 {
191 int r, i;
192 int nr = *NumberOfRanges;
193 int nc = *NumberOfChips;
194 IN_INIT();
195 IN_VAL(UDIInt, *NumberOfRanges);
196 IN_VAL(UDIInt, *NumberOfChips);
197 r = DO_CALL(UDIGetTargetConfig_c);
198 if (r == UDIErrorIncomplete)
199 return r;
200 OUT_INIT();
201 *NumberOfRanges = OUT_VAL(UDIInt);
202 *NumberOfChips = OUT_VAL(UDIInt);
203 for (i=0; i<nr; i++)
204 {
205 KnownMemory[i].Space = OUT_VAL(short);
206 KnownMemory[i].Offset = OUT_VAL(CPUOffset);
207 KnownMemory[i].Size = OUT_VAL(CPUSizeT);
208 }
209 for (i=0; i<nc; i++)
210 {
211 ChipVersions[i] = OUT_VAL(UDIUInt32);
212 }
213 return r;
214 }
215
216 UDIError UDICreateProcess (
217 UDIPId *PId /* Out */
218 )
219 {
220 int r = DO_CALL(UDICreateProcess_c);
221
222 OUT_INIT();
223 *PId = OUT_VAL(UDIPId);
224
225 return r;
226 }
227
228 UDIError UDISetCurrentProcess (
229 UDIPId PId /* In */
230 )
231 {
232 IN_INIT();
233 IN_VAL(UDIPId, PId);
234
235 return DO_CALL(UDISetCurrentProcess_c);
236 }
237
238 UDIError UDIDestroyProcess (
239 UDIPId PId /* In */
240 )
241 {
242 IN_INIT();
243 IN_VAL(UDIPId, PId);
244
245 return DO_CALL(UDIDestroyProcess_c);
246 }
247
248 UDIError UDIInitializeProcess (
249 UDIMemoryRange ProcessMemory[], /* In */
250 UDIInt NumberOfRanges, /* In */
251 UDIResource EntryPoint, /* In */
252 CPUSizeT StackSizes[], /* In */
253 UDIInt NumberOfStacks, /* In */
254 char *ArgString /* In */
255 )
256 {
257 int i, r;
258 IN_INIT();
259 IN_VAL(UDIInt, NumberOfRanges);
260 for (i=0; i<NumberOfRanges; i++)
261 {
262 IN_VAL(short, ProcessMemory[i].Space);
263 IN_VAL(CPUOffset, ProcessMemory[i].Offset);
264 IN_VAL(CPUSizeT, ProcessMemory[i].Size);
265 }
266 IN_VAL(short, EntryPoint.Space);
267 IN_VAL(CPUOffset, EntryPoint.Offset);
268 IN_VAL(UDIInt, NumberOfStacks);
269 for (i=0; i<NumberOfStacks; i++)
270 IN_VAL(CPUSizeT, StackSizes[i]);
271 IN_DATA(ArgString, strlen(ArgString)+1);
272
273 return DO_CALL(UDIInitializeProcess_c);
274 }
275
276 UDIError UDIRead (
277 UDIResource From, /* In */
278 UDIHostMemPtr To, /* Out */
279 UDICount Count, /* In */
280 UDISizeT Size, /* In */
281 UDICount *CountDone, /* Out */
282 UDIBool HostEndian /* In */
283 )
284 {
285 int cleft = Count, cthis, dthis;
286 int cdone = 0, r, bsize=2048/Size;
287
288 while (cleft)
289 {
290 cthis = (cleft<bsize) ? cleft : bsize;
291 IN_INIT();
292 IN_VAL(short, From.Space);
293 IN_VAL(CPUOffset, From.Offset);
294 IN_VAL(UDICount, cthis);
295 IN_VAL(UDISizeT, Size);
296 IN_VAL(UDIBool, HostEndian);
297
298 r = DO_CALL(UDIRead_c);
299
300 OUT_INIT();
301 dthis = OUT_VAL(UDICount);
302 OUT_DATA(To, dthis*Size);
303 cdone += dthis;
304 To += dthis*Size;
305
306 if (r != UDINoError)
307 {
308 *CountDone = cdone;
309 return r;
310 }
311 cleft -= cthis;
312 }
313 *CountDone = cdone;
314 return UDINoError;
315 }
316
317 UDIError UDIWrite (
318 UDIHostMemPtr From, /* In */
319 UDIResource To, /* In */
320 UDICount Count, /* In */
321 UDISizeT Size, /* In */
322 UDICount *CountDone, /* Out */
323 UDIBool HostEndian /* In */
324 )
325 {
326 int cleft = Count, cthis, dthis;
327 int cdone = 0, r, bsize=2048/Size;
328
329 while (cleft)
330 {
331 cthis = (cleft<bsize) ? cleft : bsize;
332 IN_INIT();
333 IN_VAL(short, To.Space);
334 IN_VAL(CPUOffset, To.Offset);
335 IN_VAL(UDICount, cthis);
336 IN_VAL(UDISizeT, Size);
337 IN_VAL(UDIBool, HostEndian);
338 IN_DATA(From, cthis*Size);
339 From += cthis*Size;
340
341 r = DO_CALL(UDIWrite_c);
342
343 OUT_INIT();
344 cdone += OUT_VAL(UDICount);
345
346 if (r != UDINoError)
347 {
348 *CountDone = cdone;
349 return r;
350 }
351 cleft -= cthis;
352 }
353 *CountDone = cdone;
354 return UDINoError;
355 }
356
357 UDIError UDICopy (
358 UDIResource From, /* In */
359 UDIResource To, /* In */
360 UDICount Count, /* In */
361 UDISizeT Size, /* In */
362 UDICount *CountDone, /* Out */
363 UDIBool Direction /* In */
364 )
365 {
366 int r;
367 IN_INIT();
368 IN_VAL(short, From.Space);
369 IN_VAL(CPUOffset, From.Offset);
370 IN_VAL(short, To.Space);
371 IN_VAL(CPUOffset, To.Offset);
372 IN_VAL(UDICount, Count);
373 IN_VAL(UDISizeT, Size);
374 IN_VAL(UDIBool, Direction);
375
376 r = DO_CALL(UDICopy_c);
377
378 OUT_INIT();
379 *CountDone = OUT_VAL(UDICount);
380
381 return r;
382 }
383
384 UDIError UDIExecute (
385 void
386 )
387 {
388 return DO_CALL(UDIExecute_c);
389 }
390
391 UDIError UDIStep (
392 UDIUInt32 Steps, /* In */
393 UDIStepType StepType, /* In */
394 UDIRange Range /* In */
395 )
396 {
397 IN_INIT();
398 IN_VAL(UDIUInt32, Steps);
399 IN_VAL(UDIStepType, StepType);
400 IN_VAL(UDIRange, Range);
401
402 return DO_CALL(UDIStep_c);
403 }
404
405 UDIVoid UDIStop (
406 void
407 )
408 {
409 DO_CALL(UDIStop_c);
410 }
411
412 UDIError UDIWait (
413 UDIInt32 MaxTime, /* In */
414 UDIPId *PId, /* Out */
415 UDIUInt32 *StopReason /* Out */
416 )
417 {
418 int r;
419 IN_INIT();
420 IN_VAL(UDIInt32, MaxTime);
421 r = DO_CALL(UDIWait_c);
422 OUT_INIT();
423 *PId = OUT_VAL(UDIPId);
424 *StopReason = OUT_VAL(UDIUInt32);
425 return r;
426 }
427
428 UDIError UDISetBreakpoint (
429 UDIResource Addr, /* In */
430 UDIInt32 PassCount, /* In */
431 UDIBreakType Type, /* In */
432 UDIBreakId *BreakId /* Out */
433 )
434 {
435 int r;
436 IN_INIT();
437 IN_VAL(short, Addr.Space);
438 IN_VAL(CPUOffset, Addr.Offset);
439 IN_VAL(UDIInt32, PassCount);
440 IN_VAL(UDIBreakType, Type);
441
442 r = DO_CALL(UDISetBreakpoint_c);
443
444 OUT_INIT();
445 *BreakId = OUT_VAL(UDIBreakId);
446 return r;
447 }
448
449 UDIError UDIQueryBreakpoint (
450 UDIBreakId BreakId, /* In */
451 UDIResource *Addr, /* Out */
452 UDIInt32 *PassCount, /* Out */
453 UDIBreakType *Type, /* Out */
454 UDIInt32 *CurrentCount /* Out */
455 )
456 {
457 int r;
458 IN_INIT();
459 IN_VAL(UDIBreakId, BreakId);
460
461 r = DO_CALL(UDIQueryBreakpoint_c);
462
463 OUT_INIT();
464 Addr->Space = OUT_VAL(short);
465 Addr->Offset = OUT_VAL(CPUOffset);
466 *PassCount = OUT_VAL(UDIInt32);
467 *Type = OUT_VAL(UDIBreakType);
468 *CurrentCount = OUT_VAL(UDIInt32);
469
470 return r;
471 }
472
473 UDIError UDIClearBreakpoint (
474 UDIBreakId BreakId /* In */
475 )
476 {
477 IN_INIT();
478 IN_VAL(UDIBreakId, BreakId);
479
480 return DO_CALL(UDIClearBreakpoint_c);
481 }
482
483 UDIError UDIGetStdout (
484 UDIHostMemPtr Buf, /* Out */
485 UDISizeT BufSize, /* In */
486 UDISizeT *CountDone /* Out */
487 )
488 {
489 int r;
490 IN_INIT();
491 if (BufSize > 4000)
492 BufSize = 4000;
493 IN_VAL(UDISizeT,BufSize);
494 r = DO_CALL(UDIGetStdout_c);
495 OUT_INIT();
496 *CountDone = OUT_VAL(UDISizeT);
497 if (*CountDone <= BufSize)
498 OUT_DATA(Buf, *CountDone);
499 return r;
500 }
501
502 UDIError UDIGetStderr (
503 UDIHostMemPtr Buf, /* Out */
504 UDISizeT BufSize, /* In */
505 UDISizeT *CountDone /* Out */
506 )
507 {
508 int r;
509 IN_INIT();
510 if (BufSize > 4000)
511 BufSize = 4000;
512 IN_VAL(UDISizeT,BufSize);
513 r = DO_CALL(UDIGetStderr_c);
514 OUT_INIT();
515 *CountDone = OUT_VAL(UDISizeT);
516 OUT_DATA(Buf, *CountDone);
517 return r;
518 }
519
520 UDIError UDIPutStdin (
521 UDIHostMemPtr Buf, /* In */
522 UDISizeT Count, /* In */
523 UDISizeT *CountDone /* Out */
524 )
525 {
526 int r;
527 IN_INIT();
528 if (Count > 4000)
529 Count = 4000;
530 IN_VAL(UDISizeT,Count);
531 IN_DATA(Buf, Count);
532 r = DO_CALL(UDIPutStdin_c);
533 OUT_INIT();
534 *CountDone = OUT_VAL(UDISizeT);
535 return r;
536 }
537
538 UDIError UDIStdinMode (
539 UDIMode *Mode /* Out */
540 )
541 {
542 int r;
543 IN_INIT();
544 r = DO_CALL(UDIStdinMode_c);
545 OUT_INIT();
546 *Mode = OUT_VAL(UDIMode);
547 return r;
548 }
549
550 UDIError UDIPutTrans (
551 UDIHostMemPtr Buf, /* In */
552 UDISizeT Count, /* In */
553 UDISizeT *CountDone /* Out */
554 )
555 {
556 int r;
557 IN_INIT();
558 if (Count > 4000)
559 Count = 4000;
560 IN_VAL(UDISizeT,Count);
561 IN_DATA(Buf, Count);
562 r = DO_CALL(UDIPutTrans_c);
563 OUT_INIT();
564 *CountDone = OUT_VAL(UDISizeT);
565 return r;
566 }
567
568 UDIError UDIGetTrans (
569 UDIHostMemPtr Buf, /* Out */
570 UDISizeT BufSize, /* In */
571 UDISizeT *CountDone /* Out */
572 )
573 {
574 int r;
575 IN_INIT();
576 if (BufSize > 4000)
577 BufSize = 4000;
578 IN_VAL(UDISizeT,BufSize);
579 r = DO_CALL(UDIGetTrans_c);
580 OUT_INIT();
581 *CountDone = OUT_VAL(UDISizeT);
582 OUT_DATA(Buf, *CountDone);
583 return r;
584 }
585
586 UDIError UDITransMode (
587 UDIMode *Mode /* Out */
588 )
589 {
590 int r;
591 IN_INIT();
592 r = DO_CALL(UDITransMode_c);
593 OUT_INIT();
594 *Mode = OUT_VAL(UDIMode);
595 return r;
596 }
597
598 #define DFEIPCIdCompany 0x0001 /* Company ID AMD */
599 #define DFEIPCIdProduct 0x1 /* Product ID 0 */
600 #define DFEIPCIdVersion 0x125 /* 1.2.5 */
601
602 unsigned UDIGetDFEIPCId ()
603 {
604 return((((UDIUInt32)DFEIPCIdCompany) << 16) |(DFEIPCIdProduct << 12) | DFEIPCIdVersion);
605 }
606
607 #endif /* __GO32__ */