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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [arch/] [mips/] [baget/] [print.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * print.c: Simple print fascility
3
 *
4
 * Copyright (C) 1998 Gleb Raiko & Vladimir Roganov
5
 */
6
#include <stdarg.h>
7
#include <linux/kernel.h>
8
#include <linux/init.h>
9
 
10
#include <asm/baget/baget.h>
11
 
12
/*
13
 *  Define this to see 'baget_printk' (debug) messages
14
 */
15
// #define BAGET_PRINTK
16
 
17
/*
18
 *  This function is same for BALO and Linux baget_printk,
19
 *  and normally prints characted to second (UART A) console.
20
 */
21
 
22
static void delay(void) {}
23
 
24
static void outc_low(char c)
25
{
26
        int i;
27
        vac_outb(c, VAC_UART_B_TX);
28
        for (i=0; i<10000; i++)
29
                delay();
30
}
31
 
32
void outc(char c)
33
{
34
        if (c == '\n')
35
                outc_low('\r');
36
        outc_low(c);
37
}
38
 
39
void outs(char *s)
40
{
41
        while(*s) outc(*s++);
42
}
43
 
44
void baget_write(char *s, int l)
45
{
46
        while(l--)
47
                outc(*s++);
48
}
49
 
50
int baget_printk(const char *fmt, ...)
51
{
52
#ifdef BAGET_PRINTK
53
        va_list args;
54
        int i;
55
        static char buf[1024];
56
 
57
        va_start(args, fmt);
58
        i = vsprintf(buf, fmt, args); /* hopefully i < sizeof(buf)-4 */
59
        va_end(args);
60
        baget_write(buf, i);
61
        return i;
62
#else
63
        return 0;
64
#endif
65
}
66
 
67
static __inline__ void puthex( int a )
68
{
69
        static char s[9];
70
        static char e[] = "0123456789ABCDEF";
71
        int i;
72
        for( i = 7; i >= 0; i--, a >>= 4 ) s[i] = e[a & 0x0F];
73
        s[8] = '\0';
74
        outs( s );
75
}
76
 
77
void __init balo_printf( char *f, ... )
78
{
79
        int *arg = (int*)&f + 1;
80
        char c;
81
        int format = 0;
82
 
83
        while((c = *f++) != 0) {
84
                switch(c) {
85
                default:
86
                        if(format) {
87
                                outc('%');
88
                                format = 0;
89
                        }
90
                        outc( c );
91
                        break;
92
                case '%':
93
                        if( format ){
94
                                format = 0;
95
                                outc(c);
96
                        } else format = 1;
97
                        break;
98
                case 'x':
99
                        if(format) puthex( *arg++ );
100
                        else outc(c);
101
                        format = 0;
102
                        break;
103
                case 's':
104
                        if( format ) outs((char *)*arg++);
105
                        else outc(c);
106
                        format = 0;
107
                        break;
108
                }
109
        }
110
}
111
 
112
void __init balo_hungup(void)
113
{
114
        outs("Hunging up.\n");
115
        while(1);
116
}

powered by: WebSVN 2.1.0

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