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

Subversion Repositories yac

[/] [yac/] [trunk/] [test_sys/] [sw/] [or32/] [support.c] - Blame information for rev 11

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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