summaryrefslogtreecommitdiffstats
path: root/src/core/main.c
blob: 64e098ca32743325290fcd7c63f098602f41c203 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**************************************************************************
Etherboot -  Network Bootstrap Program

Literature dealing with the network protocols:
	ARP - RFC826
	RARP - RFC903
	UDP - RFC768
	BOOTP - RFC951, RFC2132 (vendor extensions)
	DHCP - RFC2131, RFC2132 (options)
	TFTP - RFC1350, RFC2347 (options), RFC2348 (blocksize), RFC2349 (tsize)
	RPC - RFC1831, RFC1832 (XDR), RFC1833 (rpcbind/portmapper)
	NFS - RFC1094, RFC1813 (v3, useful for clarifications, not implemented)
	IGMP - RFC1112

**************************************************************************/

#include <gpxe/heap.h>
#include <gpxe/init.h>
#include <gpxe/device.h>
#include <gpxe/shell.h>
#include <gpxe/shell_banner.h>
#include <gpxe/shutdown.h>
#include <gpxe/hidemem.h>
#include <usr/autoboot.h>

/**
 * Start up Etherboot
 *
 * Call this function only once, before doing (almost) anything else.
 */
static void startup ( void ) {
	hide_etherboot();
	init_heap();
	call_init_fns();
	probe_devices();
}

/**
 * Shut down Etherboot
 *
 * Call this function only once, before either exiting main() or
 * starting up a non-returnable image.
 */
void shutdown ( void ) {
	remove_devices();
	call_exit_fns();
	unhide_etherboot();
}

/**
 * Main entry point
 *
 * @ret rc		Return status code
 */
int main ( void ) {

	startup();

	/* Try autobooting if we're not going straight to the shell */
	if ( ! shell_banner() ) {
		autoboot();
	}
	
	/* Autobooting failed or the user wanted the shell */
	shell();

	shutdown();

	return 0;
}