1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../LICENSE. */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-07-10 02:48:27 -07:00
|
|
|
/* Start-up code */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1999-02-14 08:48:25 -08:00
|
|
|
#include "callback.h"
|
2000-02-11 07:09:27 -08:00
|
|
|
#include "custom.h"
|
1996-11-07 05:12:16 -08:00
|
|
|
#include "fail.h"
|
1995-07-10 02:48:27 -07:00
|
|
|
#include "gc.h"
|
|
|
|
#include "gc_ctrl.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "mlvalues.h"
|
2002-09-03 06:56:36 -07:00
|
|
|
#include "osdeps.h"
|
2001-06-15 07:22:49 -07:00
|
|
|
#include "printexc.h"
|
1995-07-10 02:48:27 -07:00
|
|
|
#include "sys.h"
|
1996-11-07 05:12:16 -08:00
|
|
|
#ifdef HAS_UI
|
|
|
|
#include "ui.h"
|
|
|
|
#endif
|
1995-07-10 02:48:27 -07:00
|
|
|
|
2001-11-05 05:34:42 -08:00
|
|
|
extern int parser_trace;
|
1996-02-20 02:59:35 -08:00
|
|
|
header_t atom_table[256];
|
|
|
|
char * static_data_start, * static_data_end;
|
1997-07-02 11:16:15 -07:00
|
|
|
char * code_area_start, * code_area_end;
|
1995-07-10 02:48:27 -07:00
|
|
|
|
1997-07-02 11:16:15 -07:00
|
|
|
/* Initialize the atom table and the static data and code area limits. */
|
1996-11-07 02:55:49 -08:00
|
|
|
|
1997-07-02 11:16:15 -07:00
|
|
|
struct segment { char * begin; char * end; };
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
static void minmax_table(struct segment *table, char **min, char **max)
|
1997-07-02 11:16:15 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
*min = table[0].begin;
|
|
|
|
*max = table[0].end;
|
|
|
|
for (i = 1; table[i].begin != 0; i++) {
|
|
|
|
if (table[i].begin < *min) *min = table[i].begin;
|
|
|
|
if (table[i].end > *max) *max = table[i].end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
static void init_atoms(void)
|
1995-07-10 02:48:27 -07:00
|
|
|
{
|
|
|
|
int i;
|
1997-07-02 11:16:15 -07:00
|
|
|
extern struct segment caml_data_segments[], caml_code_segments[];
|
1996-02-20 02:59:35 -08:00
|
|
|
|
2000-01-03 08:15:14 -08:00
|
|
|
for (i = 0; i < 256; i++) atom_table[i] = Make_header(0, i, Caml_white);
|
1997-07-02 11:16:15 -07:00
|
|
|
minmax_table(caml_data_segments, &static_data_start, &static_data_end);
|
|
|
|
minmax_table(caml_code_segments, &code_area_start, &code_area_end);
|
1995-07-10 02:48:27 -07:00
|
|
|
}
|
|
|
|
|
1997-05-13 07:45:38 -07:00
|
|
|
/* Configuration parameters and flags */
|
1995-07-10 02:48:27 -07:00
|
|
|
|
1997-05-21 08:26:09 -07:00
|
|
|
static unsigned long percent_free_init = Percent_free_def;
|
|
|
|
static unsigned long max_percent_free_init = Max_percent_free_def;
|
1997-05-13 07:45:38 -07:00
|
|
|
static unsigned long minor_heap_init = Minor_heap_def;
|
|
|
|
static unsigned long heap_chunk_init = Heap_chunk_def;
|
|
|
|
static unsigned long heap_size_init = Init_heap_def;
|
|
|
|
static unsigned long max_stack_init = Max_stack_def;
|
1995-07-10 02:48:27 -07:00
|
|
|
|
1996-11-07 02:55:49 -08:00
|
|
|
/* Parse the CAMLRUNPARAM variable */
|
|
|
|
/* The option letter for each runtime option is the first letter of the
|
1997-05-13 07:45:38 -07:00
|
|
|
last word of the ML name of the option (see [stdlib/gc.mli]).
|
|
|
|
Except for l (maximum stack size) and h (initial heap size).
|
|
|
|
*/
|
|
|
|
/* Note: option l is irrelevant to the native-code runtime. */
|
|
|
|
|
2002-06-05 05:26:08 -07:00
|
|
|
/* If you change these functions, see also their copy in byterun/startup.c */
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
static void scanmult (char *opt, long unsigned int *var)
|
1997-05-13 07:45:38 -07:00
|
|
|
{
|
|
|
|
char mult = ' ';
|
|
|
|
sscanf (opt, "=%lu%c", var, &mult);
|
2002-06-05 05:26:08 -07:00
|
|
|
sscanf (opt, "=0x%lx%c", var, &mult);
|
1997-05-13 07:45:38 -07:00
|
|
|
if (mult == 'k') *var = *var * 1024;
|
|
|
|
if (mult == 'M') *var = *var * (1024 * 1024);
|
|
|
|
if (mult == 'G') *var = *var * (1024 * 1024 * 1024);
|
|
|
|
}
|
1996-11-07 02:55:49 -08:00
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
static void parse_camlrunparam(void)
|
1996-11-07 02:55:49 -08:00
|
|
|
{
|
1999-11-18 09:57:48 -08:00
|
|
|
char *opt = getenv ("OCAMLRUNPARAM");
|
|
|
|
|
|
|
|
if (opt == NULL) opt = getenv ("CAMLRUNPARAM");
|
|
|
|
|
1995-07-10 02:48:27 -07:00
|
|
|
if (opt != NULL){
|
|
|
|
while (*opt != '\0'){
|
|
|
|
switch (*opt++){
|
1997-05-19 08:42:21 -07:00
|
|
|
case 's': scanmult (opt, &minor_heap_init); break;
|
1997-05-13 07:45:38 -07:00
|
|
|
case 'i': scanmult (opt, &heap_chunk_init); break;
|
|
|
|
case 'h': scanmult (opt, &heap_size_init); break;
|
|
|
|
case 'l': scanmult (opt, &max_stack_init); break;
|
1997-05-21 08:26:09 -07:00
|
|
|
case 'o': scanmult (opt, &percent_free_init); break;
|
|
|
|
case 'O': scanmult (opt, &max_percent_free_init); break;
|
2001-02-19 04:42:33 -08:00
|
|
|
case 'v': scanmult (opt, &verb_gc); break;
|
2001-11-05 05:34:42 -08:00
|
|
|
case 'p': parser_trace = 1; break;
|
1995-07-10 02:48:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1996-11-07 02:55:49 -08:00
|
|
|
}
|
|
|
|
|
1999-02-14 08:48:25 -08:00
|
|
|
extern value caml_start_program (void);
|
1997-09-02 05:55:01 -07:00
|
|
|
extern void init_ieee_floats (void);
|
|
|
|
extern void init_signals (void);
|
1996-11-07 02:55:49 -08:00
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void caml_main(char **argv)
|
1996-11-07 02:55:49 -08:00
|
|
|
{
|
2002-02-11 05:51:40 -08:00
|
|
|
char * exe_name;
|
|
|
|
#ifdef __linux__
|
|
|
|
static char proc_self_exe[256];
|
|
|
|
#endif
|
1999-02-14 08:48:25 -08:00
|
|
|
value res;
|
|
|
|
|
1996-11-07 02:55:49 -08:00
|
|
|
init_ieee_floats();
|
2000-02-11 07:09:27 -08:00
|
|
|
init_custom_operations();
|
1996-11-07 02:55:49 -08:00
|
|
|
#ifdef DEBUG
|
2001-02-19 04:42:33 -08:00
|
|
|
verb_gc = 63;
|
1996-11-07 02:55:49 -08:00
|
|
|
#endif
|
|
|
|
parse_camlrunparam();
|
1997-05-13 07:45:38 -07:00
|
|
|
init_gc (minor_heap_init, heap_size_init, heap_chunk_init,
|
2001-02-19 04:42:33 -08:00
|
|
|
percent_free_init, max_percent_free_init);
|
1995-07-10 02:48:27 -07:00
|
|
|
init_atoms();
|
1995-12-21 03:01:45 -08:00
|
|
|
init_signals();
|
2002-02-11 05:51:40 -08:00
|
|
|
exe_name = argv[0];
|
|
|
|
#ifdef __linux__
|
2002-09-03 06:56:36 -07:00
|
|
|
if (executable_name(proc_self_exe, sizeof(proc_self_exe)) == 0)
|
2002-02-11 05:51:40 -08:00
|
|
|
exe_name = proc_self_exe;
|
|
|
|
#endif
|
|
|
|
sys_init(exe_name, argv);
|
1999-02-14 08:48:25 -08:00
|
|
|
res = caml_start_program();
|
|
|
|
if (Is_exception_result(res))
|
|
|
|
fatal_uncaught_exception(Extract_exception(res));
|
1995-07-10 02:48:27 -07:00
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
void caml_startup(char **argv)
|
1996-11-07 02:55:49 -08:00
|
|
|
{
|
|
|
|
caml_main(argv);
|
|
|
|
}
|