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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
/*
* Creation Date: <2004/08/28 18:38:22 greg>
* Time-stamp: <2004/08/28 18:38:22 greg>
*
* <methods.c>
*
* Misc device node methods
*
* Copyright (C) 2004 Greg Watson
*
* Based on MOL specific code which is
*
* 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 "libopenbios/bindings.h"
#include "libc/string.h"
#include "pearpc/pearpc.h"
#include "libopenbios/ofmem.h"
/************************************************************************/
/* RTAS (run-time abstraction services) */
/************************************************************************/
#ifdef CONFIG_RTAS
DECLARE_NODE( rtas, INSTALL_OPEN, 0, "+/rtas" );
/* ( physbase -- rtas_callback ) */
static void
rtas_instantiate( void )
{
int physbase = POP();
int s=0x1000, size = (int)of_rtas_end - (int)of_rtas_start;
unsigned long virt;
while( s < size )
s += 0x1000;
virt = ofmem_claim_virt( 0, s, 0x1000 );
ofmem_map( physbase, virt, s, -1 );
memcpy( (char*)virt, of_rtas_start, size );
printk("RTAS instantiated at %08x\n", physbase );
flush_icache_range( (char*)virt, (char*)virt + size );
PUSH( physbase );
}
NODE_METHODS( rtas ) = {
{ "instantiate", rtas_instantiate },
{ "instantiate-rtas", rtas_instantiate },
};
#endif
/************************************************************************/
/* stdout */
/************************************************************************/
DECLARE_NODE( video_stdout, INSTALL_OPEN, 0, "Tdisplay" );
/* ( addr len -- actual ) */
static void
stdout_write( void )
{
int len = POP();
char *addr = (char*)POP();
printk( "%s", s );
//vfd_draw_str( s );
console_draw_fstr(addr, len);
PUSH( len );
}
NODE_METHODS( video_stdout ) = {
{ "write", stdout_write },
};
/************************************************************************/
/* tty */
/************************************************************************/
DECLARE_NODE( tty, INSTALL_OPEN, 0, "/packages/terminal-emulator" );
/* ( addr len -- actual ) */
static void
tty_read( void )
{
int ch, len = POP();
char *p = (char*)POP();
int ret=0;
if( len > 0 ) {
ret = 1;
ch = getchar();
if( ch >= 0 ) {
*p = ch;
} else {
ret = 0;
}
}
PUSH( ret );
}
/* ( addr len -- actual ) */
static void
tty_write( void )
{
int i, len = POP();
char *p = (char*)POP();
for( i=0; i<len; i++ )
putchar( *p++ );
RET( len );
}
NODE_METHODS( tty ) = {
{ "read", tty_read },
{ "write", tty_write },
};
/************************************************************************/
/* client interface 'quiesce' */
/************************************************************************/
DECLARE_NODE( ciface, 0, 0, "/packages/client-iface" );
/* ( -- ) */
static void
ciface_quiesce( unsigned long args[], unsigned long ret[] )
{
#if 0
unsigned long msr;
/* This seems to be the correct thing to do - but I'm not sure */
asm volatile("mfmsr %0" : "=r" (msr) : );
msr &= ~(MSR_IR | MSR_DR);
asm volatile("mtmsr %0" :: "r" (msr) );
#endif
printk("=============================================================\n\n");
}
/* ( -- ms ) */
static void
ciface_milliseconds( unsigned long args[], unsigned long ret[] )
{
extern unsigned long get_timer_freq();
static unsigned long mticks=0, usecs=0;
unsigned long t;
asm volatile("mftb %0" : "=r" (t) : );
if( mticks )
usecs += get_timer_freq() / 1000000 * ( t-mticks );
mticks = t;
PUSH( usecs/1000 );
}
NODE_METHODS( ciface ) = {
{ "quiesce", ciface_quiesce },
{ "milliseconds", ciface_milliseconds },
};
/************************************************************************/
/* MMU/memory methods */
/************************************************************************/
DECLARE_NODE( memory, INSTALL_OPEN, 0, "/memory" );
DECLARE_NODE( mmu, INSTALL_OPEN, 0, "/cpu@0" );
DECLARE_NODE( mmu_ciface, 0, 0, "/packages/client-iface" );
/* ( phys size align --- base ) */
static void
mem_claim( void )
{
ucell align = POP();
ucell size = POP();
ucell phys = POP();
ucell ret = ofmem_claim_phys( phys, size, align );
if( ret == (ucell)-1 ) {
printk("MEM: claim failure\n");
throw( -13 );
return;
}
PUSH( ret );
}
/* ( phys size --- ) */
static void
mem_release( void )
{
POP(); POP();
}
/* ( phys size align --- base ) */
static void
mmu_claim( void )
{
ucell align = POP();
ucell size = POP();
ucell phys = POP();
ucell ret = ofmem_claim_virt( phys, size, align );
if( ret == -1 ) {
printk("MMU: CLAIM failure\n");
throw( -13 );
return;
}
PUSH( ret );
}
/* ( phys size --- ) */
static void
mmu_release( void )
{
POP(); POP();
}
/* ( phys virt size mode -- [ret???] ) */
static void
mmu_map( void )
{
ucell mode = POP();
ucell size = POP();
ucell virt = POP();
ucell phys = POP();
ucell ret;
/* printk("mmu_map: %x %x %x %x\n", phys, virt, size, mode ); */
ret = ofmem_map( phys, virt, size, mode );
if( ret ) {
printk("MMU: map failure\n");
throw( -13 );
return;
}
}
/* ( virt size -- ) */
static void
mmu_unmap( void )
{
POP(); POP();
}
/* ( virt -- false | phys mode true ) */
static void
mmu_translate( void )
{
ucell mode;
ucell virt = POP();
ucell phys = ofmem_translate( virt, &mode );
if( phys == -1 ) {
PUSH( 0 );
} else {
PUSH( phys );
PUSH( mode );
PUSH( -1 );
}
}
/* ( virt size align -- baseaddr|-1 ) */
static void
ciface_claim( void )
{
ucell align = POP();
ucell size = POP();
ucell virt = POP();
ucell ret = ofmem_claim( virt, size, align );
/* printk("ciface_claim: %08x %08x %x\n", virt, size, align ); */
PUSH( ret );
}
/* ( virt size -- ) */
static void
ciface_release( void )
{
POP();
POP();
}
NODE_METHODS( memory ) = {
{ "claim", mem_claim },
{ "release", mem_release },
};
NODE_METHODS( mmu ) = {
{ "claim", mmu_claim },
{ "release", mmu_release },
{ "map", mmu_map },
{ "unmap", mmu_unmap },
{ "translate", mmu_translate },
};
NODE_METHODS( mmu_ciface ) = {
{ "cif-claim", ciface_claim },
{ "cif-release", ciface_release },
};
/************************************************************************/
/* init */
/************************************************************************/
void
node_methods_init( void )
{
#ifdef CONFIG_RTAS
REGISTER_NODE( rtas );
#endif
REGISTER_NODE( video_stdout );
REGISTER_NODE( ciface );
REGISTER_NODE( memory );
REGISTER_NODE( mmu );
REGISTER_NODE( mmu_ciface );
REGISTER_NODE( tty );
}
|