1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2008 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
10 \ * IBM Corporation - initial implementation
11 \ ****************************************************************************/
13 \ (rtas-size) determines the size required for RTAS.
14 \ It looks at the rtas binary in the flash and reads the rtas-size from
15 \ its header at offset 8.
16 : (rtas-size) ( -- rtas-size )
17 s" rtas" romfs-lookup dup 0=
18 ABORT" romfs-lookup for rtas failed"
22 (rtas-size) CONSTANT rtas-size
24 : instantiate-rtas ( adr -- entry )
26 s" rtas" romfs-lookup 0=
27 ABORT" romfs-lookup for rtas failed"
28 rtas-config swap start-rtas ;
30 here fff + fffffffffffff000 and here - allot
31 here rtas-size allot CONSTANT rtas-start-addr
33 rtas-start-addr instantiate-rtas CONSTANT rtas-entry-point
38 2000000 start-rtas to rtas-entry-point
42 \ ffffffffffffffff CONSTANT rtas-entry-point
58 /l C * field rtas>args
61 CONSTANT /rtas-control-block
63 CREATE rtas-cb /rtas-control-block allot
64 rtas-cb /rtas-control-block erase
66 \ call-c ( p0 p1 p2 entry -- ret )
69 rtas-cb rtas-start-addr 0 rtas-entry-point call-c drop ;
72 \ This is the structure of the RTAS function jump table in the C code:
74 cell FIELD rtasfunctab>name
75 cell FIELD rtasfunctab>func
76 cell FIELD rtasfunctab>flags
77 CONSTANT rtasfunctab-size
79 \ Create RTAS token properties by analyzing the jump table in the C code:
80 : rtas-create-token-properties ( -- )
81 rtas-start-addr 10 + @ rtas-start-addr + \ Get pointer to jump table
82 rtas-start-addr 18 + @ rtas-start-addr + l@ \ Get the number of entries
84 dup rtasfunctab>func @ 0<> \ function pointer must not be NULL
85 over rtasfunctab>flags @ 1 and 0= \ Check the only-internal flag
88 i 1+ encode-int \ Create the token value
89 2 pick rtasfunctab>name @ zcount \ Create the token name string
90 property \ Create the property
92 rtasfunctab-size + \ Proceed to the next entry
97 \ Get the RTAS token that corresponds to an RTAS property name:
98 : rtas-get-token ( str len -- token|0 )
99 rtas-start-addr 10 + @ rtas-start-addr + \ Get pointer to jump table
100 rtas-start-addr 18 + @ rtas-start-addr + l@ \ Get the number of entries
102 dup rtasfunctab>name @ \ Get pointer to function name
103 dup 0<> \ function name must not be NULL
104 over zcount 5 pick = nip and \ Check if both strings have same length
106 3 pick 3 pick \ Make a copy of the token name string
110 i 1+ \ If the name matched, return the token
116 rtasfunctab-size + \ Proceed to the next entry
119 ." RTAS token not found: " type cr