Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: sys.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: @(#)sys.fth 2.20 07/06/05 10:54:56 | |
43 | purpose: | |
44 | copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | \ Copyright 1985-1990 Bradley Forthware | |
47 | ||
48 | \ Very-low-level interfaces to the Sun 4.2 BSD version of Unix | |
49 | \ These routines may have to be rewritten for other flavors of | |
50 | \ Unix, because the mechanism for doing system calls may differ. | |
51 | \ The names and the stack diagrams should not need to change, however. | |
52 | ||
53 | \ The wrapper is expected to implement the forth stack semantics of the | |
54 | \ routines and match the stack direction. | |
55 | \ | |
56 | decimal | |
57 | ||
58 | headerless | |
59 | ||
60 | /l ualloc-t dup equ syscall-user# | |
61 | headers | |
62 | user syscall-vec \ long address of system call vector | |
63 | headerless | |
64 | ||
65 | nuser sysretval | |
66 | ||
67 | \ I/O for running under Unix with a C program providing actual I/O routines | |
68 | ||
69 | headers | |
70 | meta | |
71 | 0 [if] | |
72 | code syscall? ( call# -- ok? ) \ For backwards compatibility | |
73 | 'user syscall-vec %l0 nget | |
74 | bubble | |
75 | 32\ tos 2 tos slln \ multiply by 4 | |
76 | 64\ tos 3 tos slln \ multiply by 8 | |
77 | %l0 tos %l0 ld \ Address of routine | |
78 | %l0 %g0 %g0 subcc | |
79 | 0= if | |
80 | %g0 1 tos sub \ (delay) | |
81 | %g0 tos move | |
82 | then | |
83 | c; | |
84 | [then] | |
85 | ||
86 | code syscall ( ?? call# -- ?? ) \ For backwards compatibility | |
87 | \ Get address of system call table | |
88 | 'user syscall-vec %l0 nget | |
89 | bubble | |
90 | 32\ tos 2 tos slln \ multiply by 4 | |
91 | 64\ tos 3 tos slln \ multiply by 8 | |
92 | %l0 tos %l0 nget \ Address of routine | |
93 | sp tos pop | |
94 | tos %o0 move \ Get some arguments | |
95 | sp 0 /n* %o1 nget | |
96 | sp 1 /n* %o2 nget | |
97 | sp 2 /n* %o3 nget | |
98 | sp 3 /n* %o4 nget | |
99 | sp 4 /n* %o5 nget | |
100 | %g2 %l2 move | |
101 | %g3 %l3 move | |
102 | %g4 %l4 move | |
103 | %g5 %l5 move | |
104 | %g6 %l6 move | |
105 | %g7 %l7 move | |
106 | %l0 %g0 %o7 jmpl | |
107 | %g1 %l1 move \ Delay slot | |
108 | ||
109 | %l1 %g1 move | |
110 | %l2 %g2 move | |
111 | %l3 %g3 move | |
112 | %l4 %g4 move | |
113 | %l5 %g5 move | |
114 | %l6 %g6 move | |
115 | %l7 %g7 move | |
116 | ||
117 | %o0 'user sysretval nput \ Save the result | |
118 | ||
119 | c; | |
120 | ||
121 | \ A syscall wrapper that uses the stack so that the wrapper can return | |
122 | \ data on the forth stacks. | |
123 | \ | |
124 | code fsyscall ( ?? call# -- ?? ) | |
125 | 'user syscall-vec %l0 nget | |
126 | bubble | |
127 | 32\ tos 2 tos slln \ multiply by 4 | |
128 | 64\ tos 3 tos slln \ multiply by 8 | |
129 | %l0 tos %l0 nget \ Address of routine | |
130 | sp %o0 move | |
131 | %g2 %l2 move | |
132 | %g3 %l3 move | |
133 | %g4 %l4 move | |
134 | %g5 %l5 move | |
135 | %g6 %l6 move | |
136 | %g7 %l7 move | |
137 | %l0 %g0 %o7 jmpl | |
138 | %g1 %l1 move \ Delay slot | |
139 | ||
140 | %l1 %g1 move | |
141 | %l2 %g2 move | |
142 | %l3 %g3 move | |
143 | %l4 %g4 move | |
144 | %l5 %g5 move | |
145 | %l6 %g6 move | |
146 | %l7 %g7 move | |
147 | %o0 sp move \ new stack pointer | |
148 | sp tos pop | |
149 | c; | |
150 | ||
151 | : retval ( -- return_value ) sysretval @ ; | |
152 | : lretval ( -- l.return_value ) sysretval @ n->l ; | |
153 | ||
154 | headers | |
155 | nuser errno \ The last system error code | |
156 | headerless | |
157 | ||
158 | : error? ( return-value -- return-value error? ) | |
159 | dup 0< dup if 15 syscall retval errno ! then ( return-value flag ) | |
160 | ; | |
161 | ||
162 | headers | |
163 | \ Depends on null-termination of Forth strings | |
164 | overload: cstr ( pstr -- cstr ) 1+ ; | |
165 | ||
166 | \ Rounds down to a block boundary. This causes all file accesses to the | |
167 | \ underlying operating system to occur on disk block boundaries. Some | |
168 | \ systems (e.g. CP/M) require this; others which don't require it | |
169 | \ usually run faster with alignment than without. | |
170 | hex | |
171 | headerless | |
172 | ||
173 | chain: unix-init-io | |
174 | install-wrapper-io | |
175 | ||
176 | \ Don't poll the keyboard under Unix; block waiting for a key | |
177 | ['] (key ['] key (is | |
178 | ; | |
179 | ' unix-init-io is init-io | |
180 | ||
181 | : unix-init ; \ Environment initialization chain | |
182 | ' unix-init is init-environment | |
183 | decimal | |
184 | headers |