Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / slof / fs / romfs.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 STRUCT
14         cell field romfs>file-header
15         cell field romfs>data
16         cell field romfs>data-size
17         cell field romfs>flags
18
19 CONSTANT /romfs-lookup-control-block
20
21 CREATE romfs-lookup-cb /romfs-lookup-control-block allot
22 romfs-lookup-cb /romfs-lookup-control-block erase
23
24 : create-filename ( string -- string\0 )
25     here >r dup 8 + allot
26     r@ over 8 + erase
27     r@ zplace r> ;
28
29 : romfs-lookup ( fn-str fn-len -- data size | false )
30     create-filename romfs-base
31     romfs-lookup-cb romfs-lookup-entry call-c
32     0= IF romfs-lookup-cb dup romfs>data @ swap romfs>data-size @ ELSE
33     false THEN ;
34
35 : ibm,romfs-lookup ( fn-str fn-len -- data-high data-low size | 0 0 false )
36   romfs-lookup dup
37   0= if drop 0 0 false else
38   swap dup 20 rshift swap ffffffff and then ;
39
40 \ FIXME For a short time ...
41 : romfs-lookup-client ibm,romfs-lookup ;
42
43 \ Fixme temp implementation
44
45 STRUCT
46         cell field romfs>next-off
47         cell field romfs>size
48         cell field romfs>flags
49         cell field romfs>data-off
50         cell field romfs>name
51
52 CONSTANT /romfs-cb
53
54 : romfs-map-file ( fn-str fn-len -- file-addr file-size )
55   romfs-base >r
56   BEGIN 2dup r@ romfs>name zcount string=ci not WHILE
57     ( fn-str fn-len ) ( R: rom-cb-file-addr )
58     r> romfs>next-off dup @ dup 0= IF 1 THROW THEN + >r REPEAT
59     ( fn-str fn-len ) ( R: rom-cb-file-addr )
60     2drop r@ romfs>data-off @ r@ + r> romfs>size @ ;
61
62 \ returns address of romfs-header file
63 : flash-header ( -- address | false )
64     get-flash-base 28 +         \ prepare flash header file address
65     dup rx@                     \ fetch "magic123"
66     6d61676963313233 <> IF      \ IF flash is not valid
67        drop                     \ | forget address
68        false                    \ | return false
69     THEN                        \ FI
70 ;
71
72 CREATE bdate-str 10 allot
73 : bdate2human ( -- addr len )
74   flash-header 40 + rx@ (.)
75   drop dup 0 + bdate-str 6 + 4 move
76   dup 4 + bdate-str 0 + 2 move
77   dup 6 + bdate-str 3 + 2 move
78   dup 8 + bdate-str b + 2 move
79   a + bdate-str e + 2 move
80   2d bdate-str 2 + c!
81   2d bdate-str 5 + c!
82   20 bdate-str a + c!
83   3a bdate-str d + c!
84   bdate-str 10
85 ;
86
87
88 \ Look up a file in the ROM file system and evaluate it
89
90 : included  ( fn fn-len -- )
91    2dup >r >r romfs-lookup dup IF
92       r> drop r> drop evaluate
93    ELSE
94       drop ." Cannot open file : " r> r> type cr
95    THEN
96 ;
97
98 : include  ( " fn " -- )
99    parse-word included
100 ;
101
102 : ?include  ( flag " fn " -- )
103    parse-word rot IF included ELSE 2drop THEN
104 ;
105
106 : include?  ( nargs flag " fn " -- )
107    parse-word rot IF
108       rot drop included
109    ELSE
110       2drop 0 ?DO drop LOOP
111    THEN
112 ;
113
114
115 \ List files in ROMfs
116
117 : (print-romfs-file-info)  ( file-addr -- )
118    9 emit  dup b 0.r  2 spaces  dup 8 + @ 6 0.r  2 spaces  20 + zcount type cr
119 ;
120
121 : romfs-list  ( -- )
122    romfs-base 0 cr BEGIN + dup (print-romfs-file-info) dup @ dup 0= UNTIL 2drop
123 ;