iPXE
Data Structures | Macros | Functions
init.h File Reference
#include <ipxe/tables.h>

Go to the source code of this file.

Data Structures

struct  init_fn
 An initialisation function. More...
 
struct  startup_fn
 A startup/shutdown function. More...
 

Macros

#define INIT_FNS   __table ( struct init_fn, "init_fns" )
 Initialisation function table. More...
 
#define __init_fn(init_order)   __table_entry ( INIT_FNS, init_order )
 Declare an initialisation functon. More...
 
#define INIT_EARLY   01
 Early initialisation. More...
 
#define INIT_CONSOLE   02
 Console initialisation. More...
 
#define INIT_NORMAL   03
 Normal initialisation. More...
 
#define INIT_LATE   04
 Late initialisation. More...
 
#define STARTUP_FNS   __table ( struct startup_fn, "startup_fns" )
 Startup/shutdown function table. More...
 
#define __startup_fn(startup_order)   __table_entry ( STARTUP_FNS, startup_order )
 Declare a startup/shutdown function. More...
 
#define STARTUP_EARLY   01
 Early startup. More...
 
#define STARTUP_NORMAL   02
 Normal startup. More...
 
#define STARTUP_LATE   03
 Late startup. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
void initialise (void)
 Initialise iPXE. More...
 
void startup (void)
 Start up iPXE. More...
 
void shutdown (int booting)
 Shut down iPXE. More...
 
static void shutdown_boot (void)
 Shut down system for OS boot. More...
 
static void shutdown_exit (void)
 Shut down system for exit back to firmware. More...
 

Macro Definition Documentation

◆ INIT_FNS

#define INIT_FNS   __table ( struct init_fn, "init_fns" )

Initialisation function table.

Definition at line 19 of file init.h.

◆ __init_fn

#define __init_fn (   init_order)    __table_entry ( INIT_FNS, init_order )

Declare an initialisation functon.

Definition at line 22 of file init.h.

◆ STARTUP_FNS

#define STARTUP_FNS   __table ( struct startup_fn, "startup_fns" )

Startup/shutdown function table.

Definition at line 48 of file init.h.

◆ __startup_fn

#define __startup_fn (   startup_order)    __table_entry ( STARTUP_FNS, startup_order )

Declare a startup/shutdown function.

Definition at line 51 of file init.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ initialise()

void initialise ( void  )

Initialise iPXE.

This function performs the one-time-only and irreversible initialisation steps, such as initialising the heap. It must be called before (almost) any other function.

There is, by definition, no counterpart to this function on the shutdown path.

Definition at line 52 of file init.c.

52  {
53  struct init_fn *init_fn;
54 
55  /* Call registered initialisation functions */
57  init_fn->initialise ();
58 }
#define INIT_FNS
Initialisation function table.
Definition: init.h:19
void(* initialise)(void)
Definition: init.h:15
An initialisation function.
Definition: init.h:14
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358

References for_each_table_entry, INIT_FNS, and init_fn::initialise.

Referenced by _efidrv_start(), main(), and undi_loader().

◆ startup()

void startup ( void  )

Start up iPXE.

This function performs the repeatable initialisation steps, such as probing devices. You may call startup() and shutdown() multiple times (as is done via the PXE API when PXENV_START_UNDI is used).

Definition at line 67 of file init.c.

67  {
68  struct startup_fn *startup_fn;
69 
70  if ( started )
71  return;
72 
73  /* Call registered startup functions */
75  if ( startup_fn->startup ) {
76  DBGC ( colour, "INIT startup %s...\n",
77  startup_fn->name );
79  }
80  }
81 
82  started = 1;
83  DBGC ( colour, "INIT startup complete\n" );
84 }
#define DBGC(...)
Definition: compiler.h:505
const char * name
Definition: init.h:42
A startup/shutdown function.
Definition: init.h:41
#define colour
Colour for debug messages.
Definition: init.c:40
static int started
"startup() has been called" flag
Definition: init.c:37
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
void(* startup)(void)
Definition: init.h:43
#define STARTUP_FNS
Startup/shutdown function table.
Definition: init.h:48

References colour, DBGC, for_each_table_entry, startup_fn::name, started, startup_fn::startup, and STARTUP_FNS.

Referenced by _efidrv_start(), main(), pxenv_start_undi(), and select_media().

◆ shutdown()

void shutdown ( int  flags)

Shut down iPXE.

Parameters
flagsShutdown behaviour flags

This function reverses the actions of startup(), and leaves iPXE in a state ready to be removed from memory. You may call startup() again after calling shutdown().

Call this function only once, before either exiting main() or starting up a non-returnable image.

Definition at line 98 of file init.c.

98  {
99  struct startup_fn *startup_fn;
100 
101  if ( ! started )
102  return;
103 
104  /* Call registered shutdown functions (in reverse order) */
106  if ( startup_fn->shutdown ) {
107  DBGC ( colour, "INIT shutdown %s...\n",
108  startup_fn->name );
110  }
111  }
112 
113  /* Reset console */
114  console_reset();
115 
116  started = 0;
117  DBGC ( colour, "INIT shutdown complete\n" );
118 }
#define DBGC(...)
Definition: compiler.h:505
#define for_each_table_entry_reverse(pointer, table)
Iterate through all entries within a linker table in reverse order.
Definition: tables.h:413
const char * name
Definition: init.h:42
A startup/shutdown function.
Definition: init.h:41
#define colour
Colour for debug messages.
Definition: init.c:40
static int started
"startup() has been called" flag
Definition: init.c:37
static void console_reset(void)
Reset console.
Definition: console.h:214
void(* shutdown)(int booting)
Definition: init.h:44
#define STARTUP_FNS
Startup/shutdown function table.
Definition: init.h:48
uint8_t flags
Flags.
Definition: ena.h:18

References colour, console_reset(), DBGC, flags, for_each_table_entry_reverse, startup_fn::name, startup_fn::shutdown, started, and STARTUP_FNS.

Referenced by intelxl_admin_shutdown(), shutdown_boot(), and shutdown_exit().

◆ shutdown_boot()

static void shutdown_boot ( void  )
inlinestatic

Shut down system for OS boot.

Definition at line 76 of file init.h.

76  {
77  shutdown ( 1 );
78 }
void shutdown(int booting)
Shut down iPXE.
Definition: init.c:98

References shutdown().

Referenced by bzimage_exec(), efi_shutdown_hook(), elfboot_exec(), int22(), multiboot_exec(), nbi_exec(), and pxenv_stop_undi().

◆ shutdown_exit()

static void shutdown_exit ( void  )
inlinestatic

Shut down system for exit back to firmware.

Definition at line 84 of file init.h.

84  {
85  shutdown ( 0 );
86 }
void shutdown(int booting)
Shut down iPXE.
Definition: init.c:98

References shutdown().

Referenced by efi_unload(), and main().