diff --git a/hardware/arduino/cores/arduino/Printable.h b/hardware/arduino/cores/arduino/Printable.h index d03c9af62c4..54f7d717c60 100644 --- a/hardware/arduino/cores/arduino/Printable.h +++ b/hardware/arduino/cores/arduino/Printable.h @@ -20,8 +20,6 @@ #ifndef Printable_h #define Printable_h -#include - class Print; /** The Printable class provides a way for new classes to allow themselves to be printed. diff --git a/hardware/arduino/cores/arduino/abi.cpp b/hardware/arduino/cores/arduino/abi.cpp new file mode 100644 index 00000000000..3c2dfed537f --- /dev/null +++ b/hardware/arduino/cores/arduino/abi.cpp @@ -0,0 +1,56 @@ +#include +#include +#include + +#include +#include + +namespace { +// guard is an integer type big enough to hold flag and a mutex. +// By default gcc uses long long int and avr ABI does not change it +// So we have 32 or 64 bits available. Actually, we need 16. + +inline char& flag_part(__guard *g) { + return *(reinterpret_cast(g)); +} + +inline uint8_t& sreg_part(__guard *g) { + return *(reinterpret_cast(g) + sizeof(char)); +} +} + +int __cxa_guard_acquire(__guard *g) { + uint8_t oldSREG = SREG; + cli(); + // Initialization of static variable has to be done with blocked interrupts + // because if this function is called from interrupt and sees that somebody + // else is already doing initialization it MUST wait until initializations + // is complete. That's impossible. + // If you don't want this overhead compile with -fno-threadsafe-statics + if (flag_part(g)) { + SREG = oldSREG; + return false; + } else { + sreg_part(g) = oldSREG; + return true; + } +} + +void __cxa_guard_release (__guard *g) { + flag_part(g) = 1; + SREG = sreg_part(g); +} + +void __cxa_guard_abort (__guard *g) { + SREG = sreg_part(g); +} + +void __cxa_pure_virtual(void) { + // We might want to write some diagnostics to uart in this case + std::terminate(); +} + +void __cxa_deleted_virtual(void) { + // We might want to write some diagnostics to uart in this case + std::terminate(); +} diff --git a/hardware/arduino/cores/arduino/abi.h b/hardware/arduino/cores/arduino/abi.h new file mode 100644 index 00000000000..370087e8c20 --- /dev/null +++ b/hardware/arduino/cores/arduino/abi.h @@ -0,0 +1,19 @@ +/* Header to define cxx abi parts missing from avrlibc */ + +#ifndef ABI_H_INCLUDED +#define ABI_H_INCLUDED + +#include + +__extension__ typedef int __guard __attribute__((mode (__DI__))); + +extern "C" { +int __cxa_guard_acquire(__guard *); +void __cxa_guard_release (__guard *); +void __cxa_guard_abort (__guard *); + +void __cxa_pure_virtual(void) __attribute__ ((__noreturn__)); +void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__)); +} + +#endif diff --git a/hardware/arduino/cores/arduino/new.cpp b/hardware/arduino/cores/arduino/new.cpp deleted file mode 100644 index 0f6d4220ef7..00000000000 --- a/hardware/arduino/cores/arduino/new.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include - -void * operator new(size_t size) -{ - return malloc(size); -} - -void operator delete(void * ptr) -{ - free(ptr); -} - -int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);}; -void __cxa_guard_release (__guard *g) {*(char *)g = 1;}; -void __cxa_guard_abort (__guard *) {}; - -void __cxa_pure_virtual(void) {}; - diff --git a/hardware/arduino/cores/arduino/new.h b/hardware/arduino/cores/arduino/new.h deleted file mode 100644 index cd940ce8b26..00000000000 --- a/hardware/arduino/cores/arduino/new.h +++ /dev/null @@ -1,22 +0,0 @@ -/* Header to define new/delete operators as they aren't provided by avr-gcc by default - Taken from http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=59453 - */ - -#ifndef NEW_H -#define NEW_H - -#include - -void * operator new(size_t size); -void operator delete(void * ptr); - -__extension__ typedef int __guard __attribute__((mode (__DI__))); - -extern "C" int __cxa_guard_acquire(__guard *); -extern "C" void __cxa_guard_release (__guard *); -extern "C" void __cxa_guard_abort (__guard *); - -extern "C" void __cxa_pure_virtual(void); - -#endif -