File: /usr/src/linux/arch/mips/baget/print.c

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