1 /* main.c --- main function for stand-alone M32C simulator.
3 Copyright (C) 2005, 2007, 2008, 2009 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>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <netinet/tcp.h>
48 extern int m32c_console_ofd
;
49 extern int m32c_console_ifd
;
51 int m32c_disassemble
= 0;
52 static unsigned int cycles
= 0;
61 printf ("insns: %14s\n", comma (cycles
));
67 setup_tcp_console (char *portname
)
69 int port
= atoi (portname
);
70 struct sockaddr_in address
;
77 printf ("invalid port number %d\n", port
);
80 printf ("waiting for tcp console on port %d\n", port
);
82 memset (&address
, 0, sizeof (address
));
83 address
.sin_family
= AF_INET
;
84 address
.sin_port
= htons (port
);
86 isocket
= socket (AF_INET
, SOCK_STREAM
, 0);
93 if (bind (isocket
, (struct sockaddr
*) &address
, sizeof (address
)))
100 printf ("waiting for connection...\n");
101 as
= sizeof (address
);
102 m32c_console_ifd
= accept (isocket
, (struct sockaddr
*) &address
, &as
);
103 if (m32c_console_ifd
== -1)
108 a
= (unsigned char *) (&address
.sin_addr
.s_addr
);
109 printf ("connection from %d.%d.%d.%d\n", a
[0], a
[1], a
[2], a
[3]);
110 m32c_console_ofd
= m32c_console_ifd
;
114 main (int argc
, char **argv
)
119 char *console_port_s
= 0;
125 while ((o
= getopt (argc
, argv
, "tc:vdm:C")) != -1)
132 console_port_s
= optarg
;
135 m32c_use_raw_console
= 1;
144 if (strcmp (optarg
, "r8c") == 0 || strcmp (optarg
, "m16c") == 0)
145 default_machine
= bfd_mach_m16c
;
146 else if (strcmp (optarg
, "m32cm") == 0
147 || strcmp (optarg
, "m32c") == 0)
148 default_machine
= bfd_mach_m32c
;
151 fprintf (stderr
, "Invalid machine: %s\n", optarg
);
157 "usage: run [-v] [-C] [-c port] [-t] [-d] [-m r8c|m16c|m32cm|m32c]"
162 prog
= bfd_openr (argv
[optind
], 0);
165 fprintf (stderr
, "Can't read %s\n", argv
[optind
]);
169 if (!bfd_check_format (prog
, bfd_object
))
171 fprintf (stderr
, "%s not a m32c program\n", argv
[optind
]);
181 setup_tcp_console (console_port_s
);
183 sim_disasm_init (prog
);
192 if (m32c_disassemble
)
195 enable_counting
= verbose
;
197 rc
= decode_opcode ();
200 if (M32C_HIT_BREAK (rc
))
202 else if (M32C_EXITED (rc
))
203 done (M32C_EXIT_STATUS (rc
));
205 assert (M32C_STEPPED (rc
));
207 trace_register_changes ();
This page took 0.034023 seconds and 5 git commands to generate.