OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_52/] [or1ksim/] [support/] [simprintf.c] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 jrydberg
/* libc.c -- dummy C library simulation
2
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
/* Debugger LIBC functions. Working, but VERY, VERY ugly written.
21
I wrote following code when basic simulator started to work and I was
22
desperate to use some printfs in my debugged code. And it was
23
also used to get some output from Dhrystone MIPS benchmark. */
24
 
25
#include <stdio.h>
26
#include <string.h>
27
#include <errno.h>
28
#include <stdarg.h>
29
 
30
#include <abstract.h>
31
#include <arch.h>
32
 
33
/* Length of printf format string */
34
#define FMTLEN 2000
35
 
36
void simprintf(unsigned long stackaddr, unsigned long regparam)
37
{
38
        unsigned long fmtaddr;
39
        char fmtstr[FMTLEN];
40
        FILE *f;
41
        int i;
42
 
43
#if STACK_ARGS
44
        fmtaddr = eval_mem32(stackaddr);
45
#else
46
        fmtaddr = regparam;
47
#endif
48
 
49
        i = 0;
50
        while (eval_mem8(fmtaddr) != '\0') {
51
                fmtstr[i++] = eval_mem8(fmtaddr);
52
                fmtaddr++;
53
                if (i == FMTLEN - 1)
54
                        break;
55
        }
56
        fmtstr[i] = '\0';
57
 
58
        debug("simprintf: stackaddr: 0x%.8lx", stackaddr);
59
        if ((f = fopen("stdout.txt", "a+"))) {
60
                unsigned long arg;
61
                unsigned long argaddr;
62
                unsigned char regstr[5];
63
                char *fmtstrend;
64
                char *fmtstrpart = fmtstr;
65
 
66
#if STACK_ARGS
67
                argaddr = stackaddr;
68
#else
69
                argaddr = 3;
70
#endif
71
                debug("simprintf: %s", fmtstrpart);
72
                while(strlen(fmtstrpart)) {
73
                        if ((fmtstrend = strstr(fmtstrpart + 1, "%")))
74
                                *fmtstrend = '\0';
75
                        if (strstr(fmtstrpart, "%")) {
76
#if STACK_ARGS
77
                                argaddr += 4;
78
                                arg = eval_mem32(argaddr);
79
#else
80
                                sprintf(regstr, "r%u", ++argaddr);
81
                                arg = eval_reg(regstr);
82
#endif
83
                                fprintf(f, fmtstrpart, arg);
84
                                debug(fmtstrpart, arg);
85
                        } else {
86
                                fprintf(f, fmtstrpart);
87
                                debug(fmtstrpart);
88
                        }
89
                        if (!fmtstrend)
90
                                break;
91
                        fmtstrpart = fmtstrend;
92
                        *fmtstrpart = '%';
93
                }
94
 
95
                if (fclose(f))
96
                        perror(strerror(errno));
97
        }
98
        else
99
                perror(strerror(errno));
100
 
101
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.