From a8b895ee0de37ed91bcc35e1633da977a638e4bf Mon Sep 17 00:00:00 2001 From: borutr Date: Wed, 16 Aug 2006 14:47:12 +0000 Subject: [PATCH] * sim/ucsim/cmd.src/newcmd.cc, sim/ucsim/cmd.src/newcmdcl.h, sim/ucsim/cmd.src/cmdutil.cc, sim/ucsim/cmd.src/cmdutil.h, sim/ucsim/sim.src/mem.cc, sim/ucsim/sim.src/uc.cc: code cleaning git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4339 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 6 + sim/ucsim/cmd.src/cmdutil.cc | 190 ++++++---------- sim/ucsim/cmd.src/cmdutil.h | 12 +- sim/ucsim/cmd.src/newcmd.cc | 412 +++++++++++++--------------------- sim/ucsim/cmd.src/newcmdcl.h | 72 +++--- sim/ucsim/sim.src/mem.cc | 294 ++++++++++++------------ sim/ucsim/sim.src/uc.cc | 417 +++++++++++++++++------------------ 7 files changed, 622 insertions(+), 781 deletions(-) diff --git a/ChangeLog b/ChangeLog index add8bca6..242623c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-08-16 Borut Razem + + * sim/ucsim/cmd.src/newcmd.cc, sim/ucsim/cmd.src/newcmdcl.h, + sim/ucsim/cmd.src/cmdutil.cc, sim/ucsim/cmd.src/cmdutil.h, + sim/ucsim/sim.src/mem.cc, sim/ucsim/sim.src/uc.cc: code cleaning + 2006-08-14 Borut Razem * support/regression/Makefile.in, diff --git a/sim/ucsim/cmd.src/cmdutil.cc b/sim/ucsim/cmd.src/cmdutil.cc index 793022d6..977068fc 100644 --- a/sim/ucsim/cmd.src/cmdutil.cc +++ b/sim/ucsim/cmd.src/cmdutil.cc @@ -118,8 +118,8 @@ get_name_entry(struct name_entry tabl[], char *name, class cl_uc *uc) return(0); for (p= name; *p; *p= toupper(*p), p++); while (tabl[i].name && - (!(tabl[i].cpu_type & uc->type) || - (strcmp(tabl[i].name, name) != 0))) + (!(tabl[i].cpu_type & uc->type) || + (strcmp(tabl[i].name, name) != 0))) { //printf("tabl[%d].name=%s <-> %s\n",i,tabl[i].name,name); i++; @@ -137,9 +137,9 @@ get_name_entry(struct name_entry tabl[], char *name, class cl_uc *uc) /*bool interpret_bitname(char *name, class cl_uc *uc, - uchar **cell, uchar *celladdr, - uchar *bitaddr, uchar *bitmask, - char **symname) + uchar **cell, uchar *celladdr, + uchar *bitaddr, uchar *bitmask, + char **symname) { char *dot, *p; char *sym, bitnumstr[2]; @@ -150,48 +150,48 @@ interpret_bitname(char *name, class cl_uc *uc, { *dot++= '\0'; if ((ne= get_name_entry(uc->sfr_tbl(), name, uc)) == NULL) - { - *celladdr= strtol(name, &p, 0); - if (p && *p) - { - dot--; - *dot= '.'; - return(DD_FALSE); - } - } + { + *celladdr= strtol(name, &p, 0); + if (p && *p) + { + dot--; + *dot= '.'; + return(DD_FALSE); + } + } else - *celladdr= ne->addr; + *celladdr= ne->addr; if ((*celladdr < 0x20) || - ((*celladdr > 0x2f) && (*celladdr < 0x80)) || - ((*celladdr > 0x7f) && (*celladdr & 0x07))) - return(DD_FALSE); + ((*celladdr > 0x2f) && (*celladdr < 0x80)) || + ((*celladdr > 0x7f) && (*celladdr & 0x07))) + return(DD_FALSE); bitnum= strtol(dot, &p, 0); if ((p && *p) || - (bitnum < 0) || - (bitnum > 7)) - return(DD_FALSE); + (bitnum < 0) || + (bitnum > 7)) + return(DD_FALSE); if (*celladdr > 0x7f) - *bitaddr= *celladdr + bitnum; + *bitaddr= *celladdr + bitnum; else - *bitaddr= (*celladdr - 0x20)*8 + bitnum; + *bitaddr= (*celladdr - 0x20)*8 + bitnum; dot--; *dot= '.'; } else { if ((ne= get_name_entry(uc->bit_tbl(), name, uc)) == NULL) - { - *bitaddr= strtol(name, &p, 0); - if ((p && *p) || - (*bitaddr > 0xff)) - return(DD_FALSE); - } + { + *bitaddr= strtol(name, &p, 0); + if ((p && *p) || + (*bitaddr > 0xff)) + return(DD_FALSE); + } else - *bitaddr= ne->addr; + *bitaddr= ne->addr; if (*bitaddr > 0x7f) - *celladdr= *bitaddr & 0xf8; + *celladdr= *bitaddr & 0xf8; else - *celladdr= (*bitaddr >> 3) + 0x20; + *celladdr= (*bitaddr >> 3) + 0x20; } // *bitaddr, *celladdr now OK *cell= uc->get_bit//FIXME @@ -202,7 +202,7 @@ interpret_bitname(char *name, class cl_uc *uc, return(DD_TRUE); i= 0; while (uc->bit_tbl()[i].name && - (uc->bit_tbl()[i].addr != *bitaddr)) + (uc->bit_tbl()[i].addr != *bitaddr)) i++; if (uc->bit_tbl()[i].name) { @@ -212,7 +212,7 @@ interpret_bitname(char *name, class cl_uc *uc, } i= 0; while (uc->sfr_tbl()[i].name && - (uc->sfr_tbl()[i].addr != *celladdr)) + (uc->sfr_tbl()[i].addr != *celladdr)) i++; if (uc->sfr_tbl()[i].name) sym= strdup(uc->sfr_tbl()[i].name); @@ -249,43 +249,43 @@ proc_escape(char *string, int *len) char *spec_c; if (*s == '\\' && - *(s+1)) - { - s++; - if (*s == '0') - { - if (!isdigit(*(s+1))) - { - *p++= '\0'; - s++; - } - else - { - char *octal, *chk, data; - int i, j; - i= strspn(s, "01234567"); - octal= (char *)malloc(i+1); - j= 0; - while (*s && - (j < i)) - octal[j++]= *s++; - octal[j]= '\0'; - data= strtol(octal, &chk, 8); - if (!chk || !(*chk)) - *p++= data; - } - } - else - if ((spec_c= strchr(spec_chars, *s)) != NULL) - { - *p++= spec[spec_c-spec_chars]; - s++; - } - else - *p++= *s++; - } + *(s+1)) + { + s++; + if (*s == '0') + { + if (!isdigit(*(s+1))) + { + *p++= '\0'; + s++; + } + else + { + char *octal, *chk, data; + int i, j; + i= strspn(s, "01234567"); + octal= (char *)malloc(i+1); + j= 0; + while (*s && + (j < i)) + octal[j++]= *s++; + octal[j]= '\0'; + data= strtol(octal, &chk, 8); + if (!chk || !(*chk)) + *p++= data; + } + } + else + if ((spec_c= strchr(spec_chars, *s)) != NULL) + { + *p++= spec[spec_c-spec_chars]; + s++; + } + else + *p++= *s++; + } else - *p++= *s++; + *p++= *s++; } *p= '\0'; *len= p-str; @@ -293,54 +293,4 @@ proc_escape(char *string, int *len) } - -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); - -int -cmd_vfprintf(FILE *f, char *format, va_list ap) -{ - int ret; - if (!f) - return(0); -#ifdef HAVE_VASPRINTF - char *msg= NULL; - vasprintf(&msg, format, ap); - ret= fprintf(f, "%s", msg); - free(msg); -#else -# ifdef HAVE_VSNPRINTF - char msg[80*25]; - vsnprintf(msg, 80*25, format, ap); - ret= fprintf(f, "%s", msg); -# else -# ifdef HAVE_VPRINTF - char msg[80*25]; - vsprintf(msg, format, ap); /* Dangerous */ - ret= fprintf(f, "%s", msg); -# else -# ifdef HAVE_DOPRNT - /* ??? */ - /*strcpy(msg, "Unimplemented printf has called.\n");*/ -# else - /*strcpy(msg, "printf can not be implemented, upgrade your libc.\n");*/ -# endif -# endif -# endif -#endif - fflush(f); - return(ret); -} - -int -cmd_fprintf(FILE *f, char *format, ...) -{ - va_list ap; - va_start(ap, format); - int ret= cmd_vfprintf(f, format, ap); - va_end(ap); - return(ret); -} - - /* End of cmd.src/cmdutil.cc */ diff --git a/sim/ucsim/cmd.src/cmdutil.h b/sim/ucsim/cmd.src/cmdutil.h index 229bdc35..f80db39a 100644 --- a/sim/ucsim/cmd.src/cmdutil.h +++ b/sim/ucsim/cmd.src/cmdutil.h @@ -36,15 +36,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA extern int make_server_socket(unsigned short int port); //extern void print_bin(long data, int bits, class cl_console *con); extern struct name_entry *get_name_entry(struct name_entry tabl[], - char *name, - class cl_uc *uc); + char *name, + class cl_uc *uc); /*extern bool interpret_bitname(char *name, class cl_uc *uc, - uchar **cell, uchar *celladdr, - uchar *bitaddr, uchar *bitmask, - char **symname);*/ + uchar **cell, uchar *celladdr, + uchar *bitaddr, uchar *bitmask, + char **symname);*/ extern char *proc_escape(char *string, int *len); -extern int cmd_vfprintf(FILE *f, char *format, va_list ap); -extern int cmd_fprintf(FILE *f, char *format, ...); #endif diff --git a/sim/ucsim/cmd.src/newcmd.cc b/sim/ucsim/cmd.src/newcmd.cc index b43f531b..2ae21942 100644 --- a/sim/ucsim/cmd.src/newcmd.cc +++ b/sim/ucsim/cmd.src/newcmd.cc @@ -269,7 +269,7 @@ cl_console::~cl_console(void) if (out) { if (flags & CONS_PROMPT) - fprintf(out, "\n"); + fprintf(out, "\n"); fflush(out); fclose(out); } @@ -304,18 +304,15 @@ cl_console::accept_last(void) void cl_console::welcome(void) { - FILE *Out= rout?rout:out; - - if (!Out || - (flags & CONS_NOWELCOME)) - return; - fprintf(Out, "uCsim %s, Copyright (C) 1997 Daniel Drotos, Talker Bt.\n" - "uCsim comes with ABSOLUTELY NO WARRANTY; for details type " - "`show w'.\n" - "This is free software, and you are welcome to redistribute it\n" - "under certain conditions; type `show c' for details.\n", - VERSIONSTR); - fflush(Out); + if (!(flags & CONS_NOWELCOME)) + { + dd_printf("uCsim %s, Copyright (C) 1997 Daniel Drotos, Talker Bt.\n" + "uCsim comes with ABSOLUTELY NO WARRANTY; for details type " + "`show w'.\n" + "This is free software, and you are welcome to redistribute it\n" + "under certain conditions; type `show c' for details.\n", + VERSIONSTR); + } } void @@ -323,7 +320,7 @@ 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)); + fname, (mode[0]=='w')?"write":"append", strerror(errno)); } void @@ -337,58 +334,40 @@ cl_console::un_redirect(void) int -cl_console::cmd_do_print(FILE *f, char *format, va_list ap) +cl_console::cmd_do_print(char *format, va_list ap) { - int ret; -#ifdef HAVE_VASPRINTF - char *msg= NULL; - vasprintf(&msg, format, ap); - ret= fprintf(f, "%s", msg); - free(msg); -#else -# ifdef HAVE_VSNPRINTF - char msg[80*25]; - vsnprintf(msg, 80*25, format, ap); - ret= fprintf(f, "%s", msg); -# else -# ifdef HAVE_VPRINTF - char msg[80*25]; - vsprintf(msg, format, ap); /* Dangerous */ - ret= fprintf(f, "%s", msg); -# else -# ifdef HAVE_DOPRNT - /* ??? */ - /*strcpy(msg, "Unimplemented printf has called.\n");*/ -# else - /*strcpy(msg, "printf can not be implemented, upgrade your libc.\n");*/ -# endif -# endif -# endif -#endif - fflush(f); + FILE *f = get_out(); + int ret = 0; + + if (f) + { + vfprintf(f, format, ap); + fflush(f); + } + return(ret); } void cl_console::print_prompt(void) { - //char *p; - FILE *Out= rout?rout:out; - if (flags & (CONS_PROMPT|CONS_FROZEN|CONS_INACTIVE)) return; flags|= CONS_PROMPT; - if (!Out) - return; if (/*app->args->arg_avail('P')*/null_prompt_option->get_value(bool(0))) - putc('\0', Out); + { + FILE *Out = get_out(); + if (Out) + { + putc('\0', Out); + fflush(Out); + } + } else { - fprintf(Out, "%d", id); - fprintf(Out, "%s", (prompt && prompt[0])?prompt:"> "); - // ((p= app->args->get_sarg(0, "prompt"))?p:"> ")); + dd_printf("%d%s", id, (prompt && prompt[0])?prompt:"> "); + // ((p= app->args->get_sarg(0, "prompt"))?p:"> ")); } - fflush(Out); } int @@ -396,14 +375,11 @@ cl_console::dd_printf(char *format, ...) { va_list ap; int ret= 0; - FILE *Out= rout?rout:out; - if (Out) - { - va_start(ap, format); - ret= cmd_do_print(Out, format, ap); - va_end(ap); - } + va_start(ap, format); + ret= cmd_do_print(format, ap); + va_end(ap); + return(ret); } @@ -415,14 +391,11 @@ cl_console::debug(char *format, ...) va_list ap; int ret= 0; - FILE *Out= rout?rout:out; - if (Out) - { - va_start(ap, format); - ret= cmd_do_print(Out, format, ap); - va_end(ap); - } + va_start(ap, format); + ret= cmd_do_print(format, ap); + va_end(ap); + return(ret); } @@ -430,14 +403,11 @@ void cl_console::print_bin(long data, int bits) { long mask= 1; - FILE *Out= rout?rout:out; - if (!Out) - return; mask= mask << ((bits >= 1)?(bits-1):0); while (bits--) { - fprintf(Out, "%c", (data&mask)?'1':'0'); + dd_printf("%c", (data&mask)?'1':'0'); mask>>= 1; } } @@ -445,7 +415,7 @@ cl_console::print_bin(long data, int bits) void cl_console::print_char_octal(char c) { - FILE *Out= rout?rout:out; + FILE *Out= get_out(); if (Out) ::print_char_octal(c, Out); @@ -549,58 +519,58 @@ cl_console::proc_input(class cl_cmdset *cmdset) else { if (cmdstr && - *cmdstr == '\004') - retval= 1; + *cmdstr == '\004') + retval= 1; else - { - class cl_cmdline *cmdline= 0; - class cl_cmd *cm= 0; - if (flags & CONS_ECHO) - dd_printf("%s\n", cmdstr); - cmdline= new cl_cmdline(app, cmdstr, this); - cmdline->init(); - if (cmdline->repeat() && - accept_last() && - last_command) - { - cm= last_command; - delete cmdline; - cmdline= last_cmdline; - } - else - { - cm= cmdset->get_cmd(cmdline, accept_last()); - if (last_cmdline) - { - delete last_cmdline; - last_cmdline= 0; - } - last_command= 0; - } - if (cm) - { - retval= cm->work(app, cmdline, this); - if (cm->can_repeat) - { - last_command= cm; - last_cmdline= cmdline; - } - else - delete cmdline; - } - else - { - 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); - pars->yyparse(); - delete cmdline; - delete pars; - } - /*if (!cm) - retval= interpret(cmdstr);*/ - } + { + class cl_cmdline *cmdline= 0; + class cl_cmd *cm= 0; + if (flags & CONS_ECHO) + dd_printf("%s\n", cmdstr); + cmdline= new cl_cmdline(app, cmdstr, this); + cmdline->init(); + if (cmdline->repeat() && + accept_last() && + last_command) + { + cm= last_command; + delete cmdline; + cmdline= last_cmdline; + } + else + { + cm= cmdset->get_cmd(cmdline, accept_last()); + if (last_cmdline) + { + delete last_cmdline; + last_cmdline= 0; + } + last_command= 0; + } + if (cm) + { + retval= cm->work(app, cmdline, this); + if (cm->can_repeat) + { + last_command= cm; + last_cmdline= cmdline; + } + else + delete cmdline; + } + else + { + 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); + pars->yyparse(); + delete cmdline; + delete pars; + } + /*if (!cm) + retval= interpret(cmdstr);*/ + } } //retval= sim->do_cmd(cmd, this); un_redirect(); @@ -618,9 +588,7 @@ cl_console::proc_input(class cl_cmdset *cmdset) int cl_console::interpret(char *cmd) { - FILE *Out= rout?rout:out; - - fprintf(Out, "Unknown command\n"); + dd_printf("Unknown command\n"); return(0); } @@ -658,8 +626,8 @@ cl_listen_console::cl_listen_console(int serverport, class cl_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)); + fprintf(stderr, "Listen on port %d: %s\n", + serverport, strerror(errno)); } in= out= 0; } @@ -711,7 +679,7 @@ cl_listen_console::proc_input(class cl_cmdset *cmdset) */ cl_sub_console::cl_sub_console(class cl_console *the_parent, - FILE *fin, FILE *fout, class cl_app *the_app): + FILE *fin, FILE *fout, class cl_app *the_app): cl_console(fin, fout, the_app) { parent= the_parent; @@ -748,7 +716,7 @@ cl_sub_console::init(void) */ cl_commander::cl_commander(class cl_app *the_app, class cl_cmdset *acmdset - /*, class cl_sim *asim*/): + /*, class cl_sim *asim*/): cl_base() { app= the_app; @@ -812,13 +780,13 @@ cl_commander::init(void) { FILE *fc= fopen(Config, "r"); if (!fc) - fprintf(stderr, "Can't open `%s': %s\n", Config, strerror(errno)); + 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); - } + { + con= mk_console(fc, stderr); + con->flags|= CONS_NOWELCOME|CONS_ECHO; + add_console(con); + } } return(0); } @@ -895,17 +863,17 @@ cl_commander::set_fd_set(void) 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; - } - } + { + 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); + ;//fprintf(stderr, "** Skipping console %p\n",c); } fd_num++; } @@ -924,13 +892,10 @@ cl_commander::all_printf(char *format, ...) for (i= 0; i < cons->count; i++) { class cl_console *c= (class cl_console*)(cons->at(i)); - FILE *Out= c->get_out(); - if (Out) - { - va_start(ap, format); - ret= c->cmd_do_print(Out, format, ap); - va_end(ap); - } + + va_start(ap, format); + ret= c->cmd_do_print(format, ap); + va_end(ap); } return(ret); } @@ -947,103 +912,38 @@ cl_commander::prompt(void) } } -int -cl_commander::all_print(char *string, int length) -{ - int i; - - for (i= 0; i < cons->count; i++) - { - class cl_console *c= (class cl_console*)(cons->at(i)); - FILE *Out= c->get_out(); - if (Out) - { - for (int j= 0; j < length; j++) - putc(string[j], Out); - } - } - return(0); -} - /* * Printing to actual_console */ -FILE * -cl_commander::get_out(void) -{ - if (actual_console) - return(actual_console->get_out()); - else if (frozen_console) - return(frozen_console->get_out()); - return(0); -} - int cl_commander::dd_printf(char *format, ...) { va_list ap; int ret= 0; - FILE *f; class cl_console *con; if (actual_console) { - f= actual_console->get_out(); con= actual_console; } else if (frozen_console) { - f= frozen_console->get_out(); con= frozen_console; } else { - f= 0; con= 0; } - if (/*actual_console && - actual_console->out*/f && - con) + if (con) { va_start(ap, format); - ret= con->cmd_do_print(f/*actual_console->out*/, format, ap); + ret= con->cmd_do_print(format, ap); va_end(ap); } return(ret); } -int -cl_commander::dd_printf(char *format, va_list ap) -{ - int ret= 0; - FILE *f; - class cl_console *con; - - if (actual_console) - { - f= actual_console->get_out(); - con= actual_console; - } - else if (frozen_console) - { - f= frozen_console->get_out(); - con= frozen_console; - } - else - { - f= 0; - con= 0; - } - if (/*actual_console && - actual_console->out*/f && - con) - { - ret= con->cmd_do_print(f/*actual_console->out*/, format, ap); - } - return(ret); -} - /* * Printing to consoles which have CONS_DEBUG flag set */ @@ -1057,14 +957,12 @@ cl_commander::debug(char *format, ...) for (i= 0; i < cons->count; i++) { class cl_console *c= (class cl_console*)(cons->at(i)); - FILE *Out= c->get_out(); - if (Out && - c->flags & CONS_DEBUG) - { - va_start(ap, format); - ret= c->cmd_do_print(Out, format, ap); - va_end(ap); - } + if (c->flags & CONS_DEBUG) + { + va_start(ap, format); + ret= c->cmd_do_print(format, ap); + va_end(ap); + } } return(ret); } @@ -1077,12 +975,10 @@ cl_commander::debug(char *format, va_list ap) for (i= 0; i < cons->count; i++) { class cl_console *c= (class cl_console*)(cons->at(i)); - FILE *Out= c->get_out(); - if (Out && - c->flags & CONS_DEBUG) - { - ret= c->cmd_do_print(Out, format, ap); - } + if (c->flags & CONS_DEBUG) + { + ret= c->cmd_do_print(format, ap); + } } return(ret); } @@ -1096,14 +992,12 @@ cl_commander::flag_printf(int iflags, char *format, ...) for (i= 0; i < cons->count; i++) { class cl_console *c= (class cl_console*)(cons->at(i)); - FILE *Out= c->get_out(); - if (Out && - (c->flags & iflags) == iflags) - { - va_start(ap, format); - ret= c->cmd_do_print(Out, format, ap); - va_end(ap); - } + if ((c->flags & iflags) == iflags) + { + va_start(ap, format); + ret= c->cmd_do_print(format, ap); + va_end(ap); + } } return(ret); } @@ -1152,24 +1046,24 @@ cl_commander::proc_input(void) for (i= 0; i < fd_num; i++) if (FD_ISSET(i, &active_set)) { - class cl_console *c; - int j; - for (j= 0; j < cons->count; j++) - { - c= (class cl_console*)(cons->at(j)); - if (c->match(i)) - { - actual_console= c; - int retval= c->proc_input(cmdset); - if (retval) - { - del_console(c); - delete c; - } - actual_console= 0; - return(cons->count == 0); - } - } + class cl_console *c; + int j; + for (j= 0; j < cons->count; j++) + { + c= (class cl_console*)(cons->at(j)); + if (c->match(i)) + { + actual_console= c; + int retval= c->proc_input(cmdset); + if (retval) + { + del_console(c); + delete c; + } + actual_console= 0; + return(cons->count == 0); + } + } } return(0); } diff --git a/sim/ucsim/cmd.src/newcmdcl.h b/sim/ucsim/cmd.src/newcmdcl.h index 8204307d..6655260a 100644 --- a/sim/ucsim/cmd.src/newcmdcl.h +++ b/sim/ucsim/cmd.src/newcmdcl.h @@ -49,31 +49,31 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA // Flags of consoles -#define CONS_NONE 0 -#define CONS_DEBUG 0x01 // Print debug messages on this console -#define CONS_FROZEN 0x02 // Console is frozen (g command issued) -#define CONS_PROMPT 0x04 // Prompt is out, waiting for input -#define CONS_INTERACTIVE 0x08 // Interactive console -#define CONS_NOWELCOME 0x10 // Do not print welcome message -#define CONS_INACTIVE 0x20 // Do not do any action -#define CONS_ECHO 0x40 // Echo commands - -#define SY_ADDR 'a' -#define ADDRESS "a" -#define SY_NUMBER 'n' -#define NUMBER "n" -#define SY_DATA 'd' -#define DATA "d" -#define SY_STRING 's' -#define STRING "s" -#define SY_MEMORY 'm' -#define MEMORY "m" -#define SY_HW 'h' -#define HW "h" -#define SY_DATALIST 'D' -#define DATALIST "D" -#define SY_BIT 'b' -#define BIT "b" +#define CONS_NONE 0 +#define CONS_DEBUG 0x01 // Print debug messages on this console +#define CONS_FROZEN 0x02 // Console is frozen (g command issued) +#define CONS_PROMPT 0x04 // Prompt is out, waiting for input +#define CONS_INTERACTIVE 0x08 // Interactive console +#define CONS_NOWELCOME 0x10 // Do not print welcome message +#define CONS_INACTIVE 0x20 // Do not do any action +#define CONS_ECHO 0x40 // Echo commands + +#define SY_ADDR 'a' +#define ADDRESS "a" +#define SY_NUMBER 'n' +#define NUMBER "n" +#define SY_DATA 'd' +#define DATA "d" +#define SY_STRING 's' +#define STRING "s" +#define SY_MEMORY 'm' +#define MEMORY "m" +#define SY_HW 'h' +#define HW "h" +#define SY_DATALIST 'D' +#define DATALIST "D" +#define SY_BIT 'b' +#define BIT "b" class cl_prompt_option: public cl_optref @@ -132,8 +132,7 @@ public: virtual void welcome(void); virtual void redirect(char *fname, char *mode); virtual void un_redirect(void); - virtual FILE *get_out(void) { return(rout?rout:out); } - int cmd_do_print(FILE *f, char *format, va_list ap); + 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, ...); @@ -148,6 +147,8 @@ public: 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 @@ -159,7 +160,6 @@ public: cl_listen_console(int serverport, class cl_app *the_app); virtual void welcome(void) {} - virtual void prompt(void) {} virtual int match(int fdnum); virtual int get_in_fd(void); @@ -173,7 +173,7 @@ 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); + FILE *fin, FILE *fout, class cl_app *the_app); virtual ~cl_sub_console(void); virtual int init(void); }; @@ -190,13 +190,12 @@ public: class cl_list *cons; fd_set read_set, active_set; UCSOCKET_T fd_num; - //class cl_sim *sim; class cl_console *actual_console, *frozen_console; class cl_cmdset *cmdset; public: cl_commander(class cl_app *the_app, - class cl_cmdset *acmdset/*, class cl_sim *asim*/); + class cl_cmdset *acmdset/*, class cl_sim *asim*/); virtual ~cl_commander(void); virtual int init(void); @@ -212,13 +211,10 @@ public: void set_fd_set(void); void prompt(void); - FILE *get_out(void); - int all_printf(char *format, ...); // print to all consoles - int all_print(char *string, int length); - int dd_printf(char *format, ...); // print to actual_console - int dd_printf(char *format, va_list ap);// print to actual_console - int debug(char *format, ...); // print consoles with debug flag set - int debug(char *format, va_list ap); // print consoles with debug flag set + int all_printf(char *format, ...); // print to all consoles + int dd_printf(char *format, ...); // print to actual_console + 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); diff --git a/sim/ucsim/sim.src/mem.cc b/sim/ucsim/sim.src/mem.cc index fc67632a..adf34b8c 100644 --- a/sim/ucsim/sim.src/mem.cc +++ b/sim/ucsim/sim.src/mem.cc @@ -78,12 +78,12 @@ cl_memory::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)); data_mask= 1; @@ -102,7 +102,7 @@ bool cl_memory::valid_address(t_addr addr) { return(addr >= start_address && - addr < start_address+size); + addr < start_address+size); } t_addr @@ -175,42 +175,42 @@ cl_memory::dump(t_addr start, t_addr stop, int bpl, class cl_console *con) if (stop > hva) stop= hva; while ((start <= stop) && - (start < hva)) + (start < hva)) { con->dd_printf(addr_format, start); con->dd_printf(" "); for (i= 0; - (i < bpl) && - (start+i < hva) && - (start+i <= stop); - i++) - { - con->dd_printf(data_format, /*read*/get(start+i)); con->dd_printf(" "); - } + (i < bpl) && + (start+i < hva) && + (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 < hva) && - (start+i <= stop); - i++) - { - long c= read(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 < hva) && + (start+i <= stop); + i++) + { + long c= read(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; @@ -226,7 +226,7 @@ cl_memory::dump(class cl_console *con) bool cl_memory::search_next(bool case_sensitive, - t_mem *array, int len, t_addr *addr) + t_mem *array, int len, t_addr *addr) { t_addr a; int i; @@ -242,26 +242,26 @@ cl_memory::search_next(bool case_sensitive, 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) @@ -275,7 +275,7 @@ cl_memory::search_next(bool case_sensitive, */ cl_memory_operator::cl_memory_operator(class cl_memory_cell *acell, - t_addr addr): + t_addr addr): cl_base() { cell= acell; @@ -286,8 +286,8 @@ cl_memory_operator::cl_memory_operator(class cl_memory_cell *acell, } cl_memory_operator::cl_memory_operator(class cl_memory_cell *acell, - t_addr addr, - t_mem *data_place, t_mem the_mask): + t_addr addr, + t_mem *data_place, t_mem the_mask): cl_base() { cell= acell; @@ -327,8 +327,8 @@ cl_memory_operator::write(t_mem val) /* Memory operator for hw callbacks */ cl_hw_operator::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): cl_memory_operator(acell, addr, data_place, the_mask) { hw= ahw; @@ -378,8 +378,8 @@ cl_hw_operator::write(t_mem val) /* Write event break on cell */ cl_write_operator::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): cl_event_break_operator(acell, addr, data_place, the_mask, auc, the_bp) { uc= auc; @@ -401,8 +401,8 @@ cl_write_operator::write(t_mem val) /* Read event break on cell */ cl_read_operator::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): cl_event_break_operator(acell, addr, data_place, the_mask, auc, the_bp) { uc= auc; @@ -605,10 +605,10 @@ cl_memory_cell::append_operator(class cl_memory_operator *op) class cl_memory_operator *o= operators, *n; n= o->get_next(); while (n) - { - o= n; - n= o->get_next(); - } + { + o= n; + n= o->get_next(); + } o->set_next(op); } } @@ -637,14 +637,14 @@ cl_memory_cell::del_operator(class cl_brk *brk) else { while (op->get_next() && - !op->get_next()->match(brk)) - op= op->get_next(); + !op->get_next()->match(brk)) + op= op->get_next(); if (op->get_next()) - { - class cl_memory_operator *m= op->get_next(); - op->set_next(m->get_next());; - delete m; - } + { + class cl_memory_operator *m= op->get_next(); + op->set_next(m->get_next());; + delete m; + } } } @@ -697,7 +697,7 @@ cl_dummy_cell::set(t_mem val) */ cl_address_space::cl_address_space(char *id, - t_addr astart, t_addr asize, int awidth): + t_addr astart, t_addr asize, int awidth): cl_memory(id, asize, awidth) { start_address= astart; @@ -790,13 +790,13 @@ cl_address_space::get_decoder(t_addr addr) for (i= 0; i < decoders->count; i++) { class cl_address_decoder *d= - dynamic_cast(decoders->object_at(i)); + dynamic_cast(decoders->object_at(i)); if (!d) - continue; + continue; if (d->covers(addr, addr)) - { - return d; - } + { + return d; + } } return NULL; } @@ -848,7 +848,7 @@ cl_address_space::set_cell_flag(t_addr addr, bool set_to, enum cell_flag flag) bool cl_address_space::decode_cell(t_addr addr, - class cl_memory_chip *chip, t_addr chipaddr) + class cl_memory_chip *chip, t_addr chipaddr) { cl_memory_cell *cell = get_cell(addr); if (cell == dummy) @@ -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 *con) { #define D if (con) con->debug D("Undecoding area 0x%x-0x%x of %s\n", begin, end, get_name()); @@ -893,57 +893,57 @@ cl_address_space::undecode_area(class cl_address_decoder *skip, for (i= 0; i < decoders->count; i++) { class cl_address_decoder *d= - dynamic_cast(decoders->object_at(i)); + dynamic_cast(decoders->object_at(i)); if (!d || - d == skip) - continue; + d == skip) + continue; D(" Checking decoder 0x%x-0x%x -> %s[0x%x]\n", - d->as_begin, d->as_end, d->memchip->get_name(), d->chip_begin); + d->as_begin, d->as_end, d->memchip->get_name(), d->chip_begin); if (d->fully_covered_by(begin, end)) - { - // decoder can be removed - D(" Can be removed\n"); - decoders->disconn(d); - i--; - delete d; - if (decoders->count == 0) - break; - } + { + // decoder can be removed + D(" Can be removed\n"); + decoders->disconn(d); + i--; + delete d; + if (decoders->count == 0) + break; + } else if (d->covers(begin, end)) - { - // decoder must be split - D(" Must be split\n"); - class cl_address_decoder *nd= d->split(begin, end); - D(" After split:\n"); - D(" 0x%x-0x%x -> %s[0x%x]\n", - d->as_begin, d->as_end, d->memchip->get_name(), d->chip_begin); - if (nd) - { - decoders->add(nd); - D(" 0x%x-0x%x -> %s[0x%x]\n", - nd->as_begin, nd->as_end, nd->memchip->get_name(), nd->chip_begin); - nd->activate(con); - } - } + { + // decoder must be split + D(" Must be split\n"); + class cl_address_decoder *nd= d->split(begin, end); + D(" After split:\n"); + D(" 0x%x-0x%x -> %s[0x%x]\n", + d->as_begin, d->as_end, d->memchip->get_name(), d->chip_begin); + if (nd) + { + decoders->add(nd); + D(" 0x%x-0x%x -> %s[0x%x]\n", + nd->as_begin, nd->as_end, nd->memchip->get_name(), nd->chip_begin); + nd->activate(con); + } + } else if (d->is_in(begin, end)) - { - // decoder sould shrink - D(" Sould shrink\n"); - if (d->shrink_out_of(begin, end)) - { - D(" Can be removed after shrink\n"); - decoders->disconn(d); - i--; - delete d; - if (decoders->count == 0) - break; - } - else - { - D(" Shrinked to 0x%x-0x%x -> %s[0x%x]\n", - d->as_begin, d->as_end, d->memchip->get_name(), d->chip_begin); - } - } + { + // decoder sould shrink + D(" Sould shrink\n"); + if (d->shrink_out_of(begin, end)) + { + D(" Can be removed after shrink\n"); + decoders->disconn(d); + i--; + delete d; + if (decoders->count == 0) + break; + } + else + { + D(" Shrinked to 0x%x-0x%x -> %s[0x%x]\n", + d->as_begin, d->as_end, d->memchip->get_name(), d->chip_begin); + } + } } #undef D } @@ -951,8 +951,8 @@ cl_address_space::undecode_area(class cl_address_decoder *skip, class cl_memory_cell * cl_address_space::register_hw(t_addr addr, class cl_hw *hw, - int *ith, - bool announce) + int *ith, + bool announce) { cl_memory_cell *cell = get_cell(addr); if (cell == dummy) @@ -983,12 +983,12 @@ cl_address_space::set_brk(t_addr addr, class cl_brk *brk) case brkWRITE: case brkWXRAM: case brkWIRAM: case brkWSFR: //e= 'W'; op= new cl_write_operator(cell, addr, cell->get_data(), cell->get_mask(), - uc, brk); + uc, brk); break; case brkREAD: case brkRXRAM: case brkRCODE: case brkRIRAM: case brkRSFR: //e= 'R'; op= new cl_read_operator(cell, addr, cell->get_data(), cell->get_mask(), - uc, brk); + uc, brk); break; case brkNONE: set_cell_flag(addr, DD_TRUE, CELL_FETCH_BRK); @@ -1076,7 +1076,7 @@ cl_memory_chip::init(void) int i; for (i= 0; i < size; i++) set(i, - (init_value<0)?rand():(init_value)); + (init_value<0)?rand():(init_value)); return(0); } @@ -1133,8 +1133,8 @@ cl_memory_chip::set_bit0(t_addr addr, t_mem bits) */ cl_address_decoder::cl_address_decoder(class cl_memory *as, - class cl_memory *chip, - t_addr asb, t_addr ase, t_addr cb) + class cl_memory *chip, + t_addr asb, t_addr ase, t_addr cb) { if (as->is_address_space()) address_space= (class cl_address_space *)as; @@ -1261,7 +1261,7 @@ cl_address_decoder::shrink_out_of(t_addr begin, t_addr end) if (begin > a) a= begin; while (a <= end && - a <= as_end) + a <= as_end) { address_space->undecode_cell(a); a++; @@ -1285,15 +1285,15 @@ cl_address_decoder::split(t_addr begin, t_addr end) if (begin > as_begin) { if (as_end > end) - nd= new cl_address_decoder(address_space, memchip, - end+1, as_end, chip_begin+(end-as_begin)+1); + nd= new cl_address_decoder(address_space, memchip, + end+1, as_end, chip_begin+(end-as_begin)+1); shrink_out_of(begin, as_end); } else if (end < as_end) { if (as_begin < begin) - nd= new cl_address_decoder(address_space, memchip, - as_begin, begin-1, chip_begin); + nd= new cl_address_decoder(address_space, memchip, + as_begin, begin-1, chip_begin); shrink_out_of(end+1, as_end); } if (nd) @@ -1360,10 +1360,9 @@ cl_error_mem_invalid_address(class cl_memory *amem, t_addr aaddr): void cl_error_mem_invalid_address::print(class cl_commander *c) { - FILE *f= c->get_out(); - cmd_fprintf(f, "%s: invalid address ", get_type_name()); - cmd_fprintf(f, mem->addr_format, addr); - cmd_fprintf(f, " in memory %s.\n", mem->get_name()); + c->dd_printf("%s: invalid address ", get_type_name()); + c->dd_printf(mem->addr_format, addr); + c->dd_printf(" in memory %s.\n", mem->get_name()); } /* Non-decoded address space access */ @@ -1378,10 +1377,9 @@ cl_error_mem_non_decoded(class cl_memory *amem, t_addr aaddr): void cl_error_mem_non_decoded::print(class cl_commander *c) { - FILE *f= c->get_out(); - cmd_fprintf(f, "%s: access of non-decoded address ", get_type_name()); - cmd_fprintf(f, mem->addr_format, addr); - cmd_fprintf(f, " in memory %s.\n", mem->get_name()); + c->dd_printf("%s: access of non-decoded address ", get_type_name()); + c->dd_printf(mem->addr_format, addr); + c->dd_printf(" in memory %s.\n", mem->get_name()); } cl_mem_error_registry::cl_mem_error_registry(void) diff --git a/sim/ucsim/sim.src/uc.cc b/sim/ucsim/sim.src/uc.cc index 8af862db..9eff9810 100644 --- a/sim/ucsim/sim.src/uc.cc +++ b/sim/ucsim/sim.src/uc.cc @@ -95,10 +95,10 @@ void cl_ticker::dump(int nr, double xtal, class cl_console *con) { con->dd_printf("timer #%d(\"%s\") %s%s: %g sec (%lu clks)\n", - nr, get_name("unnamed"), - (options&TICK_RUN)?"ON":"OFF", - (options&TICK_INISR)?",ISR":"", - get_rtime(xtal), ticks); + nr, get_name("unnamed"), + (options&TICK_RUN)?"ON":"OFF", + (options&TICK_INISR)?",ISR":"", + get_rtime(xtal), ticks); } @@ -213,10 +213,10 @@ cl_uc::init(void) char *fname= (char *)(sim->app->in_files->at(i)); long l; if ((l= read_hex_file(fname)) >= 0) - { - sim->app->get_commander()->all_printf("%ld words read from %s\n", - l, fname); - } + { + sim->app->get_commander()->all_printf("%ld words read from %s\n", + l, fname); + } } return(0); } @@ -240,7 +240,7 @@ cl_uc::reset(void) /*FIXME should we clear user counters?*/ il= (class it_level *)(it_levels->top()); while (il && - il->level >= 0) + il->level >= 0) { il= (class it_level *)(it_levels->pop()); delete il; @@ -653,10 +653,10 @@ cl_uc::address_space(char *id) { class cl_address_space *m= (cl_address_space *)(address_spaces->at(i)); if (!m || - !m->have_real_name()) - continue; + !m->have_real_name()) + continue; if (m->is_inamed(id)) - return(m); + return(m); } return(0); } @@ -673,19 +673,19 @@ cl_uc::memory(char *id) { class cl_memory *m= (cl_memory *)(address_spaces->at(i)); if (!m || - !m->have_real_name()) - continue; + !m->have_real_name()) + continue; if (m->is_inamed(id)) - return(m); + return(m); } for (i= 0; i < memchips->count; i++) { class cl_memory *m= (cl_memory *)(memchips->at(i)); if (!m || - !m->have_real_name()) - continue; + !m->have_real_name()) + continue; if (m->is_inamed(id)) - return(m); + return(m); } return(0); } @@ -701,7 +701,7 @@ ReadInt(FILE *f, bool *ok, int bytes) while (bytes) { if (fscanf(f, "%2c", &s2[0]) == EOF) - return(0); + return(0); s2[2]= '\0'; l= l*256 + strtol(s2, NULL, 16); bytes--; @@ -739,32 +739,32 @@ cl_uc::read_hex_file(const char *nam) if (!rom) { sim->app->get_commander()-> - dd_printf("No ROM address space to read in.\n"); + dd_printf("No ROM address space to read in.\n"); return(-1); } if (!nam) { sim->app->get_commander()-> - dd_printf("cl_uc::read_hex_file File name not specified\n"); + dd_printf("cl_uc::read_hex_file File name not specified\n"); return(-1); } else if ((f= fopen(nam, "r")) == NULL) { - fprintf(stderr, "Can't open `%s': %s\n", nam, strerror(errno)); - return(-1); + fprintf(stderr, "Can't open `%s': %s\n", nam, strerror(errno)); + return(-1); } //memset(inst_map, '\0', sizeof(inst_map)); ok= DD_TRUE; while (ok && - rtyp != 1) + rtyp != 1) { while (((c= getc(f)) != ':') && - (c != EOF)) ; + (c != EOF)) ; if (c != ':') - {fprintf(stderr, ": not found\n");break;} + {fprintf(stderr, ": not found\n");break;} recnum++; dnum= ReadInt(f, &ok, 1);//printf("dnum=%02x",dnum); chk = dnum; @@ -774,59 +774,59 @@ cl_uc::read_hex_file(const char *nam) rtyp= ReadInt(f, &ok, 1);//printf("rtyp=%02x ",rtyp); chk+= rtyp; for (i= 0; ok && (i < dnum); i++) - { - rec[i]= ReadInt(f, &ok, 1);//printf("%02x",rec[i]); - chk+= rec[i]; - } + { + rec[i]= ReadInt(f, &ok, 1);//printf("%02x",rec[i]); + chk+= rec[i]; + } if (ok) - { - sum= ReadInt(f, &ok, 1);//printf(" sum=%02x\n",sum); - if (ok) - { - if (((sum + chk) & 0xff) == 0) - { - if (rtyp == 0) - { - if (rom->width > 8) - addr/= 2; - for (i= 0; i < dnum; i++) - { - if (rom->width <= 8) - { - rom->set(addr, rec[i]); - addr++; - written++; - } - else if (rom->width <= 16) - { - if (get_low) - { - low= rec[i]; - get_low= 0; - } - else - { - high= rec[i]; - rom->set(addr, (high*256)+low); - addr++; - written++; - get_low= 1; - } - } - } - } - else - if (rtyp != 1) - application->debug("Unknown record type %d(0x%x)\n", - rtyp, rtyp); - } - else - application->debug("Checksum error (%x instead of %x) in " - "record %ld.\n", chk, sum, recnum); - } - else - application->debug("Read error in record %ld.\n", recnum); - } + { + sum= ReadInt(f, &ok, 1);//printf(" sum=%02x\n",sum); + if (ok) + { + if (((sum + chk) & 0xff) == 0) + { + if (rtyp == 0) + { + if (rom->width > 8) + addr/= 2; + for (i= 0; i < dnum; i++) + { + if (rom->width <= 8) + { + rom->set(addr, rec[i]); + addr++; + written++; + } + else if (rom->width <= 16) + { + if (get_low) + { + low= rec[i]; + get_low= 0; + } + else + { + high= rec[i]; + rom->set(addr, (high*256)+low); + addr++; + written++; + get_low= 1; + } + } + } + } + else + if (rtyp != 1) + application->debug("Unknown record type %d(0x%x)\n", + rtyp, rtyp); + } + else + application->debug("Checksum error (%x instead of %x) in " + "record %ld.\n", chk, sum, recnum); + } + else + application->debug("Read error in record %ld.\n", recnum); + } } if (rom->width > 8 && !get_low) @@ -900,11 +900,11 @@ cl_uc::register_hw_read(enum mem_class type, t_addr addr, class cl_hw *hw) if ((m= (class cl_m*)mems->at(type))) { if ((l= m->read_locs->get_loc(addr)) == 0) - { - l= new cl_memloc(addr); - l->init(); - m->read_locs->add(l); - } + { + l= new cl_memloc(addr); + l->init(); + m->read_locs->add(l); + } l->hws->add(hw); } else @@ -930,7 +930,7 @@ cl_uc::get_hw(enum hw_cath cath, int *idx) { hw= (class cl_hw *)(hws->at(i)); if (hw->cathegory == cath) - break; + break; } if (i >= hws->count) return(0); @@ -951,7 +951,7 @@ cl_uc::get_hw(char *id_string, int *idx) { hw= (class cl_hw *)(hws->at(i)); if (strstr(hw->id_string, id_string) == hw->id_string) - break; + break; } if (i >= hws->count) return(0); @@ -970,7 +970,7 @@ cl_uc::get_hw(enum hw_cath cath, int hwid, int *idx) i= *idx; hw= get_hw(cath, &i); while (hw && - hw->id != hwid) + hw->id != hwid) { i++; hw= get_hw(cath, &i); @@ -991,7 +991,7 @@ cl_uc::get_hw(char *id_string, int hwid, int *idx) i= *idx; hw= get_hw(id_string, &i); while (hw && - hw->id != hwid) + hw->id != hwid) { i++; hw= get_hw(id_string, &i); @@ -1069,7 +1069,7 @@ cl_uc::print_disass(t_addr addr, class cl_console *con) int j; j= rom->width/4 + ((rom->width%4)?1:0) + 1; while (j) - con->dd_printf(" "), j--; + con->dd_printf(" "), j--; i++; } con->dd_printf(" %s\n", dis); @@ -1120,10 +1120,10 @@ cl_uc::longest_inst(void) int max= 0; while (de && - de->mnemonic) + de->mnemonic) { if (de->length > max) - max= de->length; + max= de->length; de++; } return(max); @@ -1136,8 +1136,8 @@ cl_uc::get_name(t_addr addr, struct name_entry tab[], char *buf) i= 0; while (tab[i].name && - (!(tab[i].cpu_type & type) || - (tab[i].addr != addr))) + (!(tab[i].cpu_type & type) || + (tab[i].addr != addr))) i++; if (tab[i].name) strcpy(buf, tab[i].name); @@ -1146,7 +1146,7 @@ cl_uc::get_name(t_addr addr, struct name_entry tab[], char *buf) bool cl_uc::symbol2address(char *sym, struct name_entry tab[], - t_addr *addr) + t_addr *addr) { int i; @@ -1155,13 +1155,13 @@ cl_uc::symbol2address(char *sym, struct name_entry tab[], return(DD_FALSE); i= 0; while (tab[i].name && - (!(tab[i].cpu_type & type) || - strcasecmp(sym, tab[i].name) != 0)) + (!(tab[i].cpu_type & type) || + strcasecmp(sym, tab[i].name) != 0)) i++; if (tab[i].name) { if (addr) - *addr= tab[i].addr; + *addr= tab[i].addr; return(DD_TRUE); } return(DD_FALSE); @@ -1169,16 +1169,16 @@ cl_uc::symbol2address(char *sym, struct name_entry tab[], char * cl_uc::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) { char *sym_name= 0; int i; i= 0; while (bit_tbl()[i].name && - (bit_tbl()[i].addr != bit_address)) + (bit_tbl()[i].addr != bit_address)) i++; if (bit_tbl()[i].name) { @@ -1192,12 +1192,12 @@ cl_uc::symbolic_bit_name(t_addr bit_address, { i= 0; while (sfr_tbl()[i].name && - (sfr_tbl()[i].addr != mem_addr)) - i++; + (sfr_tbl()[i].addr != mem_addr)) + i++; if (sfr_tbl()[i].name) - sym_name= strdup(sfr_tbl()[i].name); + sym_name= strdup(sfr_tbl()[i].name); else - sym_name= 0; + sym_name= 0; } if (!sym_name) { @@ -1230,15 +1230,15 @@ cl_uc::handle_event(class cl_event &event) { case ev_address_space_added: { - try { - class cl_event_address_space_added &e= - dynamic_cast(event); - address_space_added(e.as); - e.handle(); - } - catch (...) - { break; } - break; + try { + class cl_event_address_space_added &e= + dynamic_cast(event); + address_space_added(e.as); + e.handle(); + } + catch (...) + { break; } + break; } default: return(pass_event_down(event)); @@ -1260,8 +1260,8 @@ cl_uc::mem_cell_changed(class cl_address_space *mem, t_addr addr) { int i; for (i= 0; i < mems->count; i++) - { - } + { + } } } */ @@ -1298,25 +1298,25 @@ cl_uc::check_errors(void) if (c) { for (i= 0; i < errors->count; i++) - { - class cl_error *error= (class cl_error *)(errors->at(i)); - if (!error->is_on()) - continue; - error->print(c); - must_stop= must_stop || (error->get_type() & err_stop); - if (error->inst) - { - class cl_console *con; - con= c->actual_console; - if (!con) - con= c->frozen_console; - if (con) - { - con->dd_printf("Erronouse instruction: "); - print_disass(error->PC, con); - } - } - } + { + class cl_error *error= (class cl_error *)(errors->at(i)); + if (!error->is_on()) + continue; + error->print(c); + must_stop= must_stop || (error->get_type() & err_stop); + if (error->inst) + { + class cl_console *con; + con= c->actual_console; + if (!con) + con= c->frozen_console; + if (con) + { + con->dd_printf("Erronouse instruction: "); + print_disass(error->PC, con); + } + } + } errors->free_all(); } else @@ -1356,7 +1356,7 @@ cl_uc::tick_hw(int cycles) { hw= (class cl_hw *)(hws->at(i)); if (hw->flags & HWF_INSIDE) - hw->tick(cycles); + hw->tick(cycles); } do_extra_hw(cycles); return(0); @@ -1383,11 +1383,11 @@ cl_uc::tick(int cycles) { class cl_ticker *t= (class cl_ticker *)(counters->at(i)); if (t) - { - if ((t->options&TICK_INISR) || - il->level < 0) - t->tick(cycles * cpc); - } + { + if ((t->options&TICK_INISR) || + il->level < 0) + t->tick(cycles * cpc); + } } // tick for hardwares @@ -1414,9 +1414,9 @@ cl_uc::get_counter(char *nam) { class cl_ticker *t= (class cl_ticker *)(counters->at(i)); if (t && - t->get_name() && - strcmp(t->get_name(), nam) == 0) - return(t); + t->get_name() && + strcmp(t->get_name(), nam) == 0) + return(t); } return(0); } @@ -1440,10 +1440,10 @@ cl_uc::add_counter(class cl_ticker *ticker, char */*nam*/) { class cl_ticker *t= (class cl_ticker *)(counters->at(i)); if (!t) - { - counters->put_at(i, ticker); - return; - } + { + counters->put_at(i, ticker); + return; + } } counters->add(ticker); } @@ -1471,13 +1471,13 @@ cl_uc::del_counter(char *nam) { class cl_ticker *t= (class cl_ticker *)(counters->at(i)); if (t && - t->get_name() && - strcmp(t->get_name(), nam) == 0) - { - delete t; - counters->put_at(i, 0); - return; - } + t->get_name() && + strcmp(t->get_name(), nam) == 0) + { + delete t; + counters->put_at(i, 0); + return; + } } } @@ -1515,13 +1515,13 @@ cl_uc::fetch(t_mem *code) rom) { if (rom->get_cell_flag(PC, CELL_FETCH_BRK) && - (brk= fbrk->get_bp(PC, &idx)) && - (brk->do_hit())) - { - if (brk->perm == brkDYNAMIC) - fbrk->del_bp(PC); - return(1); - } + (brk= fbrk->get_bp(PC, &idx)) && + (brk->do_hit())) + { + if (brk->perm == brkDYNAMIC) + fbrk->del_bp(PC); + return(1); + } } *code= fetch(); return(0); @@ -1535,7 +1535,7 @@ cl_uc::do_inst(int step) if (step < 0) step= 1; while (step-- && - res == resGO) + res == resGO) { pre_inst(); res= exec_inst(); @@ -1604,7 +1604,7 @@ cl_uc::stack_write(class cl_stack_op *op) if (op->get_op() & stack_read_operation) { class cl_error_stack_tracker_wrong_handle *e= new - cl_error_stack_tracker_wrong_handle(DD_FALSE); + cl_error_stack_tracker_wrong_handle(DD_FALSE); //fprintf(stderr, "%06"_A_"x cl_uc::stack_read() should be called for " //"%s\n", op->get_pc(), op->get_op_name()); e->init(); @@ -1622,7 +1622,7 @@ cl_uc::stack_read(class cl_stack_op *op) if (op->get_op() & stack_write_operation) { class cl_error_stack_tracker_wrong_handle *e= new - cl_error_stack_tracker_wrong_handle(DD_TRUE); + cl_error_stack_tracker_wrong_handle(DD_TRUE); e->init(); error(e); //fprintf(stderr, "%06"_A_"x cl_uc::stack_write() should be called for " @@ -1633,8 +1633,8 @@ cl_uc::stack_read(class cl_stack_op *op) { class cl_error *e= new cl_error_stack_tracker_empty(op); /*printf("0x%06"_A_"x %s operation on stack but no operation was before\n - ", - op->get_pc(), op->get_op_name());*/ + ", + op->get_pc(), op->get_op_name());*/ e->init(); error(e); return; @@ -1643,25 +1643,25 @@ cl_uc::stack_read(class cl_stack_op *op) if (top) { if (!top->match(op)) - { - class cl_error *e= new cl_error_stack_tracker_unmatch(top, op); - e->init(); - error(e); - /*printf("0x%06"_A_"x %s operation on stack but last was %s\n", - op->get_pc(), op->get_op_name(), top->get_op_name());*/ - } + { + class cl_error *e= new cl_error_stack_tracker_unmatch(top, op); + e->init(); + error(e); + /*printf("0x%06"_A_"x %s operation on stack but last was %s\n", + op->get_pc(), op->get_op_name(), top->get_op_name());*/ + } int top_size= top->data_size(), op_size= op->data_size(); if (top_size != op_size) - { - application->debug("0x%06"_A_"x %d bytes to read out of stack " - "but %d was pushed in last operation\n", - op->get_pc(), op_size, top_size); - } + { + application->debug("0x%06"_A_"x %d bytes to read out of stack " + "but %d was pushed in last operation\n", + op->get_pc(), op_size, top_size); + } } int removed= 0; while (top && - top->can_removed(op)) + top->can_removed(op)) { top= (class cl_stack_op *)stack_ops->pop(); delete top; @@ -1671,28 +1671,28 @@ cl_uc::stack_read(class cl_stack_op *op) if (removed != 1) { application->debug("0x%06"_A_"x %d ops removed from stack-tracker " - "when %s happened, top pc=0x%06"_A_"x " - "top before=0x%06"_A_"x op after=0x%06"_A_"x\n", - op->get_pc(), removed, op->get_op_name(), - top?(top->get_pc()):0, top?(top->get_before()):0, - op->get_after()); + "when %s happened, top pc=0x%06"_A_"x " + "top before=0x%06"_A_"x op after=0x%06"_A_"x\n", + op->get_pc(), removed, op->get_op_name(), + top?(top->get_pc()):0, top?(top->get_before()):0, + op->get_after()); } if (top) { int ta= top->get_after(), oa= op->get_after(); if (ta != oa) - { - application->debug("0x%06"_A_"x stack still inconsistent after %s, " - "%d byte(s) should be read out; top after" - "=0x%06"_A_"x op after=0x%06"_A_"x\n", - op->get_pc(), op->get_op_name(), abs(ta-oa), - ta, oa); - class cl_error *e= - new cl_error_stack_tracker_inconsistent(op, abs(ta-oa)); - e->init(); - error(e); - } + { + application->debug("0x%06"_A_"x stack still inconsistent after %s, " + "%d byte(s) should be read out; top after" + "=0x%06"_A_"x op after=0x%06"_A_"x\n", + op->get_pc(), op->get_op_name(), abs(ta-oa), + ta, oa); + class cl_error *e= + new cl_error_stack_tracker_inconsistent(op, abs(ta-oa)); + e->init(); + error(e); + } } delete op; @@ -1721,8 +1721,8 @@ cl_uc::ebrk_at(t_addr addr, char *id) { eb= (class cl_ev_brk *)(ebrk->at(i)); if (eb->addr == addr && - !strcmp(eb->id, id)) - return(eb); + !strcmp(eb->id, id)) + return(eb); } return(0); } @@ -1771,8 +1771,8 @@ cl_uc::rm_ebrk(t_addr addr, char *id) { eb= (class cl_ev_brk *)(ebrk->at(i)); if (eb->addr == addr && - !strcmp(eb->id, id)) - ebrk->del_bp(i, 0); + !strcmp(eb->id, id)) + ebrk->del_bp(i, 0); } } @@ -1827,7 +1827,7 @@ cl_uc::make_new_brknr(void) class cl_ev_brk * cl_uc::mk_ebrk(enum brk_perm perm, class cl_address_space *mem, - char op, t_addr addr, int hit) + char op, t_addr addr, int hit) { class cl_ev_brk *b; op= toupper(op); @@ -1844,7 +1844,7 @@ cl_uc::check_events(void) for (i= 0; i < events->count; i++) { class cl_ev_brk *brk= - dynamic_cast(events->object_at(i)); + dynamic_cast(events->object_at(i)); sim->stop(brk); } sim->stop(resBREAKPOINT); @@ -1865,18 +1865,17 @@ cl_error_unknown_code::cl_error_unknown_code(class cl_uc *the_uc) void cl_error_unknown_code::print(class cl_commander *c) { - FILE *f= c->get_out(); - cmd_fprintf(f, "%s: unknown instruction code at ", get_type_name()); + c->dd_printf("%s: unknown instruction code at ", get_type_name()); if (uc->rom) { - cmd_fprintf(f, uc->rom->addr_format, PC); - cmd_fprintf(f, " ("); - cmd_fprintf(f, uc->rom->data_format, uc->rom->get(PC)); - cmd_fprintf(f, ")"); + c->dd_printf(uc->rom->addr_format, PC); + c->dd_printf(" ("); + c->dd_printf(uc->rom->data_format, uc->rom->get(PC)); + c->dd_printf(")"); } else - cmd_fprintf(f, "0x%06x", PC); - cmd_fprintf(f, "\n"); + c->dd_printf("0x%06x", PC); + c->dd_printf("\n"); } cl_uc_error_registry::cl_uc_error_registry(void) -- 2.30.2