summaryrefslogtreecommitdiffstats
path: root/qemu/roms/openbios/arch/ppc/mol/mol.c
blob: 86b3b66bf44fa5f67cac4d3ed9fbfa1852907421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 *   Creation Date: <2003/12/19 18:46:21 samuel>
 *   Time-stamp: <2004/04/12 16:27:12 samuel>
 *
 *	<mol.c>
 *
 *
 *
 *   Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se)
 *
 *   This program is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU General Public License
 *   version 2
 *
 */

#include "config.h"
#include "kernel/kernel.h"
#include "arch/common/nvram.h"
#include "libc/vsprintf.h"
#include "libc/string.h"
#include "mol/mol.h"
#include "osi_calls.h"
#include <stdarg.h>

void
exit( int status )
{
	OSI_Exit();
}

void
fatal_error( const char *err )
{
	printk("Fatal error: %s\n", err );
	OSI_Exit();
}

void
panic( const char *err )
{
	printk("Panic: %s\n", err );
	OSI_Exit();

	/* won't come here... this keeps the gcc happy */
	for( ;; )
		;
}


/************************************************************************/
/*	print using OSI interface					*/
/************************************************************************/

static int do_indent;

int
printk( const char *fmt, ... )
{
        char *p, buf[1024];
	va_list args;
	int i;

	va_start(args, fmt);
        i = vnsprintf(buf, sizeof(buf), fmt, args);
	va_end(args);

	for( p=buf; *p; p++ ) {
		if( *p == '\n' )
			do_indent = 0;
		if( do_indent++ == 1 ) {
			OSI_PutC( '>' );
			OSI_PutC( '>' );
			OSI_PutC( ' ' );
		}
		OSI_PutC( *p );
	}
	return i;
}


/************************************************************************/
/*	TTY iface							*/
/************************************************************************/

static int ttychar = -1;

static int
tty_avail( void )
{
	return OSI_CallAvailable( OSI_TTY_GETC );
}

int
availchar( void )
{
	if( !tty_avail() )
		return 0;

	if( ttychar < 0 )
		ttychar = OSI_TTYGetc();
	if( ttychar < 0 )
		OSI_USleep(1);
	return (ttychar >= 0);
}

int
getchar( void )
{
	int ch;

	if( !tty_avail() )
		return 0;

	if( ttychar < 0 )
		return OSI_TTYGetc();
	ch = ttychar;
	ttychar = -1;
	return ch;
}

int
putchar( int c )
{
	printk("%c", c );

	if( tty_avail() )
		OSI_TTYPutc( c );
	return c;
}


/************************************************************************/
/*	MOL specific stuff						*/
/************************************************************************/

int
arch_nvram_size( void )
{
	return OSI_NVRamSize();
}

void
arch_nvram_put( char *buf )
{
	int i, size = arch_nvram_size();

	for( i=0; i<size; i++ )
		OSI_WriteNVRamByte( i, buf[i] );
}

void
arch_nvram_get( char *buf )
{
	int i, size = arch_nvram_size();

	/* support for zapping the nvram */
	if( get_bool_res("zap_nvram") == 1 ) {
		memset( buf, 0, size );
		return;
	}

	for( i=0; i<size; i++ )
		buf[i] = OSI_ReadNVRamByte( i );
}