From 352bf1bda2d4c0d08e9b674702d8ba754f4d1747 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 30 Apr 2006 01:08:52 +0000 Subject: [PATCH] Move init.h to gpxe/init.h. --- src/arch/i386/core/cpu.c | 2 +- src/arch/i386/core/i386_timer.c | 2 +- src/arch/i386/core/pci_io.c | 2 +- src/arch/i386/core/relocate.c | 2 +- src/arch/i386/core/video_subr.c | 2 +- src/arch/i386/firmware/pcbios/memsizes.c | 2 +- src/arch/i386/transitions/librm_mgmt.c | 2 +- src/core/btext.c | 2 +- src/core/heap.c | 2 +- src/core/init.c | 2 +- src/core/main.c | 2 +- src/core/pcmcia.c | 2 +- src/core/serial.c | 2 +- src/include/gpxe/init.h | 66 ++++++++++++++++++++++++ src/net/netdevice.c | 8 ++- src/proto/nfs.c | 2 +- 16 files changed, 83 insertions(+), 19 deletions(-) create mode 100644 src/include/gpxe/init.h diff --git a/src/arch/i386/core/cpu.c b/src/arch/i386/core/cpu.c index 7b2533f4..2d2e1888 100644 --- a/src/arch/i386/core/cpu.c +++ b/src/arch/i386/core/cpu.c @@ -2,7 +2,7 @@ #include "stdint.h" #include "string.h" #include "bits/cpu.h" -#include "init.h" +#include /* Standard macro to see if a specific flag is changeable */ diff --git a/src/arch/i386/core/i386_timer.c b/src/arch/i386/core/i386_timer.c index c9aa406f..3608d8a6 100644 --- a/src/arch/i386/core/i386_timer.c +++ b/src/arch/i386/core/i386_timer.c @@ -10,7 +10,7 @@ #include "etherboot.h" #include "timer.h" #include "latch.h" -#include "init.h" +#include void __load_timer2(unsigned int ticks) { diff --git a/src/arch/i386/core/pci_io.c b/src/arch/i386/core/pci_io.c index cfb31ad9..a272b447 100644 --- a/src/arch/i386/core/pci_io.c +++ b/src/arch/i386/core/pci_io.c @@ -11,7 +11,7 @@ ** /usr/src/linux/drivers/net/ne.c */ #include "etherboot.h" -#include "init.h" +#include #include #include "pci_io.h" #ifdef KEEP_IT_REAL diff --git a/src/arch/i386/core/relocate.c b/src/arch/i386/core/relocate.c index a24b4fd1..7d5ba322 100644 --- a/src/arch/i386/core/relocate.c +++ b/src/arch/i386/core/relocate.c @@ -2,7 +2,7 @@ #include "memsizes.h" #include "osdep.h" #include "etherboot.h" -#include "init.h" +#include #include "relocate.h" #ifndef KEEP_IT_REAL diff --git a/src/arch/i386/core/video_subr.c b/src/arch/i386/core/video_subr.c index 66aee114..7f3b96bf 100644 --- a/src/arch/i386/core/video_subr.c +++ b/src/arch/i386/core/video_subr.c @@ -9,7 +9,7 @@ #include "string.h" #include "io.h" #include "console.h" -#include "init.h" +#include #include "vga.h" struct console_driver vga_console; diff --git a/src/arch/i386/firmware/pcbios/memsizes.c b/src/arch/i386/firmware/pcbios/memsizes.c index 25e9fb19..4cce53d7 100644 --- a/src/arch/i386/firmware/pcbios/memsizes.c +++ b/src/arch/i386/firmware/pcbios/memsizes.c @@ -1,7 +1,7 @@ #include "stdint.h" #include "stddef.h" #include "realmode.h" -#include "init.h" +#include #include "etherboot.h" #include "memsizes.h" diff --git a/src/arch/i386/transitions/librm_mgmt.c b/src/arch/i386/transitions/librm_mgmt.c index 956408f5..6780fdc3 100644 --- a/src/arch/i386/transitions/librm_mgmt.c +++ b/src/arch/i386/transitions/librm_mgmt.c @@ -14,7 +14,7 @@ #include "string.h" #include "basemem.h" #include "relocate.h" -#include "init.h" +#include #include "librm.h" /* diff --git a/src/core/btext.c b/src/core/btext.c index 43accc47..2a2972e9 100644 --- a/src/core/btext.c +++ b/src/core/btext.c @@ -9,7 +9,7 @@ #include "etherboot.h" #include "console.h" -#include "init.h" +#include #include #ifdef CONFIG_FILO diff --git a/src/core/heap.c b/src/core/heap.c index d70aa2d9..b04b4b82 100644 --- a/src/core/heap.c +++ b/src/core/heap.c @@ -1,5 +1,5 @@ #include "etherboot.h" -#include "init.h" +#include #include "memsizes.h" #include #include "heap.h" diff --git a/src/core/init.c b/src/core/init.c index ed652379..3f41ddd1 100644 --- a/src/core/init.c +++ b/src/core/init.c @@ -7,7 +7,7 @@ ************************************************************************** */ -#include "init.h" +#include static struct init_fn init_fns[0] __table_start(init_fn); static struct init_fn init_fns_end[0] __table_end(init_fn); diff --git a/src/core/main.c b/src/core/main.c index 35c7bb2c..f6448e80 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -23,7 +23,7 @@ Literature dealing with the network protocols: #include "timer.h" #include "cpu.h" #include "console.h" -#include "init.h" +#include #include "image.h" #include diff --git a/src/core/pcmcia.c b/src/core/pcmcia.c index 03a96de8..b4faceaf 100644 --- a/src/core/pcmcia.c +++ b/src/core/pcmcia.c @@ -29,7 +29,7 @@ #define CODE_VERSION "0.1.3" #include "pcmcia-opts.h" #include "console.h" -#include "init.h" +#include int sockets; /* AHTODO: Phase this out! */ u_int pccsocks; diff --git a/src/core/serial.c b/src/core/serial.c index 802b32a7..52cf0e44 100644 --- a/src/core/serial.c +++ b/src/core/serial.c @@ -13,7 +13,7 @@ #include "stddef.h" #include "console.h" -#include "init.h" +#include #include "io.h" #include "timer.h" #include "config/serial.h" diff --git a/src/include/gpxe/init.h b/src/include/gpxe/init.h new file mode 100644 index 00000000..7a4b7262 --- /dev/null +++ b/src/include/gpxe/init.h @@ -0,0 +1,66 @@ +#ifndef INIT_H +#define INIT_H + +#include + +/* + * In order to avoid having objects dragged in just because main() + * calls their initialisation function, we allow each object to + * specify that it has a function that must be called to initialise + * that object. The function call_init_fns() will call all the + * included objects' initialisation functions. + * + * Objects that require initialisation should include init.h and + * register the initialisation function using INIT_FN(). + * + * Objects may register up to three functions: init, reset and exit. + * init gets called only once, at the point that Etherboot is + * initialised (before the call to main()). reset gets called between + * each boot attempt. exit gets called only once, just before the + * loaded OS starts up (or just before Etherboot exits, if it exits, + * or when the PXE NBP calls UNDI_SHUTDOWN, if it's a PXE NBP). + * + * The syntax is: + * INIT_FN ( init_order, init_function, reset_function, exit_function ); + * where init_order is an ordering taken from the list below. Any + * function may be left as NULL. + */ + +/* An entry in the initialisation function table */ + +struct init_fn { + void ( *init ) ( void ); + void ( *reset ) ( void ); + void ( *exit ) ( void ); +}; + +/* Use double digits to avoid problems with "10" < "9" on alphabetic sort */ +#define INIT_LIBRM 01 +#define INIT_CONSOLE 02 +#define INIT_CPU 03 +#define INIT_TIMERS 04 +#define INIT_PCIBIOS 05 +#define INIT_MEMSIZES 06 +#define INIT_RELOCATE 07 +#define INIT_LOADBUF 08 +#define INIT_PCMCIA 09 +#define INIT_HEAP 10 +#define INIT_RPC 11 +#define INIT_PROCESS 12 + +/* Macro for creating an initialisation function table entry */ +#define INIT_FN( init_order, init_func, reset_func, exit_func ) \ + struct init_fn PREFIX_OBJECT(init_fn__) \ + __table ( init_fn, init_order ) = { \ + .init = init_func, \ + .reset = reset_func, \ + .exit = exit_func, \ + }; + +/* Function prototypes */ + +void call_init_fns ( void ); +void call_reset_fns ( void ); +void call_exit_fns ( void ); + +#endif /* INIT_H */ diff --git a/src/net/netdevice.c b/src/net/netdevice.c index 19db792e..47b37cf7 100644 --- a/src/net/netdevice.c +++ b/src/net/netdevice.c @@ -24,6 +24,7 @@ #include #include #include +#include #include /** @file @@ -287,8 +288,6 @@ int net_rx_process ( struct pk_buff *pkb ) { return 0; } - - /** * Single-step the network stack * @@ -318,10 +317,9 @@ static struct process net_process = { .step = net_step, }; +/** Initialise the networking stack process */ static void init_net ( void ) { schedule ( &net_process ); } -#include - -INIT_FN ( INIT_RPC, init_net, NULL, NULL ); +INIT_FN ( INIT_PROCESS, init_net, NULL, NULL ); diff --git a/src/proto/nfs.c b/src/proto/nfs.c index ebcca737..c700ed67 100644 --- a/src/proto/nfs.c +++ b/src/proto/nfs.c @@ -1,5 +1,5 @@ #include "etherboot.h" -#include "init.h" +#include #include "proto.h" #include #include "nic.h"