Update #2408. --- v2: Add documentation to user manual. c/src/lib/libbsp/shared/bootcard.c | 84 ++++++++++++------------------------ cpukit/score/Makefile.am | 1 + cpukit/score/include/rtems/sysinit.h | 51 ++++++++++++++++++++++ cpukit/score/preinstall.am | 4 ++ 4 files changed, 83 insertions(+), 57 deletions(-) create mode 100644 cpukit/score/include/rtems/sysinit.h
diff --git a/c/src/lib/libbsp/shared/bootcard.c b/c/src/lib/libbsp/shared/bootcard.c index eeb5746..4bdc0b4 100644 --- a/c/src/lib/libbsp/shared/bootcard.c +++ b/c/src/lib/libbsp/shared/bootcard.c @@ -47,6 +47,7 @@ #include <bsp/bootcard.h> #include <rtems.h> +#include <rtems/sysinit.h> /* * At most a single pointer to the cmdline for those target @@ -54,6 +55,26 @@ */ const char *bsp_boot_cmdline; +RTEMS_LINKER_ROSET(_Sysinit, rtems_sysinit_item); + +RTEMS_SYSINIT_ITEM(bsp_start, RTEMS_SYSINIT_BSP_START); + +RTEMS_SYSINIT_ITEM(bsp_work_area_initialize, RTEMS_SYSINIT_WORK_AREAS); + +RTEMS_SYSINIT_ITEM(rtems_initialize_data_structures, RTEMS_SYSINIT_DATA_STRUCTURES); + +RTEMS_SYSINIT_ITEM(bsp_libc_init, RTEMS_SYSINIT_LIBC); + +RTEMS_SYSINIT_ITEM(bsp_pretasking_hook, RTEMS_SYSINIT_PRE_TASKING); + +RTEMS_SYSINIT_ITEM(rtems_initialize_before_drivers, RTEMS_SYSINIT_EARLY_PRE_DRIVERS); + +RTEMS_SYSINIT_ITEM(bsp_predriver_hook, RTEMS_SYSINIT_PRE_DRIVERS); + +RTEMS_SYSINIT_ITEM(rtems_initialize_device_drivers, RTEMS_SYSINIT_DRIVERS); + +RTEMS_SYSINIT_ITEM(bsp_postdriver_hook, RTEMS_SYSINIT_POST_DRIVERS); + /* * This is the initialization framework routine that weaves together * calls to RTEMS and the BSP in the proper sequence to initialize @@ -65,6 +86,8 @@ void boot_card( ) { rtems_interrupt_level bsp_isr_level; + const volatile rtems_sysinit_item *cur = RTEMS_LINKER_SET_BEGIN(_Sysinit ); + const volatile rtems_sysinit_item *end = RTEMS_LINKER_SET_END( _Sysinit ); /* * Make sure interrupts are disabled. @@ -74,63 +97,10 @@ void boot_card( bsp_boot_cmdline = cmdline; - /* - * Invoke Board Support Package initialization routine written in C. - */ - bsp_start(); - - /* - * Initialize the RTEMS Workspace and the C Program Heap. - */ - bsp_work_area_initialize(); - - /* - * Initialize RTEMS data structures - */ - rtems_initialize_data_structures(); - - /* - * Initialize the C library for those BSPs using the shared - * framework. - */ - bsp_libc_init(); - - /* - * Let the BSP do any required initialization now that RTEMS - * data structures are initialized. In older BSPs or those - * which do not use the shared framework, this is the typical - * time when the C Library is initialized so malloc() - * can be called by device drivers. For BSPs using the shared - * framework, this routine can be empty. - */ - bsp_pretasking_hook(); - - /* - * Let RTEMS perform initialization it requires before drivers - * are allowed to be initialized. - */ - rtems_initialize_before_drivers(); - - /* - * Execute BSP specific pre-driver hook. Drivers haven't gotten - * to initialize yet so this is a good chance to initialize - * buses, spurious interrupt handlers, etc.. - * - * NOTE: Many BSPs do not require this handler and use the - * shared stub. - */ - bsp_predriver_hook(); - - /* - * Initialize all device drivers. - */ - rtems_initialize_device_drivers(); - - /* - * Invoke the postdriver hook. This normally opens /dev/console - * for use as stdin, stdout, and stderr. - */ - bsp_postdriver_hook(); + while ( cur != end ) { + ( *cur->handler )(); + ++cur; + } /* * Complete initialization of RTEMS and switch to the first task. diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am index c90f4a2..04c5c87 100644 --- a/cpukit/score/Makefile.am +++ b/cpukit/score/Makefile.am @@ -18,6 +18,7 @@ include_rtemsdir = $(includedir)/rtems include_rtems_HEADERS = include_rtems_HEADERS += include/rtems/linkersets.h +include_rtems_HEADERS += include/rtems/sysinit.h include_rtems_HEADERS += include/rtems/system.h include_rtems_HEADERS += include/rtems/seterr.h diff --git a/cpukit/score/include/rtems/sysinit.h b/cpukit/score/include/rtems/sysinit.h new file mode 100644 index 0000000..fbe21da --- /dev/null +++ b/cpukit/score/include/rtems/sysinit.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * <rt...@embedded-brains.de> + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifndef _RTEMS_SYSINIT_H +#define _RTEMS_SYSINIT_H + +#include <rtems/linkersets.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define RTEMS_SYSINIT_BSP_START 0x0001000 +#define RTEMS_SYSINIT_WORK_AREAS 0x0002000 +#define RTEMS_SYSINIT_DATA_STRUCTURES 0x0003000 +#define RTEMS_SYSINIT_LIBC 0x0004000 +#define RTEMS_SYSINIT_PRE_TASKING 0x0005000 +#define RTEMS_SYSINIT_EARLY_PRE_DRIVERS 0x0006000 +#define RTEMS_SYSINIT_PRE_DRIVERS 0x0007000 +#define RTEMS_SYSINIT_DRIVERS 0x0008000 +#define RTEMS_SYSINIT_POST_DRIVERS 0x0009000 + +typedef void ( *rtems_sysinit_handler )( void ); + +typedef struct { + rtems_sysinit_handler handler; +} rtems_sysinit_item; + +#define RTEMS_SYSINIT_ITEM( handler, o ) \ + enum { _Sysinit_##handler = o - o }; \ + RTEMS_LINKER_ROSET_ITEM_ORDERED( \ + _Sysinit, \ + rtems_sysinit_item, handler, o \ + ) = { handler } + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _RTEMS_SYSINIT_H */ diff --git a/cpukit/score/preinstall.am b/cpukit/score/preinstall.am index 4a45e87..1cc44da 100644 --- a/cpukit/score/preinstall.am +++ b/cpukit/score/preinstall.am @@ -47,6 +47,10 @@ $(PROJECT_INCLUDE)/rtems/linkersets.h: include/rtems/linkersets.h $(PROJECT_INCL $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/linkersets.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/linkersets.h +$(PROJECT_INCLUDE)/rtems/sysinit.h: include/rtems/sysinit.h $(PROJECT_INCLUDE)/rtems/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/sysinit.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/sysinit.h + $(PROJECT_INCLUDE)/rtems/system.h: include/rtems/system.h $(PROJECT_INCLUDE)/rtems/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/system.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/system.h -- 1.8.4.5 _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel