Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / os / bootprom / propenc.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: propenc.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 ============================================
42id: @(#)propenc.fth 1.5 98/04/08
43purpose: Property encoding and decoding primitives
44copyright: Copyright 1990 Sun Microsystems, Inc. All Rights Reserved
45
46\ External encoding and decoding for primitive data types
47
48\ Encode integers into a byte array, suitable for passing to Unix.
49\ Decode integers from a byte array.
50
51decimal
52headers
53\ Merge two property-encoded arrays into a single array
54\ Assumes that adr0+len0 == adr1
55: encode+ ( adr0 len0 adr1 len1 -- adr0 len0+len1 ) nip + ;
56
57
58\ Copy a byte array into the dictionary.
59: encode-bytes ( adr len -- adr' len )
60 here >r ( adr len )
61 bounds ?do i c@ c, loop ( rs: start )
62 r> here over - ( adr' len )
63;
64
65: decode-bytes ( adr1 len1 len2 -- adr1+len2 len1-len2 adr1 len2 )
66 >r over swap r@ /string rot r>
67;
68
69
70\ Copy a string to the dictionary, and add a null byte at the end
71: encode-string ( adr len -- adr' len+1 )
72 here >r ( adr len )
73 bounds ?do i c@ c, loop 0 c, ( ) ( rs: start )
74 r> here over - ( adr' len+1 )
75;
76
77\ adrb,lenb is the initial null-terminated string from the argument string.
78\ lenb does not include the null. adra lena is the remainder string.
79: decode-string ( adr len -- adra lena adrb lenb )
80 0 left-parse-string
81;
82: get-encoded-string ( adr len -- adr len-1 ) 1- ;
83
84\ Copy an int as 4 bytes to the dictionary
85: encode-int ( i -- adr len ) here swap be-l, /l ;
86
87: decode-int ( adr len -- adr' len' n )
88 over be-l@ >r /l /string r>
89;
90: get-encoded-int ( adr len -- n ) drop be-l@ ;
91
92headerless
93
94: ?base ( adr len -- adr' len' )
95 dup 2 > if ( adr len )
96 over c@ ascii 0 = if ( adr len )
97 over 1+ c@ ascii x = if ( adr len )
98 hex 2 /string ( adr+2 len-2 )
99 else ( adr len )
100 octal 1 /string ( adr+1 len-1 )
101 then ( adr' len' )
102 then ( adr' len' )
103 then ( adr' len' )
104;
105
106headers
107: encode-number ( adr len apf -- n )
108 drop ( adr,len )
109 base @ >r decimal ( adr,len ) ( r: base )
110 ?base strip-blanks ( adr',len' ) ( r: base )
111 $number r> base ! if ( )
112 p" bad-number" throw ( )
113 then ( n )
114;