1 /* Copyright 1993 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19 static char udip2soc_c[]="@(#)udip2soc.c 2.11 Daniel Mann";
20 static char udip2soc_c_AMD[]="@(#)udip2soc.c 2.8, AMD";
22 * This module converts UDI Procedural calls into
23 * UDI socket messages for UNIX.
24 * It is used by DFE client processes
25 ********************************************************************** HISTORY
30 #include <sys/fcntl.h>
33 #include <sys/resource.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
39 #include <sys/errno.h>
45 extern char* sys_errlist[];
47 extern char* getenv();
49 /* local type decs. and macro defs. not in a .h file ************* MACRO/TYPE
51 #define version_c 0x121 /* DFE-IPC version id */
55 #define MAX_SESSIONS 5 /* maximum DFE-TIP connections */
56 #define SOC_BUF_SIZE 4* 1024 /* size of socket comms buffer */
57 #define SBUF_SIZE 500 /* size of string buffer */
58 #define ERRMSG_SIZE 500 /* size of error message buffer */
60 typedef struct connection_str /* record of connect session */
63 char connect_id[20]; /* connection identifier */
64 char domain_string[20]; /* dommaing for conection */
65 char tip_string[30]; /* TIP host name for AF_INET */
66 char tip_exe[80]; /* TIP exe name */
67 int dfe_sd; /* associated DFE socket */
68 int tip_pid; /* pid of TIP process */
69 struct sockaddr_in dfe_sockaddr;
70 struct sockaddr_in tip_sockaddr_in;
71 struct sockaddr tip_sockaddr;
74 typedef struct session_str
77 connection_t* soc_con_p; /* associated connection */
78 UDISessionId tip_id; /* associated TIP session ID */
81 /* global dec/defs. which are not in a .h file ************* EXPORT DEC/DEFS
84 char dfe_errmsg[ERRMSG_SIZE];/* error string */
86 /* local dec/defs. which are not in a .h file *************** LOCAL DEC/DEFS
88 LOCAL connection_t soc_con[MAX_SESSIONS];
89 LOCAL session_t session[MAX_SESSIONS];
91 LOCAL UDR* udrs = &udr; /* UDR for current session */
92 LOCAL int current; /* int-id for current session */
93 LOCAL char sbuf[SBUF_SIZE]; /* String handler buffer */
94 LOCAL char config_file[80]; /* path/name for config file */
96 /***************************************************************** UDI_CONNECT
97 * Establish a new FDE to TIP conection. The file "./udi_soc" or
98 * "/etc/udi_soc" may be examined to obtain the conection information
99 * if the "Config" parameter is not a completd "line entry".
101 * NOTE: the Session string must not start whith white-space characters.
102 * Format of string is:
103 * <session> <domain> <soc_name|host_name> <tip_exe|port> <pass to UDIconnect>
104 * soc2cayman AF_INET cayman 7000 <not supported>
105 * soc2tip AF_UNIX astring tip.exe ...
108 UDIConnect(Config, Session)
109 char *Config; /* in -- identification string */
110 UDISessionId *Session; /* out -- session ID */
112 UDIInt32 service_id = UDIConnect_c;
115 int rcnt, pos, params_pos=0;
116 char *tip_main_string;
118 struct hostent *tip_info_p;
126 #if 0 /* This is crap. It assumes that udi_soc is executable! */
127 sprintf(sbuf, "which udi_soc");
128 f_p = popen(sbuf, "r");
130 { while( (sbuf[cnt++]=getc(f_p)) != EOF);
137 rcnt < MAX_SESSIONS && session[rcnt].in_use;
140 if (rcnt >= MAX_SESSIONS)
142 sprintf(dfe_errmsg, "DFE-ipc ERROR: Too many sessions already open");
143 return UDIErrorIPCLimitation;
146 /* One connection can be multiplexed between several sessions. */
149 cnt < MAX_SESSIONS && soc_con[cnt].in_use;
152 if (cnt >= MAX_SESSIONS)
155 "DFE-ipc ERROR: Too many connections already open");
156 return UDIErrorIPCLimitation;
160 session[rcnt].soc_con_p = &soc_con[cnt];
162 if (strchr(Config, ' ')) /* test if file entry given */
164 soc_con[cnt].in_use = TRUE;
165 sscanf(Config, "%s %s %s %s %n",
166 soc_con[cnt].connect_id,
167 soc_con[cnt].domain_string,
168 soc_con[cnt].tip_string,
169 soc_con[cnt].tip_exe,
171 tip_main_string = Config + params_pos;
173 else /* here if need to read udi_soc file */
175 strcpy(config_file, "udi_soc");
176 env_p = getenv("UDICONF");
178 strcpy(config_file, env_p);
180 fd = fopen(config_file, "r");
184 sprintf(dfe_errmsg, "UDIConnect, can't open udi_soc file:\n%s ",
186 dfe_errno = UDIErrorCantOpenConfigFile;
192 if (fscanf(fd, "%s %s %s %s %[^\n]\n",
193 soc_con[cnt].connect_id,
194 soc_con[cnt].domain_string,
195 soc_con[cnt].tip_string,
196 soc_con[cnt].tip_exe,
200 if (strcmp(Config, soc_con[cnt].connect_id) != 0)
203 soc_con[cnt].in_use = TRUE; /* here if entry found */
205 tip_main_string = sbuf;
210 if (!soc_con[cnt].in_use)
213 "UDIConnect, can't find `%s' entry in udi_soc file",
215 dfe_errno = UDIErrorNoSuchConfiguration;
219 /*----------------------------------------------------------- SELECT DOMAIN */
220 if (strcmp(soc_con[cnt].domain_string, "AF_UNIX") == 0)
222 else if (strcmp(soc_con[cnt].domain_string, "AF_INET") == 0)
226 sprintf(dfe_errmsg, "DFE-ipc ERROR: socket address family not known");
227 dfe_errno = UDIErrorBadConfigFileEntry;
231 /*---------------------------------------------------- MULTIPLEXED SOCKET ? */
232 /* If the requested session requires communication with
233 a TIP which already has a socket connection established,
234 then we do not create a new socket but multiplex the
235 existing one. A TIP is said to use the same socket if
236 socket-name/host-name and the domain are the same.
238 for (rcnt=0; rcnt < MAX_SESSIONS; rcnt++)
240 if (soc_con[rcnt].in_use
242 && strcmp(soc_con[cnt].domain_string,
243 soc_con[rcnt].domain_string) == 0
244 && strcmp(soc_con[cnt].tip_string,
245 soc_con[rcnt].tip_string) == 0)
247 session[*Session].soc_con_p = &soc_con[rcnt];
248 soc_con[cnt].in_use = FALSE; /* don't need new connect */
252 /*------------------------------------------------------------------ SOCKET */
253 soc_con[cnt].dfe_sd = socket(domain, SOCK_STREAM, 0);
254 if (soc_con[cnt].dfe_sd == -1)
256 sprintf(dfe_errmsg, "DFE-ipc ERROR, socket() call failed %s ",
258 dfe_errno = UDIErrorUnknownError;
262 /*--------------------------------------------------------- AF_UNIX CONNECT */
263 if (domain == AF_UNIX)
265 if (strcmp(soc_con[cnt].tip_string, "*") == 0)
267 for (pos = 0; pos < 20; pos++)
271 sprintf(soc_con[cnt].tip_string,"/tmp/U%d", getpid() + pos);
272 f = open(soc_con[cnt].tip_string, O_CREAT);
277 unlink(soc_con[cnt].tip_string);
284 "DFE-ipc ERROR, can't create random socket name");
285 dfe_errno = UDIErrorCantConnect;
290 soc_con[cnt].tip_sockaddr.sa_family = domain;
291 bcopy(soc_con[cnt].tip_string,
292 soc_con[cnt].tip_sockaddr.sa_data,
293 sizeof(soc_con[cnt].tip_sockaddr.sa_data));
294 if (connect(soc_con[cnt].dfe_sd,
295 &soc_con[cnt].tip_sockaddr,
296 sizeof(soc_con[cnt].tip_sockaddr)))
297 { /* if connect() fails assume TIP not yet started */
298 /*------------------------------------------------------------ AF_UNIX EXEC */
303 arg0 = strrchr(soc_con[cnt].tip_exe,'/');
308 arg0 = soc_con[cnt].tip_exe;
312 if (pid == 0) /* Child */
314 execlp(soc_con[cnt].tip_exe,
316 soc_con[cnt].domain_string,
317 soc_con[cnt].tip_string,
322 if (waitpid(pid, &statusp, WNOHANG))
324 sprintf(dfe_errmsg, "DFE-ipc ERROR: can't exec the TIP");
325 dfe_errno = UDIErrorCantStartTIP;
330 for (pos = 3; pos > 0; pos--)
332 if (!connect(soc_con[cnt].dfe_sd,
333 &soc_con[cnt].tip_sockaddr,
334 sizeof(soc_con[cnt].tip_sockaddr)))
341 sprintf(dfe_errmsg, "DFE-ipc ERROR, connect() call failed: %s",
343 dfe_errno = UDIErrorCantConnect;
348 /*--------------------------------------------------------- AF_INET CONNECT */
349 else if (domain == AF_INET)
352 "DFE-ipc WARNING, need to have first started remote TIP");
354 soc_con[cnt].tip_sockaddr_in.sin_family = domain;
355 soc_con[cnt].tip_sockaddr_in.sin_addr.s_addr =
356 inet_addr(soc_con[cnt].tip_string);
357 if (soc_con[cnt].tip_sockaddr_in.sin_addr.s_addr == -1)
359 tip_info_p = gethostbyname(soc_con[cnt].tip_string);
360 if (tip_info_p == NULL)
362 sprintf(dfe_errmsg,"DFE-ipc ERROR, No such host %s",
363 soc_con[cnt].tip_string);
364 dfe_errno = UDIErrorNoSuchConnection;
367 bcopy(tip_info_p->h_addr,
368 (char *)&soc_con[cnt].tip_sockaddr_in.sin_addr,
369 tip_info_p->h_length);
371 soc_con[cnt].tip_sockaddr_in.sin_port
372 = htons(atoi(soc_con[cnt].tip_exe));
374 if (connect(soc_con[cnt].dfe_sd,
375 (struct sockaddr *) &soc_con[cnt].tip_sockaddr_in,
376 sizeof(soc_con[cnt].tip_sockaddr_in)))
378 sprintf(dfe_errmsg, "DFE-ipc ERROR, connect() call failed %s ",
380 dfe_errno = UDIErrorCantConnect;
384 /*------------------------------------------------------------- TIP CONNECT */
385 if (cnt == 0) udr_create(udrs, soc_con[cnt].dfe_sd, SOC_BUF_SIZE);
389 session[*Session].in_use = TRUE; /* session id is now in use */
392 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
393 udr_UDIInt32(udrs, &service_id);
395 DFEIPCId = (company_c << 16) + (product_c << 12) + version_c;
396 udr_UDIUInt32(udrs, &DFEIPCId);
398 udr_string(udrs, tip_main_string);
402 udrs->udr_op = UDR_DECODE; /* recv all "out" parameters */
403 udr_UDIUInt32(udrs, &TIPIPCId);
404 if ((TIPIPCId & 0xfff) < version_c)
405 sprintf(dfe_errmsg, "DFE-ipc: Obsolete TIP Specified");
407 udr_UDIInt32(udrs, &soc_con[cnt].tip_pid);
409 udr_UDISessionId(udrs, &session[*Session].tip_id);
411 udr_UDIError(udrs, &dfe_errno);
412 if (dfe_errno > 0) UDIKill(*Session, 0);
418 soc_con[cnt].in_use = FALSE;
419 session[*Session].in_use = FALSE;
420 /* XXX - Should also close dfe_sd, but not sure what to do if muxed */
424 /************************************************************** UDI_Disconnect
425 * UDIDisconnect() should be called before exiting the
426 * DFE to ensure proper shut down of the TIP.
428 UDIError UDIDisconnect(Session, Terminate)
429 UDISessionId Session;
433 UDIInt32 service_id = UDIDisconnect_c;
434 if(Session < 0 || Session > MAX_SESSIONS)
436 sprintf(dfe_errmsg," SessionId not valid (%d)", Session);
437 return UDIErrorNoSuchConfiguration;
440 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
441 udr_UDIInt32(udrs, &service_id);
442 udr_UDISessionId(udrs, &session[Session].tip_id);
443 udr_UDIBool(udrs, &Terminate);
446 session[Session].in_use = FALSE; /* session id is now free */
447 for (cnt=0; cnt < MAX_SESSIONS; cnt++)
448 if(session[cnt].in_use
449 && session[cnt].soc_con_p == session[Session].soc_con_p
451 if(cnt >= MAX_SESSIONS) /* test if socket not multiplexed */
452 if(shutdown(session[Session].soc_con_p->dfe_sd, 2))
454 sprintf(dfe_errmsg, "DFE-ipc WARNING: socket shutdown failed");
455 return UDIErrorIPCInternal;
458 session[Session].soc_con_p->in_use = 0;
460 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
461 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
465 /******************************************************************** UDI_KILL
466 * UDIKill() is used to send a signal to the TIP.
467 * This is a private IPC call.
469 UDIError UDIKill(Session, Signal)
470 UDISessionId Session;
474 UDIInt32 service_id = UDIKill_c;
475 if(Session < 0 || Session > MAX_SESSIONS)
477 sprintf(dfe_errmsg," SessionId not valid (%d)", Session);
478 return UDIErrorNoSuchConfiguration;
481 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
482 udr_UDIInt32(udrs, &service_id);
483 udr_UDISessionId(udrs, &session[Session].tip_id);
484 udr_UDIInt32(udrs, &Signal);
487 session[Session].in_use = FALSE; /* session id is now free */
488 for (cnt=0; cnt < MAX_SESSIONS; cnt++)
489 if(session[cnt].in_use
490 && session[cnt].soc_con_p == session[Session].soc_con_p
492 if(cnt < MAX_SESSIONS) /* test if socket not multiplexed */
493 if(shutdown(session[Session].soc_con_p->dfe_sd, 2))
495 sprintf(dfe_errmsg, "DFE-ipc WARNING: socket shutdown failed");
496 return UDIErrorIPCInternal;
499 session[Session].soc_con_p->in_use = 0;
501 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
502 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
506 /************************************************** UDI_Set_Current_Connection
507 * If you are connected to multiple TIPs, you can change
508 * TIPs using UDISetCurrentConnection().
510 UDIError UDISetCurrentConnection(Session)
511 UDISessionId Session;
513 UDIInt32 service_id = UDISetCurrentConnection_c;
515 if(Session < 0 || Session > MAX_SESSIONS)
516 return UDIErrorNoSuchConfiguration;
517 if(!session[Session].in_use) /* test if not in use yet */
518 return UDIErrorNoSuchConnection;
521 /* change socket or multiplex the same socket */
522 udrs->sd = session[Session].soc_con_p->dfe_sd;
525 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
526 udr_UDIInt32(udrs, &service_id);
527 udr_UDISessionId(udrs, &session[Session].tip_id);
529 if(udr_errno) return udr_errno;
531 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
532 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
536 /************************************************************ UDI_Capabilities
537 * The DFE uses UDICapabilities() to both inform the TIP
538 * of what services the DFE offers and to inquire of the
539 * TIP what services the TIP offers.
541 UDIError UDICapabilities(TIPId, TargetId, DFEId, DFE, TIP, DFEIPCId,
543 UDIUInt32 *TIPId; /* out */
544 UDIUInt32 *TargetId; /* out */
545 UDIUInt32 DFEId; /* in */
546 UDIUInt32 DFE; /* in */
547 UDIUInt32 *TIP; /* out */
548 UDIUInt32 *DFEIPCId; /* out */
549 UDIUInt32 *TIPIPCId; /* out */
550 char *TIPString; /* out */
552 UDIInt32 service_id = UDICapabilities_c;
556 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
557 udr_UDIInt32(udrs, &service_id);
558 udr_UDIInt32(udrs, &DFEId);
559 udr_UDIInt32(udrs, &DFE);
561 if(udr_errno) return udr_errno;
563 udrs->udr_op = UDR_DECODE; /* receive all "out" paramters */
564 udr_UDIInt32(udrs, TIPId);
565 udr_UDIInt32(udrs, TargetId);
566 udr_UDIInt32(udrs, TIP);
567 udr_UDIInt32(udrs, DFEIPCId);
568 *DFEIPCId = (company_c << 16) + (product_c << 12) + version_c;
569 udr_UDIInt32(udrs, TIPIPCId);
570 udr_string(udrs, sbuf);
571 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
573 if(size +1 > 80) return -1; /* test if sufficient space */
574 strcpy(TIPString, sbuf);
578 /********************************************************** UDI_Enumerate_TIPs
579 * Used by the DFE to enquire about available TIP
582 UDIError UDIEnumerateTIPs(UDIETCallback)
583 int (*UDIETCallback)(); /* In -- function to callback */
587 fp = fopen(config_file, "r");
589 return UDIErrorCantOpenConfigFile;
590 while(fgets( sbuf, SBUF_SIZE, fp))
591 if(UDIETCallback( sbuf) == UDITerminateEnumeration)
594 return UDINoError; /* return success */
597 /*********************************************************** UDI_GET_ERROR_MSG
598 * Some errors are target specific. They are indicated
599 * by a negative error return value. The DFE uses
600 * UDIGetErrorMsg() to get the descriptive text for
601 * the error message which can then be displayed to
604 UDIError UDIGetErrorMsg(error_code, msg_len, msg, CountDone)
605 UDIError error_code; /* In */
606 UDISizeT msg_len; /* In -- allowed message space */
607 char* msg; /* Out -- length of message*/
608 UDISizeT *CountDone; /* Out -- number of characters */
610 UDIInt32 service_id = UDIGetErrorMsg_c;
614 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
615 udr_UDIInt32(udrs, &service_id);
616 udr_UDIError(udrs, &error_code);
617 udr_UDISizeT(udrs, &msg_len);
619 if(udr_errno) return udr_errno;
621 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
622 udr_string(udrs, sbuf);
623 udr_UDISizeT(udrs, CountDone);
624 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
626 if(size +1 > msg_len) return -1; /* test if sufficient space */
631 /******************************************************* UDI_GET_TARGET_CONFIG
632 * UDIGetTargetConfig() gets information about the target.
634 UDIError UDIGetTargetConfig(KnownMemory, NumberOfRanges, ChipVersions,
636 UDIMemoryRange KnownMemory[]; /* Out */
637 UDIInt *NumberOfRanges; /* In and Out */
638 UDIUInt32 ChipVersions[]; /* Out */
639 UDIInt *NumberOfChips; /* In and Out */
641 UDIInt32 service_id = UDIGetTargetConfig_c;
643 int MaxOfRanges = *NumberOfRanges;
646 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
647 udr_UDIInt32(udrs, &service_id);
648 udr_UDIInt(udrs, NumberOfRanges);
649 udr_UDIInt(udrs, NumberOfChips);
651 if(udr_errno) return udr_errno;
653 udrs->udr_op = UDR_DECODE; /* receive all "out" paramters */
654 for(cnt=1; cnt <= MaxOfRanges; cnt++)
655 udr_UDIMemoryRange(udrs, &KnownMemory[cnt-1]);
656 udr_UDIInt(udrs, NumberOfRanges);
657 udr_UDIInt(udrs, NumberOfChips);
658 for(cnt=1; cnt <= *NumberOfChips; cnt++)
659 udr_UDIUInt32(udrs, &ChipVersions[cnt -1]);
660 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
664 /********************************************************** UDI_CREATE_PRCOESS
665 * UDICreateProcess() tells the target OS that a
666 * process is to be created and gets a PID back unless
667 * there is some error.
669 UDIError UDICreateProcess(pid)
670 UDIPId *pid; /* out */
672 UDIInt32 service_id = UDICreateProcess_c;
675 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
676 udr_UDIInt32(udrs, &service_id);
678 if(udr_errno) return udr_errno;
680 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
681 udr_UDIPId(udrs, pid);
682 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
686 /***************************************************** UDI_Set_Current_Process
687 * UDISetCurrentProcess uses a pid supplied by
688 * UDICreateProcess and sets it as the default for all
689 * udi calls until a new one is set. A user of a
691 UDIError UDISetCurrentProcess (pid)
694 UDIInt32 service_id = UDISetCurrentProcess_c;
697 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
698 udr_UDIInt32(udrs, &service_id);
699 udr_UDIPId(udrs, &pid);
701 if(udr_errno) return udr_errno;
703 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
704 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
708 /****************************************************** UDI_INITIALISE_PROCESS
709 * UDIInitializeProcess() prepare process for
710 * execution. (Reset processor if process os processor).
712 UDIError UDIInitializeProcess( ProcessMemory, NumberOfRanges, EntryPoint,
713 StackSizes, NumberOfStacks, ArgString)
714 UDIMemoryRange ProcessMemory[]; /* In */
715 UDIInt NumberOfRanges; /* In */
716 UDIResource EntryPoint; /* In */
717 CPUSizeT *StackSizes; /* In */
718 UDIInt NumberOfStacks; /* In */
719 char *ArgString; /* In */
721 UDIInt32 service_id = UDIInitializeProcess_c;
725 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
726 udr_UDIInt32(udrs, &service_id);
727 udr_UDIInt(udrs, &NumberOfRanges);
728 for(cnt = 0; cnt < NumberOfRanges; cnt++)
729 udr_UDIMemoryRange(udrs, &ProcessMemory[cnt] );
730 udr_UDIResource(udrs, &EntryPoint);
731 udr_UDIInt(udrs, &NumberOfStacks);
732 for(cnt = 0; cnt < NumberOfStacks; cnt++)
733 udr_CPUSizeT(udrs, &StackSizes[cnt]);
734 udr_string(udrs, ArgString);
736 if(udr_errno) return udr_errno;
738 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
739 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
743 /********************************************************* UDI_DESTROY_PROCESS
744 * UDIDestroyProcess() frees a process resource
745 * previously created by UDICreateProcess().
747 UDIError UDIDestroyProcess(pid)
750 UDIInt32 service_id = UDIDestroyProcess_c;
753 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
754 udr_UDIInt32(udrs, &service_id);
755 udr_UDIPId(udrs, &pid);
757 if(udr_errno) return udr_errno;
759 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
760 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
764 /****************************************************************** UDI_READ
765 * UDIRead() reads a block of objects from a target
766 * address space to host space.
769 UDIError UDIRead (from, to, count, size, count_done, host_endian)
770 UDIResource from; /* in - source address on target */
771 UDIHostMemPtr to; /* out - destination address on host */
772 UDICount count; /* in -- count of objects to be transferred */
773 UDISizeT size; /* in -- size of each object */
774 UDICount *count_done; /* out - count actually transferred */
775 UDIBool host_endian; /* in -- flag for endian information */
777 UDIInt32 service_id = UDIRead_c;
781 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
782 udr_UDIInt32(udrs, &service_id);
783 udr_UDIResource(udrs, &from);
784 udr_UDICount(udrs, &count);
785 udr_UDISizeT(udrs, &size);
786 udr_UDIBool(udrs, &host_endian);
788 if(udr_errno) return udr_errno;
790 udrs->udr_op = UDR_DECODE; /* receive all "out" paramters */
791 udr_UDICount(udrs, count_done);
792 byte_count = (*count_done) * size;
793 if(*count_done > 0 && *count_done <= count)
794 udr_bytes(udrs, to, byte_count);
795 if(udr_errno) return udr_errno;
796 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
800 /****************************************************************** UDI_WRITE
801 * UDIWrite() writes a block of objects from host
802 * space to a target address+space.
804 UDIError UDIWrite( from, to, count, size, count_done, host_endian )
805 UDIHostMemPtr from; /* in -- source address on host */
806 UDIResource to; /* in -- destination address on target */
807 UDICount count; /* in -- count of objects to be transferred */
808 UDISizeT size; /* in -- size of each object */
809 UDICount *count_done; /* out - count actually transferred */
810 UDIBool host_endian; /* in -- flag for endian information */
812 UDIInt32 service_id = UDIWrite_c;
813 int byte_count = count * size;
816 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
817 udr_UDIInt32(udrs, &service_id);
818 udr_UDIResource(udrs, &to);
819 udr_UDICount(udrs, &count);
820 udr_UDISizeT(udrs, &size);
821 udr_UDIBool(udrs, &host_endian);
822 udr_bytes(udrs, from, byte_count);
824 if(udr_errno) return udr_errno;
826 udrs->udr_op = UDR_DECODE; /* receive all "out" paramters */
827 udr_UDICount(udrs, count_done);
828 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
832 /******************************************************************** UDI_COPY
833 * UDICopy() copies a block of objects from one target
834 * get address/space to another target address/space.
836 UDIError UDICopy(from, to, count, size, count_done, direction )
837 UDIResource from; /* in -- destination address on target */
838 UDIResource to; /* in -- source address on target */
839 UDICount count; /* in -- count of objects to be transferred */
840 UDISizeT size; /* in -- size of each object */
841 UDICount *count_done; /* out - count actually transferred */
842 UDIBool direction; /* in -- high-to-low or reverse */
844 UDIInt32 service_id = UDICopy_c;
847 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
848 udr_UDIInt32(udrs, &service_id);
849 udr_UDIResource(udrs, &from);
850 udr_UDIResource(udrs, &to);
851 udr_UDICount(udrs, &count);
852 udr_UDISizeT(udrs, &size);
853 udr_UDIBool(udrs, &direction);
855 if(udr_errno) return udr_errno;
857 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
858 udr_UDICount(udrs, count_done);
859 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
863 /***************************************************************** UDI_EXECUTE
864 * UDIExecute() continues execution of the default
865 * process from the current PC.
867 UDIError UDIExecute()
869 UDIInt32 service_id = UDIExecute_c;
872 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
873 udr_UDIInt32(udrs, &service_id);
875 if(udr_errno) return udr_errno;
877 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
878 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
882 /******************************************************************** UDI_STEP
883 * UDIStep() specifies a number of "instruction"
886 UDIError UDIStep(steps, steptype, range)
887 UDIUInt32 steps; /* in -- number of steps */
888 UDIStepType steptype; /* in -- type of stepping to be done */
889 UDIRange range; /* in -- range if StepInRange is TRUE */
891 UDIInt32 service_id = UDIStep_c;
894 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
895 udr_UDIInt32(udrs, &service_id);
896 udr_UDIInt32(udrs, &steps);
897 udr_UDIStepType(udrs, &steptype);
898 udr_UDIRange(udrs, &range);
900 if(udr_errno) return udr_errno;
902 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
903 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
907 /******************************************************************** UDI_STOP
908 * UDIStop() stops the default process
912 if (strcmp(session[current].soc_con_p->domain_string, "AF_UNIX") == 0)
913 kill(session[current].soc_con_p->tip_pid, SIGINT);
917 /* XXX - should clean up session[] and soc_con[] structs here as well... */
922 /******************************************************************** UDI_WAIT
923 * UDIWait() returns the state of the target procesor.
925 UDIError UDIWait(maxtime, pid, stop_reason)
926 UDIInt32 maxtime; /* in -- maximum time to wait for completion */
927 UDIPId *pid; /* out -- pid of process which stopped if any */
928 UDIUInt32 *stop_reason; /* out -- PC where process stopped */
930 UDIInt32 service_id = UDIWait_c;
933 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
934 udr_UDIInt32(udrs, &service_id);
935 udr_UDIInt32(udrs, &maxtime);
937 if(udr_errno) return udr_errno;
939 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
940 udr_UDIPId(udrs, pid);
941 udr_UDIUInt32(udrs, stop_reason);
942 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
946 /********************************************************** UDI_SET_BREAKPOINT
947 * UDISetBreakpoint() sets a breakpoint at an adress
948 * and uses the passcount to state how many
949 * times that instruction should be hit before the
952 UDIError UDISetBreakpoint (addr, passcount, type, break_id)
953 UDIResource addr; /* in -- where breakpoint gets set */
954 UDIInt32 passcount; /* in -- passcount for breakpoint */
955 UDIBreakType type; /* in -- breakpoint type */
956 UDIBreakId *break_id; /* out - assigned break id */
958 UDIInt32 service_id = UDISetBreakpoint_c;
961 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
962 udr_UDIInt32(udrs, &service_id);
963 udr_UDIResource(udrs, &addr);
964 udr_UDIInt32(udrs, &passcount);
965 udr_UDIBreakType(udrs, &type);
967 if(udr_errno) return udr_errno;
969 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
970 udr_UDIBreakId(udrs, break_id);
971 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
975 /******************************************************** UDI_QUERY_BREAKPOINT
977 UDIError UDIQueryBreakpoint (break_id, addr, passcount, type, current_count)
978 UDIBreakId break_id; /* in -- assigned break id */
979 UDIResource *addr; /* out - where breakpoint was set */
980 UDIInt32 *passcount; /* out - trigger passcount for breakpoint */
981 UDIBreakType *type; /* out - breakpoint type */
982 UDIInt32 *current_count; /* out - current count for breakpoint */
984 UDIInt32 service_id = UDIQueryBreakpoint_c;
987 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
988 udr_UDIInt32(udrs, &service_id);
989 udr_UDIBreakId(udrs, &break_id);
991 if(udr_errno) return udr_errno;
993 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
994 udr_UDIResource(udrs, addr);
995 udr_UDIInt32(udrs, passcount);
996 udr_UDIBreakType(udrs, type);
997 udr_UDIInt32(udrs, current_count);
998 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
1002 /******************************************************** UDI_CLEAR_BREAKPOINT
1003 * UDIClearBreakpoint() is used to clear a breakpoint.
1005 UDIError UDIClearBreakpoint (break_id)
1006 UDIBreakId break_id; /* in -- assigned break id */
1008 UDIInt32 service_id = UDIClearBreakpoint_c;
1011 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
1012 udr_UDIInt32(udrs, &service_id);
1013 udr_UDIBreakId(udrs, &break_id);
1015 if(udr_errno) return udr_errno;
1017 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
1018 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
1022 /************************************************************** UDI_GET_STDOUT
1023 * UDIGetStdout() is called when a call to
1024 * UDIWait() indicates there is STD output data ready.
1026 UDIError UDIGetStdout(buf, bufsize, count_done)
1027 UDIHostMemPtr buf; /* out -- buffer to be filled */
1028 UDISizeT bufsize; /* in -- buffer size in bytes */
1029 UDISizeT *count_done; /* out -- number of bytes written to buf */
1031 UDIInt32 service_id = UDIGetStdout_c;
1034 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
1035 udr_UDIInt32(udrs, &service_id);
1036 udr_UDISizeT(udrs, &bufsize);
1038 if(udr_errno) return udr_errno;
1040 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
1041 udr_UDISizeT(udrs, count_done);
1042 udr_bytes(udrs, buf, *count_done);
1043 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
1047 /************************************************************** UDI_GET_STDERR
1048 * UDIGetStderr() is called when a call to
1049 * UDIWait() indicates there is STDERR output data ready
1051 UDIError UDIGetStderr(buf, bufsize, count_done)
1052 UDIHostMemPtr buf; /* out -- buffer to be filled */
1053 UDISizeT bufsize; /* in -- buffer size in bytes */
1054 UDISizeT *count_done; /* out -- number of bytes written to buf */
1056 UDIInt32 service_id = UDIGetStderr_c;
1059 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
1060 udr_UDIInt32(udrs, &service_id);
1061 udr_UDISizeT(udrs, &bufsize);
1063 if(udr_errno) return udr_errno;
1065 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
1066 udr_UDISizeT(udrs, count_done);
1067 udr_bytes(udrs, buf, *count_done);
1068 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
1072 /*************************************************************** UDI_PUT_STDIN
1073 * UDIPutStdin() is called whenever the DFE wants to
1074 * deliver an input character to the TIP.
1076 UDIError UDIPutStdin (buf, count, count_done)
1077 UDIHostMemPtr buf; /* in -- buffer to be filled */
1078 UDISizeT count; /* in -- buffer size in bytes */
1079 UDISizeT *count_done; /* out - number of bytes written to buf */
1081 UDIInt32 service_id = UDIPutStdin_c;
1084 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
1085 udr_UDIInt32(udrs, &service_id);
1086 udr_UDISizeT(udrs, &count);
1087 udr_bytes(udrs, buf, count);
1089 if(udr_errno) return udr_errno;
1091 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
1092 udr_UDISizeT(udrs, count_done);
1093 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
1097 /************************************************************** UDI_STDIN_MODE
1098 * UDIStdinMode() is used to change the mode that chazcters
1099 * are fetched from the user.
1101 UDIError UDIStdinMode(mode)
1102 UDIMode *mode; /* out - */
1104 UDIInt32 service_id = UDIStdinMode_c;
1107 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
1108 udr_UDIInt32(udrs, &service_id);
1110 if(udr_errno) return udr_errno;
1112 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
1113 udr_UDIMode(udrs, mode);
1114 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
1118 /*************************************************************** UDI_PUT_TRANS
1119 * UDIPutTrans() is used to feed input to the passthru mode.
1121 UDIError UDIPutTrans (buf, count, count_done)
1122 UDIHostMemPtr buf; /* in -- buffer address containing input data */
1123 UDISizeT count; /* in -- number of bytes in buf */
1124 UDISizeT *count_done; /* out-- number of bytes transfered */
1126 UDIInt32 service_id = UDIPutTrans_c;
1129 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
1130 udr_UDIInt32(udrs, &service_id);
1131 udr_UDISizeT(udrs, &count);
1132 udr_bytes(udrs, buf, count);
1134 if(udr_errno) return udr_errno;
1136 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
1137 udr_UDISizeT(udrs, count_done);
1138 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
1142 /*************************************************************** UDI_GET_TRANS
1143 * UDIGetTrans() is used to get output lines from the
1146 UDIError UDIGetTrans (buf, bufsize, count_done)
1147 UDIHostMemPtr buf; /* out -- buffer to be filled */
1148 UDISizeT bufsize; /* in -- size of buf */
1149 UDISizeT *count_done; /* out -- number of bytes in buf */
1151 UDIInt32 service_id = UDIGetTrans_c;
1154 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
1155 udr_UDIInt32(udrs, &service_id);
1156 udr_UDISizeT(udrs, &bufsize);
1158 if(udr_errno) return udr_errno;
1160 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
1161 udr_UDISizeT(udrs, count_done);
1162 udr_bytes(udrs, buf, *count_done);
1163 udr_UDIError(udrs, &dfe_errno); /* get any TIP error */
1167 /************************************************************** UDI_Trans_Mode
1168 * UDITransMode() is used to change the mode that the
1169 * transparent routines operate in.
1171 UDIError UDITransMode(mode)
1172 UDIMode *mode; /* out -- selected mode */
1174 UDIInt32 service_id = UDITransMode_c;
1177 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
1178 udr_UDIInt32(udrs, &service_id);
1179 udr_UDIMode(udrs, mode);
1181 if(udr_errno) return udr_errno;
1183 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
1184 udr_UDIError(udrs, &dfe_errno);
1188 /******************************************************************** UDI_TEST
1190 UDIError UDITest( cnt, str_p, array)
1192 UDIHostMemPtr str_p;
1195 UDIInt32 service_id = UDITest_c;
1196 UDIInt16 scnt = cnt;
1201 udrs->udr_op = UDR_ENCODE; /* send all "in" parameters */
1202 udr_UDIInt32(udrs, &service_id);
1204 printf("send cnt=%d scnt=%d\n", cnt, scnt);
1205 udr_UDISizeT(udrs, &cnt);
1206 udr_UDIInt16(udrs, &scnt);
1207 printf(" array[0]=0x%x array[1]=0x%x array[2]=0x%x array[3]=0x%x\n",
1208 array[0], array[1], array[2], array[3]);
1209 udr_bytes(udrs, (char*)array, 4*sizeof(UDIInt32));
1210 printf(" string=%s\n", str_p);
1211 udr_string(udrs, str_p);
1214 { fprintf(stderr, " DFE-ipc Send ERROR\n");
1218 udrs->udr_op = UDR_DECODE; /* receive all "out" parameters */
1220 udr_UDISizeT(udrs, &r_cnt);
1221 udr_UDIInt16(udrs, &scnt);
1222 printf(" rcnt=%d scnt=%d\n", r_cnt, scnt);
1223 udr_bytes(udrs, (char*)array, 4*sizeof(UDIInt32));
1225 printf(" array[0]=0x%x array[1]=0x%x array[2]=0x%x array[3]=0x%x\n",
1226 array[0], array[1], array[2], array[3]);
1227 udr_string(udrs, str_p);
1228 printf(" string=%s\n", str_p);
1230 udr_UDIError(udrs, &dfe_errno);
1236 UDIUInt32 UDIGetDFEIPCId()
1238 return ((company_c << 16) + (product_c << 12) + version_c);