Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / slof / fs / rtas / rtas-init.fs
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
8 \ *
9 \ * Contributors:
10 \ *     IBM Corporation - initial implementation
11 \ ****************************************************************************/
12
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"
19    drop 8 + @
20 ;
21
22 (rtas-size) CONSTANT rtas-size
23
24 : instantiate-rtas ( adr -- entry )
25     dup rtas-size erase
26     s" rtas" romfs-lookup 0=
27     ABORT" romfs-lookup for rtas failed"
28     rtas-config swap start-rtas ;
29
30 here fff + fffffffffffff000 and here - allot
31 here rtas-size allot CONSTANT rtas-start-addr
32
33 rtas-start-addr instantiate-rtas CONSTANT rtas-entry-point
34
35 : drone-rtas
36    rtas-start-addr
37    dup rtas-size erase
38    2000000 start-rtas to rtas-entry-point
39 ;
40
41
42 \ ffffffffffffffff CONSTANT rtas-entry-point
43
44 \ rtas control block
45
46 STRUCT
47         /l field rtas>token
48         /l field rtas>nargs
49         /l field rtas>nret
50         /l field rtas>args0
51         /l field rtas>args1
52         /l field rtas>args2
53         /l field rtas>args3
54         /l field rtas>args4
55         /l field rtas>args5
56         /l field rtas>args6
57         /l field rtas>args7
58         /l C * field rtas>args
59         /l field rtas>bla
60
61 CONSTANT /rtas-control-block
62
63 CREATE rtas-cb /rtas-control-block allot
64 rtas-cb  /rtas-control-block erase
65
66 \ call-c ( p0 p1 p2 entry -- ret )
67
68 : enter-rtas ( -- )
69     rtas-cb rtas-start-addr 0 rtas-entry-point call-c drop ;
70
71
72 \ This is the structure of the RTAS function jump table in the C code:
73 STRUCT
74         cell FIELD rtasfunctab>name
75         cell FIELD rtasfunctab>func
76         cell FIELD rtasfunctab>flags
77 CONSTANT rtasfunctab-size
78
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
83     0  DO
84         dup rtasfunctab>func @ 0<>            \ function pointer must not be NULL
85         over rtasfunctab>flags @ 1 and 0=     \ Check the only-internal flag
86         and
87         IF
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
91         THEN
92         rtasfunctab-size +                    \ Proceed to the next entry
93     LOOP
94     drop
95 ;
96
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
101     0  DO
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
105         IF
106             3 pick 3 pick               \ Make a copy of the token name string
107             comp 0=
108             IF
109                 drop 2drop
110                 i 1+                    \ If the name matched, return the token
111                 UNLOOP EXIT
112             THEN
113         ELSE
114             drop
115         THEN
116         rtasfunctab-size +              \ Proceed to the next entry
117     LOOP
118     drop
119     ." RTAS token not found: " type cr
120     0
121 ;