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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [common/] [support.c] - Blame information for rev 803

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

Line No. Rev Author Line
1 2 marcus.erl
/* Support */
2
 
3 246 julius
#include "spr-defs.h"
4 2 marcus.erl
#include "support.h"
5
#include "common.h"
6
#include "int.h"
7
 
8
#include <ctype.h>
9
 
10
volatile unsigned long timestamp = 0;
11
 
12
void int_main(void);
13
 
14
/* return value by making a syscall */
15 406 julius
void exit(int i)
16 2 marcus.erl
{
17 406 julius
asm("l.add r3,r0,%0": :"r"(i));
18
asm("l.nop %0": :"K"(NOP_EXIT));
19
        while (1) ;
20 2 marcus.erl
}
21
 
22
/* activate printf support in simulator */
23
void __printf(const char *fmt, ...)
24
{
25 140 julius
#if 0
26 406 julius
        va_list args;
27
        va_start(args, fmt);
28
        __asm__ __volatile__("  l.addi\tr3,%1,0\n \
29 2 marcus.erl
                           l.addi\tr4,%2,0\n \
30 406 julius
                           l.nop %0"::"K"(NOP_PRINTF), "r"(fmt), "r"(args):"r3", "r4");
31 140 julius
#endif
32 2 marcus.erl
}
33
 
34
/* print long */
35
void report(unsigned long value)
36
{
37 406 julius
asm("l.addi\tr3,%0,0": :"r"(value));
38
asm("l.nop %0": :"K"(NOP_REPORT));
39 2 marcus.erl
}
40
 
41
/* just to satisfy linker */
42
void __main(void)
43
{
44
}
45
 
46
/* For writing into SPR. */
47
void mtspr(unsigned long spr, unsigned long value)
48
{
49 406 julius
asm("l.mtspr\t\t%0,%1,0": :"r"(spr), "r"(value));
50 2 marcus.erl
}
51
 
52
/* For reading SPR. */
53
unsigned long mfspr(unsigned long spr)
54
{
55 406 julius
        unsigned long value;
56
asm("l.mfspr\t\t%0,%1,0": "=r"(value):"r"(spr));
57
        return value;
58 2 marcus.erl
}
59
 
60
/* Parses hex or decimal number */
61 406 julius
unsigned long strtoul(const char *str, char **endptr, int base)
62 2 marcus.erl
{
63
 
64 406 julius
        {
65 2 marcus.erl
 
66 406 julius
                unsigned long number = 0;
67
                char *pos = (char *)str;
68
                char *fail_char = (char *)str;
69 2 marcus.erl
 
70 406 julius
                while (isspace(*pos))
71
                        pos++;  /* skip leading whitespace */
72 2 marcus.erl
 
73 406 julius
                if ((base == 16) && (*pos == '0')) {    /* handle option prefix */
74
                        ++pos;
75
                        fail_char = pos;
76
                        if ((*pos == 'x') || (*pos == 'X'))
77
                                ++pos;
78
                }
79 2 marcus.erl
 
80 406 julius
                if (base == 0) { /* dynamic base */
81
                        base = 10;      /* default is 10 */
82
                        if (*pos == '0') {
83
                                ++pos;
84
                                base -= 2;      /* now base is 8 (or 16) */
85
                                fail_char = pos;
86
                                if ((*pos == 'x') || (*pos == 'X')) {
87
                                        base += 8;      /* base is 16 */
88
                                        ++pos;
89
                                }
90
                        }
91
                }
92 2 marcus.erl
 
93 406 julius
                /* check for illegal base */
94
                if (!((base < 2) || (base > 36)))
95
                        while (1) {
96
                                int digit = 40;
97
                                if ((*pos >= '0') && (*pos <= '9')) {
98
                                        digit = (*pos - '0');
99
                                } else if (*pos >= 'a') {
100
                                        digit = (*pos - 'a' + 10);
101
                                } else if (*pos >= 'A') {
102
                                        digit = (*pos - 'A' + 10);
103
                                } else
104
                                        break;
105 2 marcus.erl
 
106 406 julius
                                if (digit >= base)
107
                                        break;
108 2 marcus.erl
 
109 406 julius
                                fail_char = ++pos;
110
                                number = number * base + digit;
111
                        }
112 2 marcus.erl
 
113 406 julius
                if (endptr)
114
                        *endptr = fail_char; {
115
                        return number;
116
                        }
117
        }
118
}
119 2 marcus.erl
 
120 406 julius
unsigned long get_timer(unsigned long base)
121 2 marcus.erl
{
122 406 julius
        /*
123
           __printf("%s - %s: %d\n", __FILE__, __FUNCTION__, __LINE__);
124
           __printf("   timestamp = %.8lx base = %.8lx\n", timestamp, base);
125
         */
126
        return (timestamp - base);
127 2 marcus.erl
}
128 406 julius
 
129
void set_timer(unsigned long t)
130 2 marcus.erl
{
131 406 julius
        timestamp = t;
132 2 marcus.erl
}

powered by: WebSVN 2.1.0

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