OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [utils/] [amd-udi/] [udi/] [dos2udip.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/******************************************************************************
2
 * Copyright 1991 Advanced Micro Devices, Inc.
3
 *
4
 * This software is the property of Advanced Micro Devices, Inc  (AMD)  which
5
 * specifically  grants the user the right to modify, use and distribute this
6
 * software provided this notice is not removed or altered.  All other rights
7
 * are reserved by AMD.
8
 *
9
 * AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
10
 * SOFTWARE.  IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL
11
 * DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR
12
 * USE OF THIS SOFTWARE.
13
 *
14
 * Comments about this software should be directed to udi@amd.com. If access
15
 * to electronic mail isn't available, send mail to:
16
 *
17
 * Advanced Micro Devices, Inc.
18
 * 29K Support Products
19
 * Mail Stop 573
20
 * 5900 E. Ben White Blvd.
21
 * Austin, TX 78741
22
 * 800-292-9263
23
 *****************************************************************************
24
 * DOS386 changes were merged into:
25
 *       $Id: dos2udip.c,v 1.1.1.1 2002-01-16 10:26:06 markom Exp $
26
 *       $Id: @(#)dos2udip.c    2.11, AMD
27
 */
28
 
29
        /* TIPIPCId components */
30
#define TIPIPCIdCompany 0x0001  /* Company ID from AMD, others should change this */
31
#define TIPIPCIdVersion 0x124   /* Version */
32
#ifdef DOS386
33
#define TIPIPCIdProduct 0x3     /* Product ID for DOS386 IPC */
34
#else
35
#define TIPIPCIdProduct 0x2     /* Product ID for non-DOS386 IPC */
36
#endif
37
 
38
#include <stdio.h>
39
#include <dos.h>
40
 
41
#ifdef HAVE_STDLIB_H
42
# include <stdlib.h>
43
#endif
44
 
45
#ifdef HAVE_STRING_H
46
# include <string.h>
47
#else
48
# include <strings.h>
49
#endif
50
 
51
#include <udiproc.h>
52
#include <udidos.h>
53
static FILE *      fpstdout = stdout;   /* where we write the information */
54
 
55
#ifndef DOS386
56
#pragma check_stack( off )
57
#pragma check_pointer( off )
58
 
59
        /********************************************************
60
         * In non-DOS386 mode, a standard C PTR is just a far real ptr
61
         * so FARCPTR_TO_REALPTR and REALPTR_TO_FARCPTR are pass-thru
62
         ********************************************************/
63
#define FARCPTR_TO_REALPTR(p) p
64
#define REALPTR_TO_FARCPTR(p) p
65
 
66
#define IPCFar far      /* qualifier for pointer that can reach the real data used by IPC */
67
#define REALNULL NULL
68
typedef void far * FARCPTR;
69
 
70
#else 
71
#include "malloc.h"
72
#include "alloca.h"
73
#include "pharlap.h"
74
#include "realcopy.h"
75
 
76
#define IPCFar _far     /* qualifier for pointer that can reach the real data used by IPC */
77
#define REALNULL (REALPTR) 0
78
typedef void _far * FARCPTR;
79
 
80
 
81
        /********************************************************
82
         * In DOS386 protected mode, we have two types of pointers, near and far
83
         * near is a 32-bit pointer, ie a 32-bit offset from DS.
84
         * far is a 48-bit pointer, with an explicit segment register.
85
         * We want to be able to convert real mode pointers (16-bit seg, 16-bit ofst)
86
         * into these near and far protected mode pointers and vice versa.
87
         *
88
         * It is always possible to convert a real mode pointer to a far prot ptr.
89
         * (Pharlap provides an explicit segment that maps to the low 1 meg of memory).
90
         ********************************************************/
91
FARCPTR  REALPTR_TO_FARCPTR(REALPTR p);
92
 
93
        /********************************************************
94
         * The ability to convert from a real mode pointer to a near protected
95
         * pointer depends on being able to map converntional memory onto the
96
         * end of our data segment.  This is NOT possible under DPMI 0.90
97
         * If we're not under DPMI 0.90,
98
         * REALPTR_TO_NEARCPTR takes a real ptr, and returns its offset
99
         * in the SS_DATA segment (using the fact that the 1 meg of real
100
         * memory was mapped to the SS_DATA by dx_map_physical).
101
         *
102
         ********************************************************/
103
#define REALPTR_TO_NEARCPTR(rp) ((void *)(&conventional_memory[LINEARIZE(rp)]))
104
 
105
 
106
        /**********************************************************
107
         *  LINEARIZE converts a segment:ofst pointer into a linear
108
         *  addr between 0 and 1meg
109
         *********************************************************/
110
#define LINEARIZE(rp) ((RP_SEG(rp)<<4) + RP_OFF(rp))
111
 
112
        /********************************************************
113
         * FARCPTR_TO_REALPTR converts a far protected ptr to a real ptr.
114
         * Naturally, only certain protected pointers can be converted
115
         * into real pointers (they must map to something in the
116
         * first 1 meg of memory).  If it can't be converted, it's
117
         * a fatal error.  This is a routine rather than a macro.
118
         * If we need to convert a near prot ptr to a real ptr,
119
         * this can be done by simply casting it to a far
120
         *
121
         ********************************************************/
122
REALPTR FARCPTR_TO_REALPTR(FARPTR p);
123
 
124
extern USHORT GetCS();
125
extern USHORT GetDS();
126
 
127
 
128
#endif   /* DOS386 */
129
 
130
/****************** External Prototypes *****************************/
131
 
132
extern void TIPPrintUsage(char *arg);
133
 
134
#ifndef DOS386
135
extern UDIError UDIASMDisconnect UDIParams((
136
  UDISessionId          Session,                /* In */
137
  UDIBool               Terminate,              /* In */
138
  DOSTerm               far *TermStruct         /* In - not seen in UDIP */
139
  ));
140
extern UDIError UDIASMConnect UDIParams((
141
  char                  *Configuration,         /* In */
142
  UDISessionId          *Session,               /* Out */
143
  DOSTerm               far *TermStruct         /* In - not seen in UDIP */
144
  ));
145
 
146
#endif
147
 
148
/****************** Internal Prototypes *****************************/
149
 
150
UDIError UDICCapabilities UDIParams((
151
  UDIUInt32     *TIPId,                 /* Out */
152
  UDIUInt32     *TargetId,              /* Out */
153
  UDIUInt32     DFEId,                  /* In */
154
  UDIUInt32     DFE,                    /* In */
155
  UDIUInt32     *TIP,                   /* Out */
156
  UDIUInt32     *DFEIPCId,              /* Out */
157
  UDIUInt32     *TIPIPCId,              /* Out */
158
  char          *TIPString              /* Out */
159
  ));
160
 
161
static unsigned short GetPSP( void );
162
static void SetPSP( unsigned short PSPSegment );
163
static unsigned int ComputeTSRSize(void *topofstack);
164
static void SetupEnvironment(void);
165
static void TerminateTIP UDIParams((DOSTerm           IPCFar *TermStruct));
166
 
167
 
168
/****************** External and Static Data *****************************/
169
static int ConnectCount;
170
 
171
#ifdef DOS386
172
 
173
char    *conventional_memory;   /* pointer to first byte of conventinal memory */
174
                                /* if 0, then conventional mem not mapped */
175
USHORT  our_tsr_psp;            /* TIP's original PSP */
176
USHORT  dos_ext_psp;            /* Dos extender PSP (TIP's parent) */
177
extern  REALPTR  call_prot;     /* These are in the module dostip.asm */
178
extern  USHORT   code_selector;
179
extern  USHORT   data_selector;
180
extern  USHORT  segregblock[4];
181
extern  int end_real;           /* marks end of stuff that must be placed in low mem */
182
int * stack_table[3];           /* used when we need to get a new stack frame
183
                                 * to establish C context on each UDI call
184
                                 * but only if conventional memory didn't map */
185
REALPTR  real_basep;            /* returned by realcopy */
186
FARPTR   prot_basep;            /* returned by realcopy */
187
USHORT   rmem_adrp;             /* returned by realcopy */
188
 
189
extern char TIPName[];                  /* in DOS386, defined in rmdata in dosdfe.asm */
190
extern struct UDIVecRec TIPVecRec;      /* in DOS386, defined in rmdata in dosdfe.asm */
191
 
192
 
193
 
194
#else   /* non-DOS386 static and external data */
195
 
196
char TIPName[ FILENAME_MAX ];           /* in non-386 version, TIPName defined right here */
197
struct UDIVecRec TIPVecRec = {          /* in non-386 version, TIPVecRec defined right here */
198
    UDIDOSTIPRecognizer,        /* Initialized in main */
199
    NULL,                       /* Pointer to next TIP */
200
    NULL,                       /* Pointer to previous TIP */
201
    TIPName,                    /* Name of the executable we were loaded as */
202
    UDIASMConnect,
203
    UDIASMDisconnect,
204
    UDISetCurrentConnection,
205
    UDICCapabilities,
206
    UDIGetErrorMsg,
207
    UDIGetTargetConfig,
208
    UDICreateProcess,
209
    UDISetCurrentProcess,
210
    UDIDestroyProcess,
211
    UDIInitializeProcess,
212
    UDIRead,
213
    UDIWrite,
214
    UDICopy,
215
    UDIExecute,
216
    UDIStep,
217
    UDIStop,
218
    UDIWait,
219
    UDISetBreakpoint,
220
    UDIQueryBreakpoint,
221
    UDIClearBreakpoint,
222
    UDIGetStdout,
223
    UDIGetStderr,
224
    UDIPutStdin,
225
    UDIStdinMode,
226
    UDIPutTrans,
227
    UDIGetTrans,
228
    UDITransMode
229
   };
230
#endif
231
 
232
struct UDIVecRec IPCFar * pTIPVecRec;   /* pointer to TIPVecRec */
233
                                        /* in DOS386, this points to real memory */
234
static RealUDIVecRecPtr IPCFar * UDIVecP;
235
 
236
static int loaded_from_exp_file = 0;
237
 
238
 
239
void do_exit(int errcode)
240
{
241
  /* this routine normally just calls exit but in the special case
242
   * of DOS386 mode AND we were loaded from a .exp file, then we want
243
   * to exit in a different way by calling exp_return
244
   */
245
#ifdef DOS386
246
extern void _exp_return(int err);
247
    if (loaded_from_exp_file)
248
        _exp_return(errcode);
249
    else
250
#endif
251
        /* normal non-DOS386 and non-exp_file exit */
252
        exit(errcode);
253
}
254
 
255
 
256
void do_dos_keep(int errcode, int tsrsize)
257
{
258
  /* similar logic to do_exit above, but this time for dos_keep
259
   */
260
#ifdef DOS386
261
extern void _exp_return(int err);
262
    if (loaded_from_exp_file)
263
        _exp_return(errcode);
264
    else
265
#endif
266
        /* normal non-DOS386 and non-exp_file dos_keep */
267
        _dos_keep( 0, tsrsize );
268
}
269
 
270
void get_tip_name(int argc, char *argv[])
271
{
272
  /* This routine normally gets the Tipname from argv[1], but
273
   * in the special case of DOS386 and loaded as an exp file,
274
   * it gets the name from the stack
275
   */
276
 
277
#ifdef DOS386
278
    extern  char * _top;
279
 
280
    if ((GetCS() & 0xfffc) != SS_CODE) {
281
        /* a CS that is not SS_CODE indicates that we were
282
           loaded as a .exp file.  In that case, we don't
283
           want to exit or do a TSR, instead we want to return
284
           back to the DFE using _exp_return.
285
        */
286
        loaded_from_exp_file = TRUE;
287
        strcpy(TIPName, _top+16);
288
        return;
289
    }
290
#endif
291
 
292
    if ((argc!= 2)  || (argv[1][0] == '-')) {
293
        TIPPrintUsage(argv[1]);
294
        do_exit( 1 );
295
    }
296
 
297
    strcpy( TIPName, argv[1] );
298
}
299
 
300
 
301
#ifdef DOS386
302
REALPTR FARCPTR_TO_REALPTR(FARCPTR p)   /* converts a FAR PROT ptr to a REALPTR */
303
{
304
REALPTR  dummyrp;
305
int   err;
306
 
307
                /* returns a real mode pointer given a prot mode pointer p */
308
        err = _dx_toreal(p, 0, &dummyrp);
309
        if (err) {
310
           printf("Fatal Error _dx_toreal(%04x:%08x)\n", FP_SEG(p), FP_OFF(p));
311
           do_exit(err);
312
        }
313
        else
314
           return(dummyrp);
315
 
316
}
317
 
318
 
319
FARCPTR  REALPTR_TO_FARCPTR(REALPTR rp)
320
{
321
FARCPTR   dummyfp;
322
        FP_SET(dummyfp, LINEARIZE(rp), SS_DOSMEM);
323
        return(dummyfp);
324
}
325
 
326
/*****************
327
 * Routine used to create and initialize a stack for C context stack switching
328
 * (used only when conventional memory can't be mapped
329
 ****************/
330
static void create_stack(int stack_index, int size_in_bytes)
331
{
332
int *p;
333
int  index_to_last_int;
334
 
335
        /* malloc appropriate size and point stack_table entry to second last word */
336
    p = (int *)malloc(size_in_bytes);
337
    if (p == 0) {
338
        printf("\nTIP: unable to malloc stacks\n");
339
        do_exit(1);
340
    }
341
    index_to_last_int =  (size_in_bytes/sizeof(int)) - 1;
342
    stack_table[stack_index] = &p[index_to_last_int-1];
343
 
344
        /* and set last word to 0 (marked as free) */
345
        /* set second last word to stack size (used for alloca checking) */
346
    p[index_to_last_int-1]   = size_in_bytes-8;
347
    p[index_to_last_int] = 0;
348
}
349
#endif
350
 
351
 
352
 
353
static void TerminateTIP UDIParams((
354
  DOSTerm               IPCFar *TermStruct      /* In - not seen in UDIP */
355
  ))
356
{
357
    /* Delink ourselves from the linked list of TIPs */
358
    if (pTIPVecRec->Next != REALNULL)
359
        ((struct UDIVecRec IPCFar *)REALPTR_TO_FARCPTR(pTIPVecRec->Next))->Prev = pTIPVecRec->Prev;
360
    if (pTIPVecRec->Prev != REALNULL)
361
        ((struct UDIVecRec IPCFar *)REALPTR_TO_FARCPTR(pTIPVecRec->Prev))->Next = pTIPVecRec->Next;
362
    else
363
        *UDIVecP = pTIPVecRec->Next;    /* no previous TIP, set the interrupt vector
364
                                           to point to our Next TIP */
365
 
366
#ifdef DOS386
367
{
368
    if (loaded_from_exp_file)   /* if we were loaded from an exp file, skip all this PSP stuff */
369
        return;
370
 
371
    /* Under DOSEXT, our PSP is parented by the DOSEXTENDER's PSP */
372
    /* We want to modify the DOSEXT's PSP to point to the DFE info */
373
REALPTR ptr_dos_ext_psp_parent;
374
REALPTR ptr_dos_ext_psp_termaddr;
375
 
376
    /* Set the dos_ext_psp's Parent PSP to the current PSP (ie, the DFE PSP)*/
377
    RP_SET(ptr_dos_ext_psp_parent,0x16, dos_ext_psp);
378
    *((USHORT _far *)(REALPTR_TO_FARCPTR(ptr_dos_ext_psp_parent))) = GetPSP();
379
 
380
    /* Set the dos_ext_psp's Terminate address to reasonable address in
381
       current PSP (DFE)'s program space */
382
    RP_SET(ptr_dos_ext_psp_termaddr,0xa, dos_ext_psp);
383
    *((ULONG _far *)(REALPTR_TO_FARCPTR(ptr_dos_ext_psp_termaddr))) = (ULONG) TermStruct->TermFunc;
384
}
385
#else
386
    /* Set our TSR's PSP's Parent PSP to the current PSP */
387
    fflush(fpstdout);
388
 
389
    *(unsigned _far *)(((long)_psp << 16) + 0x16) = GetPSP();
390
 
391
    /* Set our TSR's PSP's Terminate address to reasonable address in
392
       current PSP's program space */
393
    /*(void _far (_far *) (void))(((long)_psp << 16) + 0xa) = ExitAddr;*/
394
    *(void (_far *(_far *))(void))(((long)_psp << 16) + 0xa) =
395
        TermStruct->TermFunc;
396
#endif
397
 
398
    /* Change DOS's notion of what the current PSP is to be our TSR's PSP */
399
#ifdef DOS386
400
    SetPSP(our_tsr_psp);
401
        /* Under Dosext, termination will chain back from our_psp to DOSEXT PSP */
402
        /* and then back to the DFE (since we modified the DOSEXT PSP above)    */
403
#else
404
    SetPSP(_psp );
405
#endif
406
 
407
    /* Terminate the program by using DOSTerminate 0x21/0x4c. Execution
408
       will resume at the Terminate address set above with ALL REGISTERS
409
       UNKNOWN especially SS:SP, DS, ES, etc */
410
    bdos( 0x4c, 0, 0 );
411
    }
412
 
413
UDIError UDICConnect UDIParams((
414
  char                  *Configuration,         /* In */
415
  UDISessionId          *Session,               /* Out */
416
  DOSTerm               IPCFar *TermStruct      /* In - not seen in UDIP */
417
  ))
418
{
419
    UDIError err;
420
 
421
    if ((err = UDIConnect( Configuration, Session )) <= UDINoError)
422
        ConnectCount++;
423
 
424
    if (ConnectCount == 0) {     /* Terminate the unused TIP */
425
        /* Save the error status in the TermStruct */
426
        TermStruct->retval = err;
427
 
428
        TerminateTIP( TermStruct );     /* Never returns */
429
        }
430
 
431
    return err;
432
    }
433
 
434
UDIError UDICDisconnect UDIParams((
435
  UDISessionId          Session,                /* In */
436
  UDIBool               Terminate,              /* In */
437
  DOSTerm               IPCFar *TermStruct      /* In - not seen in UDIP */
438
  ))
439
{
440
    UDIError err;
441
 
442
    /* Disconnect via the real TIP */
443
    if ((err = UDIDisconnect( Session, Terminate )) == UDINoError)
444
        ConnectCount--;
445
 
446
    if (Terminate != UDIContinueSession && ConnectCount == 0) {
447
        /* Terminate the unused TIP */
448
        /* Save the error status in the TermStruct */
449
        TermStruct->retval = err;
450
 
451
        TerminateTIP( TermStruct );     /* Never returns */
452
        }
453
 
454
    return err;
455
    }
456
 
457
UDIError UDICCapabilities UDIParams((
458
  UDIUInt32     *TIPId,                 /* Out */
459
  UDIUInt32     *TargetId,              /* Out */
460
  UDIUInt32     DFEId,                  /* In */
461
  UDIUInt32     DFE,                    /* In */
462
  UDIUInt32     *TIP,                   /* Out */
463
  UDIUInt32     *DFEIPCId,              /* Out */
464
  UDIUInt32     *TIPIPCId,              /* Out */
465
  char          *TIPString              /* Out */
466
  ))
467
{
468
    UDIError err;
469
 
470
    err = UDICapabilities( TIPId, TargetId, DFEId, DFE, TIP,
471
                                DFEIPCId, TIPIPCId, TIPString );
472
 
473
    *TIPIPCId = (((UDIUInt32)TIPIPCIdCompany) << 16) |
474
                        (TIPIPCIdProduct << 12) | TIPIPCIdVersion;
475
 
476
    return err;
477
    }
478
 
479
 
480
static RealUDIVecRecPtr IPCFar * AllocateIntVect()
481
{
482
    RealUDIVecRecPtr IPCFar * VecP;
483
 
484
    /* Try and find a vector that is unused */
485
    for (VecP =  (RealUDIVecRecPtr IPCFar *)(REALPTR_TO_FARCPTR(0x60*4));
486
         VecP <= (RealUDIVecRecPtr IPCFar *)(REALPTR_TO_FARCPTR(0x66*4));
487
         VecP++) {
488
        if (*VecP == REALNULL)
489
            return VecP;
490
        }
491
 
492
    return NULL;
493
    }
494
 
495
static RealUDIVecRecPtr IPCFar * FindIntVect()
496
{
497
    RealUDIVecRecPtr IPCFar * VecP;
498
    union rec recognizer;
499
 
500
    InitRecognizer( &recognizer );
501
 
502
    /* Try and find a vector that matches the passed in recognizer */
503
    for (VecP =  (RealUDIVecRecPtr IPCFar *)(REALPTR_TO_FARCPTR(0x60*4));
504
         VecP <= (RealUDIVecRecPtr IPCFar *)(REALPTR_TO_FARCPTR(0x66*4));
505
         VecP++) {
506
        if ((*VecP != REALNULL) && ((struct UDIVecRec IPCFar *) REALPTR_TO_FARCPTR(*VecP))->recognizer.l == recognizer.l)
507
                return VecP;
508
    }
509
 
510
    return NULL;
511
}
512
 
513
static void SetupEnvironment(void)
514
{
515
#ifndef DOS386
516
                /* if not DOS386, nothing to do except set up the
517
                   pointer to TIPVecRec
518
                   */
519
        pTIPVecRec = &TIPVecRec;
520
 
521
#else           /* setup code for DOS386 */
522
FARPTR  dummyfp;
523
REALPTR dummyrp;
524
ULONG   dummyint;
525
REALPTR IPCFar *p;
526
REALPTR ptr_dos_ext_psp;
527
int     err;
528
int     i;
529
 
530
        /**************************************************************
531
         * There are some initialization things that we might as well do before
532
         * we do the realcopy down below.  Here we do some initialization
533
         * of TIPVecRec and the code_selector and data_selector and call_prot
534
         * routine address that are then used by the real mode code.
535
         ****************************************************************/
536
 
537
        _dx_rmlink_get(&call_prot, &dummyrp, &dummyint, &dummyfp);
538
        code_selector = GetCS();
539
        data_selector = GetDS();
540
        for (i=0; i<4; i++)
541
            segregblock[i] = data_selector;
542
 
543
        /******************************************************
544
         * Map first 1 meg of physical memory into our ds: address space
545
         * This is 256 4K pages starting at physical address 0.
546
         * The pointer conventional_memory is its mapped offset in our data space
547
         * If this mapping cannot be done (because we are running under DPMI 0.90)
548
         * then we will have to access dos memory using far pointers and do some
549
         * copies of data down in the d386 routines.
550
         ********************************************************/
551
        err = _dx_map_phys(data_selector, (ULONG) 0, (ULONG) 256, (ULONG *)&conventional_memory);
552
        if (err)
553
            conventional_memory = NULL;
554
 
555
#ifdef DEBUG
556
        if (err)
557
            printf("TIP: Unable to map conventional memory %d\n", err);
558
        else
559
            printf("TIP: Successfully mapped conventional memory\n");
560
#endif
561
 
562
        if (!conventional_memory) {
563
           /* mapping conventional memory did not work */
564
           /* need to set up stacks to switch to at UDI call time */
565
            create_stack(0, 64000);
566
            create_stack(1, 10000);
567
            stack_table[2] =  0; /* end of list */
568
          }
569
 
570
        /* do a realcopy to copy all the things that must be reachable
571
           * from real mode into a real mode segment.  For simplicity,
572
           * we just always assume that REALBREAK might not work.
573
           * This is only used at TIP INIT time and the performance impact is negligent.
574
           */
575
         err = realcopy(0,                 /* real mode stuff was linked first */
576
                        end_real,         /* where the real mode stuff ends */
577
                        &real_basep,
578
                        &prot_basep,
579
                        &rmem_adrp);
580
 
581
        if (err) {
582
                printf("\nTIP: realcopy call failed;\n");
583
                printf(  "     Probable cause: insufficient free conventional memory.\n");
584
                do_exit(1);
585
        }
586
 
587
 
588
        /* The prot_basep that was returned above must now be used
589
           to access from protected mode the data elements that were
590
           copied above.  In particular, we create a pointer to the
591
           copied TIPVecRec and use that.
592
         */
593
        pTIPVecRec = (struct UDIVecRec IPCFar *) (prot_basep + (ULONG) &TIPVecRec);
594
 
595
 
596
 
597
        /**************************************************************
598
         * The real_basep that was returned from realcopy must be used as
599
         * the code segment pointer of all the real mode routines.
600
         * and so must be patched into TIPVecRec.
601
         * real_basep is returned by realcopy such that the offset parts
602
         * (as assembled in in the module dostip.asm) can remain unchanged.
603
         * So we just need to patch the real_basep seg into each of those pointers
604
         ***************************************************************/
605
        for (p = (REALPTR IPCFar *)&pTIPVecRec->exeName;
606
             p<= (REALPTR IPCFar *)&pTIPVecRec->UDITransMode; p++) {
607
                RP_SET(*p, RP_OFF(*p), RP_SEG(real_basep));
608
        }
609
 
610
        /*****************************************************
611
           Store our PSP (real segment) away for later termination
612
           and also the dos extender's PSP (our parent).  We get this by
613
           building a real pointer with seg = our_tsr_psp, ofst = 0x16,
614
           and then derefencing that
615
        *****************************************************/
616
        our_tsr_psp = GetPSP();
617
        RP_SET(ptr_dos_ext_psp, 0x16, our_tsr_psp);
618
        dos_ext_psp = *((USHORT _far *)(REALPTR_TO_FARCPTR(ptr_dos_ext_psp)));
619
 
620
#endif  /* end of DOS386 setup code */
621
}
622
 
623
 
624
static unsigned int ComputeTSRSize(void *topofstack)
625
{
626
#ifndef DOS386
627
        /* Real mode program, compute program size */
628
        /* Huge pointers force compiler to do segment arithmetic for us. */
629
static char _huge *tsrstack;
630
static char _huge *tsrbottom;
631
    /* Initialize stack and bottom of program. */
632
    tsrstack = (char huge *)topofstack;
633
    FP_SEG( tsrbottom ) = _psp;
634
    FP_OFF( tsrbottom ) = 0;
635
 
636
    /* Program size is:
637
     *     top of stack
638
     *   - bottom of program (converted to paragraphs) (using huge math)
639
     *   + one extra paragraph
640
     */
641
    return((unsigned int) (((tsrstack - tsrbottom) >> 4) + 1));
642
#else
643
        /*********************
644
         In DOS386 mode, the TSR size consists of the real memory that
645
         is used by the Pharlap DOS extender and the small amount of real memory
646
         used by UDI.  The number 6400 seems to be a good guess for now.
647
         This might have to be adjusted with newer versions of Dos extender, etc.
648
         I wonder if there is some way to compute this number accurately.
649
         **********************/
650
        return(6400);   /* our best guess for now */
651
#endif
652
}
653
 
654
main(int argc, char *argv[])
655
{
656
    unsigned tsrsize;
657
 
658
    get_tip_name(argc, argv);   /* get name from argv or whereever */
659
 
660
#ifdef TSRDEBUG
661
    {
662
    int i;
663
    printf( "Invoked with %d arguments\n", argc );
664
    for (i = 0; i < argc; i++)
665
        printf( "%s ", argv[i] );
666
    printf( "\n" );
667
    }
668
#endif
669
 
670
    InitRecognizer(&TIPVecRec.recognizer );
671
 
672
    SetupEnvironment();         /* do some setup specific to DOS or DOS386 */
673
 
674
 
675
    /* See if the interrupt vector has already been selected for us */
676
    if ((UDIVecP = FindIntVect()) == NULL) {
677
        if ((UDIVecP = AllocateIntVect()) == NULL)
678
            return -1;  /* No interrupt vectors available */
679
        }
680
    else {      /* Interrupt vector already allocated */
681
        pTIPVecRec->Next = *UDIVecP;            /* always store a real ptr there */
682
        ((struct UDIVecRec IPCFar *) REALPTR_TO_FARCPTR(pTIPVecRec->Next))->Prev = FARCPTR_TO_REALPTR(pTIPVecRec);
683
        }
684
 
685
    *UDIVecP = FARCPTR_TO_REALPTR(pTIPVecRec);
686
 
687
    tsrsize = ComputeTSRSize(&argv);    /* pass it pointer to argv (top of stack) */
688
 
689
    /* We are now ready to support DFEs. If we wish to debug back-ends,
690
       though, we are probably running CodeView with the TIP right now
691
       and don't want to really TSR because CV will shut down at that
692
       point. Instead, let's spawn a new DOS shell from which we can
693
       start a DFE (after setting a breakpoint in the TIP somewhere).
694
    */
695
#ifdef TSRDEBUG
696
    system( getenv( "COMSPEC" ) );
697
#else
698
    do_dos_keep(0, tsrsize);
699
#endif
700
 
701
    return 0;
702
}
703
 
704
 
705
#define GET_PSP_DOS2    0x51
706
#define GET_PSP_DOS3    0x62
707
#define SET_PSP         0x50
708
 
709
static unsigned short GetPSP( void )
710
{
711
    union REGS regs;
712
 
713
    if (_osmajor == 2)
714
        return 0;
715
#ifdef DOS386
716
    regs.h.ah = GET_PSP_DOS2;   /* Phar Lap requires we use this to get real segment */
717
#else
718
    regs.h.ah = GET_PSP_DOS3;
719
#endif
720
    intdos( &regs, &regs );
721
    return regs.x.bx;
722
}
723
 
724
static void SetPSP( unsigned short PSPSegment )
725
{
726
    union REGS regs;
727
 
728
    regs.h.ah = SET_PSP;
729
    regs.x.bx = PSPSegment;
730
    intdos( &regs, &regs );
731
}
732
 
733
 
734
#ifdef DOS386
735
/*============================ DOS386 glue routines ====================================*/
736
 
737
/****************************************************************
738
 * In DPMI Compatibility mode, when we get to this point, the only
739
 * thing that is on the stack is the saved far stack pointer (which actually
740
 * points back to the real mode stack).   Remember in pmstub in dostip.asm,
741
 * we switched stack pointers so that SS = DS for C level requirements.
742
 *
743
 * The INCOMING_PARAMS macro defines a packed structure which expresses what the
744
 * real mode stack really looks like when we get to each dos386 glue routine.
745
 * The STACK_PAD is all the extra stuff that was on the stack because of the switching
746
 * from real to protected mode, etc.
747
 * The packed structure can be used to express where things really are on the stack
748
 * because the DFE's MSC compiler will push things differently from the hc386 compiler.
749
 ********************************************************************/
750
typedef _packed struct {
751
        FARPTR  ret_to_dosext;
752
        USHORT  zero_word;
753
        USHORT  saved_di;
754
        USHORT  saved_si;
755
        USHORT  saved_bp;
756
        USHORT  saved_ds;
757
        ULONG   ret_to_dfe;
758
} STACK_PAD;
759
 
760
/* The following macro defines the packed structure for the incoming parameters
761
 * including the STACK_PAD stuff noted above.  It is used by those few d386_
762
 * routines that do not need converted pointers to avoid non-use warnings
763
 */
764
#define INCOMING_PARAMS_NO_PTR(params)  \
765
        _packed struct {                \
766
            STACK_PAD padding;          \
767
            params                      \
768
        } _far *in  = rm_stk_ptr;       \
769
 
770
 
771
/* The following macro defines the packed structure for the incoming parameters
772
 * (see above) and also defines a local structure for storing the converted local
773
 * pointers.  Most d386_ routines use this macro.
774
 */
775
#define INCOMING_PARAMS(params)         \
776
        INCOMING_PARAMS_NO_PTR(params)  \
777
        struct {                        \
778
            params                      \
779
            int dummy;     /* to avoid warnings and for local count */          \
780
        } local ;    /* local structure for holding converted pointers */  \
781
        int  stackspace = stacksize;    \
782
 
783
 
784
 
785
/**************************************************************
786
 * The following macros handle the creation of near C pointers from real pointers
787
 * so that the real UDI routines can be called with near C pointers.
788
 * Different macros are called for IN pointers vs. OUT pointers and
789
 * for PREPROCESSING (before the real UDI call) and POSTPROCESSING (cleanup
790
 * after returning from the real UDI call).
791
 *
792
 * If conventional_memory has been mapped, the following happens
793
 *      PREPROCESS (IN or OUT ptr) sets local.var pointer to the mapped pointer
794
 *                                 nothing to copy so count is ignored
795
 *      POSTPROCESS                nothing to do
796
 *
797
 * If conventional_memory has not been mapped, then
798
 *      PREPROCESS (IN ptr)        does alloca of count to get local pointer
799
 *                                 copies data into local allocated area
800
 *      PREPROCESS (OUT ptr)       does alloca of count to get local pointer
801
 *                                 no copy of data yet.
802
 *      POSTPROCESS (OUT ptr)      copies data from local allocated area back to real mem
803
 *
804
 * Note that a few UDI routines have pointers that are both IN and OUT
805
 */
806
 
807
        /* the following is used in a couple of places in the macros */
808
#define ALLOC_LOCAL(var, count) \
809
        if ((stackspace -= count) <= 500) return(UDIErrorIPCLimitation); \
810
        local.var = alloca(count);
811
 
812
#define INPTR_PREPROCESS_COUNT(var,count)  \
813
    if (conventional_memory) { \
814
        local.var = REALPTR_TO_NEARCPTR(in->var); \
815
    } \
816
    else { \
817
        local.dummy = count;    /* avoid double evaluation if count is expression */   \
818
        ALLOC_LOCAL(var, local.dummy); \
819
        movedata(SS_DOSMEM, LINEARIZE(in->var), data_selector, (unsigned int) local.var, local.dummy); \
820
    }
821
 
822
 
823
#define INPTR_PREPROCESS(var) INPTR_PREPROCESS_COUNT(var, sizeof(*(in->var)))
824
 
825
#define OUTPTR_PREPROCESS_COUNT(var,count)  \
826
    if (conventional_memory)  \
827
        local.var = REALPTR_TO_NEARCPTR(in->var); \
828
    else { \
829
        ALLOC_LOCAL(var,count); \
830
    }
831
 
832
#define OUTPTR_PREPROCESS(var) OUTPTR_PREPROCESS_COUNT(var, sizeof(*(in->var)))
833
 
834
#define OUTPTR_POSTPROCESS_COUNT(var,count)  \
835
    if (!conventional_memory) {\
836
        movedata(data_selector, (unsigned int)local.var, SS_DOSMEM, LINEARIZE(in->var), count); \
837
    }
838
 
839
#define OUTPTR_POSTPROCESS(var) OUTPTR_POSTPROCESS_COUNT(var, sizeof(*(in->var)))
840
 
841
 
842
 
843
/* The following routine computes the length of a string that
844
 * is pointed to by a real pointer.  This is only needed when
845
 * we cannot map real mode memory at the end of the DS.
846
 */
847
int realptr_strlen(REALPTR rp)
848
{
849
char _far *farp;
850
char _far *start;
851
 
852
    farp = (char _far *) REALPTR_TO_FARCPTR(rp);   /* need to use a far c ptr */
853
    start = farp;
854
    while (*farp++);       /* advance until a 0 located */
855
    return(FP_OFF(farp) - FP_OFF(start));
856
}
857
 
858
/*========================  Glue Routines ============================================*/
859
 
860
 
861
UDIError d386_UDIConnect (void _far * rm_stk_ptr, int stacksize)
862
{
863
INCOMING_PARAMS(
864
  char          *Configuration;         /* In  */
865
  UDISessionId  *Session;               /* Out */
866
  DOSTerm           *TermStruct;        /* In - not seen in UDIP */
867
)
868
UDIError err;
869
 
870
    INPTR_PREPROCESS_COUNT(Configuration, realptr_strlen((REALPTR)(in->Configuration))+1);
871
    OUTPTR_PREPROCESS(Session);
872
 
873
    err = UDICConnect(     /* for UDIConnect, special case, call UDICConnect in dos2udip.c */
874
        local.Configuration,
875
        local.Session,
876
        REALPTR_TO_FARCPTR((REALPTR)in->TermStruct)
877
    );
878
 
879
    OUTPTR_POSTPROCESS(Session);
880
    return(err);
881
}
882
 
883
UDIError d386_UDIDisconnect (void _far * rm_stk_ptr, int stacksize)
884
{
885
INCOMING_PARAMS(
886
  UDISessionId  Session;                /* In */
887
  UDIBool       Terminate;
888
  DOSTerm           *TermStruct;                /* In - not seen in UDIP */
889
)
890
UDIError err;
891
 
892
    local.dummy = 0;                    /* avoids warning */
893
    err = UDICDisconnect(               /* need to call UDICDisconnect */
894
        in->Session,
895
        in->Terminate,
896
        REALPTR_TO_FARCPTR((REALPTR)in->TermStruct)
897
    );
898
    return(err);
899
 
900
}
901
 
902
 
903
UDIError d386_UDISetCurrentConnection  (void _far * rm_stk_ptr, int stacksize)
904
{
905
INCOMING_PARAMS_NO_PTR(
906
  UDISessionId  Session;                /* In */
907
)
908
        return(UDISetCurrentConnection(in->Session));
909
}
910
 
911
 
912
UDIError d386_UDICapabilities  (void _far * rm_stk_ptr, int stacksize)
913
{
914
INCOMING_PARAMS(
915
  UDIUInt32     *TIPId;                 /* Out */
916
  UDIUInt32     *TargetId;              /* Out */
917
  UDIUInt32     DFEId;                  /* In */
918
  UDIUInt32     DFE;                    /* In */
919
  UDIUInt32     *TIP;                   /* Out */
920
  UDIUInt32     *DFEIPCId;              /* Out */
921
  UDIUInt32     *TIPIPCId;              /* Out */
922
  char          *TIPString;             /* Out */
923
)
924
UDIError err;
925
 
926
    OUTPTR_PREPROCESS(TIPId);
927
    OUTPTR_PREPROCESS(TargetId);
928
    OUTPTR_PREPROCESS(TIP);
929
    OUTPTR_PREPROCESS(DFEIPCId);
930
    OUTPTR_PREPROCESS(TIPIPCId);
931
    OUTPTR_PREPROCESS_COUNT(TIPString, 100);   /* max TIP string? */
932
 
933
    err = UDICCapabilities(             /* another special case call UDICapabilities */
934
        local.TIPId,
935
        local.TargetId,
936
        in->DFEId,
937
        in->DFE,
938
        local.TIP,
939
        local.DFEIPCId,
940
        local.TIPIPCId,
941
        local.TIPString
942
    );
943
 
944
    OUTPTR_POSTPROCESS(TIPId);
945
    OUTPTR_POSTPROCESS(TargetId);
946
    OUTPTR_POSTPROCESS(TIP);
947
    OUTPTR_POSTPROCESS(DFEIPCId);
948
    OUTPTR_POSTPROCESS(TIPIPCId);
949
    OUTPTR_POSTPROCESS_COUNT(TIPString, strlen(local.TIPString)+1);
950
 
951
    return(err);
952
}
953
 
954
 
955
UDIError d386_UDIGetErrorMsg  (void _far * rm_stk_ptr, int stacksize)
956
{
957
INCOMING_PARAMS(
958
  UDIError      ErrorCode;              /* In */
959
  UDISizeT      MsgSize;                /* In */
960
  char          *Msg;                   /* Out */
961
  UDISizeT      *CountDone;             /* Out */
962
)
963
UDIError err;
964
 
965
    OUTPTR_PREPROCESS_COUNT(Msg, in->MsgSize);
966
    OUTPTR_PREPROCESS(CountDone);
967
 
968
    err = UDIGetErrorMsg(
969
        in->ErrorCode,
970
        in->MsgSize,
971
        local.Msg,              /* pointers made local */
972
        local.CountDone
973
    );
974
 
975
    OUTPTR_POSTPROCESS_COUNT(Msg, *(local.CountDone)+1);
976
    OUTPTR_POSTPROCESS(CountDone);
977
    return(err);
978
}
979
 
980
 
981
 
982
UDIError d386_UDIGetTargetConfig (void _far * rm_stk_ptr, int stacksize)
983
{
984
INCOMING_PARAMS(
985
  UDIMemoryRange *KnownMemory;          /* Out */
986
  UDIInt        *NumberOfRanges;        /* In/Out */
987
  UDIUInt32     *ChipVersions;          /* Out */
988
  UDIInt        *NumberOfChips;         /* In/Out */
989
)
990
UDIError err;
991
 
992
    INPTR_PREPROCESS(NumberOfRanges);
993
    INPTR_PREPROCESS(NumberOfChips);
994
    OUTPTR_PREPROCESS_COUNT(KnownMemory, *(local.NumberOfRanges) * sizeof(UDIMemoryRange));
995
    OUTPTR_PREPROCESS_COUNT(ChipVersions, *(local.NumberOfChips) * sizeof(UDIUInt32));
996
 
997
    err = UDIGetTargetConfig(
998
        local.KnownMemory,
999
        local.NumberOfRanges,
1000
        local.ChipVersions,
1001
        local.NumberOfChips
1002
    );
1003
 
1004
    OUTPTR_POSTPROCESS(NumberOfRanges);
1005
    OUTPTR_POSTPROCESS(NumberOfChips);
1006
    OUTPTR_POSTPROCESS_COUNT(KnownMemory, *(local.NumberOfRanges) * sizeof(UDIMemoryRange));
1007
    OUTPTR_POSTPROCESS_COUNT(ChipVersions, *(local.NumberOfChips) * sizeof(UDIUInt32));
1008
 
1009
    return(err);
1010
}
1011
 
1012
UDIError d386_UDICreateProcess (void _far * rm_stk_ptr, int stacksize)
1013
{
1014
INCOMING_PARAMS(
1015
  UDIPId        *PId;                   /* Out */
1016
)
1017
UDIError err;
1018
 
1019
    OUTPTR_PREPROCESS(PId);
1020
 
1021
    err = UDICreateProcess(
1022
        local.PId
1023
    );
1024
 
1025
    OUTPTR_POSTPROCESS(PId);
1026
    return(err);
1027
}
1028
 
1029
UDIError d386_UDISetCurrentProcess (void _far * rm_stk_ptr, int stacksize)
1030
{
1031
INCOMING_PARAMS_NO_PTR(
1032
  UDIPId        PId;                    /* In */
1033
  )
1034
 
1035
    return(UDISetCurrentProcess(
1036
        in->PId
1037
    ));
1038
}
1039
 
1040
UDIError d386_UDIDestroyProcess (void _far * rm_stk_ptr, int stacksize)
1041
{
1042
INCOMING_PARAMS_NO_PTR(
1043
  UDIPId        PId;                    /* In */
1044
  )
1045
 
1046
    return(UDIDestroyProcess(
1047
        in->PId
1048
    ));
1049
}
1050
 
1051
 
1052
 
1053
UDIError d386_UDIInitializeProcess (void _far * rm_stk_ptr, int stacksize)
1054
{
1055
INCOMING_PARAMS(
1056
  UDIMemoryRange *ProcessMemory;        /* In */
1057
  UDIInt        NumberOfRanges;         /* In */
1058
  UDIResource   EntryPoint;             /* In */
1059
  CPUSizeT      *StackSizes;            /* In */
1060
  UDIInt        NumberOfStacks;         /* In */
1061
  char          *ArgString;             /* In */
1062
  )
1063
UDIError err;
1064
 
1065
    INPTR_PREPROCESS_COUNT(ProcessMemory, in->NumberOfRanges * sizeof(UDIMemoryRange));
1066
    INPTR_PREPROCESS_COUNT(StackSizes, in->NumberOfStacks * sizeof(CPUSizeT));
1067
    INPTR_PREPROCESS_COUNT(ArgString, realptr_strlen((REALPTR)(in->ArgString))+1);
1068
 
1069
    err = UDIInitializeProcess(
1070
        local.ProcessMemory,
1071
        in->NumberOfRanges,
1072
        in->EntryPoint,
1073
        local.StackSizes,
1074
        in->NumberOfStacks,
1075
        local.ArgString
1076
    );
1077
 
1078
    return(err);
1079
}
1080
 
1081
 
1082
 
1083
UDIError d386_UDIRead (void _far * rm_stk_ptr, int stacksize)
1084
{
1085
INCOMING_PARAMS(
1086
  UDIResource   From;                   /* In */
1087
  UDIHostMemPtr To;                     /* Out */
1088
  UDICount      Count;                  /* In */
1089
  UDISizeT      Size;                   /* In */
1090
  UDICount      *CountDone;             /* Out */
1091
  UDIBool       HostEndian;             /* In */
1092
  )
1093
UDIError err;
1094
 
1095
    OUTPTR_PREPROCESS_COUNT(To, in->Count * in->Size);
1096
    OUTPTR_PREPROCESS(CountDone);
1097
 
1098
    err = UDIRead(
1099
        in->From,
1100
        local.To,
1101
        in->Count,
1102
        in->Size,
1103
        local.CountDone,
1104
        in->HostEndian
1105
    );
1106
 
1107
    OUTPTR_POSTPROCESS_COUNT(To, *(local.CountDone) * in->Size);
1108
    OUTPTR_POSTPROCESS(CountDone);
1109
 
1110
    return(err);
1111
}
1112
 
1113
 
1114
 
1115
UDIError d386_UDIWrite  (void _far * rm_stk_ptr, int stacksize)
1116
{
1117
INCOMING_PARAMS(
1118
  UDIHostMemPtr From;                   /* In */
1119
  UDIResource   To;                     /* In */
1120
  UDICount      Count;                  /* In */
1121
  UDISizeT      Size;                   /* In */
1122
  UDICount      *CountDone;             /* Out */
1123
  UDIBool       HostEndian;             /* In */
1124
  )
1125
UDIError err;
1126
 
1127
    INPTR_PREPROCESS_COUNT (From, in->Count * in->Size);
1128
    OUTPTR_PREPROCESS(CountDone);
1129
 
1130
    err = UDIWrite(
1131
        local.From,
1132
        in->To,
1133
        in->Count,
1134
        in->Size,
1135
        local.CountDone,
1136
        in->HostEndian
1137
    );
1138
 
1139
    OUTPTR_POSTPROCESS(CountDone);
1140
 
1141
    return(err);
1142
 
1143
}
1144
 
1145
 
1146
UDIError d386_UDICopy (void _far * rm_stk_ptr, int stacksize)
1147
{
1148
INCOMING_PARAMS(
1149
  UDIResource   From;                   /* In */
1150
  UDIResource   To;                     /* In */
1151
  UDICount      Count;                  /* In */
1152
  UDISizeT      Size;                   /* In */
1153
  UDICount      *CountDone;             /* Out */
1154
  UDIBool       Direction;              /* In */
1155
 )
1156
UDIError err;
1157
 
1158
    OUTPTR_PREPROCESS(CountDone);
1159
 
1160
    err = UDICopy(
1161
        in->From,
1162
        in->To,
1163
        in->Count,
1164
        in->Size,
1165
        local.CountDone,
1166
        in->Direction
1167
    );
1168
 
1169
    OUTPTR_POSTPROCESS(CountDone);
1170
 
1171
    return(err);
1172
}
1173
 
1174
 
1175
UDIError d386_UDIExecute (void _far * rm_stk_ptr, int stacksize)
1176
{
1177
/* no incoming parameters */
1178
 
1179
    return(UDIExecute());
1180
}
1181
 
1182
 
1183
UDIError d386_UDIStep  (void _far * rm_stk_ptr, int stacksize)
1184
{
1185
INCOMING_PARAMS_NO_PTR(
1186
  UDIUInt32     Steps;                  /* In */
1187
  UDIStepType   StepType;               /* In */
1188
  UDIRange      Range;                  /* In */
1189
  )
1190
UDIError err;
1191
 
1192
    err = UDIStep(
1193
        in->Steps,
1194
        in->StepType,
1195
        in->Range
1196
    );
1197
 
1198
    return(err);
1199
}
1200
 
1201
 
1202
 
1203
UDIVoid d386_UDIStop   (void _far * rm_stk_ptr, int stacksize)
1204
{
1205
/* no incoming parameters, no return value */
1206
    UDIStop();
1207
}
1208
 
1209
 
1210
 
1211
 
1212
UDIError d386_UDIWait  (void _far * rm_stk_ptr, int stacksize)
1213
{
1214
INCOMING_PARAMS(
1215
  UDIInt32      MaxTime;                /* In */
1216
  UDIPId        *PId;                   /* Out */
1217
  UDIUInt32     *StopReason;            /* Out */
1218
  )
1219
UDIError err;
1220
 
1221
    OUTPTR_PREPROCESS(PId);
1222
    OUTPTR_PREPROCESS(StopReason);
1223
 
1224
    err = UDIWait(
1225
        in->MaxTime,
1226
        local.PId,
1227
        local.StopReason
1228
    );
1229
 
1230
    OUTPTR_POSTPROCESS(PId);
1231
    OUTPTR_POSTPROCESS(StopReason);
1232
 
1233
    return(err);
1234
}
1235
 
1236
 
1237
 
1238
UDIError d386_UDISetBreakpoint  (void _far * rm_stk_ptr, int stacksize)
1239
{
1240
INCOMING_PARAMS(
1241
  UDIResource   Addr;                   /* In */
1242
  UDIInt32      PassCount;              /* In */
1243
  UDIBreakType  Type;                   /* In */
1244
  UDIBreakId    *BreakId;               /* Out */
1245
  )
1246
UDIError err;
1247
 
1248
    OUTPTR_PREPROCESS(BreakId);
1249
 
1250
    err = UDISetBreakpoint(
1251
        in->Addr,
1252
        in->PassCount,
1253
        in->Type,
1254
        local.BreakId
1255
    );
1256
 
1257
    OUTPTR_POSTPROCESS(BreakId);
1258
 
1259
    return(err);
1260
}
1261
 
1262
 
1263
UDIError d386_UDIQueryBreakpoint   (void _far * rm_stk_ptr, int stacksize)
1264
{
1265
INCOMING_PARAMS(
1266
  UDIBreakId    BreakId;                /* In */
1267
  UDIResource   *Addr;                  /* Out */
1268
  UDIInt32      *PassCount;             /* Out */
1269
  UDIBreakType  *Type;          /* Out */
1270
  UDIInt32      *CurrentCount;          /* Out */
1271
  )
1272
UDIError err;
1273
 
1274
    OUTPTR_PREPROCESS(Addr);
1275
    OUTPTR_PREPROCESS(PassCount);
1276
    OUTPTR_PREPROCESS(Type);
1277
    OUTPTR_PREPROCESS(CurrentCount);
1278
 
1279
    err = UDIQueryBreakpoint(
1280
        in->BreakId,
1281
        local.Addr,
1282
        local.PassCount,
1283
        local.Type,
1284
        local.CurrentCount
1285
    );
1286
 
1287
    OUTPTR_POSTPROCESS(Addr);
1288
    OUTPTR_POSTPROCESS(PassCount);
1289
    OUTPTR_POSTPROCESS(Type);
1290
    OUTPTR_POSTPROCESS(CurrentCount);
1291
 
1292
    return(err);
1293
}
1294
 
1295
 
1296
 
1297
UDIError d386_UDIClearBreakpoint (void _far * rm_stk_ptr, int stacksize)
1298
{
1299
INCOMING_PARAMS_NO_PTR(
1300
  UDIBreakId    BreakId;                /* In */
1301
  )
1302
    return(UDIClearBreakpoint(
1303
        in->BreakId
1304
    ));
1305
 
1306
}
1307
 
1308
UDIError d386_UDIGetStdout (void _far * rm_stk_ptr, int stacksize)
1309
{
1310
INCOMING_PARAMS(
1311
  UDIHostMemPtr Buf;                    /* Out */
1312
  UDISizeT      BufSize;                /* In */
1313
  UDISizeT      *CountDone;             /* Out */
1314
  )
1315
UDIError err;
1316
 
1317
    OUTPTR_PREPROCESS_COUNT(Buf, in->BufSize);
1318
    OUTPTR_PREPROCESS(CountDone);
1319
 
1320
    err = UDIGetStdout(
1321
        local.Buf,
1322
        in->BufSize,
1323
        local.CountDone
1324
    );
1325
 
1326
    OUTPTR_POSTPROCESS_COUNT(Buf, *(local.CountDone));
1327
    OUTPTR_POSTPROCESS(CountDone);
1328
 
1329
    return(err);
1330
}
1331
 
1332
 
1333
UDIError d386_UDIGetStderr (void _far * rm_stk_ptr, int stacksize)
1334
{
1335
INCOMING_PARAMS(
1336
  UDIHostMemPtr Buf;                    /* Out */
1337
  UDISizeT      BufSize;                /* In */
1338
  UDISizeT      *CountDone;             /* Out */
1339
  )
1340
UDIError err;
1341
 
1342
    OUTPTR_PREPROCESS_COUNT(Buf, in->BufSize);
1343
    OUTPTR_PREPROCESS(CountDone);
1344
 
1345
    err = UDIGetStderr(
1346
        local.Buf,
1347
        in->BufSize,
1348
        local.CountDone
1349
    );
1350
 
1351
    OUTPTR_POSTPROCESS_COUNT(Buf, *(local.CountDone));
1352
    OUTPTR_POSTPROCESS(CountDone);
1353
 
1354
    return(err);
1355
}
1356
 
1357
 
1358
 
1359
UDIError d386_UDIPutStdin (void _far * rm_stk_ptr, int stacksize)
1360
{
1361
INCOMING_PARAMS(
1362
  UDIHostMemPtr Buf;                    /* In */
1363
  UDISizeT      Count;                  /* In */
1364
  UDISizeT      *CountDone;             /* Out */
1365
  )
1366
UDIError err;
1367
 
1368
    INPTR_PREPROCESS_COUNT(Buf, in->Count);
1369
    OUTPTR_PREPROCESS(CountDone);
1370
 
1371
    err = UDIPutStdin(
1372
        local.Buf,
1373
        in->Count,
1374
        local.CountDone
1375
    );
1376
 
1377
    OUTPTR_POSTPROCESS(CountDone);
1378
 
1379
    return(err);
1380
}
1381
 
1382
 
1383
UDIError d386_UDIStdinMode (void _far * rm_stk_ptr, int stacksize)
1384
{
1385
INCOMING_PARAMS(
1386
  UDIMode       *Mode;                  /* Out */
1387
 )
1388
UDIError err;
1389
 
1390
    OUTPTR_PREPROCESS(Mode);
1391
 
1392
    err = UDIStdinMode(
1393
        local.Mode
1394
    );
1395
 
1396
    OUTPTR_POSTPROCESS(Mode);
1397
 
1398
    return(err);
1399
}
1400
 
1401
UDIError d386_UDIPutTrans (void _far * rm_stk_ptr, int stacksize)
1402
{
1403
INCOMING_PARAMS(
1404
  UDIHostMemPtr Buf;                    /* In */
1405
  UDISizeT      Count;                  /* In */
1406
  UDISizeT      *CountDone;             /* Out */
1407
  )
1408
UDIError err;
1409
 
1410
    INPTR_PREPROCESS_COUNT(Buf, in->Count);
1411
    OUTPTR_PREPROCESS(CountDone);
1412
 
1413
    err = UDIPutTrans(
1414
        local.Buf,
1415
        in->Count,
1416
        local.CountDone
1417
    );
1418
 
1419
    OUTPTR_POSTPROCESS(CountDone);
1420
 
1421
    return(err);
1422
}
1423
 
1424
 
1425
UDIError d386_UDIGetTrans (void _far * rm_stk_ptr, int stacksize)
1426
{
1427
INCOMING_PARAMS(
1428
  UDIHostMemPtr Buf;                    /* Out */
1429
  UDISizeT      BufSize;                /* In */
1430
  UDISizeT      *CountDone;             /* Out */
1431
  )
1432
UDIError err;
1433
 
1434
    OUTPTR_PREPROCESS_COUNT(Buf, in->BufSize);
1435
    OUTPTR_PREPROCESS(CountDone);
1436
 
1437
    err = UDIGetTrans(
1438
        local.Buf,
1439
        in->BufSize,
1440
        local.CountDone
1441
    );
1442
 
1443
    OUTPTR_POSTPROCESS_COUNT(Buf, *(local.CountDone));
1444
    OUTPTR_POSTPROCESS(CountDone);
1445
 
1446
    return(err);
1447
}
1448
 
1449
 
1450
UDIError d386_UDITransMode (void _far * rm_stk_ptr, int stacksize)
1451
{
1452
INCOMING_PARAMS(
1453
  UDIMode       *Mode;                  /* Out */
1454
 )
1455
UDIError err;
1456
 
1457
    OUTPTR_PREPROCESS(Mode);
1458
 
1459
    err = UDITransMode(
1460
        local.Mode
1461
    );
1462
 
1463
    OUTPTR_POSTPROCESS(Mode);
1464
 
1465
    return(err);
1466
}
1467
 
1468
#endif
1469
/*==================== End of DOS386 glue routines ====================================*/
1470
 
1471
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.