subsystem: cleanup misc and make cpp a subsystem

Move a way from misc/ and put in its own subsystem to allow enhancements
in the future and make it a core part of Zephyr, not just something
misc.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2017-06-30 07:10:28 -04:00 committed by Kumar Gala
commit da7cc84655
11 changed files with 26 additions and 19 deletions

7
subsys/cpp/Kconfig Normal file
View file

@ -0,0 +1,7 @@
config CPLUSPLUS
bool "Enable C++ support for the application"
default n
help
This option enables the use of applications built with C++.

7
subsys/cpp/Makefile Normal file
View file

@ -0,0 +1,7 @@
obj-y += cpp_virtual.o \
cpp_vtable.o \
cpp_init_array.o \
cpp_ctors.o \
cpp_dtors.o

43
subsys/cpp/cpp_ctors.c Normal file
View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file - Constructor module
* @brief
* The ctors section contains a list of function pointers that execute the
* C++ constructors of static global objects. These must be executed before
* the application's main() routine.
*
* NOTE: Not all compilers put those function pointers into the ctors section;
* some put them into the init_array section instead.
*/
/* What a constructor function pointer looks like */
typedef void (*CtorFuncPtr)(void);
/* Constructor function pointer list is generated by the linker script. */
extern CtorFuncPtr __CTOR_LIST__[];
extern CtorFuncPtr __CTOR_END__[];
/**
*
* @brief Invoke all C++ style global object constructors
*
* This routine is invoked by the kernel prior to the execution of the
* application's main().
*/
void __do_global_ctors_aux(void)
{
unsigned int nCtors;
nCtors = (unsigned int)__CTOR_LIST__[0];
while (nCtors >= 1) {
__CTOR_LIST__[nCtors--]();
}
}

35
subsys/cpp/cpp_dtors.c Normal file
View file

@ -0,0 +1,35 @@
/*
* Copyright (c) 2016 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* @file
* @brief Basic C++ destructor module for globals
*
*/
#include <toolchain.h>
void *__dso_handle = 0;
/**
* @brief Register destructor for a global object
*
* @param destructor the global object destructor function
* @param objptr global object pointer
* @param dso Dynamic Shared Object handle for shared libraries
*
* Function does nothing at the moment, assuming the global objects
* do not need to be deleted
*
* @return N/A
*/
int __cxa_atexit(void (*destructor)(void *), void *objptr, void *dso)
{
ARG_UNUSED(destructor);
ARG_UNUSED(objptr);
ARG_UNUSED(dso);
return 0;
}

View file

@ -0,0 +1,29 @@
/*
* Copyright (c) 2015 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* @file
* @brief Execute initialization routines referenced in .init_array section
*/
typedef void (*func_ptr)(void);
extern func_ptr __init_array_start[0];
extern func_ptr __init_array_end[0];
/**
* @brief Execute initialization routines referenced in .init_array section
*
* @return N/A
*/
void __do_init_array_aux(void)
{
for (func_ptr *func = __init_array_start;
func < __init_array_end;
func++) {
(*func)();
}
}

25
subsys/cpp/cpp_virtual.c Normal file
View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2015 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* @file
* @brief Stub for C++ pure virtual functions
*/
/**
* @brief Stub for pure virtual functions
*
* This routine is needed for linking C++ code that uses pure virtual
* functions.
*
* @return N/A
*/
void __cxa_pure_virtual(void)
{
while (1) {
;
}
}

27
subsys/cpp/cpp_vtable.cpp Normal file
View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2015 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* @file
* @brief Stub for C++ virtual tables
*/
/**
*
* @brief basic virtual tables required for classes to build
*
*/
namespace __cxxabiv1 {
class __class_type_info {
virtual void dummy();
};
class __si_class_type_info {
virtual void dummy();
};
void __class_type_info::dummy() { } // causes the vtable to get created here
void __si_class_type_info::dummy() { } // causes the vtable to get created here
};