Line 28... |
Line 28... |
#include "coff.h"
|
#include "coff.h"
|
#include "debug_unit.h"
|
#include "debug_unit.h"
|
#include "opcode/or32.h"
|
#include "opcode/or32.h"
|
#include "parse.h"
|
#include "parse.h"
|
|
|
|
#define MEMORY_LEN 0x100000000
|
#define MAXLINE_LEN 18000
|
#define MAXLINE_LEN 18000
|
|
|
extern char *disassembled;
|
extern char *disassembled;
|
|
|
/* Unused mem memory marker. It is used when allocating program and data memory
|
/* Unused mem memory marker. It is used when allocating program and data memory
|
Line 101... |
Line 102... |
if (transl_table == 0)
|
if (transl_table == 0)
|
return laddr;
|
return laddr;
|
|
|
/* Try to find our translation in the table. */
|
/* Try to find our translation in the table. */
|
for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
|
for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
|
if ((laddr & ~(PAGE_SIZE - 1)) == evalsim_mem32(transl_table + i,breakpoint)) {
|
if ((laddr & ~(PAGE_SIZE - 1)) == evalsim_mem32(transl_table + i)) {
|
setsim_mem32(transl_table + i + 8, -2); /* Page modified */
|
setsim_mem32(transl_table + i + 8, -2); /* Page modified */
|
printf("found paddr=%x\n", evalsim_mem32(transl_table + i + 4,breakpoint) | (laddr & (PAGE_SIZE - 1)));
|
printf("found paddr=%x\n", evalsim_mem32(transl_table + i + 4) | (laddr & (PAGE_SIZE - 1)));
|
return (unsigned long)evalsim_mem32(transl_table + i + 4,breakpoint) | (laddr & (unsigned long)(PAGE_SIZE - 1));
|
return (unsigned long)evalsim_mem32(transl_table + i + 4) | (laddr & (unsigned long)(PAGE_SIZE - 1));
|
}
|
}
|
|
|
/* Allocate new phy page for us. */
|
/* Allocate new phy page for us. */
|
for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
|
for(i = 0; i < (MEMORY_LEN / PAGE_SIZE) * 16; i += 16)
|
if (evalsim_mem32(transl_table + i + 8,breakpoint) == 0) {
|
if (evalsim_mem32(transl_table + i + 8) == 0) {
|
setsim_mem32(transl_table + i, laddr & ~(PAGE_SIZE - 1)); /* VPN */
|
setsim_mem32(transl_table + i, laddr & ~(PAGE_SIZE - 1)); /* VPN */
|
setsim_mem32(transl_table + i + 4, (i/16) * PAGE_SIZE); /* PPN */
|
setsim_mem32(transl_table + i + 4, (i/16) * PAGE_SIZE); /* PPN */
|
setsim_mem32(transl_table + i + 8, -2); /* Page modified */
|
setsim_mem32(transl_table + i + 8, -2); /* Page modified */
|
printf("newly allocated ppn=%x\n", (unsigned long)evalsim_mem32(transl_table + i + 4,breakpoint));
|
printf("newly allocated ppn=%x\n", (unsigned long)evalsim_mem32(transl_table + i + 4));
|
printf("newly allocated .ppn=%x\n", (unsigned long)transl_table + i + 4);
|
printf("newly allocated .ppn=%x\n", (unsigned long)transl_table + i + 4);
|
printf("newly allocated ofs=%x\n", (unsigned long)(laddr & (PAGE_SIZE - 1)));
|
printf("newly allocated ofs=%x\n", (unsigned long)(laddr & (PAGE_SIZE - 1)));
|
printf("newly allocated paddr=%x\n", (unsigned long)evalsim_mem32(transl_table + i + 4,breakpoint) | (laddr & (PAGE_SIZE - 1)));
|
printf("newly allocated paddr=%x\n", (unsigned long)evalsim_mem32(transl_table + i + 4) | (laddr & (PAGE_SIZE - 1)));
|
return (unsigned long)evalsim_mem32(transl_table + i + 4,breakpoint) | (laddr & (unsigned long)(PAGE_SIZE - 1));
|
return (unsigned long)evalsim_mem32(transl_table + i + 4) | (laddr & (unsigned long)(PAGE_SIZE - 1));
|
}
|
}
|
/* If we come this far then all phy memory is used and we can't find our page
|
/* If we come this far then all phy memory is used and we can't find our page
|
nor allocate new page. */
|
nor allocate new page. */
|
transl_error = 1;
|
transl_error = 1;
|
|
|
Line 138... |
Line 139... |
return;
|
return;
|
|
|
for(; *str && *str != '\"'; str++, translate(freemem++,breakpoint))
|
for(; *str && *str != '\"'; str++, translate(freemem++,breakpoint))
|
if (*str == '\\')
|
if (*str == '\\')
|
switch (*++str) {
|
switch (*++str) {
|
case 'n': mem[translate(freemem,breakpoint)].data = '\n';
|
case 'n': setsim_mem8(translate(freemem,breakpoint), '\n');
|
break;
|
break;
|
case 't': mem[translate(freemem,breakpoint)].data = '\t';
|
case 't': setsim_mem8(translate(freemem,breakpoint), '\t');
|
break;
|
break;
|
case 'r': mem[translate(freemem,breakpoint)].data = '\r';
|
case 'r': setsim_mem8(translate(freemem,breakpoint), '\r');
|
break;
|
break;
|
case '0': mem[translate(freemem,breakpoint)].data = '\0';
|
case '0': setsim_mem8(translate(freemem,breakpoint), '\0');
|
break;
|
break;
|
default: break;
|
default: break;
|
}
|
}
|
else
|
else
|
mem[translate(freemem,breakpoint)].data = *str;
|
setsim_mem8(translate(freemem,breakpoint), *str);
|
}
|
}
|
|
|
/* Modified by CZ 26/05/01 */
|
/* Modified by CZ 26/05/01 */
|
/* Added code for new mode operation */
|
/* Added code for new mode operation */
|
void adddataword(char *item,int* breakpoint)
|
void adddataword(char *item,int* breakpoint)
|
Line 164... |
Line 165... |
num = strtoul(item, NULL, 0);
|
num = strtoul(item, NULL, 0);
|
else
|
else
|
num = eval_label(item);
|
num = eval_label(item);
|
|
|
debug("adddataword: [0x%x] <= %x\n", translate(freemem,breakpoint), num);
|
debug("adddataword: [0x%x] <= %x\n", translate(freemem,breakpoint), num);
|
mem[translate(freemem,breakpoint)].data = (char) (num >> 24);
|
setsim_mem32(translate(freemem,breakpoint), num);
|
mem[translate(freemem + 1,breakpoint)].data = (char) (num >> 16);
|
|
mem[translate(freemem + 2,breakpoint)].data = (char) (num >> 8);
|
|
mem[translate(freemem + 3,breakpoint)].data = (char) (num);
|
|
|
|
if(!GlobalMode)
|
if(!GlobalMode)
|
freemem += 4;
|
freemem += 4;
|
}
|
}
|
|
|
Line 182... |
Line 180... |
if (isdigit(*item))
|
if (isdigit(*item))
|
num = strtoul(item, NULL, 0);
|
num = strtoul(item, NULL, 0);
|
else
|
else
|
num = eval_label(item);
|
num = eval_label(item);
|
|
|
mem[translate(freemem,breakpoint)].data = (char) (num >> 8);
|
setsim_mem16(translate(freemem,breakpoint), num);
|
mem[translate(freemem + 1,breakpoint)].data = (char) (num);
|
|
|
|
freemem += 2;
|
freemem += 2;
|
}
|
}
|
|
|
void adddatabyte(char *item,int* breakpoint)
|
void adddatabyte(char *item,int* breakpoint)
|
Line 197... |
Line 194... |
if (isdigit(*item))
|
if (isdigit(*item))
|
num = strtoul(item, NULL, 0);
|
num = strtoul(item, NULL, 0);
|
else
|
else
|
num = eval_label(item);
|
num = eval_label(item);
|
|
|
mem[translate(freemem,breakpoint)].data = (char) (num);
|
setsim_mem8(translate(freemem,breakpoint),num);
|
|
|
freemem++;
|
freemem++;
|
}
|
}
|
|
|
void adddataspace(char *num)
|
void adddataspace(char *num)
|
Line 210... |
Line 207... |
}
|
}
|
|
|
void addlabel(char *label, unsigned long freemem,int* breakpoint)
|
void addlabel(char *label, unsigned long freemem,int* breakpoint)
|
{
|
{
|
struct label_entry **tmp;
|
struct label_entry **tmp;
|
|
struct mem_entry *entry;
|
debug("Adding label %s at 0x%x\n", label, translate(freemem,breakpoint));
|
debug("Adding label %s at 0x%x\n", label, translate(freemem,breakpoint));
|
tmp = &mem[translate(freemem,breakpoint)].label;
|
if(!verify_memoryarea(freemem) || !cur_area->getentry) return;
|
|
|
|
entry = cur_area->getentry(translate(freemem,breakpoint));
|
|
tmp = &(entry->label);
|
for (; *tmp; tmp = &((*tmp)->next));
|
for (; *tmp; tmp = &((*tmp)->next));
|
*tmp = malloc(sizeof(**tmp));
|
*tmp = malloc(sizeof(**tmp));
|
(*tmp)->name = malloc(strlen(label)+1);
|
(*tmp)->name = malloc(strlen(label)+1);
|
strcpy((*tmp)->name, label);
|
strcpy((*tmp)->name, label);
|
(*tmp)->next = NULL;
|
(*tmp)->next = NULL;
|
Line 296... |
Line 296... |
printf(" vaddr: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_vaddr));
|
printf(" vaddr: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_vaddr));
|
printf(" size: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_size));
|
printf(" size: 0x%.8x,", COFF_LONG_H(coffscnhdr.s_size));
|
printf(" scnptr: 0x%.8x\n", COFF_LONG_H(coffscnhdr.s_scnptr));
|
printf(" scnptr: 0x%.8x\n", COFF_LONG_H(coffscnhdr.s_scnptr));
|
|
|
sectsize = COFF_LONG_H(coffscnhdr.s_size);
|
sectsize = COFF_LONG_H(coffscnhdr.s_size);
|
|
#if 0
|
/* A couple of sanity checks. */
|
/* A couple of sanity checks. */
|
if (translate(COFF_LONG_H(coffscnhdr.s_vaddr),&breakpoint) < MEMORY_START) {
|
if (translate(COFF_LONG_H(coffscnhdr.s_vaddr),&breakpoint) < MEMORY_START) {
|
printf("Section %s starts out of ", coffscnhdr.s_name);
|
printf("Section %s starts out of ", coffscnhdr.s_name);
|
printf("memory (at %x)\n", COFF_LONG_H(coffscnhdr.s_vaddr));
|
printf("memory (at %x)\n", COFF_LONG_H(coffscnhdr.s_vaddr));
|
exit(1);
|
exit(1);
|
Line 308... |
Line 309... |
MEMORY_START + MEMORY_LEN) {
|
MEMORY_START + MEMORY_LEN) {
|
printf("Section %s ends out of ", coffscnhdr.s_name);
|
printf("Section %s ends out of ", coffscnhdr.s_name);
|
printf("memory.\n");
|
printf("memory.\n");
|
exit(1);
|
exit(1);
|
}
|
}
|
|
#endif
|
#if 0
|
#if 0
|
if (++firstthree == 1 && strcmp(coffscnhdr.s_name, ".text") != 0) {
|
if (++firstthree == 1 && strcmp(coffscnhdr.s_name, ".text") != 0) {
|
printf("First section should be .text (%s instead)\n", coffscnhdr.s_name);
|
printf("First section should be .text (%s instead)\n", coffscnhdr.s_name);
|
exit(1);
|
exit(1);
|
}
|
}
|