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 2000-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Embedded Fcode Interpreter
32 * Process cmd line args and invoke Fcode engine.
34 #include <sys/types.h>
45 #include <fcode/engine.h>
46 #include <fcode/log.h>
47 #include <fcode/debug.h>
49 #include <fcdriver/fcdriver.h>
51 #define MSG_ERRLOG_DEFAULT (MSG_FATAL|MSG_ERROR|MSG_WARN|MSG_INFO|\
52 MSG_DEBUG|MSG_FC_DEBUG)
53 #define MSG_SYSLOG_DEFAULT (MSG_FATAL|MSG_ERROR|MSG_WARN)
54 #define DEBUG_FC_LIST (DEBUG_COMMA|DEBUG_EXEC_TRACE|\
55 DEBUG_EXEC_DUMP_RS|DEBUG_EXEC_DUMP_RS|\
56 DEBUG_EXEC_SHOW_VITALS|DEBUG_TRACING|\
57 DEBUG_BYTELOAD_DS|DEBUG_BYTELOAD_RS|\
58 DEBUG_BYTELOAD_TOKENS|DEBUG_SHOW_RS|\
68 log_message(MSG_ERROR
, "Usage: %s <flags>\n", argv
[0]);
69 log_message(MSG_ERROR
,
70 " -D fcode_debug = true\n");
71 log_message(MSG_ERROR
,
72 " -d <level> set debug level\n");
73 log_message(MSG_ERROR
,
74 " -f <file> interpret fcode/source <file>\n");
75 log_message(MSG_ERROR
,
76 " -i go 'interactive'\n");
77 log_message(MSG_ERROR
,
78 " -s <string> interpret <string> as forth\n");
79 log_message(MSG_ERROR
,
80 " -a FCODE image has a.out header\n");
81 log_message(MSG_ERROR
,
82 " -e [<msglvl>:]<errorlog> Set error log file\n");
83 log_message(MSG_ERROR
,
84 " -l <msglvl> Set syslog message level\n");
85 log_message(MSG_ERROR
,
86 " -k Toggle OBP page kludge\n");
92 main(int argc
, char *argv
[])
95 extern int optind
, opterr
, optopt
;
97 char *fcode_file
= NULL
;
98 char *forthstr
= NULL
;
100 int syslog_flags
= MSG_SYSLOG_DEFAULT
;
104 extern void run_one_efdaemon_request(fcode_env_t
*);
106 common
.Progname
= argv
[0];
107 common
.search_path
= getenv("FC_SEARCH_PATH");
108 common
.fcode_fd
= -1;
109 env
= fc_env
= clone_environment(NULL
, &common
);
111 while ((c
= getopt(argc
, argv
, "ad:e:f:l:iDs:k")) != EOF
) {
118 debug
= debug_flags_to_mask(optarg
);
119 set_interpreter_debug_level(debug
);
121 env
->fcode_debug
= 1;
125 if ((errlog
= strchr(optarg
, ':')) != NULL
) {
127 error_log_flags
= parse_msg_flags(optarg
);
130 error_log_flags
= MSG_ERRLOG_DEFAULT
;
132 open_error_log(errlog
, error_log_flags
);
136 syslog_flags
= parse_msg_flags(optarg
);
141 env
->fcode_debug
= 1;
149 forthstr
= "interact";
150 env
->fcode_debug
= 1;
164 run_fcode(env
, (uchar_t
*)forthstr
, strlen(forthstr
));
165 } else if (fcode_file
) {
166 run_fcode_from_file(env
, fcode_file
, aout
);
168 if ((debug
& DEBUG_FC_LIST
) != 0 &&
169 ((error_log_flags
| syslog_flags
) & MSG_FC_DEBUG
) == 0) {
170 log_message(MSG_WARN
, "Warning, verbose debug flag(s)"
171 " on, but syslog/errlog not enabled for verbose"
174 error_log_flags
|= MSG_FC_DEBUG
;
176 syslog_flags
|= MSG_FC_DEBUG
;
178 if ((debug
& ~DEBUG_FC_LIST
) != 0 &&
179 ((error_log_flags
| syslog_flags
) & MSG_DEBUG
) == 0) {
180 log_message(MSG_WARN
, "Warning, debug flag(s) on, but"
181 " syslog/errlog not enabled for debug\n");
183 error_log_flags
|= MSG_DEBUG
;
185 syslog_flags
|= MSG_DEBUG
;
188 if (errlog
== NULL
|| lflag
) {
189 if (syslog_flags
& MSG_FC_DEBUG
)
190 log_message(MSG_WARN
, "Warning, verbose debug"
191 " not recommended for syslog\n");
192 open_syslog_log("interpreter", syslog_flags
);
194 run_one_efdaemon_request(env
);