Commit 51ffd195 authored by Alexander Shabarshin's avatar Alexander Shabarshin

added saving to hex

parent 3f96d4f9
/* Modified by Shaos <me@shaos.net> /* Modified by Shaos <me@shaos.net>
22-NOV-2018 - Added saving HEX file with copy of the code in DEBUG_OUTPUT mode
21-NOV-2018 - Some statistics added in DEBUG_EXTRA mode 21-NOV-2018 - Some statistics added in DEBUG_EXTRA mode
20-NOV-2018 - By default RV32M and RV32A extensions are disabled (STRICT_RV32I) 20-NOV-2018 - By default RV32M and RV32A extensions are disabled (STRICT_RV32I)
18-NOV-2018 - Slghtly modified for pure C 18-NOV-2018 - Slghtly modified for pure C
...@@ -139,6 +140,10 @@ uint64_t mtimecmp; ...@@ -139,6 +140,10 @@ uint64_t mtimecmp;
/* virtual start address for index 0 in the ram array */ /* virtual start address for index 0 in the ram array */
uint32_t ram_start; uint32_t ram_start;
/* last byte of the memory initialized and temporary value */
uint32_t ram_last = 0;
uint32_t ram_curr = 0;
/* used when called from the compliance tests */ /* used when called from the compliance tests */
uint32_t begin_signature = 0; uint32_t begin_signature = 0;
uint32_t end_signature = 0; uint32_t end_signature = 0;
...@@ -1807,6 +1812,11 @@ void riscv_cpu_interp_x32() ...@@ -1807,6 +1812,11 @@ void riscv_cpu_interp_x32()
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
#ifdef DEBUG_OUTPUT
FILE *fo;
char *po,hex_file[100];
#endif
/* automatic STDOUT flushing, no fflush needed */ /* automatic STDOUT flushing, no fflush needed */
setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0);
...@@ -1830,6 +1840,8 @@ int main(int argc, char** argv) ...@@ -1830,6 +1840,8 @@ int main(int argc, char** argv)
init_stats(); init_stats();
#endif #endif
for(uint32_t u=0;u<RAM_SIZE;u++) ram[u]=0;
/* open ELF file */ /* open ELF file */
elf_version(EV_CURRENT); elf_version(EV_CURRENT);
int fd = open(elf_file, O_RDONLY); int fd = open(elf_file, O_RDONLY);
...@@ -1889,7 +1901,19 @@ int main(int argc, char** argv) ...@@ -1889,7 +1901,19 @@ int main(int argc, char** argv)
Elf_Data *data = elf_getdata(scn, NULL); Elf_Data *data = elf_getdata(scn, NULL);
if (shdr.sh_addr >= ram_start) { if (shdr.sh_addr >= ram_start) {
for (size_t i = 0; i < shdr.sh_size; i++) { for (size_t i = 0; i < shdr.sh_size; i++) {
ram[shdr.sh_addr + i - ram_start] = ((uint8_t *)data->d_buf)[i]; ram_curr = shdr.sh_addr + i - ram_start;
if(ram_curr >= RAM_SIZE)
{
#ifdef DEBUG_OUTPUT
printf("memory pointer outside of range 0x%08x (section at address 0x%08x)\n", ram_curr, (uint32_t) shdr.sh_addr);
#endif
/* break; */
}
else
{
ram[ram_curr] = ((uint8_t *)data->d_buf)[i];
if(ram_curr > ram_last) ram_last = ram_curr;
}
} }
} else { } else {
#ifdef DEBUG_OUTPUT #ifdef DEBUG_OUTPUT
...@@ -1903,6 +1927,25 @@ int main(int argc, char** argv) ...@@ -1903,6 +1927,25 @@ int main(int argc, char** argv)
elf_end(elf); elf_end(elf);
close(fd); close(fd);
#ifdef DEBUG_OUTPUT
printf("codesize: 0x%08x (%i)\n", ram_last+1, ram_last+1);
strcpy(hex_file, elf_file);
po = strrchr(hex_file,'.');
if(po!=NULL) *po = 0;
strcat(hex_file,".mem");
fo = fopen(hex_file,"wt");
if(fo!=NULL)
{
for(uint32_t u=0;u<=ram_last;u++)
{
fprintf(fo,"%02X ",ram[u]);
if((u&15)==15) fprintf(fo,"\n");
}
fprintf(fo,"\n");
fclose(fo);
}
#endif
/* run program in emulator */ /* run program in emulator */
pc = ram_start; pc = ram_start;
riscv_cpu_interp_x32(); riscv_cpu_interp_x32();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment