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

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [gdb-5.0/] [utils/] [amd-udi/] [udi/] [udip2soc.c] - Blame information for rev 579

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 106 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
* So that all may benefit from your experience, please report  any  problems
15
* or  suggestions about this software to the 29K Technical Support Center at
16
* 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131  in  the  UK,  or
17
* 0031-11-1129 in Japan, toll free.  The direct dial number is 512-462-4118.
18
*
19
* Advanced Micro Devices, Inc.
20
* 29K Support Products
21
* Mail Stop 573
22
* 5900 E. Ben White Blvd.
23
* Austin, TX 78741
24
* 800-292-9263
25
*****************************************************************************
26
*/
27
static  char udip2soc_c[]="@(#)udip2soc.c       2.13  Daniel Mann";
28
static  char udip2soc_c_AMD[]="@(#)udip2soc.c   2.11, AMD";
29
/*
30
*       This module converts UDI Procedural calls into
31
*       UDI socket messages for UNIX.
32
*       It is used by DFE client processes
33
********************************************************************** HISTORY
34
*/
35
#include <stdio.h>
36
#include <string.h>
37
#include <sys/file.h>
38
#include <sys/fcntl.h>
39
#include <sys/wait.h>
40
#include <sys/time.h>
41
#include <sys/resource.h>
42
#include <sys/types.h>
43
#include <sys/socket.h>
44
#include <netinet/in.h>
45
#include <netdb.h>
46
#include <signal.h>
47
#include <sys/errno.h>
48
#include "udiproc.h"
49
#include "udisoc.h"
50
 
51
extern  int             errno;
52
extern  int             sys_nerr;
53
extern  char*           sys_errlist[];
54
extern  int             udr_errno;
55
extern  char*           getenv();
56
 
57
/* local type decs. and macro defs. not in a .h  file ************* MACRO/TYPE
58
*/
59
#define         version_c 0x121         /* DFE-IPC version id */
60
#define         TRUE -1
61
#define         FALSE 0
62
#define         PORT_NUM 7000
63
#define         MAX_SESSIONS 5          /* maximum DFE-TIP connections */
64
#define         SOC_BUF_SIZE 4* 1024    /* size of socket comms buffer */
65
#define         SBUF_SIZE 500           /* size of string buffer */
66
#define         ERRMSG_SIZE 500         /* size of error message buffer */
67
 
68
#define errmsg_m {int ii; for(ii=0; ii<ERRMSG_SIZE; ii++) dfe_errmsg[ii]=0;}
69
 
70
typedef struct connection_str           /* record of connect session */
71
{
72
    int         in_use;
73
    char        connect_id[20];         /* connection identifier */
74
    char        domain_string[20];      /* dommaing for conection */
75
    char        tip_string[30];         /* TIP host name for AF_INET */
76
    char        tip_exe[80];            /* TIP exe name */
77
    int         dfe_sd;                 /* associated DFE socket */
78
    int         tip_pid;                /* pid of TIP process */
79
    struct sockaddr_in dfe_sockaddr;
80
    struct sockaddr_in tip_sockaddr_in;
81
    struct sockaddr    tip_sockaddr;
82
} connection_t;
83
 
84
typedef struct session_str
85
{
86
    int           in_use;
87
    connection_t* soc_con_p;            /* associated connection */
88
    UDISessionId  tip_id;               /* associated TIP session ID */
89
} session_t;
90
 
91
/* global dec/defs. which are not in a .h   file ************* EXPORT DEC/DEFS
92
*/
93
UDIError        dfe_errno;
94
char    dfe_errmsg[ERRMSG_SIZE];/* error string */
95
 
96
/* local dec/defs. which are not in a .h   file *************** LOCAL DEC/DEFS
97
*/
98
LOCAL connection_t      soc_con[MAX_SESSIONS];
99
LOCAL session_t session[MAX_SESSIONS];
100
LOCAL UDR       udr;
101
LOCAL UDR*      udrs = &udr;            /* UDR for current session */
102
LOCAL int       current;                /* int-id for current session */
103
LOCAL char      sbuf[SBUF_SIZE];        /* String handler buffer */
104
LOCAL char      config_file[80];        /* path/name for config file */
105
 
