arc_cxx_support.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (c) 2012-2014 Wind River Systems, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* ------------------------------------------
  17. * Copyright (c) 2015, Synopsys, Inc. All rights reserved.
  18. * Redistribution and use in source and binary forms, with or without modification,
  19. * are permitted provided that the following conditions are met:
  20. * 1) Redistributions of source code must retain the above copyright notice, this
  21. * list of conditions and the following disclaimer.
  22. * 2) Redistributions in binary form must reproduce the above copyright notice,
  23. * this list of conditions and the following disclaimer in the documentation and/or
  24. * other materials provided with the distribution.
  25. * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
  26. * be used to endorse or promote products derived from this software without
  27. * specific prior written permission.
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  29. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  30. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  32. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  33. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  35. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  36. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * \version 2016.05
  40. * \date 2016-03-02
  41. * \author Wayne Ren(wei.ren@synopsys.com)
  42. --------------------------------------------- */
  43. #include "embARC_BSP_config.h"
  44. #if defined(__GNU__)
  45. /* embARC's GNU C++ support takes reference from Zephyr (cpp_xxx.c) */
  46. /**
  47. * @file - Constructor module
  48. * @brief
  49. * The ctors section contains a list of function pointers that execute the
  50. * C++ constructors of static global objects. These must be executed before
  51. * the application's main() routine.
  52. *
  53. * NOTE: Not all compilers put those function pointers into the ctors section;
  54. * some put them into the init_array section instead.
  55. */
  56. /* What a constructor function pointer looks like */
  57. typedef void (*CtorFuncPtr)(void);
  58. /* Constructor function pointer list is generated by the linker script. */
  59. extern CtorFuncPtr __CTOR_LIST__[];
  60. extern CtorFuncPtr __CTOR_END__[];
  61. /**
  62. *
  63. * @brief Invoke all C++ style global object constructors
  64. *
  65. * This routine is invoked before the execution of the
  66. * application's main().
  67. */
  68. void __do_global_ctors_aux(void)
  69. {
  70. unsigned int nCtors;
  71. nCtors = (unsigned int)__CTOR_LIST__[0];
  72. while (nCtors >= 1) {
  73. __CTOR_LIST__[nCtors--]();
  74. }
  75. }
  76. typedef void (*DtorFuncPtr)(void);
  77. extern DtorFuncPtr __DTOR_LIST__[];
  78. extern DtorFuncPtr __DTOR_END__[];
  79. /**
  80. *
  81. * @brief Invoke all C++ style global object destructors
  82. *
  83. * This routine is invoked after the execution of the
  84. * application's main().
  85. */
  86. void __do_global_dtors_aux(void)
  87. {
  88. unsigned int nDtors;
  89. unsigned int i;
  90. nDtors = (unsigned int)__DTOR_LIST__[0];
  91. i = 0;
  92. while (i <= nDtors) {
  93. __DTOR_LIST__[i++]();
  94. }
  95. }
  96. void *__dso_handle = 0;
  97. /**
  98. * @brief Register destructor for a global object
  99. *
  100. * @param destructor the global object destructor function
  101. * @param objptr global object pointer
  102. * @param dso Dynamic Shared Object handle for shared libraries
  103. *
  104. * Function does nothing at the moment, assuming the global objects
  105. * do not need to be deleted
  106. *
  107. * @return N/A
  108. */
  109. int __cxa_atexit(void (*destructor)(void *), void *objptr, void *dso)
  110. {
  111. return 0;
  112. }
  113. typedef void (*func_ptr)(void);
  114. extern func_ptr __init_array_start[0];
  115. extern func_ptr __init_array_end[0];
  116. /**
  117. * @brief Execute initialization routines referenced in .init_array section
  118. *
  119. * @return N/A
  120. */
  121. void __do_init_array_aux(void)
  122. {
  123. for (func_ptr *func = __init_array_start;
  124. func < __init_array_end;
  125. func++) {
  126. (*func)();
  127. }
  128. }
  129. /**
  130. * @brief Stub for pure virtual functions
  131. *
  132. * This routine is needed for linking C++ code that uses pure virtual
  133. * functions.
  134. *
  135. * @return N/A
  136. */
  137. void __cxa_pure_virtual(void)
  138. {
  139. while (1) {
  140. ;
  141. }
  142. }
  143. #endif