Commit d1d3351f authored by Alexander Shabarshin's avatar Alexander Shabarshin

more statistics

parent 494fac7e
/* Modified by Shaos <me@shaos.net>
21-NOV-2018 - Some statistics added in DEBUG_EXTRA mode
20-NOV-2018 - By default RV32M and RV32A extensions are disabled (STRICT_RV32I)
18-NOV-2018 - Slghtly modified for pure C
Source code taken from https://gist.github.com/FrankBuss/c974e59826d33e21d7cad54491ab50e8
......@@ -96,16 +97,22 @@ original copyright:
#define TRUE (-1)
#ifdef DEBUG_EXTRA
uint32_t minmemr,maxmemr,minmemw,maxmemw;
int stats[64];
void init_stats(void)
{
for(int i=0;i<64;i++) stats[i]=0;
minmemr = minmemw = ~0;
maxmemr = maxmemw = 0;
}
void print_stats(void)
{
for(int i=0;i<64;i++) if(stats[i]) printf("stats[%i] = %i\n",i,stats[i]);
printf("Memory Reading Area %x...%x\n",minmemr,maxmemr);
printf("Memory Writing Area %x...%x\n",minmemw,maxmemw);
}
#endif
......@@ -666,6 +673,10 @@ int raise_interrupt()
uint32_t get_insn32(uint32_t pc)
{
#ifdef DEBUG_EXTRA
if(pc && pc < minmemr) minmemr = pc;
if(pc+3 > maxmemr) maxmemr = pc+3;
#endif
uint32_t ptr = pc - ram_start;
if (ptr > RAM_SIZE) return 1;
uint8_t* p = ram + ptr;
......@@ -676,6 +687,10 @@ uint32_t get_insn32(uint32_t pc)
int target_read_u8(uint8_t *pval, uint32_t addr)
{
#ifdef DEBUG_EXTRA
if((addr>>28)!=4 && addr < minmemr) minmemr = addr;
if(addr > maxmemr) maxmemr = addr;
#endif
addr -= ram_start;
if (addr > RAM_SIZE) {
*pval = 0;
......@@ -692,6 +707,10 @@ int target_read_u8(uint8_t *pval, uint32_t addr)
int target_read_u16(uint16_t *pval, uint32_t addr)
{
#ifdef DEBUG_EXTRA
if((addr>>28)!=4 && addr < minmemr) minmemr = addr;
if(addr+1 > maxmemr) maxmemr = addr+1;
#endif
if (addr & 1) {
pending_exception = CAUSE_MISALIGNED_LOAD;
pending_tval = addr;
......@@ -713,6 +732,10 @@ int target_read_u16(uint16_t *pval, uint32_t addr)
int target_read_u32(uint32_t *pval, uint32_t addr)
{
#ifdef DEBUG_EXTRA
if((addr>>28)!=4 && addr < minmemr) minmemr = addr;
if(addr+3 > maxmemr) maxmemr = addr+3;
#endif
if (addr & 3) {
pending_exception = CAUSE_MISALIGNED_LOAD;
pending_tval = addr;
......@@ -744,6 +767,10 @@ int target_read_u32(uint32_t *pval, uint32_t addr)
int target_write_u8(uint32_t addr, uint8_t val)
{
#ifdef DEBUG_EXTRA
if((addr>>28)!=4 && addr < minmemw) minmemw = addr;
if(addr > maxmemw) maxmemw = addr;
#endif
if (addr == UART_TX_ADDR) {
/* test for UART output, compatible with QEMU */
printf("%c", val);
......@@ -764,6 +791,10 @@ int target_write_u8(uint32_t addr, uint8_t val)
int target_write_u16(uint32_t addr, uint16_t val)
{
#ifdef DEBUG_EXTRA
if((addr>>28)!=4 && addr < minmemw) minmemw = addr;
if(addr+1 > maxmemw) maxmemw = addr+1;
#endif
if (addr & 1) {
pending_exception = CAUSE_MISALIGNED_STORE;
pending_tval = addr;
......@@ -785,6 +816,10 @@ int target_write_u16(uint32_t addr, uint16_t val)
int target_write_u32(uint32_t addr, uint32_t val)
{
#ifdef DEBUG_EXTRA
if((addr>>28)!=4 && addr < minmemw) minmemw = addr;
if(addr+3 > maxmemw) maxmemw = addr+3;
#endif
if (addr & 3) {
pending_exception = CAUSE_MISALIGNED_STORE;
pending_tval = addr;
......
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