2 * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <gpxe/device.h>
20 #include <gpxe/init.h>
24 * Initialisation, startup and shutdown routines
28 /** Registered initialisation functions */
29 static struct init_fn init_fns
[0]
30 __table_start ( struct init_fn
, init_fns
);
31 static struct init_fn init_fns_end
[0]
32 __table_end ( struct init_fn
, init_fns
);
34 /** Registered startup/shutdown functions */
35 static struct startup_fn startup_fns
[0]
36 __table_start ( struct startup_fn
, startup_fns
);
37 static struct startup_fn startup_fns_end
[0]
38 __table_end ( struct startup_fn
, startup_fns
);
40 /** "startup() has been called" flag */
41 static int started
= 0;
46 * This function performs the one-time-only and irreversible
47 * initialisation steps, such as initialising the heap. It must be
48 * called before (almost) any other function.
50 * There is, by definition, no counterpart to this function on the
53 void initialise ( void ) {
54 struct init_fn
*init_fn
;
56 /* Call registered initialisation functions */
57 for ( init_fn
= init_fns
; init_fn
< init_fns_end
; init_fn
++ ) {
58 init_fn
->initialise ();
65 * This function performs the repeatable initialisation steps, such as
66 * probing devices. You may call startup() and shutdown() multiple
67 * times (as is done via the PXE API when PXENV_START_UNDI is used).
69 void startup ( void ) {
70 struct startup_fn
*startup_fn
;
75 /* Call registered startup functions */
76 for ( startup_fn
= startup_fns
; startup_fn
< startup_fns_end
;
78 if ( startup_fn
->startup
)
79 startup_fn
->startup();
88 * @v flags Shutdown behaviour flags
90 * This function reverses the actions of startup(), and leaves gPXE in
91 * a state ready to be removed from memory. You may call startup()
92 * again after calling shutdown().
94 * Call this function only once, before either exiting main() or
95 * starting up a non-returnable image.
97 void shutdown ( int flags
) {
98 struct startup_fn
*startup_fn
;
103 /* Call registered shutdown functions (in reverse order) */
104 for ( startup_fn
= startup_fns_end
- 1 ; startup_fn
>= startup_fns
;
106 if ( startup_fn
->shutdown
)
107 startup_fn
->shutdown ( flags
);