2 * main() entry point for a stand-alone SBCL image
6 * This software is part of the SBCL system. See the README file for
9 * This software is derived from the CMU CL system, which was
10 * written at Carnegie Mellon University and released into the
11 * public domain. The software is in the public domain and is
12 * provided with absolutely no warranty. See the COPYING and CREDITS
13 * files for more information.
19 #include <sys/types.h>
23 #include <sys/param.h>
26 #if defined(SVR4) || defined(__linux__)
38 #include "interrupt.h"
53 /* SIGINT handler that invokes the monitor (for when Lisp isn't up to it) */
55 sigint_handler(int signal, siginfo_t *info, void *void_context)
57 lose("\nSIGINT hit at 0x%08lX\n",
58 (unsigned long) *os_context_pc_addr(void_context));
61 /* (This is not static, because we want to be able to call it from
66 SHOW("entering sigint_init()");
67 install_handler(SIGINT, sigint_handler);
68 SHOW("leaving sigint_init()");
72 * helper functions for dealing with command line args
76 successful_malloc(size_t size)
78 void* result = malloc(size);
80 lose("malloc failure");
84 return (void *) NULL; /* dummy value: return something ... */
88 copied_string(char *string)
90 return strcpy(successful_malloc(1+strlen(string)), string);
94 copied_existing_filename_or_null(char *filename)
96 struct stat filename_stat;
97 if (stat(filename, &filename_stat)) { /* if failure */
100 return copied_string(filename);
104 /* Convert a null-terminated array of null-terminated strings (e.g.
105 * argv or envp) into a Lisp list of Lisp strings. */
107 alloc_string_list(char *array_ptr[])
110 return alloc_cons(alloc_string(*array_ptr),
111 alloc_string_list(1 + array_ptr));
117 /* miscellaneous chattiness */
123 "SBCL is a Common Lisp programming environment. Ordinarily you shouldn't\n\
124 need command line options when you invoke it interactively: you can just\n\
125 start it and work with the customary Lisp READ-EVAL-PRINT loop.\n\
127 One option idiom which is sometimes useful interactively (e.g. when\n\
128 exercising a test case for a bug report) is\n\
129 sbcl --sysinit /dev/null --userinit /dev/null\n\
130 to keep SBCL from reading any initialization files at startup. And some\n\
131 people like to suppress the default startup message:\n\
134 Other options can be useful when you're running SBCL noninteractively,\n\
135 e.g. from a script, or if you have a strange system configuration, so\n\
136 that SBCL can't by default find one of the files it needs. For\n\
137 information on such options, see the sbcl(1) man page.\n\
139 More information on SBCL can be found on its man page, or at\n\
140 <http://sbcl.sf.net/>.\n");
146 printf("SBCL %s\n", SBCL_VERSION_STRING);
153 "This is SBCL %s, an implementation of ANSI Common Lisp.\n\
155 SBCL is derived from the CMU CL system created at Carnegie Mellon University.\n\
156 Besides software and documentation originally created at Carnegie Mellon\n\
157 University, SBCL contains some software originally from the Massachusetts\n\
158 Institute of Technology, Symbolics Incorporated, and Xerox Corporation, and\n\
159 material contributed by volunteers since the release of CMU CL into the\n\
160 public domain. See the CREDITS file in the distribution for more information.\n\
162 SBCL is a free software system, provided as is, with absolutely no warranty.\n\
163 It is mostly in the public domain, but also includes some software copyrighted\n\
164 Massachusetts Institute of Technology, 1986;\n\
165 Symbolics, Inc., 1989, 1990, 1991, 1992; and\n\
166 Xerox Corporation, 1985, 1986, 1987, 1988, 1989, 1990\n\
167 used under BSD-style licenses allowing copying only under certain conditions.\n\
168 See the COPYING file in the distribution for more information.\n\
170 More information about SBCL is available at <http://sbcl.sourceforge.net/>.\n\
171 ", SBCL_VERSION_STRING);
175 main(int argc, char *argv[], char *envp[])
177 /* the name of the core file we're to execute. Note that this is
178 * a malloc'ed string which should be freed eventually. */
181 /* other command line options */
182 boolean noinform = 0;
183 boolean end_runtime_options = 0;
185 lispobj initial_function;
187 /* KLUDGE: os_vm_page_size is set by os_init(), and on some
188 * systems (e.g. Alpha) arch_init() needs need os_vm_page_size, so
189 * it must follow os_init(). -- WHN 2000-01-26 */
195 /* Parse our part of the command line (aka "runtime options"),
196 * stripping out those options that we handle. */
199 while (argi < argc) {
200 char *arg = argv[argi];
201 if (0 == strcmp(arg, "--noinform")) {
204 } else if (0 == strcmp(arg, "--core")) {
206 lose("more than one core file specified");
210 lose("missing filename for --core argument");
212 core = copied_string(argv[argi]);
215 } else if (0 == strcmp(arg, "--help")) {
216 /* I think this is the (or a) usual convention: upon
217 * seeing "--help" we immediately print our help
218 * string and exit, ignoring everything else. */
221 } else if (0 == strcmp(arg, "--version")) {
222 /* As in "--help" case, I think this is expected. */
225 } else if (0 == strcmp(arg, "--end-runtime-options")) {
226 end_runtime_options = 1;
230 /* This option was unrecognized as a runtime option,
231 * so it must be a toplevel option or a user option,
232 * so we must be past the end of the runtime option
237 /* This is where we strip out those options that we handle. We
238 * also take this opportunity to make sure that we don't find
239 * an out-of-place "--end-runtime-options" option. */
241 char *argi0 = argv[argi];
243 while (argi < argc) {
244 char *arg = argv[argi++];
245 /* If we encounter --end-runtime-options for the first
246 * time after the point where we had to give up on
247 * runtime options, then the point where we had to
248 * give up on runtime options must've been a user
250 if (!end_runtime_options &&
251 0 == strcmp(arg, "--end-runtime-options")) {
252 lose("bad runtime option \"%s\"", argi0);
261 /* If no core file was specified, look for one. */
263 char *sbcl_home = getenv("SBCL_HOME");
266 char *stem = "/sbcl.core";
267 lookhere = (char *) calloc(strlen(sbcl_home) +
271 sprintf(lookhere, "%s%s", sbcl_home, stem);
272 core = copied_existing_filename_or_null(lookhere);
275 putenv("SBCL_HOME=/usr/local/lib/sbcl/");
276 core = copied_existing_filename_or_null("/usr/local/lib/sbcl/sbcl.core");
278 putenv("SBCL_HOME=/usr/lib/sbcl/");
280 copied_existing_filename_or_null("/usr/lib/sbcl/sbcl.core");
284 lose("can't find core file");
287 /* If a core was specified and SBCL_HOME is unset, set it */
288 char *sbcl_home = getenv("SBCL_HOME");
290 char *envstring, *copied_core, *dir;
291 char *stem = "SBCL_HOME=";
292 copied_core = copied_string(core);
293 dir = dirname(copied_core);
294 envstring = (char *) calloc(strlen(stem) +
298 sprintf(envstring, "%s%s", stem, dir);
312 #if defined(SVR4) || defined(__linux__)
316 define_var("nil", NIL, 1);
317 define_var("t", T, 1);
319 set_lossage_handler(monitor_or_something);
323 initial_function = load_core_file(core);
324 if (initial_function == NIL) {
325 lose("couldn't find initial function");
327 SHOW("freeing core");
330 gc_initialize_pointers();
332 #ifdef BINDING_STACK_POINTER
333 SetSymbolValue(BINDING_STACK_POINTER, BINDING_STACK_START);
338 arch_install_interrupt_handlers();
339 os_install_interrupt_handlers();
341 #ifdef PSEUDO_ATOMIC_ATOMIC
342 /* Turn on pseudo atomic for when we call into Lisp. */
343 SHOW("turning on pseudo atomic");
344 SetSymbolValue(PSEUDO_ATOMIC_ATOMIC, make_fixnum(1));
345 SetSymbolValue(PSEUDO_ATOMIC_INTERRUPTED, make_fixnum(0));
348 /* Convert remaining argv values to something that Lisp can grok. */
349 SHOW("setting POSIX-ARGV symbol value");
350 SetSymbolValue(POSIX_ARGV, alloc_string_list(argv));
352 /* Install a handler to pick off SIGINT until the Lisp system gets
353 * far enough along to install its own handler. */
356 FSHOW((stderr, "/funcalling initial_function=0x%lx\n", initial_function));
357 funcall0(initial_function);
359 /* initial_function() is not supposed to return. */
360 lose("Lisp initial_function gave up control.");
361 return 0; /* dummy value: return something */