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 3 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, see <http://www.gnu.org/licenses/>. */
17 /**********************************************************************/
18 /* Forks the ARMulator and hangs on a socket passing on RDP messages */
19 /* down a pipe to the ARMulator which translates them into RDI calls. */
20 /**********************************************************************/
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <netinet/in.h>
35 #define MAXHOSTNAMELENGTH 64
37 /* Read and write routines down sockets and pipes */
39 void MYread_chars (int sock
, void *p
, int n
);
40 unsigned char MYread_char (int sock
);
41 ARMword
MYread_word (int sock
);
42 void MYread_FPword (int sock
, char *putinhere
);
44 void MYwrite_word (int sock
, ARMword i
);
45 void MYwrite_string (int sock
, char *s
);
46 void MYwrite_FPword (int sock
, char *fromhere
);
47 void MYwrite_char (int sock
, unsigned char c
);
49 void passon (int source
, int dest
, int n
);
52 /* Mother and child processes */
56 /* The child process id. */
59 /* The socket to the debugger */
62 /* The pipes between the two processes */
66 /* A pipe for handling SWI return values that goes straight from the */
67 /* parent to the ARMulator host interface, bypassing the childs RDP */
68 /* to RDI interpreter */
71 /* The maximum number of file descriptors */
74 /* The socket handle */
77 /* The machine name */
78 char localhost
[MAXHOSTNAMELENGTH
+ 1];
80 /* The socket number */
81 unsigned int socketnumber
;
83 /**************************************************************/
84 /* Takes one argument: the socket number. */
85 /* Opens a socket to the debugger, and once opened spawns the */
86 /* ARMulator and sets up a couple of pipes. */
87 /**************************************************************/
89 main (int argc
, char *argv
[])
92 struct sockaddr_in devil
, isa
;
98 fprintf (stderr
, "No socket number\n");
102 sscanf (argv
[1], "%d", &socketnumber
);
103 if (!socketnumber
|| socketnumber
> 0xffff)
105 fprintf (stderr
, "Invalid socket number: %d\n", socketnumber
);
109 gethostname (localhost
, MAXHOSTNAMELENGTH
);
110 hp
= gethostbyname (localhost
);
113 fprintf (stderr
, "Cannot get local host info\n");
118 sockethandle
= socket (hp
->h_addrtype
, SOCK_STREAM
, 0);
119 if (sockethandle
== -1)
125 devil
.sin_family
= hp
->h_addrtype
;
126 devil
.sin_port
= htons (socketnumber
);
127 devil
.sin_addr
.s_addr
= 0;
128 for (i
= 0; i
< sizeof (devil
.sin_zero
); i
++)
129 devil
.sin_zero
[i
] = '\000';
130 memcpy (&devil
.sin_addr
, hp
->h_addr_list
[0], hp
->h_length
);
132 if (bind (sockethandle
, &devil
, sizeof (devil
)) < 0)
138 /* May only accept one debugger at once */
140 if (listen (sockethandle
, 0))
146 fprintf (stderr
, "Waiting for connection from debugger...");
148 debugsock
= accept (sockethandle
, &isa
, &i
);
155 fprintf (stderr
, " done.\nConnection Established.\n");
157 nfds
= getdtablesize ();
170 if (pipe (DebuggerARMul
))
177 fprintf (stderr
, "Created pipes ok\n");
183 fprintf (stderr
, "fork() ok\n");
This page took 0.065029 seconds and 5 git commands to generate.