Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / fm / kernel / sparc / filecode.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: filecode.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\ filecode.fth 2.9 02/05/02
43\ Copyright 1985-1990 Bradley Forthware
44\ Copyright 1990-2002 Sun Microsystems, Inc. All Rights Reserved
45\ Copyright Use is subject to license terms.
46
47\ Code words to support the file system interface - Sunrise versions
48
49headerless
50\ signed mixed mode addition (same as + on the Sunrise)
51code ln+ (s n1 n2 -- n3 ) sp scr pop tos scr tos add c;
52
53\ &ptr is the address of a pointer. fetch the pointed-to
54\ character and post-increment the pointer
55
56code @c@++ ( &ptr -- char )
57 tos scr get \ Fetch the pointer
58 tos sc1 move \ Copy of the address
59 scr 0 tos ldub \ Get the byte
60 scr 1 scr add \ Increment the pointer
61 scr sc1 put \ Replace the pointer
62c;
63
64\ &ptr is the address of a pointer. store the character into
65\ the pointed-to location and post-increment the pointer
66
67code @c!++ ( char &ptr -- )
68 tos scr get \ Fetch the pointer
69 sp sc1 pop \ char in sc1
70 sc1 scr 0 stb \ Put the byte
71 scr 1 scr add \ Increment the pointer
72 scr tos put \ Replace the pointer
73 sp tos pop \ Fixup top of stack
74c;
75
76\ "adr1 len2" is the longest initial substring of the string "adr1 len1"
77\ that does not contain the character "char". "adr2 len1-len2" is the
78\ trailing substring of "adr1 len1" that is not included in "adr1 len2".
79\ Accordingly, if there are no occurrences of that character in "adr1 len1",
80\ "len2" equals "len1", so the return values are "adr1 len1 adr1+len1 0"
81
82code split-string ( adr1 len1 char -- adr1 len2 adr1+len2 len1-len2 )
83 \ char in tos
84 sp 0 /n* sc1 nget \ len1
85 sp 1 /n* scr nget \ adr1
86 sp 1 /n* sp sub \ Make room for extra return value
87
88 scr sc1 scr add \ Point to end
89 %g0 sc1 sc3 sub \ Index counts up from -len1
90 sc3 1 sc3 sub \ Account for pre-increment
91
92 ahead
93 sc3 1 sc3 addcc \ Delay: Increment and test counter
94 begin
95
96 tos sc2 cmp \ Compare to delimiter
97 = if annul \ Exit if delimiter found
98 sc3 1 sc3 addcc \ Delay: Increment and test counter
99
100 sc1 sc3 sc1 add \ Compute len2
101 sc1 sp 1 /n* nput \ .. and store on stack
102
103 scr sc3 scr add \ Compute adr1+len2
104 scr sp 0 /n* nput \ .. and store on stack
105
106 %g0 sc3 tos sub \ Return len1-len2
107 next
108 then
109
110 but then
111 0= until annul
112 scr sc3 sc2 ldub \ Delay: Get the next character
113
114 \ The test character is not present in the input string
115
116 scr sp 0 /n* nput \ Store adr1+len2 on stack
117 %g0 tos move \ Return rem-len=0
118c;
119
120headers
121
122nuser delimiter \ delimiter actually found at end of word
123
124nuser file
125
126:-h struct ( -- 0 ) 00 ;-h
127
128\ Run-time action for fields
129code-field: dofield
130\itc sp adec
131 tos sp put \ Push the tos register
132\t16 apf scr lduh \ Get the structure member offset
133\t32 apf scr ld \ Get the structure member offset
134 'user file sc1 ld \ Get the structure base address
13564\ 'user file /l + sc2 ld
13664\ sc1 h# 20 sc1 sllx
13764\ sc2 sc1 sc1 or
138 sc1 scr tos add \ Return the structure member address
139c;
140
141\ Assembles the code field when metacompiling a field
142:-h file-field-cf ( -- ) dofield place-cf-t ;-h
143
144\ Metacompiler defining word for creating fields
145:-h file-field \ name ( offset scrze -- offset' )
146 " file-field-cf" header-t over
147\t32-t l,-t
148\t16-t w,-t
149 + ?debug
150;-h