summaryrefslogtreecommitdiffstats
path: root/qemu/roms/SLOF/slof/fs/romfs.fs
blob: 7d7e4637eeac6b6c227c2732664d9b5431ddf68c (plain)
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
\ *****************************************************************************
\ * Copyright (c) 2004, 2008 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ *     IBM Corporation - initial implementation
\ ****************************************************************************/

STRUCT
	cell field romfs>file-header
	cell field romfs>data
	cell field romfs>data-size
	cell field romfs>flags

CONSTANT /romfs-lookup-control-block

CREATE romfs-lookup-cb /romfs-lookup-control-block allot
romfs-lookup-cb /romfs-lookup-control-block erase

: create-filename ( string -- string\0 )
    here >r dup 8 + allot
    r@ over 8 + erase
    r@ zplace r> ;

: romfs-lookup ( fn-str fn-len -- data size | false )
    create-filename romfs-base
    romfs-lookup-cb romfs-lookup-entry call-c
    0= IF romfs-lookup-cb dup romfs>data @ swap romfs>data-size @ ELSE
    false THEN ;

: ibm,romfs-lookup ( fn-str fn-len -- data-high data-low size | 0 0 false )
  romfs-lookup dup
  0= if drop 0 0 false else
  swap dup 20 rshift swap ffffffff and then ;

\ FIXME For a short time ...
: romfs-lookup-client ibm,romfs-lookup ;

\ Fixme temp implementation

STRUCT
	cell field romfs>next-off
	cell field romfs>size
	cell field romfs>flags
	cell field romfs>data-off
	cell field romfs>name

CONSTANT /romfs-cb

: romfs-map-file ( fn-str fn-len -- file-addr file-size )
  romfs-base >r
  BEGIN 2dup r@ romfs>name zcount string=ci not WHILE
    ( fn-str fn-len ) ( R: rom-cb-file-addr )
    r> romfs>next-off dup @ dup 0= IF 1 THROW THEN + >r REPEAT
    ( fn-str fn-len ) ( R: rom-cb-file-addr )
    2drop r@ romfs>data-off @ r@ + r> romfs>size @ ;

\ returns address of romfs-header file
: flash-header ( -- address | false )
    get-flash-base 28 +         \ prepare flash header file address
    dup rx@                     \ fetch "magic123"
    6d61676963313233 <> IF      \ IF flash is not valid
       drop                     \ | forget address
       false                    \ | return false
    THEN                        \ FI
;

CREATE bdate-str 10 allot
: bdate2human ( -- addr len )
  flash-header 40 + rx@ (.)
  drop dup 0 + bdate-str 6 + 4 move
  dup 4 + bdate-str 0 + 2 move
  dup 6 + bdate-str 3 + 2 move
  dup 8 + bdate-str b + 2 move
  a + bdate-str e + 2 move
  2d bdate-str 2 + c!
  2d bdate-str 5 + c!
  20 bdate-str a + c!
  3a bdate-str d + c!
  bdate-str 10
;


\ Look up a file in the ROM file system and evaluate it

: included  ( fn fn-len -- )
   2dup >r >r romfs-lookup dup IF
      r> drop r> drop evaluate
   ELSE
      drop ." Cannot open file : " r> r> type cr
   THEN
;

: include  ( " fn " -- )
   parse-word included
;

: ?include  ( flag " fn " -- )
   parse-word rot IF included ELSE 2drop THEN
;

: include?  ( nargs flag " fn " -- )
   parse-word rot IF
      rot drop included
   ELSE
      2drop 0 ?DO drop LOOP
   THEN
;


\ List files in ROMfs

: (print-romfs-file-info)  ( file-addr -- )
   9 emit  dup b 0.r  2 spaces  dup 8 + @ 6 0.r  2 spaces  20 + zcount type cr
;

: romfs-list  ( -- )
   romfs-base 0 cr BEGIN + dup (print-romfs-file-info) dup @ dup 0= UNTIL 2drop
;