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

Subversion Repositories minsoc

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

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

powered by: WebSVN 2.1.0

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