URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [tags/] [nog_patch_59/] [or1ksim/] [support/] [simprintf.c] - Rev 7
Go to most recent revision | Compare with Previous | Blame | View Log
/* libc.c -- dummy C library simulation Copyright (C) 1999 Damjan Lampret, lampret@opencores.org This file is part of OpenRISC 1000 Architectural Simulator. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Debugger LIBC functions. Working, but VERY, VERY ugly written. I wrote following code when basic simulator started to work and I was desperate to use some printfs in my debugged code. And it was also used to get some output from Dhrystone MIPS benchmark. */ #include <stdio.h> #include <string.h> #include <errno.h> #include <stdarg.h> #include <abstract.h> #include <arch.h> /* Length of printf format string */ #define FMTLEN 2000 void simprintf(unsigned long stackaddr, unsigned long regparam) { unsigned long fmtaddr; char fmtstr[FMTLEN]; FILE *f; int i; #if STACK_ARGS fmtaddr = eval_mem32(stackaddr); #else fmtaddr = regparam; #endif i = 0; while (eval_mem8(fmtaddr) != '\0') { fmtstr[i++] = eval_mem8(fmtaddr); fmtaddr++; if (i == FMTLEN - 1) break; } fmtstr[i] = '\0'; debug("simprintf: stackaddr: 0x%.8lx", stackaddr); if ((f = fopen("stdout.txt", "a+"))) { unsigned long arg; unsigned long argaddr; unsigned char regstr[5]; char *fmtstrend; char *fmtstrpart = fmtstr; #if STACK_ARGS argaddr = stackaddr; #else argaddr = 3; #endif debug("simprintf: %s", fmtstrpart); while(strlen(fmtstrpart)) { if ((fmtstrend = strstr(fmtstrpart + 1, "%"))) *fmtstrend = '\0'; if (strstr(fmtstrpart, "%")) { #if STACK_ARGS argaddr += 4; arg = eval_mem32(argaddr); #else sprintf(regstr, "r%u", ++argaddr); arg = eval_reg(regstr); #endif fprintf(f, fmtstrpart, arg); debug(fmtstrpart, arg); } else { fprintf(f, fmtstrpart); debug(fmtstrpart); } if (!fmtstrend) break; fmtstrpart = fmtstrend; *fmtstrpart = '%'; } if (fclose(f)) perror(strerror(errno)); } else perror(strerror(errno)); }
Go to most recent revision | Compare with Previous | Blame | View Log