From 3877a1459be9bdeb20ae891b3f68220b837a81cb Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Fri, 6 Jun 2008 19:18:15 +0000 Subject: * Makefile.in: Add Timer A support. * cpu.h (m32c_opcode_pc): New. (in_gdb): New. * gdb-if.c (sim_open): Add Timer A support. Support unbuffered console. * int.c (trigger_interrupt): Manage the U flag properly. (trigger_based_interrupt): Likewise. (trigger_fixed_interrupt): New. (trigger_peripheral_interrupt): New. * int.h (trigger_peripheral_interrupt): New. * m32c.opc: Use m32c_opcode_pc throughout, as needed. (decode_m32c): Detect jump-to-zero with traceback. (BRK): Try to do the right thing, keeping track of whether we're in gdb or not, and if the user has provided a handler or not. (GBRK): Alternate break opcode for gdb, in case the user's app needs to use BRK for itself. (BRK2): Implement. * main.c: Add Timer A support. Support TCP-based console. (setup_tcp_console): New. (main): Add Timer A support. Support TCP-based console. * mem.c: Add Timer A support. Support TCP-based console. (mem_ptr): Enhance NULL pointer detection. (stdin_ready): New. (m32c_sim_restore_console): New. (mem_get_byte): Check for console input ready. (update_timer_a): New. * r8c.opc (SSTR): Use r0l, not r0h. (REIT): Fix return frame logic. * reg.c (print_flags): New. (trace_register_changes): Use it. (m32c_dump_all_registers): New. * timer_a.h: New. * load.c: Fix indentation. * trace.c: Fix indentation. * trace.h: Fix indentation. --- sim/m32c/main.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 8 deletions(-) (limited to 'sim/m32c/main.c') diff --git a/sim/m32c/main.c b/sim/m32c/main.c index 7b54f4b..7187210 100644 --- a/sim/m32c/main.c +++ b/sim/m32c/main.c @@ -27,6 +27,12 @@ along with this program. If not, see . */ #include #include +#include +#include +#include +#include + + #include "bfd.h" #include "cpu.h" @@ -34,8 +40,15 @@ along with this program. If not, see . */ #include "misc.h" #include "load.h" #include "trace.h" +#ifdef TIMER_A +#include "int.h" +#include "timer_a.h" +#endif -static int disassemble = 0; +extern int m32c_console_ofd; +extern int m32c_console_ifd; + +int m32c_disassemble = 0; static unsigned int cycles = 0; static void @@ -50,24 +63,79 @@ done (int exit_code) exit (exit_code); } +static void +setup_tcp_console (char *portname) +{ + int port = atoi (portname); + struct sockaddr_in address; + int isocket; + socklen_t as; + unsigned char *a; + + if (port < 1024) + { + printf ("invalid port number %d\n", port); + exit (1); + } + printf ("waiting for tcp console on port %d\n", port); + + memset (&address, 0, sizeof (address)); + address.sin_family = AF_INET; + address.sin_port = htons (port); + + isocket = socket (AF_INET, SOCK_STREAM, 0); + if (isocket < 0) + { + perror ("socket"); + exit (1); + } + + if (bind (isocket, (struct sockaddr *) &address, sizeof (address))) + { + perror ("bind"); + exit (1); + } + listen (isocket, 2); + + printf ("waiting for connection...\n"); + as = sizeof (address); + m32c_console_ifd = accept (isocket, (struct sockaddr *) &address, &as); + if (m32c_console_ifd == -1) + { + perror ("accept"); + exit (1); + } + a = (unsigned char *) (&address.sin_addr.s_addr); + printf ("connection from %d.%d.%d.%d\n", a[0], a[1], a[2], a[3]); + m32c_console_ofd = m32c_console_ifd; +} + int main (int argc, char **argv) { int o; int save_trace; bfd *prog; + char *console_port_s = 0; + + setbuf (stdout, 0); + + in_gdb = 0; - while ((o = getopt (argc, argv, "tvdm:")) != -1) + while ((o = getopt (argc, argv, "tc:vdm:")) != -1) switch (o) { case 't': trace++; break; + case 'c': + console_port_s = optarg; + break; case 'v': verbose++; break; case 'd': - disassemble++; + m32c_disassemble++; break; case 'm': if (strcmp (optarg, "r8c") == 0 || strcmp (optarg, "m16c") == 0) @@ -83,8 +151,8 @@ main (int argc, char **argv) break; case '?': fprintf (stderr, - "usage: run [-v] [-t] [-d] [-m r8c|m16c|m32cm|m32c]" - " program\n"); + "usage: run [-v] [-t] [-d] [-m r8c|m16c|m32cm|m32c]" + " program\n"); exit (1); } @@ -106,8 +174,10 @@ main (int argc, char **argv) m32c_load (prog); trace = save_trace; - if (disassemble) - sim_disasm_init (prog); + if (console_port_s) + setup_tcp_console (console_port_s); + + sim_disasm_init (prog); while (1) { @@ -116,7 +186,7 @@ main (int argc, char **argv) if (trace) printf ("\n"); - if (disassemble) + if (m32c_disassemble) sim_disasm_one (); enable_counting = verbose; @@ -132,5 +202,9 @@ main (int argc, char **argv) assert (M32C_STEPPED (rc)); trace_register_changes (); + +#ifdef TIMER_A + update_timer_a (); +#endif } } -- cgit v1.1