Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / slof / fs / nvram.fs
1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2014 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 51 CONSTANT nvram-partition-type-cpulog
14 \ types 53-55 are omitted because they have been used for
15 \ storing binary tables in the past
16 60 CONSTANT nvram-partition-type-sas
17 61 CONSTANT nvram-partition-type-sms
18 6e CONSTANT nvram-partition-type-debug
19 6f CONSTANT nvram-partition-type-history
20 70 CONSTANT nvram-partition-type-common
21 7f CONSTANT nvram-partition-type-freespace
22 a0 CONSTANT nvram-partition-type-linux
23
24 : rztype ( str len -- ) \ stop at zero byte, read with nvram-c@
25    0 DO
26       dup i + nvram-c@ ?dup IF ( str char )
27          emit
28       ELSE                     ( str )
29          drop UNLOOP EXIT
30       THEN
31    LOOP
32 ;
33
34 create tmpStr 500 allot
35 : rzcount ( zstr -- str len )
36    dup tmpStr >r BEGIN
37       dup nvram-c@ dup r> dup 1+ >r c!
38    WHILE
39       char+
40    REPEAT
41    r> drop over - swap drop tmpStr swap
42 ;
43
44 : calc-header-cksum ( offset -- cksum )
45    dup nvram-c@
46    10 2 DO
47       over I + nvram-c@ +
48    LOOP
49    wbsplit + nip
50 ;
51
52 : bad-header? ( offset -- flag )
53    dup 2+ nvram-w@        ( offset length )
54    0= IF                  ( offset )
55       drop true EXIT      ( )
56    THEN
57    dup calc-header-cksum  ( offset checksum' )
58    swap 1+ nvram-c@       ( checksum ' checksum )
59    <>                     ( flag )
60 ;
61
62 : .header ( offset -- )
63    cr                         ( offset )
64    dup bad-header? IF         ( offset )
65       ."   BAD HEADER -- trying to print it anyway" cr
66    THEN
67    space                      ( offset )
68    \ print type
69    dup nvram-c@ 2 0.r         ( offset )
70    space space                ( offset )
71    \ print length
72    dup 2+ nvram-w@ 10 * 5 .r  ( offset )
73    space space                ( offset )
74    \ print name
75    4 + 0c rztype              ( )
76 ;
77
78 : .headers ( -- )
79    cr cr ." Type  Size  Name"
80    cr ." ========================"
81    0 BEGIN                      ( offset )
82       dup nvram-c@              ( offset type )
83    WHILE
84       dup .header               ( offset )
85       dup 2+ nvram-w@ 10 * +    ( offset offset' )
86       dup nvram-size < IF       ( offset )
87       ELSE
88          drop EXIT              ( )
89       THEN
90    REPEAT
91    drop                         ( )
92    cr cr
93 ;
94
95 : reset-nvram ( -- )
96    internal-reset-nvram
97 ;
98
99 : dump-partition     ['] nvram-c@      1 (dump) ;
100
101 : type-no-zero ( addr len -- )
102    0 DO
103       dup I + dup nvram-c@ 0= IF drop ELSE nvram-c@ emit THEN
104    LOOP
105    drop
106 ;
107
108 : type-no-zero-part ( from-str cnt-str addr len )
109    0 DO
110       dup i + dup nvram-c@ 0= IF
111          drop
112       ELSE
113          ( from-str cnt-str addr addr+i )
114          ( from-str==0 AND cnt-str > 0 )
115          3 pick 0= 3 pick 0 > AND IF
116             dup 1 type-no-zero
117          THEN
118
119          nvram-c@ a = IF
120             2 pick 0= IF
121                over 1- 0 max
122                rot drop swap
123             THEN
124             2 pick 1- 0 max
125             3 roll drop rot rot
126             ( from-str-- cnt-str-- addr addr+i )
127          THEN
128       THEN
129    LOOP
130    drop
131 ;
132
133 : (dmesg-prepare) ( base-addr -- base-addr' addr len act-off )
134    10 - \ go back to header
135    dup 14 + nvram-l@ dup >r
136    ( base-addr act-off ) ( R: act-off )
137    over over over + swap 10 + nvram-w@ + >r
138    ( base-addr act-off ) ( R:  act-off nvram-act-addr )
139    over 2 + nvram-w@ 10 * swap - over swap
140    ( base-addr base-addr start-size ) ( R:  act-off nvram-act-addr )
141    r> swap rot 10 + nvram-w@ - r>
142 ;
143
144 : .dmesg ( base-addr -- )
145    (dmesg-prepare) >r
146    ( base-addr addr len )
147    cr type-no-zero
148    ( base-addr ) ( R: act-off )
149    dup 10 + nvram-w@ + r> type-no-zero
150 ;
151
152 : .dmesg-part ( from-str cnt-str base-addr -- )
153    (dmesg-prepare) >r
154    ( from-str cnt-str base-addr addr len )
155    >r >r -rot r> r>
156    ( base-addr from-str cnt-str addr len )
157    cr type-no-zero-part rot
158    ( base-addr ) ( R: act-off )
159    dup 10 + nvram-w@ + r> type-no-zero-part
160 ;
161
162 : dmesg-part ( from-str cnt-str -- left-from-str left-cnt-str )
163    2dup
164    s" ibm,CPU0log" get-named-nvram-partition IF
165       2drop EXIT
166    THEN
167    drop .dmesg-part nip nip
168 ;
169
170 : dmesg2 ( -- )
171    s" ibm,CPU1log" get-named-nvram-partition IF
172       ." No log partition." cr EXIT
173    THEN
174    drop .dmesg
175 ;
176
177 : dmesg ( -- )
178    s" ibm,CPU0log" get-named-nvram-partition IF
179       ." No log partition." cr EXIT
180    THEN
181    drop .dmesg
182 ;