]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/m32c/main.c
1 /* main.c --- main function for stand-alone M32C simulator.
3 Copyright (C) 2005-2021 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/>. */
21 /* This must come before any other includes. */
31 #include <sys/types.h>
33 #ifdef HAVE_SYS_SOCKET_H
34 #ifdef HAVE_NETINET_IN_H
35 #ifdef HAVE_NETINET_TCP_H
36 #define HAVE_networking
41 #ifdef HAVE_networking
42 #include <sys/socket.h>
43 #include <netinet/in.h>
44 #include <netinet/tcp.h>
60 #ifdef HAVE_networking
61 extern int m32c_console_ofd
;
62 extern int m32c_console_ifd
;
65 int m32c_disassemble
= 0;
66 static unsigned int cycles
= 0;
75 printf ("insns: %14s\n", comma (cycles
));
80 #ifdef HAVE_networking
82 setup_tcp_console (char *portname
)
84 int port
= atoi (portname
);
85 struct sockaddr_in address
;
92 printf ("invalid port number %d\n", port
);
95 printf ("waiting for tcp console on port %d\n", port
);
97 memset (&address
, 0, sizeof (address
));
98 address
.sin_family
= AF_INET
;
99 address
.sin_port
= htons (port
);
101 isocket
= socket (AF_INET
, SOCK_STREAM
, 0);
108 if (bind (isocket
, (struct sockaddr
*) &address
, sizeof (address
)))
115 printf ("waiting for connection...\n");
116 as
= sizeof (address
);
117 m32c_console_ifd
= accept (isocket
, (struct sockaddr
*) &address
, &as
);
118 if (m32c_console_ifd
== -1)
123 a
= (unsigned char *) (&address
.sin_addr
.s_addr
);
124 printf ("connection from %d.%d.%d.%d\n", a
[0], a
[1], a
[2], a
[3]);
125 m32c_console_ofd
= m32c_console_ifd
;
130 main (int argc
, char **argv
)
135 #ifdef HAVE_networking
136 char *console_port_s
= 0;
143 while ((o
= getopt (argc
, argv
, "tc:vdm:C")) != -1)
150 #ifdef HAVE_networking
151 console_port_s
= optarg
;
153 fprintf (stderr
, "Nework console not available in this build.\n");
157 #ifdef HAVE_TERMIOS_H
158 m32c_use_raw_console
= 1;
160 fprintf (stderr
, "Raw console not available in this build.\n");
170 if (strcmp (optarg
, "r8c") == 0 || strcmp (optarg
, "m16c") == 0)
171 default_machine
= bfd_mach_m16c
;
172 else if (strcmp (optarg
, "m32cm") == 0
173 || strcmp (optarg
, "m32c") == 0)
174 default_machine
= bfd_mach_m32c
;
177 fprintf (stderr
, "Invalid machine: %s\n", optarg
);
183 "usage: run [-v] [-C] [-c port] [-t] [-d] [-m r8c|m16c|m32cm|m32c]"
188 prog
= bfd_openr (argv
[optind
], 0);
191 fprintf (stderr
, "Can't read %s\n", argv
[optind
]);
195 if (!bfd_check_format (prog
, bfd_object
))
197 fprintf (stderr
, "%s not a m32c program\n", argv
[optind
]);
206 #ifdef HAVE_networking
208 setup_tcp_console (console_port_s
);
211 sim_disasm_init (prog
);
220 if (m32c_disassemble
)
223 enable_counting
= verbose
;
225 rc
= decode_opcode ();
228 if (M32C_HIT_BREAK (rc
))
230 else if (M32C_EXITED (rc
))
231 done (M32C_EXIT_STATUS (rc
));
233 assert (M32C_STEPPED (rc
));
235 trace_register_changes ();