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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [orpmon/] [common/] [support.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 809 simons
/* Support */
2
 
3
#include "spr_defs.h"
4
#include "support.h"
5 833 simons
#include "common.h"
6 809 simons
#include "int.h"
7
 
8 878 rherveille
#include <ctype.h>
9
 
10 833 simons
volatile unsigned long timestamp = 0;
11 809 simons
 
12
void int_main(void);
13
 
14
/* return value by making a syscall */
15
void exit (int i)
16
{
17
  asm("l.add r3,r0,%0": : "r" (i));
18
  asm("l.nop %0": :"K" (NOP_EXIT));
19
  while (1);
20
}
21
 
22
/* activate printf support in simulator */
23
void __printf(const char *fmt, ...)
24
{
25 921 rherveille
 
26 809 simons
  va_list args;
27
  va_start(args, fmt);
28
  __asm__ __volatile__ ("  l.addi\tr3,%1,0\n \
29
                           l.addi\tr4,%2,0\n \
30
                           l.nop %0": :"K" (NOP_PRINTF), "r" (fmt), "r"  (args) : "r3", "r4");
31
}
32
 
33
/* print long */
34
void report(unsigned long value)
35
{
36
  asm("l.addi\tr3,%0,0": :"r" (value));
37
  asm("l.nop %0": :"K" (NOP_REPORT));
38
}
39
 
40
/* just to satisfy linker */
41
void __main(void)
42
{
43
}
44
 
45
/* For writing into SPR. */
46
void mtspr(unsigned long spr, unsigned long value)
47 921 rherveille
{
48 809 simons
  asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
49
}
50
 
51
/* For reading SPR. */
52
unsigned long mfspr(unsigned long spr)
53 921 rherveille
{
54 809 simons
  unsigned long value;
55
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
56
  return value;
57
}
58
 
59
 
60
 
61 816 markom
/* Parses hex or decimal number */
62
unsigned long strtoul (const char *str, char **endptr, int base)
63
{
64
 
65 1312 jurem
  {
66
 
67
    unsigned long number = 0;
68
    char *pos = (char *) str;
69
    char *fail_char = (char *) str;
70
 
71
 
72 816 markom
  while (isspace(*pos)) pos++;  /* skip leading whitespace */
73
 
74
  if ((base == 16) && (*pos == '0')) { /* handle option prefix */
75
    ++pos;
76
    fail_char = pos;
77
    if ((*pos == 'x') || (*pos == 'X')) ++pos;
78
  }
79 921 rherveille
 
80 816 markom
  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
 
93 878 rherveille
  /* 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 break;
104 816 markom
 
105 878 rherveille
      if (digit >= base) break;
106 816 markom
 
107 878 rherveille
      fail_char = ++pos;
108
      number = number * base + digit;
109
    }
110 816 markom
 
111 1312 jurem
  if (endptr) *endptr = fail_char; {
112 878 rherveille
    return number;
113 1312 jurem
  }
114
  }
115 816 markom
}
116 809 simons
 
117
unsigned long get_timer (unsigned long base)
118
{
119 833 simons
__printf("%s - %s: %d\n", __FILE__, __FUNCTION__, __LINE__);
120
__printf("   timestamp = %.8lx base = %.8lx\n", timestamp, base);
121 809 simons
  return (timestamp - base);
122
}
123
 
124
void set_timer (unsigned long t)
125
{
126
  timestamp = t;
127
}
128
 

powered by: WebSVN 2.1.0

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