106
/***************************************************************** UDI_CONNECT
107
* Establish a new FDE to TIP conection. The file "./udi_soc" or
108
* "/etc/udi_soc" may be examined to obtain the conection information
109
* if the "Config" parameter is not a completd "line entry".
110
*
111
* NOTE: the Session string must not start whith white-space characters.
112
* Format of string is:
113
* <session>   <domain> <soc_name|host_name> <tip_exe|port> <pass to UDIconnect>
114
* soc2cayman  AF_INET            cayman      7000           <not supported>
115
* soc2tip     AF_UNIX   astring              tip.exe        ...
116
*/
117
UDIConnect(Config, Session)
118
char*   Config;                 /* in  -- identification string */
119
UDISessionId *Session;          /* out -- session ID */
120
{
121
    UDIInt32    service_id = UDIConnect_c;
122
    int         domain;
123
    int         cnt=0;
124
    int         rcnt, pos, fd, params_pos=0;
125
    char        *tip_main_string;
126
    char        *env_p;
127
    struct hostent      *tip_info_p;
128
    FILE        *f_p;
129
    UDIUInt32   TIPIPCId;
130
    UDIUInt32   DFEIPCId;
131
 
132
    sprintf(sbuf, "which udi_soc");
133
    f_p = popen(sbuf, "r");
134
    if(f_p)
135
    {   while( (sbuf[cnt++]=getc(f_p)) != EOF);
136
        sbuf[cnt-2]=0;
137
    }
138
    pclose(f_p);
139
    errmsg_m;
140
    for (rcnt=0; rcnt < MAX_SESSIONS; rcnt++)
141
        if(!session[rcnt].in_use) break;
142
    if(rcnt >= MAX_SESSIONS)
143
    {
144
        sprintf(dfe_errmsg, "DFE-ipc ERROR: Too many sessions already open");
145
        return UDIErrorIPCLimitation;
146
    }
147
    /* One connection can be multiplexed between several sessions. */
148
    for (cnt=0; cnt < MAX_SESSIONS; cnt++)
149
        if(!soc_con[cnt].in_use) break;
150
    if(cnt >= MAX_SESSIONS)
151
    {
152
        sprintf(dfe_errmsg, "DFE-ipc ERROR: Too many connections already open");
153
        return UDIErrorIPCLimitation;
154
    }
155
    *Session = rcnt;
156
    session[rcnt].soc_con_p = &soc_con[cnt];
157
 
158
    if(strchr(Config, ' '))             /* test if file entry given */
159
    {
160
        soc_con[cnt].in_use = TRUE;
161
        sscanf(Config, "%s %s %s %s %n",
162
            soc_con[cnt].connect_id,
163
            soc_con[cnt].domain_string,
164
            soc_con[cnt].tip_string,
165
            soc_con[cnt].tip_exe,
166
            &params_pos);
167
        tip_main_string = Config + params_pos;
168
    }
169
    else                                /* here if need to read udi_soc file */
170
    {
171
        fd = -1;
172
        env_p = getenv("UDICONF");
173
        if(env_p)
174
        {   sprintf(config_file, "%s", env_p);  /* path includes file name */
175
            fd = open(config_file, O_RDONLY);
176
        }
177
        if(fd == -1)
178
        {   fd = open("udi_soc", O_RDONLY);
179
            strcpy(config_file, "udi_soc");
180
        }
181
        if(fd == -1)
182
        {   fd = open(sbuf, O_RDONLY);
183
            strcpy(config_file, sbuf);
184
        }
185
        if(fd == -1)
186
        {   sprintf(dfe_errmsg, "UDIConnect, can't open udi_soc file:\n%s ",
187
                sys_errlist[errno]);
188
            return UDIErrorCantOpenConfigFile;
189
        }
190
        while(1)
191
        {   pos = 0;
192
            while((rcnt = read(fd, &sbuf[pos], 1)) != -1)/* read a line */
193
            {   if (sbuf[pos] == '\n' || rcnt == 0 )
194
                    break;
195
                pos += 1;
196
            }
197
            sbuf[pos] = 0;                       /* terminate string */
198
            sscanf(sbuf, "%s %s %s %s %n",
199
                soc_con[cnt].connect_id,
200
                soc_con[cnt].domain_string,
201
                soc_con[cnt].tip_string,
202
                soc_con[cnt].tip_exe,
203
                &params_pos);
204
            if( strcmp(Config, soc_con[cnt].connect_id)
205
                || rcnt == -1 || rcnt == 0)
206
                if(rcnt == -1 || rcnt == 0)
207
                {   sprintf(dfe_errmsg,
208
                        "UDIConnect, can't find entry in udi_soc file");
209
                    return UDIErrorNoSuchConfiguration;
210
                }
211
                else
212
                    continue;
213
            soc_con[cnt].in_use = TRUE;         /* here if entry found */
214
            tip_main_string = sbuf + params_pos;
215
            break;
216
        }
217
        close(fd);
218
    }
219
/*-------------------------------------------------------------- '*' SOC_ID */
220
    if( *soc_con[cnt].tip_string == '*'
221
     && *soc_con[cnt+1].tip_string == 0)
222
    {
223
        rcnt = 0;
224
        pos = getpid();
225
        do
226
        {   sprintf(soc_con[cnt].tip_string,"/tmp/udi%.5d", pos++);
227
            fd = open(soc_con[cnt].tip_string, O_CREAT);
228
            if(rcnt++ > 20)
229
            {   sprintf(dfe_errmsg,
230
                        "DFE-ipc ERROR, can't create random socket name\n");
231
                return UDIErrorCantConnect;
232
            }
233
        } while(fd == -1);
234
        close(fd);
235
        unlink(soc_con[cnt].tip_string);
236
    }
237
/*----------------------------------------------------------- SELECT DOMAIN */
238
    if(!strcmp(soc_con[cnt].domain_string, "AF_UNIX"))
239
        domain = AF_UNIX;
240
    else if(!strcmp(soc_con[cnt].domain_string, "AF_INET"))
241
        domain = AF_INET;
242
    else
243
    {   errmsg_m;
244
        sprintf(dfe_errmsg, "DFE-ipc ERROR: socket address family not known");
245
        return UDIErrorBadConfigFileEntry;
246
    }
247
 
248
/*---------------------------------------------------- MULTIPLEXED SOCKET ? */
249
/* If the requested session requires communication with
250
   a TIP which already has a socket connection established,
251
   then we do not create a new socket but multiplex the
252
   existing one. A TIP is said to use the same socket if
253
   socket-name/host-name and the domain are the same.
254
 */
255
    for (rcnt=0; rcnt < MAX_SESSIONS; rcnt++)
256
    {   if( soc_con[rcnt].in_use
257
        && !strcmp(soc_con[cnt].domain_string, soc_con[rcnt].domain_string)
258
        && !strcmp(soc_con[cnt].tip_string, soc_con[rcnt].tip_string)
259
        && rcnt != cnt  )
260
        {
261
            session[*Session].soc_con_p = &soc_con[rcnt];
262
            soc_con[cnt].in_use = FALSE;        /* don't need new connect */
263
            goto tip_connect;
264
        }
265
    }
266
/*------------------------------------------------------------------ SOCKET */
267
    soc_con[cnt].dfe_sd = socket(domain, SOCK_STREAM, 0);
268
    if (soc_con[cnt].dfe_sd == -1 )
269
    {   errmsg_m;
270
        sprintf(dfe_errmsg, "DFE-ipc ERROR, socket() call failed %s ",
271
            sys_errlist[errno]);
272
        UDIKill(cnt);
273
    }
274
 
275
/*--------------------------------------------------------- AF_UNIX CONNECT */
276
    if(domain == AF_UNIX)
277
    {
278
        memset( (char*)&soc_con[cnt].tip_sockaddr, 0,
279
            sizeof(soc_con[cnt].tip_sockaddr));
280
        soc_con[cnt].tip_sockaddr.sa_family = domain;
281
        bcopy(soc_con[cnt].tip_string,
282
                soc_con[cnt].tip_sockaddr.sa_data,
283
                sizeof(soc_con[cnt].tip_sockaddr.sa_data) );
284
        if(connect(soc_con[cnt].dfe_sd,
285
                &soc_con[cnt].tip_sockaddr,
286
                sizeof(soc_con[cnt].tip_sockaddr)) == -1)
287
        {       /* if connect() fails assume TIP not yet started */
288
/*------------------------------------------------------------ AF_UNIX EXEC */
289
            int pid;
290
#ifdef __hpux
291
            int statusp;
292
#else
293
            union       wait statusp;
294
#endif
295
            char*       arg0 = strrchr(soc_con[cnt].tip_exe,'/');
296
 
297
            if(!arg0) arg0 = soc_con[cnt].tip_exe;
298
            else        arg0++;
299
 
300
            if((pid = fork()) == 0)
301
            {   execlp(
302
                    soc_con[cnt].tip_exe,
303
                    arg0,
304
                    soc_con[cnt].domain_string,
305
                    soc_con[cnt].tip_string,
306
                    NULL);
307
                exit(1);
308
            }
309
#ifdef __hpux
310
            if(waitpid(pid, &statusp, WNOHANG))
311
#else
312
            if(wait4(pid, &statusp, WNOHANG, NULL))
313
#endif
314
            {
315
                sprintf(dfe_errmsg, "DFE-ipc ERROR: can't exec the TIP\n");
316
                return UDIErrorCantStartTIP;
317
            }
318
            sleep(2);
319
                        /* not TIP is running, try conect() again */
320
            if(connect(soc_con[cnt].dfe_sd,
321
                &soc_con[cnt].tip_sockaddr,
322
                sizeof(soc_con[cnt].tip_sockaddr)) == -1)
323
            {   sprintf(dfe_errmsg, "DFE-ipc ERROR, connect() call failed: %s",
324
                        sys_errlist[errno]);
325
                return UDIErrorCantConnect;
326
            }
327
          }
328
    }
329
/*--------------------------------------------------------- AF_INET CONNECT */
330
    if(domain == AF_INET)
331
    {
332
        fprintf(stderr,"DFE-ipc WARNING, need to have first started remote TIP\n");
333
        memset( (char*)&soc_con[cnt].tip_sockaddr_in, 0,
334
            sizeof(soc_con[cnt].tip_sockaddr_in));
335
        soc_con[cnt].tip_sockaddr_in.sin_family = domain;
336
        soc_con[cnt].tip_sockaddr_in.sin_addr.s_addr =
337
            inet_addr(soc_con[cnt].tip_string);
338
        if( soc_con[cnt].tip_sockaddr_in.sin_addr.s_addr == -1)
339
        {
340
            tip_info_p = gethostbyname(soc_con[cnt].tip_string);
341
            if( tip_info_p == NULL)
342
            {   errmsg_m;
343
               sprintf(dfe_errmsg,"DFE-ipc ERROR, %s not found in /etc/hosts",
344
                   soc_con[cnt].tip_string);
345
                return UDIErrorNoSuchConnection;
346
            }
347
            bcopy(tip_info_p->h_addr,
348
                (char *)&soc_con[cnt].tip_sockaddr_in.sin_addr,
349
                tip_info_p->h_length);
350
        }
351
        soc_con[cnt].tip_sockaddr_in.sin_port=htons(atoi(soc_con[cnt].tip_exe));
352
        if(connect(soc_con[cnt].dfe_sd,
353
                &soc_con[cnt].tip_sockaddr_in,
354
                sizeof(soc_con[cnt].tip_sockaddr_in)) == -1)
355
        {   errmsg_m;
356
            sprintf(dfe_errmsg, "DFE-ipc ERROR, connect() call failed %s ",
357
                sys_errlist[errno]);
358
            return UDIErrorCantConnect;
359
        }
360
    }
361
/*------------------------------------------------------------- TIP CONNECT */
362
    if(cnt ==0) udr_create(udrs, soc_con[cnt].dfe_sd, SOC_BUF_SIZE);
363
tip_connect:
364
    current = cnt;
365
    session[*Session].in_use = TRUE;    /* session id is now in use*/
366
 
367
    udr_errno = 0;
368
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
369
    udr_UDIInt32(udrs, &service_id);
370
    DFEIPCId = (company_c << 16) + (product_c << 12) + version_c;
371
    udr_UDIUInt32(udrs, &DFEIPCId);
372
    udr_string(udrs, tip_main_string);
373
    udr_sendnow(udrs);
374
 
375
    udrs->udr_op = UDR_DECODE;          /* recv all "out" parameters */
376
    udr_UDIUInt32(udrs, &TIPIPCId);
377
    if ((TIPIPCId & 0xfff) < version_c)
378
    {   fprintf(stderr, "DFE-ipc: Obsolete TIP Specified\n");
379
        return(UDIErrorExecutableNotTIP);
380
    }
381
    udr_UDIInt32(udrs, &soc_con[cnt].tip_pid);
382
    udr_UDISessionId(udrs, &session[*Session].tip_id);
383
    udr_UDIError(udrs, &dfe_errno);
384
    if(dfe_errno > 0) UDIKill(Session, 0);
385
    return dfe_errno;
386
}
387
 
