diff -Naur sim/superH/AUTHOR sim.old/superH/AUTHOR --- sim/superH/AUTHOR Sat Dec 8 18:49:39 2001 +++ sim.old/superH/AUTHOR Sat Dec 8 18:31:27 2001 @@ -1,2 +1,2 @@ Authors: - Phillip Stanley-Marbell + Phillip Stanley-Marbell diff -Naur sim/superH/Makefile sim.old/superH/Makefile --- sim/superH/Makefile Sat Dec 8 18:48:33 2001 +++ sim.old/superH/Makefile Sat Dec 8 18:31:27 2001 @@ -7,7 +7,7 @@ include ../../conf/setup.conf TARGET = sim -BIN = $(HOME)/bin +BIN = /home/pip/bin LD = ld CC = gcc @@ -16,7 +16,8 @@ CCFLAGS = -DeEK32 -DDEBUG=0 -DSAFE=1 -DCHATTY=0 -DNETWORK=1 -DMOBILITY=0 -DSIMLOG=0 -DBITFLIP_ANALYSIS=0 -DPOWER_ANALYSIS=1 -DL_ENDIAN WFLAGS = -Wall -Winline -Wmissing-prototypes -Werror INCLUDES= -I/usr/local/include -I$(ROOT)/sys/include -LDFLAGS = -L/usr/local/lib -lm +LDFLAGS = ##-lbfd -liberty_p -lc_r_p -lm_p +LDFLAGS = -L/usr/local/lib -lbfd -liberty -lm ##-L/usr/local/lib -lefence OPTFLAGS= -O6 -funroll-loops -finline-functions -fomit-frame-pointer DBGFLAGS= ##-pg DEL = rm -f diff -Naur sim/superH/main.c sim.old/superH/main.c --- sim/superH/main.c Sat Dec 8 18:32:57 2001 +++ sim.old/superH/main.c Sat Dec 8 18:31:27 2001 @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -336,155 +337,77 @@ void load_srec(State *S, char *filename) { - char buf[MAX_SREC_LINELEN], ch; - int fd, i; - ulong rec_addr; - int pcset, rec_type, rec_length; - char *line; + asection *p = NULL; + char **matching = NULL; - if ((fd = open(filename, O_RDONLY)) < 0) + bfd *simbfd = malloc(sizeof(bfd)); + if (simbfd == NULL) { - fprintf(stdout, "open failed... : fd = %d\n", fd); - + error("Could not allocate memory for simbfd."); return; } - pcset = 0; - for (;;) - { - i = 0; - - do - { - if (read(fd, &ch, 1) == 0) - { - goto done; - } - - buf[i++] = ch; - } while (ch != '\n'); - - line = &buf[0]; - rec_type = line[1] - '0'; - switch (rec_type) - { - case 0: - { - /* Optional starting record. Skip */ - break; - } - - case 1: - { - /* Data record with 16bit address */ - break; - } - - case 2: - { - /* Data record with 24bit address */ - break; - } - - /* */ - /* BUG: We do not verify checksum on SREC records */ - /* */ - case 3: - { - /* Data record with 32bit address */ - int i; - char *tptr, tmp[8]; - - memmove(&tmp[0], &line[2], 2); - tmp[2] = '\0'; - rec_length = strtoul(&tmp[0], nil, 16); - - memmove(&tmp[0], &line[4], 8); - tmp[8] = '\0'; - rec_addr = strtoul(&tmp[0], nil, 16); - - /* Sanity check */ - if ((rec_addr < MEMBASE) || (rec_addr > MEMBASE+MEMSIZE)) - { - fprintf(stdout, "Address in SREC is out of range.\n"); - fprintf(stdout, "Aborting SRECL.\n"); - - return; - } - - if (!pcset) - { - S->PC = rec_addr; - fprintf(stdout, "Loading S-RECORD to memory at address 0x%lx\n", rec_addr); - pcset = 1; - } - else - { - fprintf(stdout, "."); - } - - /* rec_length includes length of addr and chksum */ - rec_length -= 5; + bfd_init(); - tptr = &line[12]; - for (i = 0; i < rec_length; i++) - { - memmove(&tmp[0], tptr, 2); - tmp[2] = '\0'; - tptr += 2; + /* Let BFD figure out the format */ + simbfd = bfd_openr(filename, "default"); - S->MEM[(rec_addr-MEMBASE)+i] = strtoul(&tmp[0], nil, 16); - } + /* Could open file ? */ + if (simbfd == NULL) + { + error("hmmm... bfd could not open file"); + return; + } - break; - } + /* Is it an object file ? */ + if (!bfd_check_format_matches (simbfd, bfd_object, &matching)) + { + error((char *)bfd_errmsg(bfd_get_error())); + return; + } - case 4: - { - /* Symbol record (LSI extension) */ - break; - } + fprintf(stderr, "\tFilename: %s\n\tFormat: %s\n",\ + bfd_get_filename(simbfd), simbfd->xvec->name); + fprintf(stderr, "\tStart Address: 0x%lx\n", simbfd->start_address); - case 5: - { - /* # records in preceding block */ - break; - } + /* Print names of all sections */ + for (p = simbfd->sections; p != NULL; p = p->next) + { - case 6: - { - /* Unused */ - break; - } + fprintf(stderr, "\tSections: \"%s\", size = 0x%lx, VMA = 0x%lx, LMA = 0x%lx\n",\ + p->name, p->_raw_size, p->vma, p->lma); + if (bfd_get_section_by_name(simbfd, p->name) == NULL) + { + fprintf(stderr, "could not get handle to section %s\n", p->name); + } + } - case 7: - { - /* End record for S3 records */ - break; - } + /* Load all sections */ + for (p = simbfd->sections; p != NULL; p = p->next) + { + fprintf(stderr, "Loading section \"%s\" at Memory Address 0x%lx...\n",\ + p->name, p->lma); - case 8: - { - /* End record for S2 records */ - break; - } + /* Does it fit */ + if ((p->_raw_size+(p->lma-MEMBASE)) >= MEMSIZE) + { + error("S-RECORD too big for our memory size"); + continue; + } - case 9: - { - /* End record for S1 records */ - break; - } - - default: - { - fprintf(stdout, "Seen unknown SRECORD type.\n"); - fprintf(stdout, "Aborting SRECL.\n"); - } + if ((p->lma < MEMBASE) || (p->lma >= MEMBASE+MEMSIZE)) + { + error("Load address is out of range..."); + return; } + + bfd_get_section_contents(simbfd, bfd_get_section_by_name(simbfd, p->name),\ + &S->MEM[p->lma-MEMBASE], 0, p->_raw_size); } - -done: fprintf(stdout, "\n"); + + fprintf(stderr, "\tMEMBASE : 0x%x\n\tMEMSIZE : 0x%x\n", MEMBASE, MEMSIZE); + S->PC = simbfd->start_address; return; diff -Naur sim/superH/main.h sim.old/superH/main.h --- sim/superH/main.h Sat Dec 8 18:33:40 2001 +++ sim.old/superH/main.h Sat Dec 8 18:31:27 2001 @@ -53,7 +53,6 @@ MAXSIMNODES = 1024, /* Max number of simulated systems */ MAXNEIGHBORS = 128, DEFAULT_MISS_PENALTY = 100, - MAX_SREC_LINELEN = 1024, MAX_RUN_ARGS = 64, /* # of space-delim. args permitted for RUN command */ };