From 90f4aedaef8a2310573eef905f95c671f84e5cde Mon Sep 17 00:00:00 2001 From: borutr Date: Wed, 30 Aug 2006 21:12:39 +0000 Subject: [PATCH] * sim/ucsim/cmd.src/newcmdposix.cc, sim/ucsim/cmd.src/newcmdposixcl.h, sim/ucsim/cmd.src/newcmdwin32.cc, sim/ucsim/cmd.src/newcmdwin32cl.h, sim/ucsim/app.cc, sim/ucsim/appcl.h, sim/ucsim/configure, sim/ucsim/configure.in, sim/ucsim/ddconfig_in.h, sim/ucsim/error.cc, sim/ucsim/errorcl.h, sim/ucsim/option.cc, sim/ucsim/optioncl.h, sim/ucsim/utils.cc, sim/ucsim/utils.h, sim/ucsim/cmd.src/Makefile.in, sim/ucsim/avr.src/avr.cc, sim/ucsim/avr.src/avrcl.h, sim/ucsim/cmd.src/bp.cc, sim/ucsim/cmd.src/bpcl.h, sim/ucsim/cmd.src/cmdconf.cc, sim/ucsim/cmd.src/cmdgui.cc, sim/ucsim/cmd.src/cmdmem.cc, sim/ucsim/cmd.src/cmdset.cc, sim/ucsim/cmd.src/cmdsetcl.h, sim/ucsim/cmd.src/cmdstat.cc, sim/ucsim/cmd.src/cmduc.cc, sim/ucsim/cmd.src/cmduccl.h, sim/ucsim/cmd.src/cmdutil.cc, sim/ucsim/cmd.src/cmdutil.h, sim/ucsim/cmd.src/command.cc, sim/ucsim/cmd.src/commandcl.h, sim/ucsim/cmd.src/get.cc, sim/ucsim/cmd.src/getcl.h, sim/ucsim/cmd.src/info.cc, sim/ucsim/cmd.src/newcmd.cc, sim/ucsim/cmd.src/newcmdcl.h, sim/ucsim/cmd.src/set.cc, sim/ucsim/cmd.src/show.cc, sim/ucsim/cmd.src/timer.cc, sim/ucsim/hc08.src/hc08.cc, sim/ucsim/hc08.src/hc08cl.h, sim/ucsim/s51.src/Makefile.in, sim/ucsim/s51.src/interrupt.cc, sim/ucsim/s51.src/interruptcl.h, sim/ucsim/s51.src/pca.cc, sim/ucsim/s51.src/pcacl.h, sim/ucsim/s51.src/port.cc, sim/ucsim/s51.src/portcl.h, sim/ucsim/s51.src/serial.cc, sim/ucsim/s51.src/serialcl.h, sim/ucsim/s51.src/timer0.cc, sim/ucsim/s51.src/timer0cl.h, sim/ucsim/s51.src/timer1.cc, sim/ucsim/s51.src/timer1cl.h, sim/ucsim/s51.src/timer2.cc, sim/ucsim/s51.src/timer2cl.h, sim/ucsim/s51.src/uc390.cc, sim/ucsim/s51.src/uc390cl.h, sim/ucsim/s51.src/uc390hw.cc, sim/ucsim/s51.src/uc390hwcl.h, sim/ucsim/s51.src/uc51.cc, sim/ucsim/s51.src/uc51cl.h, sim/ucsim/s51.src/wdt.cc, sim/ucsim/s51.src/wdtcl.h, sim/ucsim/sim.src/hw.cc, sim/ucsim/sim.src/hwcl.h, sim/ucsim/sim.src/mem.cc, sim/ucsim/sim.src/memcl.h, sim/ucsim/sim.src/obsolete.cc, sim/ucsim/sim.src/obsolete.h, sim/ucsim/sim.src/sim.cc, sim/ucsim/sim.src/simcl.h, sim/ucsim/sim.src/stack.cc, sim/ucsim/sim.src/stackcl.h, sim/ucsim/sim.src/test_mem_speed.cc, sim/ucsim/sim.src/uc.cc, sim/ucsim/sim.src/uccl.h, sim/ucsim/xa.src/xa.cc, sim/ucsim/xa.src/xacl.h, sim/ucsim/z80.src/z80.cc, sim/ucsim/z80.src/z80cl.h: ucsim WIN32 native port git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4348 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 43 ++ sim/ucsim/app.cc | 552 +++++++++++---------- sim/ucsim/appcl.h | 4 +- sim/ucsim/avr.src/avr.cc | 534 ++++++++++----------- sim/ucsim/avr.src/avrcl.h | 2 +- sim/ucsim/cmd.src/Makefile.in | 13 +- sim/ucsim/cmd.src/bp.cc | 54 +-- sim/ucsim/cmd.src/bpcl.h | 14 +- sim/ucsim/cmd.src/cmdconf.cc | 16 +- sim/ucsim/cmd.src/cmdgui.cc | 12 +- sim/ucsim/cmd.src/cmdmem.cc | 32 +- sim/ucsim/cmd.src/cmdset.cc | 290 +++++------ sim/ucsim/cmd.src/cmdsetcl.h | 2 +- sim/ucsim/cmd.src/cmdstat.cc | 72 +-- sim/ucsim/cmd.src/cmduc.cc | 220 ++++----- sim/ucsim/cmd.src/cmduccl.h | 4 +- sim/ucsim/cmd.src/cmdutil.cc | 201 +++++++- sim/ucsim/cmd.src/cmdutil.h | 21 +- sim/ucsim/cmd.src/command.cc | 340 ++++++------- sim/ucsim/cmd.src/commandcl.h | 48 +- sim/ucsim/cmd.src/get.cc | 50 +- sim/ucsim/cmd.src/getcl.h | 20 +- sim/ucsim/cmd.src/info.cc | 104 ++-- sim/ucsim/cmd.src/newcmd.cc | 719 +++++----------------------- sim/ucsim/cmd.src/newcmdcl.h | 142 ++---- sim/ucsim/cmd.src/newcmdposix.cc | 465 ++++++++++++++++++ sim/ucsim/cmd.src/newcmdposixcl.h | 121 +++++ sim/ucsim/cmd.src/newcmdwin32.cc | 636 ++++++++++++++++++++++++ sim/ucsim/cmd.src/newcmdwin32cl.h | 150 ++++++ sim/ucsim/cmd.src/set.cc | 118 ++--- sim/ucsim/cmd.src/show.cc | 74 +-- sim/ucsim/cmd.src/timer.cc | 84 ++-- sim/ucsim/configure | 456 +++++------------- sim/ucsim/configure.in | 64 ++- sim/ucsim/ddconfig_in.h | 5 +- sim/ucsim/error.cc | 18 +- sim/ucsim/errorcl.h | 14 +- sim/ucsim/hc08.src/hc08.cc | 132 ++--- sim/ucsim/hc08.src/hc08cl.h | 2 +- sim/ucsim/option.cc | 120 ++--- sim/ucsim/optioncl.h | 28 +- sim/ucsim/s51.src/Makefile.in | 8 +- sim/ucsim/s51.src/interrupt.cc | 40 +- sim/ucsim/s51.src/interruptcl.h | 2 +- sim/ucsim/s51.src/pca.cc | 180 +++---- sim/ucsim/s51.src/pcacl.h | 2 +- sim/ucsim/s51.src/port.cc | 54 +-- sim/ucsim/s51.src/portcl.h | 4 +- sim/ucsim/s51.src/serial.cc | 279 ++++++----- sim/ucsim/s51.src/serialcl.h | 26 +- sim/ucsim/s51.src/timer0.cc | 128 ++--- sim/ucsim/s51.src/timer0cl.h | 2 +- sim/ucsim/s51.src/timer1.cc | 4 +- sim/ucsim/s51.src/timer1cl.h | 2 +- sim/ucsim/s51.src/timer2.cc | 178 +++---- sim/ucsim/s51.src/timer2cl.h | 20 +- sim/ucsim/s51.src/uc390.cc | 88 ++-- sim/ucsim/s51.src/uc390cl.h | 2 +- sim/ucsim/s51.src/uc390hw.cc | 76 +-- sim/ucsim/s51.src/uc390hwcl.h | 2 +- sim/ucsim/s51.src/uc51.cc | 513 ++++++++++---------- sim/ucsim/s51.src/uc51cl.h | 236 ++++----- sim/ucsim/s51.src/wdt.cc | 22 +- sim/ucsim/s51.src/wdtcl.h | 2 +- sim/ucsim/sim.src/hw.cc | 72 +-- sim/ucsim/sim.src/hwcl.h | 48 +- sim/ucsim/sim.src/mem.cc | 12 +- sim/ucsim/sim.src/memcl.h | 62 +-- sim/ucsim/sim.src/obsolete.cc | 192 ++++---- sim/ucsim/sim.src/obsolete.h | 28 +- sim/ucsim/sim.src/sim.cc | 132 ++--- sim/ucsim/sim.src/simcl.h | 4 +- sim/ucsim/sim.src/stack.cc | 44 +- sim/ucsim/sim.src/stackcl.h | 30 +- sim/ucsim/sim.src/test_mem_speed.cc | 30 +- sim/ucsim/sim.src/uc.cc | 12 +- sim/ucsim/sim.src/uccl.h | 78 +-- sim/ucsim/utils.cc | 93 ++-- sim/ucsim/utils.h | 11 +- sim/ucsim/xa.src/xa.cc | 150 +++--- sim/ucsim/xa.src/xacl.h | 2 +- sim/ucsim/z80.src/z80.cc | 98 ++-- sim/ucsim/z80.src/z80cl.h | 2 +- 83 files changed, 4946 insertions(+), 4020 deletions(-) create mode 100644 sim/ucsim/cmd.src/newcmdposix.cc create mode 100644 sim/ucsim/cmd.src/newcmdposixcl.h create mode 100644 sim/ucsim/cmd.src/newcmdwin32.cc create mode 100644 sim/ucsim/cmd.src/newcmdwin32cl.h diff --git a/ChangeLog b/ChangeLog index caefe81e..7b92897f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,46 @@ +2006-08-30 Borut Razem + + * sim/ucsim/cmd.src/newcmdposix.cc, sim/ucsim/cmd.src/newcmdposixcl.h, + sim/ucsim/cmd.src/newcmdwin32.cc, sim/ucsim/cmd.src/newcmdwin32cl.h, + sim/ucsim/app.cc, sim/ucsim/appcl.h, sim/ucsim/configure, + sim/ucsim/configure.in, sim/ucsim/ddconfig_in.h, sim/ucsim/error.cc, + sim/ucsim/errorcl.h, sim/ucsim/option.cc, sim/ucsim/optioncl.h, + sim/ucsim/utils.cc, sim/ucsim/utils.h, sim/ucsim/cmd.src/Makefile.in, + sim/ucsim/avr.src/avr.cc, sim/ucsim/avr.src/avrcl.h, + sim/ucsim/cmd.src/bp.cc, sim/ucsim/cmd.src/bpcl.h, + sim/ucsim/cmd.src/cmdconf.cc, sim/ucsim/cmd.src/cmdgui.cc, + sim/ucsim/cmd.src/cmdmem.cc, sim/ucsim/cmd.src/cmdset.cc, + sim/ucsim/cmd.src/cmdsetcl.h, sim/ucsim/cmd.src/cmdstat.cc, + sim/ucsim/cmd.src/cmduc.cc, sim/ucsim/cmd.src/cmduccl.h, + sim/ucsim/cmd.src/cmdutil.cc, sim/ucsim/cmd.src/cmdutil.h, + sim/ucsim/cmd.src/command.cc, sim/ucsim/cmd.src/commandcl.h, + sim/ucsim/cmd.src/get.cc, sim/ucsim/cmd.src/getcl.h, + sim/ucsim/cmd.src/info.cc, sim/ucsim/cmd.src/newcmd.cc, + sim/ucsim/cmd.src/newcmdcl.h, sim/ucsim/cmd.src/set.cc, + sim/ucsim/cmd.src/show.cc, sim/ucsim/cmd.src/timer.cc, + sim/ucsim/hc08.src/hc08.cc, sim/ucsim/hc08.src/hc08cl.h, + sim/ucsim/s51.src/Makefile.in, sim/ucsim/s51.src/interrupt.cc, + sim/ucsim/s51.src/interruptcl.h, sim/ucsim/s51.src/pca.cc, + sim/ucsim/s51.src/pcacl.h, sim/ucsim/s51.src/port.cc, + sim/ucsim/s51.src/portcl.h, sim/ucsim/s51.src/serial.cc, + sim/ucsim/s51.src/serialcl.h, sim/ucsim/s51.src/timer0.cc, + sim/ucsim/s51.src/timer0cl.h, sim/ucsim/s51.src/timer1.cc, + sim/ucsim/s51.src/timer1cl.h, sim/ucsim/s51.src/timer2.cc, + sim/ucsim/s51.src/timer2cl.h, sim/ucsim/s51.src/uc390.cc, + sim/ucsim/s51.src/uc390cl.h, sim/ucsim/s51.src/uc390hw.cc, + sim/ucsim/s51.src/uc390hwcl.h, sim/ucsim/s51.src/uc51.cc, + sim/ucsim/s51.src/uc51cl.h, sim/ucsim/s51.src/wdt.cc, + sim/ucsim/s51.src/wdtcl.h, sim/ucsim/sim.src/hw.cc, + sim/ucsim/sim.src/hwcl.h, sim/ucsim/sim.src/mem.cc, + sim/ucsim/sim.src/memcl.h, sim/ucsim/sim.src/obsolete.cc, + sim/ucsim/sim.src/obsolete.h, sim/ucsim/sim.src/sim.cc, + sim/ucsim/sim.src/simcl.h, sim/ucsim/sim.src/stack.cc, + sim/ucsim/sim.src/stackcl.h, sim/ucsim/sim.src/test_mem_speed.cc, + sim/ucsim/sim.src/uc.cc, sim/ucsim/sim.src/uccl.h, + sim/ucsim/xa.src/xa.cc, sim/ucsim/xa.src/xacl.h, + sim/ucsim/z80.src/z80.cc, sim/ucsim/z80.src/z80cl.h: + ucsim WIN32 native port + 2006-08-30 Jesus Calvino-Fraga * doc/sdccman.lyx: added note on dynamic memory heap initialization diff --git a/sim/ucsim/app.cc b/sim/ucsim/app.cc index 6e7dcdac..44daef00 100644 --- a/sim/ucsim/app.cc +++ b/sim/ucsim/app.cc @@ -2,7 +2,7 @@ * Simulator of microcontrollers (app.cc) * * Copyright (C) 2001,01 Drotos Daniel, Talker Bt. - * + * * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * */ @@ -59,6 +59,11 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "showcl.h" #include "getcl.h" #include "setcl.h" +#ifdef _WIN32 +#include "newcmdwin32cl.h" +#else +#include "newcmdposixcl.h" +#endif /* @@ -150,28 +155,28 @@ cl_app::run(void) int done= 0; while (!done && - going) + going) { if (sim) - { - if (sim->state & SIM_GO) - { - if (commander->input_avail()) - done= commander->proc_input(); - else - sim->step(); - } - else - { - commander->wait_input(); - done= commander->proc_input(); - } - } + { + if (sim->state & SIM_GO) + { + if (commander->input_avail()) + done= commander->proc_input(); + else + sim->step(); + } + else + { + commander->wait_input(); + done= commander->proc_input(); + } + } else - { - commander->wait_input(); - done= commander->proc_input(); - } + { + commander->wait_input(); + done= commander->proc_input(); + } } return(0); } @@ -191,12 +196,12 @@ print_help(char *name) { printf("%s: %s\n", name, VERSIONSTR); printf("Usage: %s [-hHVvP] [-p prompt] [-t CPU] [-X freq[k|M]]\n" - " [-c file] [-s file] [-S optionlist]" + " [-c file] [-s file] [-S optionlist]" #ifdef SOCKET_AVAIL - " [-Z portnum] [-k portnum]" + " [-Z portnum] [-k portnum]" #endif - "\n" - " [files...]\n", name); + "\n" + " [files...]\n", name); printf ( "Options:\n" @@ -250,236 +255,299 @@ cl_app::proc_arguments(int argc, char *argv[]) switch (c) { case 'c': - if (!options->set_value("console_on", this, optarg)) - fprintf(stderr, "Warning: No \"console_on\" option found " - "to set by -c\n"); - break; + if (!options->set_value("console_on", this, optarg)) + fprintf(stderr, "Warning: No \"console_on\" option found " + "to set by -c\n"); + break; case 'C': - if (!options->set_value("config_file", this, optarg)) - fprintf(stderr, "Warning: No \"config_file\" option found to set " - "parameter of -C as config file\n"); - break; + if (!options->set_value("config_file", this, optarg)) + fprintf(stderr, "Warning: No \"config_file\" option found to set " + "parameter of -C as config file\n"); + break; #ifdef SOCKET_AVAIL case 'Z': case 'r': - { - // By Sandeep - // Modified by DD - class cl_option *o; - options->new_option(o= new cl_number_option(this, "port_number", - "Listen on port (-Z)")); - o->init(); - o->hide(); - if (!options->set_value("port_number", this, strtol(optarg, NULL, 0))) - fprintf(stderr, "Warning: No \"port_number\" option found" - " to set parameter of -Z as pot number to listen on\n"); - break; - } + { + // By Sandeep + // Modified by DD + class cl_option *o; + options->new_option(o= new cl_number_option(this, "port_number", + "Listen on port (-Z)")); + o->init(); + o->hide(); + if (!options->set_value("port_number", this, strtol(optarg, NULL, 0))) + fprintf(stderr, "Warning: No \"port_number\" option found" + " to set parameter of -Z as pot number to listen on\n"); + break; + } #endif case 'p': { - if (!options->set_value("prompt", this, optarg)) - fprintf(stderr, "Warning: No \"prompt\" option found to set " - "parameter of -p as default prompt\n"); - break; + if (!options->set_value("prompt", this, optarg)) + fprintf(stderr, "Warning: No \"prompt\" option found to set " + "parameter of -p as default prompt\n"); + break; } case 'P': - if (!options->set_value("null_prompt", this, bool(DD_TRUE))) - fprintf(stderr, "Warning: No \"null_prompt\" option found\n"); - break; + if (!options->set_value("null_prompt", this, bool(DD_TRUE))) + fprintf(stderr, "Warning: No \"null_prompt\" option found\n"); + break; case 'X': - { - double XTAL; - for (cp= optarg; *cp; *cp= toupper(*cp), cp++); - XTAL= strtod(optarg, &cp); - if (*cp == 'K') - XTAL*= 1e3; - if (*cp == 'M') - XTAL*= 1e6; - if (XTAL == 0) - { - fprintf(stderr, "Xtal frequency must be greather than 0\n"); - exit(1); - } - if (!options->set_value("xtal", this, XTAL)) - fprintf(stderr, "Warning: No \"xtal\" option found to set " - "parameter of -X as XTAL frequency\n"); - break; - } + { + double XTAL; + for (cp= optarg; *cp; *cp= toupper(*cp), cp++); + XTAL= strtod(optarg, &cp); + if (*cp == 'K') + XTAL*= 1e3; + if (*cp == 'M') + XTAL*= 1e6; + if (XTAL == 0) + { + fprintf(stderr, "Xtal frequency must be greather than 0\n"); + exit(1); + } + if (!options->set_value("xtal", this, XTAL)) + fprintf(stderr, "Warning: No \"xtal\" option found to set " + "parameter of -X as XTAL frequency\n"); + break; + } case 'v': - printf("%s: %s\n", argv[0], VERSIONSTR); + printf("%s: %s\n", argv[0], VERSIONSTR); exit(0); break; case 'V': - if (!options->set_value("debug", this, (bool)DD_TRUE)) - fprintf(stderr, "Warning: No \"debug\" option found to set " - "by -V parameter\n"); - break; + if (!options->set_value("debug", this, (bool)DD_TRUE)) + fprintf(stderr, "Warning: No \"debug\" option found to set " + "by -V parameter\n"); + break; case 't': - { - if (cpu_type) - free(cpu_type); - cpu_type= case_string(case_upper, optarg); - if (!options->set_value("cpu_type", this, /*optarg*/cpu_type)) - fprintf(stderr, "Warning: No \"cpu_type\" option found to set " - "parameter of -t as type of controller\n"); - break; - } + { + if (cpu_type) + free(cpu_type); + cpu_type= case_string(case_upper, optarg); + if (!options->set_value("cpu_type", this, /*optarg*/cpu_type)) + fprintf(stderr, "Warning: No \"cpu_type\" option found to set " + "parameter of -t as type of controller\n"); + break; + } case 's': { - FILE *Ser_in, *Ser_out; - if (s_done) - { - fprintf(stderr, "-s option can not be used more than once.\n"); - break; - } - s_done= DD_TRUE; - if ((Ser_in= fopen(optarg, "r")) == NULL) - { - fprintf(stderr, - "Can't open `%s': %s\n", optarg, strerror(errno)); - return(4); - } - if (!options->set_value("serial_in_file", this, (void*)Ser_in)) - fprintf(stderr, "Warning: No \"serial_in_file\" option found to set " - "parameter of -s as serial input file\n"); - if ((Ser_out= fopen(optarg, "w")) == NULL) - { - fprintf(stderr, - "Can't open `%s': %s\n", optarg, strerror(errno)); - return(4); - } - if (!options->set_value("serial_out_file", this, Ser_out)) - fprintf(stderr, "Warning: No \"serial_out_file\" option found " - "to set parameter of -s as serial output file\n"); - break; +#ifdef _WIN32 + /* TODO: this code should be probably used for all platforms? */ + FILE *Ser; + if (s_done) + { + fprintf(stderr, "-s option can not be used more than once.\n"); + break; + } + s_done= DD_TRUE; + if ((Ser= fopen(optarg, "r+")) == NULL) + { + fprintf(stderr, + "Can't open `%s': %s\n", optarg, strerror(errno)); + return(4); + } + if (!options->set_value("serial_in_file", this, Ser)) + fprintf(stderr, "Warning: No \"serial_in_file\" option found to set " + "parameter of -s as serial input file\n"); + if (!options->set_value("serial_out_file", this, Ser)) + fprintf(stderr, "Warning: No \"serial_out_file\" option found " + "to set parameter of -s as serial output file\n"); +#else + FILE *Ser_in, *Ser_out; + if (s_done) + { + fprintf(stderr, "-s option can not be used more than once.\n"); + break; + } + s_done= DD_TRUE; + if ((Ser_in= fopen(optarg, "r")) == NULL) + { + fprintf(stderr, + "Can't open `%s': %s\n", optarg, strerror(errno)); + return(4); + } + if (!options->set_value("serial_in_file", this, Ser_in)) + fprintf(stderr, "Warning: No \"serial_in_file\" option found to set " + "parameter of -s as serial input file\n"); + if ((Ser_out= fopen(optarg, "w")) == NULL) + { + fprintf(stderr, + "Can't open `%s': %s\n", optarg, strerror(errno)); + return(4); + } + if (!options->set_value("serial_out_file", this, Ser_out)) + fprintf(stderr, "Warning: No \"serial_out_file\" option found " + "to set parameter of -s as serial output file\n"); +#endif + break; } #ifdef SOCKET_AVAIL // socket serial I/O by Alexandre Frey case 'k': - { - FILE *Ser_in, *Ser_out; - int sock; - unsigned short serverport; - int client_sock; - - if (k_done) { - fprintf(stderr, "Serial input specified more than once.\n"); - } - k_done= DD_TRUE; - - serverport = atoi(optarg); - sock= make_server_socket(serverport); - if (listen(sock, 1) < 0) { - fprintf(stderr, "Listen on port %d: %s\n", serverport, - strerror(errno)); - return (4); - } - fprintf(stderr, "Listening on port %d for a serial connection.\n", - serverport); - if ((client_sock= accept(sock, NULL, NULL)) < 0) { - fprintf(stderr, "accept: %s\n", strerror(errno)); - } - fprintf(stderr, "Serial connection established.\n"); - - if ((Ser_in= fdopen(client_sock, "r")) == NULL) { - fprintf(stderr, "Can't create input stream: %s\n", strerror(errno)); - return (4); - } - if (!options->set_value("serial_in_file", this, (void*)Ser_in)) - fprintf(stderr, "Warning: No \"serial_in_file\" option found to " - "set parameter of -s as serial input file\n"); - if ((Ser_out= fdopen(client_sock, "w")) == NULL) { - fprintf(stderr, "Can't create output stream: %s\n", strerror(errno)); - return (4); - } - if (!options->set_value("serial_out_file", this, Ser_out)) - fprintf(stderr, "Warning: No \"serial_out_file\" option found " - "to set parameter of -s as serial output file\n"); - break; - } + { + FILE *Ser_in, *Ser_out; + UCSOCKET_T sock; + unsigned short serverport; + UCSOCKET_T client_sock; + + if (k_done) + { + fprintf(stderr, "Serial input specified more than once.\n"); + } + k_done= DD_TRUE; + + serverport = atoi(optarg); + sock = make_server_socket(serverport); +#ifdef _WIN32 + if (SOCKET_ERROR == listen((SOCKET)sock, 1)) + { + fprintf(stderr, "Listen on port %d: %d\n", serverport, + WSAGetLastError()); + return (4); + } + fprintf(stderr, "Listening on port %d for a serial connection.\n", + serverport); + if (INVALID_SOCKET == (client_sock = accept(sock, NULL, NULL))) + { + fprintf(stderr, "accept: %d\n", WSAGetLastError()); + return (4); + } + fprintf(stderr, "Serial connection established.\n"); + + int fh = _open_osfhandle((intptr_t)client_sock, 0); + if (-1 == fh) + { + perror("_open_osfhandle"); + return (4); + } + if (NULL == (Ser_in = fdopen(fh, "r"))) + { + fprintf(stderr, "Can't create input stream: %s\n", strerror(errno)); + return (4); + } + + fh = _open_osfhandle((intptr_t)client_sock, 0); + if (-1 == fh) + { + perror("_open_osfhandle"); + } + if (NULL == (Ser_out = fdopen(fh, "w"))) { + fprintf(stderr, "Can't create output stream: %s\n", strerror(errno)); + return (4); + } +#else + if (listen(sock, 1) < 0) { + fprintf(stderr, "Listen on port %d: %s\n", serverport, + strerror(errno)); + return (4); + } + fprintf(stderr, "Listening on port %d for a serial connection.\n", + serverport); + if ((client_sock= accept(sock, NULL, NULL)) < 0) { + fprintf(stderr, "accept: %s\n", strerror(errno)); + } + fprintf(stderr, "Serial connection established.\n"); + + if ((Ser_in= fdopen(client_sock, "r")) == NULL) { + fprintf(stderr, "Can't create input stream: %s\n", strerror(errno)); + return (4); + } + if ((Ser_out= fdopen(client_sock, "w")) == NULL) { + fprintf(stderr, "Can't create output stream: %s\n", strerror(errno)); + return (4); + } +#endif + if (!options->set_value("serial_in_file", this, (void*)Ser_in)) + fprintf(stderr, "Warning: No \"serial_in_file\" option found to " + "set parameter of -s as serial input file\n"); + if (!options->set_value("serial_out_file", this, Ser_out)) + fprintf(stderr, "Warning: No \"serial_out_file\" option found " + "to set parameter of -s as serial output file\n"); + break; + } #endif case 'S': - subopts= optarg; - while (*subopts != '\0') - switch (get_sub_opt(&subopts, S_opts, &value)) - { - FILE *Ser_in, *Ser_out; - case SOPT_IN: - if (value == NULL) { - fprintf(stderr, "No value for -S in\n"); - exit(1); - } - if (S_i_done) - { - fprintf(stderr, "Serial input specified more than once.\n"); - break; - } - S_i_done= DD_TRUE; - if ((Ser_in= fopen(value, "r")) == NULL) - { - fprintf(stderr, - "Can't open `%s': %s\n", value, strerror(errno)); - exit(4); - } - if (!options->set_value("serial_in_file", this, (void*)Ser_in)) - fprintf(stderr, "Warning: No \"serial_in_file\" option found " - "to set parameter of -s as serial input file\n"); - break; - case SOPT_OUT: - if (value == NULL) { - fprintf(stderr, "No value for -S out\n"); - exit(1); - } - if (S_o_done) - { - fprintf(stderr, "Serial output specified more than once.\n"); - break; - } - if ((Ser_out= fopen(value, "w")) == NULL) - { - fprintf(stderr, - "Can't open `%s': %s\n", value, strerror(errno)); - exit(4); - } - if (!options->set_value("serial_out_file", this, Ser_out)) - fprintf(stderr, "Warning: No \"serial_out_file\" option found " - "to set parameter of -s as serial output file\n"); - break; - default: - /* Unknown suboption. */ - fprintf(stderr, "Unknown suboption `%s' for -S\n", value); - exit(1); - break; - } - break; + subopts= optarg; + while (*subopts != '\0') + switch (get_sub_opt(&subopts, S_opts, &value)) + { + FILE *Ser_in, *Ser_out; + case SOPT_IN: + if (value == NULL) { + fprintf(stderr, "No value for -S in\n"); + exit(1); + } + if (S_i_done) + { + fprintf(stderr, "Serial input specified more than once.\n"); + break; + } + S_i_done= DD_TRUE; + if ((Ser_in= fopen(value, "r")) == NULL) + { + fprintf(stderr, + "Can't open `%s': %s\n", value, strerror(errno)); + exit(4); + } + if (!options->set_value("serial_in_file", this, (void*)Ser_in)) + fprintf(stderr, "Warning: No \"serial_in_file\" option found " + "to set parameter of -s as serial input file\n"); + break; + case SOPT_OUT: + if (value == NULL) { + fprintf(stderr, "No value for -S out\n"); + exit(1); + } + if (S_o_done) + { + fprintf(stderr, "Serial output specified more than once.\n"); + break; + } + if ((Ser_out= fopen(value, "w")) == NULL) + { + fprintf(stderr, + "Can't open `%s': %s\n", value, strerror(errno)); + exit(4); + } + if (!options->set_value("serial_out_file", this, Ser_out)) + fprintf(stderr, "Warning: No \"serial_out_file\" option found " + "to set parameter of -s as serial output file\n"); + break; + default: + /* Unknown suboption. */ + fprintf(stderr, "Unknown suboption `%s' for -S\n", value); + exit(1); + break; + } + break; case 'h': - print_help("s51"); - exit(0); - break; + print_help("s51"); + exit(0); + break; case 'H': - { - if (!cpus) - { - fprintf(stderr, "CPU type is not selectable\n"); - exit(0); - } - i= 0; - while (cpus[i].type_str != NULL) - { - printf("%s\n", cpus[i].type_str); - i++; - } - exit(0); - break; - } + { + if (!cpus) + { + fprintf(stderr, "CPU type is not selectable\n"); + exit(0); + } + i= 0; + while (cpus[i].type_str != NULL) + { + printf("%s\n", cpus[i].type_str); + i++; + } + exit(0); + break; + } case '?': - if (isprint(optopt)) - fprintf(stderr, "Unknown option `-%c'.\n", optopt); - else - fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); - return(1); - break; + if (isprint(optopt)) + fprintf(stderr, "Unknown option `-%c'.\n", optopt); + else + fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); + return(1); + break; default: - exit(c); + exit(c); } for (i= optind; i < argc; i++) @@ -529,7 +597,7 @@ cl_app::set_simulator(class cl_sim *simulator) if (sim) remove_simulator(); sim= simulator; - + } void @@ -555,7 +623,7 @@ cl_app::build_cmdset(class cl_cmdset *cmdset) "conf Configuration", "long help of conf")); cmd->init(); - cset->add(cmd= new cl_conf_objects_cmd("objects", 0, + cset->add(cmd= new cl_conf_objects_cmd("objects", 0, "conf objects Show object tree", "long help of conf objects")); cmd->init(); @@ -601,11 +669,11 @@ cl_app::build_cmdset(class cl_cmdset *cmdset) cset= new cl_cmdset(); cset->init(); } - cset->add(cmd= new cl_show_copying_cmd("copying", 0, + cset->add(cmd= new cl_show_copying_cmd("copying", 0, "show copying Conditions for redistributing copies of uCsim", "long help of show copying")); cmd->init(); - cset->add(cmd= new cl_show_warranty_cmd("warranty", 0, + cset->add(cmd= new cl_show_warranty_cmd("warranty", 0, "show warranty Various kinds of warranty you do not have", "long help of show warranty")); cmd->init(); @@ -681,44 +749,44 @@ cl_app::mk_options(void) class cl_option *o; options->new_option(o= new cl_bool_option(this, "null_prompt", - "Use \\0 as prompt (-P)")); + "Use \\0 as prompt (-P)")); o->init(); options->new_option(o= new cl_pointer_option(this, "serial_in_file", - "Input file for serial line (-s)")); + "Input file for serial line (-s)")); o->init(); o->hide(); options->new_option(o= new cl_pointer_option(this, "serial_out_file", - "Output file for serial line (-s)")); + "Output file for serial line (-s)")); o->init(); o->hide(); options->new_option(o= new cl_string_option(this, "prompt", - "String of prompt (-p)")); + "String of prompt (-p)")); o->init(); options->new_option(o= new cl_bool_option(this, "debug", - "Print debug messages (-V)")); + "Print debug messages (-V)")); o->init(); options->new_option(o= new cl_string_option(this, "console_on", - "Open console on this file (-c)")); + "Open console on this file (-c)")); o->init(); o->hide(); options->new_option(o= new cl_string_option(this, "config_file", - "Execute this file at startup (-C)")); + "Execute this file at startup (-C)")); o->init(); o->hide(); options->new_option(o= new cl_float_option(this, "xtal", - "Frequency of XTAL in Hz")); + "Frequency of XTAL in Hz")); o->init(); o->set_value(11059200.0); options->new_option(o= new cl_string_option(this, "cpu_type", - "Type of controller (-t)")); + "Type of controller (-t)")); o->init(); o->hide(); } diff --git a/sim/ucsim/appcl.h b/sim/ucsim/appcl.h index 5195b32d..70da7d9b 100644 --- a/sim/ucsim/appcl.h +++ b/sim/ucsim/appcl.h @@ -78,7 +78,7 @@ public: class cl_app: public cl_base { protected: - class cl_commander *commander; + class cl_commander_base *commander; public: class cl_sim *sim; class cl_ustrings *in_files; @@ -101,7 +101,7 @@ protected: public: class cl_sim *get_sim(void) { return(sim); } class cl_uc *get_uc(void); - class cl_commander *get_commander(void) { return(commander); } + class cl_commander_base *get_commander(void) { return(commander); } virtual class cl_cmd *get_cmd(class cl_cmdline *cmdline); public: // messages to broadcast diff --git a/sim/ucsim/avr.src/avr.cc b/sim/ucsim/avr.src/avr.cc index 379edd09..5991f6c3 100644 --- a/sim/ucsim/avr.src/avr.cc +++ b/sim/ucsim/avr.src/avr.cc @@ -129,7 +129,7 @@ cl_avr::make_memories(void) chip->init(); memchips->add(chip); ad= new cl_address_decoder(as= rom/*address_space(MEM_ROM_ID)*/, - chip, 0, 0xffff, 0); + chip, 0, 0xffff, 0); ad->init(); as->decoders->add(ad); ad->activate(0); @@ -138,7 +138,7 @@ cl_avr::make_memories(void) chip->init(); memchips->add(chip); ad= new cl_address_decoder(as= ram/*address_space(MEM_IRAM_ID)*/, - chip, 0, 0x7f, 0); + chip, 0, 0x7f, 0); ad->init(); as->decoders->add(ad); ad->activate(0); @@ -181,7 +181,7 @@ cl_avr::disass(t_addr addr, char *sep) code= get_mem(MEM_ROM_ID, addr); i= 0; while ((code & dis_tbl()[i].mask) != dis_tbl()[i].code && - dis_tbl()[i].mnemonic) + dis_tbl()[i].mnemonic) i++; if (dis_tbl()[i].mnemonic == NULL) { @@ -194,90 +194,90 @@ cl_avr::disass(t_addr addr, char *sep) while (*b) { if (*b == '%') - { - b++; - switch (*(b++)) - { - case 'd': // Rd .... ...d dddd .... 0<=d<=31 - if (!get_name(data= (code&0x01f0)>>4, sfr_tbl(), temp)) - sprintf(temp, "r%d", data); - break; - case 'D': // Rd .... .... dddd .... 16<=d<=31 - if (!get_name(data= 16+((code&0xf0)>>4), sfr_tbl(), temp)) - sprintf(temp, "r%d", data); - break; - case 'K': // K .... KKKK .... KKKK 0<=K<=255 - sprintf(temp, "%d", ((code&0xf00)>>4)|(code&0xf)); - break; - case 'r': // Rr .... ..r. .... rrrr 0<=r<=31 - if (!get_name(data= ((code&0x0200)>>5)|(code&0x000f), - sfr_tbl(), temp)) - sprintf(temp, "r%d", data); - break; - case '2': // Rdl .... .... ..dd .... dl= {24,26,28,30} - if (!get_name(data= 24+(2*((code&0x0030)>>4)), - sfr_tbl(), temp)) - sprintf(temp, "r%d", data); - break; - case '6': // K .... .... KK.. KKKK 0<=K<=63 - sprintf(temp, "%d", ((code&0xc0)>>2)|(code&0xf)); - break; - case 's': // s .... .... .sss .... 0<=s<=7 - sprintf(temp, "%d", (code&0x70)>>4); - break; - case 'b': // b .... .... .... .bbb 0<=b<=7 - sprintf(temp, "%d", code&0x7); - break; - case 'k': // k .... ..kk kkkk k... -64<=k<=+63 - { - int k= (code&0x3f8)>>3; - if (code&0x200) - k|= -128; - sprintf(temp, "0x%06x", k+1+(signed int)addr); - break; - } - case 'A': // k .... ...k kkkk ...k 0<=k<=64K - // kkkk kkkk kkkk kkkk 0<=k<=4M - sprintf(temp, "0x%06x", - (((code&0x1f0)>>3)|(code&1))*0x10000+ - (uint)get_mem(MEM_ROM_ID, addr+1)); - break; - case 'P': // P .... .... pppp p... 0<=P<=31 - data= (code&0xf8)>>3; - if (!get_name(data+0x20, sfr_tbl(), temp)) - sprintf(temp, "%d", data); - break; - case 'p': // P .... .PP. .... PPPP 0<=P<=63 - data= ((code&0x600)>>5)|(code&0xf); - if (!get_name(data+0x20, sfr_tbl(), temp)) - sprintf(temp, "%d", data); - break; - case 'q': // q ..q. qq.. .... .qqq 0<=q<=63 - sprintf(temp, "%d", - ((code&0x2000)>>8)|((code&0xc00)>>7)|(code&7)); - break; - case 'R': // k SRAM address on second word 0<=k<=65535 - sprintf(temp, "0x%06x", (uint)get_mem(MEM_ROM_ID, addr+1)); - break; - case 'a': // k .... kkkk kkkk kkkk -2k<=k<=2k - { - int k= code&0xfff; - if (code&0x800) - k|= -4096; - sprintf(temp, "0x%06"_A_"x", - rom->validate_address(k+1+(signed int)addr)); - break; - } - default: - strcpy(temp, "?"); - break; - } - t= temp; - while (*t) - *(p++)= *(t++); - } + { + b++; + switch (*(b++)) + { + case 'd': // Rd .... ...d dddd .... 0<=d<=31 + if (!get_name(data= (code&0x01f0)>>4, sfr_tbl(), temp)) + sprintf(temp, "r%d", data); + break; + case 'D': // Rd .... .... dddd .... 16<=d<=31 + if (!get_name(data= 16+((code&0xf0)>>4), sfr_tbl(), temp)) + sprintf(temp, "r%d", data); + break; + case 'K': // K .... KKKK .... KKKK 0<=K<=255 + sprintf(temp, "%d", ((code&0xf00)>>4)|(code&0xf)); + break; + case 'r': // Rr .... ..r. .... rrrr 0<=r<=31 + if (!get_name(data= ((code&0x0200)>>5)|(code&0x000f), + sfr_tbl(), temp)) + sprintf(temp, "r%d", data); + break; + case '2': // Rdl .... .... ..dd .... dl= {24,26,28,30} + if (!get_name(data= 24+(2*((code&0x0030)>>4)), + sfr_tbl(), temp)) + sprintf(temp, "r%d", data); + break; + case '6': // K .... .... KK.. KKKK 0<=K<=63 + sprintf(temp, "%d", ((code&0xc0)>>2)|(code&0xf)); + break; + case 's': // s .... .... .sss .... 0<=s<=7 + sprintf(temp, "%d", (code&0x70)>>4); + break; + case 'b': // b .... .... .... .bbb 0<=b<=7 + sprintf(temp, "%d", code&0x7); + break; + case 'k': // k .... ..kk kkkk k... -64<=k<=+63 + { + int k= (code&0x3f8)>>3; + if (code&0x200) + k|= -128; + sprintf(temp, "0x%06x", k+1+(signed int)addr); + break; + } + case 'A': // k .... ...k kkkk ...k 0<=k<=64K + // kkkk kkkk kkkk kkkk 0<=k<=4M + sprintf(temp, "0x%06x", + (((code&0x1f0)>>3)|(code&1))*0x10000+ + (uint)get_mem(MEM_ROM_ID, addr+1)); + break; + case 'P': // P .... .... pppp p... 0<=P<=31 + data= (code&0xf8)>>3; + if (!get_name(data+0x20, sfr_tbl(), temp)) + sprintf(temp, "%d", data); + break; + case 'p': // P .... .PP. .... PPPP 0<=P<=63 + data= ((code&0x600)>>5)|(code&0xf); + if (!get_name(data+0x20, sfr_tbl(), temp)) + sprintf(temp, "%d", data); + break; + case 'q': // q ..q. qq.. .... .qqq 0<=q<=63 + sprintf(temp, "%d", + ((code&0x2000)>>8)|((code&0xc00)>>7)|(code&7)); + break; + case 'R': // k SRAM address on second word 0<=k<=65535 + sprintf(temp, "0x%06x", (uint)get_mem(MEM_ROM_ID, addr+1)); + break; + case 'a': // k .... kkkk kkkk kkkk -2k<=k<=2k + { + int k= code&0xfff; + if (code&0x800) + k|= -4096; + sprintf(temp, "0x%06"_A_"x", + rom->validate_address(k+1+(signed int)addr)); + break; + } + default: + strcpy(temp, "?"); + break; + } + t= temp; + while (*t) + *(p++)= *(t++); + } else - *(p++)= *(b++); + *(p++)= *(b++); } *p= '\0'; @@ -298,7 +298,7 @@ cl_avr::disass(t_addr addr, char *sep) if (sep == NULL) { while (strlen(buf) < 6) - strcat(buf, " "); + strcat(buf, " "); } else strcat(buf, sep); @@ -308,7 +308,7 @@ cl_avr::disass(t_addr addr, char *sep) void -cl_avr::print_regs(class cl_console *con) +cl_avr::print_regs(class cl_console_base *con) { uchar data, sreg= ram->get(SREG); uint x, y, z; @@ -316,30 +316,30 @@ cl_avr::print_regs(class cl_console *con) ram->dump(0, 31, 16, con); con->dd_printf("ITHSVNZC SREG= 0x%02x %3d %c\n", - sreg, sreg, isprint(sreg)?sreg:'.'); + sreg, sreg, isprint(sreg)?sreg:'.'); con->dd_printf("%c%c%c%c%c%c%c%c ", - (sreg&BIT_I)?'1':'0', - (sreg&BIT_T)?'1':'0', - (sreg&BIT_H)?'1':'0', - (sreg&BIT_S)?'1':'0', - (sreg&BIT_V)?'1':'0', - (sreg&BIT_N)?'1':'0', - (sreg&BIT_Z)?'1':'0', - (sreg&BIT_C)?'1':'0'); + (sreg&BIT_I)?'1':'0', + (sreg&BIT_T)?'1':'0', + (sreg&BIT_H)?'1':'0', + (sreg&BIT_S)?'1':'0', + (sreg&BIT_V)?'1':'0', + (sreg&BIT_N)?'1':'0', + (sreg&BIT_Z)?'1':'0', + (sreg&BIT_C)?'1':'0'); con->dd_printf("SP = 0x%06x\n", ram->get(SPH)*256+ram->get(SPL)); x= ram->get(XH)*256 + ram->get(XL); data= ram->get(x); con->dd_printf("X= 0x%04x [X]= 0x%02x %3d %c ", x, - data, data, isprint(data)?data:'.'); + data, data, isprint(data)?data:'.'); y= ram->get(YH)*256 + ram->get(YL); data= ram->get(y); con->dd_printf("Y= 0x%04x [Y]= 0x%02x %3d %c ", y, - data, data, isprint(data)?data:'.'); + data, data, isprint(data)?data:'.'); z= ram->get(ZH)*256 + ram->get(ZL); data= ram->get(z); con->dd_printf("Z= 0x%04x [Z]= 0x%02x %3d %c\n", z, - data, data, isprint(data)?data:'.'); + data, data, isprint(data)?data:'.'); print_disass(PC, con); } @@ -430,197 +430,197 @@ cl_avr::exec_inst(void) { case 0x0000: { - // 0x0... - switch (code & 0xfc00) - { - case 0x0000: - { - switch (code & 0xff00) - { - case 0x0100: return(movw_Rd_Rr(code)); - case 0x0200: return(muls_Rd_Rr(code)); - case 0x0300: - { - switch (code & 0xff88) - { - case 0x0300: return(mulsu_Rd_Rr(code)); - case 0x0308: return(fmul_Rd_Rr(code)); - case 0x0380: return(fmuls_Rd_Rr(code)); - case 0x0388: return(fmulsu_Rd_Rr(code)); - } - break; - } - break; - } - break; - } - case 0x0400: return(cpc_Rd_Rr(code)); - case 0x0800: return(sbc_Rd_Rr(code)); - case 0x0c00: return(add_Rd_Rr(code)); - } - break; + // 0x0... + switch (code & 0xfc00) + { + case 0x0000: + { + switch (code & 0xff00) + { + case 0x0100: return(movw_Rd_Rr(code)); + case 0x0200: return(muls_Rd_Rr(code)); + case 0x0300: + { + switch (code & 0xff88) + { + case 0x0300: return(mulsu_Rd_Rr(code)); + case 0x0308: return(fmul_Rd_Rr(code)); + case 0x0380: return(fmuls_Rd_Rr(code)); + case 0x0388: return(fmulsu_Rd_Rr(code)); + } + break; + } + break; + } + break; + } + case 0x0400: return(cpc_Rd_Rr(code)); + case 0x0800: return(sbc_Rd_Rr(code)); + case 0x0c00: return(add_Rd_Rr(code)); + } + break; } case 0x1000: { - // 0x1... - switch (code & 0xfc00) - { - case 0x1000: return(cpse_Rd_Rr(code)); - case 0x1400: return(cp_Rd_Rr(code)); - case 0x1800: return(sub_Rd_Rr(code)); - case 0x1c00: return(adc_Rd_Rr(code)); - } - break; + // 0x1... + switch (code & 0xfc00) + { + case 0x1000: return(cpse_Rd_Rr(code)); + case 0x1400: return(cp_Rd_Rr(code)); + case 0x1800: return(sub_Rd_Rr(code)); + case 0x1c00: return(adc_Rd_Rr(code)); + } + break; } case 0x2000: { - // 0x2... - switch (code & 0xfc00) - { - case 0x2000: return(and_Rd_Rr(code)); - case 0x2400: return(eor_Rd_Rr(code)); - case 0x2800: return(or_Rd_Rr(code)); - case 0x2c00: return(mov_Rd_Rr(code)); - } - break; + // 0x2... + switch (code & 0xfc00) + { + case 0x2000: return(and_Rd_Rr(code)); + case 0x2400: return(eor_Rd_Rr(code)); + case 0x2800: return(or_Rd_Rr(code)); + case 0x2c00: return(mov_Rd_Rr(code)); + } + break; } case 0x8000: { - // 0x8... - switch (code &0xf208) - { - case 0x8000: return(ldd_Rd_Z_q(code)); - case 0x8008: return(ldd_Rd_Y_q(code)); - case 0x8200: return(std_Z_q_Rr(code)); - case 0x8208: return(std_Y_q_Rr(code)); - } - break; + // 0x8... + switch (code &0xf208) + { + case 0x8000: return(ldd_Rd_Z_q(code)); + case 0x8008: return(ldd_Rd_Y_q(code)); + case 0x8200: return(std_Z_q_Rr(code)); + case 0x8208: return(std_Y_q_Rr(code)); + } + break; } case 0x9000: { - // 0x9... - if ((code & 0xff0f) == 0x9509) - return(icall(code)); - if ((code & 0xff0f) == 0x9409) - return(ijmp(code)); - if ((code & 0xff00) == 0x9600) - return(adiw_Rdl_K(code)); - if ((code & 0xff00) == 0x9700) - return(sbiw_Rdl_K(code)); - switch (code & 0xfc00) - { - case 0x9000: - { - switch (code & 0xfe0f) - { - case 0x9000: return(lds_Rd_k(code)); - case 0x9001: return(ld_Rd_ZS(code)); - case 0x9002: return(ld_Rd_SZ(code)); - case 0x9004: return(lpm_Rd_Z(code)); - case 0x9005: return(lpm_Rd_ZS(code)); - case 0x9006: return(elpm_Rd_Z(code)); - case 0x9007: return(elpm_Rd_ZS(code)); - case 0x9009: return(ld_Rd_YS(code)); - case 0x900a: return(ld_Rd_SY(code)); - case 0x900c: return(ld_Rd_X(code)); - case 0x900d: return(ld_Rd_XS(code)); - case 0x900e: return(ld_Rd_SX(code)); - case 0x900f: return(pop_Rd(code)); - case 0x9200: return(sts_k_Rr(code)); - case 0x9201: return(st_ZS_Rr(code)); - case 0x9202: return(st_SZ_Rr(code)); - case 0x9209: return(st_YS_Rr(code)); - case 0x920a: return(st_SY_Rr(code)); - case 0x920c: return(st_X_Rr(code)); - case 0x920d: return(st_XS_Rr(code)); - case 0x920e: return(st_SX_Rr(code)); - case 0x920f: return(push_Rr(code)); - } - break; - } - case 0x9400: - { - switch (code & 0xfe0f) - { - case 0x9400: return(com_Rd(code)); - case 0x9401: return(neg_Rd(code)); - case 0x9402: return(swap_Rd(code)); - case 0x9403: return(inc_Rd(code)); - case 0x9405: return(asr_Rd(code)); - case 0x9406: return(lsr_Rd(code)); - case 0x9407: return(ror_Rd(code)); - case 0x940a: return(dec_Rd(code)); - case 0x940c: case 0x940d: return(jmp_k(code)); - case 0x940e: case 0x940f: return(call_k(code)); - } - break; - } - case 0x9800: - { - switch (code & 0xff00) - { - case 0x9800: return(cbi_A_b(code)); - case 0x9900: return(sbic_P_b(code)); - case 0x9a00: return(sbi_A_b(code)); - case 0x9b00: return(sbis_P_b(code)); - } - break; - } - case 0x9c00: return(mul_Rd_Rr(code)); - } - break; + // 0x9... + if ((code & 0xff0f) == 0x9509) + return(icall(code)); + if ((code & 0xff0f) == 0x9409) + return(ijmp(code)); + if ((code & 0xff00) == 0x9600) + return(adiw_Rdl_K(code)); + if ((code & 0xff00) == 0x9700) + return(sbiw_Rdl_K(code)); + switch (code & 0xfc00) + { + case 0x9000: + { + switch (code & 0xfe0f) + { + case 0x9000: return(lds_Rd_k(code)); + case 0x9001: return(ld_Rd_ZS(code)); + case 0x9002: return(ld_Rd_SZ(code)); + case 0x9004: return(lpm_Rd_Z(code)); + case 0x9005: return(lpm_Rd_ZS(code)); + case 0x9006: return(elpm_Rd_Z(code)); + case 0x9007: return(elpm_Rd_ZS(code)); + case 0x9009: return(ld_Rd_YS(code)); + case 0x900a: return(ld_Rd_SY(code)); + case 0x900c: return(ld_Rd_X(code)); + case 0x900d: return(ld_Rd_XS(code)); + case 0x900e: return(ld_Rd_SX(code)); + case 0x900f: return(pop_Rd(code)); + case 0x9200: return(sts_k_Rr(code)); + case 0x9201: return(st_ZS_Rr(code)); + case 0x9202: return(st_SZ_Rr(code)); + case 0x9209: return(st_YS_Rr(code)); + case 0x920a: return(st_SY_Rr(code)); + case 0x920c: return(st_X_Rr(code)); + case 0x920d: return(st_XS_Rr(code)); + case 0x920e: return(st_SX_Rr(code)); + case 0x920f: return(push_Rr(code)); + } + break; + } + case 0x9400: + { + switch (code & 0xfe0f) + { + case 0x9400: return(com_Rd(code)); + case 0x9401: return(neg_Rd(code)); + case 0x9402: return(swap_Rd(code)); + case 0x9403: return(inc_Rd(code)); + case 0x9405: return(asr_Rd(code)); + case 0x9406: return(lsr_Rd(code)); + case 0x9407: return(ror_Rd(code)); + case 0x940a: return(dec_Rd(code)); + case 0x940c: case 0x940d: return(jmp_k(code)); + case 0x940e: case 0x940f: return(call_k(code)); + } + break; + } + case 0x9800: + { + switch (code & 0xff00) + { + case 0x9800: return(cbi_A_b(code)); + case 0x9900: return(sbic_P_b(code)); + case 0x9a00: return(sbi_A_b(code)); + case 0x9b00: return(sbis_P_b(code)); + } + break; + } + case 0x9c00: return(mul_Rd_Rr(code)); + } + break; } case 0xa000: { - // 0xa... - switch (code &0xf208) - { - case 0xa000: return(ldd_Rd_Z_q(code)); - case 0xa008: return(ldd_Rd_Y_q(code)); - case 0xa200: return(std_Z_q_Rr(code)); - case 0xa208: return(std_Y_q_Rr(code)); - } - break; + // 0xa... + switch (code &0xf208) + { + case 0xa000: return(ldd_Rd_Z_q(code)); + case 0xa008: return(ldd_Rd_Y_q(code)); + case 0xa200: return(std_Z_q_Rr(code)); + case 0xa208: return(std_Y_q_Rr(code)); + } + break; } case 0xb000: { - // 0xb... - switch (code & 0xf800) - { - case 0xb000: return(in_Rd_A(code)); - case 0xb800: return(out_A_Rr(code)); - } - break; + // 0xb... + switch (code & 0xf800) + { + case 0xb000: return(in_Rd_A(code)); + case 0xb800: return(out_A_Rr(code)); + } + break; } case 0xe000: { - // 0xe... - switch (code & 0xff0f) - { - case 0xef0f: return(ser_Rd(code)); - } - break; + // 0xe... + switch (code & 0xff0f) + { + case 0xef0f: return(ser_Rd(code)); + } + break; } case 0xf000: { - // 0xf... - switch (code & 0xfc00) - { - case 0xf000: return(brbs_s_k(code)); - case 0xf400: return(brbc_s_k(code)); - case 0xf800: case 0xfc00: - { - switch (code & 0xfe08) - { - case 0xf800: return(bld_Rd_b(code)); - case 0xfa00: return(bst_Rd_b(code)); - case 0xfc00: case 0xfc08: return(sbrc_Rr_b(code)); - case 0xfe00: case 0xfe08: return(sbrs_Rr_b(code)); - } - break; - } - } - break; + // 0xf... + switch (code & 0xfc00) + { + case 0xf000: return(brbs_s_k(code)); + case 0xf400: return(brbc_s_k(code)); + case 0xf800: case 0xfc00: + { + switch (code & 0xfe08) + { + case 0xf800: return(bld_Rd_b(code)); + case 0xfa00: return(bst_Rd_b(code)); + case 0xfc00: case 0xfc08: return(sbrc_Rr_b(code)); + case 0xfe00: case 0xfe08: return(sbrs_Rr_b(code)); + } + break; + } + } + break; } } /*if (PC) diff --git a/sim/ucsim/avr.src/avrcl.h b/sim/ucsim/avr.src/avrcl.h index 712efd8f..34f3c5ea 100644 --- a/sim/ucsim/avr.src/avrcl.h +++ b/sim/ucsim/avr.src/avrcl.h @@ -57,7 +57,7 @@ public: virtual struct name_entry *sfr_tbl(void); virtual struct name_entry *bit_tbl(void); virtual char *disass(t_addr addr, char *sep); - virtual void print_regs(class cl_console *con); + virtual void print_regs(class cl_console_base *con); virtual int exec_inst(void); diff --git a/sim/ucsim/cmd.src/Makefile.in b/sim/ucsim/cmd.src/Makefile.in index 73777ca8..4621566e 100644 --- a/sim/ucsim/cmd.src/Makefile.in +++ b/sim/ucsim/cmd.src/Makefile.in @@ -26,6 +26,7 @@ CPPFLAGS = @CPPFLAGS@ -I$(srcdir) -I$(top_srcdir) -I$(top_builddir) \ CFLAGS = @CFLAGS@ -Wall CXXFLAGS = @CXXFLAGS@ -Wall M_OR_MM = @M_OR_MM@ +WINSOCK_AVAIL = @WINSOCK_AVAIL@ prefix = @prefix@ exec_prefix = @exec_prefix@ @@ -40,10 +41,16 @@ infodir = @infodir@ srcdir = @srcdir@ VPATH = @srcdir@ -OBJECTS = cmdset.o command.o newcmd.o cmdutil.o syntax.o \ +OBJECTS = cmdset.o command.o cmdutil.o syntax.o \ get.o set.o timer.o bp.o info.o show.o cmdgui.o cmdconf.o \ cmduc.o cmdstat.o cmdmem.o \ - cmdpars.o cmdlex.o + cmdpars.o cmdlex.o newcmd.o + +ifeq ($(WINSOCK_AVAIL), 1) +OBJECTS += newcmdwin32.o +else +OBJECTS += newcmdposix.o +endif DEVEL = $(shell ( bash -c "test -e $(top_builddir)devel && echo yes" )) @@ -86,7 +93,7 @@ installdirs: dep: Makefile.dep Makefile.dep: $(srcdir)/*.cc $(srcdir)/*.h - $(CXXCPP) $(CPPFLAGS) $(M_OR_MM) $(filter %.cc,$^) >Makefile.dep + $(CXXCPP) $(CPPFLAGS) $(M_OR_MM) $(addprefix $(srcdir)/, $(OBJECTS:.o=.cc)) >Makefile.dep include Makefile.dep include $(srcdir)/clean.mk diff --git a/sim/ucsim/cmd.src/bp.cc b/sim/ucsim/cmd.src/bp.cc index 617f43e5..bc31d24b 100644 --- a/sim/ucsim/cmd.src/bp.cc +++ b/sim/ucsim/cmd.src/bp.cc @@ -45,7 +45,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA //int //cl_break_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_break_cmd) { t_addr addr= 0; @@ -53,9 +53,9 @@ COMMAND_DO_WORK_UC(cl_break_cmd) char op; class cl_address_space *mem; class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; if (cmdline->syntax_match(uc, ADDRESS)) { addr= params[0]->value.address; @@ -91,7 +91,7 @@ COMMAND_DO_WORK_UC(cl_break_cmd) void cl_break_cmd::do_fetch(class cl_uc *uc, - t_addr addr, int hit, class cl_console *con) + t_addr addr, int hit, class cl_console_base *con) { if (hit > 99999) { @@ -103,8 +103,8 @@ cl_break_cmd::do_fetch(class cl_uc *uc, else { class cl_brk *b= new cl_fetch_brk(uc->address_space(MEM_ROM_ID), - uc->make_new_brknr(), - addr, perm, hit); + uc->make_new_brknr(), + addr, perm, hit); b->init(); uc->fbrk->add_bp(b); char *s= uc->disass(addr, NULL); @@ -115,9 +115,9 @@ cl_break_cmd::do_fetch(class cl_uc *uc, void cl_break_cmd::do_event(class cl_uc *uc, - class cl_address_space *mem, - char op, t_addr addr, int hit, - class cl_console *con) + class cl_address_space *mem, + char op, t_addr addr, int hit, + class cl_console_base *con) { class cl_ev_brk *b= NULL; @@ -135,7 +135,7 @@ cl_break_cmd::do_event(class cl_uc *uc, //int //cl_clear_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_clear_cmd) { int idx; @@ -144,10 +144,10 @@ COMMAND_DO_WORK_UC(cl_clear_cmd) if (cmdline->param(0) == 0) { if (!brk) - { - con->dd_printf("No breakpoint at this address.\n"); - return(0); - } + { + con->dd_printf("No breakpoint at this address.\n"); + return(0); + } uc->fbrk->del_bp(uc->PC); return(0); } @@ -158,12 +158,12 @@ COMMAND_DO_WORK_UC(cl_clear_cmd) { t_addr addr; if (!param->as_address(uc)) - return(DD_FALSE); + return(DD_FALSE); addr= param->value.address; if (uc->fbrk->bp_at(addr) == 0) - con->dd_printf("No breakpoint at 0x%06x\n", addr); + con->dd_printf("No breakpoint at 0x%06x\n", addr); else - uc->fbrk->del_bp(addr); + uc->fbrk->del_bp(addr); } return(DD_FALSE); @@ -176,7 +176,7 @@ COMMAND_DO_WORK_UC(cl_clear_cmd) //int //cl_delete_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_delete_cmd) { if (cmdline->param(0) == 0) @@ -189,14 +189,14 @@ COMMAND_DO_WORK_UC(cl_delete_cmd) int i= 0; class cl_cmd_arg *param; while ((param= cmdline->param(i++))) - { - long num; - if (param->get_ivalue(&num)) - { - if (!uc->rm_brk(num)) - con->dd_printf("Error\n"); - } - } + { + long num; + if (param->get_ivalue(&num)) + { + if (!uc->rm_brk(num)) + con->dd_printf("Error\n"); + } + } } return(DD_FALSE); } diff --git a/sim/ucsim/cmd.src/bpcl.h b/sim/ucsim/cmd.src/bpcl.h index 61e0b7f4..407b6add 100644 --- a/sim/ucsim/cmd.src/bpcl.h +++ b/sim/ucsim/cmd.src/bpcl.h @@ -37,11 +37,11 @@ public: enum brk_perm perm; COMMAND_METHODS_ON(uc,cl_break_cmd) virtual void do_fetch(class cl_uc *uc, - t_addr addr, int hit, class cl_console *con); + t_addr addr, int hit, class cl_console_base *con); virtual void do_event(class cl_uc *uc, - class cl_address_space *mem, - char op, t_addr addr, int hit, - class cl_console *con); + class cl_address_space *mem, + char op, t_addr addr, int hit, + class cl_console_base *con); COMMAND_TAIL; // TBREAK @@ -49,9 +49,9 @@ class cl_tbreak_cmd: public cl_break_cmd { public: cl_tbreak_cmd(char *aname, - int can_rep, - char *short_hlp, - char *long_hlp): + int can_rep, + char *short_hlp, + char *long_hlp): cl_break_cmd(aname, can_rep, short_hlp, long_hlp) {perm=brkDYNAMIC;} }; diff --git a/sim/ucsim/cmd.src/cmdconf.cc b/sim/ucsim/cmd.src/cmdconf.cc index f521e890..b0797b6f 100644 --- a/sim/ucsim/cmd.src/cmdconf.cc +++ b/sim/ucsim/cmd.src/cmdconf.cc @@ -43,7 +43,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA //int //cl_conf_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_conf_cmd) { int i; @@ -51,7 +51,7 @@ COMMAND_DO_WORK_UC(cl_conf_cmd) con->dd_printf("ucsim version %s\n", VERSIONSTR); con->dd_printf("Type of microcontroller: %s\n", uc->id_string()); con->dd_printf("Controller has %d hardware element(s).\n", - uc->hws->count); + uc->hws->count); for (i= 0; i < uc->hws->count; i++) { class cl_hw *hw= (class cl_hw *)(uc->hws->at(i)); @@ -66,8 +66,8 @@ COMMAND_DO_WORK_UC(cl_conf_cmd) */ static void -conf_objects_cmd_print_node(class cl_console *con, - int indent, class cl_base *node) +conf_objects_cmd_print_node(class cl_console_base *con, + int indent, class cl_base *node) { if (!node) return; @@ -86,14 +86,14 @@ conf_objects_cmd_print_node(class cl_console *con, //int //cl_conf_addmem_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_APP(cl_conf_objects_cmd) { //class cl_address_space *mem= 0; /*class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) };*/ + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) };*/ class cl_error *cl_error_base = new cl_error(); conf_objects_cmd_print_node(con, 0, /*application*/cl_error_base->get_class()); delete cl_error_base; diff --git a/sim/ucsim/cmd.src/cmdgui.cc b/sim/ucsim/cmd.src/cmdgui.cc index 5a1fdef9..10c6928c 100644 --- a/sim/ucsim/cmd.src/cmdgui.cc +++ b/sim/ucsim/cmd.src/cmdgui.cc @@ -44,16 +44,16 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA //int //cl_gui_start_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_gui_start_cmd) { class cl_hw *hw; class cl_memory *mem; t_addr start, end; class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; if (cmdline->syntax_match(uc, HW)) { hw= params[0]->value.hw; @@ -66,7 +66,7 @@ COMMAND_DO_WORK_UC(cl_gui_start_cmd) else { con->dd_printf("Error: wrong syntax\n" - "%s\n", short_help?short_help:"no help"); + "%s\n", short_help?short_help:"no help"); } return(DD_FALSE);; @@ -80,7 +80,7 @@ COMMAND_DO_WORK_UC(cl_gui_start_cmd) //int //cl_gui_stop_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_gui_stop_cmd) { return(DD_FALSE);; diff --git a/sim/ucsim/cmd.src/cmdmem.cc b/sim/ucsim/cmd.src/cmdmem.cc index 79666e1a..3aafc9a1 100644 --- a/sim/ucsim/cmd.src/cmdmem.cc +++ b/sim/ucsim/cmd.src/cmdmem.cc @@ -43,13 +43,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA //int //cl_conf_addmem_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_memory_createchip_cmd) { class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; char *memid= NULL; int size= -1; int width= 8; @@ -89,13 +89,13 @@ COMMAND_DO_WORK_UC(cl_memory_createchip_cmd) //int //cl_conf_addmem_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_memory_createaddressspace_cmd) { class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; char *memid= NULL; int start= 0, size= -1, width= 8; @@ -125,7 +125,7 @@ COMMAND_DO_WORK_UC(cl_memory_createaddressspace_cmd) else { class cl_address_space *mem= - new cl_address_space(memid, start, size, width); + new cl_address_space(memid, start, size, width); mem->init(); uc->address_spaces->add(mem); mem->set_uc(uc); @@ -141,14 +141,14 @@ COMMAND_DO_WORK_UC(cl_memory_createaddressspace_cmd) //int //cl_conf_addmem_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_memory_createaddressdecoder_cmd) { class cl_cmd_arg *params[5]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3), - cmdline->param(4) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3), + cmdline->param(4) }; class cl_memory *as= 0, *chip= 0; t_addr as_begin= 0, as_end= 0, chip_begin= 0; @@ -201,14 +201,14 @@ COMMAND_DO_WORK_UC(cl_memory_createaddressdecoder_cmd) else if (chip_begin >= chip->get_size()) con->dd_printf("Wrong chip area specification\n"); else if (as_begin < as->start_address || - as_end >= as->highest_valid_address()) + as_end >= as->highest_valid_address()) con->dd_printf("Specified area is out of address space\n"); else if (as_end-as_begin > chip->get_size()-chip_begin) con->dd_printf("Specified area is out of chip size\n"); else { class cl_address_decoder *d= - new cl_address_decoder(as, chip, as_begin, as_end, chip_begin); + new cl_address_decoder(as, chip, as_begin, as_end, chip_begin); ((class cl_address_space *)as)->decoders->add(d); d->activate(con); } diff --git a/sim/ucsim/cmd.src/cmdset.cc b/sim/ucsim/cmd.src/cmdset.cc index f0226ceb..8f3523bb 100644 --- a/sim/ucsim/cmd.src/cmdset.cc +++ b/sim/ucsim/cmd.src/cmdset.cc @@ -50,51 +50,51 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA //int //cl_run_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_SIM(cl_run_cmd) { class cl_brk *b; t_addr start, end; class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; if (params[0]) if (!(params[0]->get_address(sim->uc, &start))) { - con->dd_printf("Error: wrong start address\n"); - return(DD_FALSE); + con->dd_printf("Error: wrong start address\n"); + return(DD_FALSE); } if (params[1]) if (!(params[1]->get_address(sim->uc, &end))) { - con->dd_printf("Error: wromg end address\n"); - return(DD_FALSE); + con->dd_printf("Error: wromg end address\n"); + return(DD_FALSE); } if (params[0]) { if (!sim->uc->inst_at(start)) - con->dd_printf("Warning: maybe not instruction at 0x%06lx\n", start); + con->dd_printf("Warning: maybe not instruction at 0x%06lx\n", start); sim->uc->PC= start; if (params[1]) - { - if (start == end) - { - con->dd_printf("Addresses must be different.\n"); - return(DD_FALSE); - } - if ((b= sim->uc->fbrk_at(end))) - { - } - else - { - b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID), - sim->uc->make_new_brknr(), end, - brkDYNAMIC, 1); - sim->uc->fbrk->add_bp(b); - } - } + { + if (start == end) + { + con->dd_printf("Addresses must be different.\n"); + return(DD_FALSE); + } + if ((b= sim->uc->fbrk_at(end))) + { + } + else + { + b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID), + sim->uc->make_new_brknr(), end, + brkDYNAMIC, 1); + sim->uc->fbrk->add_bp(b); + } + } } con->dd_printf("Simulation started, PC=0x%06x\n", sim->uc->PC); if (sim->uc->fbrk_at(sim->uc->PC)) @@ -112,7 +112,7 @@ COMMAND_DO_WORK_SIM(cl_run_cmd) //int //cl_stop_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_SIM(cl_stop_cmd) { sim->stop(resUSER); @@ -128,7 +128,7 @@ COMMAND_DO_WORK_SIM(cl_stop_cmd) //int //cl_step_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_step_cmd) { //printf("step %x\n",uc->PC); @@ -146,7 +146,7 @@ COMMAND_DO_WORK_UC(cl_step_cmd) //int //cl_next_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_SIM(cl_next_cmd) { class cl_brk *b; @@ -160,7 +160,7 @@ COMMAND_DO_WORK_SIM(cl_next_cmd) int i= 0; de= &(sim->uc->dis_tbl()[i]); while ((code & de->mask) != de->code && - de->mnemonic) + de->mnemonic) { i++; de= &(sim->uc->dis_tbl()[i]); @@ -174,19 +174,19 @@ COMMAND_DO_WORK_SIM(cl_next_cmd) { next= sim->uc->PC + inst_len; if (!sim->uc->fbrk_at(next)) - { - b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID), - sim->uc->make_new_brknr(), - next, brkDYNAMIC, 1); + { + b= new cl_fetch_brk(sim->uc->address_space(MEM_ROM_ID), + sim->uc->make_new_brknr(), + next, brkDYNAMIC, 1); - b->init(); -// sim->uc->fbrk->add_bp(b); + b->init(); +// sim->uc->fbrk->add_bp(b); - sim->uc->fbrk->add(b); - b->activate(); - } + sim->uc->fbrk->add(b); + b->activate(); + } if (sim->uc->fbrk_at(sim->uc->PC)) - sim->uc->do_inst(1); + sim->uc->do_inst(1); sim->start(con); //sim->uc->do_inst(-1); } @@ -205,11 +205,11 @@ COMMAND_DO_WORK_SIM(cl_next_cmd) //int //cl_help_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_APP(cl_help_cmd) { class cl_sim *sim; - class cl_commander *commander; + class cl_commander_base *commander; class cl_cmdset *cmdset= 0; int i; class cl_cmd_arg *parm= cmdline->param(0); @@ -222,11 +222,11 @@ COMMAND_DO_WORK_APP(cl_help_cmd) if (!parm) { for (i= 0; i < cmdset->count; i++) { - class cl_cmd *c= (class cl_cmd *)(cmdset->at(i)); - if (c->short_help) - con->dd_printf("%s\n", c->short_help); - else - con->dd_printf("%s\n", (char*)(c->names->at(0))); + class cl_cmd *c= (class cl_cmd *)(cmdset->at(i)); + if (c->short_help) + con->dd_printf("%s\n", c->short_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); } } else @@ -234,55 +234,55 @@ COMMAND_DO_WORK_APP(cl_help_cmd) matches= 0; do_set(cmdline, 0, cmdset, con); if (matches == 1 && - cmd_found) - { - int names; - con->dd_printf("Names of command:"); - for (names= 0; names < cmd_found->names->count; names++) - con->dd_printf(" %s", (char*)(cmd_found->names->at(names))); - con->dd_printf("\n"); - class cl_cmdset *subset= cmd_found->get_subcommands(); - if (subset) - { - con->dd_printf("\"%s\" must be followed by the name of a " - "subcommand\nList of subcommands:\n", - (char*)(cmd_found->names->at(0))); - for (i= 0; i < subset->count; i++) - { - class cl_cmd *c= - dynamic_cast(subset->object_at(i)); - con->dd_printf("%s\n", c->short_help); - } - } - if (cmd_found->long_help) - con->dd_printf("%s\n", cmd_found->long_help); - } + cmd_found) + { + int names; + con->dd_printf("Names of command:"); + for (names= 0; names < cmd_found->names->count; names++) + con->dd_printf(" %s", (char*)(cmd_found->names->at(names))); + con->dd_printf("\n"); + class cl_cmdset *subset= cmd_found->get_subcommands(); + if (subset) + { + con->dd_printf("\"%s\" must be followed by the name of a " + "subcommand\nList of subcommands:\n", + (char*)(cmd_found->names->at(0))); + for (i= 0; i < subset->count; i++) + { + class cl_cmd *c= + dynamic_cast(subset->object_at(i)); + con->dd_printf("%s\n", c->short_help); + } + } + if (cmd_found->long_help) + con->dd_printf("%s\n", cmd_found->long_help); + } if (!matches || - !cmd_found) - con->dd_printf("No such command.\n"); + !cmd_found) + con->dd_printf("No such command.\n"); //return(DD_FALSE); /* int pari; for (pari= 0; pari < cmdline->nuof_params(); pari++) - { - class cl_cmd_arg *act_param; - act_param= (class cl_cmd_arg *)(cmdline->param(pari)); - for (i= 0; i < cmdset->count; i++) - { - class cl_cmd *c= (class cl_cmd *)(cmdset->at(i)); - if (!c->name_match(act_param->s_value, DD_FALSE)) - continue; - if (c->short_help) - con->dd_printf("%s\n", c->short_help); - else - con->dd_printf("%s\n", (char*)(c->names->at(0))); - if (pari < cmdline->nuof_params()-1) - continue; - cmdset= c->get_subcommands(); - if (!cmdset) - return(DD_FALSE); - } - } + { + class cl_cmd_arg *act_param; + act_param= (class cl_cmd_arg *)(cmdline->param(pari)); + for (i= 0; i < cmdset->count; i++) + { + class cl_cmd *c= (class cl_cmd *)(cmdset->at(i)); + if (!c->name_match(act_param->s_value, DD_FALSE)) + continue; + if (c->short_help) + con->dd_printf("%s\n", c->short_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); + if (pari < cmdline->nuof_params()-1) + continue; + cmdset= c->get_subcommands(); + if (!cmdset) + return(DD_FALSE); + } + } return(DD_FALSE); */ } @@ -292,43 +292,43 @@ COMMAND_DO_WORK_APP(cl_help_cmd) matches= 0; for (i= 0; i < cmdset->count; i++) { - c= (class cl_cmd *)(cmdset->at(i)); - if (c->name_match(parm->value.string.string, DD_FALSE)) - matches++; + c= (class cl_cmd *)(cmdset->at(i)); + if (c->name_match(parm->value.string.string, DD_FALSE)) + matches++; } if (!matches) con->dd_printf("No such command\n"); else if (matches > 1) for (i= 0; i < cmdset->count; i++) - { - c= (class cl_cmd *)(cmdset->at(i)); - if (!c->name_match(parm->value.string.string, DD_FALSE)) - continue; - if (c->short_help) - con->dd_printf("%s\n", c->short_help); - else - con->dd_printf("%s\n", (char*)(c->names->at(0))); - } + { + c= (class cl_cmd *)(cmdset->at(i)); + if (!c->name_match(parm->value.string.string, DD_FALSE)) + continue; + if (c->short_help) + con->dd_printf("%s\n", c->short_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); + } else for (i= 0; i < cmdset->count; i++) - { - c= (class cl_cmd *)(cmdset->at(i)); - if (!c->name_match(parm->value.string.string, DD_FALSE)) - continue; - if (c->short_help) - con->dd_printf("%s\n", c->short_help); - else - con->dd_printf("%s\n", (char*)(c->names->at(0))); - int names; - con->dd_printf("Names of command:"); - for (names= 0; names < c->names->count; names++) - con->dd_printf(" %s", (char*)(c->names->at(names))); - con->dd_printf("\n"); - if (c->long_help) - con->dd_printf("%s\n", c->long_help); - else - con->dd_printf("%s\n", (char*)(c->names->at(0))); - } + { + c= (class cl_cmd *)(cmdset->at(i)); + if (!c->name_match(parm->value.string.string, DD_FALSE)) + continue; + if (c->short_help) + con->dd_printf("%s\n", c->short_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); + int names; + con->dd_printf("Names of command:"); + for (names= 0; names < c->names->count; names++) + con->dd_printf(" %s", (char*)(c->names->at(names))); + con->dd_printf("\n"); + if (c->long_help) + con->dd_printf("%s\n", c->long_help); + else + con->dd_printf("%s\n", (char*)(c->names->at(0))); + } } else con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax"); @@ -339,37 +339,37 @@ COMMAND_DO_WORK_APP(cl_help_cmd) bool cl_help_cmd::do_set(class cl_cmdline *cmdline, int pari, - class cl_cmdset *cmdset, - class cl_console *con) + class cl_cmdset *cmdset, + class cl_console_base *con) { int i; for (i= 0; i < cmdset->count; i++) { class cl_cmd *cmd= dynamic_cast(cmdset->object_at(i)); if (!cmd) - continue; + continue; if (pari >= cmdline->nuof_params()) - return(DD_FALSE); + return(DD_FALSE); class cl_cmd_arg *param= cmdline->param(pari); if (!param) - return(DD_FALSE); + return(DD_FALSE); class cl_cmdset *next_set= cmd->get_subcommands(); if (cmd->name_match(param->s_value, DD_FALSE)) - { - if (pari+1 >= cmdline->nuof_params()) - { - matches++; - cmd_found= cmd; - if (cmd->short_help) - con->dd_printf("%s\n", cmd->short_help); - else - con->dd_printf("%s\n", (char*)(cmd->names->at(0))); - //continue; - } - else - if (next_set) - do_set(cmdline, pari+1, next_set, con); - } + { + if (pari+1 >= cmdline->nuof_params()) + { + matches++; + cmd_found= cmd; + if (cmd->short_help) + con->dd_printf("%s\n", cmd->short_help); + else + con->dd_printf("%s\n", (char*)(cmd->names->at(0))); + //continue; + } + else + if (next_set) + do_set(cmdline, pari+1, next_set, con); + } } return(DD_TRUE); } @@ -382,7 +382,7 @@ cl_help_cmd::do_set(class cl_cmdline *cmdline, int pari, //int //cl_quit_cmd::do_work(class cl_sim *sim, -// class cl_cmdline */*cmdline*/, class cl_console */*con*/) +// class cl_cmdline */*cmdline*/, class cl_console_base */*con*/) COMMAND_DO_WORK(cl_quit_cmd) { return(1); @@ -396,7 +396,7 @@ COMMAND_DO_WORK(cl_quit_cmd) //int //cl_kill_cmd::do_work(class cl_sim *sim, -// class cl_cmdline */*cmdline*/, class cl_console */*con*/) +// class cl_cmdline */*cmdline*/, class cl_console_base */*con*/) COMMAND_DO_WORK_APP(cl_kill_cmd) { app->going= 0; @@ -421,8 +421,8 @@ COMMAND_DO_WORK_APP(cl_exec_cmd) else con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n"); - class cl_commander *c= app->get_commander(); - class cl_console *cons= con->clone_for_exec(fn); + class cl_commander_base *c= app->get_commander(); + class cl_console_base *cons= con->clone_for_exec(fn); if (cons) { cons->flags|= CONS_NOWELCOME; diff --git a/sim/ucsim/cmd.src/cmdsetcl.h b/sim/ucsim/cmd.src/cmdsetcl.h index 381c2cf7..4757eff9 100644 --- a/sim/ucsim/cmd.src/cmdsetcl.h +++ b/sim/ucsim/cmd.src/cmdsetcl.h @@ -46,7 +46,7 @@ COMMAND_METHODS_ON(app,cl_help_cmd) int matches; class cl_cmd *cmd_found; bool do_set(class cl_cmdline *cmdline, int pari, class cl_cmdset *cmdset, - class cl_console *con); + class cl_console_base *con); COMMAND_TAIL; COMMAND(cl_quit_cmd); diff --git a/sim/ucsim/cmd.src/cmdstat.cc b/sim/ucsim/cmd.src/cmdstat.cc index fbf5dd92..f3599839 100644 --- a/sim/ucsim/cmd.src/cmdstat.cc +++ b/sim/ucsim/cmd.src/cmdstat.cc @@ -45,7 +45,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA //int //cl_stat_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_statistic_cmd) { class cl_hw *hw; @@ -53,9 +53,9 @@ COMMAND_DO_WORK_UC(cl_statistic_cmd) t_addr start= 0, end= 0; bool addresses= DD_FALSE; class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; if (cmdline->syntax_match(uc, HW)) { hw= params[0]->value.hw; @@ -79,41 +79,41 @@ COMMAND_DO_WORK_UC(cl_statistic_cmd) } else { - /*con->dd_printf("Error: wrong syntax\n" - "%s\n", short_help?short_help:"no help");*/ - int i; - unsigned long wr, ww; - for (i= 0; i < uc->address_spaces->count; i++) - { - mem= (class cl_address_space *)(uc->address_spaces->at(i)); - wr= mem->get_nuof_reads(); - ww= mem->get_nuof_writes(); - con->dd_printf("%s writes= %10lu " - "reads= %10lu " - "(%10lu operations)\n", - mem->get_name("mem"), ww, wr, ww+wr); - } + /*con->dd_printf("Error: wrong syntax\n" + "%s\n", short_help?short_help:"no help");*/ + int i; + unsigned long wr, ww; + for (i= 0; i < uc->address_spaces->count; i++) + { + mem= (class cl_address_space *)(uc->address_spaces->at(i)); + wr= mem->get_nuof_reads(); + ww= mem->get_nuof_writes(); + con->dd_printf("%s writes= %10lu " + "reads= %10lu " + "(%10lu operations)\n", + mem->get_name("mem"), ww, wr, ww+wr); + } } if (mem) { - t_addr i; - unsigned long wr, ww; - wr= mem->get_nuof_reads(); - ww= mem->get_nuof_writes(); - if (!addresses) - con->dd_printf("%s writes= %10lu " - "reads= %10lu\n", mem->get_name("mem"), ww, wr); - else - for (i= start; i <= end; i++) - { - class cl_memory_cell *c= mem->get_cell(i); - unsigned long w= c->nuof_writes, r= c->nuof_reads; - double dr= wr?((double(r)*100.0)/double(wr)):0.0; - double dw= ww?((double(w)*100.0)/double(ww)):0.0; - con->dd_printf("%s[0x%06x] writes= %10lu (%6.2lf%%) " - "reads= %10lu (%6.2lf%%)\n", - mem->get_name("mem"), i, w, dw, r, dr); - } + t_addr i; + unsigned long wr, ww; + wr= mem->get_nuof_reads(); + ww= mem->get_nuof_writes(); + if (!addresses) + con->dd_printf("%s writes= %10lu " + "reads= %10lu\n", mem->get_name("mem"), ww, wr); + else + for (i= start; i <= end; i++) + { + class cl_memory_cell *c= mem->get_cell(i); + unsigned long w= c->nuof_writes, r= c->nuof_reads; + double dr= wr?((double(r)*100.0)/double(wr)):0.0; + double dw= ww?((double(w)*100.0)/double(ww)):0.0; + con->dd_printf("%s[0x%06x] writes= %10lu (%6.2lf%%) " + "reads= %10lu (%6.2lf%%)\n", + mem->get_name("mem"), i, w, dw, r, dr); + } } } diff --git a/sim/ucsim/cmd.src/cmduc.cc b/sim/ucsim/cmd.src/cmduc.cc index cb3aa557..02330e4f 100644 --- a/sim/ucsim/cmd.src/cmduc.cc +++ b/sim/ucsim/cmd.src/cmduc.cc @@ -43,29 +43,29 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA //int //cl_state_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_state_cmd) { con->dd_printf("CPU state= %s PC= 0x%06x XTAL= %g\n", - get_id_string(cpu_states, uc->state), - uc->PC, - uc->xtal); + get_id_string(cpu_states, uc->state), + uc->PC, + uc->xtal); con->dd_printf("Total time since last reset= %g sec (%lu clks)\n", - uc->get_rtime(), uc->ticks->ticks); + uc->get_rtime(), uc->ticks->ticks); con->dd_printf("Time in isr = %g sec (%lu clks) %3.2g%%\n", - uc->isr_ticks->get_rtime(uc->xtal), - uc->isr_ticks->ticks, - (uc->ticks->ticks == 0)?0.0: - (100.0*((double)(uc->isr_ticks->ticks)/ - (double)(uc->ticks->ticks)))); + uc->isr_ticks->get_rtime(uc->xtal), + uc->isr_ticks->ticks, + (uc->ticks->ticks == 0)?0.0: + (100.0*((double)(uc->isr_ticks->ticks)/ + (double)(uc->ticks->ticks)))); con->dd_printf("Time in idle= %g sec (%lu clks) %3.2g%%\n", - uc->idle_ticks->get_rtime(uc->xtal), - uc->idle_ticks->ticks, - (uc->ticks->ticks == 0)?0.0: - (100.0*((double)(uc->idle_ticks->ticks)/ - (double)(uc->ticks->ticks)))); + uc->idle_ticks->get_rtime(uc->xtal), + uc->idle_ticks->ticks, + (uc->ticks->ticks == 0)?0.0: + (100.0*((double)(uc->idle_ticks->ticks)/ + (double)(uc->ticks->ticks)))); con->dd_printf("Max value of stack pointer= 0x%06x, avg= 0x%06x\n", - uc->sp_max, uc->sp_avg); + uc->sp_max, uc->sp_avg); return(0); } @@ -77,7 +77,7 @@ COMMAND_DO_WORK_UC(cl_state_cmd) //int //cl_file_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_file_cmd) { char *fname= 0; @@ -103,7 +103,7 @@ COMMAND_DO_WORK_UC(cl_file_cmd) //int //cl_dl_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_dl_cmd) { long l; @@ -122,7 +122,7 @@ COMMAND_DO_WORK_UC(cl_dl_cmd) //int //cl_pc_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_pc_cmd) { t_addr addr; @@ -131,18 +131,18 @@ COMMAND_DO_WORK_UC(cl_pc_cmd) if (params[0]) { if (!(params[0]->get_address(uc, &addr))) - { - con->dd_printf("Error: wrong parameter\n"); - return(DD_FALSE); - } + { + con->dd_printf("Error: wrong parameter\n"); + return(DD_FALSE); + } class cl_address_space *rom= uc->address_space(MEM_ROM_ID); if (rom) - { - if (addr > rom->highest_valid_address()) - addr= rom->highest_valid_address(); - } + { + if (addr > rom->highest_valid_address()) + addr= rom->highest_valid_address(); + } if (!uc->inst_at(addr)) - con->dd_printf("Warning: maybe not instruction at 0x%06x\n", addr); + con->dd_printf("Warning: maybe not instruction at 0x%06x\n", addr); uc->PC= addr; } uc->print_disass(uc->PC, con); @@ -157,7 +157,7 @@ COMMAND_DO_WORK_UC(cl_pc_cmd) //int //cl_reset_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_reset_cmd) { uc->reset(); @@ -172,77 +172,77 @@ COMMAND_DO_WORK_UC(cl_reset_cmd) //int //cl_dump_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_dump_cmd) { class cl_memory *mem= 0; long bpl= 8; t_addr start= 0, end; class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; if (params[0] && params[0]->as_bit(uc)) { int i= 0; while (params[0] && - params[0]->as_bit(uc)) - { - t_mem m; - mem= params[0]->value.bit.mem; - m= mem->read(params[0]->value.bit.mem_address); - char *sn= - uc->symbolic_bit_name((t_addr)-1, - mem, - params[0]->value.bit.mem_address, - params[0]->value.bit.mask); - con->dd_printf("%10s ", sn?sn:""); - con->dd_printf(mem->addr_format, params[0]->value.bit.mem_address); - con->dd_printf(" "); - con->dd_printf(mem->data_format, m); - con->dd_printf(" %c\n", (m&(params[0]->value.bit.mask))?'1':'0'); - i++; - params[0]= cmdline->param(i); - } + params[0]->as_bit(uc)) + { + t_mem m; + mem= params[0]->value.bit.mem; + m= mem->read(params[0]->value.bit.mem_address); + char *sn= + uc->symbolic_bit_name((t_addr)-1, + mem, + params[0]->value.bit.mem_address, + params[0]->value.bit.mask); + con->dd_printf("%10s ", sn?sn:""); + con->dd_printf(mem->addr_format, params[0]->value.bit.mem_address); + con->dd_printf(" "); + con->dd_printf(mem->data_format, m); + con->dd_printf(" %c\n", (m&(params[0]->value.bit.mask))?'1':'0'); + i++; + params[0]= cmdline->param(i); + } if (params[0]) - con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n"); + con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n"); } else { if (!params[0] || - !params[0]->as_memory(uc)) - { - con->dd_printf("No memory specified. Use \"info memory\" for available memories\n"); - return(DD_FALSE); - } + !params[0]->as_memory(uc)) + { + con->dd_printf("No memory specified. Use \"info memory\" for available memories\n"); + return(DD_FALSE); + } if (cmdline->syntax_match(uc, MEMORY)) - { - mem= params[0]->value.memory.memory; - mem->dump(con); - } + { + mem= params[0]->value.memory.memory; + mem->dump(con); + } else if (cmdline->syntax_match(uc, MEMORY ADDRESS)) { - mem = params[0]->value.memory.memory; - start= params[1]->value.address; - end = start+10*8-1; - mem->dump(start, end, bpl, con); + mem = params[0]->value.memory.memory; + start= params[1]->value.address; + end = start+10*8-1; + mem->dump(start, end, bpl, con); } else if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS)) { - mem = params[0]->value.memory.memory; - start= params[1]->value.address; - end = params[2]->value.address; - mem->dump(start, end, bpl, con); + mem = params[0]->value.memory.memory; + start= params[1]->value.address; + end = params[2]->value.address; + mem->dump(start, end, bpl, con); } else if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS NUMBER)) { - mem = params[0]->value.memory.memory; - start= params[1]->value.address; - end = params[2]->value.address; - bpl = params[3]->value.number; - mem->dump(start, end, bpl, con); + mem = params[0]->value.memory.memory; + start= params[1]->value.address; + end = params[2]->value.address; + bpl = params[3]->value.number; + mem->dump(start, end, bpl, con); } else - con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n"); + con->dd_printf("%s\n", short_help?short_help:"Error: wrong syntax\n"); } return(DD_FALSE);; @@ -256,7 +256,7 @@ COMMAND_DO_WORK_UC(cl_dump_cmd) //int //cl_di_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_di_cmd) { cmdline->insert_param(0, new cl_cmd_sym_arg("iram")); @@ -272,7 +272,7 @@ COMMAND_DO_WORK_UC(cl_di_cmd) //int //cl_dx_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_dx_cmd) { cmdline->insert_param(0, new cl_cmd_sym_arg("xram")); @@ -288,7 +288,7 @@ COMMAND_DO_WORK_UC(cl_dx_cmd) //int //cl_dch_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_dch_cmd) { cmdline->insert_param(0, new cl_cmd_sym_arg("rom")); @@ -304,7 +304,7 @@ COMMAND_DO_WORK_UC(cl_dch_cmd) //int //cl_ds_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_ds_cmd) { cmdline->insert_param(0, new cl_cmd_sym_arg("sfr")); @@ -320,12 +320,12 @@ COMMAND_DO_WORK_UC(cl_ds_cmd) //int //cl_dc_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_dc_cmd) { t_addr start= last, end= last+20; class cl_cmd_arg *params[2]= { cmdline->param(0), - cmdline->param(1) }; + cmdline->param(1) }; class cl_address_space *rom= uc->address_space(MEM_ROM_ID); if (!rom) @@ -369,15 +369,15 @@ static int disass_last_stop= 0; //int //cl_disassemble_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_disassemble_cmd) { t_addr start, realstart; int offset= -1, dir, lines= 20; class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; start= disass_last_stop; if (params[0] == 0) ; @@ -411,18 +411,18 @@ COMMAND_DO_WORK_UC(cl_disassemble_cmd) if (!rom) return(DD_FALSE); while (realstart <= rom->highest_valid_address() && - !uc->inst_at(realstart)) + !uc->inst_at(realstart)) realstart= realstart+1; if (offset) { dir= (offset < 0)?-1:+1; while (offset) - { - realstart= rom->inc_address(realstart, dir); - while (!uc->inst_at(realstart)) - realstart= rom->inc_address(realstart, dir); - offset+= -dir; - } + { + realstart= rom->inc_address(realstart, dir); + while (!uc->inst_at(realstart)) + realstart= rom->inc_address(realstart, dir); + offset+= -dir; + } } while (lines) @@ -430,7 +430,7 @@ COMMAND_DO_WORK_UC(cl_disassemble_cmd) uc->print_disass(realstart, con); realstart= rom->inc_address(realstart, +1) + rom->start_address; while (!uc->inst_at(realstart)) - realstart= rom->inc_address(realstart, +1) + rom->start_address; + realstart= rom->inc_address(realstart, +1) + rom->start_address; lines--; } @@ -447,16 +447,16 @@ COMMAND_DO_WORK_UC(cl_disassemble_cmd) //int //cl_fill_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_fill_cmd) { class cl_memory *mem= 0; t_mem what= 0; t_addr start= 0, end; class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS NUMBER)) { mem = params[0]->value.memory.memory; @@ -466,9 +466,9 @@ COMMAND_DO_WORK_UC(cl_fill_cmd) t_addr i; for (i= start; i <= end; i++) { - t_mem d; - d= what; - mem->write(i, d); + t_mem d; + d= what; + mem->write(i, d); } } else @@ -485,12 +485,12 @@ COMMAND_DO_WORK_UC(cl_fill_cmd) int cl_where_cmd::do_real_work(class cl_uc *uc, - class cl_cmdline *cmdline, class cl_console *con, - bool case_sensitive) + class cl_cmdline *cmdline, class cl_console_base *con, + bool case_sensitive) { class cl_memory *mem= 0; class cl_cmd_arg *params[2]= { cmdline->param(0), - cmdline->param(1) }; + cmdline->param(1) }; if (cmdline->syntax_match(uc, MEMORY DATALIST)) { mem= params[0]->value.memory.memory; @@ -498,16 +498,16 @@ cl_where_cmd::do_real_work(class cl_uc *uc, int len= params[1]->value.data_list.len; if (!len) { - con->dd_printf("Error: nothing to search for\n"); - return(DD_FALSE); + con->dd_printf("Error: nothing to search for\n"); + return(DD_FALSE); } t_addr addr= 0; bool found= mem->search_next(case_sensitive, array, len, &addr); while (found) { - mem->dump(addr, addr+len-1, 8, con); - addr++; - found= mem->search_next(case_sensitive, array, len, &addr); + mem->dump(addr, addr+len-1, 8, con); + addr++; + found= mem->search_next(case_sensitive, array, len, &addr); } } else @@ -518,7 +518,7 @@ cl_where_cmd::do_real_work(class cl_uc *uc, //int //cl_where_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_where_cmd) { return(do_real_work(uc, cmdline, con, DD_FALSE)); @@ -526,7 +526,7 @@ COMMAND_DO_WORK_UC(cl_where_cmd) //int //cl_Where_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_Where_cmd) { return(do_real_work(uc, cmdline, con, DD_TRUE)); diff --git a/sim/ucsim/cmd.src/cmduccl.h b/sim/ucsim/cmd.src/cmduccl.h index 8b7012f7..94f1ae68 100644 --- a/sim/ucsim/cmd.src/cmduccl.h +++ b/sim/ucsim/cmd.src/cmduccl.h @@ -47,8 +47,8 @@ COMMAND_HEAD(cl_where_cmd) public: int last; COMMAND_METHODS_ON(uc,cl_where_cmd) virtual int do_real_work(class cl_uc *uc, - class cl_cmdline *cmdline, class cl_console *con, - bool case_sensitive); + class cl_cmdline *cmdline, class cl_console_base *con, + bool case_sensitive); COMMAND_TAIL; COMMAND_DATA_ANCESTOR_ON(uc,cl_Where_cmd,cl_where_cmd,int last); diff --git a/sim/ucsim/cmd.src/cmdutil.cc b/sim/ucsim/cmd.src/cmdutil.cc index 977068fc..c6820e9b 100644 --- a/sim/ucsim/cmd.src/cmdutil.cc +++ b/sim/ucsim/cmd.src/cmdutil.cc @@ -2,7 +2,8 @@ * Simulator of microcontrollers (cmd.src/cmdutil.cc) * * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. - * + * Copyright (C) 2006, Borut Razem - borut.razem@siol.net + * * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * */ @@ -30,6 +31,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include +#include #include #ifdef SOCKET_AVAIL # include HEADER_SOCKET @@ -38,11 +40,16 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA # include # endif #endif +#ifdef _WIN32 +#include +#endif + #include "i_string.h" #include "stypes.h" #include "globals.h" #include "uccl.h" +#include "cmdutil.h" /* @@ -50,12 +57,59 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA */ #ifdef SOCKET_AVAIL +#ifdef _WIN32 +static void +init_winsock(void) +{ + static bool is_initialized = false; + + if (!is_initialized) + { + WSADATA wsaData; + + // Initialize Winsock + int iResult = WSAStartup(MAKEWORD(2,2), &wsaData); + if (iResult != 0) + { + printf("WSAStartup failed: %d\n", iResult); + exit(1); + } + } +} + +SOCKET +make_server_socket(unsigned short int port) +{ + init_winsock(); + + struct sockaddr_in name; + + /* Create the socket. */ + SOCKET sock = WSASocket(PF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0); + if (INVALID_SOCKET == sock) + { + fprintf(stderr, "socket: %d\n", WSAGetLastError()); + return INVALID_SOCKET; + } + + name.sin_family = AF_INET; + name.sin_port = htons(port); + name.sin_addr.s_addr= htonl(INADDR_ANY); + if (SOCKET_ERROR == bind(sock, (struct sockaddr *)&name, sizeof(name))) + { + fprintf(stderr, "bind: %d\n", WSAGetLastError()); + return INVALID_SOCKET; + } + + return sock; +} +#else int make_server_socket(unsigned short int port) { int sock, i; struct sockaddr_in name; - + /* Create the socket. */ sock= socket(PF_INET, SOCK_STREAM, 0); if (sock < 0) @@ -63,7 +117,7 @@ make_server_socket(unsigned short int port) perror("socket"); return(0); } - + /* Give the socket a name. */ i= 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&i, sizeof(i)) < 0) @@ -82,25 +136,142 @@ make_server_socket(unsigned short int port) return(sock); } #endif +#endif +#if _WIN32 +enum e_handle_type +get_handle_type(HANDLE handle) +{ + DWORD file_type = GetFileType(handle); -/* - * Printing out an integer in binary format - */ + switch (file_type) + { + case FILE_TYPE_CHAR: + { + DWORD err; + + if (!ClearCommError(handle, &err, NULL)) + { + if (ERROR_INVALID_HANDLE == GetLastError()) + return CH_CONSOLE; + } + } + return CH_SERIAL; + + case FILE_TYPE_DISK: + return CH_FILE; + } + + char sockbuf[256]; + int optlen = sizeof(sockbuf); -/*void -print_bin(long data, int bits, class cl_console *con) + if (SOCKET_ERROR != getsockopt((SOCKET)handle, SOL_SOCKET, SO_TYPE, sockbuf, &optlen) || + WSAENOTSOCK != WSAGetLastError()) + return CH_SOCKET; + + assert(false); + return CH_UNDEF; +} + +bool +input_avail(HANDLE handle, e_handle_type type) { - long mask= 1; + if (CH_UNDEF == type) + type = get_handle_type(handle); - mask= mask << ((bits >= 1)?(bits-1):0); - while (bits--) + switch (type) { - con->printf("%c", (data&mask)?'1':'0'); - mask>>= 1; + case CH_SOCKET: + { + struct timeval tv = {0, 0}; + + assert(INVALID_HANDLE_VALUE != handle); + + fd_set s; + FD_ZERO(&s); + FD_SET((SOCKET)handle, &s); + + int ret = select(0, &s, NULL, NULL, &tv); + if (SOCKET_ERROR == ret) + fprintf(stderr, "Can't select: %d\n", WSAGetLastError()); + + return ret != SOCKET_ERROR && ret != 0; + } + + case CH_FILE: + return true; + + case CH_CONSOLE: + { + PINPUT_RECORD pIRBuf; + DWORD NumPending; + DWORD NumPeeked; + + /* + * Peek all pending console events + */ + if (INVALID_HANDLE_VALUE == handle || + !GetNumberOfConsoleInputEvents(handle, &NumPending) || + NumPending == 0 || + NULL == (pIRBuf = (PINPUT_RECORD)_alloca(NumPending * sizeof(INPUT_RECORD)))) + return FALSE; + + if (PeekConsoleInput(handle, pIRBuf, NumPending, &NumPeeked) && + NumPeeked != 0L && + NumPeeked <= NumPending) + { + + /* + * Scan all of the peeked events to determine if any is a key event + * which should be recognized. + */ + for ( ; NumPeeked > 0 ; NumPeeked--, pIRBuf++ ) + { + if (KEY_EVENT == pIRBuf->EventType && + pIRBuf->Event.KeyEvent.bKeyDown && + pIRBuf->Event.KeyEvent.uChar.AsciiChar) + return true; + } + } + + return false; + } + + case CH_SERIAL: + { + DWORD err; + COMSTAT comStat; + + bool res = ClearCommError(handle, &err, &comStat); + assert(res); + + return res ? comStat.cbInQue > 0 : false; + } + + default: + assert(false); + return false; } -}*/ +} +#else +bool +input_avail(UCSOCKET_T fd) +{ + assert(0 <= fd); + + fd_set s; + FD_ZERO(&s); + FD_SET(fd, &s); + + struct timeval tv = {0, 0}; + int i = select(fd + 1, &s, NULL, NULL, &tv); + if (i < 0) + perror("select"); + + return i > 0; +} +#endif /* * Searching for a name in the specified table @@ -145,7 +316,7 @@ interpret_bitname(char *name, class cl_uc *uc, char *sym, bitnumstr[2]; struct name_entry *ne; int bitnum, i; - + if ((dot= strchr(name, '.')) != NULL) { *dot++= '\0'; diff --git a/sim/ucsim/cmd.src/cmdutil.h b/sim/ucsim/cmd.src/cmdutil.h index f80db39a..09ade8d2 100644 --- a/sim/ucsim/cmd.src/cmdutil.h +++ b/sim/ucsim/cmd.src/cmdutil.h @@ -2,7 +2,8 @@ * Simulator of microcontrollers (cmd.src/cmdutil.h) * * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. - * + * Copyright (C) 2006, Borut Razem - borut.razem@siol.net + * * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * */ @@ -28,13 +29,25 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #ifndef CMD_CMDUTIL_HEADER #define CMD_CMDUTIL_HEADER +#ifdef SOCKET_AVAIL +# include HEADER_SOCKET +#endif + #include "ddconfig.h" #include "uccl.h" - -extern int make_server_socket(unsigned short int port); -//extern void print_bin(long data, int bits, class cl_console *con); +#ifdef SOCKET_AVAIL +extern UCSOCKET_T make_server_socket(unsigned short int port); +#endif +#ifdef _WIN32 +enum e_handle_type { CH_UNDEF, CH_FILE, CH_SOCKET, CH_CONSOLE, CH_SERIAL,}; +enum e_handle_type get_handle_type(HANDLE handle); +bool input_avail(HANDLE handle, e_handle_type type = CH_UNDEF); +#else +bool input_avail(UCSOCKET_T handle); +#endif +//extern void print_bin(long data, int bits, class cl_console_base *con); extern struct name_entry *get_name_entry(struct name_entry tabl[], char *name, class cl_uc *uc); diff --git a/sim/ucsim/cmd.src/command.cc b/sim/ucsim/cmd.src/command.cc index 6d96129e..cdd40a58 100644 --- a/sim/ucsim/cmd.src/command.cc +++ b/sim/ucsim/cmd.src/command.cc @@ -42,7 +42,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA */ cl_cmdline::cl_cmdline(class cl_app *the_app, - char *acmd, class cl_console *acon): + char *acmd, class cl_console_base *acon): cl_base() { app= the_app; @@ -73,7 +73,7 @@ char * cl_cmdline::skip_delims(char *start) { while (*start && - strchr(" \t\v\r,", *start)) + strchr(" \t\v\r,", *start)) start++; return(start); } @@ -117,37 +117,37 @@ cl_cmdline::split(void) { char *end= start, *param_str; if (*start == '"') - split_out_string(&start, &end); + split_out_string(&start, &end); else if (*start == '>') - split_out_output_redirection(&start, &end); + split_out_output_redirection(&start, &end); else - { - char *dot; + { + char *dot; i= strcspn(start, " \t\v\r,"); end= start+i; param_str= (char *)malloc(i+1); strncpy(param_str, start, i); - param_str[i]= '\0'; - tokens->add(strdup(param_str)); - if ((dot= strchr(param_str, '.')) != NULL) - split_out_bit(dot, param_str); - else if ((dot= strchr(param_str, '[')) != NULL) - split_out_array(dot, param_str); - else if (strchr("0123456789-+", *param_str) != NULL) - { - // number - params->add(arg= new cl_cmd_int_arg((long) - strtol(param_str, 0, 0))); - arg->init(); - } - else - { - // symbol - params->add(arg= new cl_cmd_sym_arg(param_str)); - arg->init(); - } - free(param_str); - } + param_str[i]= '\0'; + tokens->add(strdup(param_str)); + if ((dot= strchr(param_str, '.')) != NULL) + split_out_bit(dot, param_str); + else if ((dot= strchr(param_str, '[')) != NULL) + split_out_array(dot, param_str); + else if (strchr("0123456789-+", *param_str) != NULL) + { + // number + params->add(arg= new cl_cmd_int_arg((long) + strtol(param_str, 0, 0))); + arg->init(); + } + else + { + // symbol + params->add(arg= new cl_cmd_sym_arg(param_str)); + arg->init(); + } + free(param_str); + } start= end; start= skip_delims(start); } @@ -329,8 +329,8 @@ cl_cmdline::shift(void) if (s && *s) { while (*s && - strchr(" \t\v\r,", *s) == NULL) - s++; + strchr(" \t\v\r,", *s) == NULL) + s++; s= skip_delims(s); char *p= strdup(s); free(cmd); @@ -339,7 +339,7 @@ cl_cmdline::shift(void) params= new cl_list(2, 2, "params"); split(); if (strcmp(get_name(), "\n") == 0) - set_name(0); + set_name(0); } return(have_real_name()); } @@ -349,7 +349,7 @@ cl_cmdline::repeat(void) { char *n; return((n= get_name()) && - *n == '\n'); + *n == '\n'); } class cl_cmd_arg * @@ -387,59 +387,59 @@ cl_cmdline::syntax_match(class cl_uc *uc, char *syntax) int iparam= 0; class cl_cmd_arg *parm= (class cl_cmd_arg *)(params->at(iparam)); while (*p && - parm) + parm) { //printf("***Checking %s as %c\n",parm->get_svalue(),*p); if (uc) - switch (*p) - { - case SY_ADDR: - if (!parm->as_address(uc)) - return(DD_FALSE); - //printf("ADDRESS match %lx\n",parm->value.address); - break; - case SY_MEMORY: - if (!parm->as_memory(uc)) - return(DD_FALSE); - //printf("MEMORY match %s\n",parm->value.memory->class_name); - break; - case SY_BIT: - if (!parm->as_bit(uc)) - return(DD_FALSE); - break; - } + switch (*p) + { + case SY_ADDR: + if (!parm->as_address(uc)) + return(DD_FALSE); + //printf("ADDRESS match %lx\n",parm->value.address); + break; + case SY_MEMORY: + if (!parm->as_memory(uc)) + return(DD_FALSE); + //printf("MEMORY match %s\n",parm->value.memory->class_name); + break; + case SY_BIT: + if (!parm->as_bit(uc)) + return(DD_FALSE); + break; + } switch (*p) - { - case SY_ADDR: case SY_MEMORY: case SY_BIT: break; - case SY_NUMBER: - if (!parm->as_number()) - return(DD_FALSE); - break; - case SY_DATA: - if (!parm->as_data()) - return(DD_FALSE); - break; - case SY_HW: - if (!parm->as_hw(uc)) - return(DD_FALSE); - break; - case SY_STRING: - if (!parm->as_string()) - return(DD_FALSE); - break; - case SY_DATALIST: - if (!set_data_list(parm, &iparam)) - return(DD_FALSE); - break; - default: - return(DD_FALSE); - } + { + case SY_ADDR: case SY_MEMORY: case SY_BIT: break; + case SY_NUMBER: + if (!parm->as_number()) + return(DD_FALSE); + break; + case SY_DATA: + if (!parm->as_data()) + return(DD_FALSE); + break; + case SY_HW: + if (!parm->as_hw(uc)) + return(DD_FALSE); + break; + case SY_STRING: + if (!parm->as_string()) + return(DD_FALSE); + break; + case SY_DATALIST: + if (!set_data_list(parm, &iparam)) + return(DD_FALSE); + break; + default: + return(DD_FALSE); + } p++; iparam++; if (iparam < params->count) - parm= (class cl_cmd_arg *)(params->at(iparam)); + parm= (class cl_cmd_arg *)(params->at(iparam)); else - parm= 0; + parm= 0; } if (!*p && !parm) @@ -462,41 +462,41 @@ cl_cmdline::set_data_list(class cl_cmd_arg *parm, int *iparm) for (i= *iparm, next_parm= param(i); next_parm; i++, next_parm= param(i)) { if (next_parm->is_string()) - { - int l; - char *s; - //s= proc_escape(next_parm->get_svalue(), &l); - if (!next_parm->as_string()) - continue; - s= next_parm->value.string.string; - l= next_parm->value.string.len; - if (!array) - array= (t_mem*)malloc(sizeof(t_mem)*l); - else - array= (t_mem*)realloc(array, sizeof(t_mem)*(l+len)); - for (j= 0; j < l; j++) - { - array[len]= s[j]; - len++; - } - //if (s) - //free(s); - } + { + int l; + char *s; + //s= proc_escape(next_parm->get_svalue(), &l); + if (!next_parm->as_string()) + continue; + s= next_parm->value.string.string; + l= next_parm->value.string.len; + if (!array) + array= (t_mem*)malloc(sizeof(t_mem)*l); + else + array= (t_mem*)realloc(array, sizeof(t_mem)*(l+len)); + for (j= 0; j < l; j++) + { + array[len]= s[j]; + len++; + } + //if (s) + //free(s); + } else - { - if (!next_parm->as_data()) - { - if (array) - free(array); - return(DD_FALSE); - } - if (!array) - array= (t_mem*)malloc(sizeof(t_mem)); - else - array= (t_mem*)realloc(array, sizeof(t_mem)*(1+len)); - array[len]= next_parm->value.data; - len++; - } + { + if (!next_parm->as_data()) + { + if (array) + free(array); + return(DD_FALSE); + } + if (!array) + array= (t_mem*)malloc(sizeof(t_mem)); + else + array= (t_mem*)realloc(array, sizeof(t_mem)*(1+len)); + array[len]= next_parm->value.data; + len++; + } } *iparm= i; parm->value.data_list.array= array; @@ -511,10 +511,10 @@ cl_cmdline::set_data_list(class cl_cmd_arg *parm, int *iparm) */ cl_cmd::cl_cmd(enum cmd_operate_on op_on, - char *aname, - int can_rep, - char *short_hlp, - char *long_hlp): + char *aname, + int can_rep, + char *short_hlp, + char *long_hlp): cl_base() { operate_on= op_on; @@ -562,20 +562,20 @@ cl_cmd::name_match(char *aname, int strict) if (strict) { for (i= 0; i < names->count; i++) - { - char *n= (char*)(names->at(i)); - if (strcmp(aname, n) == 0) - return(1); - } + { + char *n= (char*)(names->at(i)); + if (strcmp(aname, n) == 0) + return(1); + } } else { for (i= 0; i < names->count; i++) - { - char *n= (char*)(names->at(i)); - if (strstr(n, aname) == n) - return(1); - } + { + char *n= (char*)(names->at(i)); + if (strstr(n, aname) == n) + return(1); + } } return(0); } @@ -594,7 +594,7 @@ cl_cmd::syntax_ok(class cl_cmdline *cmdline) int cl_cmd::work(class cl_app *app, - class cl_cmdline *cmdline, class cl_console *con) + class cl_cmdline *cmdline, class cl_console_base *con) { if (!syntax_ok(cmdline)) return(0); @@ -606,24 +606,24 @@ cl_cmd::work(class cl_app *app, { case operate_on_app: if (!app) - { - con->dd_printf("There is no application to work on!\n"); - return(DD_TRUE); - } + { + con->dd_printf("There is no application to work on!\n"); + return(DD_TRUE); + } return(do_work(app, cmdline, con)); case operate_on_sim: if (!sim) - { - con->dd_printf("There is no simulator to work on!\n"); - return(DD_TRUE); - } + { + con->dd_printf("There is no simulator to work on!\n"); + return(DD_TRUE); + } return(do_work(sim, cmdline, con)); case operate_on_uc: if (!sim) - { - con->dd_printf("There is no microcontroller to work on!\n"); - return(DD_TRUE); - } + { + con->dd_printf("There is no microcontroller to work on!\n"); + return(DD_TRUE); + } return(do_work(uc, cmdline, con)); default: return(do_work(cmdline, con)); @@ -631,37 +631,37 @@ cl_cmd::work(class cl_app *app, } int -cl_cmd::do_work(class cl_cmdline *cmdline, class cl_console *con) +cl_cmd::do_work(class cl_cmdline *cmdline, class cl_console_base *con) { con->dd_printf("Command \"%s\" does nothing.\n", - (char*)(names->at(0))); + (char*)(names->at(0))); return(0); } int cl_cmd::do_work(class cl_app *app, - class cl_cmdline *cmdline, class cl_console *con) + class cl_cmdline *cmdline, class cl_console_base *con) { con->dd_printf("Command \"%s\" does nothing on application.\n", - (char*)(names->at(0))); + (char*)(names->at(0))); return(0); } int cl_cmd::do_work(class cl_sim *sim, - class cl_cmdline *cmdline, class cl_console *con) + class cl_cmdline *cmdline, class cl_console_base *con) { con->dd_printf("Command \"%s\" does nothing on simulator.\n", - (char*)(names->at(0))); + (char*)(names->at(0))); return(0); } int cl_cmd::do_work(class cl_uc *uc, - class cl_cmdline *cmdline, class cl_console *con) + class cl_cmdline *cmdline, class cl_console_base *con) { con->dd_printf("Command \"%s\" does nothing on microcontroller.\n", - (char*)(names->at(0))); + (char*)(names->at(0))); return(0); } @@ -695,7 +695,7 @@ cl_cmdset::get_cmd(class cl_cmdline *cmdline, bool accept_last) { class cl_cmd *c= (class cl_cmd *)at(i); if (c->name_match(cmdline, 1)) - return(c); + return(c); } // not exact match class cl_cmd *c_matched= 0; @@ -703,12 +703,12 @@ cl_cmdset::get_cmd(class cl_cmdline *cmdline, bool accept_last) { class cl_cmd *c= (class cl_cmd *)at(i); if (c->name_match(cmdline, 0)) - { - if (!c_matched) - c_matched= c; - else - return(0); - } + { + if (!c_matched) + c_matched= c; + else + return(0); + } } return(c_matched); //return(0); @@ -723,7 +723,7 @@ cl_cmdset::get_cmd(char *cmd_name) { class cl_cmd *c= (class cl_cmd *)at(i); if (c->name_match(cmd_name, 1)) - return(c); + return(c); } return(0); } @@ -739,7 +739,7 @@ cl_cmdset::del(char *nam) { class cl_cmd *cmd= (class cl_cmd *)(at(i)); if (cmd->name_match(nam, 1)) - free_at(i); + free_at(i); } } @@ -754,10 +754,10 @@ cl_cmdset::replace(char *nam, class cl_cmd *cmd) { class cl_cmd *c= (class cl_cmd *)(at(i)); if (c->name_match(nam, 1)) - { - delete c; - put_at(i, cmd); - } + { + delete c; + put_at(i, cmd); + } } } @@ -768,10 +768,10 @@ cl_cmdset::replace(char *nam, class cl_cmd *cmd) */ cl_super_cmd::cl_super_cmd(char *aname, - int can_rep, - char *short_hlp, - char *long_hlp, - class cl_cmdset *acommands): + int can_rep, + char *short_hlp, + char *long_hlp, + class cl_cmdset *acommands): cl_cmd(operate_on_none, aname, can_rep, short_hlp, long_hlp) { commands= acommands; @@ -785,7 +785,7 @@ cl_super_cmd::~cl_super_cmd(void) int cl_super_cmd::work(class cl_app *app, - class cl_cmdline *cmdline, class cl_console *con) + class cl_cmdline *cmdline, class cl_console_base *con) { class cl_cmd *cmd= 0; @@ -795,21 +795,21 @@ cl_super_cmd::work(class cl_app *app, if (!cmdline->shift()) { if ((cmd= commands->get_cmd("_no_parameters_")) != 0) - return(cmd->work(app, cmdline, con)); + return(cmd->work(app, cmdline, con)); int i; con->dd_printf("\"%s\" must be followed by the name of a subcommand\n" - "List of subcommands:\n", (char*)(names->at(0))); + "List of subcommands:\n", (char*)(names->at(0))); for (i= 0; i < commands->count; i++) - { - cmd= (class cl_cmd *)(commands->at(i)); - con->dd_printf("%s\n", cmd->short_help); - } + { + cmd= (class cl_cmd *)(commands->at(i)); + con->dd_printf("%s\n", cmd->short_help); + } return(0); } if ((cmd= commands->get_cmd(cmdline, con->accept_last())) == NULL) { con->dd_printf("Undefined subcommand: \"%s\". Try \"help %s\".\n", - cmdline->get_name(), (char*)(names->at(0))); + cmdline->get_name(), (char*)(names->at(0))); return(0); } return(cmd->work(app, cmdline, con)); diff --git a/sim/ucsim/cmd.src/commandcl.h b/sim/ucsim/cmd.src/commandcl.h index 36dc7767..7a3a332a 100644 --- a/sim/ucsim/cmd.src/commandcl.h +++ b/sim/ucsim/cmd.src/commandcl.h @@ -58,10 +58,10 @@ public: class cl_list *params; class cl_ustrings *tokens; char *matched_syntax; - class cl_console *con; + class cl_console_base *con; public: - cl_cmdline(class cl_app *the_app, char *acmd, class cl_console *acon); + cl_cmdline(class cl_app *the_app, char *acmd, class cl_console_base *acon); virtual ~cl_cmdline(void); virtual int init(void); @@ -102,10 +102,10 @@ public: public: cl_cmd(enum cmd_operate_on opon, - char *aname, - int can_rep, - char *short_hlp, - char *long_hlp); + char *aname, + int can_rep, + char *short_hlp, + char *long_hlp); virtual ~cl_cmd(void); virtual class cl_cmdset *get_subcommands(void) { return(0); } @@ -114,14 +114,14 @@ public: virtual int name_match(class cl_cmdline *cmdline, int strict); virtual int syntax_ok(class cl_cmdline *cmdline); virtual int work(class cl_app *app, - class cl_cmdline *cmdline, class cl_console *con); - virtual int do_work(class cl_cmdline *cmdline, class cl_console *con); + class cl_cmdline *cmdline, class cl_console_base *con); + virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con); virtual int do_work(class cl_app *app, - class cl_cmdline *cmdline, class cl_console *con); + class cl_cmdline *cmdline, class cl_console_base *con); virtual int do_work(class cl_sim *sim, - class cl_cmdline *cmdline, class cl_console *con); + class cl_cmdline *cmdline, class cl_console_base *con); virtual int do_work(class cl_uc *uc, - class cl_cmdline *cmdline, class cl_console *con); + class cl_cmdline *cmdline, class cl_console_base *con); }; #define COMMAND_HEAD(CLASS_NAME) \ @@ -138,7 +138,7 @@ public:\ char *short_help,\ char *long_help):\ cl_cmd(operate_on_none, aname, can_rep, short_help, long_help) {}\ - virtual int do_work(class cl_cmdline *cmdline, class cl_console *con); + virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con); #define COMMAND_METHODS_ON(ON,CLASS_NAME) \ public:\ @@ -148,7 +148,7 @@ public:\ char *long_help):\ cl_cmd(operate_on_ ## ON, aname, can_rep, short_help, long_help) {}\ virtual int do_work(class cl_ ## ON * ON ,\ - class cl_cmdline *cmdline, class cl_console *con); + class cl_cmdline *cmdline, class cl_console_base *con); #define COMMAND_METHODS_ANCESTOR(CLASS_NAME,ANCESTOR) \ public:\ @@ -157,7 +157,7 @@ public:\ char *short_help,\ char *long_help):\ ANCESTOR (aname, can_rep, short_help, long_help) {}\ - virtual int do_work(class cl_cmdline *cmdline, class cl_console *con); + virtual int do_work(class cl_cmdline *cmdline, class cl_console_base *con); #define COMMAND_METHODS_ANCESTOR_ON(ON,CLASS_NAME,ANCESTOR) \ public:\ @@ -167,7 +167,7 @@ public:\ char *long_help):\ ANCESTOR (aname, can_rep, short_help, long_help) {}\ virtual int do_work(class cl_ ## ON * ON ,\ - class cl_cmdline *cmdline, class cl_console *con); \ + class cl_cmdline *cmdline, class cl_console_base *con); \ #define COMMAND_TAIL } @@ -213,19 +213,19 @@ COMMAND_TAIL #define COMMAND_DO_WORK(CLASS_NAME) \ int \ -CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console *con) +CLASS_NAME::do_work(class cl_cmdline *cmdline, class cl_console_base *con) #define COMMAND_DO_WORK_APP(CLASS_NAME) \ int \ CLASS_NAME::do_work(class cl_app *app,\ - class cl_cmdline *cmdline, class cl_console *con) + class cl_cmdline *cmdline, class cl_console_base *con) #define COMMAND_DO_WORK_SIM(CLASS_NAME) \ int \ CLASS_NAME::do_work(class cl_sim *sim,\ - class cl_cmdline *cmdline, class cl_console *con) + class cl_cmdline *cmdline, class cl_console_base *con) #define COMMAND_DO_WORK_UC(CLASS_NAME) \ int \ CLASS_NAME::do_work(class cl_uc *uc,\ - class cl_cmdline *cmdline, class cl_console *con) + class cl_cmdline *cmdline, class cl_console_base *con) // Command set is list of cl_cmd objects class cl_cmdset: public cl_list @@ -252,15 +252,15 @@ public: public: cl_super_cmd(char *aname, - int can_rep, - char *short_hlp, - char *long_hlp, - class cl_cmdset *acommands); + int can_rep, + char *short_hlp, + char *long_hlp, + class cl_cmdset *acommands); virtual ~cl_super_cmd(void); virtual class cl_cmdset *get_subcommands(void) { return(commands); } virtual int work(class cl_app *app, - class cl_cmdline *cmdline, class cl_console *con); + class cl_cmdline *cmdline, class cl_console_base *con); }; diff --git a/sim/ucsim/cmd.src/get.cc b/sim/ucsim/cmd.src/get.cc index d16f892d..fe6d4c46 100644 --- a/sim/ucsim/cmd.src/get.cc +++ b/sim/ucsim/cmd.src/get.cc @@ -2,7 +2,7 @@ * Simulator of microcontrollers (cmd.src/get.cc) * * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. - * + * * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * */ @@ -50,7 +50,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA //int //cl_get_sfr_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_get_sfr_cmd) { class cl_address_space *mem= uc->address_space(MEM_SFR_ID); @@ -67,11 +67,11 @@ COMMAND_DO_WORK_UC(cl_get_sfr_cmd) i++, parm= cmdline->param(i)) { if (!parm->as_address(uc) || - !mem->valid_address(parm->value.address)) - con->dd_printf("Warning: Invalid address %s\n", - (char*)cmdline->tokens->at(i+1)); + !mem->valid_address(parm->value.address)) + con->dd_printf("Warning: Invalid address %s\n", + (char*)cmdline->tokens->at(i+1)); else - mem->dump(parm->value.address, parm->value.address, 1, con); + mem->dump(parm->value.address, parm->value.address, 1, con); } return(DD_FALSE);; @@ -85,7 +85,7 @@ COMMAND_DO_WORK_UC(cl_get_sfr_cmd) //int //cl_get_option_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_APP(cl_get_option_cmd) { class cl_cmd_arg *parm= cmdline->param(0); @@ -104,25 +104,25 @@ COMMAND_DO_WORK_APP(cl_get_option_cmd) { class cl_option *o= (class cl_option *)(/*uc*/app->options->at(i)); if ((!s || - !strcmp(s, o->get_name()))) - { - if (!o->hidden) - { - con->dd_printf("%2d. %s(by %s): ", i, object_name(o), - object_name(o->get_creator())); - o->print(con); - con->dd_printf(" - %s\n", o->help); - } - else - { - /* - con->dd_printf("%2d. %s(by %s) is hidden!\n", i, object_name(o), - object_name(o->get_creator())); - */ - } - } + !strcmp(s, o->get_name()))) + { + if (!o->hidden) + { + con->dd_printf("%2d. %s(by %s): ", i, object_name(o), + object_name(o->get_creator())); + o->print(con); + con->dd_printf(" - %s\n", o->help); + } + else + { + /* + con->dd_printf("%2d. %s(by %s) is hidden!\n", i, object_name(o), + object_name(o->get_creator())); + */ + } + } } - + return(DD_FALSE);; } diff --git a/sim/ucsim/cmd.src/getcl.h b/sim/ucsim/cmd.src/getcl.h index e41f747d..a65de00d 100644 --- a/sim/ucsim/cmd.src/getcl.h +++ b/sim/ucsim/cmd.src/getcl.h @@ -36,13 +36,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA { public: cl_get_sfr_cmd(//class cl_sim *asim, - char *aname, - int can_rep, - char *short_hlp, - char *long_hlp): + char *aname, + int can_rep, + char *short_hlp, + char *long_hlp): cl_cmd(aname, can_rep, short_hlp, long_hlp) {} virtual int do_work(class cl_sim *sim, - class cl_cmdline *cmdline, class cl_console *con); + class cl_cmdline *cmdline, class cl_console_base *con); };*/ COMMAND_ON(uc,cl_get_sfr_cmd); @@ -51,13 +51,13 @@ COMMAND_ON(uc,cl_get_sfr_cmd); { public: cl_get_option_cmd(//class cl_sim *asim, - char *aname, - int can_rep, - char *short_hlp, - char *long_hlp): + char *aname, + int can_rep, + char *short_hlp, + char *long_hlp): cl_cmd(aname, can_rep, short_hlp, long_hlp) {} virtual int do_work(class cl_sim *sim, - class cl_cmdline *cmdline, class cl_console *con); + class cl_cmdline *cmdline, class cl_console_base *con); };*/ COMMAND_ON(app,cl_get_option_cmd); diff --git a/sim/ucsim/cmd.src/info.cc b/sim/ucsim/cmd.src/info.cc index ff6881c5..077c7327 100644 --- a/sim/ucsim/cmd.src/info.cc +++ b/sim/ucsim/cmd.src/info.cc @@ -41,7 +41,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA //int //cl_info_bp_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_info_bp_cmd) { int i; @@ -53,26 +53,26 @@ COMMAND_DO_WORK_UC(cl_info_bp_cmd) class cl_brk *fb= (class cl_brk *)(uc->fbrk->at(i)); s= uc->disass(fb->addr, NULL); con->dd_printf("%-3d %-10s %s %-5d %-5d 0x%06x %s\n", fb->nr, - "fetch", (fb->perm==brkFIX)?"keep":"del ", - fb->hit, fb->cnt, - fb->addr, s); + "fetch", (fb->perm==brkFIX)?"keep":"del ", + fb->hit, fb->cnt, + fb->addr, s); free(s); } for (i= 0; i < uc->ebrk->count; i++) { class cl_ev_brk *eb= (class cl_ev_brk *)(uc->ebrk->at(i)); con->dd_printf("%-3d %-10s %s %-5d %-5d 0x%06x %s\n", eb->nr, - "event", (eb->perm==brkFIX)?"keep":"del ", - eb->hit, eb->cnt, - eb->addr, eb->id); + "event", (eb->perm==brkFIX)?"keep":"del ", + eb->hit, eb->cnt, + eb->addr, eb->id); } /*t_addr a; class cl_rom *r= (class cl_rom *)(sim->uc->mem(MEM_ROM)); for (a= 0; a < sim->uc->get_mem_size(MEM_ROM); a++) { if (r->bp_map->get(a)) - con->dd_printf("0x%06x\n", a); - }*/ + con->dd_printf("0x%06x\n", a); + }*/ return(0); } @@ -83,7 +83,7 @@ COMMAND_DO_WORK_UC(cl_info_bp_cmd) //int //cl_info_reg_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_info_reg_cmd) { uc->print_regs(con); @@ -97,14 +97,14 @@ COMMAND_DO_WORK_UC(cl_info_reg_cmd) //int //cl_info_hw_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_info_hw_cmd) { class cl_hw *hw; class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; if (cmdline->syntax_match(uc, HW)) { hw= params[0]->value.hw; @@ -123,7 +123,7 @@ COMMAND_DO_WORK_UC(cl_info_hw_cmd) //int //cl_info_stack_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_info_stack_cmd) { int i; @@ -152,56 +152,56 @@ COMMAND_DO_WORK_UC(cl_info_memory_cmd) { class cl_memory_chip *m= (class cl_memory_chip *)(uc->memchips->at(i)); if (m) - con->dd_printf(" 0x%06x-0x%06x %8d %s (%d,%s,%s)\n", - m->get_start_address(), - m->highest_valid_address(), - m->get_size(), - m->get_name(), - m->width, m->data_format, m->addr_format); + con->dd_printf(" 0x%06x-0x%06x %8d %s (%d,%s,%s)\n", + m->get_start_address(), + m->highest_valid_address(), + m->get_size(), + m->get_name(), + m->width, m->data_format, m->addr_format); } con->dd_printf("Address spaces:\n"); for (i= 0; i < uc->address_spaces->count; i++) { class cl_address_space *m= - (class cl_address_space *)(uc->address_spaces->at(i)); + (class cl_address_space *)(uc->address_spaces->at(i)); if (m) - con->dd_printf(" 0x%06x-0x%06x %8d %s (%d,%s,%s)\n", - m->get_start_address(), - m->highest_valid_address(), - m->get_size(), - m->get_name(), - m->width, m->data_format, m->addr_format); + con->dd_printf(" 0x%06x-0x%06x %8d %s (%d,%s,%s)\n", + m->get_start_address(), + m->highest_valid_address(), + m->get_size(), + m->get_name(), + m->width, m->data_format, m->addr_format); } con->dd_printf("Address decoders:\n"); for (i= 0; i < uc->address_spaces->count; i++) { class cl_address_space *m= - (class cl_address_space *)(uc->address_spaces->at(i)); + (class cl_address_space *)(uc->address_spaces->at(i)); int j; for (j= 0; j < m->decoders->count; j++) - { - class cl_address_decoder *d= - (class cl_address_decoder *)(m->decoders->at(j)); - con->dd_printf("%2d ", j); - if (d->address_space) - { - con->dd_printf("%s ", d->address_space->get_name("unknown")); - con->dd_printf(d->address_space->addr_format, d->as_begin); - con->dd_printf(" "); - con->dd_printf(d->address_space->addr_format, d->as_end); - } - else - con->dd_printf("x"); - con->dd_printf(" -> "); - if (d->memchip) - { - con->dd_printf("%s ", d->memchip->get_name("unknown")); - con->dd_printf(d->memchip->addr_format, d->chip_begin); - } - else - con->dd_printf("x"); - con->dd_printf(" %s\n", (d->activated)?"activated":"inactive"); - } + { + class cl_address_decoder *d= + (class cl_address_decoder *)(m->decoders->at(j)); + con->dd_printf("%2d ", j); + if (d->address_space) + { + con->dd_printf("%s ", d->address_space->get_name("unknown")); + con->dd_printf(d->address_space->addr_format, d->as_begin); + con->dd_printf(" "); + con->dd_printf(d->address_space->addr_format, d->as_end); + } + else + con->dd_printf("x"); + con->dd_printf(" -> "); + if (d->memchip) + { + con->dd_printf("%s ", d->memchip->get_name("unknown")); + con->dd_printf(d->memchip->addr_format, d->chip_begin); + } + else + con->dd_printf("x"); + con->dd_printf(" %s\n", (d->activated)?"activated":"inactive"); + } } return(0); } diff --git a/sim/ucsim/cmd.src/newcmd.cc b/sim/ucsim/cmd.src/newcmd.cc index 4717409e..a603324d 100644 --- a/sim/ucsim/cmd.src/newcmd.cc +++ b/sim/ucsim/cmd.src/newcmd.cc @@ -2,7 +2,8 @@ * Simulator of microcontrollers (cmd.src/newcmd.cc) * * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. - * + * Copyright (C) 2006, Borut Razem - borut.razem@siol.net + * * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * */ @@ -31,22 +32,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include -#include -#include -#ifdef SOCKET_AVAIL -# include HEADER_SOCKET -# if defined HAVE_SYS_SOCKET_H -# include -# include -# include -# endif -#endif -#if FD_HEADER_OK -# include HEADER_FD -#endif -#ifdef HAVE_UNISTD_H -# include -#endif #include "i_string.h" #include "cmdlexcl.h" @@ -70,7 +55,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA * Options of console */ -cl_prompt_option::cl_prompt_option(class cl_console *console): +cl_prompt_option::cl_prompt_option(class cl_console_base *console): cl_optref(console) { con= console; @@ -100,7 +85,7 @@ cl_prompt_option::option_changed(void) } -cl_debug_option::cl_debug_option(class cl_console *console): +cl_debug_option::cl_debug_option(class cl_console_base *console): cl_prompt_option(console) {} @@ -134,112 +119,8 @@ cl_debug_option::option_changed(void) *____________________________________________________________________________ */ -cl_console::cl_console(char *fin, char *fout, class cl_app *the_app): - cl_base() -{ - FILE *f; - - app= the_app; - in= 0; - if (fin) - if (f= fopen(fin, "r"), in= f, !f) - fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno)); - out= 0; - if (fout) - if (f= fopen(fout, "w"), out= f, !f) - fprintf(stderr, "Can't open `%s': %s\n", fout, strerror(errno)); - prompt= 0; - flags= CONS_NONE; - if (in && - isatty(fileno(in))) - flags|= CONS_INTERACTIVE; - else - ;//fprintf(stderr, "Warning: non-interactive console\n"); - rout= 0; - id= 0; - lines_printed= new cl_ustrings(100, 100, "console_cache"); -} - -cl_console::cl_console(FILE *fin, FILE *fout, class cl_app *the_app): - cl_base() -{ - app= the_app; - in = fin; - out= fout; - prompt= 0; - flags= CONS_NONE; - if (in && - isatty(fileno(in))) - flags|= CONS_INTERACTIVE; - else - ;//fprintf(stderr, "Warning: non-interactive console\n"); - rout= 0; - id= 0; - lines_printed= new cl_ustrings(100, 100, "console_cache"); -} - -/* - * use the port number supplied to connect to localhost for - * (by Sandeep) - */ - -#ifdef SOCKET_AVAIL -static int -connect_to_port(int portnum) -{ - int sock= socket(AF_INET,SOCK_STREAM,0); - struct sockaddr_in sin; - - sin.sin_family = AF_INET; - sin.sin_port = htons(portnum); - sin.sin_addr.s_addr = inet_addr("127.0.0.1"); - - if (connect(sock, (struct sockaddr *)&sin, sizeof(sin))) { - fprintf(stderr, "Connect to port %d: %s\n", portnum, strerror(errno)); - return -1; - } - return sock; -} - -cl_console::cl_console(int portnumber, class cl_app *the_app) -{ - int sock= connect_to_port(portnumber); - - app= the_app; - if (!(in= fdopen(sock, "r"))) - fprintf(stderr, "cannot open port for input\n"); - if (!(out= fdopen(sock, "w"))) - fprintf(stderr, "cannot open port for output\n"); - //fprintf(stderr, "init socket done\n"); - id= 0; - lines_printed= new cl_ustrings(1, 1, "console_cache"); -} -#endif - -class cl_console * -cl_console::clone_for_exec(char *fin) -{ - FILE *fi= 0, *fo= 0; - - if (!fin) - return(0); - if (fi= fopen(fin, "r"), !fi) - { - fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno)); - return(0); - } - if ((fo= fdopen(dup(fileno(out)), "a")) == 0) - { - fclose(fi); - fprintf(stderr, "Can't re-open output file: %s\n", strerror(errno)); - return(0); - } - class cl_console *con= new cl_sub_console(this, fi, fo, app); - return(con); -} - int -cl_console::init(void) +cl_console_base::init(void) { cl_base::init(); prompt_option= new cl_prompt_option(this); @@ -257,48 +138,8 @@ cl_console::init(void) return(0); } -cl_console::~cl_console(void) -{ - if (in) - fclose(in); - un_redirect(); - if (out) - { - if (flags & CONS_PROMPT) - fprintf(out, "\n"); - fflush(out); - fclose(out); - } - delete prompt_option; - delete null_prompt_option; - delete debug_option; -#ifdef SOCKET_AVAIL - /* if (sock) - { - shutdown(sock, 2); - close(sock); - }*/ -#endif -} - - -bool -cl_console::accept_last(void) -{ - if (!in) - return(DD_FALSE); - if (isatty(fileno(in))) - return(DD_TRUE); - return(DD_FALSE); -} - - -/* - * Output functions - */ - void -cl_console::welcome(void) +cl_console_base::welcome(void) { if (!(flags & CONS_NOWELCOME)) { @@ -312,64 +153,25 @@ cl_console::welcome(void) } void -cl_console::redirect(char *fname, char *mode) -{ - if ((rout= fopen(fname, mode)) == NULL) - dd_printf("Unable to open file '%s' for %s: %s\n", - fname, (mode[0]=='w')?"write":"append", strerror(errno)); -} - -void -cl_console::un_redirect(void) +cl_console_base::print_prompt(void) { - if (!rout) + if (flags & (CONS_PROMPT | CONS_FROZEN | CONS_INACTIVE)) return; - fclose(rout); - rout= NULL; -} - - -int -cl_console::cmd_do_print(char *format, va_list ap) -{ - int ret; - FILE *f = get_out(); - - if (f) - { - ret= vfprintf(f, format, ap); - fflush(f); - } - else - ret= 0; - - return(ret); -} -void -cl_console::print_prompt(void) -{ - if (flags & (CONS_PROMPT|CONS_FROZEN|CONS_INACTIVE)) - return; - flags|= CONS_PROMPT; + flags |= CONS_PROMPT; if (/*app->args->arg_avail('P')*/null_prompt_option->get_value(bool(0))) { - FILE *Out = get_out(); - if (Out) - { - putc('\0', Out); - fflush(Out); - } + dd_printf("%c", 0); } else { - dd_printf("%d%s", id, (prompt && prompt[0])?prompt:"> "); + dd_printf("%d%s", id, (prompt && prompt[0]) ? prompt : "> "); // ((p= app->args->get_sarg(0, "prompt"))?p:"> ")); } } int -cl_console::dd_printf(char *format, ...) +cl_console_base::dd_printf(char *format, ...) { va_list ap; int ret= 0; @@ -382,7 +184,7 @@ cl_console::dd_printf(char *format, ...) } int -cl_console::debug(char *format, ...) +cl_console_base::debug(char *format, ...) { if ((flags & CONS_DEBUG) == 0) return(0); @@ -397,8 +199,12 @@ cl_console::debug(char *format, ...) return(ret); } +/* + * Printing out an integer in binary format + */ + void -cl_console::print_bin(long data, int bits) +cl_console_base::print_bin(long data, int bits) { long mask= 1; @@ -411,103 +217,95 @@ cl_console::print_bin(long data, int bits) } void -cl_console::print_char_octal(char c) -{ - FILE *Out= get_out(); - - if (Out) - ::print_char_octal(c, Out); +cl_console_base::print_char_octal(char c) +{ + if (strchr("\a\b\f\n\r\t\v\"", c)) + switch (c) + { + case '\a': dd_printf("\a"); break; + case '\b': dd_printf("\b"); break; + case '\f': dd_printf("\f"); break; + case '\n': dd_printf("\n"); break; + case '\r': dd_printf("\r"); break; + case '\t': dd_printf("\t"); break; + case '\v': dd_printf("\v"); break; + case '\"': dd_printf("\""); break; + } + else if (isprint(c)) + dd_printf("%c", c); + else + dd_printf("\\%03hho", c); } - -/* - * Input functions - */ - int -cl_console::get_in_fd(void) +cl_console_base::interpret(char *cmd) { - if (flags & CONS_INACTIVE) - return(-2); - return(in?fileno(in):-1); + dd_printf("Unknown command\n"); + return(0); } -int -cl_console::input_avail(void) +void +cl_console_base::set_id(int new_id) { - struct timeval tv; - UCSOCKET_T i; - - if ((i= get_in_fd()) < 0) - return(0); - fd_set s; - FD_ZERO(&s); - FD_SET(i, &s); - tv.tv_sec= tv.tv_usec= 0; - i= select(i+1, &s, NULL, NULL, &tv); - return(i); + char *s; + + id= new_id; + set_name(s= format_string("console%d", id)); + free(s); } -char * -cl_console::read_line(void) +void +cl_console_base::set_prompt(char *p) { - char *s= NULL; + if (prompt) + free(prompt); + if (p && *p) + prompt= strdup(p); + else + prompt= 0; +} -#ifdef HAVE_GETLINE - if (getline(&s, 0, in) < 0) - return(0); -#elif defined HAVE_GETDELIM - size_t n= 30; - s= (char *)malloc(n); - if (getdelim(&s, &n, '\n', in) < 0) - { - free(s); - return(0); - } -#elif defined HAVE_FGETS - s= (char *)malloc(300); - if (fgets(s, 300, in) == NULL) +bool +cl_console_base::input_active(void) const +{ + if (((flags & CONS_FROZEN) == 0 || + (flags & CONS_INTERACTIVE) != 0) && + (flags & CONS_INACTIVE) == 0) { - free(s); - return(0); + return true; } -#endif - s[strlen(s)-1]= '\0'; - if (s[strlen(s)-1] == '\r') - s[strlen(s)-1]= '\0'; - flags&= ~CONS_PROMPT; - return(s); + else + return false; } int -cl_console::proc_input(class cl_cmdset *cmdset) +cl_console_base::proc_input(class cl_cmdset *cmdset) { - int retval= 0; + int retval = 0; un_redirect(); - if (feof(in)) + if (is_eof()) { - fprintf(out, "End\n"); - return(1); + dd_printf("End\n"); + return 1; } - char *cmdstr= read_line(); + char *cmdstr = read_line(); if (!cmdstr) - return(1); + return 1; if (flags & CONS_FROZEN) { app->get_sim()->stop(resUSER); flags&= ~CONS_FROZEN; - retval= 0; + retval = 0; } else { - if (cmdstr && - *cmdstr == '\004') - retval= 1; + if (cmdstr && *cmdstr == '\004') + retval = 1; else { class cl_cmdline *cmdline= 0; - class cl_cmd *cm= 0; + class cl_cmd *cm = 0; if (flags & CONS_ECHO) dd_printf("%s\n", cmdstr); cmdline= new cl_cmdline(app, cmdstr, this); @@ -516,9 +314,9 @@ cl_console::proc_input(class cl_cmdset *cmdset) accept_last() && last_command) { - cm= last_command; + cm = last_command; delete cmdline; - cmdline= last_cmdline; + cmdline = last_cmdline; } else { @@ -526,17 +324,17 @@ cl_console::proc_input(class cl_cmdset *cmdset) if (last_cmdline) { delete last_cmdline; - last_cmdline= 0; + last_cmdline = 0; } - last_command= 0; + last_command = 0; } if (cm) { retval= cm->work(app, cmdline, this); if (cm->can_repeat) { - last_command= cm; - last_cmdline= cmdline; + last_command = cm; + last_cmdline = cmdline; } else delete cmdline; @@ -545,8 +343,8 @@ cl_console::proc_input(class cl_cmdset *cmdset) { class YY_cl_ucsim_parser_CLASS *pars; class cl_ucsim_lexer *lexer; - lexer= new cl_ucsim_lexer(cmdstr); - pars= new YY_cl_ucsim_parser_CLASS(lexer); + lexer = new cl_ucsim_lexer(cmdstr); + pars = new YY_cl_ucsim_parser_CLASS(lexer); pars->yyparse(); delete cmdline; delete pars; @@ -563,239 +361,29 @@ cl_console::proc_input(class cl_cmdset *cmdset) return(retval); } -/* - * Old version, sim->do_cmd() falls into this if it doesn't find a new - * command object which can handle entered command - */ - -int -cl_console::interpret(char *cmd) -{ - dd_printf("Unknown command\n"); - return(0); -} - -void -cl_console::set_id(int new_id) -{ - char *s; - - id= new_id; - set_name(s= format_string("console%d", id)); - free(s); -} - -void -cl_console::set_prompt(char *p) -{ - if (prompt) - free(prompt); - if (p && - *p) - prompt= strdup(p); - else - prompt= 0; -} - - -/* - * This console listen on a socket and can accept connection requests - */ -#ifdef SOCKET_AVAIL - -cl_listen_console::cl_listen_console(int serverport, class cl_app *the_app) -{ - app= the_app; - if ((sock= make_server_socket(serverport)) >= 0) - { - if (listen(sock, 10) < 0) - fprintf(stderr, "Listen on port %d: %s\n", - serverport, strerror(errno)); - } - in= out= 0; -} - -int -cl_listen_console::get_in_fd(void) -{ - return(sock); -} - -int -cl_listen_console::proc_input(class cl_cmdset *cmdset) -{ - int newsock; - ACCEPT_SOCKLEN_T size; - struct sockaddr_in sock_addr; - class cl_commander *cmd; - - cmd= app->get_commander(); - size= sizeof(struct sockaddr); - newsock= accept(sock, (struct sockaddr*)&sock_addr, &size); - if (newsock < 0) - { - perror("accept"); - return(0); - } - if (!(in= fdopen(newsock, "r+"))) - fprintf(stderr, "cannot open port for input\n"); - if (!(out= fdopen(newsock, "w+"))) - fprintf(stderr, "cannot open port for output\n"); - class cl_console *c= cmd->mk_console(in, out); - c->flags|= CONS_INTERACTIVE; - cmd->add_console(c); - in= out= 0; - return(0); -} - -#endif /* SOCKET_AVAIL */ - - -/* - * Sub-console - */ - -cl_sub_console::cl_sub_console(class cl_console *the_parent, - FILE *fin, FILE *fout, class cl_app *the_app): - cl_console(fin, fout, the_app) -{ - parent= the_parent; -} - -cl_sub_console::~cl_sub_console(void) -{ - class cl_commander *c= app->get_commander(); - - if (parent && c) - { - c->activate_console(parent); - } -} - -int -cl_sub_console::init(void) -{ - class cl_commander *c= app->get_commander(); - - if (parent && c) - { - c->deactivate_console(parent); - } - cl_console::init(); - flags|= CONS_ECHO; - return(0); -} - /* * Command interpreter *____________________________________________________________________________ */ -cl_commander::cl_commander(class cl_app *the_app, class cl_cmdset *acmdset - /*, class cl_sim *asim*/): +cl_commander_base::cl_commander_base(class cl_app *the_app, class cl_cmdset *acmdset): cl_base() { app= the_app; - cons= new cl_list(1, 1, "consoles"); + cons= new cl_list(1, 1, "consoles"); actual_console= frozen_console= 0; cmdset= acmdset; } -int -cl_commander::init(void) -{ - class cl_optref console_on_option(this); - class cl_optref config_file_option(this); - class cl_optref port_number_option(this); - class cl_console *con; - - console_on_option.init(); - console_on_option.use("console_on"); - config_file_option.init(); - config_file_option.use("config_file"); - port_number_option.init(); - - cl_base::init(); - set_name("Commander"); - - bool need_config= DD_TRUE; - -#ifdef SOCKET_AVAIL - if (port_number_option.use("port_number")) - add_console(mk_console(port_number_option.get_value((long)0))); -#endif - - /* The following code is commented out because it produces gcc warnings - * newcmd.cc: In member function `virtual int cl_commander::init()': - * newcmd.cc:785: warning: 'Config' might be used uninitialized in this function - * newcmd.cc:786: warning: 'cn' might be used uninitialized in this function - */ - /* - char *Config= config_file_option.get_value(Config); - char *cn= console_on_option.get_value(cn); - */ - /* Here shoud probably be something else, but is still better then the former code... */ - char *Config= config_file_option.get_value(""); - char *cn= console_on_option.get_value(""); - - if (cn) - { - add_console(con= mk_console(cn, cn)); - exec_on(con, Config); - need_config= DD_FALSE; - } - if (cons->get_count() == 0) - { - add_console(con= mk_console(stdin, stdout)); - exec_on(con, Config); - need_config= DD_FALSE; - } - if (need_config && - Config && - *Config) - { - FILE *fc= fopen(Config, "r"); - if (!fc) - fprintf(stderr, "Can't open `%s': %s\n", Config, strerror(errno)); - else - { - con= mk_console(fc, stderr); - con->flags|= CONS_NOWELCOME|CONS_ECHO; - add_console(con); - } - } - return(0); -} - -cl_commander::~cl_commander(void) +cl_commander_base::~cl_commander_base(void) { delete cons; delete cmdset; } -class cl_console * -cl_commander::mk_console(char *fin, char *fout) -{ - return(new cl_console(fin, fout, app)); -} - -class cl_console * -cl_commander::mk_console(FILE *fin, FILE *fout) -{ - return(new cl_console(fin, fout, app)); -} - -#ifdef SOCKET_AVAIL -class cl_console * -cl_commander::mk_console(int portnumber) -{ - return(new cl_listen_console(portnumber, app)); -} -#endif - void -cl_commander::add_console(class cl_console *console) +cl_commander_base::add_console(class cl_console_base *console) { if (!console) return; @@ -806,14 +394,14 @@ cl_commander::add_console(class cl_console *console) } void -cl_commander::del_console(class cl_console *console) +cl_commander_base::del_console(class cl_console_base *console) { cons->disconn(console); set_fd_set(); } void -cl_commander::activate_console(class cl_console *console) +cl_commander_base::activate_console(class cl_console_base *console) { console->flags&= ~CONS_INACTIVE; //console->print_prompt(); @@ -821,54 +409,25 @@ cl_commander::activate_console(class cl_console *console) } void -cl_commander::deactivate_console(class cl_console *console) +cl_commander_base::deactivate_console(class cl_console_base *console) { console->flags|= CONS_INACTIVE; set_fd_set(); } -void -cl_commander::set_fd_set(void) -{ - int i; - - //fprintf(stderr, "** Setting fd set\n"); - FD_ZERO(&read_set); - fd_num= 0; - for (i= 0; i < cons->count; i++) - { - UCSOCKET_T fd; - class cl_console *c= (class cl_console*)(cons->at(i)); - if ((fd= c->get_in_fd()) >= 0) - { - if ((c->flags & CONS_FROZEN) == 0 || - (c->flags & CONS_INTERACTIVE) != 0) - { - FD_SET(fd, &read_set); - if (fd > fd_num) - fd_num= fd; - } - } - else - ;//fprintf(stderr, "** Skipping console %p\n",c); - } - fd_num++; -} - - /* * Printing to all consoles */ int -cl_commander::all_printf(char *format, ...) +cl_commander_base::all_printf(char *format, ...) { va_list ap; int i, ret= 0; - + for (i= 0; i < cons->count; i++) { - class cl_console *c= (class cl_console*)(cons->at(i)); + class cl_console_base *c= (class cl_console_base*)(cons->at(i)); va_start(ap, format); ret= c->cmd_do_print(format, ap); @@ -878,13 +437,13 @@ cl_commander::all_printf(char *format, ...) } void -cl_commander::prompt(void) +cl_commander_base::prompt(void) { int i; - + for (i= 0; i < cons->count; i++) { - class cl_console *c= (class cl_console*)(cons->at(i)); + class cl_console_base *c= (class cl_console_base*)(cons->at(i)); c->print_prompt(); } } @@ -894,10 +453,10 @@ cl_commander::prompt(void) */ int -cl_commander::dd_printf(char *format, va_list ap) +cl_commander_base::dd_printf(char *format, va_list ap) { int ret= 0; - class cl_console *con; + class cl_console_base *con; if (actual_console) { @@ -919,7 +478,7 @@ cl_commander::dd_printf(char *format, va_list ap) } int -cl_commander::dd_printf(char *format, ...) +cl_commander_base::dd_printf(char *format, ...) { va_list ap; int ret= 0; @@ -936,14 +495,14 @@ cl_commander::dd_printf(char *format, ...) */ int -cl_commander::debug(char *format, ...) +cl_commander_base::debug(char *format, ...) { va_list ap; int i, ret= 0; for (i= 0; i < cons->count; i++) { - class cl_console *c= (class cl_console*)(cons->at(i)); + class cl_console_base *c= (class cl_console_base*)(cons->at(i)); if (c->flags & CONS_DEBUG) { va_start(ap, format); @@ -955,13 +514,13 @@ cl_commander::debug(char *format, ...) } int -cl_commander::debug(char *format, va_list ap) +cl_commander_base::debug(char *format, va_list ap) { int i, ret= 0; for (i= 0; i < cons->count; i++) { - class cl_console *c= (class cl_console*)(cons->at(i)); + class cl_console_base *c= (class cl_console_base*)(cons->at(i)); if (c->flags & CONS_DEBUG) { ret= c->cmd_do_print(format, ap); @@ -971,14 +530,14 @@ cl_commander::debug(char *format, va_list ap) } int -cl_commander::flag_printf(int iflags, char *format, ...) +cl_commander_base::flag_printf(int iflags, char *format, ...) { va_list ap; int i, ret= 0; for (i= 0; i < cons->count; i++) { - class cl_console *c= (class cl_console*)(cons->at(i)); + class cl_console_base *c= (class cl_console_base*)(cons->at(i)); if ((c->flags & iflags) == iflags) { va_start(ap, format); @@ -990,75 +549,21 @@ cl_commander::flag_printf(int iflags, char *format, ...) } int -cl_commander::input_avail(void) +cl_commander_base::input_avail_on_frozen(void) { - struct timeval tv; - int i; - - tv.tv_sec= tv.tv_usec= 0; - active_set= read_set; - i= select(fd_num, &active_set, NULL, NULL, &tv); - return(i); -} - -int -cl_commander::input_avail_on_frozen(void) -{ - int fd; - - if (!frozen_console) - return(0); - if ((fd= frozen_console->get_in_fd()) >= 0 && - !isatty(fd)) + if (!frozen_console || frozen_console->is_tty()) return(0); return(frozen_console->input_avail()); } -int -cl_commander::wait_input(void) -{ - int i; - - active_set= read_set; - prompt(); - i= select(fd_num, &active_set, NULL, NULL, NULL); - return(i); -} - -int -cl_commander::proc_input(void) -{ - for (int j = 0; j < cons->count; j++) - { - class cl_console *c = (class cl_console*)(cons->at(j)); - - int fd = c->get_in_fd(); - if (fd >= 0 && FD_ISSET(fd, &active_set)) - { - actual_console = c; - int retval = c->proc_input(cmdset); - if (retval) - { - del_console(c); - delete c; - } - actual_console = 0; - return(0 == cons->count); - } - } - return 0; -} - void -cl_commander::exec_on(class cl_console *cons, char *file_name) +cl_commander_base::exec_on(class cl_console_base *cons, char *file_name) { - FILE *fi= fopen(file_name, "r"); - - if (!cons || - !fi) + if (!cons || !file_name || !fopen(file_name, "r")) return; - class cl_console *subcon= cons->clone_for_exec(file_name); - subcon->flags|= CONS_NOWELCOME; + + class cl_console_base *subcon = cons->clone_for_exec(file_name); + subcon->flags |= CONS_NOWELCOME; add_console(subcon); } diff --git a/sim/ucsim/cmd.src/newcmdcl.h b/sim/ucsim/cmd.src/newcmdcl.h index 471614c8..49ae8cf4 100644 --- a/sim/ucsim/cmd.src/newcmdcl.h +++ b/sim/ucsim/cmd.src/newcmdcl.h @@ -1,7 +1,8 @@ /* - * Simulator of microcontrollers (cmd.src/cmdcl.h) + * Simulator of microcontrollers (cmd.src/newcmdcl.h) * * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. + * Copyright (C) 2006, Borut Razem - borut.razem@siol.net * * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * @@ -34,9 +35,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include -#if FD_HEADER_OK -# include HEADER_FD -#endif // prj #include "pobjcl.h" @@ -79,9 +77,9 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA class cl_prompt_option: public cl_optref { protected: - class cl_console *con; + class cl_console_base *con; public: - cl_prompt_option(class cl_console *console); + cl_prompt_option(class cl_console_base *console); virtual int init(void); virtual void option_changed(void); }; @@ -89,7 +87,7 @@ public: class cl_debug_option: public cl_prompt_option { public: - cl_debug_option(class cl_console *console); + cl_debug_option(class cl_console_base *console); virtual int init(void); virtual void option_changed(void); }; @@ -98,115 +96,76 @@ public: * Command console */ -class cl_console: public cl_base +class cl_console_base: public cl_base { - friend class cl_commander; protected: - FILE *in, *out, *rout/*redirected output*/; - int id; class cl_prompt_option *prompt_option; class cl_optref *null_prompt_option; class cl_debug_option *debug_option; class cl_ustrings *lines_printed; class cl_cmd *last_command; class cl_cmdline *last_cmdline; -public: - class cl_app *app; - int flags; // See CONS_XXXX - char *prompt; public: - cl_console(void): cl_base() { app= 0; in= out= 0; flags= 0; } - cl_console(char *fin, char *fout, class cl_app *the_app); - cl_console(FILE *fin, FILE *fout, class cl_app *the_app); - cl_console(char *fin, FILE *fout); -#ifdef SOCKET_AVAIL - cl_console(int portnumber, class cl_app *the_app); -#endif - virtual ~cl_console(void); - virtual class cl_console *clone_for_exec(char *fin); - virtual int init(void); + cl_console_base(void): cl_base() { app = 0; flags = 0; prompt = 0; } - virtual bool accept_last(void); + virtual class cl_console_base *clone_for_exec(char *fin) = 0; - virtual void welcome(void); - virtual void redirect(char *fname, char *mode); - virtual void un_redirect(void); - int cmd_do_print(char *format, va_list ap); - virtual void print_prompt(void); - virtual int dd_printf(char *format, ...); - virtual int debug(char *format, ...); - virtual void print_bin(long data, int bits); - virtual void print_char_octal(char c); - virtual int get_in_fd(void); - virtual int input_avail(void); - virtual char *read_line(void); - virtual int proc_input(class cl_cmdset *cmdset); - virtual bool interpret(char *cmd); - virtual void set_id(int new_id); - virtual int get_id(void) { return(id); } - virtual void set_prompt(char *p); -private: - FILE *get_out(void) { return(rout?rout:out); } -}; - -#ifdef SOCKET_AVAIL -class cl_listen_console: public cl_console -{ -public: - int sock; -public: - cl_listen_console(int serverport, class cl_app *the_app); + virtual void redirect(char *fname, char *mode) = 0; + virtual void un_redirect(void) = 0; + virtual int cmd_do_print(char *format, va_list ap) = 0; + virtual bool is_tty(void) const = 0; + virtual bool is_eof(void) const = 0; + virtual int input_avail(void) = 0; + virtual char *read_line(void) = 0; - virtual void welcome(void) {} - - virtual int get_in_fd(void); + virtual int init(void); + virtual void welcome(void); virtual int proc_input(class cl_cmdset *cmdset); -}; -#endif + void print_prompt(void); + int dd_printf(char *format, ...); + int debug(char *format, ...); + void print_bin(long data, int bits); + void print_char_octal(char c); + + bool interpret(char *cmd); + int get_id(void) const { return(id); } + void set_id(int new_id); + void set_prompt(char *p); + + bool input_active(void) const; + bool accept_last(void) { return is_tty() ? DD_TRUE : DD_FALSE; } -class cl_sub_console: public cl_console -{ - class cl_console *parent; public: - cl_sub_console(class cl_console *the_parent, - FILE *fin, FILE *fout, class cl_app *the_app); - virtual ~cl_sub_console(void); - virtual int init(void); -}; + int flags; // See CONS_XXXX +protected: + class cl_app *app; + char *prompt; + int id; +}; /* * Command interpreter */ -class cl_commander: public cl_base +class cl_commander_base: public cl_base { public: class cl_app *app; class cl_list *cons; - fd_set read_set, active_set; - UCSOCKET_T fd_num; - class cl_console *actual_console, *frozen_console; + class cl_console_base *actual_console, *frozen_console; class cl_cmdset *cmdset; public: - cl_commander(class cl_app *the_app, - class cl_cmdset *acmdset/*, class cl_sim *asim*/); - virtual ~cl_commander(void); - virtual int init(void); + cl_commander_base(class cl_app *the_app, class cl_cmdset *acmdset); + virtual ~cl_commander_base(void); - virtual class cl_console *mk_console(char *fin, char *fout); - virtual class cl_console *mk_console(FILE *fin, FILE *fout); -#ifdef SOCKET_AVAIL - virtual class cl_console *mk_console(int portnumber); -#endif - void add_console(class cl_console *console); - void del_console(class cl_console *console); - void activate_console(class cl_console *console); - void deactivate_console(class cl_console *console); - void set_fd_set(void); + void add_console(class cl_console_base *console); + void del_console(class cl_console_base *console); + void activate_console(class cl_console_base *console); + void deactivate_console(class cl_console_base *console); void prompt(void); int all_printf(char *format, ...); // print to all consoles @@ -215,14 +174,17 @@ public: int debug(char *format, ...); // print consoles with debug flag set int debug(char *format, va_list ap); // print consoles with debug flag set int flag_printf(int iflags, char *format, ...); - int input_avail(void); int input_avail_on_frozen(void); - int wait_input(void); - int proc_input(void); - void exec_on(class cl_console *cons, char *file_name); + void exec_on(class cl_console_base *cons, char *file_name); + + virtual int init(void) = 0; + virtual void set_fd_set(void) = 0; + virtual int proc_input(void) = 0; + virtual int input_avail(void) = 0; + virtual int wait_input(void) = 0; }; #endif -/* End of cmd.src/cmdcl.h */ +/* End of cmd.src/newcmdcl.h */ diff --git a/sim/ucsim/cmd.src/newcmdposix.cc b/sim/ucsim/cmd.src/newcmdposix.cc new file mode 100644 index 00000000..f82bcad0 --- /dev/null +++ b/sim/ucsim/cmd.src/newcmdposix.cc @@ -0,0 +1,465 @@ +/* + * Simulator of microcontrollers (cmd.src/newcmdposix.cc) + * + * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. + * Copyright (C) 2006, Borut Razem - borut.razem@siol.net + * + * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu + * + */ + +/* This file is part of microcontroller simulator: ucsim. + +UCSIM is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +UCSIM is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with UCSIM; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. */ +/*@1@*/ + +#include "ddconfig.h" + +#include +#include +#include +#include +#include +#include +#ifdef SOCKET_AVAIL +# include HEADER_SOCKET +# if defined HAVE_SYS_SOCKET_H +# include +# include +# include +# endif +#endif +#if FD_HEADER_OK +# include HEADER_FD +#endif +#ifdef HAVE_UNISTD_H +# include +#endif +#include "i_string.h" + +#include "cmdlexcl.h" +#include "cmdpars.h" + +// prj +#include "globals.h" +#include "utils.h" + +// sim +#include "simcl.h" +#include "argcl.h" +#include "appcl.h" + +// local +#include "newcmdposixcl.h" + + +/* + * Command console + *____________________________________________________________________________ + */ + +cl_console::cl_console(char *fin, char *fout, class cl_app *the_app) +{ + FILE *f; + + app= the_app; + in= 0; + if (fin) + if (f= fopen(fin, "r"), in= f, !f) + fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno)); + out= 0; + if (fout) + if (f= fopen(fout, "w"), out= f, !f) + fprintf(stderr, "Can't open `%s': %s\n", fout, strerror(errno)); + prompt= 0; + flags= CONS_NONE; + if (is_tty()) + flags|= CONS_INTERACTIVE; + else + ;//fprintf(stderr, "Warning: non-interactive console\n"); + rout= 0; + id= 0; + lines_printed= new cl_ustrings(100, 100, "console_cache"); +} + +cl_console::cl_console(FILE *fin, FILE *fout, class cl_app *the_app) +{ + app= the_app; + in = fin; + out= fout; + prompt= 0; + flags= CONS_NONE; + if (is_tty()) + flags|= CONS_INTERACTIVE; + else + ;//fprintf(stderr, "Warning: non-interactive console\n"); + rout= 0; + id= 0; + lines_printed= new cl_ustrings(100, 100, "console_cache"); +} + +class cl_console * +cl_console::clone_for_exec(char *fin) +{ + FILE *fi= 0, *fo= 0; + + if (!fin) + return(0); + if (fi= fopen(fin, "r"), !fi) + { + fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno)); + return(0); + } + if ((fo= fdopen(dup(fileno(out)), "a")) == 0) + { + fclose(fi); + fprintf(stderr, "Can't re-open output file: %s\n", strerror(errno)); + return(0); + } + class cl_console *con= new cl_sub_console(this, fi, fo, app); + return(con); +} + +cl_console::~cl_console(void) +{ + if (in) + fclose(in); + un_redirect(); + if (out) + { + if (flags & CONS_PROMPT) + fprintf(out, "\n"); + fflush(out); + fclose(out); + } + delete prompt_option; + delete null_prompt_option; + delete debug_option; +#ifdef SOCKET_AVAIL + /* if (sock) + { + shutdown(sock, 2); + close(sock); + }*/ +#endif +} + + +/* + * Output functions + */ + +void +cl_console::redirect(char *fname, char *mode) +{ + if ((rout= fopen(fname, mode)) == NULL) + dd_printf("Unable to open file '%s' for %s: %s\n", + fname, (mode[0]=='w')?"write":"append", strerror(errno)); +} + +void +cl_console::un_redirect(void) +{ + if (!rout) + return; + fclose(rout); + rout = NULL; +} + +int +cl_console::cmd_do_print(char *format, va_list ap) +{ + int ret; + FILE *f = get_out(); + + if (f) + { + ret= vfprintf(f, format, ap); + fflush(f); + } + else + ret = 0; + + return ret; +} + +/* + * Input functions + */ + +char * +cl_console::read_line(void) +{ + char *s= NULL; + +#ifdef HAVE_GETLINE + if (getline(&s, 0, in) < 0) + return(0); +#elif defined HAVE_GETDELIM + size_t n= 30; + s= (char *)malloc(n); + if (getdelim(&s, &n, '\n', in) < 0) + { + free(s); + return(0); + } +#elif defined HAVE_FGETS + s= (char *)malloc(300); + if (fgets(s, 300, in) == NULL) + { + free(s); + return(0); + } +#endif + s[strlen(s)-1]= '\0'; + if (s[strlen(s)-1] == '\r') + s[strlen(s)-1]= '\0'; + flags&= ~CONS_PROMPT; + return(s); +} + + +/* + * This console listen on a socket and can accept connection requests + */ +#ifdef SOCKET_AVAIL + +cl_listen_console::cl_listen_console(int serverport, class cl_app *the_app) +{ + app= the_app; + if ((sock= make_server_socket(serverport)) >= 0) + { + if (listen(sock, 10) < 0) + fprintf(stderr, "Listen on port %d: %s\n", + serverport, strerror(errno)); + } + in= out= rout= 0; +} + +int +cl_listen_console::proc_input(class cl_cmdset *cmdset) +{ + int newsock; + ACCEPT_SOCKLEN_T size; + struct sockaddr_in sock_addr; + class cl_commander_base *cmd; + FILE *in, *out; + + cmd= app->get_commander(); + size= sizeof(struct sockaddr); + newsock= accept(sock, (struct sockaddr*)&sock_addr, &size); + if (newsock < 0) + { + perror("accept"); + return(0); + } + if (!(in= fdopen(newsock, "r"))) + fprintf(stderr, "cannot open port for input\n"); + if (!(out= fdopen(newsock, "w"))) + fprintf(stderr, "cannot open port for output\n"); + class cl_console_base *c= new cl_console(in, out, app); + c->flags|= CONS_INTERACTIVE; + cmd->add_console(c); + return(0); +} + +#endif /* SOCKET_AVAIL */ + + +/* + * Sub-console + */ + +cl_sub_console::cl_sub_console(class cl_console_base *the_parent, + FILE *fin, FILE *fout, class cl_app *the_app): + cl_console(fin, fout, the_app) +{ + parent= the_parent; +} + +cl_sub_console::~cl_sub_console(void) +{ + class cl_commander_base *c= app->get_commander(); + + if (parent && c) + { + c->activate_console(parent); + } +} + +int +cl_sub_console::init(void) +{ + class cl_commander_base *c= app->get_commander(); + + if (parent && c) + { + c->deactivate_console(parent); + } + cl_console::init(); + flags|= CONS_ECHO; + return(0); +} + + +/* + * Command interpreter + *____________________________________________________________________________ + */ + +int +cl_commander::init(void) +{ + class cl_optref console_on_option(this); + class cl_optref config_file_option(this); + class cl_optref port_number_option(this); + class cl_console_base *con; + + console_on_option.init(); + console_on_option.use("console_on"); + config_file_option.init(); + config_file_option.use("config_file"); + port_number_option.init(); + + cl_base::init(); + set_name("Commander"); + + bool need_config= DD_TRUE; + +#ifdef SOCKET_AVAIL + if (port_number_option.use("port_number")) + add_console(new cl_listen_console(port_number_option.get_value((long)0), app)); +#endif + + /* The following code is commented out because it produces gcc warnings + * newcmd.cc: In member function `virtual int cl_commander::init()': + * newcmd.cc:785: warning: 'Config' might be used uninitialized in this function + * newcmd.cc:786: warning: 'cn' might be used uninitialized in this function + */ + /* + char *Config= config_file_option.get_value(Config); + char *cn= console_on_option.get_value(cn); + */ + /* Here shoud probably be something else, but is still better then the former code... */ + char *Config= config_file_option.get_value(""); + char *cn= console_on_option.get_value(""); + + if (cn) + { + add_console(con= new cl_console(cn, cn, app)); + exec_on(con, Config); + need_config= DD_FALSE; + } + if (cons->get_count() == 0) + { + add_console(con= new cl_console(stdin, stdout, app)); + exec_on(con, Config); + need_config= DD_FALSE; + } + if (need_config && + Config && + *Config) + { + FILE *fc= fopen(Config, "r"); + if (!fc) + fprintf(stderr, "Can't open `%s': %s\n", Config, strerror(errno)); + else + { + con= new cl_console(fc, stderr, app); + con->flags|= CONS_NOWELCOME|CONS_ECHO; + add_console(con); + } + } + return(0); +} + +void +cl_commander::set_fd_set(void) +{ + int i; + + FD_ZERO(&read_set); + fd_num = 0; + for (i = 0; i < cons->count; i++) + { + class cl_console *c= dynamic_cast((class cl_console_base*)(cons->at(i))); + + if (c->input_active()) + { + UCSOCKET_T fd = c->get_in_fd(); + assert(0 <= fd); + + FD_SET(fd, &read_set); + if (fd > fd_num) + fd_num = fd; + } + } + fd_num++; +} + +int +cl_commander::input_avail(void) +{ + struct timeval tv = {0, 0}; + active_set = read_set; + + int i = select(fd_num, &active_set, NULL, NULL, &tv); + if (i < 0) + perror("select"); + + return i; +} + +int +cl_commander::wait_input(void) +{ + prompt(); + active_set = read_set; + int i = select(fd_num, &active_set, NULL, NULL, NULL); + return i; +} + +int +cl_commander::proc_input(void) +{ + for (int j = 0; j < cons->count; j++) + { + class cl_console *c = dynamic_cast((class cl_console_base*)(cons->at(j))); + + if (c->input_active()) + { + UCSOCKET_T fd = c->get_in_fd(); + assert(0 <= fd); + + if (FD_ISSET(fd, &active_set)) + { + actual_console = c; + int retval = c->proc_input(cmdset); + if (retval) + { + del_console(c); + delete c; + } + actual_console = 0; + return(0 == cons->count); + } + } + } + return 0; +} + + +/* End of cmd.src/newcmdposix.cc */ diff --git a/sim/ucsim/cmd.src/newcmdposixcl.h b/sim/ucsim/cmd.src/newcmdposixcl.h new file mode 100644 index 00000000..08501674 --- /dev/null +++ b/sim/ucsim/cmd.src/newcmdposixcl.h @@ -0,0 +1,121 @@ +/* + * Simulator of microcontrollers (cmd.src/newcmdposixcl.h) + * + * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. + * Copyright (C) 2006, Borut Razem - borut.razem@siol.net + * + * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu + * + */ + +/* This file is part of microcontroller simulator: ucsim. + +UCSIM is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +UCSIM is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with UCSIM; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. */ +/*@1@*/ + +#ifndef CMD_NEWCMDFDCL_HEADER +#define CMD_NEWCMDFDCL_HEADER + +#include "newcmdcl.h" +#include "cmdutil.h" + + +/* + * Command fd console + */ + +class cl_console: public cl_console_base +{ +protected: + FILE *in, *out, *rout/*redirected output*/; + +public: + cl_console(void) { in = out = rout = 0; } + cl_console(char *fin, char *fout, class cl_app *the_app); + cl_console(FILE *fin, FILE *fout, class cl_app *the_app); + int cmd_do_print(char *format, va_list ap); + + virtual ~cl_console(void); + virtual class cl_console *clone_for_exec(char *fin); + + virtual void redirect(char *fname, char *mode); + virtual void un_redirect(void); + virtual UCSOCKET_T get_in_fd(void) { return(in ? fileno(in) : -1); } + virtual bool is_tty(void) const { return in && isatty(fileno(in)); } + virtual bool is_eof(void) const { return in ? feof(in) : true; } + virtual bool input_avail(void) { return input_active() ? ::input_avail(fileno(in)) : false; }; + virtual char *read_line(void); + +private: + FILE *get_out(void) { return rout ? rout : out; } +}; + +#ifdef SOCKET_AVAIL +class cl_listen_console: public cl_console +{ +private: + int sock; + +public: + cl_listen_console(int serverport, class cl_app *the_app); + + virtual void welcome(void) {} + + virtual UCSOCKET_T get_in_fd(void) { return(sock); } + virtual int proc_input(class cl_cmdset *cmdset); +}; +#endif + + +class cl_sub_console: public cl_console +{ +private: + class cl_console_base *parent; + +public: + cl_sub_console(class cl_console_base *the_parent, + FILE *fin, FILE *fout, class cl_app *the_app); + virtual ~cl_sub_console(void); + virtual int init(void); +}; + + +/* + * Command interpreter + */ + +class cl_commander: public cl_commander_base +{ +private: + fd_set read_set, active_set; + UCSOCKET_T fd_num; + +public: + cl_commander(class cl_app *the_app, class cl_cmdset *acmdset) + : cl_commander_base(the_app, acmdset) + { + } + + virtual int init(void); + virtual void set_fd_set(void); + virtual int input_avail(void); + virtual int wait_input(void); + virtual int proc_input(void); +}; + +#endif + +/* End of cmd.src/newcmdposixcl.h */ diff --git a/sim/ucsim/cmd.src/newcmdwin32.cc b/sim/ucsim/cmd.src/newcmdwin32.cc new file mode 100644 index 00000000..d49b6d17 --- /dev/null +++ b/sim/ucsim/cmd.src/newcmdwin32.cc @@ -0,0 +1,636 @@ +/* + * Simulator of microcontrollers (cmd.src/newcmdwin32.cc) + * + * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. + * Copyright (C) 2006, Borut Razem - borut.razem@siol.net + * + * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu + * + */ + +/* This file is part of microcontroller simulator: ucsim. + +UCSIM is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +UCSIM is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with UCSIM; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. */ +/*@1@*/ + +#include "ddconfig.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "i_string.h" + +#include "cmdlexcl.h" +#include "cmdpars.h" + +// prj +#include "globals.h" +#include "utils.h" + +// sim +#include "simcl.h" +#include "argcl.h" +#include "appcl.h" + +// local +#include "newcmdwin32cl.h" + + +/* + * Channel + *____________________________________________________________________________ + */ + +inline void +cl_channel::set(void) +{ + fp = 0; + handle = INVALID_HANDLE_VALUE; + type = CH_UNDEF; +} + +inline void +cl_channel::set(HANDLE _handle, e_handle_type _type) +{ + assert(INVALID_HANDLE_VALUE != _handle); + + fp = 0; + handle = _handle; + type = (_type == CH_UNDEF) ? guess_type() : _type; +} + +inline void +cl_channel::set(FILE *_fp, e_handle_type _type) +{ + assert(_fp); + fp = _fp; + handle = (HANDLE)_get_osfhandle(fileno(fp)); + assert(INVALID_HANDLE_VALUE != handle); + type = (_type == CH_UNDEF) ? guess_type() : _type; +} + +void +cl_channel::close(void) +{ + assert(INVALID_HANDLE_VALUE != handle); + + if (CH_SOCKET == type) + { + shutdown((SOCKET)handle, SD_BOTH); + closesocket((SOCKET)handle); + } + if (fp) + fclose(fp); + else if (CH_SOCKET != type) + CloseHandle(handle); + + fp = 0; + handle = INVALID_HANDLE_VALUE; + type = CH_UNDEF; +} + +/* + * Command console + *____________________________________________________________________________ + */ + +cl_console::cl_console(char *fin, char *fout, class cl_app *the_app) +{ + FILE *f; + + app = the_app; + if (fin) + { + if (!(f = fopen(fin, "r"))) + fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno)); + in.set(f, CH_FILE); + } + + if (fout) + { + if (!(f = fopen(fout, "w"))) + fprintf(stderr, "Can't open `%s': %s\n", fout, strerror(errno)); + out.set(f, CH_FILE); + } + + prompt = 0; + flags = CONS_NONE; + if (in.is_tty()) + flags |= CONS_INTERACTIVE; + else + ;//fprintf(stderr, "Warning: non-interactive console\n"); + id = 0; + lines_printed = new cl_ustrings(100, 100, "console_cache"); +} + +cl_console::cl_console(FILE *fin, FILE *fout, class cl_app *the_app) +{ + app = the_app; + in.set(fin); + out.set(fout); + + prompt = 0; + flags = CONS_NONE; + if (in.is_tty()) + flags |= CONS_INTERACTIVE; + else + ;//fprintf(stderr, "Warning: non-interactive console\n"); + id = 0; + lines_printed = new cl_ustrings(100, 100, "console_cache"); +} + +cl_console::cl_console(cl_channel _in, cl_channel _out, class cl_app *the_app) +{ + app = the_app; + in = _in; + out = _out; + + prompt = 0; + flags = CONS_NONE; + if (in.is_tty()) + flags |= CONS_INTERACTIVE; + else + ;//fprintf(stderr, "Warning: non-interactive console\n"); + id = 0; + lines_printed= new cl_ustrings(100, 100, "console_cache"); +} + +class cl_console * +cl_console::clone_for_exec(char *fin) +{ + FILE *fi; + if (!fin) + return 0; + + if (!(fi = fopen(fin, "r"))) + { + fprintf(stderr, "Can't open `%s': %s\n", fin, strerror(errno)); + return 0; + } + cl_channel ch_in = cl_channel(fi, CH_FILE); + class cl_console *con= new cl_sub_console(this, ch_in, out, app); + return con; +} + +cl_console::~cl_console(void) +{ + if (CH_UNDEF != in.get_type()) + in.close(); + un_redirect(); + if (CH_UNDEF != out.get_type()) + { + if (flags & CONS_PROMPT) + dd_printf("\n"); + out.close(); + } + delete prompt_option; + delete null_prompt_option; + delete debug_option; +} + + +/* + * Output functions + */ + +void +cl_console::redirect(char *fname, char *mode) +{ + FILE *fp = fopen(fname, mode); + if (!fp) + dd_printf("Unable to open file '%s' for %s: %s\n", + fname, (mode[0]=='w') ? "write" : "append", strerror(errno)); + out.set(fp, CH_FILE); +} + +void +cl_console::un_redirect(void) +{ + if (CH_UNDEF != rout.get_type()) + out.close(); +} + +int +cl_console::cmd_do_print(char *format, va_list ap) +{ + FILE *f = get_out()->get_fp(); + + if (f) + { + int ret = vfprintf(f, format, ap); + fflush(f); + return ret; + } + else + return 0; +} + +/* + * Input functions + */ + +char * +cl_console::read_line(void) +{ +#define BUF_LEN 1024 + + TRACE("%d-%s\n", get_id(), __PRETTY_FUNCTION__); + + char *s = NULL; + FILE *fp = in.get_fp(); + assert(fp); + +#ifdef HAVE_GETLINE + if (getline(&s, 0, fp) < 0) + return(0); +#elif defined HAVE_GETDELIM + size_t n = BUF_LEN; + s = (char *)malloc(n); + if (getdelim(&s, &n, '\n', fp) < 0) + { + free(s); + return(0); + } +#elif defined HAVE_FGETS + s = (char *)malloc(BUF_LEN); + if (fgets(s, BUF_LEN, fp) == NULL) + { + free(s); + return(0); + } +#endif + s[strlen(s)-1]= '\0'; + if (s[strlen(s)-1] == '\r') + s[strlen(s)-1]= '\0'; + flags&= ~CONS_PROMPT; + return(s); +} + + +/* + * This console cl_listen_console on a socket and can accept connection requests + */ + +cl_listen_console::cl_listen_console(int serverport, class cl_app *the_app) +{ + SOCKET sock; + app = the_app; + + if (INVALID_SOCKET != (sock = make_server_socket(serverport))) + { + if (SOCKET_ERROR == listen(sock, 10)) + fprintf(stderr, "Can't listen on port %d: %d\n", serverport, WSAGetLastError()); + } + in.set((HANDLE)sock, CH_SOCKET); +} + +int +cl_listen_console::proc_input(class cl_cmdset *cmdset) +{ + class cl_commander_base *cmd = app->get_commander(); + + struct sockaddr_in sock_addr; + ACCEPT_SOCKLEN_T size = sizeof(struct sockaddr); + SOCKET newsock = accept((SOCKET)get_in_fd(), (struct sockaddr*)&sock_addr, &size); + + if (INVALID_SOCKET == newsock) + { + fprintf(stderr, "Can't accept: %d\n", WSAGetLastError()); + return(0); + } + + int fh = _open_osfhandle((intptr_t)newsock, _O_TEXT); + if (-1 == fh) + { + fprintf(stderr, "Can't _open_osfhandle\n"); + } + FILE *fp = fdopen(fh, "r"); + if (!fp) + fprintf(stderr, "Can't open port for input\n"); + cl_channel ch_in = cl_channel(fp, CH_SOCKET); + + fh = _open_osfhandle((intptr_t)newsock, _O_TEXT); + if (-1 == fh) + { + fprintf(stderr, "Can't _open_osfhandle\n"); + } + fp = fdopen(fh, "w"); + if (!fp) + fprintf(stderr, "Can't open port for output\n"); + cl_channel ch_out = cl_channel(fp, CH_SOCKET); + + class cl_console_base *c = new cl_console(ch_in, ch_out, app); + c->flags |= CONS_INTERACTIVE; + cmd->add_console(c); + + return 0; +} + + +/* + * Sub-console + */ + +cl_sub_console::cl_sub_console(class cl_console_base *the_parent, + cl_channel _in, cl_channel _out, class cl_app *the_app): + cl_console(_in, _out, the_app) +{ + parent = the_parent; +} + +cl_sub_console::~cl_sub_console(void) +{ + class cl_commander_base *c = app->get_commander(); + + if (parent && c) + { + c->activate_console(parent); + } +} + +int +cl_sub_console::init(void) +{ + class cl_commander_base *c = app->get_commander(); + + if (parent && c) + { + c->deactivate_console(parent); + } + cl_console::init(); + flags |= CONS_ECHO; + return 0; +} + + +/* + * Command interpreter + *____________________________________________________________________________ + */ + +int +cl_commander::init(void) +{ + TRACE("%s\n", __PRETTY_FUNCTION__); + + class cl_optref console_on_option(this); + class cl_optref config_file_option(this); + class cl_optref port_number_option(this); + class cl_console_base *con; + + console_on_option.init(); + console_on_option.use("console_on"); + config_file_option.init(); + config_file_option.use("config_file"); + port_number_option.init(); + + cl_base::init(); + set_name("Commander"); + + bool need_config = DD_TRUE; + + if (port_number_option.use("port_number")) + add_console(new cl_listen_console(port_number_option.get_value((long)0), app)); + + /* The following code is commented out because it produces gcc warnings + * newcmd.cc: In member function `virtual int cl_commander::init()': + * newcmd.cc:785: warning: 'Config' might be used uninitialized in this function + * newcmd.cc:786: warning: 'cn' might be used uninitialized in this function + */ + /* + char *Config= config_file_option.get_value(Config); + char *cn= console_on_option.get_value(cn); + */ + /* Here shoud probably be something else, but is still better then the former code... */ + char *Config = config_file_option.get_value(""); + char *cn = console_on_option.get_value(""); + + if (cn) + { + add_console(con = new cl_console(cn, cn, app)); + exec_on(con, Config); + need_config = DD_FALSE; + } + if (cons->get_count() == 0) + { + add_console(con = new cl_console(stdin, stdout, app)); + exec_on(con, Config); + need_config = DD_FALSE; + } + if (need_config && Config && *Config) + { + FILE *fc = fopen(Config, "r"); + if (!fc) + fprintf(stderr, "Can't open `%s': %s\n", Config, strerror(errno)); + else + { + con = new cl_console(fc, stderr, app); + con->flags |= CONS_NOWELCOME | CONS_ECHO; + add_console(con); + } + } + return(0); +} + +void +cl_commander::set_fd_set(void) +{ + TRACE("%s\n", __PRETTY_FUNCTION__); + + int i; + + FD_ZERO(&read_set); + + for (i = 0; i < cons->count; i++) + { + class cl_console *c= dynamic_cast((class cl_console_base*)(cons->at(i))); + + if (c->input_active() && CH_SOCKET == c->in.get_type()) + { + HANDLE fd = c->get_in_fd(); + assert(INVALID_HANDLE_VALUE != fd); + + FD_SET((SOCKET)fd, &read_set); + } + } +} + +int +cl_commander::console_count(void) +{ + int i = 0; + + for (int j = 0; j < cons->count; j++) + { + class cl_console *c = dynamic_cast((class cl_console_base*)(cons->at(j))); + + if (c->input_active()) + { + switch (c->in.get_type()) + { + case CH_CONSOLE: + case CH_FILE: + case CH_SERIAL: + ++i; + break; + + default: + break; + } + } + } + + return i; +} + +int +cl_commander::console_input_avail(void) +{ + int i = 0; + + FD_ZERO(&console_active_set); + for (int j = 0; j < cons->count; j++) + { + class cl_console *c = dynamic_cast((class cl_console_base*)(cons->at(j))); + + if (c->input_avail()) + { + HANDLE fd = c->get_in_fd(); + assert(INVALID_HANDLE_VALUE != fd); + + switch (c->in.get_type()) + { + case CH_CONSOLE: + case CH_FILE: + case CH_SERIAL: + FD_SET((SOCKET)fd, &console_active_set); + ++i; + break; + + default: + break; + } + } + } + + return i; +} + +int +cl_commander::socket_input_avail(long timeout, bool sleep) +{ + active_set = read_set; + + if (active_set.fd_count) + { + struct timeval tv = {0, 0}; + + struct timeval *tvp = sleep ? NULL : &tv; + + int i = select(0, &active_set, NULL, NULL, tvp); + if (SOCKET_ERROR == i) + { + fprintf(stderr, "Can't select: %d\n", WSAGetLastError()); + return 0; + } + + return i; + } + else + { + Sleep(timeout / 1000); + return 0; + } +} + +int +cl_commander::input_avail_timeout(long timeout) +{ + TRACE("%s\n", __PRETTY_FUNCTION__); + + int n; + if (0 != (n = console_input_avail())) + FD_ZERO(&active_set); + else + n = socket_input_avail(timeout, false); + + return n; +} + +#define CONSOLE_TIMEOUT 300000 + +int +cl_commander::wait_input(void) +{ + TRACE("%s\n", __PRETTY_FUNCTION__); + + prompt(); + + if (0 < console_count()) + { + int n; + + while (0 == (n = input_avail_timeout(CONSOLE_TIMEOUT))) + ; + + return n; + } + else + { + FD_ZERO(&console_active_set); + return socket_input_avail(0, true); + } +} + +int +cl_commander::proc_input(void) +{ + TRACE("%s\n", __PRETTY_FUNCTION__); + + for (int j = 0; j < cons->count; j++) + { + class cl_console *c = dynamic_cast((class cl_console_base*)(cons->at(j))); + + if (c->input_active()) + { + HANDLE fd = c->get_in_fd(); + assert(INVALID_HANDLE_VALUE != fd); + + if (FD_ISSET(fd, &active_set) || FD_ISSET(fd, &console_active_set)) + { + actual_console = c; + if (c->proc_input(cmdset)) + { + del_console(c); + delete c; + } + actual_console = 0; + return 0 == cons->count; + } + } + } + return 0; +} + + +/* End of cmd.src/newcmdwin32.cc */ diff --git a/sim/ucsim/cmd.src/newcmdwin32cl.h b/sim/ucsim/cmd.src/newcmdwin32cl.h new file mode 100644 index 00000000..522a89c8 --- /dev/null +++ b/sim/ucsim/cmd.src/newcmdwin32cl.h @@ -0,0 +1,150 @@ +/* + * Simulator of microcontrollers (cmd.src/newcmdwin32cl.h) + * + * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. + * Copyright (C) 2006, Borut Razem - borut.razem@siol.net + * + * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu + * + */ + +/* This file is part of microcontroller simulator: ucsim. + +UCSIM is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +UCSIM is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with UCSIM; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. */ +/*@1@*/ + +#ifndef CMD_NEWCMDFDCL_HEADER +#define CMD_NEWCMDFDCL_HEADER + +#include "newcmdcl.h" +#include "cmdutil.h" + + +class cl_channel +{ +public: + cl_channel(void) { set(); } + cl_channel(HANDLE _handle, e_handle_type _type = CH_UNDEF) { set(_handle, _type); } + cl_channel(FILE *_fp, e_handle_type _type = CH_UNDEF) { set(_fp, _type); } + + void set(void); + void set(HANDLE _handle, e_handle_type _type = CH_UNDEF); + void set(FILE *_fp, e_handle_type _type = CH_UNDEF); + + void close(void); + bool input_avail(void) const { return ::input_avail(handle, type); } + enum e_handle_type get_type(void) const { return type; } + HANDLE get_handle(void) const { return handle; } + FILE *get_fp(void) const { return fp; } + bool is_tty(void) const { return CH_FILE != type; } + bool is_eof(void) const { return get_fp() ? feof(get_fp()) : true; } + +private: + e_handle_type guess_type(void) { return get_handle_type(handle); } + + e_handle_type type; + HANDLE handle; + FILE *fp; +}; + + +/* + * Command socket console + */ + +class cl_console: public cl_console_base +{ + friend class cl_commander; + +protected: + cl_channel in, out, rout/*redirected output*/; + +public: + cl_console(void) { in = cl_channel(); out = cl_channel(); rout = cl_channel(); } + cl_console(char *fin, char *fout, class cl_app *the_app); + cl_console(FILE *fin, FILE *fout, class cl_app *the_app); + cl_console(cl_channel _in, cl_channel _out, class cl_app *the_app); + + int cmd_do_print(char *format, va_list ap); + + virtual ~cl_console(void); + virtual class cl_console *clone_for_exec(char *fin); + + virtual void redirect(char *fname, char *mode); + virtual void un_redirect(void); + virtual bool is_tty(void) const { return CH_FILE != in.get_type(); } + virtual bool is_eof(void) const { return in.is_eof(); } + virtual HANDLE get_in_fd(void) { return in.get_handle(); } + virtual bool input_avail(void) { return input_active() ? in.input_avail() : false; } + virtual char *read_line(void); + +private: + class cl_channel *get_out(void) { return (CH_UNDEF != rout.get_type()) ? &rout : &out; } +}; + +class cl_listen_console: public cl_console +{ +public: + cl_listen_console(int serverport, class cl_app *the_app); + + virtual void welcome(void) {} + virtual int proc_input(class cl_cmdset *cmdset); +}; + +class cl_sub_console: public cl_console +{ +private: + class cl_console_base *parent; + +public: + cl_sub_console(class cl_console_base *the_parent, + cl_channel _in, cl_channel _out, class cl_app *the_app); + virtual ~cl_sub_console(void); + virtual int init(void); +}; + + +/* + * Command interpreter + */ + +class cl_commander: public cl_commander_base +{ +private: + fd_set read_set, active_set, console_active_set; + +public: + cl_commander(class cl_app *the_app, class cl_cmdset *acmdset) + : cl_commander_base(the_app, acmdset) + { + } + + virtual int init(void); + virtual void set_fd_set(void); + virtual int input_avail(void) { return input_avail_timeout(0); } + virtual int wait_input(void); + virtual int proc_input(void); + +private: + int console_count(void); + int console_input_avail(void); + int socket_input_avail(long timeout, bool sleep); + int input_avail_timeout(long timeout); +}; + +#endif + +/* End of cmd.src/newcmdwin32cl.h */ diff --git a/sim/ucsim/cmd.src/set.cc b/sim/ucsim/cmd.src/set.cc index 5fd6ceaa..dc5cbb76 100644 --- a/sim/ucsim/cmd.src/set.cc +++ b/sim/ucsim/cmd.src/set.cc @@ -51,14 +51,14 @@ //int //cl_set_mem_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_set_mem_cmd) { class cl_memory *mem= 0; class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; if (cmdline->syntax_match(uc, MEMORY ADDRESS DATALIST)) { mem= params[0]->value.memory.memory; @@ -70,17 +70,17 @@ COMMAND_DO_WORK_UC(cl_set_mem_cmd) con->dd_printf("Error: no data\n"); else if (start < mem->get_start_address()) con->dd_printf("Start address less then 0x%"_A_"x\n", - mem->get_start_address()); + mem->get_start_address()); else { - int i; - t_addr addr; - for (i= 0, addr= start; - i < len && mem->valid_address(addr); - i++, addr++) - mem->write(addr, array[i]); - uc->check_errors(); - mem->dump(start, start+len-1, 8, con); + int i; + t_addr addr; + for (i= 0, addr= start; + i < len && mem->valid_address(addr); + i++, addr++) + mem->write(addr, array[i]); + uc->check_errors(); + mem->dump(start, start+len-1, 8, con); } } else @@ -97,16 +97,16 @@ COMMAND_DO_WORK_UC(cl_set_mem_cmd) //int //cl_set_bit_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_set_bit_cmd) { class cl_memory *mem; t_addr mem_addr= 0; t_mem bit_mask= 0; class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; if (cmdline->syntax_match(uc, BIT NUMBER)) { mem= params[0]->value.bit.mem; @@ -134,9 +134,9 @@ COMMAND_DO_WORK_UC(cl_set_hw_cmd) { class cl_hw *hw= 0; class cl_cmd_arg *params[1]= { cmdline->param(0)/*, - cmdline->param(1), - cmdline->param(2), - cmdline->param(3)*/ }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3)*/ }; if (params[0] && /*cmdline->syntax_match(uc, HW)*/params[0]->as_hw(uc)) { hw= params[0]->value.hw; @@ -156,12 +156,12 @@ COMMAND_DO_WORK_UC(cl_set_hw_cmd) else*/ { if (hw) - { - cmdline->shift(); - hw->set_cmd(cmdline, con); - } + { + cmdline->shift(); + hw->set_cmd(cmdline, con); + } else - con->dd_printf("Error: no hw\n"); + con->dd_printf("Error: no hw\n"); } return(DD_FALSE);; } @@ -174,15 +174,15 @@ COMMAND_DO_WORK_UC(cl_set_hw_cmd) //int //cl_set_option_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_APP(cl_set_option_cmd) { char *id= 0, *s= 0; int idx; class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; class cl_option *option= 0; if (cmdline->syntax_match(0/*app->get_uc()*/, NUMBER STRING)) { @@ -197,15 +197,15 @@ COMMAND_DO_WORK_APP(cl_set_option_cmd) int n= app->options->nuof_options(id, cr); if (n > 1) { - con->dd_printf("Ambiguous option name, use number instead\n"); - return(DD_FALSE); + con->dd_printf("Ambiguous option name, use number instead\n"); + return(DD_FALSE); } else if (n == 0) ;//con->dd_printf("Named option does not exist\n"); else { - if ((option= app->options->get_option(id, cr)) == 0) - option= app->options->get_option(cr, id); + if ((option= app->options->get_option(id, cr)) == 0) + option= app->options->get_option(cr, id); } } else if (cmdline->syntax_match(0/*app->get_uc()*/, STRING STRING)) { @@ -214,8 +214,8 @@ COMMAND_DO_WORK_APP(cl_set_option_cmd) int n= app->options->nuof_options(id); if (n > 1) { - con->dd_printf("Ambiguous option name, use number instead\n"); - return(DD_FALSE); + con->dd_printf("Ambiguous option name, use number instead\n"); + return(DD_FALSE); } else if (n == 0) ;//con->dd_printf("Named option does not exist\n"); @@ -243,13 +243,13 @@ COMMAND_DO_WORK_APP(cl_set_option_cmd) //int //cl_set_option_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_APP(cl_set_error_cmd) { class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; char *error_name= NIL, *value= NIL; if (cmdline->syntax_match(0/*app->get_uc()*/, STRING STRING)) { @@ -266,26 +266,26 @@ COMMAND_DO_WORK_APP(cl_set_error_cmd) { int i; for (i= 0; i < registered_errors->count; i++) - { - class cl_error_class *e= - dynamic_cast(registered_errors->object_at(i)); - if (e->is_inamed(error_name)) - { - if (strchr("uU-?", *value) != NULL) - e->set_on(ERROR_PARENT); - else if (strchr("1tTyY", *value) != NULL || - (strlen(value) > 1 && - strchr("nN", value[2]) != NULL)) - e->set_on(ERROR_ON); - else if (strchr("0fFnN", *value) != NULL || - (strlen(value) > 1 && - strchr("fF", value[2]) != NULL)) - e->set_on(ERROR_OFF); - else - con->dd_printf("Bad value (%s)\n", value); - return(DD_FALSE); - } - } + { + class cl_error_class *e= + dynamic_cast(registered_errors->object_at(i)); + if (e->is_inamed(error_name)) + { + if (strchr("uU-?", *value) != NULL) + e->set_on(ERROR_PARENT); + else if (strchr("1tTyY", *value) != NULL || + (strlen(value) > 1 && + strchr("nN", value[2]) != NULL)) + e->set_on(ERROR_ON); + else if (strchr("0fFnN", *value) != NULL || + (strlen(value) > 1 && + strchr("fF", value[2]) != NULL)) + e->set_on(ERROR_OFF); + else + con->dd_printf("Bad value (%s)\n", value); + return(DD_FALSE); + } + } } con->dd_printf("Error %s not found\n", error_name); diff --git a/sim/ucsim/cmd.src/show.cc b/sim/ucsim/cmd.src/show.cc index 8cd41186..9ef2c66e 100644 --- a/sim/ucsim/cmd.src/show.cc +++ b/sim/ucsim/cmd.src/show.cc @@ -49,7 +49,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA //int //cl_show_copying_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK(cl_show_copying_cmd) { con->dd_printf("%s\n", copying); @@ -64,7 +64,7 @@ COMMAND_DO_WORK(cl_show_copying_cmd) //int //cl_show_warranty_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK(cl_show_warranty_cmd) { con->dd_printf("%s\n", warranty); @@ -94,34 +94,34 @@ COMMAND_DO_WORK_APP(cl_show_option_cmd) { class cl_option *o= (class cl_option *)(/*uc*/app->options->at(i)); if (!s || - !strcmp(s, o->get_name())) - { - int j; - con->dd_printf("%d. %s: ", i, object_name(o)); - o->print(con); - con->dd_printf(" - %s\n", o->help); - con->dd_printf(" Type: %s\n", o->get_type_name()); - /*union option_value *val= o->get_value(); - con->dd_printf(" Value: \""); - unsigned int uj; - TYPE_UBYTE *d= (TYPE_UBYTE*)val; - for (uj= 0; uj < sizeof(*val); uj++) - con->print_char_octal(d[uj]); - con->dd_printf("\"\n");*/ - con->dd_printf(" Hidden: %s\n", (o->hidden)?"True":"False"); - con->dd_printf(" Creator: \"%s\"\n %d Users:\n", - object_name(o->get_creator()), - o->users->count); - for (j= 0; j < o->users->count; j++) - { - class cl_optref *r= (class cl_optref *)(o->users->at(j)); - con->dd_printf(" %2d. owner(s)=\"%s\"\n", j, - object_name(r->get_owner())); - } - if (i >= 0 && - i < app->options->count-1) - con->dd_printf("\n"); - } + !strcmp(s, o->get_name())) + { + int j; + con->dd_printf("%d. %s: ", i, object_name(o)); + o->print(con); + con->dd_printf(" - %s\n", o->help); + con->dd_printf(" Type: %s\n", o->get_type_name()); + /*union option_value *val= o->get_value(); + con->dd_printf(" Value: \""); + unsigned int uj; + TYPE_UBYTE *d= (TYPE_UBYTE*)val; + for (uj= 0; uj < sizeof(*val); uj++) + con->print_char_octal(d[uj]); + con->dd_printf("\"\n");*/ + con->dd_printf(" Hidden: %s\n", (o->hidden)?"True":"False"); + con->dd_printf(" Creator: \"%s\"\n %d Users:\n", + object_name(o->get_creator()), + o->users->count); + for (j= 0; j < o->users->count; j++) + { + class cl_optref *r= (class cl_optref *)(o->users->at(j)); + con->dd_printf(" %2d. owner(s)=\"%s\"\n", j, + object_name(r->get_owner())); + } + if (i >= 0 && + i < app->options->count-1) + con->dd_printf("\n"); + } } return(DD_FALSE); @@ -132,8 +132,8 @@ COMMAND_DO_WORK_APP(cl_show_option_cmd) #include "errorcl.h" static void -show_error_cmd_print_node(class cl_console *con, - int indent, class cl_base *node) +show_error_cmd_print_node(class cl_console_base *con, + int indent, class cl_base *node) { if (!node) return; @@ -144,10 +144,10 @@ show_error_cmd_print_node(class cl_console *con, class cl_error_class *ec= dynamic_cast(node); char *str; con->dd_printf("%s: %s [%s/%s]\n", - str= case_string(case_case, ec->get_type_name()), - name, get_id_string(error_on_off_names, - ec->get_on()), - (ec->is_on())?"ON":"OFF"); + str= case_string(case_case, ec->get_type_name()), + name, get_id_string(error_on_off_names, + ec->get_on()), + (ec->is_on())?"ON":"OFF"); free(str); class cl_base *c= node->first_child(); while (c) @@ -181,7 +181,7 @@ COMMAND_DO_WORK_APP(cl_show_error_cmd) class cl_error_class *ec; ec= dynamic_cast(registered_errors->object_at(i)); if (!ec->get_parent()) - show_error_cmd_print_node(con, 0, ec); + show_error_cmd_print_node(con, 0, ec); } return(DD_FALSE); } diff --git a/sim/ucsim/cmd.src/timer.cc b/sim/ucsim/cmd.src/timer.cc index e029c49b..3f8ad9d7 100644 --- a/sim/ucsim/cmd.src/timer.cc +++ b/sim/ucsim/cmd.src/timer.cc @@ -44,13 +44,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA //int //cl_timer_cmd::do_work(class cl_sim *sim, -// class cl_cmdline *cmdline, class cl_console *con) +// class cl_cmdline *cmdline, class cl_console_base *con) COMMAND_DO_WORK_UC(cl_timer_cmd) { class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; if (!params[0]) { @@ -62,11 +62,11 @@ COMMAND_DO_WORK_UC(cl_timer_cmd) as_nr= DD_TRUE; id_nr= params[0]->value.number; if (id_nr <= 0) - { - con->dd_printf("Error: " - "Timer id must be greater than zero or a string\n"); - return(DD_TRUE); - } + { + con->dd_printf("Error: " + "Timer id must be greater than zero or a string\n"); + return(DD_TRUE); + } ticker= uc->get_counter(id_nr); } else @@ -87,12 +87,12 @@ COMMAND_DO_WORK_UC(cl_timer_cmd) */ COMMAND_DO_WORK_UC(cl_timer_add_cmd) - //add(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con) + //add(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con) { class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; long dir= +1, in_isr= 0; if (cl_timer_cmd::do_work(uc, cmdline, con)) @@ -100,21 +100,21 @@ COMMAND_DO_WORK_UC(cl_timer_add_cmd) if (ticker) { if (!as_nr) - con->dd_printf("Error: Timer \"%s\" already exists\n", id_str); + con->dd_printf("Error: Timer \"%s\" already exists\n", id_str); else - con->dd_printf("Error: Timer %d already exists\n", id_nr); + con->dd_printf("Error: Timer %d already exists\n", id_nr); return(DD_FALSE); } if (cmdline->nuof_params() > 0) { if (cmdline->syntax_match(uc, NUMBER)) - dir= params[0]->value.number; + dir= params[0]->value.number; else if (cmdline->syntax_match(uc, NUMBER NUMBER)) - { - dir= params[0]->value.number; - in_isr= params[1]->value.number; - } + { + dir= params[0]->value.number; + in_isr= params[1]->value.number; + } } if (!as_nr) @@ -138,16 +138,16 @@ COMMAND_DO_WORK_UC(cl_timer_add_cmd) */ COMMAND_DO_WORK_UC(cl_timer_delete_cmd) - //del(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con) + //del(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con) { if (cl_timer_cmd::do_work(uc, cmdline, con)) return(DD_FALSE); if (!ticker) { if (!as_nr) - con->dd_printf("Timer \"%s\" does not exist\n", id_str); + con->dd_printf("Timer \"%s\" does not exist\n", id_str); else - con->dd_printf("Timer %d does not exist\n", id_nr); + con->dd_printf("Timer %d does not exist\n", id_nr); return(DD_FALSE); } if (!as_nr) @@ -165,12 +165,12 @@ COMMAND_DO_WORK_UC(cl_timer_delete_cmd) */ COMMAND_DO_WORK_UC(cl_timer_get_cmd) - //get(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con) + //get(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con) { if (cmdline->nuof_params()) { if (cl_timer_cmd::do_work(uc, cmdline, con)) - return(DD_FALSE); + return(DD_FALSE); } else ticker= 0; @@ -182,11 +182,11 @@ COMMAND_DO_WORK_UC(cl_timer_get_cmd) uc->isr_ticks->dump(0, uc->xtal, con); uc->idle_ticks->dump(0, uc->xtal, con); for (id_nr= 0; id_nr < uc->counters->count; id_nr++) - { - ticker= uc->get_counter(id_nr); - if (ticker) - ticker->dump(id_nr, uc->xtal, con); - } + { + ticker= uc->get_counter(id_nr); + if (ticker) + ticker->dump(id_nr, uc->xtal, con); + } } return(DD_FALSE); @@ -199,16 +199,16 @@ COMMAND_DO_WORK_UC(cl_timer_get_cmd) */ COMMAND_DO_WORK_UC(cl_timer_run_cmd) - //run(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con) + //run(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con) { if (cl_timer_cmd::do_work(uc, cmdline, con)) return(DD_FALSE); if (!ticker) { if (!as_nr) - con->dd_printf("Timer %d does not exist\n", id_str); + con->dd_printf("Timer %d does not exist\n", id_str); else - con->dd_printf("Timer %d does not exist\n", id_nr); + con->dd_printf("Timer %d does not exist\n", id_nr); return(0); } ticker->options|= TICK_RUN; @@ -223,7 +223,7 @@ COMMAND_DO_WORK_UC(cl_timer_run_cmd) */ COMMAND_DO_WORK_UC(cl_timer_stop_cmd) - //stop(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con) + //stop(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con) { if (cl_timer_cmd::do_work(uc, cmdline, con)) return(DD_FALSE); @@ -231,9 +231,9 @@ COMMAND_DO_WORK_UC(cl_timer_stop_cmd) if (!ticker) { if (!as_nr) - con->dd_printf("Timer %d does not exist\n", id_str); + con->dd_printf("Timer %d does not exist\n", id_str); else - con->dd_printf("Timer %d does not exist\n", id_nr); + con->dd_printf("Timer %d does not exist\n", id_nr); return(DD_FALSE); } ticker->options&= ~TICK_RUN; @@ -249,21 +249,21 @@ COMMAND_DO_WORK_UC(cl_timer_stop_cmd) */ COMMAND_DO_WORK_UC(cl_timer_value_cmd) - //val(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console *con) + //val(class cl_uc *uc, class cl_cmdline *cmdline, class cl_console_base *con) { class cl_cmd_arg *params[4]= { cmdline->param(0), - cmdline->param(1), - cmdline->param(2), - cmdline->param(3) }; + cmdline->param(1), + cmdline->param(2), + cmdline->param(3) }; if (cl_timer_cmd::do_work(uc, cmdline, con)) return(DD_FALSE); if (!ticker) { if (!as_nr) - con->dd_printf("Error: Timer %d does not exist\n", id_str); + con->dd_printf("Error: Timer %d does not exist\n", id_str); else - con->dd_printf("Error: Timer %d does not exist\n", id_nr); + con->dd_printf("Error: Timer %d does not exist\n", id_nr); return(DD_FALSE); } if (params[2]) diff --git a/sim/ucsim/configure b/sim/ucsim/configure index 8c0ecfcf..628cd7d5 100755 --- a/sim/ucsim/configure +++ b/sim/ucsim/configure @@ -468,7 +468,7 @@ ac_includes_default="\ # include #endif" -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS AWK VERSION VERSIONHI VERSIONLO VERSIONP docdir enable_ucsim enable_dlso enable_51 enable_avr enable_z80 enable_hc08 enable_xa enable_serio CXX CXXFLAGS LDFLAGS CPPFLAGS ac_ct_CXX EXEEXT OBJEXT CXXCPP INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA RANLIB ac_ct_RANLIB STRIP build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS ac_ct_CC LN_S ECHO ac_ct_STRIP CPP EGREP LIBTOOL LIBTOOL_DEPS LEX LEXLIB LEX_OUTPUT_ROOT YACC BISON_PLUS_PLUS SERIAL_AVAIL dl_ok DL panel_ok curses_ok CURSES_LIBS M_OR_MM SHAREDLIB PICOPT dlso_ok LIBOBJS LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS AWK VERSION VERSIONHI VERSIONLO VERSIONP docdir enable_ucsim enable_dlso enable_51 enable_avr enable_z80 enable_hc08 enable_xa enable_serio CXX CXXFLAGS LDFLAGS CPPFLAGS ac_ct_CXX EXEEXT OBJEXT CXXCPP INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA RANLIB ac_ct_RANLIB STRIP build build_cpu build_vendor build_os host host_cpu host_vendor host_os CC CFLAGS ac_ct_CC LN_S ECHO ac_ct_STRIP CPP EGREP LIBTOOL LIBTOOL_DEPS LEX LEXLIB LEX_OUTPUT_ROOT YACC BISON_PLUS_PLUS WINSOCK_AVAIL dl_ok DL panel_ok curses_ok CURSES_LIBS M_OR_MM SHAREDLIB PICOPT dlso_ok LIBOBJS LTLIBOBJS' ac_subst_files='' # Initialize some variables set by options. @@ -8672,7 +8672,7 @@ fi fi if test ${LEX} = "flex"; then - cat >>confdefs.h <<\_ACEOF + cat >>confdefs.h <<\_ACEOF #define HAVE_FLEX 1 _ACEOF @@ -8939,157 +8939,9 @@ _ACEOF fi -for ac_header in getopt.h -do -as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 -else - # Is the header compilable? -echo "$as_me:$LINENO: checking $ac_header usability" >&5 -echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include <$ac_header> -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_cxx_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_header_compiler=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 -ac_header_compiler=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -echo "${ECHO_T}$ac_header_compiler" >&6 -# Is the header present? -echo "$as_me:$LINENO: checking $ac_header presence" >&5 -echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include <$ac_header> -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_cxx_preproc_warn_flag - ac_cpp_err=$ac_cpp_err$ac_cxx_werror_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - ac_header_preproc=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi -rm -f conftest.err conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -echo "${ECHO_T}$ac_header_preproc" >&6 - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_cxx_preproc_warn_flag in - yes:no: ) - { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 -echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 -echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 -echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 -echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 -echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 -echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 -echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} - { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 -echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} - ( - cat <<\_ASBOX -## ------------------------------------------ ## -## Report this to the AC_PACKAGE_NAME lists. ## -## ------------------------------------------ ## -_ASBOX - ) | - sed "s/^/$as_me: WARNING: /" >&2 - ;; -esac -echo "$as_me:$LINENO: checking for $ac_header" >&5 -echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 -if eval "test \"\${$as_ac_Header+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - eval "$as_ac_Header=\$ac_header_preproc" -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 - -fi -if test `eval echo '${'$as_ac_Header'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - -done - - -for ac_header in unistd.h +for ac_header in getopt.h unistd.h termios.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` if eval "test \"\${$as_ac_Header+set}\" = set"; then @@ -9239,157 +9091,6 @@ fi done -if test "${ac_cv_header_termios_h+set}" = set; then - echo "$as_me:$LINENO: checking for termios.h" >&5 -echo $ECHO_N "checking for termios.h... $ECHO_C" >&6 -if test "${ac_cv_header_termios_h+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -fi -echo "$as_me:$LINENO: result: $ac_cv_header_termios_h" >&5 -echo "${ECHO_T}$ac_cv_header_termios_h" >&6 -else - # Is the header compilable? -echo "$as_me:$LINENO: checking termios.h usability" >&5 -echo $ECHO_N "checking termios.h usability... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -$ac_includes_default -#include -_ACEOF -rm -f conftest.$ac_objext -if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 - (eval $ac_compile) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_cxx_werror_flag" - || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest.$ac_objext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - ac_header_compiler=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -ac_header_compiler=no -fi -rm -f conftest.err conftest.$ac_objext conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 -echo "${ECHO_T}$ac_header_compiler" >&6 - -# Is the header present? -echo "$as_me:$LINENO: checking termios.h presence" >&5 -echo $ECHO_N "checking termios.h presence... $ECHO_C" >&6 -cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -#include -_ACEOF -if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 - (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } >/dev/null; then - if test -s conftest.err; then - ac_cpp_err=$ac_cxx_preproc_warn_flag - ac_cpp_err=$ac_cpp_err$ac_cxx_werror_flag - else - ac_cpp_err= - fi -else - ac_cpp_err=yes -fi -if test -z "$ac_cpp_err"; then - ac_header_preproc=yes -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_header_preproc=no -fi -rm -f conftest.err conftest.$ac_ext -echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 -echo "${ECHO_T}$ac_header_preproc" >&6 - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_cxx_preproc_warn_flag in - yes:no: ) - { echo "$as_me:$LINENO: WARNING: termios.h: accepted by the compiler, rejected by the preprocessor!" >&5 -echo "$as_me: WARNING: termios.h: accepted by the compiler, rejected by the preprocessor!" >&2;} - { echo "$as_me:$LINENO: WARNING: termios.h: proceeding with the compiler's result" >&5 -echo "$as_me: WARNING: termios.h: proceeding with the compiler's result" >&2;} - ac_header_preproc=yes - ;; - no:yes:* ) - { echo "$as_me:$LINENO: WARNING: termios.h: present but cannot be compiled" >&5 -echo "$as_me: WARNING: termios.h: present but cannot be compiled" >&2;} - { echo "$as_me:$LINENO: WARNING: termios.h: check for missing prerequisite headers?" >&5 -echo "$as_me: WARNING: termios.h: check for missing prerequisite headers?" >&2;} - { echo "$as_me:$LINENO: WARNING: termios.h: see the Autoconf documentation" >&5 -echo "$as_me: WARNING: termios.h: see the Autoconf documentation" >&2;} - { echo "$as_me:$LINENO: WARNING: termios.h: section \"Present But Cannot Be Compiled\"" >&5 -echo "$as_me: WARNING: termios.h: section \"Present But Cannot Be Compiled\"" >&2;} - { echo "$as_me:$LINENO: WARNING: termios.h: proceeding with the preprocessor's result" >&5 -echo "$as_me: WARNING: termios.h: proceeding with the preprocessor's result" >&2;} - { echo "$as_me:$LINENO: WARNING: termios.h: in the future, the compiler will take precedence" >&5 -echo "$as_me: WARNING: termios.h: in the future, the compiler will take precedence" >&2;} - ( - cat <<\_ASBOX -## ------------------------------------------ ## -## Report this to the AC_PACKAGE_NAME lists. ## -## ------------------------------------------ ## -_ASBOX - ) | - sed "s/^/$as_me: WARNING: /" >&2 - ;; -esac -echo "$as_me:$LINENO: checking for termios.h" >&5 -echo $ECHO_N "checking for termios.h... $ECHO_C" >&6 -if test "${ac_cv_header_termios_h+set}" = set; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - ac_cv_header_termios_h=$ac_header_preproc -fi -echo "$as_me:$LINENO: result: $ac_cv_header_termios_h" >&5 -echo "${ECHO_T}$ac_cv_header_termios_h" >&6 - -fi -if test $ac_cv_header_termios_h = yes; then - cat >>confdefs.h <<\_ACEOF -#define HAVE_TERMIOS_H 1 -_ACEOF - - SERIAL_AVAIL=1 -else - SERIAL_AVAIL=0 - -fi - - - - if test "${ac_cv_header_curses_h+set}" = set; then echo "$as_me:$LINENO: checking for curses.h" >&5 echo $ECHO_N "checking for curses.h... $ECHO_C" >&6 @@ -9697,6 +9398,7 @@ fi +WINSOCK_AVAIL=0 if test $ucsim_cv_socket = unknown; then if test "${ac_cv_header_winsock2_h+set}" = set; then echo "$as_me:$LINENO: checking for winsock2.h" >&5 @@ -9849,12 +9551,14 @@ _ACEOF _ACEOF ucsim_cv_socket="" + WINSOCK_AVAIL=1 fi fi + if test $ucsim_cv_socket != unknown; then cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ @@ -10502,7 +10206,7 @@ _ACEOF # Checking for functions/libs # =========================================================================== if echo $ucsim_cv_socket|grep winsock2 >/dev/null 2>&1; then - LIBS="-lwsock32 $LIBS" + LIBS="-lws2_32 $LIBS" else echo "$as_me:$LINENO: checking for socket in -lsocket" >&5 @@ -11279,6 +10983,108 @@ fi done +for ac_func in _vsnprintf +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_cxx_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + for ac_func in vasprintf do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` @@ -12250,9 +12056,9 @@ esac else #echo "CROSS ENDIAN" if $CXX -v 2>&1|grep "mingw" >/dev/null 2>&1; then - ac_cv_c_bigendian=no + ac_cv_c_bigendian=no else - : # FIXME + : # FIXME fi #echo "CROSS ENDIAN DONE" fi @@ -12329,9 +12135,9 @@ else gopt="-g" fi if test "$CXXFLAGS"x = x ;then - CXXFLAGS="$gopt" + CXXFLAGS="$gopt" else - CXXFLAGS="$CXXFLAGS $gopt" + CXXFLAGS="$CXXFLAGS $gopt" fi @@ -12407,7 +12213,7 @@ echo "$as_me:$LINENO: result: $ucsim_cv_CXXfpic" >&5 echo "${ECHO_T}$ucsim_cv_CXXfpic" >&6 if test "$ucsim_cv_CXXfpic" = "yes"; then - PICOPT="-fpic" + PICOPT="-fpic" fi fi if test "$PICOPT"x != "x"; then @@ -14575,13 +14381,13 @@ _ACEOF else if $CXX -v 2>&1|grep "mingw" >/dev/null 2>&1; then - ac_cv_sizeof_char=1 - ac_cv_sizeof_short=2 - ac_cv_sizeof_int=4 - ac_cv_sizeof_long=4 - ac_cv_sizeof_long_long=4 + ac_cv_sizeof_char=1 + ac_cv_sizeof_short=2 + ac_cv_sizeof_int=4 + ac_cv_sizeof_long=4 + ac_cv_sizeof_long_long=4 else - : # FIXME + : # FIXME fi #echo fi @@ -14589,24 +14395,24 @@ fi type_name() { if expr "$ac_cv_sizeof_char" '>=' "$1" >/dev/null; then - echo "char" - exit + echo "char" + exit fi if expr "$ac_cv_sizeof_short" '>=' "$1" >/dev/null; then - echo "short" - exit + echo "short" + exit fi if expr "$ac_cv_sizeof_int" '>=' "$1" >/dev/null; then - echo "int" - exit + echo "int" + exit fi if expr "$ac_cv_sizeof_long" '>=' "$1" >/dev/null; then - echo "long" - exit + echo "long" + exit fi if expr "$ac_cv_sizeof_long_long" '>=' "$1" >/dev/null; then - echo "long long" - exit + echo "long long" + exit fi echo "long long" } @@ -15340,7 +15146,7 @@ s,@LEXLIB@,$LEXLIB,;t t s,@LEX_OUTPUT_ROOT@,$LEX_OUTPUT_ROOT,;t t s,@YACC@,$YACC,;t t s,@BISON_PLUS_PLUS@,$BISON_PLUS_PLUS,;t t -s,@SERIAL_AVAIL@,$SERIAL_AVAIL,;t t +s,@WINSOCK_AVAIL@,$WINSOCK_AVAIL,;t t s,@dl_ok@,$dl_ok,;t t s,@DL@,$DL,;t t s,@panel_ok@,$panel_ok,;t t diff --git a/sim/ucsim/configure.in b/sim/ucsim/configure.in index e2c137df..2dae014c 100644 --- a/sim/ucsim/configure.in +++ b/sim/ucsim/configure.in @@ -118,7 +118,7 @@ AC_SUBST(LIBTOOL_DEPS) AC_PROG_LEX if test ${LEX} = "flex"; then - AC_DEFINE(HAVE_FLEX) + AC_DEFINE(HAVE_FLEX) fi AC_PROG_YACC AC_CHECK_PROG(BISON_PLUS_PLUS, bison++, bison++, :) @@ -134,15 +134,7 @@ if test -d /stuff/include; then fi AC_HEADER_STDC -AC_CHECK_HEADERS(getopt.h) -AC_CHECK_HEADERS(unistd.h) - -AC_CHECK_HEADER(termios.h, - AC_DEFINE(HAVE_TERMIOS_H) - SERIAL_AVAIL=1, - SERIAL_AVAIL=0 -) -AC_SUBST(SERIAL_AVAIL) +AC_CHECK_HEADERS(getopt.h unistd.h termios.h) AC_CHECK_HEADER(curses.h, AC_DEFINE(HAVE_CURSES_H) @@ -158,14 +150,17 @@ AC_CHECK_HEADER(sys/socket.h, ucsim_cv_socket="" ) +WINSOCK_AVAIL=0 if test $ucsim_cv_socket = unknown; then AC_CHECK_HEADER(winsock2.h, AC_DEFINE(HAVE_WINSOCK2_H) AC_DEFINE(SOCKET_AVAIL) AC_DEFINE_UNQUOTED(UCSOCKET_T, SOCKET) ucsim_cv_socket="" + WINSOCK_AVAIL=1 ) fi +AC_SUBST(WINSOCK_AVAIL) if test $ucsim_cv_socket != unknown; then AC_EGREP_HEADER(socklen_t, @@ -236,7 +231,7 @@ AC_DEFINE_UNQUOTED(HEADER_FD, ${ucsim_cv_fd}) # Checking for functions/libs # =========================================================================== if echo $ucsim_cv_socket|grep winsock2 >/dev/null 2>&1; then - LIBS="-lwsock32 $LIBS" + LIBS="-lws2_32 $LIBS" else AC_CHECK_LIB(socket,socket) AC_CHECK_LIB(nsl,xdr_short) @@ -297,6 +292,7 @@ AC_SUBST(CURSES_LIBS) AC_FUNC_VPRINTF AC_CHECK_FUNCS(vsnprintf) +AC_CHECK_FUNCS(_vsnprintf) AC_CHECK_FUNCS(vasprintf) AC_CHECK_FUNCS(strlen strcpy strcat strstr strcmp strerror strtok strdup) AC_CHECK_FUNCS(strchr memcpy) @@ -404,7 +400,7 @@ if test "$CC" = "i586-mingw32msvc-gcc"; then ac_cv_c_bigendian=no ac_cv_sizeof_char=1 ac_cv_sizeof_short=2 - ac_cv_sizeof_int=4 + ac_cv_sizeof_int=4 ac_cv_sizeof_long=4 ac_cv_sizeof_long_long=4 fi @@ -415,9 +411,9 @@ then else #echo "CROSS ENDIAN" if $CXX -v 2>&1|grep "mingw" >/dev/null 2>&1; then - ac_cv_c_bigendian=no + ac_cv_c_bigendian=no else - : # FIXME + : # FIXME fi #echo "CROSS ENDIAN DONE" fi @@ -443,13 +439,13 @@ if test "$ucsim_cv_CXXgstabs" = "yes"; then gopt="-gstabs+ -g3" elif test "$ucsim_cv_CXXggdb" = "yes"; then gopt="-ggdb -g3" -else +else gopt="-g" fi if test "$CXXFLAGS"x = x ;then - CXXFLAGS="$gopt" + CXXFLAGS="$gopt" else - CXXFLAGS="$CXXFLAGS $gopt" + CXXFLAGS="$CXXFLAGS $gopt" fi DD_COPT(CXX, pipe) @@ -465,7 +461,7 @@ if test "$ucsim_cv_CXXfPIC" = "yes"; then else DD_COPT(CXX, fpic) if test "$ucsim_cv_CXXfpic" = "yes"; then - PICOPT="-fpic" + PICOPT="-fpic" fi fi if test "$PICOPT"x != "x"; then @@ -500,13 +496,13 @@ AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(long long) else if $CXX -v 2>&1|grep "mingw" >/dev/null 2>&1; then - ac_cv_sizeof_char=1 - ac_cv_sizeof_short=2 - ac_cv_sizeof_int=4 - ac_cv_sizeof_long=4 - ac_cv_sizeof_long_long=4 + ac_cv_sizeof_char=1 + ac_cv_sizeof_short=2 + ac_cv_sizeof_int=4 + ac_cv_sizeof_long=4 + ac_cv_sizeof_long_long=4 else - : # FIXME + : # FIXME fi #echo fi @@ -514,24 +510,24 @@ fi type_name() { if expr "$ac_cv_sizeof_char" '>=' "$1" >/dev/null; then - echo "char" - exit + echo "char" + exit fi if expr "$ac_cv_sizeof_short" '>=' "$1" >/dev/null; then - echo "short" - exit + echo "short" + exit fi if expr "$ac_cv_sizeof_int" '>=' "$1" >/dev/null; then - echo "int" - exit + echo "int" + exit fi if expr "$ac_cv_sizeof_long" '>=' "$1" >/dev/null; then - echo "long" - exit + echo "long" + exit fi if expr "$ac_cv_sizeof_long_long" '>=' "$1" >/dev/null; then - echo "long long" - exit + echo "long long" + exit fi echo "long long" } diff --git a/sim/ucsim/ddconfig_in.h b/sim/ucsim/ddconfig_in.h index cb2c9c29..71f023ec 100644 --- a/sim/ucsim/ddconfig_in.h +++ b/sim/ucsim/ddconfig_in.h @@ -2,7 +2,7 @@ * Simulator of microcontrollers (ddconfig.h) * * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. - * + * * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * */ @@ -30,7 +30,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #define DD_TRUE 1 #define DD_FALSE 0 -#define NIL 0 +#define NIL 0 #undef STDC_HEADERS #undef HAVE_GETOPT_H @@ -75,6 +75,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #undef HAVE_VPRINTF #undef HAVE_DOPRNT #undef HAVE_VSNPRINTF +#undef HAVE__VSNPRINTF #undef HAVE_VASPRINTF #undef HAVE_GETLINE diff --git a/sim/ucsim/error.cc b/sim/ucsim/error.cc index 5b125a8c..8494cdd2 100644 --- a/sim/ucsim/error.cc +++ b/sim/ucsim/error.cc @@ -40,9 +40,9 @@ struct id_element error_on_off_names[]= { { ERROR_PARENT, "unset" }, - { ERROR_ON , "on" }, - { ERROR_OFF , "off" }, - { 0 , 0 } + { ERROR_ON , "on" }, + { ERROR_OFF , "off" }, + { 0 , 0 } }; static class cl_error_registry error_registry; @@ -53,7 +53,7 @@ class cl_list *cl_error_registry::registered_errors= NIL; */ cl_error_class::cl_error_class(enum error_type typ, char *aname, - enum error_on_off be_on/* = ERROR_PARENT*/): + enum error_on_off be_on/* = ERROR_PARENT*/): cl_base() { type= typ; @@ -62,8 +62,8 @@ cl_error_class::cl_error_class(enum error_type typ, char *aname, } cl_error_class::cl_error_class(enum error_type typ, char *aname, - class cl_error_class *parent, - enum error_on_off be_on/* = ERROR_PARENT*/): + class cl_error_class *parent, + enum error_on_off be_on/* = ERROR_PARENT*/): cl_base() { type= typ; @@ -88,9 +88,9 @@ cl_error_class::is_on(void) if (on == ERROR_PARENT) { if (!get_parent()) - return(DD_TRUE); + return(DD_TRUE); class cl_error_class *p= - dynamic_cast(get_parent()); + dynamic_cast(get_parent()); return(p->is_on()); } else @@ -167,7 +167,7 @@ cl_error::is_on(void) } void -cl_error::print(class cl_commander *c) +cl_error::print(class cl_commander_base *c) { c->dd_printf("%s\n", get_type_name()); } diff --git a/sim/ucsim/errorcl.h b/sim/ucsim/errorcl.h index dd7bb8d9..91d821f3 100644 --- a/sim/ucsim/errorcl.h +++ b/sim/ucsim/errorcl.h @@ -54,10 +54,10 @@ protected: enum error_on_off on; public: cl_error_class(enum error_type typ, char *aname, - enum error_on_off be_on= ERROR_PARENT); + enum error_on_off be_on= ERROR_PARENT); cl_error_class(enum error_type typ, char *aname, - class cl_error_class *parent, - enum error_on_off be_on= ERROR_PARENT); + class cl_error_class *parent, + enum error_on_off be_on= ERROR_PARENT); enum error_on_off get_on(void) { return(on); } void set_on(enum error_on_off val); @@ -99,15 +99,15 @@ private: } }; -class cl_commander; //forward +class cl_commander_base; //forward class cl_error: public cl_base { protected: class cl_error_class *classification; public: - bool inst; // Occured during instruction execution - t_addr PC; // Address of the instruction + bool inst; // Occured during instruction execution + t_addr PC; // Address of the instruction public: cl_error(void); virtual ~cl_error(void); @@ -119,7 +119,7 @@ public: virtual bool is_on(void); virtual class cl_error_class *get_class(void) { return(classification); } - virtual void print(class cl_commander *c); + virtual void print(class cl_commander_base *c); virtual char *get_type_name(); }; diff --git a/sim/ucsim/hc08.src/hc08.cc b/sim/ucsim/hc08.src/hc08.cc index 5603fead..40dd7e2f 100644 --- a/sim/ucsim/hc08.src/hc08.cc +++ b/sim/ucsim/hc08.src/hc08.cc @@ -284,63 +284,63 @@ cl_hc08::disass(t_addr addr, char *sep) while (*b) { if (*b == '%') - { - b++; - switch (*(b++)) - { - case 's': // s signed byte immediate - sprintf(temp, "#%d", (char)get_mem(MEM_ROM_ID, addr+immed_offset)); - ++immed_offset; - break; - case 'w': // w word immediate operand - sprintf(temp, "#0x%04x", - (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)<<8) | - (get_mem(MEM_ROM_ID, addr+immed_offset+1))) ); - ++immed_offset; - ++immed_offset; - break; - case 'b': // b byte immediate operand - sprintf(temp, "#0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset)); - ++immed_offset; - break; - case 'x': // x extended addressing - sprintf(temp, "0x%04x", - (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)<<8) | - (get_mem(MEM_ROM_ID, addr+immed_offset+1))) ); - ++immed_offset; - ++immed_offset; - break; - case 'd': // d direct addressing - sprintf(temp, "*0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset)); - ++immed_offset; - break; - case '2': // 2 word index offset - sprintf(temp, "0x%04x", - (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)<<8) | - (get_mem(MEM_ROM_ID, addr+immed_offset+1))) ); - ++immed_offset; - ++immed_offset; - break; - case '1': // b byte index offset + { + b++; + switch (*(b++)) + { + case 's': // s signed byte immediate + sprintf(temp, "#%d", (char)get_mem(MEM_ROM_ID, addr+immed_offset)); + ++immed_offset; + break; + case 'w': // w word immediate operand + sprintf(temp, "#0x%04x", + (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)<<8) | + (get_mem(MEM_ROM_ID, addr+immed_offset+1))) ); + ++immed_offset; + ++immed_offset; + break; + case 'b': // b byte immediate operand + sprintf(temp, "#0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset)); + ++immed_offset; + break; + case 'x': // x extended addressing + sprintf(temp, "0x%04x", + (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)<<8) | + (get_mem(MEM_ROM_ID, addr+immed_offset+1))) ); + ++immed_offset; + ++immed_offset; + break; + case 'd': // d direct addressing + sprintf(temp, "*0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset)); + ++immed_offset; + break; + case '2': // 2 word index offset + sprintf(temp, "0x%04x", + (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)<<8) | + (get_mem(MEM_ROM_ID, addr+immed_offset+1))) ); + ++immed_offset; + ++immed_offset; + break; + case '1': // b byte index offset sprintf(temp, "0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset)); - ++immed_offset; - break; - case 'p': // b byte index offset + ++immed_offset; + break; + case 'p': // b byte index offset sprintf(temp, "0x%04x", addr+immed_offset+1 +(char)get_mem(MEM_ROM_ID, addr+immed_offset)); - ++immed_offset; - break; - default: - strcpy(temp, "?"); - break; - } - t= temp; - while (*t) - *(p++)= *(t++); - } + ++immed_offset; + break; + default: + strcpy(temp, "?"); + break; + } + t= temp; + while (*t) + *(p++)= *(t++); + } else - *(p++)= *(b++); + *(p++)= *(b++); } *p= '\0'; @@ -361,7 +361,7 @@ cl_hc08::disass(t_addr addr, char *sep) if (sep == NULL) { while (strlen(buf) < 6) - strcat(buf, " "); + strcat(buf, " "); } else strcat(buf, sep); @@ -371,26 +371,26 @@ cl_hc08::disass(t_addr addr, char *sep) void -cl_hc08::print_regs(class cl_console *con) +cl_hc08::print_regs(class cl_console_base *con) { con->dd_printf("V--HINZC Flags= 0x%02x %3d %c ", - regs.P, regs.P, isprint(regs.P)?regs.P:'.'); + regs.P, regs.P, isprint(regs.P)?regs.P:'.'); con->dd_printf("A= 0x%02x %3d %c\n", - regs.A, regs.A, isprint(regs.A)?regs.A:'.'); + regs.A, regs.A, isprint(regs.A)?regs.A:'.'); con->dd_printf("%c--%c%c%c%c%c ", - (regs.P&BIT_V)?'1':'0', - (regs.P&BIT_H)?'1':'0', - (regs.P&BIT_I)?'1':'0', - (regs.P&BIT_N)?'1':'0', - (regs.P&BIT_Z)?'1':'0', - (regs.P&BIT_C)?'1':'0'); + (regs.P&BIT_V)?'1':'0', + (regs.P&BIT_H)?'1':'0', + (regs.P&BIT_I)?'1':'0', + (regs.P&BIT_N)?'1':'0', + (regs.P&BIT_Z)?'1':'0', + (regs.P&BIT_C)?'1':'0'); con->dd_printf(" H= 0x%02x %3d %c ", - regs.H, regs.H, isprint(regs.H)?regs.H:'.'); + regs.H, regs.H, isprint(regs.H)?regs.H:'.'); con->dd_printf("X= 0x%02x %3d %c\n", - regs.X, regs.X, isprint(regs.X)?regs.X:'.'); + regs.X, regs.X, isprint(regs.X)?regs.X:'.'); con->dd_printf("SP= 0x%04x [SP+1]= %02x %3d %c\n", - regs.SP, ram->get(regs.SP+1), ram->get(regs.SP+1), - isprint(ram->get(regs.SP+1))?ram->get(regs.SP+1):'.'); + regs.SP, ram->get(regs.SP+1), ram->get(regs.SP+1), + isprint(ram->get(regs.SP+1))?ram->get(regs.SP+1):'.'); print_disass(PC, con); } diff --git a/sim/ucsim/hc08.src/hc08cl.h b/sim/ucsim/hc08.src/hc08cl.h index 35efadf8..20bf4c31 100644 --- a/sim/ucsim/hc08.src/hc08cl.h +++ b/sim/ucsim/hc08.src/hc08cl.h @@ -57,7 +57,7 @@ public: virtual int inst_branch(t_addr addr); virtual int longest_inst(void); virtual char *disass(t_addr addr, char *sep); - virtual void print_regs(class cl_console *con); + virtual void print_regs(class cl_console_base *con); virtual int exec_inst(void); diff --git a/sim/ucsim/option.cc b/sim/ucsim/option.cc index 45e62cf1..01b7db0c 100644 --- a/sim/ucsim/option.cc +++ b/sim/ucsim/option.cc @@ -45,12 +45,12 @@ /*struct id_element option_type_names[]= { - { non_opt , "non" }, - { integer_opt , "integer" }, - { float_opt , "float" }, - { bool_opt , "boolean" }, - { string_opt , "string" }, - { pointer_opt , "pointer" }, + { non_opt , "non" }, + { integer_opt , "integer" }, + { float_opt , "float" }, + { bool_opt , "boolean" }, + { string_opt , "string" }, + { pointer_opt , "pointer" }, { 0, 0 } };*/ @@ -275,24 +275,24 @@ cl_options::get_option(char *the_name, class cl_base *creator) idx--; o= (class cl_option *)(at(idx)); while (compare(the_name, key_of(o)) == 0 && - idx > 0) - { - idx--; - o= (class cl_option *)(at(idx)); - } + idx > 0) + { + idx--; + o= (class cl_option *)(at(idx)); + } if (compare(the_name, key_of(o)) != 0) - idx++; + idx++; } o= (class cl_option *)(at(idx)); while (compare(the_name, key_of(o)) == 0 && - o->get_creator() != creator && - idx < count) + o->get_creator() != creator && + idx < count) { idx++; o= (class cl_option *)(at(idx)); if (compare(the_name, key_of(o)) == 0 && - o->get_creator() == creator) - return(o); + o->get_creator() == creator) + return(o); } if (compare(the_name, key_of(o)) == 0 && o->get_creator() == creator) @@ -313,24 +313,24 @@ cl_options::get_option(char *the_name, char *creator) idx--; o= (class cl_option *)(at(idx)); while (compare(the_name, key_of(o)) == 0 && - idx > 0) - { - idx--; - o= (class cl_option *)(at(idx)); - } + idx > 0) + { + idx--; + o= (class cl_option *)(at(idx)); + } if (compare(the_name, key_of(o)) != 0) - idx++; + idx++; } o= (class cl_option *)(at(idx)); while (compare(the_name, key_of(o)) == 0 && - strcmp(object_name(o->get_creator()), creator) != 0 && - idx < count) + strcmp(object_name(o->get_creator()), creator) != 0 && + idx < count) { idx++; o= (class cl_option *)(at(idx)); if (compare(the_name, key_of(o)) == 0 && - strcmp(object_name(o->get_creator()), creator) == 0) - return(o); + strcmp(object_name(o->get_creator()), creator) == 0) + return(o); } if (compare(the_name, key_of(o)) == 0 && strcmp(object_name(o->get_creator()), creator) == 0) @@ -355,7 +355,7 @@ cl_options::nuof_options(char *the_name) { class cl_option *o= (class cl_option *)(at(i)); if (strcmp(the_name, o->get_name()) == 0) - n++; + n++; } return(n); } @@ -369,8 +369,8 @@ cl_options::nuof_options(char *the_name, char *creator) { class cl_option *o= (class cl_option *)(at(i)); if (strcmp(the_name, o->get_name()) == 0 && - strcmp(creator, object_name(o->get_creator())) == 0) - n++; + strcmp(creator, object_name(o->get_creator())) == 0) + n++; } return(n); } @@ -454,14 +454,14 @@ cl_optref::~cl_optref(void) { option->del_reference(this); if (option->get_creator() == owner) - application->options->del_option(option); + application->options->del_option(option); } } class cl_option * cl_optref::create(class cl_base *creator, - enum option_type type, - char *the_name, char *help) + enum option_type type, + char *the_name, char *help) { if (option) option->del_reference(this); @@ -552,7 +552,7 @@ cl_optref::get_value(bool) if (!option) { fprintf(stderr, "Warning: \"%s\" is sdereferencing a non-existent " - "bool option: %s\n", object_name(owner), get_name()); + "bool option: %s\n", object_name(owner), get_name()); return(DD_FALSE); } else @@ -569,7 +569,7 @@ cl_optref::get_value(char *) if (!option) { fprintf(stderr, "Warning: \"%s\" is sdereferencing a non-existent " - "string option: %s\n", object_name(owner), get_name()); + "string option: %s\n", object_name(owner), get_name()); return(0); } else @@ -586,7 +586,7 @@ cl_optref::get_value(void *) if (!option) { fprintf(stderr, "Warning: \"%s\" is sdereferencing a non-existent " - "pointer option: %s\n", object_name(owner), get_name()); + "pointer option: %s\n", object_name(owner), get_name()); return(NIL); } else @@ -603,7 +603,7 @@ cl_optref::get_value(long) if (!option) { fprintf(stderr, "Warning: \"%s\" is sdereferencing a non-existent " - "number option: %s\n", object_name(owner), get_name()); + "number option: %s\n", object_name(owner), get_name()); return(0); } else @@ -620,7 +620,7 @@ cl_optref::get_value(double) if (!option) { fprintf(stderr, "Warning: \"%s\" is sdereferencing a non-existent " - "float option: %s\n", object_name(owner), get_name()); + "float option: %s\n", object_name(owner), get_name()); return(0); } else @@ -639,12 +639,12 @@ cl_optref::get_value(double) */ cl_bool_option::cl_bool_option(class cl_base *the_creator, - char *aname, char *Ihelp): + char *aname, char *Ihelp): cl_option(the_creator, aname, Ihelp) {} void -cl_bool_option::print(class cl_console *con) +cl_bool_option::print(class cl_console_base *con) { if (/**(bool *)option*/value.bval) con->dd_printf("TRUE"); @@ -661,11 +661,11 @@ cl_bool_option::set_value(char *s) { c= toupper(*s); if (c == '1' || - c == 'T' || - c == 'Y') - /**(bool *)option=*/ value.bval= DD_TRUE; + c == 'T' || + c == 'Y') + /**(bool *)option=*/ value.bval= DD_TRUE; else - /**(bool *)option=*/ value.bval= DD_FALSE; + /**(bool *)option=*/ value.bval= DD_FALSE; } inform_users(); } @@ -678,7 +678,7 @@ cl_bool_option::set_value(char *s) */ cl_string_option::cl_string_option(class cl_base *the_creator, - char *aname, char *Ihelp): + char *aname, char *Ihelp): cl_option(the_creator, aname, Ihelp) {} @@ -692,7 +692,7 @@ cl_string_option::operator=(class cl_option &o) } void -cl_string_option::print(class cl_console *con) +cl_string_option::print(class cl_console_base *con) { if (/**(bool *)option*/value.sval) con->dd_printf("\"%s\"", value.sval); @@ -708,7 +708,7 @@ cl_string_option::print(class cl_console *con) */ cl_pointer_option::cl_pointer_option(class cl_base *the_creator, - char *aname, char *Ihelp): + char *aname, char *Ihelp): cl_option(the_creator, aname, Ihelp) {} @@ -720,7 +720,7 @@ cl_pointer_option::operator=(class cl_option &o) } void -cl_pointer_option::print(class cl_console *con) +cl_pointer_option::print(class cl_console_base *con) { if (value.pval) con->dd_printf("\"%p\"", value.pval); @@ -734,15 +734,15 @@ cl_pointer_option::print(class cl_console *con) */ /* cl_cons_debug_opt::cl_cons_debug_opt(class cl_app *the_app, - char *Iid, - char *Ihelp): + char *Iid, + char *Ihelp): cl_option(0, Iid, Ihelp) { app= the_app; } void -cl_cons_debug_opt::print(class cl_console *con) +cl_cons_debug_opt::print(class cl_console_base *con) { if (con->flags & CONS_DEBUG) con->dd_printf("TRUE"); @@ -764,9 +764,9 @@ cl_cons_debug_opt::set_value(bool opt) if (app->get_commander()->actual_console) { if (opt) - app->get_commander()->actual_console->flags|= CONS_DEBUG; + app->get_commander()->actual_console->flags|= CONS_DEBUG; else - app->get_commander()->actual_console->flags&= ~CONS_DEBUG; + app->get_commander()->actual_console->flags&= ~CONS_DEBUG; } inform_users(); } @@ -781,11 +781,11 @@ cl_cons_debug_opt::set_value(char *s) { c= toupper(*s); if (c == '1' || - c == 'T' || - c == 'Y') - set_value(1); + c == 'T' || + c == 'Y') + set_value(1); else - set_value(0); + set_value(0); } } */ @@ -797,12 +797,12 @@ cl_cons_debug_opt::set_value(char *s) */ cl_number_option::cl_number_option(class cl_base *the_creator, - char *aname, char *Ihelp): + char *aname, char *Ihelp): cl_option(the_creator, aname, Ihelp) {} void -cl_number_option::print(class cl_console *con) +cl_number_option::print(class cl_console_base *con) { con->dd_printf("%ld", value.ival); } @@ -823,12 +823,12 @@ cl_number_option::set_value(char *s) */ cl_float_option::cl_float_option(class cl_base *the_creator, - char *aname, char *Ihelp): + char *aname, char *Ihelp): cl_option(the_creator, aname, Ihelp) {} void -cl_float_option::print(class cl_console *con) +cl_float_option::print(class cl_console_base *con) { con->dd_printf("%.3f", value.fval); } diff --git a/sim/ucsim/optioncl.h b/sim/ucsim/optioncl.h index da4d4baa..b8b298ca 100644 --- a/sim/ucsim/optioncl.h +++ b/sim/ucsim/optioncl.h @@ -79,7 +79,7 @@ public: virtual void hide(void) { hidden= DD_TRUE; } virtual void show(void) { hidden= DD_FALSE; } - virtual void print(class cl_console *con) {} + virtual void print(class cl_console_base *con) {} virtual char *get_type_name(void) { return("non"); } virtual union option_value *get_value(void) { return(&value); } @@ -116,15 +116,15 @@ public: virtual int nuof_options(char *the_name, char *creator); virtual class cl_option *set_value(char *the_name, cl_base *creator, - bool value); + bool value); virtual class cl_option *set_value(char *the_name, cl_base *creator, - char *value); + char *value); virtual class cl_option *set_value(char *the_name, cl_base *creator, - void *value); + void *value); virtual class cl_option *set_value(char *the_name, cl_base *creator, - long value); + long value); virtual class cl_option *set_value(char *the_name, cl_base *creator, - double value); + double value); }; @@ -139,8 +139,8 @@ public: virtual ~cl_optref(void); virtual class cl_option *create(class cl_base *creator, - enum option_type type, - char *the_name, char *help); + enum option_type type, + char *the_name, char *help); virtual void default_option(char *the_name); virtual class cl_option *use(void); virtual class cl_option *use(char *the_name); @@ -160,7 +160,7 @@ class cl_bool_option: public cl_option { public: cl_bool_option(class cl_base *the_creator, char *aname, char *Ihelp); - virtual void print(class cl_console *con); + virtual void print(class cl_console_base *con); virtual char *get_type_name(void) { return("boolean"); } virtual void set_value(char *s); }; @@ -171,7 +171,7 @@ class cl_string_option: public cl_option public: cl_string_option(class cl_base *the_creator, char *aname, char *Ihelp); virtual class cl_option &operator=(class cl_option &o); - virtual void print(class cl_console *con); + virtual void print(class cl_console_base *con); virtual char *get_type_name(void) { return("string"); } }; @@ -181,7 +181,7 @@ class cl_pointer_option: public cl_option public: cl_pointer_option(class cl_base *the_creator, char *aname, char *Ihelp); virtual class cl_option &operator=(class cl_option &o); - virtual void print(class cl_console *con); + virtual void print(class cl_console_base *con); virtual char *get_type_name(void) { return("pointer"); } }; @@ -190,7 +190,7 @@ class cl_number_option: public cl_option { public: cl_number_option(class cl_base *the_creator, char *aname, char *Ihelp); - virtual void print(class cl_console *con); + virtual void print(class cl_console_base *con); virtual char *get_type_name(void) { return("integer"); } virtual void set_value(char *s); }; @@ -200,7 +200,7 @@ class cl_float_option: public cl_option { public: cl_float_option(class cl_base *the_creator, char *aname, char *Ihelp); - virtual void print(class cl_console *con); + virtual void print(class cl_console_base *con); virtual char *get_type_name(void) { return("float"); } virtual void set_value(char *s); }; @@ -213,7 +213,7 @@ public: public: cl_cons_debug_opt(class cl_app *the_app, char *Iid, char *Ihelp); - virtual void print(class cl_console *con); + virtual void print(class cl_console_base *con); virtual void get_value(bool *val); diff --git a/sim/ucsim/s51.src/Makefile.in b/sim/ucsim/s51.src/Makefile.in index cc95874e..97aa8641 100644 --- a/sim/ucsim/s51.src/Makefile.in +++ b/sim/ucsim/s51.src/Makefile.in @@ -26,7 +26,6 @@ CXXFLAGS = @CXXFLAGS@ -Wall M_OR_MM = @M_OR_MM@ PICOPT = @PICOPT@ SHAREDLIB = @SHAREDLIB@ -SERIAL_AVAIL = @SERIAL_AVAIL@ SDCC = sdcc SDCFLAGS = --debug --stack-after-data --model-small @@ -53,15 +52,10 @@ EXEEXT = @EXEEXT@ OBJECTS_SHARED = glob.o sim51.o \ inc.o jmp.o mov.o logic.o arith.o bit.o \ - timer0.o timer1.o timer2.o port.o interrupt.o \ + timer0.o timer1.o timer2.o serial.o port.o interrupt.o \ wdt.o pca.o \ uc51.o uc52.o uc51r.o uc89c51r.o uc251.o \ uc390.o uc390hw.o - -ifeq ($(SERIAL_AVAIL), 1) -OBJECTS_SHARED += serial.o -endif - OBJECTS_EXE = s51.o OBJECTS = $(OBJECTS_SHARED) $(OBJECTS_EXE) diff --git a/sim/ucsim/s51.src/interrupt.cc b/sim/ucsim/s51.src/interrupt.cc index 80aad40c..f8a8f8d3 100644 --- a/sim/ucsim/s51.src/interrupt.cc +++ b/sim/ucsim/s51.src/interrupt.cc @@ -63,9 +63,9 @@ void cl_interrupt::added_to_uc(void) { uc->it_sources->add(new cl_it_src(bmEX0, TCON, bmIE0, 0x0003, true, - "external #0", 1)); + "external #0", 1)); uc->it_sources->add(new cl_it_src(bmEX1, TCON, bmIE1, 0x0013, true, - "external #1", 3)); + "external #1", 3)); } void @@ -114,13 +114,13 @@ cl_interrupt::happen(class cl_hw *where, enum hw_event he, void *params) t_mem p3n= ep->new_pins & ep->new_value; t_mem p3o= ep->pins & ep->prev_value; if (bit_IT0 && - !(p3n & bm_INT0) && - (p3o & bm_INT0)) - cell_tcon->set_bit1(bmIE0); + !(p3n & bm_INT0) && + (p3o & bm_INT0)) + cell_tcon->set_bit1(bmIE0); if (bit_IT1 && - !(p3n & bm_INT1) && - (p3o & bm_INT1)) - cell_tcon->set_bit1(bmIE1); + !(p3n & bm_INT1) && + (p3o & bm_INT1)) + cell_tcon->set_bit1(bmIE1); bit_INT0= p3n & bm_INT0; bit_INT1= p3n & bm_INT1; } @@ -128,13 +128,13 @@ cl_interrupt::happen(class cl_hw *where, enum hw_event he, void *params) void -cl_interrupt::print_info(class cl_console *con) +cl_interrupt::print_info(class cl_console_base *con) { int ie= sfr->get(IE); int i; con->dd_printf("Interrupts are %s. Interrupt sources:\n", - (ie&bmEA)?"enabled":"disabled"); + (ie&bmEA)?"enabled":"disabled"); con->dd_printf(" Handler En Pr Req Act Name\n"); for (i= 0; i < uc->it_sources->count; i++) { @@ -143,8 +143,8 @@ cl_interrupt::print_info(class cl_console *con) con->dd_printf(" %-3s", (ie&(is->ie_mask))?"en":"dis"); con->dd_printf(" %2d", uc->it_priority(is->ie_mask)); con->dd_printf(" %-3s", - (sfr->get(is->src_reg)&(is->src_mask))? - "YES":"no"); + (sfr->get(is->src_reg)&(is->src_mask))? + "YES":"no"); con->dd_printf(" %-3s", (is->active)?"act":"no"); con->dd_printf(" %s", object_name(is)); con->dd_printf("\n"); @@ -155,14 +155,14 @@ cl_interrupt::print_info(class cl_console *con) { class it_level *il= (class it_level *)(uc->it_levels->at(i)); if (il->level >= 0) - { - con->dd_printf(" %2d", il->level); - con->dd_printf(" 0x%06x", il->addr); - con->dd_printf(" 0x%06x", il->PC); - con->dd_printf(" %s", (il->source)?(object_name(il->source)): - "nothing"); - con->dd_printf("\n"); - } + { + con->dd_printf(" %2d", il->level); + con->dd_printf(" 0x%06x", il->addr); + con->dd_printf(" 0x%06x", il->PC); + con->dd_printf(" %s", (il->source)?(object_name(il->source)): + "nothing"); + con->dd_printf("\n"); + } } } diff --git a/sim/ucsim/s51.src/interruptcl.h b/sim/ucsim/s51.src/interruptcl.h index 2b84e8c3..ebc52574 100644 --- a/sim/ucsim/s51.src/interruptcl.h +++ b/sim/ucsim/s51.src/interruptcl.h @@ -56,7 +56,7 @@ public: virtual void reset(void); virtual void happen(class cl_hw *where, enum hw_event he, void *params); - virtual void print_info(class cl_console *con); + virtual void print_info(class cl_console_base *con); }; diff --git a/sim/ucsim/s51.src/pca.cc b/sim/ucsim/s51.src/pca.cc index 3497fa2c..b9eeef39 100644 --- a/sim/ucsim/s51.src/pca.cc +++ b/sim/ucsim/s51.src/pca.cc @@ -77,17 +77,17 @@ void cl_pca::added_to_uc(void) { uc->it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF4, 0x0033, false, - "PCA module #4", 5)); + "PCA module #4", 5)); uc->it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF3, 0x0033, false, - "PCA module #3", 5)); + "PCA module #3", 5)); uc->it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF2, 0x0033, false, - "PCA module #2", 5)); + "PCA module #2", 5)); uc->it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF1, 0x0033, false, - "PCA module #1", 5)); + "PCA module #1", 5)); uc->it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCCF0, 0x0033, false, - "PCA module #0", 5)); + "PCA module #0", 5)); uc->it_sources->add_at(4, new cl_it_src(bmEC, CCON, bmCF, 0x0033, false, - "PCA counter", 5)); + "PCA counter", 5)); } void @@ -103,7 +103,7 @@ cl_pca::write(class cl_memory_cell *cell, t_mem *val) bit_ECF = *val & bmECF; t_mem o= clk_source; if ((clk_source= *val & (bmCPS1|bmCPS0)) != o) - t0_overflows= ECI_edge= 0; + t0_overflows= ECI_edge= 0; } else if (cell == cell_ccon) { @@ -113,31 +113,31 @@ cl_pca::write(class cl_memory_cell *cell, t_mem *val) { int i; for (i= 0; i < 5; i++) - { - if (cell == cell_ccapm[i]) - { - t_mem o= ccapm[i]; - ccapm[i]= *val & 0xff; - if (o != ccapm[i]) - cex_neg[i]= cex_pos[i]= DD_FALSE; - } - else - { - if (ccapm[i] & (bmMAT|bmTOG)) - { - if (cell == cell_ccapl[i]) - { - cell_ccapm[i]->set_bit0(bmECOM); - ccapm[i]= cell_ccapm[i]->get(); - } - else if (cell == cell_ccaph[i]) - { - cell_ccapm[i]->set_bit1(bmECOM); - ccapm[i]= cell_ccapm[i]->get(); - } - } - } - } + { + if (cell == cell_ccapm[i]) + { + t_mem o= ccapm[i]; + ccapm[i]= *val & 0xff; + if (o != ccapm[i]) + cex_neg[i]= cex_pos[i]= DD_FALSE; + } + else + { + if (ccapm[i] & (bmMAT|bmTOG)) + { + if (cell == cell_ccapl[i]) + { + cell_ccapm[i]->set_bit0(bmECOM); + ccapm[i]= cell_ccapm[i]->get(); + } + else if (cell == cell_ccaph[i]) + { + cell_ccapm[i]->set_bit1(bmECOM); + ccapm[i]= cell_ccapm[i]->get(); + } + } + } + } } } @@ -149,11 +149,11 @@ cl_pca::mem_cell_changed(class cl_m *mem, t_addr addr) if (mem && sfr && mem == sfr) { if (addr == addr_ccapXl) - ccapXl= sfr->get_cell(addr_ccapXl); + ccapXl= sfr->get_cell(addr_ccapXl); else if (addr == addr_ccapXh) - ccapXh= sfr->get_cell(addr_ccapXh); + ccapXh= sfr->get_cell(addr_ccapXh); else if (addr == addr_ccapmX) - ccapmX= sfr->get_cell(addr_ccapmX); + ccapmX= sfr->get_cell(addr_ccapmX); } }*/ @@ -196,22 +196,22 @@ cl_pca::do_pca_counter(int cycles) while (cycles--) { if (cell_cl->add(1) == 0) - { - int i; - for (i= 0; i < 5; i++) - if (ccapm[i] & bmPWM) - cell_ccapl[i]->set(cell_ccaph[i]->get()); - if (cell_ch->add(1) == 0) - { - // CH,CL overflow - cell_ccon->set_bit1(bmCF); - do_pca_module(0); - do_pca_module(1); - do_pca_module(2); - do_pca_module(3); - do_pca_module(4); - } - } + { + int i; + for (i= 0; i < 5; i++) + if (ccapm[i] & bmPWM) + cell_ccapl[i]->set(cell_ccaph[i]->get()); + if (cell_ch->add(1) == 0) + { + // CH,CL overflow + cell_ccon->set_bit1(bmCF); + do_pca_module(0); + do_pca_module(1); + do_pca_module(2); + do_pca_module(3); + do_pca_module(4); + } + } } } @@ -247,33 +247,33 @@ cl_pca::do_pca_module(int nr) { // Comparator enabled if (cell_cl->get() == cell_ccapl[nr]->get() && - cell_ch->get() == cell_ccaph[nr]->get()) - { - // Match - if (nr == 4 && - (bit_WDTE)) - { - reset(); - return; - } - cell_ccon->set_bit1(bmCCF[nr]); - if (ccapm[nr] & bmTOG) - { - // Toggle - sfr->set(P1, sfr->get(P1) ^ bmCEX[nr]); - } - } + cell_ch->get() == cell_ccaph[nr]->get()) + { + // Match + if (nr == 4 && + (bit_WDTE)) + { + reset(); + return; + } + cell_ccon->set_bit1(bmCCF[nr]); + if (ccapm[nr] & bmTOG) + { + // Toggle + sfr->set(P1, sfr->get(P1) ^ bmCEX[nr]); + } + } if (ccapm[nr] & bmPWM) - { - // PWM - /*if (cell_cl->get() == 0) - cell_ccapl[nr]->set(cell_ccaph[nr]->get());*/ - if (cell_cl->get() < cell_ccapl[nr]->get()) - //sfr->set(P1, sfr->get(P1) & ~(bmCEX[nr])); - sfr->set_bit1(P1, bmCEX[nr]); - else - sfr->set_bit1(P1, bmCEX[nr]); - } + { + // PWM + /*if (cell_cl->get() == 0) + cell_ccapl[nr]->set(cell_ccaph[nr]->get());*/ + if (cell_cl->get() < cell_ccapl[nr]->get()) + //sfr->set(P1, sfr->get(P1) & ~(bmCEX[nr])); + sfr->set_bit1(P1, bmCEX[nr]); + else + sfr->set_bit1(P1, bmCEX[nr]); + } } } @@ -298,22 +298,22 @@ cl_pca::happen(class cl_hw *where, enum hw_event he, void *params) t_mem p1n= ep->new_pins & ep->new_value; t_mem p1o= ep->pins & ep->prev_value; if (!(p1n & bmECI) && - (p1o & bmECI)) - ECI_edge++; + (p1o & bmECI)) + ECI_edge++; int i; for (i= 0; i < 5; i++) - { - if (!(p1n & bmCEX[i]) && - (p1o & bmCEX[i])) - cex_neg[i]= DD_TRUE; - else if ((p1n & bmCEX[i]) && - !(p1o & bmCEX[i])) - cex_pos[i]= DD_TRUE; - } + { + if (!(p1n & bmCEX[i]) && + (p1o & bmCEX[i])) + cex_neg[i]= DD_TRUE; + else if ((p1n & bmCEX[i]) && + !(p1o & bmCEX[i])) + cex_pos[i]= DD_TRUE; + } } else if (where->cathegory == HW_TIMER && - he == EV_OVERFLOW && - where->id == 0) + he == EV_OVERFLOW && + where->id == 0) { t0_overflows++; } @@ -321,7 +321,7 @@ cl_pca::happen(class cl_hw *where, enum hw_event he, void *params) void -cl_pca::print_info(class cl_console *con) +cl_pca::print_info(class cl_console_base *con) { con->dd_printf("%s[%d] FIXME\n", id_string, id); } diff --git a/sim/ucsim/s51.src/pcacl.h b/sim/ucsim/s51.src/pcacl.h index 9c5ced51..dcbab4e0 100644 --- a/sim/ucsim/s51.src/pcacl.h +++ b/sim/ucsim/s51.src/pcacl.h @@ -67,7 +67,7 @@ public: virtual void reset(void); virtual void happen(class cl_hw *where, enum hw_event he, void *params); - virtual void print_info(class cl_console *con); + virtual void print_info(class cl_console_base *con); }; diff --git a/sim/ucsim/s51.src/port.cc b/sim/ucsim/s51.src/port.cc index a02ad790..b9f0a476 100644 --- a/sim/ucsim/s51.src/port.cc +++ b/sim/ucsim/s51.src/port.cc @@ -46,30 +46,30 @@ cl_port::init(void) case 0: addr_p= P0; break; case 1: { - addr_p= P1; - /*class cl_hw *hw; - if ((hw= uc->get_hw(HW_TIMER, 2, 0))) - hws_to_inform->add(hw);*/ - make_partner(HW_TIMER, 2); - make_partner(HW_PCA, 0); - break; + addr_p= P1; + /*class cl_hw *hw; + if ((hw= uc->get_hw(HW_TIMER, 2, 0))) + hws_to_inform->add(hw);*/ + make_partner(HW_TIMER, 2); + make_partner(HW_PCA, 0); + break; } case 2: addr_p= P2; break; case 3: { - addr_p= P3; - //class cl_hw *hw; - /*if ((hw= uc->get_hw(HW_TIMER, 0, 0))) - hws_to_inform->add(hw); - if ((hw= uc->get_hw(HW_TIMER, 1, 0))) - hws_to_inform->add(hw); - if ((hw= uc->get_hw(HW_DUMMY, 0, 0))) - hws_to_inform->add(hw);*/ - make_partner(HW_TIMER, 0); - make_partner(HW_TIMER, 1); - make_partner(HW_INTERRUPT, 0); - make_partner(HW_DUMMY, 0); - break; + addr_p= P3; + //class cl_hw *hw; + /*if ((hw= uc->get_hw(HW_TIMER, 0, 0))) + hws_to_inform->add(hw); + if ((hw= uc->get_hw(HW_TIMER, 1, 0))) + hws_to_inform->add(hw); + if ((hw= uc->get_hw(HW_DUMMY, 0, 0))) + hws_to_inform->add(hw);*/ + make_partner(HW_TIMER, 0); + make_partner(HW_TIMER, 1); + make_partner(HW_INTERRUPT, 0); + make_partner(HW_DUMMY, 0); + break; } default: addr_p= P0; return(1); } @@ -109,7 +109,7 @@ cl_port::write(class cl_memory_cell *cell, t_mem *val) } void -cl_port::set_cmd(class cl_cmdline *cmdline, class cl_console *con) +cl_port::set_cmd(class cl_cmdline *cmdline, class cl_console_base *con) { struct ev_port_changed ep; class cl_cmd_arg *params[1]= { cmdline->param(0) }; @@ -127,12 +127,12 @@ cl_port::set_cmd(class cl_cmdline *cmdline, class cl_console *con) ep.new_value= cell_p->get(); ep.new_pins= port_pins; if (ep.pins != ep.new_pins) - inform_partners(EV_PORT_CHANGED, &ep); + inform_partners(EV_PORT_CHANGED, &ep); } else { con->dd_printf("set hardware port[%d] pins_value\n Set port pins\n", - id); + id); value= 0; } } @@ -146,7 +146,7 @@ cl_port::mem_cell_changed(class cl_m *mem, t_addr addr) }*/ void -cl_port::print_info(class cl_console *con) +cl_port::print_info(class cl_console_base *con) { uchar data; @@ -155,19 +155,19 @@ cl_port::print_info(class cl_console *con) con->dd_printf("P%d ", id); con->print_bin(data, 8); con->dd_printf(" 0x%02x %3d %c (Value in SFR register)\n", - data, data, isprint(data)?data:'.'); + data, data, isprint(data)?data:'.'); data= /*uc->*/port_pins/*[id]*/; con->dd_printf("Pin%d ", id); con->print_bin(data, 8); con->dd_printf(" 0x%02x %3d %c (Output of outside circuits)\n", - data, data, isprint(data)?data:'.'); + data, data, isprint(data)?data:'.'); data= cell_p->read(); con->dd_printf("Port%d ", id); con->print_bin(data, 8); con->dd_printf(" 0x%02x %3d %c (Value on the port pins)\n", - data, data, isprint(data)?data:'.'); + data, data, isprint(data)?data:'.'); } diff --git a/sim/ucsim/s51.src/portcl.h b/sim/ucsim/s51.src/portcl.h index 001d7c9d..3566dd75 100644 --- a/sim/ucsim/s51.src/portcl.h +++ b/sim/ucsim/s51.src/portcl.h @@ -49,11 +49,11 @@ public: virtual t_mem read(class cl_memory_cell *cell); virtual void write(class cl_memory_cell *cell, t_mem *val); - virtual void set_cmd(class cl_cmdline *cmdline, class cl_console *con); + virtual void set_cmd(class cl_cmdline *cmdline, class cl_console_base *con); //virtual void mem_cell_changed(class cl_m *mem, t_addr addr); //virtual int tick(int cycles); - virtual void print_info(class cl_console *con); + virtual void print_info(class cl_console_base *con); }; diff --git a/sim/ucsim/s51.src/serial.cc b/sim/ucsim/s51.src/serial.cc index 2f7b0be1..dde27150 100644 --- a/sim/ucsim/s51.src/serial.cc +++ b/sim/ucsim/s51.src/serial.cc @@ -2,7 +2,7 @@ * Simulator of microcontrollers (serial.cc) * * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. - * + * * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * */ @@ -40,6 +40,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include +#include // prj #include "globals.h" @@ -48,6 +49,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "serialcl.h" #include "regs51.h" #include "uc51cl.h" +#include "cmdutil.h" cl_serial::cl_serial(class cl_uc *auc): @@ -58,18 +60,22 @@ cl_serial::cl_serial(class cl_uc *auc): cl_serial::~cl_serial(void) { + if (serial_in != serial_out && serial_in) + { +#ifdef HAVE_TERMIOS_H + if (isatty(fileno(serial_in))) + tcsetattr(fileno(serial_in), TCSANOW, &saved_attributes_in); +#endif + fclose(serial_in); + } if (serial_out) { +#ifdef HAVE_TERMIOS_H if (isatty(fileno(serial_out))) - tcsetattr(fileno(serial_out), TCSANOW, &saved_attributes_out); + tcsetattr(fileno(serial_out), TCSANOW, &saved_attributes_out); +#endif fclose(serial_out); } - if (serial_in) - { - if (isatty(fileno(serial_in))) - tcsetattr(fileno(serial_in), TCSANOW, &saved_attributes_in); - fclose(serial_in); - } delete serial_in_file_option; delete serial_out_file_option; } @@ -77,8 +83,10 @@ cl_serial::~cl_serial(void) int cl_serial::init(void) { +#ifdef HAVE_TERMIOS_H int i; struct termios tattr; +#endif set_name("mcs51_uart"); sfr= uc->address_space(MEM_SFR_ID); @@ -104,60 +112,69 @@ cl_serial::init(void) serial_in= fopen(fni, "r"); if ((fno= serial_out_file_option->get_value((char*)0))) serial_out= fopen(fno, "w");*/ - + //serial_in = (FILE*)application->args->get_parg(0, "Ser_in"); //serial_out= (FILE*)application->args->get_parg(0, "Ser_out"); serial_in = (FILE*)serial_in_file_option->get_value((void*)0); serial_out= (FILE*)serial_out_file_option->get_value((void*)0); - if (serial_in) + + if (serial_in != serial_out && serial_in) { // making `serial' unbuffered if (setvbuf(serial_in, NULL, _IONBF, 0)) - perror("Unbuffer serial input channel"); + perror("Unbuffer serial input channel"); +#ifdef _WIN32 + if (CH_SERIAL != get_handle_type((HANDLE)_get_osfhandle(fileno(serial_in)))) +#elif defined HAVE_TERMIOS_H // setting O_NONBLOCK if ((i= fcntl(fileno(serial_in), F_GETFL, 0)) < 0) - perror("Get flags of serial input"); + perror("Get flags of serial input"); i|= O_NONBLOCK; if (fcntl(fileno(serial_in), F_SETFL, i) < 0) - perror("Set flags of serial input"); + perror("Set flags of serial input"); // switching terminal to noncanonical mode if (isatty(fileno(serial_in))) - { - tcgetattr(fileno(serial_in), &saved_attributes_in); - tcgetattr(fileno(serial_in), &tattr); - tattr.c_lflag&= ~(ICANON|ECHO); - tattr.c_cc[VMIN] = 1; - tattr.c_cc[VTIME]= 0; - tcsetattr(fileno(serial_in), TCSAFLUSH, &tattr); - } + { + tcgetattr(fileno(serial_in), &saved_attributes_in); + tcgetattr(fileno(serial_in), &tattr); + tattr.c_lflag&= ~(ICANON|ECHO); + tattr.c_cc[VMIN] = 1; + tattr.c_cc[VTIME]= 0; + tcsetattr(fileno(serial_in), TCSAFLUSH, &tattr); + } else - fprintf(stderr, "Warning: serial input interface connected to a " - "non-terminal file.\n"); +#endif + fprintf(stderr, "Warning: serial input interface connected to a " + "non-terminal file.\n"); } if (serial_out) { // making `serial' unbuffered if (setvbuf(serial_out, NULL, _IONBF, 0)) - perror("Unbuffer serial output channel"); + perror("Unbuffer serial output channel"); +#ifdef _WIN32 + if (CH_SERIAL != get_handle_type((HANDLE)_get_osfhandle(fileno(serial_out)))) +#elif defined HAVE_TERMIOS_H // setting O_NONBLOCK if ((i= fcntl(fileno(serial_out), F_GETFL, 0)) < 0) - perror("Get flags of serial output"); + perror("Get flags of serial output"); i|= O_NONBLOCK; if (fcntl(fileno(serial_out), F_SETFL, i) < 0) - perror("Set flags of serial output"); + perror("Set flags of serial output"); // switching terminal to noncanonical mode if (isatty(fileno(serial_out))) - { - tcgetattr(fileno(serial_out), &saved_attributes_out); - tcgetattr(fileno(serial_out), &tattr); - tattr.c_lflag&= ~(ICANON|ECHO); - tattr.c_cc[VMIN] = 1; - tattr.c_cc[VTIME]= 0; - tcsetattr(fileno(serial_out), TCSAFLUSH, &tattr); - } + { + tcgetattr(fileno(serial_out), &saved_attributes_out); + tcgetattr(fileno(serial_out), &tattr); + tattr.c_lflag&= ~(ICANON|ECHO); + tattr.c_cc[VMIN] = 1; + tattr.c_cc[VTIME]= 0; + tcsetattr(fileno(serial_out), TCSAFLUSH, &tattr); + } else - fprintf(stderr, "Warning: serial output interface connected to a " - "non-terminal file.\n"); +#endif + fprintf(stderr, "Warning: serial output interface connected to a " + "non-terminal file.\n"); } class cl_hw *t2= uc->get_hw(HW_TIMER, 2, 0); @@ -188,9 +205,9 @@ void cl_serial::added_to_uc(void) { uc->it_sources->add(new cl_it_src(bmES , SCON, bmTI , 0x0023, false, - "serial transmit", 6)); + "serial transmit", 6)); uc->it_sources->add(new cl_it_src(bmES , SCON, bmRI , 0x0023, false, - "serial receive", 6)); + "serial receive", 6)); } t_mem @@ -219,42 +236,42 @@ cl_serial::write(class cl_memory_cell *cell, t_mem *val) _bmREN= *val & bmREN; _bits= 8; switch (_mode) - { - case 0: - _bits= 8; - _divby= 12; - break; - case 1: - _bits= 10; - _divby= _bmSMOD?16:32; - break; - case 2: - _bits= 11; - _divby= _bmSMOD?16:32; - break; - case 3: - _bits= 11; - _divby= _bmSMOD?16:32; - break; - } + { + case 0: + _bits= 8; + _divby= 12; + break; + case 1: + _bits= 10; + _divby= _bmSMOD?16:32; + break; + case 2: + _bits= 11; + _divby= _bmSMOD?16:32; + break; + case 3: + _bits= 11; + _divby= _bmSMOD?16:32; + break; + } } else if (cell == pcon) { _bmSMOD= *val & bmSMOD; /*switch (_mode) - { - case 1: - _divby= _bmSMOD?16:32; - break; - case 2: - _divby= _bmSMOD?16:32; - break; - case 3: - _divby= _bmSMOD?16:32; - break; - }*/ + { + case 1: + _divby= _bmSMOD?16:32; + break; + case 2: + _divby= _bmSMOD?16:32; + break; + case 3: + _divby= _bmSMOD?16:32; + break; + }*/ if (_mode) - _divby= _bmSMOD?16:32; + _divby= _bmSMOD?16:32; } } @@ -301,19 +318,19 @@ cl_serial::serial_bit_cnt(void) if (s_sending) { while (*tr_src >= _divby) - { - (*tr_src)-= _divby; - s_tr_bit++; - //printf("serial bit sent %d\n",uc->ticks->ticks); - } + { + (*tr_src)-= _divby; + s_tr_bit++; + //printf("serial bit sent %d\n",uc->ticks->ticks); + } } if (s_receiving) { while (*rec_src >= _divby) - { - (*rec_src)-= _divby; - s_rec_bit++; - } + { + (*rec_src)-= _divby; + s_rec_bit++; + } } return(0); } @@ -330,10 +347,10 @@ cl_serial::tick(int cycles) s_sending= DD_FALSE; scon->set_bit1(bmTI); if (serial_out) - { - putc(s_out, serial_out); - fflush(serial_out); - } + { + putc(s_out, serial_out); + fflush(serial_out); + } s_tr_bit-= _bits; //printf("serial out %d bit rems %d\n",s_tr_bit,uc->ticks->ticks); } @@ -341,31 +358,33 @@ cl_serial::tick(int cycles) serial_in && !s_receiving) { - fd_set set; static struct timeval timeout= {0,0}; - FD_ZERO(&set); - FD_SET(fileno(serial_in), &set); - int i= select(fileno(serial_in)+1, &set, NULL, NULL, &timeout); - if (i > 0 && - FD_ISSET(fileno(serial_in), &set)) - { - s_receiving= DD_TRUE; - s_rec_bit= 0; - s_rec_tick= /*uc51->*/s_rec_t1= 0; - } +#ifdef _WIN32 + HANDLE handle = (HANDLE)_get_osfhandle(fileno(serial_in)); + assert(INVALID_HANDLE_VALUE != handle); + + if (input_avail(handle)) +#else + if (input_avail(fileno(serial_in))) +#endif + { + s_receiving= DD_TRUE; + s_rec_bit= 0; + s_rec_tick= /*uc51->*/s_rec_t1= 0; + } } if (s_receiving && (s_rec_bit >= _bits)) { if (::read(fileno(serial_in), &c, 1) == 1) - { - s_in= c; - sbuf->set(s_in); - received(c); - } + { + s_in= c; + sbuf->set(s_in); + received(c); + } s_receiving= DD_FALSE; s_rec_bit-= _bits; } - + int l; s_tr_tick+= (l= cycles * uc->clock_per_cycle()); s_rec_tick+= l; @@ -399,41 +418,41 @@ cl_serial::happen(class cl_hw *where, enum hw_event he, void *params) if (where->cathegory == HW_TIMER) { if (where->id == 1) - { - //printf("serial: timer overflowed %ld\n", uc->ticks->ticks); - s_rec_t1++; - s_tr_t1++; - } + { + //printf("serial: timer overflowed %ld\n", uc->ticks->ticks); + s_rec_t1++; + s_tr_t1++; + } if (where->id == 2 /*&& there_is_t2*/) - { - switch (he) - { - case EV_T2_MODE_CHANGED: - { - if (!t2_baud) - s_rec_t1= s_tr_t1= 0; - t_mem *d= (t_mem *)params; - t2_baud= *d & (bmRCLK | bmTCLK); - break; - } - case EV_OVERFLOW: - //printf("T2 baud ov r%d t%d\n",s_rec_t1,s_tr_t1); - s_rec_t1++; - s_tr_t1++; - break; - default: break; - } - } + { + switch (he) + { + case EV_T2_MODE_CHANGED: + { + if (!t2_baud) + s_rec_t1= s_tr_t1= 0; + t_mem *d= (t_mem *)params; + t2_baud= *d & (bmRCLK | bmTCLK); + break; + } + case EV_OVERFLOW: + //printf("T2 baud ov r%d t%d\n",s_rec_t1,s_tr_t1); + s_rec_t1++; + s_tr_t1++; + break; + default: break; + } + } } } void -cl_serial::print_info(class cl_console *con) +cl_serial::print_info(class cl_console_base *con) { char *modes[]= { "Shift, fixed clock", - "8 bit UART timer clocked", - "9 bit UART fixed clock", - "9 bit UART timer clocked" }; + "8 bit UART timer clocked", + "9 bit UART fixed clock", + "9 bit UART timer clocked" }; int sc= scon->get(); con->dd_printf("%s[%d]", id_string, id); @@ -442,7 +461,7 @@ cl_serial::print_info(class cl_console *con) if (mode == 1 || mode == 2) con->dd_printf(" (timer%d)", (t2_baud)?2:1); con->dd_printf(" MultiProc=%s", - (mode&2)?((sc&bmSM2)?"ON":"OFF"):"none"); + (mode&2)?((sc&bmSM2)?"ON":"OFF"):"none"); con->dd_printf(" irq=%s", (sfr->get(IE)&bmES)?"en":"dis"); con->dd_printf(" prio=%d", uc->it_priority(bmPS)); con->dd_printf("\n"); @@ -458,10 +477,10 @@ cl_serial::print_info(class cl_console *con) con->dd_printf(" irq=%c", (sc&bmTI)?'1':'0'); con->dd_printf("\n"); /*con->dd_printf("s_rec_t1=%d s_rec_bit=%d s_rec_tick=%d\n", - s_rec_t1, s_rec_bit, s_rec_tick); + s_rec_t1, s_rec_bit, s_rec_tick); con->dd_printf("s_tr_t1=%d s_tr_bit=%d s_tr_tick=%d\n", - s_tr_t1, s_tr_bit, s_tr_tick); - con->dd_printf("divby=%d bits=%d\n", _divby, _bits);*/ + s_tr_t1, s_tr_bit, s_tr_tick); + con->dd_printf("divby=%d bits=%d\n", _divby, _bits);*/ } diff --git a/sim/ucsim/s51.src/serialcl.h b/sim/ucsim/s51.src/serialcl.h index b727f616..859d618a 100644 --- a/sim/ucsim/s51.src/serialcl.h +++ b/sim/ucsim/s51.src/serialcl.h @@ -47,18 +47,18 @@ protected: #endif class cl_optref *serial_in_file_option; class cl_optref *serial_out_file_option; - FILE *serial_in; // Serial line input - FILE *serial_out; // Serial line output - uchar s_in; // Serial channel input reg - uchar s_out; // Serial channel output reg - bool s_sending; // Transmitter is working - bool s_receiving; // Receiver is working - int s_rec_bit; // Bit counter of receiver - int s_tr_bit; // Bit counter of transmitter - int s_rec_t1; // T1 overflows for receiving - int s_tr_t1; // T1 overflows for sending - int s_rec_tick; // Machine cycles for receiving - int s_tr_tick; // Machine cycles for sending + FILE *serial_in; // Serial line input + FILE *serial_out; // Serial line output + uchar s_in; // Serial channel input reg + uchar s_out; // Serial channel output reg + bool s_sending; // Transmitter is working + bool s_receiving; // Receiver is working + int s_rec_bit; // Bit counter of receiver + int s_tr_bit; // Bit counter of transmitter + int s_rec_t1; // T1 overflows for receiving + int s_tr_t1; // T1 overflows for sending + int s_rec_tick; // Machine cycles for receiving + int s_tr_tick; // Machine cycles for sending uchar _mode; uchar _bmREN; uchar _bmSMOD; @@ -83,7 +83,7 @@ public: virtual void reset(void); virtual void happen(class cl_hw *where, enum hw_event he, void *params); - virtual void print_info(class cl_console *con); + virtual void print_info(class cl_console_base *con); }; diff --git a/sim/ucsim/s51.src/timer0.cc b/sim/ucsim/s51.src/timer0.cc index 281f8c18..6eea6fac 100644 --- a/sim/ucsim/s51.src/timer0.cc +++ b/sim/ucsim/s51.src/timer0.cc @@ -87,22 +87,22 @@ cl_timer0::init(void) { //t_mem d; if (id == 0 || id == 1) - { - //cell_tmod= sfr->register_hw(TMOD, this, 0); - register_cell(sfr, TMOD, &cell_tmod, wtd_restore_write); - //d= cell_tmod->get(); write(cell_tmod, &d); - //cell_tcon= sfr->register_hw(TCON, this, 0); - register_cell(sfr, TCON, &cell_tcon, wtd_restore_write); - //d= cell_tcon->get(); write(cell_tcon, &d); - INT= sfr->read(P3) & mask_INT; - } + { + //cell_tmod= sfr->register_hw(TMOD, this, 0); + register_cell(sfr, TMOD, &cell_tmod, wtd_restore_write); + //d= cell_tmod->get(); write(cell_tmod, &d); + //cell_tcon= sfr->register_hw(TCON, this, 0); + register_cell(sfr, TCON, &cell_tcon, wtd_restore_write); + //d= cell_tcon->get(); write(cell_tcon, &d); + INT= sfr->read(P3) & mask_INT; + } else if (id == 2) - { - cell_tmod= 0; - //cell_tcon= sfr->register_hw(T2CON, this, 0); - register_cell(sfr, T2CON, &cell_tcon, wtd_restore_write); - //d= cell_tcon->get(); write(cell_tcon, &d); - } + { + cell_tmod= 0; + //cell_tcon= sfr->register_hw(T2CON, this, 0); + register_cell(sfr, T2CON, &cell_tcon, wtd_restore_write); + //d= cell_tcon->get(); write(cell_tcon, &d); + } //cell_tl= sfr->get_cell(addr_tl); //cell_th= sfr->get_cell(addr_th); use_cell(sfr, addr_tl, &cell_tl, wtd_restore); @@ -116,10 +116,10 @@ cl_timer0::added_to_uc(void) { if (id == 0) uc->it_sources->add(new cl_it_src(bmET0, TCON, bmTF0, 0x000b, true, - "timer #0", 2)); + "timer #0", 2)); else if (id == 1) uc->it_sources->add(new cl_it_src(bmET1, TCON, bmTF1, 0x001b, true, - "timer #1", 4)); + "timer #1", 4)); } /*t_mem @@ -135,13 +135,13 @@ cl_timer0::write(class cl_memory_cell *cell, t_mem *val) { t_mem md= *val & (mask_M0|mask_M1); if (md == mask_M0) - mode= 1; + mode= 1; else if (md == mask_M1) - mode= 2; + mode= 2; else if (md == (mask_M0|mask_M1)) - mode= 3; + mode= 3; else - mode= 0; + mode= 0; GATE= *val & mask_GATE; C_T = *val & mask_C_T; T_edge= 0; @@ -192,15 +192,15 @@ cl_timer0::do_mode0(int cycles) if (GATE) { if ((/*p3 & mask_*/INT) == 0) - return(0); + return(0); } if (C_T) { /*cycles= 0; if ((uc51->prev_p3 & mask_T) && - !(p3 & uc51->port_pins[3] & mask_T)) - cycles= 1;*/ + !(p3 & uc51->port_pins[3] & mask_T)) + cycles= 1;*/ cycles= T_edge; T_edge= 0; } @@ -209,14 +209,14 @@ cl_timer0::do_mode0(int cycles) // mod 0, TH= 8 bit t/c, TL= 5 bit precounter t_mem tl= cell_tl->add(1); if ((tl & 0x1f) == 0) - { - cell_tl->set(0); - if (!cell_th->add(1)) - { - cell_tcon->set_bit1(mask_TF); - overflow(); - } - } + { + cell_tl->set(0); + if (!cell_th->add(1)) + { + cell_tcon->set_bit1(mask_TF); + overflow(); + } + } } return(0); @@ -232,15 +232,15 @@ cl_timer0::do_mode1(int cycles) if (GATE) { if ((/*p3 & mask_*/INT) == 0) - return(0); + return(0); } if (C_T) { /*cycles= 0; if ((uc51->prev_p3 & mask_T) && - !(p3 & uc51->port_pins[3] & mask_T)) - cycles= 1;*/ + !(p3 & uc51->port_pins[3] & mask_T)) + cycles= 1;*/ cycles= T_edge; T_edge= 0; } @@ -249,13 +249,13 @@ cl_timer0::do_mode1(int cycles) { // mod 1 TH+TL= 16 bit t/c if (!cell_tl->add(1)) - { - if (!cell_th->add(1)) - { - cell_tcon->set_bit1(mask_TF); - overflow(); - } - } + { + if (!cell_th->add(1)) + { + cell_tcon->set_bit1(mask_TF); + overflow(); + } + } } return(0); @@ -271,15 +271,15 @@ cl_timer0::do_mode2(int cycles) if (GATE) { if ((/*p3 & mask_*/INT) == 0) - return(0); + return(0); } if (C_T) { /*cycles= 0; if ((uc51->prev_p3 & mask_T) && - !(p3 & uc51->port_pins[3] & mask_T)) - cycles= 1;*/ + !(p3 & uc51->port_pins[3] & mask_T)) + cycles= 1;*/ cycles= T_edge; T_edge= 0; } @@ -289,12 +289,12 @@ cl_timer0::do_mode2(int cycles) { // mod 2 TL= 8 bit t/c auto reload from TH if (!cell_tl->add(1)) - { - cell_tl->set(cell_th->get()); - cell_tcon->set_bit1(mask_TF); - //printf("timer%d overflow %d (%d) %d\n",id,uc->ticks->ticks,i,startt+(i*12)); - overflow(); - } + { + cell_tl->set(cell_th->get()); + cell_tcon->set_bit1(mask_TF); + //printf("timer%d overflow %d (%d) %d\n",id,uc->ticks->ticks,i,startt+(i*12)); + overflow(); + } //i++; } return(0); @@ -312,15 +312,15 @@ cl_timer0::do_mode3(int cycles) if (GATE) { if ((/*p3 & mask_*/INT) == 0) - goto do_th; + goto do_th; } if (C_T) { /*cycles= 0; if ((uc51->prev_p3 & mask_T) && - !(p3 & uc51->port_pins[3] & mask_T)) - cycles= 1;*/ + !(p3 & uc51->port_pins[3] & mask_T)) + cycles= 1;*/ cycles= T_edge; T_edge= 0; } @@ -328,18 +328,18 @@ cl_timer0::do_mode3(int cycles) while (cycles--) { if (!cell_tl->add(1)) - { - cell_tcon->set_bit1(mask_TF); - overflow(); - } + { + cell_tcon->set_bit1(mask_TF); + overflow(); + } } do_th: if ((cell_tcon->get() & bmTR1) != 0) while (cyc--) { - if (!cell_th->add(1)) - cell_tcon->set_bit1(bmTF1); + if (!cell_th->add(1)) + cell_tcon->set_bit1(bmTF1); } return(0); } @@ -362,15 +362,15 @@ cl_timer0::happen(class cl_hw *where, enum hw_event he, void *params) t_mem p3n= ep->new_pins & ep->new_value; t_mem p3o= ep->pins & ep->prev_value; if ((p3n & mask_T) && - !(p3o & mask_T)) - T_edge++; + !(p3o & mask_T)) + T_edge++; INT= p3n & mask_INT; //printf("timer%d p%dchanged (%02x,%02x->%02x,%02x) INT=%d(%02x) edge=%d(%02x)\n",id,where->id,ep->prev_value,ep->pins,ep->new_value,ep->new_pins,INT,mask_INT,T_edge,mask_T); } } void -cl_timer0::print_info(class cl_console *con) +cl_timer0::print_info(class cl_console_base *con) { char *modes[]= { "13 bit", "16 bit", "8 bit autoreload", "2x8 bit" }; //t_mem tmod= cell_tmod->get(); @@ -378,7 +378,7 @@ cl_timer0::print_info(class cl_console *con) class cl_address_space *sfr= uc->address_space(MEM_SFR_ID); con->dd_printf("%s[%d] 0x%04x", id_string, id, - 256*cell_th->get()+cell_tl->get()); + 256*cell_th->get()+cell_tl->get()); //int mode= tmod & (bmM00|bmM10); con->dd_printf(" %s", modes[mode]); con->dd_printf(" %s", (/*tmod&bm*/C_T/*0*/)?"counter":"timer"); diff --git a/sim/ucsim/s51.src/timer0cl.h b/sim/ucsim/s51.src/timer0cl.h index 56184f9e..f0628fb4 100644 --- a/sim/ucsim/s51.src/timer0cl.h +++ b/sim/ucsim/s51.src/timer0cl.h @@ -64,7 +64,7 @@ public: virtual void overflow(void); virtual void happen(class cl_hw *where, enum hw_event he, void *params); - virtual void print_info(class cl_console *con); + virtual void print_info(class cl_console_base *con); }; diff --git a/sim/ucsim/s51.src/timer1.cc b/sim/ucsim/s51.src/timer1.cc index 40221009..ec639869 100644 --- a/sim/ucsim/s51.src/timer1.cc +++ b/sim/ucsim/s51.src/timer1.cc @@ -61,7 +61,7 @@ cl_timer1::overflow(void) }*/ void -cl_timer1::print_info(class cl_console *con) +cl_timer1::print_info(class cl_console_base *con) { char *modes[]= { "13 bit", "16 bit", "8 bit autoreload", "stop" }; //int tmod= cell_tmod->get(); @@ -69,7 +69,7 @@ cl_timer1::print_info(class cl_console *con) class cl_address_space *sfr= uc->address_space(MEM_SFR_ID); con->dd_printf("%s[%d] 0x%04x", id_string, id, - 256*cell_th->get()+cell_tl->get()); + 256*cell_th->get()+cell_tl->get()); //int mode= (tmod & (bmM11|bmM01)) >> 4; con->dd_printf(" %s", modes[mode]); con->dd_printf(" %s", (/*tmod&bm*/C_T/*1*/)?"counter":"timer"); diff --git a/sim/ucsim/s51.src/timer1cl.h b/sim/ucsim/s51.src/timer1cl.h index d696b45c..cd182327 100644 --- a/sim/ucsim/s51.src/timer1cl.h +++ b/sim/ucsim/s51.src/timer1cl.h @@ -50,7 +50,7 @@ public: virtual int do_mode3(int cycles); //virtual void overflow(void); - virtual void print_info(class cl_console *con); + virtual void print_info(class cl_console_base *con); }; diff --git a/sim/ucsim/s51.src/timer2.cc b/sim/ucsim/s51.src/timer2.cc index 9a215c25..a238179f 100644 --- a/sim/ucsim/s51.src/timer2.cc +++ b/sim/ucsim/s51.src/timer2.cc @@ -31,7 +31,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA cl_timer2::cl_timer2(class cl_uc *auc, int aid, char *aid_string, - int afeatures): + int afeatures): cl_timer0(auc, /*2*/aid, /*"timer2"*/aid_string) { features= afeatures; @@ -44,7 +44,7 @@ cl_timer2::cl_timer2(class cl_uc *auc, int aid, char *aid_string, if (features & (t2_down|t2_clock_out)) { register_cell(sfr, T2MOD, &cell_t2mod, - wtd_restore_write); + wtd_restore_write); } } @@ -65,9 +65,9 @@ void cl_timer2::added_to_uc(void) { uc->it_sources->add(new cl_it_src(bmET2, T2CON, bmTF2, 0x002b, false, - "timer #2 TF2", 7)); + "timer #2 TF2", 7)); exf2it= new cl_it_src(bmET2, T2CON, bmEXF2, 0x002b, false, - "timer #2 EXF2", 7); + "timer #2 EXF2", 7); uc->it_sources->add(exf2it); } @@ -80,20 +80,20 @@ cl_timer2::mem_cell_changed(class cl_mem *mem, t_addr addr) if (mem && sfr && mem == sfr) { switch (addr) - { - case T2CON: - c= cell_tcon= sfr->get_cell(T2CON); - break; - } + { + case T2CON: + c= cell_tcon= sfr->get_cell(T2CON); + break; + } if (c) - { - t_mem d= c->get(); - write(c, &d); - } + { + t_mem d= c->get(); + write(c, &d); + } if (addr == addr_tl) - cell_tl= sfr->get_cell(addr_tl); + cell_tl= sfr->get_cell(addr_tl); if (addr == addr_th) - cell_th= sfr->get_cell(addr_th); + cell_th= sfr->get_cell(addr_th); cell_rcap2l= sfr->get_cell(RCAP2L); cell_rcap2h= sfr->get_cell(RCAP2H); } @@ -123,33 +123,33 @@ cl_timer2::write(class cl_memory_cell *cell, t_mem *val) CP_RL2= *val & mask_CP_RL2; EXEN2 = *val & bmEXEN2; if (!(RCLK || TCLK) && - !CP_RL2) - mode= T2MODE_RELOAD; + !CP_RL2) + mode= T2MODE_RELOAD; else if (!(RCLK || TCLK) && - CP_RL2) - mode= T2MODE_CAPTURE; + CP_RL2) + mode= T2MODE_CAPTURE; else if (RCLK || TCLK) - mode= T2MODE_BAUDRATE; + mode= T2MODE_BAUDRATE; else - mode= T2MODE_OFF; + mode= T2MODE_OFF; if (mode != oldmode) - inform_partners(EV_T2_MODE_CHANGED, val); + inform_partners(EV_T2_MODE_CHANGED, val); } else if (cell == cell_t2mod) { bit_dcen= (*val & bmDCEN) != 0; bit_t2oe= (*val & bmT2OE) != 0; if ((features & t2_down) && - bit_dcen && - mode == T2MODE_RELOAD) - { - mode= T2MODE_DOWN; - if (exf2it) - exf2it->deactivate(); - } + bit_dcen && + mode == T2MODE_RELOAD) + { + mode= T2MODE_DOWN; + if (exf2it) + exf2it->deactivate(); + } if ((features & t2_clock_out) && - bit_t2oe) - mode= T2MODE_CLKOUT; + bit_t2oe) + mode= T2MODE_CLKOUT; } if (mode != oldmode || TR && !oldtr || @@ -207,12 +207,12 @@ cl_timer2::do_t2_baud(int cycles) while (cycles--) { if (!cell_tl->add(1)) - if (!cell_th->add(1)) - { - cell_th->set(cell_rcap2h->get()); - cell_tl->set(cell_rcap2l->get()); - inform_partners(EV_OVERFLOW, 0); - } + if (!cell_th->add(1)) + { + cell_th->set(cell_rcap2h->get()); + cell_tl->set(cell_rcap2l->get()); + inform_partners(EV_OVERFLOW, 0); + } } return(resGO); } @@ -242,7 +242,7 @@ cl_timer2::do_t2_capture(int cycles) if (!cell_tl->add(1)) { if (!cell_th->add(1)) - cell_tcon->set_bit1(bmTF2); + cell_tcon->set_bit1(bmTF2); } } @@ -271,11 +271,11 @@ cl_timer2::do_t2_reload(int cycles) if (!cell_tl->add(1)) { if (!cell_th->add(1)) - { - cell_tcon->set_bit1(mask_TF); - cell_th->set(cell_rcap2h->get()); - cell_tl->set(cell_rcap2l->get()); - } + { + cell_tcon->set_bit1(mask_TF); + cell_th->set(cell_rcap2h->get()); + cell_tl->set(cell_rcap2l->get()); + } } } @@ -294,39 +294,39 @@ cl_timer2::do_t2_down(int cycles) // UP while (cycles--) if (!cell_tl->add(1)) - { - if (!cell_th->add(1)) - { - cell_tcon->set_bit1(mask_TF); - cell_th->set(cell_rcap2h->get()); - cell_tl->set(cell_rcap2l->get()); - toggle= DD_TRUE; - } - } + { + if (!cell_th->add(1)) + { + cell_tcon->set_bit1(mask_TF); + cell_th->set(cell_rcap2h->get()); + cell_tl->set(cell_rcap2l->get()); + toggle= DD_TRUE; + } + } else // DOWN while (cycles--) { - t_mem l, h; - if ((l= cell_tl->add(-1)) == 0xff) - h= cell_th->add(-1); - else - h= cell_th->get(); - if ((TYPE_UWORD)(h*256+l) < - (TYPE_UWORD)(cell_rcap2h->get()*256+cell_rcap2l->get())) - { - cell_tcon->set_bit1(mask_TF); - cell_th->set(0xff); - cell_tl->set(0xff); - toggle= DD_TRUE; - } + t_mem l, h; + if ((l= cell_tl->add(-1)) == 0xff) + h= cell_th->add(-1); + else + h= cell_th->get(); + if ((TYPE_UWORD)(h*256+l) < + (TYPE_UWORD)(cell_rcap2h->get()*256+cell_rcap2l->get())) + { + cell_tcon->set_bit1(mask_TF); + cell_th->set(0xff); + cell_tl->set(0xff); + toggle= DD_TRUE; + } } if (toggle && sfr) { class cl_memory_cell *p1= sfr->get_cell(P1); if (p1) - p1->set(p1->get() ^ bmEXF2); + p1->set(p1->get() ^ bmEXF2); } } @@ -350,20 +350,20 @@ cl_timer2::do_t2_clock_out(int cycles) while (cycles--) { if (!cell_tl->add(1)) - if (!cell_th->add(1)) - { - cell_th->set(cell_rcap2h->get()); - cell_tl->set(cell_rcap2l->get()); - inform_partners(EV_OVERFLOW, 0); - if (!C_T && - sfr) - { - // toggle T2 on P1 - class cl_memory_cell *p1= sfr->get_cell(P1); - if (p1) - p1->set(p1->get() ^ bmT2); - } - } + if (!cell_th->add(1)) + { + cell_th->set(cell_rcap2h->get()); + cell_tl->set(cell_rcap2l->get()); + inform_partners(EV_OVERFLOW, 0); + if (!C_T && + sfr) + { + // toggle T2 on P1 + class cl_memory_cell *p1= sfr->get_cell(P1); + if (p1) + p1->set(p1->get() ^ bmT2); + } + } } } @@ -379,34 +379,34 @@ cl_timer2::happen(class cl_hw *where, enum hw_event he, void *params) t_mem p1n= ep->new_pins & ep->new_value; t_mem p1o= ep->pins & ep->prev_value; if (!(p1n & mask_T) && - (p1o & mask_T)) - T_edge++; + (p1o & mask_T)) + T_edge++; if (!(p1n & bmT2EX) && - (p1o & bmT2EX)) - t2ex_edge++; + (p1o & bmT2EX)) + t2ex_edge++; bit_t2ex= p1n & bmT2EX; } } void -cl_timer2::print_info(class cl_console *con) +cl_timer2::print_info(class cl_console_base *con) { int t2con= cell_tcon->get(); con->dd_printf("%s[%d] 0x%04x", id_string, id, - 256*cell_th->get()+cell_tl->get()); + 256*cell_th->get()+cell_tl->get()); if (RCLK || TCLK) { con->dd_printf(" baud"); if (RCLK) - con->dd_printf(" RCLK"); + con->dd_printf(" RCLK"); if (TCLK) - con->dd_printf(" TCLK"); + con->dd_printf(" TCLK"); } else con->dd_printf(" %s", (CP_RL2)?"capture":"reload"); con->dd_printf(" 0x%04x", - 256*cell_rcap2h->get()+cell_rcap2l->get()); + 256*cell_rcap2h->get()+cell_rcap2l->get()); con->dd_printf(" %s", (C_T)?"counter":"timer"); con->dd_printf(" %s", (TR)?"ON":"OFF"); con->dd_printf(" irq=%c", (t2con&bmTF2)?'1':'0'); diff --git a/sim/ucsim/s51.src/timer2cl.h b/sim/ucsim/s51.src/timer2cl.h index 57e7b4f3..15d2d264 100644 --- a/sim/ucsim/s51.src/timer2cl.h +++ b/sim/ucsim/s51.src/timer2cl.h @@ -37,17 +37,17 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "timer0cl.h" -#define T2MODE_RELOAD 0 -#define T2MODE_CAPTURE 1 -#define T2MODE_BAUDRATE 2 -#define T2MODE_OFF 3 -#define T2MODE_DOWN 4 -#define T2MODE_CLKOUT 5 +#define T2MODE_RELOAD 0 +#define T2MODE_CAPTURE 1 +#define T2MODE_BAUDRATE 2 +#define T2MODE_OFF 3 +#define T2MODE_DOWN 4 +#define T2MODE_CLKOUT 5 enum t2_features { - t2_default = 0x01, - t2_down = 0x02, - t2_clock_out = 0x04 + t2_default = 0x01, + t2_down = 0x02, + t2_clock_out = 0x04 }; @@ -82,7 +82,7 @@ public: virtual void do_t2_clock_out(int cycles); virtual void happen(class cl_hw *where, enum hw_event he, void *params); - virtual void print_info(class cl_console *con); + virtual void print_info(class cl_console_base *con); }; diff --git a/sim/ucsim/s51.src/uc390.cc b/sim/ucsim/s51.src/uc390.cc index 05ebe08e..3d2ad4f5 100644 --- a/sim/ucsim/s51.src/uc390.cc +++ b/sim/ucsim/s51.src/uc390.cc @@ -393,7 +393,7 @@ cl_uc390::make_memories(void) chip->init(); memchips->add(chip); ad= new cl_address_decoder(as= address_space(MEM_IXRAM_ID), - chip, 0, 0xfff, 0); + chip, 0, 0xfff, 0); ad->init(); as->decoders->add(ad); ad->activate(0); @@ -419,7 +419,7 @@ void cl_uc390::clear_sfr(void) { cl_uc52::clear_sfr(); - /* SFR value */ + /* SFR value */ sfr->write(0x80, 0xff); /* P4 */ sfr->write(0x81, 0x07); /* SP */ sfr->write(0x86, 0x04); /* DPS */ @@ -622,7 +622,7 @@ cl_uc390::inst_jmp_Sa_dptr (uchar code) } PC = rom->validate_address(sfr->read (ph) * 256 + sfr->read (pl) + - acc->read()); + acc->read()); if (sfr->get (ACON) & 0x02) /* AM1 set: 24-bit flat? */ PC += sfr->read (px) * 256*256; @@ -695,11 +695,11 @@ cl_uc390::inst_movc_a_Sa_dptr (uchar code) if (sfr->get (ACON) & 0x02) /* AM1 set: 24-bit flat? */ acc->write (rom->read ((sfr->read (px) * 256*256 + - sfr->read (ph) * 256 + sfr->read (pl) + + sfr->read (ph) * 256 + sfr->read (pl) + acc->read()))); else acc->write (rom->read ((sfr->read (ph) * 256 + sfr->read (pl) + - acc->read()))); + acc->read()))); if (dps & 0x20) /* auto-switch dptr */ sfr->write (DPS, dps ^ 1); /* toggle dual-dptr switch */ @@ -975,14 +975,14 @@ cl_uc390::inst_lcall (uchar code, uint addr, bool intr) class cl_stack_op *so; if (addr) { - PC = addr; - so= new cl_stack_intr(instPC, PC, pushed, sp_before, sfr->get(SP)); - } + PC = addr; + so= new cl_stack_intr(instPC, PC, pushed, sp_before, sfr->get(SP)); + } else { - PC = h * 256 + l; - so= new cl_stack_call(instPC, PC, pushed, sp_before, sfr->get(SP)); - } + PC = h * 256 + l; + so= new cl_stack_call(instPC, PC, pushed, sp_before, sfr->get(SP)); + } so->init(); stack_write(so); } @@ -1129,21 +1129,21 @@ cl_uc390::disass (t_addr addr, char *sep) sprintf (temp, "%02"_M_"x", rom->get (addr + 2)); break; case 'b': // bitaddr at 2nd byte - { - t_addr ba = rom->get (addr+1); - if (get_name (ba, bit_tbl(), temp)) - break; - if (get_name ((ba<128) ? ((ba/8)+32) : (ba&0xf8), sfr_tbl(), temp)) - { - strcat (temp, "."); - sprintf (c, "%1"_M_"d", ba & 0x07); - strcat (temp, c); - break; - } - sprintf (temp, "%02x.%"_M_"d", (ba<128) ? ((ba/8)+32) : (ba&0xf8), - ba & 0x07); - break; - } + { + t_addr ba = rom->get (addr+1); + if (get_name (ba, bit_tbl(), temp)) + break; + if (get_name ((ba<128) ? ((ba/8)+32) : (ba&0xf8), sfr_tbl(), temp)) + { + strcat (temp, "."); + sprintf (c, "%1"_M_"d", ba & 0x07); + strcat (temp, c); + break; + } + sprintf (temp, "%02x.%"_M_"d", (ba<128) ? ((ba/8)+32) : (ba&0xf8), + ba & 0x07); + break; + } case 'r': // rel8 address at 2nd byte sprintf (temp, "%04"_A_"x", t_addr (addr + 2 + (signed char) (rom->get (addr + 1)))); @@ -1195,7 +1195,7 @@ cl_uc390::disass (t_addr addr, char *sep) } void -cl_uc390::print_regs (class cl_console *con) +cl_uc390::print_regs (class cl_console_base *con) { t_addr start; t_mem data; @@ -1211,38 +1211,38 @@ cl_uc390::print_regs (class cl_console *con) start = sfr->get (PSW) & 0x18; data = iram->get (iram->get (start)); con->dd_printf("%06x %02x %c", - iram->get (start), data, isprint (data) ? data : '.'); + iram->get (start), data, isprint (data) ? data : '.'); con->dd_printf(" ACC= 0x%02x %3d %c B= 0x%02x", - sfr->get (ACC), sfr->get (ACC), - isprint (sfr->get (ACC)) ? - (sfr->get (ACC)) : '.', sfr->get (B)); + sfr->get (ACC), sfr->get (ACC), + isprint (sfr->get (ACC)) ? + (sfr->get (ACC)) : '.', sfr->get (B)); eram2xram (); data = get_mem (MEM_XRAM_ID, sfr->get (DPX) * 256*256 + sfr->get (DPH) * 256 + sfr->get (DPL)); con->dd_printf (" DPTR= 0x%02x%02x%02x @DPTR= 0x%02x %3d %c\n", - sfr->get (DPX), sfr->get (DPH), sfr->get (DPL), - data, data, isprint (data) ? data : '.'); + sfr->get (DPX), sfr->get (DPH), sfr->get (DPL), + data, data, isprint (data) ? data : '.'); data = iram->get (iram->get (start + 1)); con->dd_printf ("%06x %02x %c", iram->get (start + 1), data, - isprint (data) ? data : '.'); + isprint (data) ? data : '.'); data= sfr->get (PSW); con->dd_printf (" PSW= 0x%02x CY=%c AC=%c OV=%c P=%c ", - data, - (data & bmCY) ? '1' : '0', (data & bmAC) ? '1' : '0', - (data & bmOV) ? '1' : '0', (data & bmP ) ? '1' : '0' - ); + data, + (data & bmCY) ? '1' : '0', (data & bmAC) ? '1' : '0', + (data & bmOV) ? '1' : '0', (data & bmP ) ? '1' : '0' + ); /* show stack pointer */ if (sfr->get (ACON) & 0x04) /* SA: 10 bit stack */ con->dd_printf ("SP10 0x%03x %3d\n", - (sfr->get (ESP) & 3) * 256 + sfr->get (SP), - get_mem (MEM_IXRAM_ID, (sfr->get (ESP) & 3) * 256 + sfr->get (SP)) - ); + (sfr->get (ESP) & 3) * 256 + sfr->get (SP), + get_mem (MEM_IXRAM_ID, (sfr->get (ESP) & 3) * 256 + sfr->get (SP)) + ); else con->dd_printf ("SP 0x%02x %3d\n", - sfr->get (SP), - iram->get (sfr->get (SP)) - ); + sfr->get (SP), + iram->get (sfr->get (SP)) + ); print_disass (PC, con); } diff --git a/sim/ucsim/s51.src/uc390cl.h b/sim/ucsim/s51.src/uc390cl.h index e81d4fcb..399a937f 100644 --- a/sim/ucsim/s51.src/uc390cl.h +++ b/sim/ucsim/s51.src/uc390cl.h @@ -74,7 +74,7 @@ public: /* mods for disassembly of flat24 */ virtual struct dis_entry *dis_tbl(void); virtual char * disass(t_addr addr, char *sep); - virtual void print_regs(class cl_console *con); + virtual void print_regs(class cl_console_base *con); protected: int flat24_flag; /* true if processor == ds390f */ diff --git a/sim/ucsim/s51.src/uc390hw.cc b/sim/ucsim/s51.src/uc390hw.cc index d01c1722..5012d676 100644 --- a/sim/ucsim/s51.src/uc390hw.cc +++ b/sim/ucsim/s51.src/uc390hw.cc @@ -93,10 +93,10 @@ cl_uc390_hw::read (class cl_memory_cell *cell) { if (ctm_ticks && uc390->ticks->ticks >= ctm_ticks + 65535) - { - ctm_ticks = 0; - cell->set (cell->get() | 0x08); /* set CKRDY */ - } + { + ctm_ticks = 0; + cell->set (cell->get() | 0x08); /* set CKRDY */ + } } return cell->get(); } @@ -111,7 +111,7 @@ cl_uc390_hw::write (class cl_memory_cell *cell, t_mem *val) /* Bit 0 (BGS) is TA-protected */ if (timed_access_state != 2 || timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles - *val = (*val & ~0x01) | (cell_exif->get() & 0x01); + *val = (*val & ~0x01) | (cell_exif->get() & 0x01); /* CKRDY and RGMD are read-only */ *val = (*val & 0x0c) | (*val & ~0x0c); @@ -131,12 +131,12 @@ cl_uc390_hw::write (class cl_memory_cell *cell, t_mem *val) timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles *val = cell_acon->get(); else - { + { - /* lockout: IDM1:IDM0 and SA can't be set at the same time */ - if ((cell_mcon->get() & 0xc0) == 0xc0) /* IDM1 and IDM0 set? */ - *val &= ~0x04; /* lockout SA */ - } + /* lockout: IDM1:IDM0 and SA can't be set at the same time */ + if ((cell_mcon->get() & 0xc0) == 0xc0) /* IDM1 and IDM0 set? */ + *val &= ~0x04; /* lockout SA */ + } *val |= 0xf8; /* always 1 */ } else if (cell == cell_p5cnt) @@ -144,22 +144,22 @@ cl_uc390_hw::write (class cl_memory_cell *cell, t_mem *val) /* Bits 0...2 are TA-protected */ if (timed_access_state != 2 || timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles - *val = (*val & ~0x07) | (cell_p5cnt->get() & 0x07); + *val = (*val & ~0x07) | (cell_p5cnt->get() & 0x07); } else if (cell == cell_c0c) { /* Bit 3 (CRST) is TA-protected */ if (timed_access_state != 2 || timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles - *val = (*val & ~0x08) | (cell_c0c->get() & 0x08); + *val = (*val & ~0x08) | (cell_c0c->get() & 0x08); } else if (cell == cell_pmr) { /* fixme: check previous state */ if ((*val & 0xd0) == 0x90) /* CD1:CD0 set to 10, CTM set */ { - ctm_ticks = uc390->ticks->ticks; - cell_exif->set (cell_exif->get() & ~0x08); /* clear CKRDY */ + ctm_ticks = uc390->ticks->ticks; + cell_exif->set (cell_exif->get() & ~0x08); /* clear CKRDY */ } else ctm_ticks = 0; @@ -170,7 +170,7 @@ cl_uc390_hw::write (class cl_memory_cell *cell, t_mem *val) /* MCON is TA-protected */ if (timed_access_state != 2 || timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles - *val = cell_mcon->get(); + *val = cell_mcon->get(); else /* lockout: IDM1:IDM0 and SA can't be set at the same time */ if ((cell_acon->get() & 0x04) == 0x04) /* SA set? */ @@ -199,7 +199,7 @@ cl_uc390_hw::write (class cl_memory_cell *cell, t_mem *val) /* COR is TA-protected */ if (timed_access_state != 2 || timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles - *val = cell_cor->get(); + *val = cell_cor->get(); } else if (cell == cell_mcnt0) { @@ -226,14 +226,14 @@ cl_uc390_hw::write (class cl_memory_cell *cell, t_mem *val) /* Bits 0, 1, 3 and 6 are TA-protected */ if (timed_access_state != 2 || timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles - *val = (*val & ~0x4b) | (cell_wdcon->get() & 0x4b); + *val = (*val & ~0x4b) | (cell_wdcon->get() & 0x4b); } else if (cell == cell_c1c) { /* Bit 3 (CRST) is TA-protected */ if (timed_access_state != 2 || timed_access_ticks + 2*12 < uc390->ticks->ticks) // fixme: 3 cycles - *val = (*val & ~0x08) | (cell_c1c->get() & 0x08); + *val = (*val & ~0x08) | (cell_c1c->get() & 0x08); } } @@ -245,23 +245,23 @@ cl_uc390_hw::mem_cell_changed (class cl_m *mem, t_addr addr) if (mem && sfr && mem == sfr) switch (addr) { - case DPS: cell_dps = sfr->get_cell (DPS); break; - case P4CNT: cell_p4cnt = sfr->get_cell (P4CNT); break; - case EXIF: cell_exif = sfr->get_cell (EXIF); break; - case ACON: cell_acon = sfr->get_cell (ACON); break; - case P5CNT: cell_p5cnt = sfr->get_cell (P5CNT); break; - case C0C: cell_c0c = sfr->get_cell (C0C); break; - case PMR: cell_pmr = sfr->get_cell (PMR); break; - case MCON: cell_mcon = sfr->get_cell (MCON); break; - case TA: cell_ta = sfr->get_cell (TA); break; - case COR: cell_cor = sfr->get_cell (COR); break; - case MCNT0: cell_mcnt0 = sfr->get_cell (MCNT0); break; - case MCNT1: cell_mcnt1 = sfr->get_cell (MCNT1); break; - case MA: cell_ma = sfr->get_cell (MA); break; - case MB: cell_mb = sfr->get_cell (MB); break; - case MC: cell_mc = sfr->get_cell (MC); break; - case WDCON: cell_wdcon = sfr->get_cell (WDCON); break; - case C1C: cell_c1c = sfr->get_cell (C1C); break; + case DPS: cell_dps = sfr->get_cell (DPS); break; + case P4CNT: cell_p4cnt = sfr->get_cell (P4CNT); break; + case EXIF: cell_exif = sfr->get_cell (EXIF); break; + case ACON: cell_acon = sfr->get_cell (ACON); break; + case P5CNT: cell_p5cnt = sfr->get_cell (P5CNT); break; + case C0C: cell_c0c = sfr->get_cell (C0C); break; + case PMR: cell_pmr = sfr->get_cell (PMR); break; + case MCON: cell_mcon = sfr->get_cell (MCON); break; + case TA: cell_ta = sfr->get_cell (TA); break; + case COR: cell_cor = sfr->get_cell (COR); break; + case MCNT0: cell_mcnt0 = sfr->get_cell (MCNT0); break; + case MCNT1: cell_mcnt1 = sfr->get_cell (MCNT1); break; + case MA: cell_ma = sfr->get_cell (MA); break; + case MB: cell_mb = sfr->get_cell (MB); break; + case MC: cell_mc = sfr->get_cell (MC); break; + case WDCON: cell_wdcon = sfr->get_cell (WDCON); break; + case C1C: cell_c1c = sfr->get_cell (C1C); break; } }*/ @@ -273,7 +273,7 @@ cl_uc390_hw::reset(void) } void -cl_uc390_hw::print_info(class cl_console *con) +cl_uc390_hw::print_info(class cl_console_base *con) { int i; long l; @@ -282,7 +282,7 @@ cl_uc390_hw::print_info(class cl_console *con) con->dd_printf ("%s" " EXIF 0x%02x: IE5 %c IE4 %c IE3 %c IE2 %c CKRDY %c RGMD %c RGSL %c BGS %c\n", id_string, - i, + i, (i & 0x80) ? '1' : '0', (i & 0x40) ? '1' : '0', (i & 0x20) ? '1' : '0', @@ -293,7 +293,7 @@ cl_uc390_hw::print_info(class cl_console *con) (i & 0x01) ? '1' : '0'); i = sfr->get (DPS); con->dd_printf ("\tDPS 0x%02x: ID1 %c ID0 %c TSL %c SEL %c\n", - i, + i, (i & 0x80) ? '1' : '0', (i & 0x40) ? '1' : '0', (i & 0x20) ? '1' : '0', diff --git a/sim/ucsim/s51.src/uc390hwcl.h b/sim/ucsim/s51.src/uc390hwcl.h index a3476d17..0f4f1254 100644 --- a/sim/ucsim/s51.src/uc390hwcl.h +++ b/sim/ucsim/s51.src/uc390hwcl.h @@ -55,7 +55,7 @@ public: //virtual void mem_cell_changed (class cl_mem *mem, t_addr addr); virtual void reset (void); - virtual void print_info (class cl_console *con); + virtual void print_info (class cl_console_base *con); }; diff --git a/sim/ucsim/s51.src/uc51.cc b/sim/ucsim/s51.src/uc51.cc index bd23d3d7..aec033ac 100644 --- a/sim/ucsim/s51.src/uc51.cc +++ b/sim/ucsim/s51.src/uc51.cc @@ -30,9 +30,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include -#ifdef HAVE_TERMIOS_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif @@ -135,8 +132,8 @@ cl_51core::id_string(void) for (i= 0; cpus_51[i].type_str != NULL && cpus_51[i].type != type; i++) ; sprintf(id_string_51, "%s %s", - cpus_51[i].type_str?cpus_51[i].type_str:"51", - (technology==CPU_HMOS)?"HMOS":"CMOS"); + cpus_51[i].type_str?cpus_51[i].type_str:"51", + (technology==CPU_HMOS)?"HMOS":"CMOS"); return(id_string_51); } @@ -152,10 +149,8 @@ cl_51core::mk_hw_elements(void) h->init(); hws->add(h= new cl_timer1(this, 1, "timer1")); h->init(); -#ifdef HAVE_TERMIOS_H hws->add(h= new cl_serial(this)); h->init(); -#endif hws->add(h= new cl_port(this, 0)); h->init(); hws->add(h= new cl_port(this, 1)); @@ -237,7 +232,7 @@ cl_51core::make_memories(void) chip->init(); memchips->add(chip); ad= new cl_address_decoder(as= rom/*address_space(MEM_ROM_ID)*/, - chip, 0, 0xffff, 0); + chip, 0, 0xffff, 0); ad->init(); as->decoders->add(ad); ad->activate(0); @@ -246,7 +241,7 @@ cl_51core::make_memories(void) chip->init(); memchips->add(chip); ad= new cl_address_decoder(as= iram/*address_space(MEM_IRAM_ID)*/, - chip, 0, 0x7f, 0); + chip, 0, 0x7f, 0); ad->init(); as->decoders->add(ad); ad->activate(0); @@ -255,7 +250,7 @@ cl_51core::make_memories(void) chip->init(); memchips->add(chip); ad= new cl_address_decoder(as= xram/*address_space(MEM_XRAM_ID)*/, - chip, 0, 0xffff, 0); + chip, 0, 0xffff, 0); ad->init(); as->decoders->add(ad); ad->activate(0); @@ -264,7 +259,7 @@ cl_51core::make_memories(void) chip->init(); memchips->add(chip); ad= new cl_address_decoder(as= sfr/*address_space(MEM_SFR_ID)*/, - chip, 0x80, 0xff, 0); + chip, 0x80, 0xff, 0); ad->init(); as->decoders->add(ad); ad->activate(0); @@ -284,13 +279,13 @@ cl_51core::~cl_51core(void) if (serial_out) { if (isatty(fileno(serial_out))) - tcsetattr(fileno(serial_out), TCSANOW, &saved_attributes_out); + tcsetattr(fileno(serial_out), TCSANOW, &saved_attributes_out); fclose(serial_out); } if (serial_in) { if (isatty(fileno(serial_in))) - tcsetattr(fileno(serial_in), TCSANOW, &saved_attributes_in); + tcsetattr(fileno(serial_in), TCSANOW, &saved_attributes_in); fclose(serial_in); } */ @@ -332,75 +327,75 @@ cl_51core::disass(t_addr addr, char *sep) while (*b) { if (*b == '%') - { - b++; - switch (*(b++)) - { - case 'A': // absolute address - sprintf(temp, "%04"_A_"x", - t_addr((addr&0xf800)| - (((code>>5)&0x07)*256 + - rom->get(addr+1)))); - break; - case 'l': // long address - sprintf(temp, "%04"_A_"x", - t_addr(rom->get(addr+1)*256 + - rom->get(addr+2))); - break; - case 'a': // addr8 (direct address) at 2nd byte - if (!get_name(rom->get(addr+1), sfr_tbl(), temp)) - sprintf(temp, "%02"_M_"x", rom->get(addr+1)); - break; - case '8': // addr8 (direct address) at 3rd byte - if (!get_name(rom->get(addr+2), sfr_tbl(), temp)) - sprintf(temp, "%02"_M_"x", rom->get(addr+2)); - //sprintf(temp, "%02"_M_"x", rom->get(addr+2)); - break; - case 'b': // bitaddr at 2nd byte - { - t_addr ba= rom->get(addr+1); - if (get_name(ba, bit_tbl(), temp)) - break; - if (get_name((ba<128)?((ba/8)+32):(ba&0xf8), sfr_tbl(), temp)) - { - strcat(temp, "."); - sprintf(c, "%1"_M_"d", ba & 0x07); - strcat(temp, c); - break; - } - sprintf(temp, "%02x.%"_M_"d", (ba<128)?((ba/8)+32):(ba&0xf8), - ba & 0x07); - break; - } - case 'r': // rel8 address at 2nd byte - sprintf(temp, "%04"_A_"x", - t_addr(addr+2+(signed char)(rom->get(addr+1)))); - break; - case 'R': // rel8 address at 3rd byte - sprintf(temp, "%04"_A_"x", - t_addr(addr+3+(signed char)(rom->get(addr+2)))); - break; - case 'd': // data8 at 2nd byte - sprintf(temp, "%02"_M_"x", rom->get(addr+1)); - break; - case 'D': // data8 at 3rd byte - sprintf(temp, "%02"_M_"x", rom->get(addr+2)); - break; - case '6': // data16 at 2nd(H)-3rd(L) byte - sprintf(temp, "%04"_A_"x", - t_addr(rom->get(addr+1)*256 + - rom->get(addr+2))); - break; - default: - strcpy(temp, "?"); - break; - } - t= temp; - while (*t) - *(p++)= *(t++); - } + { + b++; + switch (*(b++)) + { + case 'A': // absolute address + sprintf(temp, "%04"_A_"x", + t_addr((addr&0xf800)| + (((code>>5)&0x07)*256 + + rom->get(addr+1)))); + break; + case 'l': // long address + sprintf(temp, "%04"_A_"x", + t_addr(rom->get(addr+1)*256 + + rom->get(addr+2))); + break; + case 'a': // addr8 (direct address) at 2nd byte + if (!get_name(rom->get(addr+1), sfr_tbl(), temp)) + sprintf(temp, "%02"_M_"x", rom->get(addr+1)); + break; + case '8': // addr8 (direct address) at 3rd byte + if (!get_name(rom->get(addr+2), sfr_tbl(), temp)) + sprintf(temp, "%02"_M_"x", rom->get(addr+2)); + //sprintf(temp, "%02"_M_"x", rom->get(addr+2)); + break; + case 'b': // bitaddr at 2nd byte + { + t_addr ba= rom->get(addr+1); + if (get_name(ba, bit_tbl(), temp)) + break; + if (get_name((ba<128)?((ba/8)+32):(ba&0xf8), sfr_tbl(), temp)) + { + strcat(temp, "."); + sprintf(c, "%1"_M_"d", ba & 0x07); + strcat(temp, c); + break; + } + sprintf(temp, "%02x.%"_M_"d", (ba<128)?((ba/8)+32):(ba&0xf8), + ba & 0x07); + break; + } + case 'r': // rel8 address at 2nd byte + sprintf(temp, "%04"_A_"x", + t_addr(addr+2+(signed char)(rom->get(addr+1)))); + break; + case 'R': // rel8 address at 3rd byte + sprintf(temp, "%04"_A_"x", + t_addr(addr+3+(signed char)(rom->get(addr+2)))); + break; + case 'd': // data8 at 2nd byte + sprintf(temp, "%02"_M_"x", rom->get(addr+1)); + break; + case 'D': // data8 at 3rd byte + sprintf(temp, "%02"_M_"x", rom->get(addr+2)); + break; + case '6': // data16 at 2nd(H)-3rd(L) byte + sprintf(temp, "%04"_A_"x", + t_addr(rom->get(addr+1)*256 + + rom->get(addr+2))); + break; + default: + strcpy(temp, "?"); + break; + } + t= temp; + while (*t) + *(p++)= *(t++); + } else - *(p++)= *(b++); + *(p++)= *(b++); } *p= '\0'; @@ -421,7 +416,7 @@ cl_51core::disass(t_addr addr, char *sep) if (sep == NULL) { while (strlen(buf) < 6) - strcat(buf, " "); + strcat(buf, " "); } else strcat(buf, sep); @@ -431,7 +426,7 @@ cl_51core::disass(t_addr addr, char *sep) void -cl_51core::print_regs(class cl_console *con) +cl_51core::print_regs(class cl_console_base *con) { t_addr start; uchar data; @@ -442,22 +437,22 @@ cl_51core::print_regs(class cl_console *con) start= psw->get() & 0x18; data= iram->get(iram->get(start)); con->dd_printf("%06x %02x %c", - iram->get(start), data, isprint(data)?data:'.'); + iram->get(start), data, isprint(data)?data:'.'); con->dd_printf(" ACC= 0x%02x %3d %c B= 0x%02x", sfr->get(ACC), sfr->get(ACC), - isprint(sfr->get(ACC))?(sfr->get(ACC)):'.', sfr->get(B)); + isprint(sfr->get(ACC))?(sfr->get(ACC)):'.', sfr->get(B)); //eram2xram(); data= xram->get(sfr->get(DPH)*256+sfr->get(DPL)); con->dd_printf(" DPTR= 0x%02x%02x @DPTR= 0x%02x %3d %c\n", sfr->get(DPH), - sfr->get(DPL), data, data, isprint(data)?data:'.'); + sfr->get(DPL), data, data, isprint(data)?data:'.'); data= iram->get(iram->get(start+1)); con->dd_printf("%06x %02x %c", iram->get(start+1), data, - isprint(data)?data:'.'); + isprint(data)?data:'.'); data= psw->get(); con->dd_printf(" PSW= 0x%02x CY=%c AC=%c OV=%c P=%c\n", data, - (data&bmCY)?'1':'0', (data&bmAC)?'1':'0', - (data&bmOV)?'1':'0', (data&bmP)?'1':'0'); + (data&bmCY)?'1':'0', (data&bmAC)?'1':'0', + (data&bmOV)?'1':'0', (data&bmP)?'1':'0'); print_disass(PC, con); } @@ -493,7 +488,7 @@ cl_51core::bit2mem(t_addr bitaddr, t_addr *memaddr, t_mem *bitmask) t_addr cl_51core::bit_address(class cl_memory *mem, - t_addr mem_address, int bit_number) + t_addr mem_address, int bit_number) { if (bit_number < 0 || bit_number > 7 || @@ -508,16 +503,16 @@ cl_51core::bit_address(class cl_memory *mem, if (mem == sfr) { if (mem_address < 128 || - mem_address % 8 != 0 || - mem_address > 255) - return(-1); + mem_address % 8 != 0 || + mem_address > 255) + return(-1); return(128 + (mem_address-128) + bit_number); } if (mem == iram) { if (mem_address < 0x20 || - mem_address >= 0x20+32) - return(-1); + mem_address >= 0x20+32) + return(-1); return((mem_address-0x20)*8 + bit_number); } return(-1); @@ -593,50 +588,50 @@ cl_51core::analyze(t_addr addr) code= rom->get(addr); tabl= &(dis_tbl()[code]); while (!inst_at(addr) && - code != 0xa5 /* break point */) + code != 0xa5 /* break point */) { set_inst_at(addr); switch (tabl->branch) - { - case 'a': // acall - analyze((addr & 0xf800)| - ((rom->get(addr+1)&0x07)*256+ - rom->get(addr+2))); - analyze(addr+tabl->length); - break; - case 'A': // ajmp - addr= (addr & 0xf800)| - ((rom->get(addr+1) & 0x07)*256 + rom->get(addr+2)); - break; - case 'l': // lcall - analyze(rom->get(addr+1)*256 + rom->get(addr+2)); - analyze(addr+tabl->length); - break; - case 'L': // ljmp - addr= rom->get(addr+1)*256 + rom->get(addr+2); - break; - case 'r': // reljmp (2nd byte) - analyze(rom->validate_address(addr+(signed char)(rom->get(addr+1)))); - analyze(addr+tabl->length); - break; - case 'R': // reljmp (3rd byte) - analyze(rom->validate_address(addr+(signed char)(rom->get(addr+2)))); - analyze(addr+tabl->length); - break; - case 's': // sjmp - { - signed char target; - target= rom->get(addr+1); - addr+= 2; - addr= rom->validate_address(addr+target); - break; - } - case '_': - return; - default: - addr= rom->validate_address(addr+tabl->length); - break; - } + { + case 'a': // acall + analyze((addr & 0xf800)| + ((rom->get(addr+1)&0x07)*256+ + rom->get(addr+2))); + analyze(addr+tabl->length); + break; + case 'A': // ajmp + addr= (addr & 0xf800)| + ((rom->get(addr+1) & 0x07)*256 + rom->get(addr+2)); + break; + case 'l': // lcall + analyze(rom->get(addr+1)*256 + rom->get(addr+2)); + analyze(addr+tabl->length); + break; + case 'L': // ljmp + addr= rom->get(addr+1)*256 + rom->get(addr+2); + break; + case 'r': // reljmp (2nd byte) + analyze(rom->validate_address(addr+(signed char)(rom->get(addr+1)))); + analyze(addr+tabl->length); + break; + case 'R': // reljmp (3rd byte) + analyze(rom->validate_address(addr+(signed char)(rom->get(addr+2)))); + analyze(addr+tabl->length); + break; + case 's': // sjmp + { + signed char target; + target= rom->get(addr+1); + addr+= 2; + addr= rom->validate_address(addr+target); + break; + } + case '_': + return; + default: + addr= rom->validate_address(addr+tabl->length); + break; + } code= rom->get(addr); tabl= &(dis_tbl()[code]); } @@ -862,89 +857,89 @@ cl_51core::exec_inst(void) * (inp_avail will be TRUE if ENTER is pressed) and it can confuse * command interepter. */ -//static class cl_console *c= NULL; +//static class cl_console_base *c= NULL; int cl_51core::do_inst(int step) { result= resGO; while ((result == resGO) && - (state != stPD) && - (step != 0)) + (state != stPD) && + (step != 0)) { if (step > 0) - step--; + step--; if (state == stGO) - { - interrupt->was_reti= DD_FALSE; - pre_inst(); - result= exec_inst(); - post_inst(); - /* - { - if (c) - print_regs(c); - else - { - if (sim->app->get_commander()==NULL) - printf("no commander PC=0x%x\n",PC); - else - if (sim->app->get_commander()->frozen_console==NULL) - printf("no frozen console PC=0x%x\n",PC); - else - c= sim->app->get_commander()->frozen_console; - if (c) - print_regs(c); - else - printf("no console PC=0x%x\n",PC); - } - } - */ - /*if (result == resGO) - result= check_events();*/ - } + { + interrupt->was_reti= DD_FALSE; + pre_inst(); + result= exec_inst(); + post_inst(); + /* + { + if (c) + print_regs(c); + else + { + if (sim->app->get_commander()==NULL) + printf("no commander PC=0x%x\n",PC); + else + if (sim->app->get_commander()->frozen_console==NULL) + printf("no frozen console PC=0x%x\n",PC); + else + c= sim->app->get_commander()->frozen_console; + if (c) + print_regs(c); + else + printf("no console PC=0x%x\n",PC); + } + } + */ + /*if (result == resGO) + result= check_events();*/ + } else - { - // tick hw in idle state - inst_ticks= 1; - post_inst(); - tick(1); - } + { + // tick hw in idle state + inst_ticks= 1; + post_inst(); + tick(1); + } if (result == resGO) - { - int res; - if ((res= do_interrupt()) != resGO) - result= res; - else - result= idle_pd(); - } + { + int res; + if ((res= do_interrupt()) != resGO) + result= res; + else + result= idle_pd(); + } if ((step < 0) && - ((ticks->ticks % 100000) < 50)) - { - if (sim->app->get_commander()->input_avail_on_frozen()) - { - result= resUSER; - } - else - if (sim->app->get_commander()->input_avail()) - break; - } + ((ticks->ticks % 100000) < 50)) + { + if (sim->app->get_commander()->input_avail_on_frozen()) + { + result= resUSER; + } + else + if (sim->app->get_commander()->input_avail()) + break; + } if (((result == resINTERRUPT) && - stop_at_it) || - result >= resSTOP) - { - sim->stop(result); - break; - } + stop_at_it) || + result >= resSTOP) + { + sim->stop(result); + break; + } } if (state == stPD) { //FIXME: tick outsiders eg. watchdog if (sim->app->get_commander()->input_avail_on_frozen()) - { - //fprintf(stderr,"uc: inp avail in PD mode, user stop\n"); + { + //fprintf(stderr,"uc: inp avail in PD mode, user stop\n"); result= resUSER; sim->stop(result); - } + } } return(result); } @@ -963,41 +958,41 @@ cl_51core::post_inst(void) { // IE0 edge triggered if (p3_int0_edge) - { - // falling edge on INT0 - sim->app->get_commander()-> - debug("%g sec (%d clks): Falling edge detected on INT0 (P3.2)\n", - get_rtime(), ticks->ticks); - sfr->set_bit1(TCON, bmIE0); - p3_int0_edge= 0; - } + { + // falling edge on INT0 + sim->app->get_commander()-> + debug("%g sec (%d clks): Falling edge detected on INT0 (P3.2)\n", + get_rtime(), ticks->ticks); + sfr->set_bit1(TCON, bmIE0); + p3_int0_edge= 0; + } } else { // IE0 level triggered if (p3 & bm_INT0) - sfr->set_bit0(TCON, bmIE0); + sfr->set_bit0(TCON, bmIE0); else - sfr->set_bit1(TCON, bmIE0); + sfr->set_bit1(TCON, bmIE0); } if ((tcon & bmIT1)) { // IE1 edge triggered if (p3_int1_edge) - { - // falling edge on INT1 - sfr->set_bit1(TCON, bmIE1); - p3_int1_edge= 0; - } + { + // falling edge on INT1 + sfr->set_bit1(TCON, bmIE1); + p3_int1_edge= 0; + } } else { // IE1 level triggered if (p3 & bm_INT1) - sfr->set_bit0(TCON, bmIE1); + sfr->set_bit0(TCON, bmIE1); else - sfr->set_bit1(TCON, bmIE1); - }*/ + sfr->set_bit1(TCON, bmIE1); + }*/ //prev_p3= p3 & port_pins[3]; //prev_p1= p3 & port_pins[1]; //} @@ -1035,28 +1030,28 @@ cl_51core::do_interrupt(void) { class cl_it_src *is= (class cl_it_src *)(it_sources->at(i)); if (is->is_active() && - (ie & is->ie_mask) && - (sfr->get(is->src_reg) & is->src_mask)) - { - int pr= it_priority(is->ie_mask); - if (il->level >= 0 && - pr <= il->level) - continue; - if (state == stIDLE) - { - state= stGO; - sfr->set_bit0(PCON, bmIDL); - interrupt->was_reti= DD_TRUE; - return(resGO); - } - if (is->clr_bit) - sfr->set_bit0(is->src_reg, is->src_mask); - sim->app->get_commander()-> - debug("%g sec (%d clks): Accepting interrupt `%s' PC= 0x%06x\n", - get_rtime(), ticks->ticks, object_name(is), PC); - IL= new it_level(pr, is->addr, PC, is); - return(accept_it(IL)); - } + (ie & is->ie_mask) && + (sfr->get(is->src_reg) & is->src_mask)) + { + int pr= it_priority(is->ie_mask); + if (il->level >= 0 && + pr <= il->level) + continue; + if (state == stIDLE) + { + state= stGO; + sfr->set_bit0(PCON, bmIDL); + interrupt->was_reti= DD_TRUE; + return(resGO); + } + if (is->clr_bit) + sfr->set_bit0(is->src_reg, is->src_mask); + sim->app->get_commander()-> + debug("%g sec (%d clks): Accepting interrupt `%s' PC= 0x%06x\n", + get_rtime(), ticks->ticks, object_name(is), PC); + IL= new it_level(pr, is->addr, PC, is); + return(accept_it(IL)); + } } return(resGO); } @@ -1103,18 +1098,18 @@ cl_51core::idle_pd(void) if (pcon & bmIDL) { if (state != stIDLE) - sim->app->get_commander()-> - debug("%g sec (%d clks): CPU in Idle mode (PC=0x%x, PCON=0x%x)\n", - get_rtime(), ticks->ticks, PC, pcon); + sim->app->get_commander()-> + debug("%g sec (%d clks): CPU in Idle mode (PC=0x%x, PCON=0x%x)\n", + get_rtime(), ticks->ticks, PC, pcon); state= stIDLE; //was_reti= 1; } if (pcon & bmPD) { if (state != stPD) - sim->app->get_commander()-> - debug("%g sec (%d clks): CPU in PowerDown mode\n", - get_rtime(), ticks->ticks); + sim->app->get_commander()-> + debug("%g sec (%d clks): CPU in PowerDown mode\n", + get_rtime(), ticks->ticks); state= stPD; } return(resGO); @@ -1137,7 +1132,7 @@ cl_51core::check_events(void) { eb= (class cl_ev_brk *)(ebrk->at(i)); if (eb->match(&event_at)) - return(resBREAKPOINT); + return(resBREAKPOINT); } return(resGO); }*/ @@ -1254,20 +1249,20 @@ cl_uc51_dummy_hw::write(class cl_memory_cell *cell, t_mem *val) p = DD_FALSE; uc= *val; for (i= 0; i < 8; i++) - { - if (uc & 1) - p= !p; - uc>>= 1; - } + { + if (uc & 1) + p= !p; + uc>>= 1; + } if (p) - cell_psw->set_bit1(bmP); + cell_psw->set_bit1(bmP); else - cell_psw->set_bit0(bmP); + cell_psw->set_bit0(bmP); } else if (cell == cell_sp) { if (*val > uc->sp_max) - uc->sp_max= *val; + uc->sp_max= *val; uc->sp_avg= (uc->sp_avg+(*val))/2; } /*else if (cell == cell_pcon) @@ -1289,11 +1284,11 @@ cl_uc51_dummy_hw::happen(class cl_hw *where, enum hw_event he, void *params) t_mem p3o= ep->pins & ep->prev_value; t_mem p3n= ep->new_pins & ep->new_value; if ((p3o & bm_INT0) && - !(p3n & bm_INT0)) - uc51->p3_int0_edge++; + !(p3n & bm_INT0)) + uc51->p3_int0_edge++; if ((p3o & bm_INT1) && - !(p3n & bm_INT1)) - uc51->p3_int1_edge++; + !(p3n & bm_INT1)) + uc51->p3_int1_edge++; } }*/ diff --git a/sim/ucsim/s51.src/uc51cl.h b/sim/ucsim/s51.src/uc51cl.h index b3db9e02..58950df2 100644 --- a/sim/ucsim/s51.src/uc51cl.h +++ b/sim/ucsim/s51.src/uc51cl.h @@ -73,17 +73,17 @@ public: public: // Help to detect external it requests (falling edge) - uchar prev_p1; // Prev state of P1 - uchar prev_p3; // Prev state of P3 + uchar prev_p1; // Prev state of P1 + uchar prev_p3; // Prev state of P3 int p3_int0_edge, p3_int1_edge; public: // Simulation of interrupt system class cl_interrupt *interrupt; - //bool was_reti; // Instruction had an effect on IE + //bool was_reti; // Instruction had an effect on IE public: - int result; // result of instruction execution + int result; // result of instruction execution cl_51core(int Itype, int Itech, class cl_sim *asim); virtual ~cl_51core(void); @@ -99,12 +99,12 @@ public: virtual struct name_entry *sfr_tbl(void); virtual struct name_entry *bit_tbl(void); virtual char *disass(t_addr addr, char *sep); - virtual void print_regs(class cl_console *con); + virtual void print_regs(class cl_console_base *con); virtual class cl_address_space *bit2mem(t_addr bitaddr, - t_addr *memaddr, t_mem *bitmask); + t_addr *memaddr, t_mem *bitmask); virtual t_addr bit_address(class cl_memory *mem, - t_addr mem_address, - int bit_number); + t_addr mem_address, + int bit_number); virtual void reset(void); virtual void clear_sfr(void); virtual void analyze(t_addr addr); @@ -127,117 +127,117 @@ protected: //virtual void post_inst(void); virtual int inst_unknown(void); - virtual int inst_nop(uchar code); /* 00 */ - virtual int inst_ajmp_addr(uchar code); /* [02468ace]1 */ - virtual int inst_ljmp(uchar code); /* 02 */ - virtual int inst_rr(uchar code); /* 03 */ - virtual int inst_inc_a(uchar code); /* 04 */ - virtual int inst_inc_addr(uchar code); /* 05 */ - virtual int inst_inc_Sri(uchar code); /* 06,07 */ - virtual int inst_inc_rn(uchar code); /* 08-0f */ - virtual int inst_jbc_bit_addr(uchar code); /* 10 */ - virtual int inst_acall_addr(uchar code); /* [13579bdf]1 */ + virtual int inst_nop(uchar code); /* 00 */ + virtual int inst_ajmp_addr(uchar code); /* [02468ace]1 */ + virtual int inst_ljmp(uchar code); /* 02 */ + virtual int inst_rr(uchar code); /* 03 */ + virtual int inst_inc_a(uchar code); /* 04 */ + virtual int inst_inc_addr(uchar code); /* 05 */ + virtual int inst_inc_Sri(uchar code); /* 06,07 */ + virtual int inst_inc_rn(uchar code); /* 08-0f */ + virtual int inst_jbc_bit_addr(uchar code); /* 10 */ + virtual int inst_acall_addr(uchar code); /* [13579bdf]1 */ virtual int inst_lcall(uchar code, uint addr, bool intr);/* 12 */ - virtual int inst_rrc(uchar code); /* 13 */ - virtual int inst_dec_a(uchar code); /* 14 */ - virtual int inst_dec_addr(uchar code); /* 15 */ - virtual int inst_dec_Sri(uchar code); /* 16,17 */ - virtual int inst_dec_rn(uchar code); /* 18-1f */ - virtual int inst_jb_bit_addr(uchar code); /* 20 */ - virtual int inst_ret(uchar code); /* 22 */ - virtual int inst_rl(uchar code); /* 23 */ - virtual int inst_add_a_Sdata(uchar code); /* 24 */ - virtual int inst_add_a_addr(uchar code); /* 25 */ - virtual int inst_add_a_Sri(uchar code); /* 26,27 */ - virtual int inst_add_a_rn(uchar code); /* 28-2f */ - virtual int inst_jnb_bit_addr(uchar code); /* 30 */ - virtual int inst_reti(uchar code); /* 32 */ - virtual int inst_rlc(uchar code); /* 33 */ - virtual int inst_addc_a_Sdata(uchar code); /* 34 */ - virtual int inst_addc_a_addr(uchar code); /* 35 */ - virtual int inst_addc_a_Sri(uchar code); /* 36,37 */ - virtual int inst_addc_a_rn(uchar code); /* 38-3f */ - virtual int inst_jc_addr(uchar code); /* 40 */ - virtual int inst_orl_addr_a(uchar code); /* 42 */ - virtual int inst_orl_addr_Sdata(uchar code); /* 43 */ - virtual int inst_orl_a_Sdata(uchar code); /* 44 */ - virtual int inst_orl_a_addr(uchar code); /* 45 */ - virtual int inst_orl_a_Sri(uchar code); /* 46,47 */ - virtual int inst_orl_a_rn(uchar code); /* 48-4f */ - virtual int inst_jnc_addr(uchar code); /* 50 */ - virtual int inst_anl_addr_a(uchar code); /* 52 */ - virtual int inst_anl_addr_Sdata(uchar code); /* 53 */ - virtual int inst_anl_a_Sdata(uchar code); /* 54 */ - virtual int inst_anl_a_addr(uchar code); /* 55 */ - virtual int inst_anl_a_Sri(uchar code); /* 56,57 */ - virtual int inst_anl_a_rn(uchar code); /* 58-5f */ - virtual int inst_jz_addr(uchar code); /* 60 */ - virtual int inst_xrl_addr_a(uchar code); /* 62 */ - virtual int inst_xrl_addr_Sdata(uchar code); /* 63 */ - virtual int inst_xrl_a_Sdata(uchar code); /* 64 */ - virtual int inst_xrl_a_addr(uchar code); /* 65 */ - virtual int inst_xrl_a_Sri(uchar code); /* 66,67 */ - virtual int inst_xrl_a_rn(uchar code); /* 68-6f */ - virtual int inst_jnz_addr(uchar code); /* 70 */ - virtual int inst_orl_c_bit(uchar code); /* 72 */ - virtual int inst_jmp_Sa_dptr(uchar code); /* 73 */ - virtual int inst_mov_a_Sdata(uchar code); /* 74 */ - virtual int inst_mov_addr_Sdata(uchar code); /* 75 */ - virtual int inst_mov_Sri_Sdata(uchar code); /* 76,77 */ - virtual int inst_mov_rn_Sdata(uchar code); /* 78-7f */ - virtual int inst_sjmp(uchar code); /* 80 */ - virtual int inst_anl_c_bit(uchar code); /* 82 */ - virtual int inst_movc_a_Sa_pc(uchar code); /* 83 */ - virtual int inst_div_ab(uchar code); /* 84 */ - virtual int inst_mov_addr_addr(uchar code); /* 85 */ - virtual int inst_mov_addr_Sri(uchar code); /* 86,87 */ - virtual int inst_mov_addr_rn(uchar code); /* 88-8f */ - virtual int inst_mov_dptr_Sdata(uchar code); /* 90 */ - virtual int inst_mov_bit_c(uchar code); /* 92 */ - virtual int inst_movc_a_Sa_dptr(uchar code); /* 93 */ - virtual int inst_subb_a_Sdata(uchar code); /* 94 */ - virtual int inst_subb_a_addr(uchar code); /* 95 */ - virtual int inst_subb_a_Sri(uchar code); /* 96,97 */ - virtual int inst_subb_a_rn(uchar code); /* 98-9f */ - virtual int inst_orl_c_Sbit(uchar code); /* a0 */ - virtual int inst_mov_c_bit(uchar code); /* a2 */ - virtual int inst_inc_dptr(uchar code); /* a3 */ - virtual int inst_mul_ab(uchar code); /* a4 */ - virtual int inst_mov_Sri_addr(uchar code); /* a6,a7 */ - virtual int inst_mov_rn_addr(uchar code); /* a8-af */ - virtual int inst_anl_c_Sbit(uchar code); /* b0 */ - virtual int inst_cpl_bit(uchar code); /* b2 */ - virtual int inst_cpl_c(uchar code); /* b3 */ - virtual int inst_cjne_a_Sdata_addr(uchar code); /* b4 */ - virtual int inst_cjne_a_addr_addr(uchar code); /* b5 */ - virtual int inst_cjne_Sri_Sdata_addr(uchar code); /* b6,b7 */ - virtual int inst_cjne_rn_Sdata_addr(uchar code); /* b8-bf */ - virtual int inst_push(uchar code); /* c0 */ - virtual int inst_clr_bit(uchar code); /* c2 */ - virtual int inst_clr_c(uchar code); /* c3*/ - virtual int inst_swap(uchar code); /* c4 */ - virtual int inst_xch_a_addr(uchar code); /* c5 */ - virtual int inst_xch_a_Sri(uchar code); /* c6,c7 */ - virtual int inst_xch_a_rn(uchar code); /* c8-cf */ - virtual int inst_pop(uchar code); /* d0 */ - virtual int inst_setb_bit(uchar code); /* d2 */ - virtual int inst_setb_c(uchar code); /* d3 */ - virtual int inst_da_a(uchar code); /* d4 */ - virtual int inst_djnz_addr_addr(uchar code); /* d5 */ - virtual int inst_xchd_a_Sri(uchar code); /* d6,d7 */ - virtual int inst_djnz_rn_addr(uchar code); /* d8-df */ - virtual int inst_movx_a_Sdptr(uchar code); /* e0 */ - virtual int inst_movx_a_Sri(uchar code); /* e2,e3 */ - virtual int inst_clr_a(uchar code); /* e4 */ - virtual int inst_mov_a_addr(uchar code); /* e5 */ - virtual int inst_mov_a_Sri(uchar code); /* e6,e7 */ - virtual int inst_mov_a_rn(uchar code); /* e8-ef */ - virtual int inst_movx_Sdptr_a(uchar code); /* f0 */ - virtual int inst_movx_Sri_a(uchar code); /* f2,f3 */ - virtual int inst_cpl_a(uchar code); /* f4 */ - virtual int inst_mov_addr_a(uchar code); /* f5 */ - virtual int inst_mov_Sri_a(uchar code); /* f6,f7 */ - virtual int inst_mov_rn_a(uchar code); /* f8-ff */ + virtual int inst_rrc(uchar code); /* 13 */ + virtual int inst_dec_a(uchar code); /* 14 */ + virtual int inst_dec_addr(uchar code); /* 15 */ + virtual int inst_dec_Sri(uchar code); /* 16,17 */ + virtual int inst_dec_rn(uchar code); /* 18-1f */ + virtual int inst_jb_bit_addr(uchar code); /* 20 */ + virtual int inst_ret(uchar code); /* 22 */ + virtual int inst_rl(uchar code); /* 23 */ + virtual int inst_add_a_Sdata(uchar code); /* 24 */ + virtual int inst_add_a_addr(uchar code); /* 25 */ + virtual int inst_add_a_Sri(uchar code); /* 26,27 */ + virtual int inst_add_a_rn(uchar code); /* 28-2f */ + virtual int inst_jnb_bit_addr(uchar code); /* 30 */ + virtual int inst_reti(uchar code); /* 32 */ + virtual int inst_rlc(uchar code); /* 33 */ + virtual int inst_addc_a_Sdata(uchar code); /* 34 */ + virtual int inst_addc_a_addr(uchar code); /* 35 */ + virtual int inst_addc_a_Sri(uchar code); /* 36,37 */ + virtual int inst_addc_a_rn(uchar code); /* 38-3f */ + virtual int inst_jc_addr(uchar code); /* 40 */ + virtual int inst_orl_addr_a(uchar code); /* 42 */ + virtual int inst_orl_addr_Sdata(uchar code); /* 43 */ + virtual int inst_orl_a_Sdata(uchar code); /* 44 */ + virtual int inst_orl_a_addr(uchar code); /* 45 */ + virtual int inst_orl_a_Sri(uchar code); /* 46,47 */ + virtual int inst_orl_a_rn(uchar code); /* 48-4f */ + virtual int inst_jnc_addr(uchar code); /* 50 */ + virtual int inst_anl_addr_a(uchar code); /* 52 */ + virtual int inst_anl_addr_Sdata(uchar code); /* 53 */ + virtual int inst_anl_a_Sdata(uchar code); /* 54 */ + virtual int inst_anl_a_addr(uchar code); /* 55 */ + virtual int inst_anl_a_Sri(uchar code); /* 56,57 */ + virtual int inst_anl_a_rn(uchar code); /* 58-5f */ + virtual int inst_jz_addr(uchar code); /* 60 */ + virtual int inst_xrl_addr_a(uchar code); /* 62 */ + virtual int inst_xrl_addr_Sdata(uchar code); /* 63 */ + virtual int inst_xrl_a_Sdata(uchar code); /* 64 */ + virtual int inst_xrl_a_addr(uchar code); /* 65 */ + virtual int inst_xrl_a_Sri(uchar code); /* 66,67 */ + virtual int inst_xrl_a_rn(uchar code); /* 68-6f */ + virtual int inst_jnz_addr(uchar code); /* 70 */ + virtual int inst_orl_c_bit(uchar code); /* 72 */ + virtual int inst_jmp_Sa_dptr(uchar code); /* 73 */ + virtual int inst_mov_a_Sdata(uchar code); /* 74 */ + virtual int inst_mov_addr_Sdata(uchar code); /* 75 */ + virtual int inst_mov_Sri_Sdata(uchar code); /* 76,77 */ + virtual int inst_mov_rn_Sdata(uchar code); /* 78-7f */ + virtual int inst_sjmp(uchar code); /* 80 */ + virtual int inst_anl_c_bit(uchar code); /* 82 */ + virtual int inst_movc_a_Sa_pc(uchar code); /* 83 */ + virtual int inst_div_ab(uchar code); /* 84 */ + virtual int inst_mov_addr_addr(uchar code); /* 85 */ + virtual int inst_mov_addr_Sri(uchar code); /* 86,87 */ + virtual int inst_mov_addr_rn(uchar code); /* 88-8f */ + virtual int inst_mov_dptr_Sdata(uchar code); /* 90 */ + virtual int inst_mov_bit_c(uchar code); /* 92 */ + virtual int inst_movc_a_Sa_dptr(uchar code); /* 93 */ + virtual int inst_subb_a_Sdata(uchar code); /* 94 */ + virtual int inst_subb_a_addr(uchar code); /* 95 */ + virtual int inst_subb_a_Sri(uchar code); /* 96,97 */ + virtual int inst_subb_a_rn(uchar code); /* 98-9f */ + virtual int inst_orl_c_Sbit(uchar code); /* a0 */ + virtual int inst_mov_c_bit(uchar code); /* a2 */ + virtual int inst_inc_dptr(uchar code); /* a3 */ + virtual int inst_mul_ab(uchar code); /* a4 */ + virtual int inst_mov_Sri_addr(uchar code); /* a6,a7 */ + virtual int inst_mov_rn_addr(uchar code); /* a8-af */ + virtual int inst_anl_c_Sbit(uchar code); /* b0 */ + virtual int inst_cpl_bit(uchar code); /* b2 */ + virtual int inst_cpl_c(uchar code); /* b3 */ + virtual int inst_cjne_a_Sdata_addr(uchar code); /* b4 */ + virtual int inst_cjne_a_addr_addr(uchar code); /* b5 */ + virtual int inst_cjne_Sri_Sdata_addr(uchar code); /* b6,b7 */ + virtual int inst_cjne_rn_Sdata_addr(uchar code); /* b8-bf */ + virtual int inst_push(uchar code); /* c0 */ + virtual int inst_clr_bit(uchar code); /* c2 */ + virtual int inst_clr_c(uchar code); /* c3*/ + virtual int inst_swap(uchar code); /* c4 */ + virtual int inst_xch_a_addr(uchar code); /* c5 */ + virtual int inst_xch_a_Sri(uchar code); /* c6,c7 */ + virtual int inst_xch_a_rn(uchar code); /* c8-cf */ + virtual int inst_pop(uchar code); /* d0 */ + virtual int inst_setb_bit(uchar code); /* d2 */ + virtual int inst_setb_c(uchar code); /* d3 */ + virtual int inst_da_a(uchar code); /* d4 */ + virtual int inst_djnz_addr_addr(uchar code); /* d5 */ + virtual int inst_xchd_a_Sri(uchar code); /* d6,d7 */ + virtual int inst_djnz_rn_addr(uchar code); /* d8-df */ + virtual int inst_movx_a_Sdptr(uchar code); /* e0 */ + virtual int inst_movx_a_Sri(uchar code); /* e2,e3 */ + virtual int inst_clr_a(uchar code); /* e4 */ + virtual int inst_mov_a_addr(uchar code); /* e5 */ + virtual int inst_mov_a_Sri(uchar code); /* e6,e7 */ + virtual int inst_mov_a_rn(uchar code); /* e8-ef */ + virtual int inst_movx_Sdptr_a(uchar code); /* f0 */ + virtual int inst_movx_Sri_a(uchar code); /* f2,f3 */ + virtual int inst_cpl_a(uchar code); /* f4 */ + virtual int inst_mov_addr_a(uchar code); /* f5 */ + virtual int inst_mov_Sri_a(uchar code); /* f6,f7 */ + virtual int inst_mov_rn_a(uchar code); /* f8-ff */ }; diff --git a/sim/ucsim/s51.src/wdt.cc b/sim/ucsim/s51.src/wdt.cc index d4b10cd6..d62b5271 100644 --- a/sim/ucsim/s51.src/wdt.cc +++ b/sim/ucsim/s51.src/wdt.cc @@ -64,8 +64,8 @@ cl_wdt::write(class cl_memory_cell *cell, t_mem *val) { wdt= 0; /*uc->sim->app->get_commander()-> - debug("%g sec (%d tick): Watchdog timer enabled/reset PC= 0x%06x" - "\n", uc->get_rtime(), uc->ticks->ticks, uc51r->PC);*/ + debug("%g sec (%d tick): Watchdog timer enabled/reset PC= 0x%06x" + "\n", uc->get_rtime(), uc->ticks->ticks, uc51r->PC);*/ } written_since_reset= DD_TRUE; } @@ -77,13 +77,13 @@ cl_wdt::tick(int cycles) { wdt+= cycles; if (wdt > reset_value) - { - /*sim->app->get_commander()-> - debug("%g sec (%d ticks): Watchdog timer resets the CPU, " - "PC= 0x%06x\n", get_rtime(), ticks->ticks, PC);*/ - uc->reset(); - //return(resWDTRESET); - } + { + /*sim->app->get_commander()-> + debug("%g sec (%d ticks): Watchdog timer resets the CPU, " + "PC= 0x%06x\n", get_rtime(), ticks->ticks, PC);*/ + uc->reset(); + //return(resWDTRESET); + } } return(0); } @@ -96,10 +96,10 @@ cl_wdt::reset(void) } void -cl_wdt::print_info(class cl_console *con) +cl_wdt::print_info(class cl_console_base *con) { con->dd_printf("%s[%d] %s counter=%d (remains=%d)\n", id_string, id, - (wdt>=0)?"ON":"OFF", wdt, (wdt>=0)?(reset_value-wdt):0); + (wdt>=0)?"ON":"OFF", wdt, (wdt>=0)?(reset_value-wdt):0); } diff --git a/sim/ucsim/s51.src/wdtcl.h b/sim/ucsim/s51.src/wdtcl.h index be1d57a5..dc8f87a1 100644 --- a/sim/ucsim/s51.src/wdtcl.h +++ b/sim/ucsim/s51.src/wdtcl.h @@ -56,7 +56,7 @@ public: virtual int tick(int cycles); virtual void reset(void); - virtual void print_info(class cl_console *con); + virtual void print_info(class cl_console_base *con); }; diff --git a/sim/ucsim/sim.src/hw.cc b/sim/ucsim/sim.src/hw.cc index 45fa7059..ea4c5f4e 100644 --- a/sim/ucsim/sim.src/hw.cc +++ b/sim/ucsim/sim.src/hw.cc @@ -39,8 +39,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA */ cl_watched_cell::cl_watched_cell(class cl_address_space *amem, t_addr aaddr, - class cl_memory_cell **astore, - enum what_to_do_on_cell_change awtd) + class cl_memory_cell **astore, + enum what_to_do_on_cell_change awtd) { mem= amem; addr= aaddr; @@ -50,13 +50,13 @@ cl_watched_cell::cl_watched_cell(class cl_address_space *amem, t_addr aaddr, { cell= mem->get_cell(addr); if (store) - *store= cell; + *store= cell; } } void cl_watched_cell::mem_cell_changed(class cl_address_space *amem, t_addr aaddr, - class cl_hw *hw) + class cl_hw *hw) { if (mem && mem == amem && @@ -64,19 +64,19 @@ cl_watched_cell::mem_cell_changed(class cl_address_space *amem, t_addr aaddr, { cell= mem->get_cell(addr); if (store && - (wtd & WTD_RESTORE)) - *store= cell; + (wtd & WTD_RESTORE)) + *store= cell; if (wtd & WTD_WRITE) - { - t_mem d= cell->get(); - hw->write(cell, &d); - } + { + t_mem d= cell->get(); + hw->write(cell, &d); + } } } void cl_watched_cell::address_space_added(class cl_address_space *amem, - class cl_hw *hw) + class cl_hw *hw) { } @@ -90,19 +90,19 @@ class cl_hw *hw) { cell= mem->get_cell(addr); if (store && - (wtd & WTD_RESTORE)) - *store= cell; + (wtd & WTD_RESTORE)) + *store= cell; if (wtd & WTD_WRITE) - { - t_mem d= cell->get(); - hw->write(cell, &d); - } + { + t_mem d= cell->get(); + hw->write(cell, &d); + } } } void cl_used_cell::address_space_added(class cl_address_space *amem, - class cl_hw *hw) + class cl_hw *hw) { } @@ -188,15 +188,15 @@ cl_hw::write(class cl_m *mem, t_addr addr, t_mem *val) }*/ void -cl_hw::set_cmd(class cl_cmdline *cmdline, class cl_console *con) +cl_hw::set_cmd(class cl_cmdline *cmdline, class cl_console_base *con) { con->dd_printf("Nothing to do\n"); } class cl_memory_cell * cl_hw::register_cell(class cl_address_space *mem, t_addr addr, - class cl_memory_cell **store, - enum what_to_do_on_cell_change awtd) + class cl_memory_cell **store, + enum what_to_do_on_cell_change awtd) { class cl_watched_cell *wc; class cl_memory_cell *cell; @@ -216,8 +216,8 @@ cl_hw::register_cell(class cl_address_space *mem, t_addr addr, class cl_memory_cell * cl_hw::use_cell(class cl_address_space *mem, t_addr addr, - class cl_memory_cell **store, - enum what_to_do_on_cell_change awtd) + class cl_memory_cell **store, + enum what_to_do_on_cell_change awtd) { class cl_watched_cell *wc; class cl_memory_cell *cell; @@ -237,7 +237,7 @@ cl_hw::mem_cell_changed(class cl_address_space *mem, t_addr addr) for (i= 0; i < watched_cells->count; i++) { class cl_watched_cell *wc= - (class cl_watched_cell *)(watched_cells->at(i)); + (class cl_watched_cell *)(watched_cells->at(i)); wc->mem_cell_changed(mem, addr, this); } } @@ -250,7 +250,7 @@ cl_hw::address_space_added(class cl_address_space *as) for (i= 0; i < watched_cells->count; i++) { class cl_watched_cell *wc= - dynamic_cast(watched_cells->object_at(i)); + dynamic_cast(watched_cells->object_at(i)); wc->address_space_added(as, this); } } @@ -280,7 +280,7 @@ cl_hw::inform_partners(enum hw_event he, void *params) void -cl_hw::print_info(class cl_console *con) +cl_hw::print_info(class cl_console_base *con) { con->dd_printf("%s[%d]\n", id_string, id); } @@ -366,12 +366,12 @@ cl_partner_hw::refresh(void) { // partner is already set if (partner != hw) - { - // partner changed? - partner= hw; - } + { + // partner changed? + partner= hw; + } else - partner= hw; + partner= hw; } partner= hw; } @@ -385,12 +385,12 @@ cl_partner_hw::refresh(class cl_hw *new_hw) id == new_hw->id) { if (partner) - { - // partner changed? - partner= new_hw; - } + { + // partner changed? + partner= new_hw; + } else - partner= new_hw; + partner= new_hw; } } diff --git a/sim/ucsim/sim.src/hwcl.h b/sim/ucsim/sim.src/hwcl.h index 3024011f..d573010b 100644 --- a/sim/ucsim/sim.src/hwcl.h +++ b/sim/ucsim/sim.src/hwcl.h @@ -43,14 +43,14 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA enum what_to_do_on_cell_change { - wtd_none = 0x01, - wtd_write = 0x02, - wtd_restore = 0x04, - wtd_restore_write = 0x08 + wtd_none = 0x01, + wtd_write = 0x02, + wtd_restore = 0x04, + wtd_restore_write = 0x08 }; -#define WTD_WRITE (wtd_write|wtd_restore_write) -#define WTD_RESTORE (wtd_restore|wtd_restore_write) +#define WTD_WRITE (wtd_write|wtd_restore_write) +#define WTD_RESTORE (wtd_restore|wtd_restore_write) class cl_hw; // forward @@ -65,27 +65,27 @@ public: enum what_to_do_on_cell_change wtd; public: cl_watched_cell(class cl_address_space *amem, t_addr aaddr, - class cl_memory_cell **astore, - enum what_to_do_on_cell_change awtd); + class cl_memory_cell **astore, + enum what_to_do_on_cell_change awtd); virtual void mem_cell_changed(class cl_address_space *amem, t_addr aaddr, - class cl_hw *hw); + class cl_hw *hw); virtual void address_space_added(class cl_address_space *amem, - class cl_hw *hw); + class cl_hw *hw); }; class cl_used_cell: public cl_watched_cell { public: cl_used_cell(class cl_address_space *amem, t_addr aaddr, - class cl_memory_cell **astore, - enum what_to_do_on_cell_change awtd): + class cl_memory_cell **astore, + enum what_to_do_on_cell_change awtd): cl_watched_cell(amem, aaddr, astore, awtd) {} virtual void mem_cell_changed(class cl_address_space *amem, t_addr aaddr, - class cl_hw *hw); + class cl_hw *hw); virtual void address_space_added(class cl_address_space *amem, - class cl_hw *hw); + class cl_hw *hw); }; class cl_hw: public cl_guiobj @@ -111,26 +111,26 @@ public: virtual t_mem read(class cl_memory_cell *cell) { return(cell->get()); } virtual void write(class cl_memory_cell */*cell*/, t_mem */*val*/) {} - virtual void set_cmd(class cl_cmdline *cmdline, class cl_console *con); + virtual void set_cmd(class cl_cmdline *cmdline, class cl_console_base *con); virtual class cl_memory_cell *register_cell(class cl_address_space *mem, - t_addr addr, - class cl_memory_cell **store, - enum what_to_do_on_cell_change - awtd); + t_addr addr, + class cl_memory_cell **store, + enum what_to_do_on_cell_change + awtd); virtual class cl_memory_cell *use_cell(class cl_address_space *mem, - t_addr addr, - class cl_memory_cell **store, - enum what_to_do_on_cell_change awtd); + t_addr addr, + class cl_memory_cell **store, + enum what_to_do_on_cell_change awtd); virtual void mem_cell_changed(class cl_address_space *mem, t_addr addr); virtual void address_space_added(class cl_address_space *as); virtual int tick(int cycles); virtual void reset(void) {} virtual void happen(class cl_hw */*where*/, enum hw_event /*he*/, - void */*params*/) {} + void */*params*/) {} virtual void inform_partners(enum hw_event he, void *params); - virtual void print_info(class cl_console *con); + virtual void print_info(class cl_console_base *con); }; class cl_hws: public cl_list diff --git a/sim/ucsim/sim.src/mem.cc b/sim/ucsim/sim.src/mem.cc index adf34b8c..9d27714d 100644 --- a/sim/ucsim/sim.src/mem.cc +++ b/sim/ucsim/sim.src/mem.cc @@ -164,7 +164,7 @@ cl_memory::err_non_decoded(t_addr addr) t_addr -cl_memory::dump(t_addr start, t_addr stop, int bpl, class cl_console *con) +cl_memory::dump(t_addr start, t_addr stop, int bpl, class cl_console_base *con) { int i; t_addr lva= lowest_valid_address(); @@ -219,7 +219,7 @@ cl_memory::dump(t_addr start, t_addr stop, int bpl, class cl_console *con) } t_addr -cl_memory::dump(class cl_console *con) +cl_memory::dump(class cl_console_base *con) { return(dump(dump_finished, dump_finished+10*8-1, 8, con)); } @@ -885,7 +885,7 @@ cl_address_space::undecode_cell(t_addr addr) void cl_address_space::undecode_area(class cl_address_decoder *skip, - t_addr begin, t_addr end,class cl_console *con) + t_addr begin, t_addr end,class cl_console_base *con) { #define D if (con) con->debug D("Undecoding area 0x%x-0x%x of %s\n", begin, end, get_name()); @@ -1166,7 +1166,7 @@ cl_address_decoder::init(void) bool -cl_address_decoder::activate(class cl_console *con) +cl_address_decoder::activate(class cl_console_base *con) { #define D if (con) con->debug D("Activation of an address decoder\n"); @@ -1358,7 +1358,7 @@ cl_error_mem_invalid_address(class cl_memory *amem, t_addr aaddr): } void -cl_error_mem_invalid_address::print(class cl_commander *c) +cl_error_mem_invalid_address::print(class cl_commander_base *c) { c->dd_printf("%s: invalid address ", get_type_name()); c->dd_printf(mem->addr_format, addr); @@ -1375,7 +1375,7 @@ cl_error_mem_non_decoded(class cl_memory *amem, t_addr aaddr): } void -cl_error_mem_non_decoded::print(class cl_commander *c) +cl_error_mem_non_decoded::print(class cl_commander_base *c) { c->dd_printf("%s: access of non-decoded address ", get_type_name()); c->dd_printf(mem->addr_format, addr); diff --git a/sim/ucsim/sim.src/memcl.h b/sim/ucsim/sim.src/memcl.h index 625808db..e647f5ea 100644 --- a/sim/ucsim/sim.src/memcl.h +++ b/sim/ucsim/sim.src/memcl.h @@ -42,23 +42,23 @@ class cl_event_handler; // Cell types -#define CELL_NORMAL 0x00 /* Nothing special */ -#define CELL_HW_READ 0x01 /* Hw handles read */ -#define CELL_HW_WRITE 0x02 /* Hw catches write */ -//#define CELL_INST 0x04 /* Marked as instruction */ -//#define CELL_FETCH_BRK 0x08 /* Fetch breakpoint */ -#define CELL_READ_BRK 0x10 /* Read event breakpoint */ -#define CELL_WRITE_BRK 0x20 /* Write event breakpoint */ +#define CELL_NORMAL 0x00 /* Nothing special */ +#define CELL_HW_READ 0x01 /* Hw handles read */ +#define CELL_HW_WRITE 0x02 /* Hw catches write */ +//#define CELL_INST 0x04 /* Marked as instruction */ +//#define CELL_FETCH_BRK 0x08 /* Fetch breakpoint */ +#define CELL_READ_BRK 0x10 /* Read event breakpoint */ +#define CELL_WRITE_BRK 0x20 /* Write event breakpoint */ // Cell flags enum cell_flag { - CELL_NONE = 0x00, - CELL_INST = 0x04, /* Marked as instruction */ - CELL_FETCH_BRK = 0x08, /* Fetch breakpoint */ - CELL_NON_DECODED = 0x40 /* Cell is not decoded (yet) */ + CELL_NONE = 0x00, + CELL_INST = 0x04, /* Marked as instruction */ + CELL_FETCH_BRK = 0x08, /* Fetch breakpoint */ + CELL_NON_DECODED = 0x40 /* Cell is not decoded (yet) */ }; -#define CELL_GENERAL (CELL_NORMAL|CELL_INST|CELL_FETCH_BRK) +#define CELL_GENERAL (CELL_NORMAL|CELL_INST|CELL_FETCH_BRK) /* @@ -100,10 +100,10 @@ public: virtual void err_non_decoded(t_addr addr); virtual t_addr dump(t_addr start, t_addr stop, int bpl, - class cl_console *con); - virtual t_addr dump(class cl_console *con); + class cl_console_base *con); + virtual t_addr dump(class cl_console_base *con); virtual bool search_next(bool case_sensitive, - t_mem *array, int len, t_addr *addr); + t_mem *array, int len, t_addr *addr); virtual t_addr lowest_valid_address(void) { return(start_address); } @@ -135,7 +135,7 @@ protected: public: cl_memory_operator(class cl_memory_cell *acell, t_addr addr); cl_memory_operator(class cl_memory_cell *acell, t_addr addr, - t_mem *data_place, t_mem the_mask); + t_mem *data_place, t_mem the_mask); virtual void set_data(t_mem *data_place, t_mem the_mask); virtual class cl_memory_operator *get_next(void) { return(next_operator); } @@ -155,7 +155,7 @@ protected: class cl_hw *hw; public: cl_hw_operator(class cl_memory_cell *acell, t_addr addr, - t_mem *data_place, t_mem the_mask, class cl_hw *ahw); + t_mem *data_place, t_mem the_mask, class cl_hw *ahw); virtual bool match(class cl_hw *the_hw) { return(hw == the_hw); } @@ -171,8 +171,8 @@ protected: class cl_brk *bp; public: cl_event_break_operator(class cl_memory_cell *acell, t_addr addr, - t_mem *data_place, t_mem the_mask, - class cl_uc *auc, class cl_brk *the_bp): + t_mem *data_place, t_mem the_mask, + class cl_uc *auc, class cl_brk *the_bp): cl_memory_operator(acell, addr, data_place, the_mask) { uc= auc; @@ -186,8 +186,8 @@ class cl_write_operator: public cl_event_break_operator { public: cl_write_operator(class cl_memory_cell *acell, t_addr addr, - t_mem *data_place, t_mem the_mask, - class cl_uc *auc, class cl_brk *the_bp); + t_mem *data_place, t_mem the_mask, + class cl_uc *auc, class cl_brk *the_bp); virtual t_mem write(t_mem val); }; @@ -196,8 +196,8 @@ class cl_read_operator: public cl_event_break_operator { public: cl_read_operator(class cl_memory_cell *acell, t_addr addr, - t_mem *data_place, t_mem the_mask, - class cl_uc *auc, class cl_brk *the_bp); + t_mem *data_place, t_mem the_mask, + class cl_uc *auc, class cl_brk *the_bp); virtual t_mem read(void); }; @@ -300,14 +300,14 @@ public: virtual void set_cell_flag(t_addr addr, bool set_to, enum cell_flag flag); virtual bool decode_cell(t_addr addr, - class cl_memory_chip *chip, t_addr chipaddr); + class cl_memory_chip *chip, t_addr chipaddr); virtual void undecode_cell(t_addr addr); virtual void undecode_area(class cl_address_decoder *skip, - t_addr begin, t_addr end, class cl_console *con); + t_addr begin, t_addr end, class cl_console_base *con); virtual class cl_memory_cell *register_hw(t_addr addr, class cl_hw *hw, - int *ith, - bool announce); + int *ith, + bool announce); virtual void set_brk(t_addr addr, class cl_brk *brk); virtual void del_brk(t_addr addr, class cl_brk *brk); @@ -372,11 +372,11 @@ public: bool activated; public: cl_address_decoder(class cl_memory *as, class cl_memory *chip, - t_addr asb, t_addr ase, t_addr cb); + t_addr asb, t_addr ase, t_addr cb); virtual ~cl_address_decoder(void); virtual int init(void); - virtual bool activate(class cl_console *con); + virtual bool activate(class cl_console_base *con); virtual bool fully_covered_by(t_addr begin, t_addr end); virtual bool is_in(t_addr begin, t_addr end); @@ -436,7 +436,7 @@ class cl_error_mem_invalid_address: public cl_error_mem public: cl_error_mem_invalid_address(class cl_memory *amem, t_addr aaddr); - virtual void print(class cl_commander *c); + virtual void print(class cl_commander_base *c); }; class cl_error_mem_non_decoded: public cl_error_mem @@ -444,7 +444,7 @@ class cl_error_mem_non_decoded: public cl_error_mem public: cl_error_mem_non_decoded(class cl_memory *amem, t_addr aaddr); - virtual void print(class cl_commander *c); + virtual void print(class cl_commander_base *c); }; class cl_mem_error_registry: public cl_error_registry diff --git a/sim/ucsim/sim.src/obsolete.cc b/sim/ucsim/sim.src/obsolete.cc index 2624a4ce..ef9a2c1c 100644 --- a/sim/ucsim/sim.src/obsolete.cc +++ b/sim/ucsim/sim.src/obsolete.cc @@ -156,7 +156,7 @@ cl_rom::~cl_rom(void) cl_mem::cl_mem(enum mem_class atype, char *aclass_name, - t_addr asize, int awidth, class cl_uc *auc): + t_addr asize, int awidth, class cl_uc *auc): cl_guiobj() { int i; @@ -203,12 +203,12 @@ cl_mem::init(void) addr_format= (char *)malloc(10); sprintf(addr_format, "0x%%0%dx", - size-1<=0xf?1: - (size-1<=0xff?2: - (size-1<=0xfff?3: - (size-1<=0xffff?4: - (size-1<=0xfffff?5: - (size-1<=0xffffff?6:12)))))); + size-1<=0xf?1: + (size-1<=0xff?2: + (size-1<=0xfff?3: + (size-1<=0xffff?4: + (size-1<=0xfffff?5: + (size-1<=0xffffff?6:12)))))); data_format= (char *)malloc(10); sprintf(data_format, "%%0%dx", width/4+((width%4)?1:0)); @@ -282,7 +282,7 @@ cl_mem::write(t_addr addr, t_mem val) else ((TYPE_UDWORD*)mem)[addr]= (*val)&mask;*/ fprintf(stderr, "FIXME cl_mem::write(0x%06"_A_"x, 0x%04"_M_"x)\n", - addr, val); + addr, val); return(0); } @@ -324,47 +324,47 @@ cl_mem::add(t_addr addr, long what) } t_addr -cl_mem::dump(t_addr start, t_addr stop, int bpl, class cl_console *con) +cl_mem::dump(t_addr start, t_addr stop, int bpl, class cl_console_base *con) { int i; while ((start <= stop) && - (start < size)) + (start < size)) { con->dd_printf(addr_format, start); con->dd_printf(" "); for (i= 0; - (i < bpl) && - (start+i < size) && - (start+i <= stop); - i++) - { - con->dd_printf(data_format, /*read*/get(start+i)); con->dd_printf(" "); - } + (i < bpl) && + (start+i < size) && + (start+i <= stop); + i++) + { + con->dd_printf(data_format, /*read*/get(start+i)); con->dd_printf(" "); + } while (i < bpl) - { - int j; - j= width/4 + ((width%4)?1:0) + 1; - while (j) - { - con->dd_printf(" "); - j--; - } - i++; - } + { + int j; + j= width/4 + ((width%4)?1:0) + 1; + while (j) + { + con->dd_printf(" "); + j--; + } + i++; + } for (i= 0; (i < bpl) && - (start+i < size) && - (start+i <= stop); - i++) - { - long c= get(start+i); - con->dd_printf("%c", isprint(255&c)?(255&c):'.'); - if (width > 8) - con->dd_printf("%c", isprint(255&(c>>8))?(255&(c>>8)):'.'); - if (width > 16) - con->dd_printf("%c", isprint(255&(c>>16))?(255&(c>>16)):'.'); - if (width > 24) - con->dd_printf("%c", isprint(255&(c>>24))?(255&(c>>24)):'.'); - } + (start+i < size) && + (start+i <= stop); + i++) + { + long c= get(start+i); + con->dd_printf("%c", isprint(255&c)?(255&c):'.'); + if (width > 8) + con->dd_printf("%c", isprint(255&(c>>8))?(255&(c>>8)):'.'); + if (width > 16) + con->dd_printf("%c", isprint(255&(c>>16))?(255&(c>>16)):'.'); + if (width > 24) + con->dd_printf("%c", isprint(255&(c>>24))?(255&(c>>24)):'.'); + } con->dd_printf("\n"); dump_finished= start+i; start+= bpl; @@ -373,7 +373,7 @@ cl_mem::dump(t_addr start, t_addr stop, int bpl, class cl_console *con) } t_addr -cl_mem::dump(class cl_console *con) +cl_mem::dump(class cl_console_base *con) { return(dump(dump_finished, dump_finished+10*8-1, 8, con)); } @@ -468,7 +468,7 @@ cl_mapped_cell::get_event_handler(void) */ cl_m::cl_m(enum mem_class atype, char *aclass_name, t_addr asize, int awidth, - class cl_uc *auc): + class cl_uc *auc): cl_memory(aclass_name, asize, awidth) //cl_mem(atype, aclass_name, 0, awidth, auc) { @@ -731,26 +731,26 @@ cl_m::search_next(bool case_sensitive, t_mem *array, int len, t_addr *addr) found= DD_FALSE; while (!found && - a+len <= size) + a+len <= size) { bool match= DD_TRUE; for (i= 0; i < len && match; i++) - { - t_mem d1, d2; - d1= get(a+i); - d2= array[i]; - if (!case_sensitive) - { - if (/*d1 < 128*/isalpha(d1)) - d1= toupper(d1); - if (/*d2 < 128*/isalpha(d2)) - d2= toupper(d2); - } - match= d1 == d2; - } + { + t_mem d1, d2; + d1= get(a+i); + d2= array[i]; + if (!case_sensitive) + { + if (/*d1 < 128*/isalpha(d1)) + d1= toupper(d1); + if (/*d2 < 128*/isalpha(d2)) + d2= toupper(d2); + } + match= d1 == d2; + } found= match; if (!found) - a++; + a++; } if (addr) @@ -780,11 +780,11 @@ cl_m::register_hw(t_addr addr, class cl_hw *hw, int *ith, bool announce) nc= new cl_ev_reg_cell(width, uc); nc->set(cell->get()); nc->set_type(nc->get_type() & - ~(CELL_GENERAL|CELL_READ_BRK|CELL_WRITE_BRK)); + ~(CELL_GENERAL|CELL_READ_BRK|CELL_WRITE_BRK)); nc->set_type(nc->get_type() | (cell->get_type() & CELL_GENERAL)); class cl_event_handler *eh= nc->get_event_handler(); if (eh) - nc->set_type(nc->get_type() | eh->copy_from(cell->get_event_handler())); + nc->set_type(nc->get_type() | eh->copy_from(cell->get_event_handler())); nc->add_hw(hw, ith); } else @@ -836,7 +836,7 @@ cl_m::set_brk(t_addr addr, class cl_brk *brk) set_cell_flag(addr, DD_TRUE, CELL_FETCH_BRK); return; break; - default: e= '.'; break; + default: e= '.'; break; } if (cell->get_type() & (CELL_HW_READ | CELL_HW_WRITE)) @@ -849,25 +849,25 @@ cl_m::set_brk(t_addr addr, class cl_brk *brk) int i= 0; class cl_hw *hw; while ((hw= cell->get_hw(i)) != 0) - { - nc->add_hw(hw, 0); - i++; - } + { + nc->add_hw(hw, 0); + i++; + } if (((class cl_registered_cell *)cell)->hardwares) - { - free(((class cl_registered_cell *)cell)->hardwares); - ((class cl_registered_cell *)cell)->hardwares= 0; - } + { + free(((class cl_registered_cell *)cell)->hardwares); + ((class cl_registered_cell *)cell)->hardwares= 0; + } class cl_event_handler *eh; if ((eh= nc->get_event_handler())) - nc->set_type(nc->get_type() | eh->add_bp(brk)); + nc->set_type(nc->get_type() | eh->add_bp(brk)); } else if (cell->get_type() & (CELL_READ_BRK | CELL_WRITE_BRK)) { /* Break is already set on it */ class cl_event_handler *eh; if ((eh= cell->get_event_handler())) - cell->set_type(cell->get_type() | eh->add_bp(brk)); + cell->set_type(cell->get_type() | eh->add_bp(brk)); return; } else @@ -879,7 +879,7 @@ cl_m::set_brk(t_addr addr, class cl_brk *brk) nc->set_type(nc->get_type() | (cell->get_type() & CELL_GENERAL)); class cl_event_handler *eh; if ((eh= nc->get_event_handler())) - nc->set_type(nc->get_type() | eh->add_bp(brk)); + nc->set_type(nc->get_type() | eh->add_bp(brk)); } if (addr >= size) @@ -926,13 +926,13 @@ cl_m::del_brk(t_addr addr, class cl_brk *brk) class cl_event_handler *eh; int t= CELL_NORMAL; if ((eh= cell->get_event_handler())) - t= eh->del_bp(brk); + t= eh->del_bp(brk); if (t & (CELL_READ_BRK|CELL_WRITE_BRK)) - { - cell->set_type(cell->get_type() & ~(CELL_READ_BRK|CELL_WRITE_BRK)); - cell->set_type(cell->get_type() | t); - return; - } + { + cell->set_type(cell->get_type() & ~(CELL_READ_BRK|CELL_WRITE_BRK)); + cell->set_type(cell->get_type() | t); + return; + } nc= new cl_registered_cell(width); nc->set(cell->get()); nc->set_type(cell->get_type() & ~CELL_GENERAL); @@ -940,12 +940,12 @@ cl_m::del_brk(t_addr addr, class cl_brk *brk) int i= 0; class cl_hw *hw; while ((hw= cell->get_hw(i)) != 0) - { - nc->add_hw(hw, 0); - i++; - } + { + nc->add_hw(hw, 0); + i++; + } if (((class cl_registered_cell *)cell)->hardwares) - free(((class cl_registered_cell *)cell)->hardwares); + free(((class cl_registered_cell *)cell)->hardwares); } else if (cell->get_type() & (CELL_READ_BRK | CELL_WRITE_BRK)) { @@ -953,13 +953,13 @@ cl_m::del_brk(t_addr addr, class cl_brk *brk) class cl_event_handler *eh; int t= CELL_NORMAL; if ((eh= cell->get_event_handler())) - t= eh->del_bp(brk); + t= eh->del_bp(brk); if (t & (CELL_READ_BRK|CELL_WRITE_BRK)) - { - cell->set_type(cell->get_type() & ~(CELL_READ_BRK|CELL_WRITE_BRK)); - cell->set_type(cell->get_type() | t); - return; - } + { + cell->set_type(cell->get_type() & ~(CELL_READ_BRK|CELL_WRITE_BRK)); + cell->set_type(cell->get_type() | t); + return; + } nc= new cl_normal_cell(width); nc->set(cell->get()); nc->set_type(cell->get_type() & ~CELL_GENERAL); @@ -1118,8 +1118,8 @@ cl_registered_cell::read(void) if (nuof_hws) for (i= 0; i < nuof_hws; i++) { - d= hardwares[i]->read(this); - ; + d= hardwares[i]->read(this); + ; } #ifdef STATISTIC nuof_reads++; @@ -1136,9 +1136,9 @@ cl_registered_cell::read(enum hw_cath skip) if (nuof_hws) for (i= 0; i < nuof_hws; i++) { - if ((skip & hardwares[i]->cathegory) == 0) - d= hardwares[i]->read(this); - ; + if ((skip & hardwares[i]->cathegory) == 0) + d= hardwares[i]->read(this); + ; } #ifdef STATISTIC nuof_reads++; @@ -1155,8 +1155,8 @@ cl_registered_cell::write(t_mem val) if (nuof_hws) for (i= 0; i < nuof_hws; i++) { - hardwares[i]->write(this, &val); - ; + hardwares[i]->write(this, &val); + ; } #ifdef STATISTIC nuof_writes++; @@ -1176,7 +1176,7 @@ cl_registered_cell::add_hw(class cl_hw *hw, int *ith) hardwares= (class cl_hw **)malloc(sizeof(class cl_hw *)); else hardwares= (class cl_hw **)realloc(hardwares, - sizeof(class c_hw *) * (nuof_hws+1)); + sizeof(class c_hw *) * (nuof_hws+1)); hardwares[nuof_hws]= hw; nuof_hws++; if (ith) diff --git a/sim/ucsim/sim.src/obsolete.h b/sim/ucsim/sim.src/obsolete.h index 0acc1d11..fd12bdaa 100644 --- a/sim/ucsim/sim.src/obsolete.h +++ b/sim/ucsim/sim.src/obsolete.h @@ -18,21 +18,21 @@ public: public: cl_mem(enum mem_class atype, char *aclass_name, t_addr asize, int awidth, - class cl_uc *auc); + class cl_uc *auc); virtual ~cl_mem(void); virtual int init(void); virtual char *id_string(void); virtual int get_cell_flag(t_addr //addr - ) { return(CELL_NORMAL); } + ) { return(CELL_NORMAL); } virtual bool get_cell_flag(t_addr //addr - , int //flag - ) + , int //flag + ) { return(DD_FALSE); } virtual void set_cell_flag(t_addr addr, bool set_to, int flag) {} virtual t_mem read(t_addr addr); virtual t_mem read(t_addr addr, enum hw_cath //skip - ) {return(read(addr));} + ) {return(read(addr));} virtual t_mem get(t_addr addr); virtual t_mem write(t_addr addr, t_mem val); virtual void set(t_addr addr, t_mem val); @@ -43,18 +43,18 @@ public: virtual t_mem add(t_addr addr, long what); virtual t_mem wadd(t_addr addr, long what) { return(add(addr, what)); } virtual t_addr dump(t_addr start, t_addr stop, int bpl, - class cl_console *con); - virtual t_addr dump(class cl_console *con); + class cl_console_base *con); + virtual t_addr dump(class cl_console_base *con); virtual bool search_next(bool case_sensitive, - t_mem *array, int len, t_addr *addr); + t_mem *array, int len, t_addr *addr); virtual class cl_cell *get_cell(t_addr addr) {return(0);} virtual class cl_cell *register_hw(t_addr addr, class cl_hw *hw, int *ith, - bool announce) + bool announce) { return(0); } virtual void set_brk(t_addr //addr - , class cl_brk *//brk - ) {} + , class cl_brk *//brk + ) {} virtual void del_brk(t_addr addr, class cl_brk *brk) {} #ifdef STATISTIC virtual unsigned long get_nuof_reads(void) {return(0);} @@ -129,10 +129,10 @@ public: virtual t_mem wadd(t_addr addr, long what); virtual bool search_next(bool case_sensitive, - t_mem *array, int len, t_addr *addr); + t_mem *array, int len, t_addr *addr); virtual class cl_cell *register_hw(t_addr addr, class cl_hw *hw, int *ith, - bool announce); + bool announce); virtual void set_brk(t_addr addr, class cl_brk *brk); virtual void del_brk(t_addr addr, class cl_brk *brk); @@ -149,7 +149,7 @@ class cl_normal_cell: public cl_cell { public: t_mem data; - TYPE_UBYTE type; // See CELL_XXXX + TYPE_UBYTE type; // See CELL_XXXX //protected: public: diff --git a/sim/ucsim/sim.src/sim.cc b/sim/ucsim/sim.src/sim.cc index ed6fb467..248ca311 100644 --- a/sim/ucsim/sim.src/sim.cc +++ b/sim/ucsim/sim.src/sim.cc @@ -2,7 +2,7 @@ * Simulator of microcontrollers (sim.cc) * * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. - * + * * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * */ @@ -56,6 +56,10 @@ cl_sim::cl_sim(class cl_app *the_app): //arguments= new cl_list(2, 2); //accept_args= more_args?strdup(more_args):0; gui= new cl_gui(this); + + state = SIM_QUIT; + argc = 0; + argv = 0; } int @@ -92,21 +96,21 @@ cl_sim::main(void) int done= 0; while (!done && - (state & SIM_QUIT) == 0) + (state & SIM_QUIT) == 0) { if (state & SIM_GO) - { - uc->do_inst(-1); - if (app->get_commander()->input_avail()) - { - done= app->get_commander()->proc_input(); - } - } + { + uc->do_inst(-1); + if (app->get_commander()->input_avail()) + { + done= app->get_commander()->proc_input(); + } + } else - { - app->get_commander()->wait_input(); - done= app->get_commander()->proc_input(); - } + { + app->get_commander()->wait_input(); + done= app->get_commander()->proc_input(); + } } return(0); } @@ -120,7 +124,7 @@ cl_sim::step(void) } /*int -cl_sim::do_cmd(char *cmdstr, class cl_console *console) +cl_sim::do_cmd(char *cmdstr, class cl_console_base *console) { class cl_cmdline *cmdline; class cl_cmd *cm; @@ -138,7 +142,7 @@ cl_sim::do_cmd(char *cmdstr, class cl_console *console) }*/ void -cl_sim::start(class cl_console *con) +cl_sim::start(class cl_console_base *con) { state|= SIM_GO; con->flags|= CONS_FROZEN; @@ -149,54 +153,54 @@ cl_sim::start(class cl_console *con) void cl_sim::stop(int reason) { - class cl_commander *cmd= app->get_commander(); + class cl_commander_base *cmd= app->get_commander(); state&= ~SIM_GO; if (cmd->frozen_console) { if (reason == resUSER && - cmd->frozen_console->input_avail()) - cmd->frozen_console->read_line(); + cmd->frozen_console->input_avail()) + cmd->frozen_console->read_line(); cmd->frozen_console->dd_printf("Stop at 0x%06x: (%d) ", uc->PC, reason); switch (reason) - { - case resHALT: - cmd->frozen_console->dd_printf("Halted\n"); - break; - case resINV_ADDR: - cmd->frozen_console->dd_printf("Invalid address\n"); - break; - case resSTACK_OV: - cmd->frozen_console->dd_printf("Stack overflow\n"); - break; - case resBREAKPOINT: - cmd->frozen_console->dd_printf("Breakpoint\n"); - uc->print_regs(cmd->frozen_console); - break; - case resINTERRUPT: - cmd->frozen_console->dd_printf("Interrupt\n"); - break; - case resWDTRESET: - cmd->frozen_console->dd_printf("Watchdog reset\n"); - break; - case resUSER: - cmd->frozen_console->dd_printf("User stopped\n"); - break; - case resINV_INST: - { - cmd->frozen_console->dd_printf("Invalid instruction"); - if (uc->rom) - cmd->frozen_console->dd_printf(" 0x%04x\n", - uc->rom->get(uc->PC)); - } + { + case resHALT: + cmd->frozen_console->dd_printf("Halted\n"); + break; + case resINV_ADDR: + cmd->frozen_console->dd_printf("Invalid address\n"); + break; + case resSTACK_OV: + cmd->frozen_console->dd_printf("Stack overflow\n"); + break; + case resBREAKPOINT: + cmd->frozen_console->dd_printf("Breakpoint\n"); + uc->print_regs(cmd->frozen_console); + break; + case resINTERRUPT: + cmd->frozen_console->dd_printf("Interrupt\n"); + break; + case resWDTRESET: + cmd->frozen_console->dd_printf("Watchdog reset\n"); + break; + case resUSER: + cmd->frozen_console->dd_printf("User stopped\n"); + break; + case resINV_INST: + { + cmd->frozen_console->dd_printf("Invalid instruction"); + if (uc->rom) + cmd->frozen_console->dd_printf(" 0x%04x\n", + uc->rom->get(uc->PC)); + } break; - case resERROR: - // uc::check_error prints error messages... - break; - default: - cmd->frozen_console->dd_printf("Unknown reason\n"); - break; - } + case resERROR: + // uc::check_error prints error messages... + break; + default: + cmd->frozen_console->dd_printf("Unknown reason\n"); + break; + } cmd->frozen_console->dd_printf("F 0x%06x\n", uc->PC); // for sdcdb //if (cmd->actual_console != cmd->frozen_console) cmd->frozen_console->flags&= ~CONS_FROZEN; @@ -209,22 +213,22 @@ cl_sim::stop(int reason) void cl_sim::stop(class cl_ev_brk *brk) { - class cl_commander *cmd= app->get_commander(); + class cl_commander_base *cmd= app->get_commander(); state&= ~SIM_GO; if (cmd->frozen_console) { - class cl_console *con= cmd->frozen_console; + class cl_console_base *con= cmd->frozen_console; /* if (reason == resUSER && - cmd->frozen_console->input_avail()) - cmd->frozen_console->read_line(); + cmd->frozen_console->input_avail()) + cmd->frozen_console->read_line(); */ //con->dd_printf("Stop at 0x%06x\n", uc->PC); con->dd_printf("Event `%s' at %s[0x%"_A_"x]: 0x%"_A_"x %s\n", - brk->id, brk->get_mem()->get_name(), brk->addr, - uc->instPC, - uc->disass(uc->instPC, " ")); + brk->id, brk->get_mem()->get_name(), brk->addr, + uc->instPC, + uc->disass(uc->instPC, " ")); //con->flags&= ~CONS_FROZEN; //con->print_prompt(); //cmd->frozen_console= 0; @@ -268,11 +272,11 @@ cl_sim::build_cmdset(class cl_cmdset *cmdset) { cset= new cl_cmdset(); cset->init(); - cset->add(cmd= new cl_gui_start_cmd("start", 0, + cset->add(cmd= new cl_gui_start_cmd("start", 0, "gui start Start interfacing with GUI tool", "long help of gui start")); cmd->init(); - cset->add(cmd= new cl_gui_stop_cmd("stop", 0, + cset->add(cmd= new cl_gui_stop_cmd("stop", 0, "gui stop Stop interfacing with GUI tool", "long help of gui stop")); cmd->init(); diff --git a/sim/ucsim/sim.src/simcl.h b/sim/ucsim/sim.src/simcl.h index 990b5cbf..7dc2b796 100644 --- a/sim/ucsim/sim.src/simcl.h +++ b/sim/ucsim/sim.src/simcl.h @@ -51,7 +51,7 @@ public: int state; // See SIM_XXXX int argc; char **argv; - //class cl_commander *cmd; + //class cl_commander_base *cmd; class cl_uc *uc; class cl_gui *gui; @@ -72,7 +72,7 @@ public: //virtual void mem_cell_changed(class cl_address_space *m, t_addr addr); virtual int main(void); - virtual void start(class cl_console *con); + virtual void start(class cl_console_base *con); virtual void stop(int reason); virtual void stop(class cl_ev_brk *brk); virtual int step(void); diff --git a/sim/ucsim/sim.src/stack.cc b/sim/ucsim/sim.src/stack.cc index 39a8b16f..e40fb4a4 100644 --- a/sim/ucsim/sim.src/stack.cc +++ b/sim/ucsim/sim.src/stack.cc @@ -37,8 +37,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA static class cl_stack_error_registry stack_error_registry; cl_stack_op::cl_stack_op(enum stack_op op, - t_addr iPC, - t_addr iSP_before, t_addr iSP_after): + t_addr iPC, + t_addr iSP_before, t_addr iSP_after): cl_base() { operation= op; @@ -62,13 +62,13 @@ cl_stack_op::mk_copy(void) } void -cl_stack_op::info_head(class cl_console *con) +cl_stack_op::info_head(class cl_console_base *con) { con->dd_printf("OP SP before-after L DATA/ADDR INSTRUCTION\n"); } void -cl_stack_op::info(class cl_console *con, class cl_uc *uc) +cl_stack_op::info(class cl_console_base *con, class cl_uc *uc) { con->dd_printf("%-4s 0x%06"_A_"x-0x%06"_A_"x %d ", get_op_name(), SP_before, SP_after, abs(SP_before-SP_after)); @@ -85,7 +85,7 @@ cl_stack_op::get_op_name(void) } void -cl_stack_op::print_info(class cl_console *con) +cl_stack_op::print_info(class cl_console_base *con) { con->dd_printf("-"); } @@ -164,7 +164,7 @@ cl_stack_call::get_op_name(void) } void -cl_stack_call::print_info(class cl_console *con) +cl_stack_call::print_info(class cl_console_base *con) { con->dd_printf("0x%06"_A_"x", called_addr); } @@ -215,7 +215,7 @@ cl_stack_intr::get_op_name(void) } void -cl_stack_intr::print_info(class cl_console *con) +cl_stack_intr::print_info(class cl_console_base *con) { con->dd_printf("0x%06"_A_"x", called_addr); } @@ -276,7 +276,7 @@ cl_stack_push::get_matching_op(void) } void -cl_stack_push::print_info(class cl_console *con) +cl_stack_push::print_info(class cl_console_base *con) { t_addr d= data; con->dd_printf("0x%06"_A_"x", d); @@ -444,10 +444,10 @@ cl_error_stack_tracker_wrong_handle::cl_error_stack_tracker_wrong_handle(bool wr } void -cl_error_stack_tracker_wrong_handle::print(class cl_commander *c) +cl_error_stack_tracker_wrong_handle::print(class cl_commander_base *c) { c->dd_printf("%s: wrong stack tracker handle called for %s operation\n", - get_type_name(), write_operation?"write":"read"); + get_type_name(), write_operation?"write":"read"); } /* Stack Tracker: operation on empty stack */ @@ -466,12 +466,12 @@ cl_error_stack_tracker_empty::~cl_error_stack_tracker_empty(void) } void -cl_error_stack_tracker_empty::print(class cl_commander *c) +cl_error_stack_tracker_empty::print(class cl_commander_base *c) { c->dd_printf("%s(0x%06"_A_"x: %s on empty stack, PC=" - "0x06"_A_"x, SP=0x%06"_A_"x->0x%06"_A_"x\n", - get_type_name(), operation->get_pc(), operation->get_op_name(), - operation->get_before(), operation->get_after()); + "0x06"_A_"x, SP=0x%06"_A_"x->0x%06"_A_"x\n", + get_type_name(), operation->get_pc(), operation->get_op_name(), + operation->get_before(), operation->get_after()); } /* Stack Tracker: operation on empty stack */ @@ -492,13 +492,13 @@ cl_error_stack_tracker_unmatch::~cl_error_stack_tracker_unmatch(void) } void -cl_error_stack_tracker_unmatch::print(class cl_commander *c) +cl_error_stack_tracker_unmatch::print(class cl_commander_base *c) { c->dd_printf("%s(0x%06"_A_"x): %s when %s expected, " - "SP=0x%06"_A_"x->0x%06"_A_"x\n", - get_type_name(), operation->get_pc(), - operation->get_op_name(), top->get_matching_name(), - operation->get_before(), operation->get_after()); + "SP=0x%06"_A_"x->0x%06"_A_"x\n", + get_type_name(), operation->get_pc(), + operation->get_op_name(), top->get_matching_name(), + operation->get_before(), operation->get_after()); } /* Stack Tracker: stack is inconsistent */ @@ -518,11 +518,11 @@ cl_error_stack_tracker_inconsistent::~cl_error_stack_tracker_inconsistent(void) } void -cl_error_stack_tracker_inconsistent::print(class cl_commander *c) +cl_error_stack_tracker_inconsistent::print(class cl_commander_base *c) { c->dd_printf("%s(0x%06"_A_"x): %d byte(s) unread from the stack\n", - get_type_name(), operation->get_pc(), - unread_data_size); + get_type_name(), operation->get_pc(), + unread_data_size); } cl_stack_error_registry::cl_stack_error_registry(void) diff --git a/sim/ucsim/sim.src/stackcl.h b/sim/ucsim/sim.src/stackcl.h index 15c97dc2..9b25d61e 100644 --- a/sim/ucsim/sim.src/stackcl.h +++ b/sim/ucsim/sim.src/stackcl.h @@ -49,18 +49,18 @@ class cl_stack_op: public cl_base { protected: enum stack_op operation; - t_addr PC; // of instruction + t_addr PC; // of instruction t_addr SP_before; t_addr SP_after; public: cl_stack_op(enum stack_op op, - t_addr iPC, t_addr iSP_before, t_addr iSP_after); + t_addr iPC, t_addr iSP_before, t_addr iSP_after); virtual ~cl_stack_op(void); virtual class cl_stack_op *mk_copy(void); - static void info_head(class cl_console *con); - virtual void info(class cl_console *con, class cl_uc *uc); + static void info_head(class cl_console_base *con); + virtual void info(class cl_console_base *con, class cl_uc *uc); protected: - virtual void print_info(class cl_console *con); + virtual void print_info(class cl_console_base *con); public: virtual char *get_op_name(void); virtual char *get_matching_name(void) { return("unknown"); } @@ -83,11 +83,11 @@ protected: t_addr pushed_addr; public: cl_stack_call(t_addr iPC, t_addr called, t_addr pushed, - t_addr iSP_before, t_addr iSP_after); + t_addr iSP_before, t_addr iSP_after); virtual class cl_stack_op *mk_copy(void); protected: virtual char *get_op_name(void); - virtual void print_info(class cl_console *con); + virtual void print_info(class cl_console_base *con); public: virtual char *get_matching_name(void); virtual enum stack_op get_matching_op(void); @@ -99,11 +99,11 @@ class cl_stack_intr: public cl_stack_call { public: cl_stack_intr(t_addr iPC, t_addr called, t_addr pushed, - t_addr iSP_before, t_addr iSP_after); + t_addr iSP_before, t_addr iSP_after); virtual class cl_stack_op *mk_copy(void); protected: virtual char *get_op_name(void); - virtual void print_info(class cl_console *con); + virtual void print_info(class cl_console_base *con); public: virtual char *get_matching_name(void); virtual enum stack_op get_matching_op(void); @@ -120,7 +120,7 @@ public: virtual class cl_stack_op *mk_copy(void); protected: virtual char *get_op_name(void); - virtual void print_info(class cl_console *con); + virtual void print_info(class cl_console_base *con); public: virtual char *get_matching_name(void); virtual enum stack_op get_matching_op(void); @@ -197,7 +197,7 @@ public: public: cl_error_stack_tracker_wrong_handle(bool write_op); - virtual void print(class cl_commander *c); + virtual void print(class cl_commander_base *c); }; class cl_error_stack_tracker_empty: public cl_error_stack_tracker @@ -208,7 +208,7 @@ public: cl_error_stack_tracker_empty(class cl_stack_op *op); virtual ~cl_error_stack_tracker_empty(void); - virtual void print(class cl_commander *c); + virtual void print(class cl_commander_base *c); }; class cl_error_stack_tracker_unmatch: public cl_error_stack_tracker @@ -220,7 +220,7 @@ public: class cl_stack_op *op); virtual ~cl_error_stack_tracker_unmatch(void); - virtual void print(class cl_commander *c); + virtual void print(class cl_commander_base *c); }; class cl_error_stack_tracker_inconsistent: public cl_error_stack_tracker @@ -230,10 +230,10 @@ protected: int unread_data_size; public: cl_error_stack_tracker_inconsistent(class cl_stack_op *op, - int the_unread_data_size); + int the_unread_data_size); virtual ~cl_error_stack_tracker_inconsistent(void); - virtual void print(class cl_commander *c); + virtual void print(class cl_commander_base *c); }; class cl_stack_error_registry: public cl_error_registry diff --git a/sim/ucsim/sim.src/test_mem_speed.cc b/sim/ucsim/sim.src/test_mem_speed.cc index 920f13cf..8290b931 100644 --- a/sim/ucsim/sim.src/test_mem_speed.cc +++ b/sim/ucsim/sim.src/test_mem_speed.cc @@ -48,15 +48,15 @@ do_rw_test(class cl_mem *mem, int time) while (go) for (a= 0; go && a < mem->size; a++) { - t_mem d2; - for (d2= 0; go && d2 <= 255; d2++) - { - d2= mem->write(a, d2); - d= mem->read(a); - if (d != d2) - printf("%"_M_"d written to mem and %"_M_"d read back!\n", d2, d); - counter+= 1; - } + t_mem d2; + for (d2= 0; go && d2 <= 255; d2++) + { + d2= mem->write(a, d2); + d= mem->read(a); + if (d != d2) + printf("%"_M_"d written to mem and %"_M_"d read back!\n", d2, d); + counter+= 1; + } } return(counter); } @@ -67,21 +67,21 @@ main(void) int i; class cl_mem *mem; class cl_m *m2; - class cl_console *con; + class cl_console_base *con; signal(SIGALRM, alarmed); - con= new cl_console(stdin, stdout, 0); + con= new cl_console_base(stdin, stdout, 0); mem= new cl_mem(MEM_SFR, "egy", 0x10000, 8, 0); mem->init(); printf("%g operations on classic memory within 5 sec\n", - do_rw_test(mem, 5)); + do_rw_test(mem, 5)); //mem->dump(con); m2= new cl_m(MEM_TYPES, "test", 0x10000, 8, 0); m2->init(); printf("%g operations on new memory within 5 sec\n", - do_rw_test(m2, 5)); + do_rw_test(m2, 5)); class cl_hw_test *hw= new cl_hw_test(); for (i= 0; i < 0x10000; i++) @@ -89,10 +89,10 @@ main(void) class cl_cell *c= m2->get_cell(i); int dummy; if (c) - c->add_hw(hw, &dummy); + c->add_hw(hw, &dummy); } printf("%g operations on new memory within 5 sec with hw read\n", - do_rw_test(m2, 5)); + do_rw_test(m2, 5)); //m2->dump(con); return(0); diff --git a/sim/ucsim/sim.src/uc.cc b/sim/ucsim/sim.src/uc.cc index 9eff9810..4d57c0c7 100644 --- a/sim/ucsim/sim.src/uc.cc +++ b/sim/ucsim/sim.src/uc.cc @@ -92,7 +92,7 @@ cl_ticker::get_rtime(double xtal) } void -cl_ticker::dump(int nr, double xtal, class cl_console *con) +cl_ticker::dump(int nr, double xtal, class cl_console_base *con) { con->dd_printf("timer #%d(\"%s\") %s%s: %g sec (%lu clks)\n", nr, get_name("unnamed"), @@ -1039,7 +1039,7 @@ cl_uc::disass(t_addr addr, char *sep) } void -cl_uc::print_disass(t_addr addr, class cl_console *con) +cl_uc::print_disass(t_addr addr, class cl_console_base *con) { char *dis; class cl_brk *b; @@ -1077,7 +1077,7 @@ cl_uc::print_disass(t_addr addr, class cl_console *con) } void -cl_uc::print_regs(class cl_console *con) +cl_uc::print_regs(class cl_console_base *con) { con->dd_printf("No registers\n"); } @@ -1292,7 +1292,7 @@ void cl_uc::check_errors(void) { int i; - class cl_commander *c= sim->app->get_commander(); + class cl_commander_base *c= sim->app->get_commander(); bool must_stop= DD_FALSE; if (c) @@ -1306,7 +1306,7 @@ cl_uc::check_errors(void) must_stop= must_stop || (error->get_type() & err_stop); if (error->inst) { - class cl_console *con; + class cl_console_base *con; con= c->actual_console; if (!con) con= c->frozen_console; @@ -1863,7 +1863,7 @@ cl_error_unknown_code::cl_error_unknown_code(class cl_uc *the_uc) } void -cl_error_unknown_code::print(class cl_commander *c) +cl_error_unknown_code::print(class cl_commander_base *c) { c->dd_printf("%s: unknown instruction code at ", get_type_name()); if (uc->rom) diff --git a/sim/ucsim/sim.src/uccl.h b/sim/ucsim/sim.src/uccl.h index d26af207..332092cb 100644 --- a/sim/ucsim/sim.src/uccl.h +++ b/sim/ucsim/sim.src/uccl.h @@ -41,9 +41,9 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA /* Counter to count clock ticks */ -#define TICK_RUN 0x01 -#define TICK_INISR 0x02 -#define TICK_IDLE 0x03 +#define TICK_RUN 0x01 +#define TICK_INISR 0x02 +#define TICK_IDLE 0x03 class cl_ticker: public cl_base { @@ -58,7 +58,7 @@ public: virtual int tick(int nr); virtual double get_rtime(double xtal); - virtual void dump(int nr, double xtal, class cl_console *con); + virtual void dump(int nr, double xtal, class cl_console_base *con); }; @@ -77,40 +77,40 @@ public: class cl_uc: public cl_base { public: - int type; // CPU family - int technology; // CMOS, HMOS - int state; // GO, IDLE, PD + int type; // CPU family + int technology; // CMOS, HMOS + int state; // GO, IDLE, PD //class cl_list *options; class cl_xtal_option *xtal_option; - t_addr PC, instPC; // Program Counter - bool inst_exec; // Instruction is executed - class cl_ticker *ticks; // Nr of XTAL clocks - class cl_ticker *isr_ticks; // Time in ISRs - class cl_ticker *idle_ticks; // Time in idle mode - class cl_list *counters; // User definable timers (tickers) - int inst_ticks; // ticks of an instruction - double xtal; // Clock speed - - int brk_counter; // Number of breakpoints - class brk_coll *fbrk; // Collection of FETCH break-points - class brk_coll *ebrk; // Collection of EVENT breakpoints + t_addr PC, instPC; // Program Counter + bool inst_exec; // Instruction is executed + class cl_ticker *ticks; // Nr of XTAL clocks + class cl_ticker *isr_ticks; // Time in ISRs + class cl_ticker *idle_ticks; // Time in idle mode + class cl_list *counters; // User definable timers (tickers) + int inst_ticks; // ticks of an instruction + double xtal; // Clock speed + + int brk_counter; // Number of breakpoints + class brk_coll *fbrk; // Collection of FETCH break-points + class brk_coll *ebrk; // Collection of EVENT breakpoints class cl_sim *sim; //class cl_list *mems; class cl_hws *hws; - class cl_list *memchips; // v3 + class cl_list *memchips; // v3 class cl_address_space_list *address_spaces; - class cl_address_space *rom; // Required for almost every uc + class cl_address_space *rom; // Required for almost every uc //class cl_list *address_decoders; - class cl_irqs *it_sources; // Sources of interrupts - class cl_list *it_levels; // Follow interrupt services - class cl_list *stack_ops; // Track stack operations + class cl_irqs *it_sources; // Sources of interrupts + class cl_list *it_levels; // Follow interrupt services + class cl_list *stack_ops; // Track stack operations - class cl_list *errors; // Errors of instruction execution - class cl_list *events; // Events happened during inst exec + class cl_list *errors; // Errors of instruction execution + class cl_list *events; // Events happened during inst exec t_addr sp_max; t_addr sp_avg; @@ -192,8 +192,8 @@ public: virtual void remove_all_breaks(void); virtual int make_new_brknr(void); virtual class cl_ev_brk *mk_ebrk(enum brk_perm perm, - class cl_address_space *mem, - char op, t_addr addr, int hit); + class cl_address_space *mem, + char op, t_addr addr, int hit); virtual void check_events(void); // disassembling and symbol recognition @@ -201,26 +201,26 @@ public: virtual struct dis_entry *dis_tbl(void); virtual struct name_entry *sfr_tbl(void); virtual struct name_entry *bit_tbl(void); - virtual void print_disass(t_addr addr, class cl_console *con); - virtual void print_regs(class cl_console *con); + virtual void print_disass(t_addr addr, class cl_console_base *con); + virtual void print_regs(class cl_console_base *con); virtual int inst_length(t_addr addr); virtual int inst_branch(t_addr addr); virtual int longest_inst(void); virtual bool get_name(t_addr addr, struct name_entry tab[], char *buf); virtual bool symbol2address(char *sym, struct name_entry tab[], - t_addr *addr); + t_addr *addr); virtual char *symbolic_bit_name(t_addr bit_address, - class cl_memory *mem, - t_addr mem_addr, - t_mem bit_mask); + class cl_memory *mem, + t_addr mem_addr, + t_mem bit_mask); /* Converting abstract address spaces into real ones */ virtual class cl_address_space *bit2mem(t_addr bitaddr, - t_addr *memaddr, - t_mem *bitmask); + t_addr *memaddr, + t_mem *bitmask); virtual t_addr bit_address(class cl_memory *mem, - t_addr mem_address, - int bit_number) { return(-1); } + t_addr mem_address, + int bit_number) { return(-1); } // messages from app to handle and broadcast virtual bool handle_event(class cl_event &event); @@ -252,7 +252,7 @@ protected: public: cl_error_unknown_code(class cl_uc *the_uc); - virtual void print(class cl_commander *c); + virtual void print(class cl_commander_base *c); }; class cl_uc_error_registry: public cl_error_registry diff --git a/sim/ucsim/utils.cc b/sim/ucsim/utils.cc index b7a625d3..a46aebc4 100644 --- a/sim/ucsim/utils.cc +++ b/sim/ucsim/utils.cc @@ -2,7 +2,7 @@ * Simulator of microcontrollers (utils.cc) * * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. - * + * * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * */ @@ -58,7 +58,7 @@ get_sub_opt(char **option, const char * const *tokens, char **valuep) *valuep= 0; i= 0; while (tokens[i] && - strcmp(*option, tokens[i])) + strcmp(*option, tokens[i])) i++; if (!tokens[i]) *valuep= *option; @@ -72,8 +72,7 @@ get_id_string(struct id_element *ids, int id) { int i= 0; - while (ids[i].id_string && - id != ids[i].id) + while (ids[i].id_string && id != ids[i].id) i++; return(ids[i].id_string); } @@ -91,8 +90,7 @@ get_string_id(struct id_element *ids, char *str) { int i= 0; - while (ids[i].id_string && - strcmp(ids[i].id_string, str) != 0) + while (ids[i].id_string && strcmp(ids[i].id_string, str) != 0) i++; return(ids[i].id); } @@ -102,8 +100,7 @@ get_string_id(struct id_element *ids, char *str, int def) { int i= 0; - while (ids[i].id_string && - strcmp(ids[i].id_string, str) != 0) + while (ids[i].id_string && strcmp(ids[i].id_string, str) != 0) i++; return(ids[i].id_string?ids[i].id:def); } @@ -112,59 +109,29 @@ get_string_id(struct id_element *ids, char *str, int def) extern "C" int vasprintf(char **strp, const char *format, va_list ap); extern "C" int vsnprintf(char *str, size_t size,const char *format,va_list ap); -static char * -vformat_string(char *format, va_list ap) +char * +format_string(char *format, ...) { + va_list ap; + + va_start(ap, format); #ifdef HAVE_VASPRINTF char *msg= NULL; vasprintf(&msg, format, ap); return(msg); -#else -# ifdef HAVE_VSNPRINTF +#elif defined HAVE_VSNPRINTF char *msg= (char*)malloc(80*25); vsnprintf(msg, 80*25, format, ap); return(msg); -# else -# ifdef HAVE_VPRINTF +#elif defined HAVE__VSNPRINTF char *msg= (char*)malloc(80*25); - vsprintf(msg, format, ap); /* Dangerous */ + _vsnprintf(msg, 80*25, format, ap); return(msg); -# endif -# endif +#else +#error No vasprintf or vsnprintf #endif -} - -char * -format_string(char *format, ...) -{ - va_list ap; - - va_start(ap, format); - char *s= vformat_string(format, ap); va_end(ap); - return(s); -} - - -void -print_char_octal(char c, FILE *f) -{ - if (strchr("\a\b\f\n\r\t\v\"", c)) - switch (c) - { - case '\a': fprintf(f, "\a"); break; - case '\b': fprintf(f, "\b"); break; - case '\f': fprintf(f, "\f"); break; - case '\n': fprintf(f, "\n"); break; - case '\r': fprintf(f, "\r"); break; - case '\t': fprintf(f, "\t"); break; - case '\v': fprintf(f, "\v"); break; - case '\"': fprintf(f, "\""); break; - } - else if (isprint(c)) - fprintf(f, "%c", c); - else - fprintf(f, "\\%03hho", c); + return(msg); } @@ -175,8 +142,7 @@ object_name(class cl_base *o) if (o) name= o->get_name(); - if (name && - *name) + if (name && *name) return(name); return("(unkown)"); } @@ -191,23 +157,26 @@ case_string(enum letter_case lcase, char *str) switch (lcase) { case case_upper: - while (p && *p) { - *p= toupper(*p); - p++; - } + while (p && *p) + { + *p= toupper(*p); + p++; + } break; case case_lower: - while (p && *p) { - *p= tolower(*p); - p++; - } + while (p && *p) + { + *p= tolower(*p); + p++; + } break; case case_case: if (!p || *p == '\0') - break; - while (isspace(*p)) p++; + break; + while (isspace(*p)) + p++; if (*p) - *p= toupper(*p); + *p= toupper(*p); break; } return(s); diff --git a/sim/ucsim/utils.h b/sim/ucsim/utils.h index 9a70db0f..f0cecff1 100644 --- a/sim/ucsim/utils.h +++ b/sim/ucsim/utils.h @@ -2,7 +2,7 @@ * Simulator of microcontrollers (utils.h) * * Copyright (C) 1999,99 Drotos Daniel, Talker Bt. - * + * * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu * */ @@ -34,15 +34,16 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "stypes.h" -extern int get_sub_opt(char **option, - const char * const *tokens, - char **valuep); +//#define TRACE printf +#define TRACE 1 ? (void)0 : (*(void (*)(const char *, ...))0) + + +extern int get_sub_opt(char **option, const char * const *tokens, char **valuep); extern char *get_id_string(struct id_element *ids, int id); extern char *get_id_string(struct id_element *ids, int id, char *def); extern int get_string_id(struct id_element *ids, char *str); extern int get_string_id(struct id_element *ids, char *str, int def); extern char *format_string(char *format, ...); -extern void print_char_octal(char c, FILE *f); extern char *object_name(class cl_base *o); extern char *case_string(enum letter_case lcase, char *str); diff --git a/sim/ucsim/xa.src/xa.cc b/sim/ucsim/xa.src/xa.cc index 35be697a..4f20da91 100644 --- a/sim/ucsim/xa.src/xa.cc +++ b/sim/ucsim/xa.src/xa.cc @@ -424,15 +424,15 @@ cl_xa::disass(t_addr addr, char *sep) case DIRECT_REG : sprintf(parm_str, "%s,%s", get_dir_name(((code & 0x7) << 8) | - get_mem(MEM_ROM_ID, addr+immed_offset)), + get_mem(MEM_ROM_ID, addr+immed_offset)), reg_strs[((code >> 4) & 0xf)] ); ++immed_offset; break; case REG_DIRECT : sprintf(parm_str, "%s,%s", - reg_strs[((code >> 4) & 0xf)], + reg_strs[((code >> 4) & 0xf)], get_dir_name(((code & 0x7) << 8) | - get_mem(MEM_ROM_ID, addr+immed_offset))); + get_mem(MEM_ROM_ID, addr+immed_offset))); ++immed_offset; break; case REG_DATA8 : @@ -512,16 +512,16 @@ cl_xa::disass(t_addr addr, char *sep) case DIRECT_DATA8 : sprintf(parm_str, "%s,#0x%02x", get_dir_name(((code & 0x0070) << 4) | - get_mem(MEM_ROM_ID, addr+immed_offset)), + get_mem(MEM_ROM_ID, addr+immed_offset)), get_mem(MEM_ROM_ID, addr+immed_offset+1)); immed_offset += 3; break; case DIRECT_DATA16 : sprintf(parm_str, "%s,#0x%04x", get_dir_name(((code & 0x0070) << 4) | - get_mem(MEM_ROM_ID, addr+immed_offset)), + get_mem(MEM_ROM_ID, addr+immed_offset)), get_mem(MEM_ROM_ID, addr+immed_offset+2) + - (get_mem(MEM_ROM_ID, addr+immed_offset+1)<<8)); + (get_mem(MEM_ROM_ID, addr+immed_offset+1)<<8)); immed_offset += 3; break; @@ -531,11 +531,11 @@ cl_xa::disass(t_addr addr, char *sep) break; case CY_BIT : sprintf(parm_str, "C,%s", - get_bit_name(((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2))); + get_bit_name(((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2))); break; case BIT_CY : sprintf(parm_str, "%s,C", - get_bit_name(((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2))); + get_bit_name(((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2))); break; case REG_DATA4 : strcpy(parm_str, "REG_DATA4"); @@ -557,14 +557,14 @@ cl_xa::disass(t_addr addr, char *sep) break; case DIRECT_DATA4 : sprintf(parm_str, "%s,#0x%x", - get_dir_name(((code & 0x70)<<4) | - get_mem(MEM_ROM_ID, addr+2)), - code&0x0f); + get_dir_name(((code & 0x70)<<4) | + get_mem(MEM_ROM_ID, addr+2)), + code&0x0f); break; case DIRECT : sprintf(parm_str, "%s", - get_dir_name(((code & 0x007) << 4) + - get_mem(MEM_ROM_ID, addr+2))); + get_dir_name(((code & 0x007) << 4) + + get_mem(MEM_ROM_ID, addr+2))); break; case REG : sprintf(parm_str, "%s", @@ -576,33 +576,33 @@ cl_xa::disass(t_addr addr, char *sep) break; case BIT_ALONE : sprintf(parm_str, "%s", - get_bit_name(((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2))); + get_bit_name(((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2))); break; case BIT_REL8 : sprintf(parm_str, "%s,0x%04x", - get_bit_name((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2), - ((signed char)get_mem(MEM_ROM_ID, addr+3)*2+addr+len)&0xfffe); + get_bit_name((code&0x0003)<<8) + get_mem(MEM_ROM_ID, addr+2), + ((signed char)get_mem(MEM_ROM_ID, addr+3)*2+addr+len)&0xfffe); break; case DATA4: sprintf(parm_str, "#0x%02x", code&0x0f); break; case ADDR24 : sprintf(parm_str, "0x%06x", - (get_mem(MEM_ROM_ID, addr+3)<<16) + - (get_mem(MEM_ROM_ID, addr+1)<<8) + - get_mem(MEM_ROM_ID, addr+2)); + (get_mem(MEM_ROM_ID, addr+3)<<16) + + (get_mem(MEM_ROM_ID, addr+1)<<8) + + get_mem(MEM_ROM_ID, addr+2)); break; break; case REG_REL8 : sprintf(parm_str, "%s,0x%04x", - reg_strs[(code>>4) & 0xf], - ((signed char)get_mem(MEM_ROM_ID, addr+2)*2+addr+len)&0xfffe); + reg_strs[(code>>4) & 0xf], + ((signed char)get_mem(MEM_ROM_ID, addr+2)*2+addr+len)&0xfffe); break; case DIRECT_REL8 : sprintf(parm_str, "%s,0x%04x", - get_dir_name(((code&0x07)<<8) + - get_mem(MEM_ROM_ID, addr+2)), - ((signed char)get_mem(MEM_ROM_ID, addr+2)*2+addr+len)&0xfffe); + get_dir_name(((code&0x07)<<8) + + get_mem(MEM_ROM_ID, addr+2)), + ((signed char)get_mem(MEM_ROM_ID, addr+2)*2+addr+len)&0xfffe); break; case REG_USP: sprintf(parm_str, "REG_USP"); @@ -612,58 +612,58 @@ cl_xa::disass(t_addr addr, char *sep) break; case REL8 : sprintf(parm_str, "0x%04x", - ((signed char)get_mem(MEM_ROM_ID, addr+1)*2+addr+len)&0xfffe); + ((signed char)get_mem(MEM_ROM_ID, addr+1)*2+addr+len)&0xfffe); break; case REL16 : sprintf(parm_str, "0x%04x", - ((signed short)((get_mem(MEM_ROM_ID, addr+1)<<8) + get_mem(MEM_ROM_ID, addr+2))*2+addr+len)&0xfffe); + ((signed short)((get_mem(MEM_ROM_ID, addr+1)<<8) + get_mem(MEM_ROM_ID, addr+2))*2+addr+len)&0xfffe); break; case RLIST : { /* TODO: the list should be comma reperated - and maybe for POP the list should be reversed */ + and maybe for POP the list should be reversed */ unsigned char rlist=code&0xff; parm_str[0]='\0'; if (code&0x0800) { // word list - if (code&0x4000) { // R8-R15 - if (rlist&0x80) strcat (parm_str, "R15 "); - if (rlist&0x40) strcat (parm_str, "R14"); - if (rlist&0x20) strcat (parm_str, "R13 "); - if (rlist&0x10) strcat (parm_str, "R12 "); - if (rlist&0x08) strcat (parm_str, "R11 "); - if (rlist&0x04) strcat (parm_str, "R10 "); - if (rlist&0x02) strcat (parm_str, "R9 "); - if (rlist&0x01) strcat (parm_str, "R8 "); - } else { // R7-R0 - if (rlist&0x80) strcat (parm_str, "R7 "); - if (rlist&0x40) strcat (parm_str, "R6 "); - if (rlist&0x20) strcat (parm_str, "R5 "); - if (rlist&0x10) strcat (parm_str, "R4 "); - if (rlist&0x08) strcat (parm_str, "R3 "); - if (rlist&0x04) strcat (parm_str, "R2 "); - if (rlist&0x02) strcat (parm_str, "R1 "); - if (rlist&0x01) strcat (parm_str, "R0 "); - } + if (code&0x4000) { // R8-R15 + if (rlist&0x80) strcat (parm_str, "R15 "); + if (rlist&0x40) strcat (parm_str, "R14"); + if (rlist&0x20) strcat (parm_str, "R13 "); + if (rlist&0x10) strcat (parm_str, "R12 "); + if (rlist&0x08) strcat (parm_str, "R11 "); + if (rlist&0x04) strcat (parm_str, "R10 "); + if (rlist&0x02) strcat (parm_str, "R9 "); + if (rlist&0x01) strcat (parm_str, "R8 "); + } else { // R7-R0 + if (rlist&0x80) strcat (parm_str, "R7 "); + if (rlist&0x40) strcat (parm_str, "R6 "); + if (rlist&0x20) strcat (parm_str, "R5 "); + if (rlist&0x10) strcat (parm_str, "R4 "); + if (rlist&0x08) strcat (parm_str, "R3 "); + if (rlist&0x04) strcat (parm_str, "R2 "); + if (rlist&0x02) strcat (parm_str, "R1 "); + if (rlist&0x01) strcat (parm_str, "R0 "); + } } else { // byte list - if (code&0x4000) { //R7h-R4l - if (rlist&0x80) strcat (parm_str, "R7h "); - if (rlist&0x40) strcat (parm_str, "R7l "); - if (rlist&0x20) strcat (parm_str, "R6h "); - if (rlist&0x10) strcat (parm_str, "R6l "); - if (rlist&0x08) strcat (parm_str, "R5h "); - if (rlist&0x04) strcat (parm_str, "R5l "); - if (rlist&0x02) strcat (parm_str, "R4h "); - if (rlist&0x01) strcat (parm_str, "R4l "); - } else { // R3h-R0l - if (rlist&0x80) strcat (parm_str, "R3h "); - if (rlist&0x40) strcat (parm_str, "R3l "); - if (rlist&0x20) strcat (parm_str, "R2h "); - if (rlist&0x10) strcat (parm_str, "R2l "); - if (rlist&0x08) strcat (parm_str, "R1h "); - if (rlist&0x04) strcat (parm_str, "R1l "); - if (rlist&0x02) strcat (parm_str, "R0h "); - if (rlist&0x01) strcat (parm_str, "R0l "); - } + if (code&0x4000) { //R7h-R4l + if (rlist&0x80) strcat (parm_str, "R7h "); + if (rlist&0x40) strcat (parm_str, "R7l "); + if (rlist&0x20) strcat (parm_str, "R6h "); + if (rlist&0x10) strcat (parm_str, "R6l "); + if (rlist&0x08) strcat (parm_str, "R5h "); + if (rlist&0x04) strcat (parm_str, "R5l "); + if (rlist&0x02) strcat (parm_str, "R4h "); + if (rlist&0x01) strcat (parm_str, "R4l "); + } else { // R3h-R0l + if (rlist&0x80) strcat (parm_str, "R3h "); + if (rlist&0x40) strcat (parm_str, "R3l "); + if (rlist&0x20) strcat (parm_str, "R2h "); + if (rlist&0x10) strcat (parm_str, "R2l "); + if (rlist&0x08) strcat (parm_str, "R1h "); + if (rlist&0x04) strcat (parm_str, "R1l "); + if (rlist&0x02) strcat (parm_str, "R0h "); + if (rlist&0x01) strcat (parm_str, "R0l "); + } } } break; @@ -672,7 +672,7 @@ cl_xa::disass(t_addr addr, char *sep) sprintf(parm_str, "%s,%s,0x%02x", reg_strs[((code >> 4) & 0xf)], get_dir_name(((code & 0x7) << 8) + - get_mem(MEM_ROM_ID, addr+immed_offset)), + get_mem(MEM_ROM_ID, addr+immed_offset)), ((signed char) get_mem(MEM_ROM_ID, addr+immed_offset+1) * 2) & 0xfffe ); break; case REG_DATA8_REL8 : @@ -698,7 +698,7 @@ cl_xa::disass(t_addr addr, char *sep) sprintf(parm_str, "[%s],#0x%04x,0x%02x", w_reg_strs[(code >> 4) & 0x7], get_mem(MEM_ROM_ID, addr+immed_offset+2) + - (get_mem(MEM_ROM_ID, addr+immed_offset+1)<<8), + (get_mem(MEM_ROM_ID, addr+immed_offset+1)<<8), ((signed char)get_mem(MEM_ROM_ID, addr+immed_offset) * 2) & 0xfffe ); break; @@ -712,17 +712,17 @@ cl_xa::disass(t_addr addr, char *sep) case REG_REGOFF8 : sprintf(parm_str, "%s,%s+0x%02x", - w_reg_strs[(code >> 4) & 0x7], - w_reg_strs[code & 0x7], - get_mem(MEM_ROM_ID, addr+immed_offset)); + w_reg_strs[(code >> 4) & 0x7], + w_reg_strs[code & 0x7], + get_mem(MEM_ROM_ID, addr+immed_offset)); break; case REG_REGOFF16 : sprintf(parm_str, "%s,%s+0x%02x", - w_reg_strs[(code >> 4) & 0x7], - w_reg_strs[code & 0x7], - get_mem(MEM_ROM_ID, addr+immed_offset+1) + - (get_mem(MEM_ROM_ID, addr+immed_offset+0)<<8)); + w_reg_strs[(code >> 4) & 0x7], + w_reg_strs[code & 0x7], + get_mem(MEM_ROM_ID, addr+immed_offset+1) + + (get_mem(MEM_ROM_ID, addr+immed_offset+0)<<8)); break; case A_PLUSDPTR : @@ -774,7 +774,7 @@ cl_xa::disass(t_addr addr, char *sep) Used to print a status line while stepping through the code. |--------------------------------------------------------------------*/ void -cl_xa::print_regs(class cl_console *con) +cl_xa::print_regs(class cl_console_base *con) { unsigned char flags; diff --git a/sim/ucsim/xa.src/xacl.h b/sim/ucsim/xa.src/xacl.h index fb64cae1..172f9235 100644 --- a/sim/ucsim/xa.src/xacl.h +++ b/sim/ucsim/xa.src/xacl.h @@ -83,7 +83,7 @@ public: int *mnemonic); virtual char *disass(t_addr addr, char *sep); - virtual void print_regs(class cl_console *con); + virtual void print_regs(class cl_console_base *con); virtual int exec_inst(void); virtual int get_reg(int word_flag, unsigned int index); diff --git a/sim/ucsim/z80.src/z80.cc b/sim/ucsim/z80.src/z80.cc index 05c7b8dd..46c5654d 100644 --- a/sim/ucsim/z80.src/z80.cc +++ b/sim/ucsim/z80.src/z80.cc @@ -331,35 +331,35 @@ cl_z80::disass(t_addr addr, char *sep) while (*b) { if (*b == '%') - { - b++; - switch (*(b++)) - { - case 'd': // d jump relative target, signed? byte immediate operand - sprintf(temp, "#%d", (char)get_mem(MEM_ROM_ID, addr+immed_offset)); - ++immed_offset; - break; - case 'w': // w word immediate operand - sprintf(temp, "#0x%04x", - (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)) | - (get_mem(MEM_ROM_ID, addr+immed_offset+1)<<8)) ); - ++immed_offset; - ++immed_offset; - break; - case 'b': // b byte immediate operand - sprintf(temp, "#0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset)); - ++immed_offset; - break; - default: - strcpy(temp, "?"); - break; - } - t= temp; - while (*t) - *(p++)= *(t++); - } + { + b++; + switch (*(b++)) + { + case 'd': // d jump relative target, signed? byte immediate operand + sprintf(temp, "#%d", (char)get_mem(MEM_ROM_ID, addr+immed_offset)); + ++immed_offset; + break; + case 'w': // w word immediate operand + sprintf(temp, "#0x%04x", + (uint)((get_mem(MEM_ROM_ID, addr+immed_offset)) | + (get_mem(MEM_ROM_ID, addr+immed_offset+1)<<8)) ); + ++immed_offset; + ++immed_offset; + break; + case 'b': // b byte immediate operand + sprintf(temp, "#0x%02x", (uint)get_mem(MEM_ROM_ID, addr+immed_offset)); + ++immed_offset; + break; + default: + strcpy(temp, "?"); + break; + } + t= temp; + while (*t) + *(p++)= *(t++); + } else - *(p++)= *(b++); + *(p++)= *(b++); } *p= '\0'; @@ -380,7 +380,7 @@ cl_z80::disass(t_addr addr, char *sep) if (sep == NULL) { while (strlen(buf) < 6) - strcat(buf, " "); + strcat(buf, " "); } else strcat(buf, sep); @@ -390,36 +390,36 @@ cl_z80::disass(t_addr addr, char *sep) void -cl_z80::print_regs(class cl_console *con) +cl_z80::print_regs(class cl_console_base *con) { con->dd_printf("SZ-A--P-C Flags= 0x%02x %3d %c ", - regs.F, regs.F, isprint(regs.F)?regs.F:'.'); + regs.F, regs.F, isprint(regs.F)?regs.F:'.'); con->dd_printf("A= 0x%02x %3d %c\n", - regs.A, regs.A, isprint(regs.A)?regs.A:'.'); + regs.A, regs.A, isprint(regs.A)?regs.A:'.'); con->dd_printf("%c%c-%c--%c-%c\n", - (regs.F&BIT_S)?'1':'0', - (regs.F&BIT_Z)?'1':'0', - (regs.F&BIT_A)?'1':'0', - (regs.F&BIT_P)?'1':'0', - (regs.F&BIT_C)?'1':'0'); + (regs.F&BIT_S)?'1':'0', + (regs.F&BIT_Z)?'1':'0', + (regs.F&BIT_A)?'1':'0', + (regs.F&BIT_P)?'1':'0', + (regs.F&BIT_C)?'1':'0'); con->dd_printf("BC= 0x%04x [BC]= %02x %3d %c ", - regs.BC, ram->get(regs.BC), ram->get(regs.BC), - isprint(ram->get(regs.BC))?ram->get(regs.BC):'.'); + regs.BC, ram->get(regs.BC), ram->get(regs.BC), + isprint(ram->get(regs.BC))?ram->get(regs.BC):'.'); con->dd_printf("DE= 0x%04x [DE]= %02x %3d %c ", - regs.DE, ram->get(regs.DE), ram->get(regs.DE), - isprint(ram->get(regs.DE))?ram->get(regs.DE):'.'); + regs.DE, ram->get(regs.DE), ram->get(regs.DE), + isprint(ram->get(regs.DE))?ram->get(regs.DE):'.'); con->dd_printf("HL= 0x%04x [HL]= %02x %3d %c\n", - regs.HL, ram->get(regs.HL), ram->get(regs.HL), - isprint(ram->get(regs.HL))?ram->get(regs.HL):'.'); + regs.HL, ram->get(regs.HL), ram->get(regs.HL), + isprint(ram->get(regs.HL))?ram->get(regs.HL):'.'); con->dd_printf("IX= 0x%04x [IX]= %02x %3d %c ", - regs.IX, ram->get(regs.IX), ram->get(regs.IX), - isprint(ram->get(regs.IX))?ram->get(regs.IX):'.'); + regs.IX, ram->get(regs.IX), ram->get(regs.IX), + isprint(ram->get(regs.IX))?ram->get(regs.IX):'.'); con->dd_printf("IY= 0x%04x [IY]= %02x %3d %c ", - regs.IY, ram->get(regs.IY), ram->get(regs.IY), - isprint(ram->get(regs.IY))?ram->get(regs.IY):'.'); + regs.IY, ram->get(regs.IY), ram->get(regs.IY), + isprint(ram->get(regs.IY))?ram->get(regs.IY):'.'); con->dd_printf("SP= 0x%04x [SP]= %02x %3d %c\n", - regs.SP, ram->get(regs.SP), ram->get(regs.SP), - isprint(ram->get(regs.SP))?ram->get(regs.SP):'.'); + regs.SP, ram->get(regs.SP), ram->get(regs.SP), + isprint(ram->get(regs.SP))?ram->get(regs.SP):'.'); print_disass(PC, con); } diff --git a/sim/ucsim/z80.src/z80cl.h b/sim/ucsim/z80.src/z80cl.h index 966d2464..4d66aef9 100644 --- a/sim/ucsim/z80.src/z80cl.h +++ b/sim/ucsim/z80.src/z80cl.h @@ -57,7 +57,7 @@ public: virtual int inst_branch(t_addr addr); virtual int longest_inst(void); virtual char *disass(t_addr addr, char *sep); - virtual void print_regs(class cl_console *con); + virtual void print_regs(class cl_console_base *con); virtual int exec_inst(void); -- 2.30.2