388
/************************************************************** UDI_Disconnect
389
* UDIDisconnect() should be called before exiting the
390
* DFE to ensure proper shut down of the TIP.
391
*/
392
UDIError UDIDisconnect(Session,  Terminate)
393
UDISessionId    Session;
394
UDIBool         Terminate;
395
{
396
    int cnt;
397
    UDIInt32    service_id = UDIDisconnect_c;
398
    if(Session < 0 || Session > MAX_SESSIONS)
399
    {   errmsg_m;
400
        sprintf(dfe_errmsg," SessionId not valid (%d)", Session);
401
        return UDIErrorNoSuchConfiguration;
402
    }
403
    udr_errno = 0;
404
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
405
    udr_UDIInt32(udrs, &service_id);
406
    udr_UDISessionId(udrs, &session[Session].tip_id);
407
    udr_UDIBool(udrs, &Terminate);
408
    udr_sendnow(udrs);
409
 
410
    session[Session].in_use = FALSE;    /* session id is now free */
411
    for (cnt=0; cnt < MAX_SESSIONS; cnt++)
412
        if(session[cnt].in_use
413
        && session[cnt].soc_con_p == session[Session].soc_con_p
414
                ) break;
415
    if(cnt >= MAX_SESSIONS)     /* test if socket not multiplexed */
416
        if(shutdown(session[Session].soc_con_p->dfe_sd, 2))
417
        {   errmsg_m;
418
            sprintf(dfe_errmsg, "DFE-ipc WARNING: socket shutdown failed");
419
            return UDIErrorIPCInternal;
420
        }
421
 
422
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
423
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
424
    return dfe_errno;
425
}
426
 
427
/******************************************************************** UDI_KILL
428
* UDIKill() is used to send a signal to the TIP.
429
* This is a private IPC call.
430
*/
431
UDIError UDIKill(Session,  Signal)
432
UDISessionId    Session;
433
UDIInt32        Signal;
434
{
435
    int cnt;
436
    UDIInt32    service_id = UDIKill_c;
437
    if(Session < 0 || Session > MAX_SESSIONS)
438
    {   errmsg_m;
439
        sprintf(dfe_errmsg," SessionId not valid (%d)", Session);
440
        return UDIErrorNoSuchConfiguration;
441
    }
442
    udr_errno = 0;
443
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
444
    udr_UDIInt32(udrs, &service_id);
445
    udr_UDISessionId(udrs, &session[Session].tip_id);
446
    udr_UDIInt32(udrs, &Signal);
447
    udr_sendnow(udrs);
448
 
449
    session[Session].in_use = FALSE;    /* session id is now free */
450
    for (cnt=0; cnt < MAX_SESSIONS; cnt++)
451
        if(session[cnt].in_use
452
        && session[cnt].soc_con_p == session[Session].soc_con_p
453
                ) break;
454
    if(cnt < MAX_SESSIONS)      /* test if socket not multiplexed */
455
        if(shutdown(session[Session].soc_con_p->dfe_sd, 2))
456
        {   errmsg_m;
457
            sprintf(dfe_errmsg, "DFE-ipc WARNING: socket shutdown failed");
458
            return UDIErrorIPCInternal;
459
        }
460
 
461
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
462
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
463
    return dfe_errno;
464
}
465
 
466
/************************************************** UDI_Set_Current_Connection
467
* If you are connected to multiple TIPs, you can change
468
* TIPs using UDISetCurrentConnection().
469
*/
470
UDIError UDISetCurrentConnection(Session)
471
UDISessionId    Session;
472
{
473
    UDIInt32    service_id = UDISetCurrentConnection_c;
474
 
475
    if(Session < 0 || Session > MAX_SESSIONS)
476
        return UDIErrorNoSuchConfiguration;
477
    if(!session[Session].in_use)                /* test if not in use yet */
478
        return UDIErrorNoSuchConnection;
479
 
480
    current = Session;
481
    /* change socket or multiplex the same socket  */
482
    udrs->sd = session[Session].soc_con_p->dfe_sd;
483
 
484
    udr_errno = 0;
485
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
486
    udr_UDIInt32(udrs, &service_id);
487
    udr_UDISessionId(udrs, &session[Session].tip_id);
488
    udr_sendnow(udrs);
489
    if(udr_errno) return udr_errno;
490
 
491
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
492
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
493
    return dfe_errno;
494
}
495
 
496
/************************************************************ UDI_Capabilities
497
* The DFE uses UDICapabilities() to both inform the TIP
498
* of what services the DFE offers and to inquire of the
499
* TIP what services the TIP offers.
500
*/
501
UDIError UDICapabilities(TIPId, TargetId, DFEId, DFE, TIP, DFEIPCId,
502
                TIPIPCId, TIPString)
503
UDIUInt32       *TIPId;         /* out */
504
UDIUInt32       *TargetId;      /* out */
505
UDIUInt32       DFEId;          /* in */
506
UDIUInt32       DFE;            /* in */
507
UDIUInt32       *TIP;           /* out */
508
UDIUInt32       *DFEIPCId;      /* out */
509
UDIUInt32       *TIPIPCId;      /* out */
510
char            *TIPString;     /* out */
511
{
512
    UDIInt32    service_id = UDICapabilities_c;
513
    int         size;
514
 
515
    udr_errno = 0;
516
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
517
    udr_UDIInt32(udrs, &service_id);
518
    udr_UDIInt32(udrs, &DFEId);
519
    udr_UDIInt32(udrs, &DFE);
520
    udr_sendnow(udrs);
521
    if(udr_errno) return udr_errno;
522
 
523
    udrs->udr_op = UDR_DECODE;          /* receive all "out" paramters */
524
    udr_UDIInt32(udrs, TIPId);
525
    udr_UDIInt32(udrs, TargetId);
526
    udr_UDIInt32(udrs, TIP);
527
    udr_UDIInt32(udrs, DFEIPCId);
528
    *DFEIPCId = (company_c << 16) + (product_c << 12) + version_c;
529
    udr_UDIInt32(udrs, TIPIPCId);
530
    udr_string(udrs, sbuf);
531
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
532
    size = strlen(sbuf);
533
    if(size +1 > 80) return -1;         /* test if sufficient space */
534
    strcpy(TIPString, sbuf);
535
    return dfe_errno;
536
}
537
 
538
/********************************************************** UDI_Enumerate_TIPs
539
* Used by the DFE to enquire about available TIP
540
* connections.
541
*/
542
UDIError UDIEnumerateTIPs(UDIETCallback)
543
  int (*UDIETCallback)();               /* In -- function to callback */
544
{
545
    FILE        *fp;
546
 
547
    fp = fopen(config_file, "r");
548
    if(fp == NULL)
549
        return UDIErrorCantOpenConfigFile;
550
    while(fgets( sbuf, SBUF_SIZE, fp))
551
        if(UDIETCallback( sbuf) == UDITerminateEnumeration)
552
            break;
553
    fclose( fp);
554
    return UDINoError;                  /* return success */
555
}
556
 
557
/*********************************************************** UDI_GET_ERROR_MSG
558
* Some errors are target specific. They are indicated
559
* by a negative error return value. The DFE uses
560
* UDIGetErrorMsg() to get the descriptive text for
561
* the error message which can then  be  displayed  to
562
* the user.
563
*/
564
UDIError UDIGetErrorMsg(error_code, msg_len, msg, CountDone)
565
UDIError        error_code;             /* In */
566
UDISizeT        msg_len;                /* In  -- allowed message space */
567
char*           msg;                    /* Out -- length of message*/
568
UDISizeT        *CountDone;             /* Out -- number of characters */
569
{
570
    UDIInt32    service_id = UDIGetErrorMsg_c;
571
    int         size;
572
 
573
    udr_errno = 0;
574
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
575
    udr_UDIInt32(udrs, &service_id);
576
    udr_UDIError(udrs, &error_code);
577
    udr_UDISizeT(udrs, &msg_len);
578
    udr_sendnow(udrs);
579
    if(udr_errno) return udr_errno;
580
 
581
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
582
    udr_string(udrs, sbuf);
583
    udr_UDISizeT(udrs, CountDone);
584
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
585
    size = strlen(sbuf);
586
    if(size +1 > msg_len) return -1;    /* test if sufficient space */
587
    strcpy(msg, sbuf);
588
    return dfe_errno;
589
}
590
 
591
/******************************************************* UDI_GET_TARGET_CONFIG
592
* UDIGetTargetConfig() gets information about the target.
593
*/
594
UDIError UDIGetTargetConfig(KnownMemory, NumberOfRanges, ChipVersions,
595
                NumberOfChips)
596
UDIMemoryRange  KnownMemory[];          /* Out */
597
UDIInt          *NumberOfRanges;        /* In and Out */
598
UDIUInt32       ChipVersions[];         /* Out */
599
UDIInt          *NumberOfChips;         /* In and Out */
600
{
601
    UDIInt32    service_id = UDIGetTargetConfig_c;
602
    int         cnt;
603
    int         MaxOfRanges = *NumberOfRanges;
604
 
605
    udr_errno = 0;
606
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
607
    udr_UDIInt32(udrs, &service_id);
608
    udr_UDIInt(udrs, NumberOfRanges);
609
    udr_UDIInt(udrs, NumberOfChips);
610
    udr_sendnow(udrs);
611
    if(udr_errno) return udr_errno;
612
 
613
    udrs->udr_op = UDR_DECODE;          /* receive all "out" paramters */
614
    for(cnt=1; cnt <= MaxOfRanges; cnt++)
615
        udr_UDIMemoryRange(udrs, &KnownMemory[cnt-1]);
616
    udr_UDIInt(udrs, NumberOfRanges);
617
    udr_UDIInt(udrs, NumberOfChips);
618
    for(cnt=1; cnt <= *NumberOfChips; cnt++)
619
        udr_UDIUInt32(udrs, &ChipVersions[cnt -1]);
620
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
621
    return dfe_errno;
622
}
623
 
624
/********************************************************** UDI_CREATE_PRCOESS
625
* UDICreateProcess() tells the  target  OS  that  a
626
* process is to be created and gets a PID back unless
627
* there is some error.
628
*/
629
UDIError UDICreateProcess(pid)
630
UDIPId  *pid;   /* out */
631
{
632
    UDIInt32    service_id = UDICreateProcess_c;
633
 
634
    udr_errno = 0;
635
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
636
    udr_UDIInt32(udrs, &service_id);
637
    udr_sendnow(udrs);
638
    if(udr_errno) return udr_errno;
639
 
640
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
641
    udr_UDIPId(udrs, pid);
642
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
643
    return dfe_errno;
644
}
645
 
646
/***************************************************** UDI_Set_Current_Process
647
* UDISetCurrentProcess  uses   a   pid   supplied   by
648
* UDICreateProcess  and  sets it as the default for all
649
* udi calls until a new one is set.  A user of  a
650
*/
651
UDIError UDISetCurrentProcess (pid)
652
UDIPId  pid;                    /* In */
653
{
654
    UDIInt32    service_id = UDISetCurrentProcess_c;
655
 
656
    udr_errno = 0;
657
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
658
    udr_UDIInt32(udrs, &service_id);
659
    udr_UDIPId(udrs, &pid);
660
    udr_sendnow(udrs);
661
    if(udr_errno) return udr_errno;
662
 
663
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
664
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
665
    return dfe_errno;
666
}
667
 
668
/****************************************************** UDI_INITIALISE_PROCESS
669
* UDIInitializeProcess() prepare process for
670
* execution. (Reset processor if process os processor).
671
*/
672
UDIError UDIInitializeProcess( ProcessMemory, NumberOfRanges, EntryPoint,
673
                StackSizes, NumberOfStacks, ArgString)
674
UDIMemoryRange  ProcessMemory[];        /* In */
675
UDIInt          NumberOfRanges;         /* In */
676
UDIResource     EntryPoint;             /* In */
677
CPUSizeT        *StackSizes;            /* In */
678
UDIInt          NumberOfStacks;         /* In */
679
char            *ArgString;             /* In */
680
{
681
    UDIInt32    service_id = UDIInitializeProcess_c;
682
    int         cnt;
683
 
684
    udr_errno = 0;
685
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
686
    udr_UDIInt32(udrs, &service_id);
687
    udr_UDIInt(udrs, &NumberOfRanges);
688
    for(cnt = 0; cnt < NumberOfRanges; cnt++)
689
        udr_UDIMemoryRange(udrs, &ProcessMemory[cnt] );
690
    udr_UDIResource(udrs, &EntryPoint);
691
    udr_UDIInt(udrs, &NumberOfStacks);
692
    for(cnt = 0; cnt < NumberOfStacks; cnt++)
693
        udr_CPUSizeT(udrs, &StackSizes[cnt]);
694
    udr_string(udrs, ArgString);
695
    udr_sendnow(udrs);
696
    if(udr_errno) return udr_errno;
697
 
698
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
699
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
700
    return dfe_errno;
701
}
702
 
703
/********************************************************* UDI_DESTROY_PROCESS
704
* UDIDestroyProcess() frees a process resource
705
* previously created by UDICreateProcess().
706
*/
707
UDIError UDIDestroyProcess(pid)
708
UDIPId   pid;   /* in */
709
{
710
    UDIInt32    service_id = UDIDestroyProcess_c;
711
 
712
    udr_errno = 0;
713
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
714
    udr_UDIInt32(udrs, &service_id);
715
    udr_UDIPId(udrs, &pid);
716
    udr_sendnow(udrs);
717
    if(udr_errno) return udr_errno;
718
 
719
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
720
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
721
    return dfe_errno;
722
}
723
 
724
/****************************************************************** UDI_READ
725
* UDIRead() reads a block of objects from  a  target
726
* address space  to host space.
727
*/
728
 
729
UDIError UDIRead (from, to, count, size, count_done, host_endian)
730
UDIResource     from;           /* in - source address on target */
731
UDIHostMemPtr   to;             /* out - destination address on host */
732
UDICount        count;          /* in -- count of objects to be transferred */
733
UDISizeT        size;           /* in -- size of each object */
734
UDICount        *count_done;    /* out - count actually transferred */
735
UDIBool         host_endian;    /* in -- flag for endian information */
736
{
737
    UDIInt32    service_id = UDIRead_c;
738
    int         byte_count;
739
 
740
    udr_errno = 0;
741
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
742
    udr_UDIInt32(udrs, &service_id);
743
    udr_UDIResource(udrs, &from);
744
    udr_UDICount(udrs, &count);
745
    udr_UDISizeT(udrs, &size);
746
    udr_UDIBool(udrs, &host_endian);
747
    udr_sendnow(udrs);
748
    if(udr_errno) return udr_errno;
749
 
750
    udrs->udr_op = UDR_DECODE;          /* receive all "out" paramters */
751
    udr_UDICount(udrs, count_done);
752
    byte_count = (*count_done) * size;
753
    if(*count_done > 0 && *count_done <= count)
754
        udr_bytes(udrs, to, byte_count);
755
    if(udr_errno) return udr_errno;
756
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
757
    return dfe_errno;
758
}
759
 
760
/****************************************************************** UDI_WRITE
761
* UDIWrite() writes a block  of  objects  from  host
762
* space  to  a  target  address+space.
763
*/
764
UDIError UDIWrite( from, to, count, size, count_done, host_endian )
765
UDIHostMemPtr   from;           /* in -- source address on host */
766
UDIResource     to;             /* in -- destination address on target */
767
UDICount        count;          /* in -- count of objects to be transferred */
768
UDISizeT        size;           /* in -- size of each object */
769
UDICount        *count_done;    /* out - count actually transferred */
770
UDIBool         host_endian;    /* in -- flag for endian information */
771
{
772
    UDIInt32    service_id = UDIWrite_c;
773
    int         byte_count = count * size;
774
 
775
    udr_errno = 0;
776
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
777
    udr_UDIInt32(udrs, &service_id);
778
    udr_UDIResource(udrs, &to);
779
    udr_UDICount(udrs, &count);
780
    udr_UDISizeT(udrs, &size);
781
    udr_UDIBool(udrs, &host_endian);
782
    udr_bytes(udrs, from, byte_count);
783
    udr_sendnow(udrs);
784
    if(udr_errno) return udr_errno;
785
 
786
    udrs->udr_op = UDR_DECODE;          /* receive all "out" paramters */
787
    udr_UDICount(udrs, count_done);
788
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
789
    return dfe_errno;
790
}
791
 
792
/******************************************************************** UDI_COPY
793
* UDICopy() copies a block of objects from one  target
794
* get  address/space to another target address/space.
795
*/
796
UDIError UDICopy(from, to, count, size, count_done, direction )
797
UDIResource     from;           /* in -- destination address on target */
798
UDIResource     to;             /* in -- source address on target */
799
UDICount        count;          /* in -- count of objects to be transferred */
800
UDISizeT        size;           /* in -- size of each object */
801
UDICount        *count_done;    /* out - count actually transferred */
802
UDIBool         direction;      /* in -- high-to-low or reverse */
803
{
804
    UDIInt32    service_id = UDICopy_c;
805
 
806
    udr_errno = 0;
807
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
808
    udr_UDIInt32(udrs, &service_id);
809
    udr_UDIResource(udrs, &from);
810
    udr_UDIResource(udrs, &to);
811
    udr_UDICount(udrs, &count);
812
    udr_UDISizeT(udrs, &size);
813
    udr_UDIBool(udrs, &direction);
814
    udr_sendnow(udrs);
815
    if(udr_errno) return udr_errno;
816
 
817
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
818
    udr_UDICount(udrs, count_done);
819
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
820
    return dfe_errno;
821
}
822
 
823
/***************************************************************** UDI_EXECUTE
824
* UDIExecute() continues execution  of  the  default
825
* process from the current PC.
826
*/
827
UDIError UDIExecute()
828
{
829
    UDIInt32    service_id = UDIExecute_c;
830
 
831
    udr_errno = 0;
832
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
833
    udr_UDIInt32(udrs, &service_id);
834
    udr_sendnow(udrs);
835
    if(udr_errno) return udr_errno;
836
 
837
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
838
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
839
    return dfe_errno;
840
}
841
 
842
/******************************************************************** UDI_STEP
843
* UDIStep()  specifies  a  number  of  "instruction"
844
* steps  to  make.
845
*/
846
UDIError UDIStep(steps, steptype, range)
847
UDIUInt32       steps;          /* in -- number of steps */
848
UDIStepType     steptype;       /* in -- type of stepping to be done */
849
UDIRange        range;          /* in -- range if StepInRange is TRUE */
850
{
851
    UDIInt32    service_id = UDIStep_c;
852
 
853
    udr_errno = 0;
854
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
855
    udr_UDIInt32(udrs, &service_id);
856
    udr_UDIInt32(udrs, &steps);
857
    udr_UDIStepType(udrs, &steptype);
858
    udr_UDIRange(udrs, &range);
859
    udr_sendnow(udrs);
860
    if(udr_errno) return udr_errno;
861
 
862
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
863
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
864
    return dfe_errno;
865
}
866
 
867
/******************************************************************** UDI_STOP
868
* UDIStop() stops the default process
869
*/
870
UDIVoid UDIStop()
871
{
872
    if(!strcmp(session[current].soc_con_p->domain_string, "AF_UNIX"))
873
        kill(session[current].soc_con_p->tip_pid, SIGUSR1);
874
    else
875
        udr_signal(udrs);
876
    return;
877
}
878
 
879
/******************************************************************** UDI_WAIT
880
* UDIWait() returns the state of the target  procesor.
881
*/
882
UDIError UDIWait(maxtime, pid, stop_reason)
883
UDIInt32   maxtime;        /* in -- maximum time to wait for completion */
884
UDIPId     *pid;           /* out -- pid of process which stopped if any */
885
UDIUInt32  *stop_reason;   /* out -- PC where process stopped */
886
{
887
    UDIInt32    service_id = UDIWait_c;
888
 
889
    udr_errno = 0;
890
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
891
    udr_UDIInt32(udrs, &service_id);
892
    udr_UDIInt32(udrs, &maxtime);
893
    udr_sendnow(udrs);
894
    if(udr_errno) return udr_errno;
895
 
896
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
897
    udr_UDIPId(udrs, pid);
898
    udr_UDIUInt32(udrs, stop_reason);
899
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
900
    return dfe_errno;
901
}
902
 
903
/********************************************************** UDI_SET_BREAKPOINT
904
* UDISetBreakpoint() sets a breakpoint  at  an  adress
905
* and  uses  the  passcount  to state how many
906
* times that instruction should  be  hit  before  the
907
* break  occurs.
908
*/
909
UDIError UDISetBreakpoint (addr, passcount, type, break_id)
910
UDIResource     addr;           /* in -- where breakpoint gets set */
911
UDIInt32        passcount;      /* in -- passcount for breakpoint  */
912
UDIBreakType    type;           /* in -- breakpoint type */
913
UDIBreakId      *break_id;      /* out - assigned break id */
914
{
915
    UDIInt32    service_id = UDISetBreakpoint_c;
916
 
917
    udr_errno = 0;
918
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
919
    udr_UDIInt32(udrs, &service_id);
920
    udr_UDIResource(udrs, &addr);
921
    udr_UDIInt32(udrs, &passcount);
922
    udr_UDIBreakType(udrs, &type);
923
    udr_sendnow(udrs);
924
    if(udr_errno) return udr_errno;
925
 
926
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
927
    udr_UDIBreakId(udrs, break_id);
928
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
929
    return dfe_errno;
930
}
931
 
932
/******************************************************** UDI_QUERY_BREAKPOINT
933
*/
934
UDIError UDIQueryBreakpoint (break_id, addr, passcount, type, current_count)
935
UDIBreakId      break_id;       /* in -- assigned break id */
936
UDIResource     *addr;          /* out - where breakpoint was set */
937
UDIInt32        *passcount;     /* out - trigger passcount for breakpoint  */
938
UDIBreakType    *type;          /* out - breakpoint type */
939
UDIInt32        *current_count; /* out - current count for breakpoint  */
940
{
941
    UDIInt32    service_id = UDIQueryBreakpoint_c;
942
 
943
    udr_errno = 0;
944
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
945
    udr_UDIInt32(udrs, &service_id);
946
    udr_UDIBreakId(udrs, &break_id);
947
    udr_sendnow(udrs);
948
    if(udr_errno) return udr_errno;
949
 
950
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
951
    udr_UDIResource(udrs, addr);
952
    udr_UDIInt32(udrs, passcount);
953
    udr_UDIBreakType(udrs, type);
954
    udr_UDIInt32(udrs, current_count);
955
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
956
    return dfe_errno;
957
}
958
 
959
/******************************************************** UDI_CLEAR_BREAKPOINT
960
* UDIClearBreakpoint() is used to  clear  a  breakpoint.
961
*/
962
UDIError UDIClearBreakpoint (break_id)
963
UDIBreakId      break_id;       /* in -- assigned break id */
964
{
965
    UDIInt32    service_id = UDIClearBreakpoint_c;
966
 
967
    udr_errno = 0;
968
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
969
    udr_UDIInt32(udrs, &service_id);
970
    udr_UDIBreakId(udrs, &break_id);
971
    udr_sendnow(udrs);
972
    if(udr_errno) return udr_errno;
973
 
974
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
975
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
976
    return dfe_errno;
977
}
978
 
979
/************************************************************** UDI_GET_STDOUT
980
* UDIGetStdout()  is  called   when   a   call   to
981
* UDIWait() indicates there is STD output data ready.
982
*/
983
UDIError UDIGetStdout(buf, bufsize, count_done)
984
UDIHostMemPtr   buf;            /* out -- buffer to be filled */
985
UDISizeT        bufsize;        /* in  -- buffer size in bytes */
986
UDISizeT        *count_done;    /* out -- number of bytes written to buf */
987
{
988
    UDIInt32    service_id = UDIGetStdout_c;
989
 
990
    udr_errno = 0;
991
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
992
    udr_UDIInt32(udrs, &service_id);
993
    udr_UDISizeT(udrs, &bufsize);
994
    udr_sendnow(udrs);
995
    if(udr_errno) return udr_errno;
996
 
997
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
998
    udr_UDISizeT(udrs, count_done);
999
    udr_bytes(udrs, buf, *count_done);
1000
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
1001
    return dfe_errno;
1002
}
1003
 
1004
/************************************************************** UDI_GET_STDERR
1005
* UDIGetStderr()  is  called   when   a   call   to
1006
* UDIWait() indicates there is STDERR output data ready
1007
*/
1008
UDIError UDIGetStderr(buf, bufsize, count_done)
1009
UDIHostMemPtr   buf;            /* out -- buffer to be filled */
1010
UDISizeT        bufsize;        /* in  -- buffer size in bytes */
1011
UDISizeT        *count_done;    /* out -- number of bytes written to buf */
1012
{
1013
    UDIInt32    service_id = UDIGetStderr_c;
1014
 
1015
    udr_errno = 0;
1016
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
1017
    udr_UDIInt32(udrs, &service_id);
1018
    udr_UDISizeT(udrs, &bufsize);
1019
    udr_sendnow(udrs);
1020
    if(udr_errno) return udr_errno;
1021
 
1022
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
1023
    udr_UDISizeT(udrs, count_done);
1024
    udr_bytes(udrs, buf, *count_done);
1025
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
1026
    return dfe_errno;
1027
}
1028
 
1029
/*************************************************************** UDI_PUT_STDIN
1030
* UDIPutStdin() is called whenever the DFE wants to
1031
* deliver an input character to the TIP.
1032
*/
1033
UDIError UDIPutStdin (buf, count, count_done)
1034
UDIHostMemPtr   buf;            /* in -- buffer to be filled */
1035
UDISizeT        count;          /* in -- buffer size in bytes */
1036
UDISizeT        *count_done;    /* out - number of bytes written to buf */
1037
{
1038
    UDIInt32    service_id = UDIPutStdin_c;
1039
 
1040
    udr_errno = 0;
1041
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
1042
    udr_UDIInt32(udrs, &service_id);
1043
    udr_UDISizeT(udrs, &count);
1044
    udr_bytes(udrs, buf, count);
1045
    udr_sendnow(udrs);
1046
    if(udr_errno) return udr_errno;
1047
 
1048
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
1049
    udr_UDISizeT(udrs, count_done);
1050
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
1051
    return dfe_errno;
1052
}
1053
 
