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

Subversion Repositories minsoc

[/] [minsoc/] [trunk/] [sw/] [support/] [support.c] - Blame information for rev 9

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

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

powered by: WebSVN 2.1.0

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