Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / arch / sun / reset / common.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: common.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: @(#)common.fth 1.2 06/02/16
43purpose:
44copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47: ,string ( adr,len -- )
48 here over allot place-cstr drop
49;
50: ,decimal ( n -- )
51 base @ >r decimal
52 <# u#s u#> here over allot place-cstr drop
53 r> base !
54;
55
56create sccs-id
57 " "r"n@(#)OBP " ,string
58 obp-release count ,string
59 " " ,string
60 compile-signature compile-date$ ,string
61[ifndef] SUN4V
62 banner-name$ dup if " " ,string ,string else 2drop then
63[then]
64 sub-release count ?dup if " " ,string ,string else drop then
65 0 c,
66
670 value obj-base
680 value obj-size
69
70also assembler definitions
71
72[ifexist] eprom-pa
73: >prom-addr ( symbol -- pa ) obj-base - eprom-pa + ;
74[then]
75
76: $set-external ( name$ register -- )
77 >r ( name$ ) ( r: reg)
78 0 r@ sethi ( $name ) ( r: reg )
79 2>r here obj-base - 4 - 2r> ( adr $name ) ( r: reg )
80 3dup ( adr $name adr $name ) ( r: reg )
81 $set-reference-hi22 ( adr name$ ) ( r: reg )
82 r@ 0 r> or ( adr name$ )
83 here obj-base - 4 - -rot ( adr adr2 name$ )
84 $set-reference-lo10 ( adr )
85 drop
86;
87
88: $export-procedure ( adr name$ -- )
89 rot obj-base - -rot external-procedure $add-symbol
90;
91
92: $acall ( procedure-name$ -- )
93 [ also assembler ]
94
95 here call \ make space for relocatable addr
96 here 4 - obj-base - ( procedure-name$ offset )
97 -rot $add-call \ symtab entry
98 [ previous ]
99;
100
101: clear-call-stack
102 %o7 %g6 move
103 here 8 + call nop
104 here 8 + call nop
105 here 8 + call nop
106 here 8 + call nop
107 here 8 + call nop
108 here 8 + call nop
109 here 8 + call nop
110 here 8 + call nop
111 %g6 %o7 move
112;
113
114previous definitions
115also srassembler alias $export-procedure $export-procedure previous
116
117: dropin-size ( -- n )
118 decomp-size 4 round-up
119 obj-size 4 round-up +
120 h# 20 - \ Drop-in Header Size
121;
122
123: save-obj ( pstr -- )
124 terminate-string-table
125 new-file
126
127 dropin-magic obj-base 0 la+ l! \ MAGIC
128 dropin-size obj-base 1 la+ l! \ Size
129 0 obj-base 2 la+ l! \ Reserved
130 0 obj-base 3 la+ l! \ Reserved
131 0 obj-base 4 la+ x!
132 " OBP" obj-base 4 la+ place-cstr drop
133 compile-signature xlsplit obj-base d# 11 wa+ w!
134 ( date.time ) obj-base d# 6 la+ l!
135 0 obj-base d# 7 la+ l!
136 major-release# obj-base d# 28 ca+ c!
137 minor-release# obj-base d# 29 ca+ c!
138 patch-release# obj-base d# 30 ca+ c!
139 h# 7f obj-base d# 31 ca+ c!
140
141 /elf32-header /section-headers + ( first-offset )
142
143 /section-names 1 !loc \ Section name table size
144 obj-size 2 !loc \ Text size
145 0 3 !loc \ Data size
146 0 4 !loc \ BSS size
147 /relocation-table 5 !loc \ Text reloc. table size
148 0 6 !loc \ Data reloc. table size
149 /symbol-table 7 !loc \ Symbol table size
150 /string-table 8 !loc \ String table size
151 drop
152
153 default-elf-header /elf32-header ofd @ fputs \ ELF header
154 section-headers /section-headers ofd @ fputs \ Section headers
155 section-names /section-names ofd @ fputs \ Section name table
156
157 obj-base obj-size ofd @ fputs
158
159 relocation-table /relocation-table ofd @ fputs
160 symbol-table /symbol-table ofd @ fputs
161 string-table /string-table ofd @ fputs
162
163 ofd @ fclose
164;
165
1660 value symbol.fd
167
168: begin-obj ( -- )
169 [ also assembler ] init-labels [ previous ]
170 h# 1000 [ also assembler ] .align [ previous ]
171 here is obj-base
172 p" reset.symbols" new-file ofd @ is symbol.fd
173 " # This is a machine generated file"r"n" symbol.fd fputs
174;
175
176: end-obj ( -- )
177 end-code here obj-base - to obj-size
178 symbol.fd ?dup if fclose then
179;
180
1810 value in-label?
182: (check-stack) ( -- )
183 depth if
184 where lastacf .name
185 depth 0< if ." underflowed" else ." mangled" then
186 ." the stack" cr abort
187 then
188;
189
190: (write-trace) ( N -- )
191 symbol.fd if
192 " trace: " symbol.fd fputs
193 here obj-base - push-hex (u.) pop-base symbol.fd fputs
194 " ," symbol.fd fputs
195 push-hex (u.) pop-base symbol.fd fputs
196 " "r"n" symbol.fd fputs
197 else
198 drop
199 then
200;
201
202: label ( -- )
203 (check-stack)
204 in-label? if
205 where
206 ." end-code missing from " lastacf .name
207 ." .. Sequential labels are not allowed!!" cr
208 abort
209 then
210 true to in-label?
211 align here transient value resident
212 symbol.fd if
213 lastacf >name name>string symbol.fd fputs
214 " : " symbol.fd fputs
215 lastacf execute obj-base - push-hex (u.) pop-base symbol.fd fputs
216 " "r"n" symbol.fd fputs
217 then
218 do-entercode
219;
220
221also assembler definitions
222: end-code ( -- )
223 0 to in-label? (check-stack)
224 do-exitcode
225;
226previous definitions