Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / fm / lib / loclabel.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: loclabel.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\ loclabel.fth 2.10 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\ Local labels for the assembler.
48\ A local label can be inserted in an assembly-language program
49\ to mark a position. A relative branch instruction can then reference
50\ that location by its local name.
51\
52\ Local label names: 0 L: 1 L: 2 L: 3 L: etc.
53\ Local label forward references: 0 F: 1 F: etc
54\ Local label backward references: 0 B: 1 B: etc
55\
56\ There are 5 local labels, numbered 0 to 4.
57\ Each local label may be referenced from up to 10 locations.
58\
59decimal
60also assembler definitions
61
62headerless
6320 constant #references-max
6410 constant #labels-max
65
66#labels-max #references-max * /n* buffer: references
67#labels-max /n* buffer: local-labels
68#labels-max /n* buffer: next-references
69
70: >reference ( index -- adr ) /n* #references-max * references + ;
71
72: >label ( index -- adr ) local-labels swap na+ ;
73
74: >next-reference ( index -- adr ) next-references swap na+ ;
75
76: resolve-forward-references ( label# -- )
77 dup >next-reference @
78 [ also forth ] swap [ previous ] >reference
79
80 ?do i @ >resolve /n +loop
81;
82
83\ Erase all forward references from this label
84: clear-label ( label# -- ) dup >reference swap >next-reference ! ;
85
86headers
87: L: ( label# -- )
88 dup resolve-forward-references ( label# )
89 dup >label over >next-reference ! ( label# )
90 dup clear-label ( label# )
91 >label <mark [ also forth ] swap [ previous ] !
92;
93
94: B: ( label# -- adr ) \ Find the address of a backward reference
95 >label @ <resolve
96;
97
98: F: ( label# -- adr ) \ Remember a forward reference
99 >mark
100 over >next-reference @ !
101 /n [ also forth ] swap [ previous ] >next-reference +!
102 here \ the address we leave is a dummy
103;
104
105headerless
106: init-labels ( -- )
107 #labels-max 0 do i clear-label loop
108;
109
110init-labels
111
112[ifexist] do-label-hook
113
114' init-labels is do-label-hook
115
116[else]
117
118where ." Bootstrap code.." cr
119\ Bootstrapping..
120
121also forth definitions
122: code code [ also assembler ] init-labels [ previous ] ;
123: label label [ also assembler ] init-labels [ previous ] ;
124previous definitions
125
126[then]
127
128
129previous definitions