Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / fm / cwrapper / sparc / boot.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: boot.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: @(#)boot.fth 2.16 07/06/05
43copyright: Copyright 1985-1990 Bradley Forthware
44copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
45copyright: Use is subject to license terms.
46
47\ ident "@(#)boot.fth 2.16 07/06/05 SMI"
48
49\ Version for running Forth as a Unix user process
50
51\ Boot code (cold and warm start). The cold start code is executed
52\ when Forth is initially started. Its job is to initialize the Forth
53\ virtual machine registers. The warm start code is executed when Forth
54\ is re-entered, perhaps as a result of an exception.
55
56hex
57
58only forth also labels also meta also definitions
59
600 constant main-task
61
62headerless
63
64\ Stuff initialized at cold start time
65
66nuser memtop \ The top of the memory used by Forth
67headers
680 value #args \ The process's argument count
690 value args \ The process's argument list
70headerless
71label cold-code ( -- )
72
73\ called with forth_startup(header-adr, functions, mem_end, &gargc, &gargv)
74\ %i0 %i1 %i2 %i3 %i4
75
76\ Get some registers
77 %o6 -10 /l* %o6 save \ Propagate stack pointer to new frame
78
79\ Find the base address
80 here-t 4 + call \ Absolute address of next instruction
81 here-t 4 - base set \ Relative address of this instruction
82 %o7 base base sub \ Base address of Forth kernel
83
84\ Allocate high memory for the stacks and stuff, starting at memtop and
85\ allocating downwards. %i2 is the allocation pointer.
86
87 %i2 %l6 move \ We'll need this later for memtop
88
89\ Find the user area size from the header
90 %i0 8 %l4 ld \ Data size = user area size in %l4
91
92\ Allocate the RAM copy of the User Area
93 %i2 %l4 %i2 sub
94 %i2 up move \ Set user pointer
95
96 'body main-task %l3 set \ Allow the exception handler to find the
97 base %l3 %l5 add \ user area by storing the address of the
9832\ up %l5 2 sth \ main user area in the "constant" main-task
9932\ up th 10 %l3 srl
10032\ %l3 %l5 0 sth
101
10264\ up %l5 6 sth \ main user area in the "constant" main-task
10364\ up th 10 %l3 srlx
10464\ %l3 %l5 4 sth
10564\ %l3 th 10 %l3 srlx
10664\ %l3 %l5 2 sth
10764\ %l3 th 10 %l3 srlx
10864\ %l3 %l5 0 sth
109
110\ Copy the initial User Area image to the RAM copy
111 %i0 4 %l3 ld \ Text size = offset to start of data
112 base %l3 %l3 add \ Init-up pointer in %l3
113
114 begin
115 %l4 4 %l4 subcc
116 %l3 %l4 %l5 ld
117 0= until
118 %l5 up %l4 st \ Delay slot
119
120\ Now the user area has been copied to the proper place, so we can set
121\ some important user variables whose inital values are determined at
122\ run time.
123
124\ Set the value of #args and args
125 %i3 'user #args nput
126 %i4 'user args nput
127
128\ Top of memory and dictionary limit
129 %l6 'user memtop nput
130
131\ Set the up0 user variable
132 up 'user up0 nput
133
134\ Establish the return stack and set the rp0 user variable
135 %i2 rp move \ Set rp
136 rp 'user .rp0 nput
137 %i2 rs-size-t %i2 sub \ allocate space for the return stack
138
139\ Establish the Parameter Stack
140 %i2 'user .sp0 nput
141 %i2 /n sp add \ /n accounts for the top of stack register
142
143 %i2 ps-size-t %i2 sub \ Allocate the stuff on the stack
144
145\t16 h# 1.0000 %l6 set
146\t16 %l6 tshift-t %l6 sll
147\t16 %l6 base %l6 add \ limit is origin + (64K << tokenshift)
148 %l6 %i2 cmp
149 u< if nop
150 %l6 %i2 move
151 then
152 %i2 'user limit nput
153
154\ Save the address of the system call table in the user variable syscall-vec
155 %i1 up syscall-user# nput
156
157\ Set the dictionary pointer
158 %i0 4 %l0 ld \ Text size
159 base %l0 %l0 add \ Base + text
160 %l0 'user dp nput \ Set dp
161
162\ Enter Forth
163 'body cold ip set
164 ip base ip add
165c;
166
167headers