bare-startup.c 2.5 KB
Newer Older
1
/*
2 3 4 5
 * Copyright (C) 2011 CERN (www.cern.ch)
 * Author: Alessandro Rubini
 *
 * Released according to the GNU LGPL, version 2.1 or any later version.
6 7 8 9 10 11
 */

/*
 * This is the startup thing for "freestanding" stuff under Linux.
 * It must also clear the BSS as I'm too lazy to do that in asm
 */
Alessandro Rubini's avatar
Alessandro Rubini committed
12
#include <ppsi/ppsi.h>
13
#include "bare-linux.h"
14 15


Alessandro Rubini's avatar
Alessandro Rubini committed
16
void ppsi_clear_bss(void)
17 18
{
	int *ptr;
19
	extern int __bss_start, __bss_end;
20 21 22 23 24

	for (ptr = &__bss_start; ptr < &__bss_end; ptr++)
		*ptr = 0;
}

25
/* ppg fields */
26 27 28 29 30
static defaultDS_t defaultDS;
static currentDS_t currentDS;
static [parentDS_t parentDS;
static portDS_t portDS;
static timePropertiesDS_t timePropertiesDS;
31 32
static struct pp_servo servo;

33
static struct pp_globals ppg_static; /* forward declaration */
34 35
static unsigned char __tx_buffer[PP_MAX_FRAME_LENGTH];
static unsigned char __rx_buffer[PP_MAX_FRAME_LENGTH];
36 37 38 39 40 41 42

static struct pp_instance ppi_static = {
	.glbs			= &ppg_static,
	.portDS			= &portDS,
	.n_ops			= &bare_net_ops,
	.t_ops			= &bare_time_ops,
	.iface_name 		= "eth0",
43
	.port_name 		= "eth0",
44
	.vlans_array_len	= CONFIG_VLAN_ARRAY_SIZE,
45
	.proto			= PP_DEFAULT_PROTO,
46
	.delayMechanism			= CONFIG_HAS_P2P ? P2P : E2E,
47 48
	.__tx_buffer		= __tx_buffer,
	.__rx_buffer		= __rx_buffer,
49 50 51 52 53 54 55 56 57 58 59 60 61 62
};

/* We now have a structure with all globals, and multiple ppi inside */
static struct pp_globals ppg_static = {
	.pp_instances		= &ppi_static,
	.nlinks			= 1,
	.servo			= &servo,
	.defaultDS		= &defaultDS,
	.currentDS		= &currentDS,
	.parentDS		= &parentDS,
	.timePropertiesDS	= &timePropertiesDS,
	.rt_opts		= &__pp_default_rt_opts,
};

63
int ppsi_main(int argc, char **argv)
64
{
65
	struct pp_globals *ppg = &ppg_static;
66
	struct pp_instance *ppi = &ppi_static; /* no malloc, one instance */
67
	struct bare_timex t;
68

69 70
	pp_printf("PPSi, bare kernel. Commit %s, built on " __DATE__ "\n",
		PPSI_VERSION);
71

72
	ppg->rt_opts = &__pp_default_rt_opts;
73

74 75 76
	if (sys_adjtimex(&t) >= 0)
		timePropertiesDS.currentUtcOffset = t.tai;

77
	if (pp_parse_cmdline(ppg, argc, argv) != 0)
78 79
		return -1;

80
	/* This just allocates the stuff */
81
	pp_init_globals(ppg, &__pp_default_rt_opts);
82

83
	/* The actual sockets are opened in state-initializing */
84
	bare_main_loop(ppi);
85
	return 0;
86
}
87

88
/* We can't parse a config file or string (no system calls, /me is lazy) */
89 90 91 92 93 94
int pp_config_file(struct pp_globals *ppg, int force, char *fname)
{
	pp_printf("No support for config file: can't read \"%s\"\n",
		  fname);
	return -1;
}
95 96 97 98 99 100

int pp_config_string(struct pp_globals *ppg, char *s)
{
	pp_printf("No support for config options: can't parse \"%s\"\n", s);
	return -1;
}