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

Subversion Repositories or1k

[/] [or1k/] [branches/] [oc/] [orpmon/] [common/] [support.c] - Blame information for rev 1771

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

Line No. Rev Author Line
1 809 simons
/* Support */
2
 
3
#include <sys/time.h>
4
#include "spr_defs.h"
5
#include "support.h"
6
#include "int.h"
7
 
8
unsigned long timestamp = 0;
9
 
10
void int_main(void);
11
 
12
/* return value by making a syscall */
13
void exit (int i)
14
{
15
  asm("l.add r3,r0,%0": : "r" (i));
16
  asm("l.nop %0": :"K" (NOP_EXIT));
17
  while (1);
18
}
19
 
20
/* activate printf support in simulator */
21
void __printf(const char *fmt, ...)
22
{
23
 
24
  va_list args;
25
  va_start(args, fmt);
26
  __asm__ __volatile__ ("  l.addi\tr3,%1,0\n \
27
                           l.addi\tr4,%2,0\n \
28
                           l.nop %0": :"K" (NOP_PRINTF), "r" (fmt), "r"  (args) : "r3", "r4");
29
}
30
 
31
/* print long */
32
void report(unsigned long value)
33
{
34
  asm("l.addi\tr3,%0,0": :"r" (value));
35
  asm("l.nop %0": :"K" (NOP_REPORT));
36
}
37
 
38
/* just to satisfy linker */
39
void __main(void)
40
{
41
}
42
 
43
/* For writing into SPR. */
44
void mtspr(unsigned long spr, unsigned long value)
45
{
46
  asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
47
}
48
 
49
/* For reading SPR. */
50
unsigned long mfspr(unsigned long spr)
51
{
52
  unsigned long value;
53
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
54
  return value;
55
}
56
 
57
void *memcpy (void *__restrict dstvoid,
58
              __const void *__restrict srcvoid, size_t length)
59
{
60
  char *dst = dstvoid;
61
  const char *src = (const char *) srcvoid;
62
 
63
  while (length--)
64
    *dst++ = *src++;
65
  return dst;
66
}
67
 
68
int memcmp (void *__restrict dstvoid,
69
              __const void *__restrict srcvoid, size_t length)
70
{
71
  char *dst = dstvoid;
72
  const char *src = (const char *) srcvoid;
73
 
74
  while (length--)
75
    if(*dst++ != *src++)
76
      if(*(--dst) > *(--src))
77
        return 1;
78
      else
79
        return -1;
80
  return 1;
81
}
82
 
83
 
84
void *memchr (void *__restrict dstvoid,
85
              __const char data, size_t length)
86
{
87
  char *dst = dstvoid;
88
 
89
  while (length--) *dst++ = data;
90
  return dst;
91
}
92
 
93
int strlen (__const char *srcvoid)
94
{
95
  int len = 0;
96
  while (*srcvoid++) len++;
97
  return len;
98
}
99
 
100
int strcmp (const char *s1, const char *s2)
101
{
102
 
103
  while (*s1 != '\0' && *s1 == *s2) {
104
    s1++;
105
    s2++;
106
  }
107
 
108
  return (*(unsigned char *) s1) - (*(unsigned char *) s2);
109
}
110
 
111
char *strcpy (char *dst0, char *src0)
112
{
113
  char *s = dst0;
114
 
115
  while ((*dst0++ = *src0++));
116
 
117
  return s;
118
}
119
 
120
void reset_timer (void)
121
{
122
  timestamp = 0;
123
}
124
 
125
unsigned long get_timer (unsigned long base)
126
{
127
  return (timestamp - base);
128
}
129
 
130
void set_timer (unsigned long t)
131
{
132
  timestamp = t;
133
}
134
 

powered by: WebSVN 2.1.0

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