4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2000 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #ifndef _FCODE_ENGINE_H
28 #define _FCODE_ENGINE_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/types.h>
39 #define CONVERT_HANDLES
42 typedef long long fstack_t
;
43 typedef unsigned long long ufstack_t
;
45 typedef long fstack_t
;
46 typedef unsigned long ufstack_t
;
48 typedef long *acf_t
; /* pointer to execution token */
49 typedef long token_t
; /* sizeof a forth token */
52 typedef uint64_t u_xforth_t
;
53 typedef int64_t s_xforth_t
;
54 typedef uint64_t xforth_t
;
57 typedef uint32_t u_lforth_t
;
58 typedef int32_t s_lforth_t
;
59 typedef uint32_t lforth_t
;
62 typedef uint16_t u_wforth_t
;
63 typedef int16_t s_wforth_t
;
64 typedef uint16_t wforth_t
;
67 typedef uint64_t u_dforth_t
;
68 typedef int64_t s_dforth_t
;
69 typedef uint64_t dforth_t
;
71 /* Variable/Value/Constant type */
72 typedef token_t variable_t
;
74 typedef struct PROPERTY
{
78 struct PROPERTY
*next
;
81 typedef struct RESOURCE
{
82 struct RESOURCE
*next
;
89 typedef struct FCODE_ENV fcode_env_t
;
91 typedef struct DEVICE_VECTOR
{
93 * If there is private data associated with a node this vector
94 * table contains the routines that will be called to augment the
96 * These two routines allow the interpreter to use a different
99 * Any routine installed here is assumed to have the standard forth
100 * call state. It must be a void function call taking a forth execution
101 * environment, returning any data on the stack. In general the
102 * vector call should have the same semantics as the original routine
103 * it is replacing. (see get_prop as an example).
105 * The caller has the responsibility of converting the resulting data
106 * back to a form it requires.
109 void (*get_package_prop
)(fcode_env_t
*);
110 void (*get_inherited_prop
)(fcode_env_t
*);
113 typedef struct DEVICE device_t
;
115 #define MAX_MY_ADDR 4
123 fstack_t parent_adr_cells
;
125 fstack_t my_addr
[MAX_MY_ADDR
];
126 fstack_t frame_buffer_adr
;
128 token_t
*init_data
; /* initialised instance data */
129 void *private; /* app private data */
130 device_vector_t vectors
;
133 typedef struct INSTANCE
{
134 struct INSTANCE
*parent
;
137 * These are copies of the same structures from the device definition
138 * however changes here will be thrown away when the instance is
144 fstack_t my_addr
[MAX_MY_ADDR
];
145 fstack_t frame_buffer_adr
;
149 typedef struct FCODE_TOKEN
{
152 acf_t apf
; /* pointer to acf in dictionary */
165 typedef struct ERROR_FRAME
{
166 struct ERROR_FRAME
*next
;
175 fcode_token
*table
; /* token table */
176 uchar_t
*base
; /* dictionary base */
177 uchar_t
*here
; /* current dp */
178 char *name
; /* last name */
179 long level
; /* level */
180 token_t
*ip
; /* instruction pointer */
181 token_t
*wa
; /* word address */
182 fstack_t
*ds0
; /* base of dats stack */
183 fstack_t
*rs0
; /* base of return stack */
184 fstack_t
*ds
; /* data stack base */
185 fstack_t
*rs
; /* return stack base */
186 variable_t num_base
; /* current base */
187 token_t
*current
; /* current voc */
189 token_t
**order
; /* Voc. search order */
190 token_t
*lastlink
; /* last forth def */
191 token_t
*forth_voc_link
; /* Storage location for 'forth' voc */
192 int last_token
; /* last defined token */
193 device_t
*root_node
; /* root node */
194 device_t
*attachment_pt
;
195 device_t
*current_device
; /* */
196 instance_t
*my_self
; /* pointer to my data */
197 int offset_incr
; /* size of FCODE token offsets */
198 error_frame
*catch_frame
;
199 uchar_t
*fcode_buffer
; /* pointer to fcode buffer */
200 uchar_t
*fcode_ptr
; /* pointer into fcode buffer */
201 uchar_t
*last_fcode_ptr
; /* pointer to last fcode fetched */
202 fstack_t last_fcode
; /* last fcode# executed */
203 fstack_t last_error
; /* last throw code executed */
204 int fcode_incr
; /* space between bytecodes */
206 variable_t state
; /* compile or run? */
209 fstack_t instance_mode
;
210 int interactive
; /* DEBUG, interact variable */
215 fstack_t control
; /* control VM behaviour */
216 input_typ
*input
; /* input buffer pointer */
218 char *picturebufpos
; /* pictured string buffer position */
219 char *picturebuf
; /* pictured string buffer */
220 int picturebuflen
; /* pictured string buffer length */
221 variable_t output_column
; /* output column# (#out) */
222 variable_t output_line
; /* output line# (#line) */
223 #ifdef CONVERT_HANDLES
224 device_t
*(*convert_phandle
)(fcode_env_t
*, fstack_t
);
225 fstack_t (*revert_phandle
)(fcode_env_t
*, device_t
*);
226 void (*allocate_phandle
)(fcode_env_t
*);
228 fc_resource_t
*propbufs
;
229 void *private; /* private data ptr for app use. */
232 #define MAX_FCODE 0xfff /* max no. of Fcode entries in table */
235 typedef unsigned char flag_t
;
242 #define DEPTH (DS-env->ds0)
243 #define CURRENT (env->current)
244 #define ORDER (env->order)
245 #define BASE (env->base)
246 #define HERE (env->here)
247 #define CONTEXT env->order[env->order_depth]
248 #define MYSELF (env->my_self)
250 #ifdef FCODE_INTERNAL
251 #include <fcode/proto.h>
253 #include <fcode/public.h>
255 #define SIGN_SHIFT ((8*(sizeof (fstack_t)))-1)
256 #define SIGN_BIT (((ufstack_t)1)<<SIGN_SHIFT)
259 * Note that sizeof (token_t) MUST equal sizeof (token_t *). If it doesn't,
260 * many things will break.
262 #define _ALIGN(x, y) (((long)(x)) & ~(sizeof (y)-1))
263 #define TOKEN_ROUNDUP(x) _ALIGN((x + ((sizeof (token_t)-1))), token_t)
265 #define min(x, y) ((x) < (y) ? (x) : (y))
266 #define max(x, y) ((x) > (y) ? (x) : (y))
268 /* values for flag_t */
269 #define ANSI_WORD 0x01
270 #define P1275_WORD 0x02
271 #define FLAG_NONAME 0x04
272 #define IMMEDIATE 0x08
273 #define FLAG_VALUE 0x10
274 #define FLAG_DEBUG 0x20
275 #define DEFINER (FLAG_NONAME|IMMEDIATE)
277 #define FORTH(fl, nm, fnc) define_word(env, fl, nm, fnc);
279 #define LINK_TO_ACF(x) (((token_t *)(x))+1)
280 #define LINK_TO_FLAGS(x) (((flag_t *)(x))-1)
281 #define ACF_TO_LINK(x) (((token_t *)(x))-1)
282 #define ACF_TO_BODY(x) (((acf_t)(x))+1)
283 #define BODY_TO_LINK(x) (((acf_t)(x))-1)
284 #define BODY_TO_FLAGS(x) (((flag_t *)(BODY_TO_LINK(x))) - 1)
285 #define EXPOSE_ACF *((acf_t)env->current) = \
286 (token_t)(env->lastlink)
288 #define COMPILE_TOKEN(x) PUSH(DS, (fstack_t)(x)); compile_comma(env);
289 #define CHECK_DEPTH(env, x, w) if ((x) > (env->ds - env->ds0)) \
290 forth_abort(env, "%s: stack underflow\n", w);
291 #define CHECK_RETURN_DEPTH(env, x, w) if ((x) > (env->rs - env->rs0)) \
292 forth_abort(env, "%s: return stack underflow\n", w);
294 #define FCRP_NOERROR 0x80000000 /* fc_run_priv: no err msg. */
296 #ifdef CONVERT_HANDLES
297 #define CONVERT_PHANDLE(e, x, y) x = env->convert_phandle(e, y)
298 #define REVERT_PHANDLE(e, x, y) x = env->revert_phandle(e, y)
299 #define ALLOCATE_PHANDLE(e) env->allocate_phandle(e)
301 #define CONVERT_PHANDLE(e, x, y) x = (device_t *)(y)
302 #define REVERT_PHANDLE(e, x, y) x = (fstack_t)(y)
303 #define ALLOCATE_PHANDLE(e)
306 extern fcode_env_t
*env
;
307 extern int dict_size
;
308 extern int in_forth_abort
;
309 extern int stack_size
;
310 extern token_t value_defines
[][3];
311 extern void (*bbranch_ptrs
[3])(fcode_env_t
*);
312 extern void (*blit_ptr
)(fcode_env_t
*);
313 extern void (*create_ptr
)(fcode_env_t
*);
314 extern void (*do_bdo_ptr
)(fcode_env_t
*);
315 extern void (*do_bqdo_ptr
)(fcode_env_t
*);
316 extern void (*do_leave_ptr
)(fcode_env_t
*);
317 extern void (*do_loop_ptr
)(fcode_env_t
*);
318 extern void (*do_ploop_ptr
)(fcode_env_t
*);
319 extern void (*does_ptr
)(fcode_env_t
*);
320 extern void (*quote_ptr
)(fcode_env_t
*);
321 extern void (*quote_ptr
)(fcode_env_t
*);
322 extern void (*semi_ptr
)(fcode_env_t
*);
323 extern void (*tlit_ptr
)(fcode_env_t
*);
324 extern void (*to_ptr
)(fcode_env_t
*);
325 extern void (*to_ptr
)(fcode_env_t
*);
331 #endif /* _FCODE_ENGINE_H */