Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / os / bootprom / console.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: console.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: @(#)console.fth 1.8 01/05/30
43purpose: Implements console character I/O
44copyright: Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved
45
46\ Input and output selection mechanism
47
48headers
49nuser stdin 0 stdin !
50nuser stdout 0 stdout !
51
52headerless
530 value copy-down$
54nuser pending-char
55nuser char-pending?
56
57: "read" ( -- adr len ) " read" ; \ Space savings
58: "write" ( -- adr len ) " write" ; \ Space savings
59: stdin-getchar ( -- okay? )
60 pending-char 1 "read" stdin @ $call-method 1 =
61;
62: console-key? ( -- flag )
63 char-pending? @ if
64 true
65 else
66 stdin-getchar dup if char-pending? on then ( flag )
67 then
68;
69: console-key ( -- char )
70 char-pending? @ if
71 pending-char c@ char-pending? off
72 else
73 begin stdin-getchar until
74 pending-char c@
75 then
76;
77nuser temp-char
78
79stand-init: Allocate some space for string relocation
80 d# 82 alloc-mem is copy-down$
81;
82
83: (copy-down$) ( str,len -- str',len )
84 over d# 32 >> over d# 81 < and if ( str,len )
85 \ Sigh, we got a string we cant just send to FCODE.
86 copy-down$ tuck over ( str,adr,len adr,len )
87 2>r move 2r> ( adr,len )
88 then ( str,len )
89;
90
91\ break a write into 80 char chunks.
92: console-type ( adr len -- )
93 begin
94 dup while ( adr,len )
95 2dup d# 80 min ( adr,len adr,len' )
96 (copy-down$) "write" stdout @ $call-method >r ( adr,len )
97 r@ - swap r> + swap ( adr',len' )
98 repeat ( adr,len )
99 2drop ( )
100;
101: console-emit ( char -- ) temp-char c! temp-char 1 console-type ;
102
103\ close the device if it is not the stdout device.
104: ?close ( ihandle|0 -- )
105 ?dup if
106 stdout @ over <> if close-dev else drop then
107 then
108;
109: has-method? ( method-adr,len phandle -- flag )
110 find-method dup if nip then ( flag )
111;
112: .missing ( routine-adr,len type-adr,len -- )
113 ." The selected " type ." device has no " type ." routine" cr
114;
115
116: pihandle= ( phandle ihandle -- flag )
117 dup if ihandle>phandle = else 2drop false then
118;
119\ : already-opened? ( phandle -- flag ) stdout @ pihandle= ;
120
121headers
122: input ( pathname-adr,len -- )
123 2dup locate-device if
124 type ." not found." cr exit
125 else ( pathname-adr,len phandle )
126 \ Exit if already selected.
127 dup stdin @ pihandle= if
128 3drop exit
129 then
130 "read" rot has-method? if ( pathname-adr,len )
131 open-dev ?dup if ( ihandle )
132 stdin @ swap stdin ! ( old-ihandle )
133
134 " install-abort" stdin @ $call-method ( old-ihandle )
135 ?dup if ( old-ihandle )
136 " remove-abort" 2 pick $call-method ( old-ihandle )
137 close-dev
138 then
139 else
140 ." Can't open input device." cr exit
141 then
142 else ( pathname-adr,len )
143 2drop "read" " input" .missing exit
144 then
145 then
146;
147
148variable stdout-#lines \ For communication with client program
149' stdout-#lines " stdout-#lines" chosen-variable
150' stdin " stdin" chosen-variable
151' stdout " stdout" chosen-variable
152
153variable termemu-#lines \ For communication with terminal emulator
154
155headerless
156
157\ Set #lines in /chosen node for client programs to read
158: report-#lines ( -- )
159 termemu-#lines @ -1 <> if ( #lines )
160 \ The terminal emulator package set termemu-#lines
161 termemu-#lines @ ( #lines )
162 else ( #lines )
163
164 \ termemu-#lines was not set, so check for a "#lines" property
165 \ in the output device's package.
166
167 " #lines" stdout @ ihandle>phandle get-package-property if ( )
168 \ No "#lines" property; report "unknown"
169 -1 ( unknown-#lines )
170 else ( adr len )
171 \ Report the value of the "#lines" property
172 get-encoded-int ( #lines )
173 then ( #lines )
174 then ( #lines )
175 stdout-#lines !
176;
177
178headers
179: output ( pathname-adr,len -- )
180 2dup locate-device if ( pathname-adr,len )
181 type ." not found." cr exit
182 else ( pathname-adr,len phandle )
183 \ Exit if already selected.
184 dup stdout @ pihandle= if
185 3drop exit
186 then
187 "write" rot has-method? if ( pathname-adr,len )
188 -1 termemu-#lines ! \ Set value for terminal emulator to change
189 open-dev ?dup if ( ihandle )
190 stdout @ swap stdout ! ( old-ihandle )
191 ?close
192 report-#lines
193 else
194 ." Can't open output device." cr exit
195 then
196 else ( pathname-adr,len )
197 2drop "write" " output" .missing exit
198 then
199 then
200;
201
202: keyboard ( -- adr len ) " keyboard" ;
203: screen ( -- adr len ) " screen" ;
204: ttya ( -- adr len ) " ttya" ;
205: ttyb ( -- adr len ) " ttyb" ;
206
207: io ( pathname-adr,len -- )
208 2dup 2>r ( path$ ) ( r: path$ )
209 2r@ screen $= 2r> keyboard $= or if ( path$ )
210 2drop screen output keyboard input exit
211 then 2dup input output ( path$ )
212;
213
214: console-io ( -- )
215 stdin @ 0<>
216 stdout @ 0<> and if
217 char-pending? off
218 ['] console-key? is key?
219 ['] console-key is (key
220 ['] console-emit is (emit
221 ['] console-type is (type
222 then
223;
224
225headers