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

Subversion Repositories test_project

[/] [test_project/] [trunk/] [sw/] [support/] [support.c] - Blame information for rev 52

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 julius
/* Support */
2
 
3 33 julius
#ifndef OR32
4 25 julius
#include <sys/time.h>
5
#endif
6
 
7
#include "spr_defs.h"
8
#include "support.h"
9
#include "int.h"
10
 
11 52 julius
#ifdef UART_PRINTF
12
//#include "snprintf.h"
13
#include "vfnprintf.h"
14
#include "uart.h"
15
#endif
16
 
17 33 julius
#if OR32
18 25 julius
void excpt_dummy();
19
void int_main();
20
 
21
unsigned long excpt_buserr = (unsigned long) excpt_dummy;
22
unsigned long excpt_dpfault = (unsigned long) excpt_dummy;
23
unsigned long excpt_ipfault = (unsigned long) excpt_dummy;
24
unsigned long excpt_tick = (unsigned long) excpt_dummy;
25
unsigned long excpt_align = (unsigned long) excpt_dummy;
26
unsigned long excpt_illinsn = (unsigned long) excpt_dummy;
27
unsigned long excpt_int = (unsigned long) int_main;
28
unsigned long excpt_dtlbmiss = (unsigned long) excpt_dummy;
29
unsigned long excpt_itlbmiss = (unsigned long) excpt_dummy;
30
unsigned long excpt_range = (unsigned long) excpt_dummy;
31
unsigned long excpt_syscall = (unsigned long) excpt_dummy;
32
unsigned long excpt_break = (unsigned long) excpt_dummy;
33
unsigned long excpt_trap = (unsigned long) excpt_dummy;
34
 
35
 
36
/* Start function, called by reset exception handler.  */
37
void reset ()
38
{
39
  int i = main();
40 52 julius
  or32_exit (i);
41 25 julius
}
42
 
43
/* return value by making a syscall */
44 52 julius
void or32_exit (int i)
45 25 julius
{
46
  asm("l.add r3,r0,%0": : "r" (i));
47
  asm("l.nop %0": :"K" (NOP_EXIT));
48
  while (1);
49
}
50
 
51 52 julius
#ifdef UART_PRINTF
52
 
53
static int uart_init_done = 0;
54
 
55
#define PRINTFBUFFER_SIZE 512
56
char PRINTFBUFFER[PRINTFBUFFER_SIZE]; // Declare a global printf buffer
57
 
58
void printf(const char *fmt, ...)
59
{
60
  // init uart if not done already
61
  if (!uart_init_done)
62
    {
63
      uart_init();
64
      uart_init_done = 1;
65
    }
66
 
67
  va_list args;
68
  va_start(args, fmt);
69
 
70
  //int str_l = vsnprintf(PRINTFBUFFER, PRINTFBUFFER_SIZE, fmt, args);
71
  int str_l = vfnprintf(PRINTFBUFFER, PRINTFBUFFER_SIZE, fmt, args);
72
 
73
  if (!str_l) return; // no length string - just return
74
 
75
  int c=0;
76
  // now print each char via the UART
77
  while (c < str_l)
78
    uart_putc(PRINTFBUFFER[c++]);
79
 
80
  va_end(args);
81
 
82
}
83
 
84
#else
85 25 julius
/* activate printf support in simulator */
86
void printf(const char *fmt, ...)
87
{
88
  va_list args;
89
  va_start(args, fmt);
90
  __asm__ __volatile__ ("  l.addi\tr3,%1,0\n \
91
                           l.addi\tr4,%2,0\n \
92
                           l.nop %0": :"K" (NOP_PRINTF), "r" (fmt), "r"  (args));
93
}
94
 
95 52 julius
/*
96
void *memcpy (void *__restrict dstvoid,
97
              __const void *__restrict srcvoid, size_t length)
98
{
99
  char *dst = dstvoid;
100
  const char *src = (const char *) srcvoid;
101
 
102
  while (length--)
103
    *dst++ = *src++;
104
  return dst;
105
}
106
*/
107
#endif
108
 
109
 
110
 
111
 
112
 
113 25 julius
/* print long */
114
void report(unsigned long value)
115
{
116
  asm("l.addi\tr3,%0,0": :"r" (value));
117
  asm("l.nop %0": :"K" (NOP_REPORT));
118
}
119
 
120
/* just to satisfy linker */
121
void __main()
122
{
123
}
124
 
125
/* start_TIMER                    */
126
void start_timer(int x)
127
{
128
}
129
 
130
/* read_TIMER                    */
131
/*  Returns a value since started in uS */
132
unsigned int read_timer(int x)
133
{
134
  unsigned long count = 0;
135
 
136
  /* Read the Time Stamp Counter */
137
/*        asm("simrdtsc %0" :"=r" (count)); */
138
  /*asm("l.sys 201"); */
139
  return count;
140
}
141
 
142
/* For writing into SPR. */
143
void mtspr(unsigned long spr, unsigned long value)
144
{
145
  asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
146
}
147
 
148
/* For reading SPR. */
149
unsigned long mfspr(unsigned long spr)
150
{
151
  unsigned long value;
152
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
153
  return value;
154
}
155
 
156
#else
157
void report(unsigned long value)
158
{
159
  printf("report(0x%x);\n", (unsigned) value);
160
}
161
 
162
/* start_TIMER                    */
163
void start_timer(int tmrnum)
164
{
165
}
166
 
167
/* read_TIMER                    */
168
/*  Returns a value since started in uS */
169
unsigned int read_timer(int tmrnum)
170
{
171
  struct timeval tv;
172
  struct timezone tz;
173
 
174
  gettimeofday(&tv, &tz);
175
 
176
  return(tv.tv_sec*1000000+tv.tv_usec);
177
}
178
 
179
#endif
180
 
181
 
182
void excpt_dummy() {}

powered by: WebSVN 2.1.0

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