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 */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* Automatique. Distributed only by permission. */
|
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-07-10 02:48:27 -07:00
|
|
|
/* Start-up code */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.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"
|
|
|
|
#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
|
|
|
|
1996-02-20 02:59:35 -08:00
|
|
|
header_t atom_table[256];
|
|
|
|
char * static_data_start, * static_data_end;
|
1995-07-10 02:48:27 -07:00
|
|
|
|
1996-11-07 02:55:49 -08:00
|
|
|
/* Initialize the atom table */
|
|
|
|
|
1995-07-10 02:48:27 -07:00
|
|
|
static void init_atoms()
|
|
|
|
{
|
|
|
|
int i;
|
1996-02-20 02:59:35 -08:00
|
|
|
extern struct { char * begin; char * end; } caml_data_segments[];
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) atom_table[i] = Make_header(0, i, White);
|
|
|
|
static_data_start = caml_data_segments[0].begin;
|
|
|
|
static_data_end = caml_data_segments[0].end;
|
|
|
|
for (i = 1; caml_data_segments[i].begin != 0; i++) {
|
|
|
|
if (caml_data_segments[i].begin < static_data_start)
|
|
|
|
static_data_start = caml_data_segments[i].begin;
|
|
|
|
if (caml_data_segments[i].end > static_data_end)
|
|
|
|
static_data_end = caml_data_segments[i].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 verbose_init = 0;
|
|
|
|
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. */
|
|
|
|
|
|
|
|
static void scanmult (opt, var)
|
|
|
|
char *opt;
|
|
|
|
unsigned long *var;
|
|
|
|
{
|
|
|
|
char mult = ' ';
|
|
|
|
sscanf (opt, "=%lu%c", var, &mult);
|
|
|
|
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
|
|
|
|
|
|
|
static void parse_camlrunparam()
|
|
|
|
{
|
|
|
|
char *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;
|
|
|
|
case 'v': scanmult (opt, &verbose_init); break;
|
1995-07-10 02:48:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1996-11-07 02:55:49 -08:00
|
|
|
}
|
|
|
|
|
1997-03-17 02:17:32 -08:00
|
|
|
extern void caml_start_program P((void));
|
1996-11-07 02:55:49 -08:00
|
|
|
extern void init_ieee_floats P((void));
|
|
|
|
extern void init_signals P((void));
|
|
|
|
|
|
|
|
void caml_main(argv)
|
|
|
|
char ** argv;
|
|
|
|
{
|
|
|
|
init_ieee_floats();
|
|
|
|
#ifdef DEBUG
|
|
|
|
verbose_init = 1;
|
|
|
|
#endif
|
|
|
|
parse_camlrunparam();
|
1997-05-13 07:45:38 -07:00
|
|
|
init_gc (minor_heap_init, heap_size_init, heap_chunk_init,
|
1997-05-19 08:42:21 -07:00
|
|
|
percent_free_init, max_percent_free_init, verbose_init);
|
1995-07-10 02:48:27 -07:00
|
|
|
init_atoms();
|
1995-12-21 03:01:45 -08:00
|
|
|
init_signals();
|
1995-07-10 02:48:27 -07:00
|
|
|
sys_init(argv);
|
1997-03-17 02:17:32 -08:00
|
|
|
caml_start_program();
|
1995-07-10 02:48:27 -07:00
|
|
|
}
|
|
|
|
|
1996-11-07 02:55:49 -08:00
|
|
|
void caml_startup(argv)
|
|
|
|
char ** argv;
|
|
|
|
{
|
|
|
|
caml_main(argv);
|
|
|
|
}
|