Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: ttydriver.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 | \ id: @(#)ttydriver.fth 3.21 02/10/24 | |
43 | \ purpose: | |
44 | \ copyright: Copyright 1996-2002 Sun Microsystems, Inc. All Rights Reserved | |
45 | \ copyright: Use is subject to license terms. | |
46 | ||
47 | headerless | |
48 | ||
49 | \ The high level serial driver interface. | |
50 | \ provides all the standard routines and relies upon underlying | |
51 | \ | |
52 | \ usea, useb - to switch interfaces | |
53 | \ inituart - init current uart | |
54 | \ ukey? - can read? | |
55 | \ ukey - read single char | |
56 | \ uemit? - can transmit? | |
57 | \ uemit - write char | |
58 | \ ubreak? - break detected? | |
59 | \ clear-break - Cleanup after a BREAK | |
60 | \ | |
61 | ||
62 | : map-in ( offset len -- vaddr ) " map-in" $call-parent ; | |
63 | : map-out ( vaddr len -- ) " map-out" $call-parent ; | |
64 | ||
65 | : select-channel ( channel -- ) | |
66 | \ Point to the correct property name. Since the property is boolean, | |
67 | \ the information is conveyed by its presence, not its value. | |
68 | #channels 1 = if | |
69 | \ Grover or fiesta platforms | |
70 | " rts-dtr-off" | |
71 | else | |
72 | \ Excal or other sun4s platforms | |
73 | dup if " port-b-rts-dtr-off" else " port-a-rts-dtr-off" then | |
74 | then ( channel name$ ) | |
75 | get-my-property dup 0= if ( channel prop$ false | channel true ) | |
76 | nip nip ( channel false ) | |
77 | then ( channel flag ) | |
78 | is dtr-rts-on? ( channel ) | |
79 | ||
80 | \ Initialize channel | |
81 | if useb h# 02 else usea h# 01 then ( mask ) | |
82 | dup channel-init and ( mask set? ) | |
83 | if ( mask ) | |
84 | drop ( ) | |
85 | else ( mask ) | |
86 | channel-init or is channel-init ( ) | |
87 | inituart ( ) | |
88 | then | |
89 | ; | |
90 | ||
91 | : (open) ( arg$ -- okay? ) | |
92 | \ First time we are opened then we set uartbase and init serial line. | |
93 | uartbase 0= if ( arg$ ) | |
94 | tty-base my-space tty-size map-in ( arg$ va ) | |
95 | dup is uartbase 0= if ( arg$ ) | |
96 | 2drop false exit ( 0 ) | |
97 | then ( arg$ ) | |
98 | then | |
99 | ||
100 | >r >r ( ) | |
101 | 0 select-channel ( ) | |
102 | default-ttya-mode ( mode$ ) | |
103 | r> r> ( mode$ arg$ ) | |
104 | #channels 1- if ( mode$ arg$ ) | |
105 | ascii , left-parse-string if ( mode$ rem$ adr ) | |
106 | c@ ascii b = if ( mode$ rem$ ) | |
107 | >r >r ( mode$ ) | |
108 | 2drop ( ) | |
109 | 1 select-channel ( ) | |
110 | default-ttyb-mode ( mode$ ) | |
111 | r> r> ( mode$ rem$ ) | |
112 | then ( mode$ rem$ ) | |
113 | else ( mode$ rem$ adr ) | |
114 | drop ( mode$ rem$ ) | |
115 | then ( mode$ rem$ ) | |
116 | then ( mode$ rem$ ) | |
117 | dup if 2swap then 2drop ( mode$' ) | |
118 | ||
119 | 0 parse-mode ?dup 0= if ( ) | |
120 | default-tty-mode 0 parse-mode ( flag ) | |
121 | then ( flag ) | |
122 | dup if ( flag ) | |
123 | opencount 1+ is opencount ( ) | |
124 | then | |
125 | ; | |
126 | ||
127 | headers | |
128 | external | |
129 | ||
130 | : open ( -- flag ) my-args (open) ; | |
131 | ||
132 | : close ( -- ) | |
133 | opencount ?dup if 1- is opencount then | |
134 | opencount if exit then ( ) | |
135 | uartbase tty-size map-out ( ) | |
136 | false to channel-init ( ) | |
137 | false to uartbase ( ) | |
138 | ; | |
139 | ||
140 | : read ( adr len -- #read ) | |
141 | ukey? 0= if 2drop -2 exit then ( adr len ) | |
142 | tuck ( len adr len ) | |
143 | begin dup 0<> ukey? 0<> and while ( len adr len ) | |
144 | over ukey mask-#data and swap c! ( len adr len ) | |
145 | 1 /string ( len adr' len' ) | |
146 | repeat ( len adr' len' ) | |
147 | nip - ( #read ) | |
148 | ; | |
149 | ||
150 | : write ( adr len -- #written ) | |
151 | tuck bounds ?do ( len ) | |
152 | i c@ uemit ( len ) | |
153 | loop ( len ) | |
154 | begin uemit? until ( len ) | |
155 | ; | |
156 | ||
157 | : poll-tty ( -- ) | |
158 | ttylock @ if exit then | |
159 | ubreak? if clear-break user-abort then | |
160 | \ Give lower levels chance to work. | |
161 | ukey? drop | |
162 | ; | |
163 | ||
164 | : install-abort ( -- ) ['] poll-tty d# 10 alarm ; | |
165 | ||
166 | : remove-abort ( -- ) ['] poll-tty 0 alarm ; | |
167 | ||
168 | : restore ( -- ) ; |