1054
/************************************************************** UDI_STDIN_MODE
1055
* UDIStdinMode() is used to change the mode that chazcters
1056
* are fetched from the user.
1057
*/
1058
UDIError        UDIStdinMode(mode)
1059
UDIMode         *mode;          /* out - */
1060
{
1061
    UDIInt32    service_id = UDIStdinMode_c;
1062
 
1063
    udr_errno = 0;
1064
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
1065
    udr_UDIInt32(udrs, &service_id);
1066
    udr_sendnow(udrs);
1067
    if(udr_errno) return udr_errno;
1068
 
1069
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
1070
    udr_UDIMode(udrs, mode);
1071
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
1072
    return dfe_errno;
1073
}
1074
 
1075
/*************************************************************** UDI_PUT_TRANS
1076
* UDIPutTrans() is used to feed input to  the  passthru  mode.
1077
*/
1078
UDIError        UDIPutTrans (buf, count, count_done)
1079
UDIHostMemPtr   buf;            /* in -- buffer address containing input data */
1080
UDISizeT        count;          /* in -- number of bytes in buf */
1081
UDISizeT        *count_done;    /* out-- number of bytes transfered */
1082
{
1083
    UDIInt32    service_id = UDIPutTrans_c;
1084
 
1085
    udr_errno = 0;
1086
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
1087
    udr_UDIInt32(udrs, &service_id);
1088
    udr_UDISizeT(udrs, &count);
1089
    udr_bytes(udrs, buf, count);
1090
    udr_sendnow(udrs);
1091
    if(udr_errno) return udr_errno;
1092
 
1093
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
1094
    udr_UDISizeT(udrs, count_done);
1095
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
1096
    return dfe_errno;
1097
}
1098
 
1099
/*************************************************************** UDI_GET_TRANS
1100
* UDIGetTrans() is used to get output lines from the
1101
* passthru mode.
1102
*/
1103
UDIError        UDIGetTrans (buf, bufsize, count_done)
1104
UDIHostMemPtr   buf;            /* out -- buffer to be filled */
1105
UDISizeT        bufsize;        /* in  -- size of buf */
1106
UDISizeT        *count_done;    /* out -- number of bytes in buf */
1107
{
1108
    UDIInt32    service_id = UDIGetTrans_c;
1109
 
1110
    udr_errno = 0;
1111
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
1112
    udr_UDIInt32(udrs, &service_id);
1113
    udr_UDISizeT(udrs, &bufsize);
1114
    udr_sendnow(udrs);
1115
    if(udr_errno) return udr_errno;
1116
 
1117
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
1118
    udr_UDISizeT(udrs, count_done);
1119
    udr_bytes(udrs, buf, *count_done);
1120
    udr_UDIError(udrs, &dfe_errno);     /* get any TIP error */
1121
    return dfe_errno;
1122
}
1123
 
1124
/************************************************************** UDI_Trans_Mode
1125
* UDITransMode() is used to change the mode that the
1126
* transparent routines operate in.
1127
*/
1128
UDIError UDITransMode(mode)
1129
UDIMode         *mode;          /* out  -- selected mode */
1130
{
1131
    UDIInt32    service_id = UDITransMode_c;
1132
 
1133
    udr_errno = 0;
1134
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
1135
    udr_UDIInt32(udrs, &service_id);
1136
    udr_UDIMode(udrs, mode);
1137
    udr_sendnow(udrs);
1138
    if(udr_errno) return udr_errno;
1139
 
1140
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
1141
    udr_UDIError(udrs, &dfe_errno);
1142
    return dfe_errno;
1143
}
1144
 
1145
/******************************************************************** UDI_TEST
1146
*/
1147
UDIError UDITest( cnt, str_p, array)
1148
UDISizeT        cnt;
1149
UDIHostMemPtr   str_p;
1150
UDIInt32        array[];
1151
{
1152
    UDIInt32    service_id = UDITest_c;
1153
    UDIInt16    scnt = cnt;
1154
    UDISizeT    r_cnt;
1155
    char        buf[256];
1156
 
1157
    udr_errno = 0;
1158
    udrs->udr_op = UDR_ENCODE;          /* send all "in" parameters */
1159
    udr_UDIInt32(udrs, &service_id);
1160
 
1161
    printf("send        cnt=%d scnt=%d\n", cnt, scnt);
1162
    udr_UDISizeT(udrs, &cnt);
1163
    udr_UDIInt16(udrs, &scnt);
1164
    printf("    array[0]=0x%x array[1]=0x%x array[2]=0x%x array[3]=0x%x\n",
1165
        array[0], array[1], array[2], array[3]);
1166
    udr_bytes(udrs, (char*)array, 4*sizeof(UDIInt32));
1167
    printf("    string=%s\n", str_p);
1168
    udr_string(udrs, str_p);
1169
    udr_sendnow(udrs);
1170
    if(udr_errno)
1171
    {   fprintf(stderr, " DFE-ipc Send ERROR\n");
1172
        return udr_errno;
1173
    }
1174
 
1175
    udrs->udr_op = UDR_DECODE;          /* receive all "out" parameters */
1176
    printf("recv        ");
1177
    udr_UDISizeT(udrs, &r_cnt);
1178
    udr_UDIInt16(udrs, &scnt);
1179
    printf("    rcnt=%d scnt=%d\n", r_cnt, scnt);
1180
    udr_bytes(udrs, (char*)array, 4*sizeof(UDIInt32));
1181
 
1182
    printf("    array[0]=0x%x array[1]=0x%x array[2]=0x%x array[3]=0x%x\n",
1183
        array[0], array[1], array[2], array[3]);
1184
    udr_string(udrs, str_p);
1185
    printf("    string=%s\n", str_p);
1186
 
1187
    udr_UDIError(udrs, &dfe_errno);
1188
    return dfe_errno;
1189
}
1190
 
1191
UDIUInt32 UDIGetDFEIPCId()
1192
{
1193
    return ((company_c << 16) + (product_c << 12) + version_c);
1194
}
1195
 

powered by: WebSVN 2.1.0

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