1 /* main.c --- main function for stand-alone M32C simulator.
3 Copyright (C) 2005-2017 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc.
6 This file is part of the GNU simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
30 #include <sys/types.h>
32 #ifdef HAVE_SYS_SOCKET_H
33 #ifdef HAVE_NETINET_IN_H
34 #ifdef HAVE_NETINET_TCP_H
35 #define HAVE_networking
40 #ifdef HAVE_networking
41 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <netinet/tcp.h>
59 #ifdef HAVE_networking
60 extern int m32c_console_ofd
;
61 extern int m32c_console_ifd
;
64 int m32c_disassemble
= 0;
65 static unsigned int cycles
= 0;
74 printf ("insns: %14s\n", comma (cycles
));
79 #ifdef HAVE_networking
81 setup_tcp_console (char *portname
)
83 int port
= atoi (portname
);
84 struct sockaddr_in address
;
91 printf ("invalid port number %d\n", port
);
94 printf ("waiting for tcp console on port %d\n", port
);
96 memset (&address
, 0, sizeof (address
));
97 address
.sin_family
= AF_INET
;
98 address
.sin_port
= htons (port
);
100 isocket
= socket (AF_INET
, SOCK_STREAM
, 0);
107 if (bind (isocket
, (struct sockaddr
*) &address
, sizeof (address
)))
114 printf ("waiting for connection...\n");
115 as
= sizeof (address
);
116 m32c_console_ifd
= accept (isocket
, (struct sockaddr
*) &address
, &as
);
117 if (m32c_console_ifd
== -1)
122 a
= (unsigned char *) (&address
.sin_addr
.s_addr
);
123 printf ("connection from %d.%d.%d.%d\n", a
[0], a
[1], a
[2], a
[3]);
124 m32c_console_ofd
= m32c_console_ifd
;
129 main (int argc
, char **argv
)
134 #ifdef HAVE_networking
135 char *console_port_s
= 0;
142 while ((o
= getopt (argc
, argv
, "tc:vdm:C")) != -1)
149 #ifdef HAVE_networking
150 console_port_s
= optarg
;
152 fprintf (stderr
, "Nework console not available in this build.\n");
156 #ifdef HAVE_TERMIOS_H
157 m32c_use_raw_console
= 1;
159 fprintf (stderr
, "Raw console not available in this build.\n");
169 if (strcmp (optarg
, "r8c") == 0 || strcmp (optarg
, "m16c") == 0)
170 default_machine
= bfd_mach_m16c
;
171 else if (strcmp (optarg
, "m32cm") == 0
172 || strcmp (optarg
, "m32c") == 0)
173 default_machine
= bfd_mach_m32c
;
176 fprintf (stderr
, "Invalid machine: %s\n", optarg
);
182 "usage: run [-v] [-C] [-c port] [-t] [-d] [-m r8c|m16c|m32cm|m32c]"
187 prog
= bfd_openr (argv
[optind
], 0);
190 fprintf (stderr
, "Can't read %s\n", argv
[optind
]);
194 if (!bfd_check_format (prog
, bfd_object
))
196 fprintf (stderr
, "%s not a m32c program\n", argv
[optind
]);
205 #ifdef HAVE_networking
207 setup_tcp_console (console_port_s
);
210 sim_disasm_init (prog
);
219 if (m32c_disassemble
)
222 enable_counting
= verbose
;
224 rc
= decode_opcode ();
227 if (M32C_HIT_BREAK (rc
))
229 else if (M32C_EXITED (rc
))
230 done (M32C_EXIT_STATUS (rc
));
232 assert (M32C_STEPPED (rc
));
234 trace_register_changes ();
This page took 0.042074 seconds and 4 git commands to generate.