Line 38... |
Line 38... |
#include "arch.h"
|
#include "arch.h"
|
#include "abstract.h"
|
#include "abstract.h"
|
#include "sim-config.h"
|
#include "sim-config.h"
|
#include "debug.h"
|
#include "debug.h"
|
|
|
|
DEFAULT_DEBUG_CHANNEL(simprintf);
|
|
|
/* Length of PRINTF format string */
|
/* Length of PRINTF format string */
|
#define FMTLEN 2000
|
#define FMTLEN 2000
|
|
|
char fmtstr[FMTLEN];
|
char fmtstr[FMTLEN];
|
|
|
Line 68... |
Line 70... |
{
|
{
|
FILE *f;
|
FILE *f;
|
|
|
simgetstr(stackaddr, regparam);
|
simgetstr(stackaddr, regparam);
|
|
|
debug(6, "simprintf: stackaddr: 0x%"PRIxADDR"\n", stackaddr);
|
TRACE("simprintf: stackaddr: 0x%"PRIxADDR"\n", stackaddr);
|
if ((f = fopen(config.sim.fstdout, "a+"))) {
|
if ((f = fopen(config.sim.fstdout, "a+"))) {
|
uint32_t arg;
|
uint32_t arg;
|
oraddr_t argaddr;
|
oraddr_t argaddr;
|
char *fmtstrend;
|
char *fmtstrend;
|
char *fmtstrpart = fmtstr;
|
char *fmtstrpart = fmtstr;
|
Line 85... |
Line 87... |
#endif
|
#endif
|
tee_exe_log = (config.sim.exe_log && (config.sim.exe_log_type == EXE_LOG_SOFTWARE || config.sim.exe_log_type == EXE_LOG_SIMPLE)
|
tee_exe_log = (config.sim.exe_log && (config.sim.exe_log_type == EXE_LOG_SOFTWARE || config.sim.exe_log_type == EXE_LOG_SIMPLE)
|
&& config.sim.exe_log_start <= runtime.cpu.instructions && (config.sim.exe_log_end <= 0 || runtime.cpu.instructions <= config.sim.exe_log_end));
|
&& config.sim.exe_log_start <= runtime.cpu.instructions && (config.sim.exe_log_end <= 0 || runtime.cpu.instructions <= config.sim.exe_log_end));
|
|
|
if (tee_exe_log) fprintf (runtime.sim.fexe_log, "SIMPRINTF: ");
|
if (tee_exe_log) fprintf (runtime.sim.fexe_log, "SIMPRINTF: ");
|
debug(6, "simprintf: %s\n", fmtstrpart);
|
TRACE("simprintf: %s\n", fmtstrpart);
|
while(strlen(fmtstrpart)) {
|
while(strlen(fmtstrpart)) {
|
debug(6, "simprintf(): 1");
|
TRACE("simprintf(): 1");
|
if ((fmtstrend = strstr(fmtstrpart + 1, "%")))
|
if ((fmtstrend = strstr(fmtstrpart + 1, "%")))
|
*fmtstrend = '\0';
|
*fmtstrend = '\0';
|
debug(6," 2");
|
TRACE(" 2");
|
if (strstr(fmtstrpart, "%")) {
|
if (strstr(fmtstrpart, "%")) {
|
char *tmp;
|
char *tmp;
|
int string = 0;
|
int string = 0;
|
debug(6, " 3");
|
TRACE(" 3");
|
#if STACK_ARGS
|
#if STACK_ARGS
|
arg = eval_direct32(argaddr,1,0);
|
arg = eval_direct32(argaddr,1,0);
|
argaddr += 4;
|
argaddr += 4;
|
#else
|
#else
|
{
|
{
|
Line 106... |
Line 108... |
|
|
sprintf(regstr, "r%"PRIxADDR, ++argaddr);
|
sprintf(regstr, "r%"PRIxADDR, ++argaddr);
|
arg = evalsim_reg(atoi(regstr));
|
arg = evalsim_reg(atoi(regstr));
|
}
|
}
|
#endif
|
#endif
|
debug(6, " 4: fmtstrpart=%p fmtstrpart=%s arg=0x%08"PRIx32"\n",
|
TRACE(" 4: fmtstrpart=%p fmtstrpart=%s arg=0x%08"PRIx32"\n",
|
fmtstrpart, fmtstrpart, arg);
|
fmtstrpart, fmtstrpart, arg);
|
tmp = fmtstrpart;
|
tmp = fmtstrpart;
|
if (*tmp == '%') {
|
if (*tmp == '%') {
|
tmp++;
|
tmp++;
|
while (*tmp == '-' || *tmp >= '0' && *tmp <= '9') tmp++;
|
while (*tmp == '-' || *tmp >= '0' && *tmp <= '9') tmp++;
|
Line 125... |
Line 127... |
str = (char *)malloc(len);
|
str = (char *)malloc(len);
|
len = 0;
|
len = 0;
|
for(; eval_direct8(arg,1,0); len++)
|
for(; eval_direct8(arg,1,0); len++)
|
*(str+len) = eval_direct8(arg++,1,0);
|
*(str+len) = eval_direct8(arg++,1,0);
|
*(str+len) = eval_direct8(arg,1,0); /* null ch */
|
*(str+len) = eval_direct8(arg,1,0); /* null ch */
|
debug(6, "4a: len=%d str=%s\n", len, str);
|
TRACE("4a: len=%d str=%s\n", len, str);
|
debug(6, "4b:");
|
TRACE("4b:");
|
fprintf(f, fmtstrpart, str);
|
fprintf(f, fmtstrpart, str);
|
if (tee_exe_log) fprintf(runtime.sim.fexe_log, fmtstrpart, str);
|
if (tee_exe_log) fprintf(runtime.sim.fexe_log, fmtstrpart, str);
|
free(str);
|
free(str);
|
} else {
|
} else {
|
fprintf(f, fmtstrpart, arg);
|
fprintf(f, fmtstrpart, arg);
|
if (tee_exe_log) fprintf(runtime.sim.fexe_log, fmtstrpart, arg);
|
if (tee_exe_log) fprintf(runtime.sim.fexe_log, fmtstrpart, arg);
|
}
|
}
|
} else {
|
} else {
|
debug(6, " 5");
|
TRACE(" 5");
|
fprintf(f, fmtstrpart);
|
fprintf(f, fmtstrpart);
|
if (tee_exe_log) fprintf(runtime.sim.fexe_log, fmtstrpart);
|
if (tee_exe_log) fprintf(runtime.sim.fexe_log, fmtstrpart);
|
debug(6, fmtstrpart);
|
TRACE(fmtstrpart);
|
}
|
}
|
if (!fmtstrend)
|
if (!fmtstrend)
|
break;
|
break;
|
debug(6, " 6");
|
TRACE(" 6");
|
fmtstrpart = fmtstrend;
|
fmtstrpart = fmtstrend;
|
*fmtstrpart = '%';
|
*fmtstrpart = '%';
|
debug(6, " 7");
|
TRACE(" 7");
|
}
|
}
|
|
|
debug(6," 8\n");
|
TRACE(" 8\n");
|
if (fclose(f))
|
if (fclose(f))
|
perror(strerror(errno));
|
perror(strerror(errno));
|
}
|
}
|
else
|
else
|
perror(strerror(errno));
|
perror(strerror(errno));
|