Skip to content

Commit 91c7df5

Browse files
author
Stefan Reinauer
committed
localvalues support, contributed by David Paktor <[email protected]>
git-svn-id: svn://coreboot.org/openbios/fcode-utils@102 f158a5a8-5612-0410-a976-696ce0be7e32
1 parent 26375b4 commit 91c7df5

File tree

5 files changed

+286
-0
lines changed

5 files changed

+286
-0
lines changed

localvalues/GlobalLocalValues.fth

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
\ (C) Copyright 2005 IBM Corporation. All Rights Reserved.
2+
\ Licensed under the Common Public License (CPL) version 1.0
3+
\ for full details see:
4+
\ http://www.opensource.org/licenses/cpl1.0.php
5+
\
6+
\ Module Author: David L. Paktor [email protected]
7+
8+
\ Load Locals Support under Global-Definitions. Bypass Instance warning
9+
10+
\ Make sure this option is turned on.
11+
[flag] Local-Values
12+
13+
global-definitions
14+
15+
\ Bypass warning about Instance without altering LocalValuesSupport file
16+
alias generic-instance instance
17+
[macro] bypass-instance f[ noop .( Bypassed instance!) f]
18+
19+
overload alias instance bypass-instance
20+
21+
fload LocalValuesSupport.fth
22+
23+
\ Replace normal meaning of Instance, still in Global scope.
24+
overload alias instance generic-instance
25+
26+
\ Restore Device-Definitions scope.
27+
device-definitions
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
\ (C) Copyright 2005 IBM Corporation. All Rights Reserved.
2+
\ Licensed under the Common Public License (CPL) version 1.0
3+
\ for full details see:
4+
\ http://www.opensource.org/licenses/cpl1.0.php
5+
\
6+
\ Module Author: David L. Paktor [email protected]
7+
8+
\ Load Support file for development of FCode that uses Local Values
9+
\ under Global-Definitions. Bypass Instance warning.
10+
\ Replace this with GlobalLocalValues.fth in your final product.
11+
12+
\ Make sure this option is turned on.
13+
[flag] Local-Values
14+
15+
global-definitions
16+
17+
\ Bypass warning about Instance without altering LocalValuesSupport file
18+
alias generic-instance instance
19+
[macro] bypass-instance f[ noop .( Bypassed instance!) f]
20+
21+
overload alias instance bypass-instance
22+
23+
fload LocalValuesSupport.fth
24+
fload LocalValuesDevelSupport.fth
25+
26+
\ Replace normal meaning of Instance, still in Global scope.
27+
overload alias instance generic-instance
28+
29+
\ Restore Device-Definitions scope.
30+
device-definitions
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
\ (C) Copyright 2005 IBM Corporation. All Rights Reserved.
2+
\ Licensed under the Common Public License (CPL) version 1.0
3+
\ for full details see:
4+
\ http://www.opensource.org/licenses/cpl1.0.php
5+
\
6+
\ Module Author: David L. Paktor [email protected]
7+
8+
\ Support file for development of FCode that uses Local Values
9+
\ FLoad this right after LocalValuesSupport.fth
10+
\ Remove it from your final product.
11+
12+
\ Exported Function: max-local-storage-size ( -- n )
13+
\ Returns the measured maximum size of storage for Local Values
14+
\ used by any given test run. This number can be used to guide
15+
\ the declaration of _local-storage-size_
16+
\
17+
\ (C) Copyright 2005 IBM Corporation. All Rights Reserved.
18+
\ Module Author: David L. Paktor [email protected]
19+
20+
\ Count the current depth on a per-instance basis,
21+
\ but collect the maximum depth over all instances.
22+
23+
headers
24+
0 instance value local-storage-depth
25+
26+
external
27+
0 value max-local-storage-size
28+
headers
29+
30+
\ Overload the {push-locals} and {pop-locals} routines to do this.
31+
\ Do not suppress the overload warnings; they'll serve as a reminder.
32+
: {pop-locals} ( #locals -- )
33+
local-storage-depth over - to local-storage-depth
34+
{pop-locals}
35+
;
36+
37+
: {push-locals} ( #ilocals #ulocals -- )
38+
2dup + local-storage-depth +
39+
dup to local-storage-depth
40+
max-local-storage-size max
41+
to max-local-storage-size
42+
{push-locals}
43+
;
44+
45+

localvalues/LocalValuesSupport.fth

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
\ (C) Copyright 2005 IBM Corporation. All Rights Reserved.
2+
\ Licensed under the Common Public License (CPL) version 1.0
3+
\ for full details see:
4+
\ http://www.opensource.org/licenses/cpl1.0.php
5+
\
6+
\ Module Author: David L. Paktor [email protected]
7+
8+
\ The support routines for Local Values in FCode.
9+
10+
\ Function imported
11+
\ _local-storage-size_ \ Size, in cells, of backing store for locals
12+
\ \ A constant. If not supplied, default value of d# 64 will be used.
13+
\
14+
\ Functions exported:
15+
\ {push-locals} ( #ilocals #ulocals -- )
16+
\ {pop-locals} ( #locals -- )
17+
\ _{local} ( local-var# -- addr )
18+
\
19+
\ Additional overloaded function:
20+
\ catch \ Restore Locals after a throw
21+
22+
\ The user is responsible for declaring the maximum depth of the
23+
\ run-time Locals stack, in storage units, by defining the
24+
\ constant _local-storage-size_ before floading this file.
25+
\ The definition may be created either by defining it as a constant
26+
\ in the startup-file that FLOADs this and other files in the
27+
\ source program, or via a command-line user-symbol definition
28+
\ of a form resembling: -d '_local-storage-size_=d# 42'
29+
\ (be sure to enclose it within quotes so that the shell treats
30+
\ it as a single string, and, of course, replace the "42" with
31+
\ the actual number you need...)
32+
\ If both forms are present, the command-line user-symbol value will
33+
\ be used to create a duplicate definition of the named constant,
34+
\ which will prevail over the earlier definition, and will remain
35+
\ available for examination during development and testing. The
36+
\ duplicate-name warning, which will not be suppressed, will also
37+
\ act to alert the developer of this condition.
38+
\ To measure the actual usage (in a test run), use the separate tool
39+
\ found in the file LocalValuesDevelSupport.fth .
40+
\ If the user omits defining _local-storage-size_ the following
41+
\ ten-line sequence will supply a default:
42+
43+
[ifdef] _local-storage-size_
44+
f[ [defined] _local-storage-size_ true ]f
45+
[else]
46+
[ifexist] _local-storage-size_
47+
f[ false ]f
48+
[else]
49+
f[ d# 64 true ]f
50+
[then]
51+
[then] ( Compile-time: size true | false )
52+
[if] fliteral constant _local-storage-size_ [then]
53+
54+
_local-storage-size_ \ The number of storage units to allocate
55+
cells \ Convert to address units
56+
dup \ Keep a copy around...
57+
( n ) instance buffer: locals-storage \ Use one of the copies
58+
59+
\ The Locals Pointer, added to the base address of locals-storage
60+
\ points to the base-address of the currently active set of Locals.
61+
\ Locals will be accessed as a positive offset from there.
62+
\ Start the Locals Pointer at end of the buffer.
63+
\ A copy of ( N ), the number of address units that were allocated
64+
\ for the buffer, is still on the stack. Use it here.
65+
( n ) instance value locals-pointer
66+
67+
\ Support for {push-locals}
68+
69+
\ Error-check.
70+
: not-enough-locals? ( #ilocals #ulocals -- error? )
71+
+ cells locals-pointer swap - 0<
72+
;
73+
74+
\ Error message.
75+
: .not-enough-locals ( -- )
76+
cr ." FATAL ERROR: Local Values Usage exceeds allocation." cr
77+
;
78+
79+
\ Detect, announce and handle error.
80+
: check-enough-locals ( #ilocals #ulocals -- | <ABORT> )
81+
not-enough-locals? if
82+
.not-enough-locals
83+
abort
84+
then
85+
;
86+
87+
\ The uninitialized locals can be allocated in a single batch
88+
: push-uninitted-locals ( #ulocals -- )
89+
cells locals-pointer swap - to locals-pointer
90+
;
91+
92+
\ The Initialized locals are initted from the items on top of the stack
93+
\ at the start of the routine. If we allocate them one at a time,
94+
\ we get them into the right order. I.e., the last-one named gets
95+
\ the top item, the earlier ones get successively lower items.
96+
: push-one-initted-local ( pstack-item -- )
97+
locals-pointer 1 cells -
98+
dup to locals-pointer
99+
locals-storage + !
100+
;
101+
102+
\ Push all the Initialized locals.
103+
: push-initted-locals ( N_#ilocals-1 ... N_0 #ilocals -- )
104+
0 ?do push-one-initted-local loop
105+
;
106+
107+
: {push-locals} ( N_#ilocals ... N_1 #ilocals #ulocals -- )
108+
2dup check-enough-locals
109+
push-uninitted-locals ( ..... #i )
110+
push-initted-locals ( )
111+
;
112+
113+
\ Pop all the locals.
114+
\ The param is the number to pop.
115+
: {pop-locals} ( total#locals -- )
116+
cells locals-pointer + to locals-pointer
117+
;
118+
119+
\ The address from/to which values will be moved, given the local-var#
120+
: _{local} ( local-var# -- addr )
121+
cells locals-pointer + locals-storage +
122+
;
123+
124+
\ We need to overload catch such that the state of the Locals Pointer
125+
\ will be preserved and restored after a throw .
126+
overload : catch ( ??? xt -- ???' false | ???'' throw-code )
127+
locals-pointer >r ( ??? xt ) ( R: old-locals-ptr )
128+
catch ( ???' false | ???'' throw-code ) ( R: old-locals-ptr )
129+
\ No need to inspect the throw-code.
130+
\ If catch returned a zero, the Locals Pointer
131+
\ is valid anyway, so restoring it is harmless.
132+
r> to locals-pointer
133+
;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
\ (C) Copyright 2005-2006 IBM Corporation. All Rights Reserved.
2+
\ Licensed under the Common Public License (CPL) version 1.0
3+
\ for full details see:
4+
\ http://www.opensource.org/licenses/cpl1.0.php
5+
\
6+
\ Module Author: David L. Paktor [email protected]
7+
8+
\ Control file for loading of Local Values Support file with variants.
9+
\ Command-line Symbol-definitions select whether the support will
10+
\ be under Global-Definitions, and whether to include the extra
11+
\ Development-time support features.
12+
\
13+
\ The command-line symbols are:
14+
\ Global-Locals
15+
\ and
16+
\ Locals-Release
17+
\
18+
\ The default is device-node-specific support in a Development-time setting.
19+
\
20+
\ If Global-Locals is defined, support will be under Global-Definitions
21+
\ If Locals-Release is defined, this is a final production release run,
22+
\ and the Development-time support features will be removed.
23+
24+
\ Make sure this option is turned on.
25+
[flag] Local-Values
26+
27+
[ifdef] Global-Locals
28+
\ Load Support file under Global-Definitions.
29+
global-definitions
30+
31+
\ Bypass warning about Instance without altering LocalValuesSupport file
32+
alias generic-instance instance
33+
[macro] bypass-instance f[ noop .( Bypassed instance!) f]
34+
35+
overload alias instance bypass-instance
36+
[endif] \ Global-Locals
37+
38+
fload LocalValuesSupport.fth
39+
40+
[ifndef] Locals-Release
41+
\ Load Development-time support features
42+
fload LocalValuesDevelSupport.fth
43+
[endif] \ not Locals-Release
44+
45+
[ifdef] Global-Locals
46+
\ Replace normal meaning of Instance, still in Global scope.
47+
overload alias instance generic-instance
48+
49+
\ Restore Device-Definitions scope.
50+
device-definitions
51+
[endif] \ Global-Locals

0 commit comments

Comments
 (0)