Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: util.fth | |
4 | \ | |
5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | \ | |
7 | \ - Do no alter or remove copyright notices | |
8 | \ | |
9 | \ - Redistribution and use of this software in source and binary forms, with | |
10 | \ or without modification, are permitted provided that the following | |
11 | \ conditions are met: | |
12 | \ | |
13 | \ - Redistribution of source code must retain the above copyright notice, | |
14 | \ this list of conditions and the following disclaimer. | |
15 | \ | |
16 | \ - Redistribution in binary form must reproduce the above copyright notice, | |
17 | \ this list of conditions and the following disclaimer in the | |
18 | \ documentation and/or other materials provided with the distribution. | |
19 | \ | |
20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors | |
21 | \ may be used to endorse or promote products derived from this software | |
22 | \ without specific prior written permission. | |
23 | \ | |
24 | \ This software is provided "AS IS," without a warranty of any kind. | |
25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
36 | \ | |
37 | \ You acknowledge that this software is not designed, licensed or | |
38 | \ intended for use in the design, construction, operation or maintenance of | |
39 | \ any nuclear facility. | |
40 | \ | |
41 | \ ========== Copyright Header End ============================================ | |
42 | id: @(#)util.fth 2.26 03/12/08 13:22:26 | |
43 | purpose: | |
44 | copyright: Copyright 1994-2003 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Copyright 1985-1994 Bradley Forthware | |
46 | copyright: Use is subject to license terms. | |
47 | ||
48 | hex | |
49 | headerless0 | |
50 | ||
51 | alias (s ( | |
52 | ||
53 | : >user# ( acf -- user# ) >body >user up@ - ; | |
54 | : 'user# \ name ( -- user# ) | |
55 | ' ( acf-of-user-variable ) >user# | |
56 | ; | |
57 | headers | |
58 | \ : tr ( token-bits -- adr ) \ Token relocate | |
59 | \ \t16 tshift << | |
60 | \ origin+ | |
61 | \ ; | |
62 | : x ( adr -- ) execute ; \ Convenience word | |
63 | \ : .cstr ( adr -- ) \ Display C string | |
64 | \ begin dup c@ ?dup while | |
65 | \ dup newline = if drop cr else emit then | |
66 | \ 1+ | |
67 | \ repeat | |
68 | \ drop | |
69 | \ ; | |
70 | ||
71 | : .h ( n -- ) push-hex . pop-base ; | |
72 | : .x ( u -- ) push-hex u. pop-base ; | |
73 | : .d ( n -- ) push-decimal . pop-base ; | |
74 | ||
75 | defer lo-segment-base ' origin is lo-segment-base | |
76 | defer lo-segment-limit ' origin is lo-segment-limit | |
77 | defer hi-segment-base ' first-code-word is hi-segment-base | |
78 | \ XXX Later, we may change first-code-word to low-dictionary-adr | |
79 | defer hi-segment-limit ' here is hi-segment-limit | |
80 | ||
81 | : dictionary-size ( -- n ) here origin- ; | |
82 | ||
83 | headerless | |
84 | ||
85 | : #! ( -- ) [compile] \ ; immediate \ For use with script files | |
86 | alias >is >data \ Backwards compatibility | |
87 | ||
88 | : strip-blanks ( adr,len -- adr',len' ) -leading -trailing ; | |
89 | : optional-arg$ ( -- adr len ) 0 parse strip-blanks ; | |
90 | ||
91 | headers | |
92 | ||
93 | alias not invert | |
94 | alias eval evaluate | |
95 | ||
96 | : c? ( adr -- ) c@ u. ; | |
97 | : w? ( adr -- ) w@ u. ; | |
98 | : l? ( adr -- ) l@ u. ; | |
99 | 64\ : x? ( adr -- ) x@ u. ; | |
100 | : d? ( adr -- ) d@ swap u. u. ; | |
101 | ||
102 | \ : behavior ( xt1 -- xt2 ) >body >user token@ ; | |
103 | ||
104 | : showstack ( -- ) ['] (.s is status ; | |
105 | : noshowstack ( -- ) ['] noop is status ; | |
106 | ||
107 | \ Default value is yes | |
108 | : confirmed? ( adr len -- yes? ) | |
109 | type ." [y/n]? " key dup emit cr upc ascii N <> | |
110 | ; | |
111 | ||
112 | : lowmask ( #bits -- mask ) 1 swap lshift 1- ; | |
113 | : lowbits ( n #bits -- bits ) lowmask and ; | |
114 | ||
115 | \ : many ( -- ) key? 0= if 0 >in ! then ; | |
116 | ||
117 | : .lx ( n -- ) push-hex [ /l 2* 1+ ] literal u.r pop-base ; | |
118 | : .nx ( l -- ) push-hex [ /n 2* 1+ ] literal u.r pop-base ; | |
119 | : .ndump ( adr n -- ) /n* bounds ?do i @ .nx /n +loop ; | |
120 | ||
121 | : .buffers ( -- ) | |
122 | buffer-link ( next-buffer-word ) | |
123 | begin another-link? while ( acf ) | |
124 | dup .name ( acf ) | |
125 | dup >body ( acf apf ) | |
126 | dup >user @ .x ( acf apf ) \ Show buffer-addr | |
127 | /buffer .x ( acf ) \ Show buffer-size | |
128 | cr | |
129 | exit? if drop exit then ( acf ) | |
130 | >buffer-link ( prev-buffer:-acf ) | |
131 | repeat ( ) | |
132 | ; | |
133 | ||
134 | [ifnexist] bits \ Might be defined in code | |
135 | : bits ( N #bits -- N' bits ) | |
136 | 2dup >> -rot ( N' N #bits ) | |
137 | 1 swap << 1- ( N' N bitmask ) | |
138 | and ( N' bits ) | |
139 | ; | |
140 | [then] | |
141 | ||
142 | \ Keep the "flip" words here. | |
143 | \ We want them in the desktop FORTH as well... | |
144 | alias wbflip flip | |
145 | alias lwflip wflip | |
146 | ||
147 | : wbflips ( adr len -- ) | |
148 | bounds ?do | |
149 | i unaligned-w@ wbflip i unaligned-w! | |
150 | /w +loop | |
151 | ; | |
152 | : lwflips ( adr len -- ) | |
153 | bounds ?do | |
154 | i unaligned-l@ lwflip i unaligned-l! | |
155 | /l +loop | |
156 | ; | |
157 | : lbflip ( n1 -- n2 ) lwsplit wbflip swap wbflip wljoin ; | |
158 | : lbflips ( adr len -- ) | |
159 | bounds ?do | |
160 | i unaligned-l@ lbflip i unaligned-l! | |
161 | /l +loop | |
162 | ; | |
163 | ||
164 | false | |
165 | 64\ drop true | |
166 | [if] | |
167 | : xbflip ( x -- x' ) xlsplit lbflip swap lbflip lxjoin ; | |
168 | : xlflip ( x -- x' ) xlsplit swap lxjoin ; | |
169 | : xwflip ( x -- x' ) xlsplit lwflip swap lwflip lxjoin ; | |
170 | ||
171 | : xbflips ( adr,len -- ) | |
172 | bounds ?do | |
173 | i unaligned-@ xbflip i unaligned-! | |
174 | /x +loop | |
175 | ; | |
176 | : xlflips ( adr,len -- ) | |
177 | bounds ?do | |
178 | i unaligned-@ xlflip i unaligned-! | |
179 | /x +loop | |
180 | ; | |
181 | : xwflips ( adr,len -- ) | |
182 | bounds ?do | |
183 | i unaligned-@ xwflip i unaligned-! | |
184 | /x +loop | |
185 | ; | |
186 | [then] |