dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / efcode / engine / init.c
blob6440340f5acdf1fdb256b5c51f2378935830ed11
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
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;
39 void *
40 safe_malloc(size_t n, char *f, int l)
42 void *p;
44 p = malloc((size_t)n);
45 if (p) {
46 memset(p, 0, (size_t)n);
47 } else
48 log_message(MSG_ERROR, "%s:%d:Malloc(%llx) failed\n", f, l,
49 (uint64_t)n);
50 return (p);
53 void *
54 safe_realloc(void *p, size_t n, char *f, int l)
56 void *newp;
58 if ((newp = safe_malloc(n, f, l)) == NULL) {
59 log_message(MSG_ERROR, "%s:%d:realloc(%p, %x) failed\n", f, l,
60 p, n);
61 safe_free(p, f, l);
62 return (NULL);
64 if (p) {
65 memcpy(newp, p, n);
66 safe_free(p, f, l);
68 return (newp);
71 void
72 safe_free(void *p, char *f, int l)
74 if (p) {
75 free(p);
79 char *
80 safe_strdup(char *s, char *f, int l)
82 char *p = strdup(s);
84 return (p);
87 #pragma init(_init)
89 static void
90 _init(void)
92 int i;
93 acf_t f_error_addr;
94 fcode_env_t *env;
96 NOTICE;
98 fcode_impl_count = 0;
99 env = MALLOC(sizeof (fcode_env_t));
100 env->table = MALLOC((MAX_FCODE + 1) * sizeof (fcode_token));
101 env->base = MALLOC(dict_size);
102 env->here = env->base;
103 env->ds = env->ds0 = MALLOC(stack_size * sizeof (fstack_t));
104 env->rs = env->rs0 = MALLOC(stack_size * sizeof (fstack_t));
105 env->order = MALLOC(MAX_ORDER * sizeof (token_t));
106 env->input = MALLOC(sizeof (input_typ));
107 env->num_base = 0x10;
109 /* Setup the initial forth environment */
110 do_forth(env);
111 do_definitions(env);
112 install_handlers(env);
114 initial_env = env;
117 * Need to define this early because it is the default for
118 * all unimpl, FCODE functions
120 P1275(0x0fc, IMMEDIATE, "ferror", f_error);
121 f_error_addr = LINK_TO_ACF(env->lastlink);
122 for (i = 0; i <= MAX_FCODE; i++) {
123 DEBUGF(ANY, env->table[i].usage = 0);
124 SET_TOKEN(i, IMMEDIATE, "ferror", f_error_addr);
126 fcode_impl_count = 0;