1 /* main.c -- top level of ARMulator: ARM6 Instruction Emulator.
2 Copyright (C) 1994 Advanced RISC Machines Ltd.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /**********************************************************************/
19 /* Forks the ARMulator and hangs on a socket passing on RDP messages */
20 /* down a pipe to the ARMulator which translates them into RDI calls. */
21 /**********************************************************************/
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <netinet/in.h>
36 #define MAXHOSTNAMELENGTH 64
38 /* Read and write routines down sockets and pipes */
40 void MYread_chars (int sock
, void *p
, int n
);
41 unsigned char MYread_char (int sock
);
42 ARMword
MYread_word (int sock
);
43 void MYread_FPword (int sock
, char *putinhere
);
45 void MYwrite_word (int sock
, ARMword i
);
46 void MYwrite_string (int sock
, char *s
);
47 void MYwrite_FPword (int sock
, char *fromhere
);
48 void MYwrite_char (int sock
, unsigned char c
);
50 void passon (int source
, int dest
, int n
);
53 /* Mother and child processes */
57 /* The child process id. */
60 /* The socket to the debugger */
63 /* The pipes between the two processes */
67 /* A pipe for handling SWI return values that goes straight from the */
68 /* parent to the ARMulator host interface, bypassing the childs RDP */
69 /* to RDI interpreter */
72 /* The maximum number of file descriptors */
75 /* The socket handle */
78 /* The machine name */
79 char localhost
[MAXHOSTNAMELENGTH
+ 1];
81 /* The socket number */
82 unsigned int socketnumber
;
84 /**************************************************************/
85 /* Takes one argument: the socket number. */
86 /* Opens a socket to the debugger, and once opened spawns the */
87 /* ARMulator and sets up a couple of pipes. */
88 /**************************************************************/
90 main (int argc
, char *argv
[])
93 struct sockaddr_in devil
, isa
;
99 fprintf (stderr
, "No socket number\n");
103 sscanf (argv
[1], "%d", &socketnumber
);
104 if (!socketnumber
|| socketnumber
> 0xffff)
106 fprintf (stderr
, "Invalid socket number: %d\n", socketnumber
);
110 gethostname (localhost
, MAXHOSTNAMELENGTH
);
111 hp
= gethostbyname (localhost
);
114 fprintf (stderr
, "Cannot get local host info\n");
119 sockethandle
= socket (hp
->h_addrtype
, SOCK_STREAM
, 0);
120 if (sockethandle
< 0)
126 devil
.sin_family
= hp
->h_addrtype
;
127 devil
.sin_port
= htons (socketnumber
);
128 devil
.sin_addr
.s_addr
= 0;
129 for (i
= 0; i
< sizeof (devil
.sin_zero
); i
++)
130 devil
.sin_zero
[i
] = '\000';
131 memcpy (&devil
.sin_addr
, hp
->h_addr_list
[0], hp
->h_length
);
133 if (bind (sockethandle
, &devil
, sizeof (devil
)) < 0)
139 /* May only accept one debugger at once */
141 if (listen (sockethandle
, 0))
147 fprintf (stderr
, "Waiting for connection from debugger...");
149 debugsock
= accept (sockethandle
, &isa
, &i
);
156 fprintf (stderr
, " done.\nConnection Established.\n");
158 nfds
= getdtablesize ();
171 if (pipe (DebuggerARMul
))
178 fprintf (stderr
, "Created pipes ok\n");
184 fprintf (stderr
, "fork() ok\n");
This page took 0.037767 seconds and 4 git commands to generate.