4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <fcode/private.h>
33 #include <fcode/log.h>
35 fcode_env_t
*initial_env
= 0;
36 int dict_size
= 0x4000000; /* 64Mb, hopefully big enough... */
37 int stack_size
= 0x200;
40 safe_malloc(size_t n
, char *f
, int l
)
44 p
= malloc((size_t)n
);
45 #if defined(__sparcv9)
47 * For Ultrasparc, we must force addresses to be less than 4Gb,
48 * since Fcode assumes that addresses can be stored in 32 bits.
49 * To get around this would require turning all addresses into
50 * cookies, which is a lot of work.
52 if (((uint64_t)p
) >= 0x100000000) {
53 log_message(MSG_WARN
, "Malloc returned address > 4Gb\n");
55 #endif /* __sparcv9 */
57 memset(p
, 0, (size_t)n
);
59 log_message(MSG_ERROR
, "%s:%d:Malloc(%llx) failed\n", f
, l
,
65 safe_realloc(void *p
, size_t n
, char *f
, int l
)
69 if ((newp
= safe_malloc(n
, f
, l
)) == NULL
) {
70 log_message(MSG_ERROR
, "%s:%d:realloc(%p, %x) failed\n", f
, l
,
83 safe_free(void *p
, char *f
, int l
)
91 safe_strdup(char *s
, char *f
, int l
)
109 fcode_impl_count
= 0;
110 env
= MALLOC(sizeof (fcode_env_t
));
111 env
->table
= MALLOC((MAX_FCODE
+ 1) * sizeof (fcode_token
));
112 env
->base
= MALLOC(dict_size
);
113 env
->here
= env
->base
;
114 env
->ds
= env
->ds0
= MALLOC(stack_size
* sizeof (fstack_t
));
115 env
->rs
= env
->rs0
= MALLOC(stack_size
* sizeof (fstack_t
));
116 env
->order
= MALLOC(MAX_ORDER
* sizeof (token_t
));
117 env
->input
= MALLOC(sizeof (input_typ
));
118 env
->num_base
= 0x10;
120 /* Setup the initial forth environment */
123 install_handlers(env
);
128 * Need to define this early because it is the default for
129 * all unimpl, FCODE functions
131 P1275(0x0fc, IMMEDIATE
, "ferror", f_error
);
132 f_error_addr
= LINK_TO_ACF(env
->lastlink
);
133 for (i
= 0; i
<= MAX_FCODE
; i
++) {
134 DEBUGF(ANY
, env
->table
[i
].usage
= 0);
135 SET_TOKEN(i
, IMMEDIATE
, "ferror", f_error_addr
);
137 fcode_impl_count
= 0;