Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / openbios / arch / ppc / mol / mol.c
1 /*
2  *   Creation Date: <2003/12/19 18:46:21 samuel>
3  *   Time-stamp: <2004/04/12 16:27:12 samuel>
4  *
5  *      <mol.c>
6  *
7  *
8  *
9  *   Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
10  *
11  *   This program is free software; you can redistribute it and/or
12  *   modify it under the terms of the GNU General Public License
13  *   version 2
14  *
15  */
16
17 #include "config.h"
18 #include "kernel/kernel.h"
19 #include "arch/common/nvram.h"
20 #include "libc/vsprintf.h"
21 #include "libc/string.h"
22 #include "mol/mol.h"
23 #include "osi_calls.h"
24 #include <stdarg.h>
25
26 void
27 exit( int status )
28 {
29         OSI_Exit();
30 }
31
32 void
33 fatal_error( const char *err )
34 {
35         printk("Fatal error: %s\n", err );
36         OSI_Exit();
37 }
38
39 void
40 panic( const char *err )
41 {
42         printk("Panic: %s\n", err );
43         OSI_Exit();
44
45         /* won't come here... this keeps the gcc happy */
46         for( ;; )
47                 ;
48 }
49
50
51 /************************************************************************/
52 /*      print using OSI interface                                       */
53 /************************************************************************/
54
55 static int do_indent;
56
57 int
58 printk( const char *fmt, ... )
59 {
60         char *p, buf[1024];
61         va_list args;
62         int i;
63
64         va_start(args, fmt);
65         i = vnsprintf(buf, sizeof(buf), fmt, args);
66         va_end(args);
67
68         for( p=buf; *p; p++ ) {
69                 if( *p == '\n' )
70                         do_indent = 0;
71                 if( do_indent++ == 1 ) {
72                         OSI_PutC( '>' );
73                         OSI_PutC( '>' );
74                         OSI_PutC( ' ' );
75                 }
76                 OSI_PutC( *p );
77         }
78         return i;
79 }
80
81
82 /************************************************************************/
83 /*      TTY iface                                                       */
84 /************************************************************************/
85
86 static int ttychar = -1;
87
88 static int
89 tty_avail( void )
90 {
91         return OSI_CallAvailable( OSI_TTY_GETC );
92 }
93
94 int
95 availchar( void )
96 {
97         if( !tty_avail() )
98                 return 0;
99
100         if( ttychar < 0 )
101                 ttychar = OSI_TTYGetc();
102         if( ttychar < 0 )
103                 OSI_USleep(1);
104         return (ttychar >= 0);
105 }
106
107 int
108 getchar( void )
109 {
110         int ch;
111
112         if( !tty_avail() )
113                 return 0;
114
115         if( ttychar < 0 )
116                 return OSI_TTYGetc();
117         ch = ttychar;
118         ttychar = -1;
119         return ch;
120 }
121
122 int
123 putchar( int c )
124 {
125         printk("%c", c );
126
127         if( tty_avail() )
128                 OSI_TTYPutc( c );
129         return c;
130 }
131
132
133 /************************************************************************/
134 /*      MOL specific stuff                                              */
135 /************************************************************************/
136
137 int
138 arch_nvram_size( void )
139 {
140         return OSI_NVRamSize();
141 }
142
143 void
144 arch_nvram_put( char *buf )
145 {
146         int i, size = arch_nvram_size();
147
148         for( i=0; i<size; i++ )
149                 OSI_WriteNVRamByte( i, buf[i] );
150 }
151
152 void
153 arch_nvram_get( char *buf )
154 {
155         int i, size = arch_nvram_size();
156
157         /* support for zapping the nvram */
158         if( get_bool_res("zap_nvram") == 1 ) {
159                 memset( buf, 0, size );
160                 return;
161         }
162
163         for( i=0; i<size; i++ )
164                 buf[i] = OSI_ReadNVRamByte( i );
165 }