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

Subversion Repositories minsoc

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

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 53 ConX.
#include "or1200.h"
8 2 rfajardo
#include "support.h"
9
#include "int.h"
10
 
11
#ifdef UART_PRINTF
12 80 rfajardo
#include <uart.h>
13 2 rfajardo
#endif
14
 
15
#if OR32
16
void int_main();
17
 
18 36 rfajardo
void ext_except()
19 2 rfajardo
{
20
        int_main();
21
}
22
 
23
/* Start function, called by reset exception handler.  */
24
void reset ()
25
{
26 53 ConX.
        int i = main();
27
        or32_exit (i);
28 2 rfajardo
}
29
 
30
/* return value by making a syscall */
31
void or32_exit (int i)
32
{
33 53 ConX.
        asm("l.add r3,r0,%0": : "r" (i));
34
        asm("l.nop %0": :"K" (NOP_EXIT));
35
        while (1);
36 2 rfajardo
}
37
 
38
#ifdef UART_PRINTF
39
 
40
static int uart_init_done = 0;
41
 
42
#define PRINTFBUFFER_SIZE 512
43
char PRINTFBUFFER[PRINTFBUFFER_SIZE]; // Declare a global printf buffer
44
 
45 36 rfajardo
void minsoc_printf(const char *fmt, ...)
46 2 rfajardo
{
47 53 ConX.
        // init uart if not done already
48
        if (!uart_init_done)
49
        {
50
                uart_init();
51
                uart_init_done = 1;
52
        }
53 2 rfajardo
 
54 53 ConX.
        va_list args;
55
        va_start(args, fmt);
56
 
57
        //int str_l = vsnprintf(PRINTFBUFFER, PRINTFBUFFER_SIZE, fmt, args);
58
        int str_l = vfnprintf(PRINTFBUFFER, PRINTFBUFFER_SIZE, fmt, args);
59
 
60
        if (!str_l) return; // no length string - just return
61
 
62
        int c=0;
63
        // now print each char via the UART
64
        while (c < str_l)
65
                uart_putc(PRINTFBUFFER[c++]);
66
 
67
        va_end(args);
68 2 rfajardo
}
69
 
70
#else
71
/* activate printf support in simulator */
72 36 rfajardo
void minsoc_printf(const char *fmt, ...)
73 2 rfajardo
{
74 53 ConX.
        va_list args;
75
        va_start(args, fmt);
76
        __asm__ __volatile__ ("  l.addi\tr3,%1,0\n \
77
                        l.addi\tr4,%2,0\n \
78
                        l.nop %0": :"K" (NOP_PRINTF), "r" (fmt), "r"  (args));
79 2 rfajardo
}
80
 
81
#endif
82
 
83
 
84
 
85
 
86
 
87
/* print long */
88
void report(unsigned long value)
89
{
90 53 ConX.
        asm("l.addi\tr3,%0,0": :"r" (value));
91
        asm("l.nop %0": :"K" (NOP_REPORT));
92 2 rfajardo
}
93
 
94
/* just to satisfy linker */
95
void __main()
96
{
97
}
98
 
99
/* start_TIMER                    */
100
void start_timer(int x)
101
{
102
}
103
 
104
/* For writing into SPR. */
105
void mtspr(unsigned long spr, unsigned long value)
106
{
107 53 ConX.
        asm("l.mtspr\t\t%0,%1,0": : "r" (spr), "r" (value));
108 2 rfajardo
}
109
 
110
/* For reading SPR. */
111
unsigned long mfspr(unsigned long spr)
112
{
113 53 ConX.
        unsigned long value;
114
        asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
115
        return value;
116 2 rfajardo
}
117
 
118
#else
119
void report(unsigned long value)
120
{
121 53 ConX.
        printf("report(0x%x);\n", (unsigned) value);
122 2 rfajardo
}
123
 
124
#endif

powered by: WebSVN 2.1.0

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