1 /* main.c --- main function for stand-alone M32C simulator.
3 Copyright (C) 2005-2024 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>
34 #ifdef HAVE_SYS_SOCKET_H
35 #ifdef HAVE_NETINET_IN_H
36 #ifdef HAVE_NETINET_TCP_H
37 #define HAVE_networking
42 #ifdef HAVE_networking
43 #include <sys/socket.h>
44 #include <netinet/in.h>
45 #include <netinet/tcp.h>
61 #ifdef HAVE_networking
62 extern int m32c_console_ofd
;
63 extern int m32c_console_ifd
;
66 int m32c_disassemble
= 0;
67 static unsigned int cycles
= 0;
76 printf ("insns: %14s\n", comma (cycles
));
81 #ifdef HAVE_networking
83 setup_tcp_console (char *portname
)
85 int port
= atoi (portname
);
86 struct sockaddr_in address
;
93 printf ("invalid port number %d\n", port
);
96 printf ("waiting for tcp console on port %d\n", port
);
98 memset (&address
, 0, sizeof (address
));
99 address
.sin_family
= AF_INET
;
100 address
.sin_port
= htons (port
);
102 isocket
= socket (AF_INET
, SOCK_STREAM
, 0);
109 if (bind (isocket
, (struct sockaddr
*) &address
, sizeof (address
)))
116 printf ("waiting for connection...\n");
117 as
= sizeof (address
);
118 m32c_console_ifd
= accept (isocket
, (struct sockaddr
*) &address
, &as
);
119 if (m32c_console_ifd
== -1)
124 a
= (unsigned char *) (&address
.sin_addr
.s_addr
);
125 printf ("connection from %d.%d.%d.%d\n", a
[0], a
[1], a
[2], a
[3]);
126 m32c_console_ofd
= m32c_console_ifd
;
131 main (int argc
, char **argv
)
136 #ifdef HAVE_networking
137 char *console_port_s
= 0;
139 static const struct option longopts
[] = { { 0 } };
145 while ((o
= getopt_long (argc
, argv
, "tc:vdm:C", longopts
, NULL
))
153 #ifdef HAVE_networking
154 console_port_s
= optarg
;
156 fprintf (stderr
, "Nework console not available in this build.\n");
160 #ifdef HAVE_TERMIOS_H
161 m32c_use_raw_console
= 1;
163 fprintf (stderr
, "Raw console not available in this build.\n");
173 if (strcmp (optarg
, "r8c") == 0 || strcmp (optarg
, "m16c") == 0)
174 default_machine
= bfd_mach_m16c
;
175 else if (strcmp (optarg
, "m32cm") == 0
176 || strcmp (optarg
, "m32c") == 0)
177 default_machine
= bfd_mach_m32c
;
180 fprintf (stderr
, "Invalid machine: %s\n", optarg
);
186 "usage: run [-v] [-C] [-c port] [-t] [-d] [-m r8c|m16c|m32cm|m32c]"
191 prog
= bfd_openr (argv
[optind
], 0);
194 fprintf (stderr
, "Can't read %s\n", argv
[optind
]);
198 if (!bfd_check_format (prog
, bfd_object
))
200 fprintf (stderr
, "%s not a m32c program\n", argv
[optind
]);
209 #ifdef HAVE_networking
211 setup_tcp_console (console_port_s
);
214 sim_disasm_init (prog
);
223 if (m32c_disassemble
)
226 enable_counting
= verbose
;
228 rc
= decode_opcode ();
231 if (M32C_HIT_BREAK (rc
))
233 else if (M32C_EXITED (rc
))
234 done (M32C_EXIT_STATUS (rc
));
236 assert (M32C_STEPPED (rc
));
238 trace_register_changes ();