From e86960a2834194a372020cf40e808d12770d4038 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 28 Feb 2016 13:19:02 -0500 Subject: [PATCH] Add cxa_guard functions for C++ ABI compatibility --- src/SConscript | 3 ++- src/cxa.cc | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/cxa.cc diff --git a/src/SConscript b/src/SConscript index 4806671..efe4765 100644 --- a/src/SConscript +++ b/src/SConscript @@ -10,7 +10,8 @@ import subprocess files = [ 'boot.s', 'Main.cc', - 'Console.cc' + 'Console.cc', + 'cxa.cc', ] toolchain_bin = Dir(os.environ['POLKA_TOOLCHAIN']).Dir('bin') diff --git a/src/cxa.cc b/src/cxa.cc new file mode 100644 index 0000000..40650c4 --- /dev/null +++ b/src/cxa.cc @@ -0,0 +1,49 @@ +/* cxa.cc + * vim: set tw=80: + * Eryn Wells + */ +/** + * Implements some functions required by the C++ ABI so that local static + * variables can be initialized properly. + */ + +namespace __cxxabiv1 { + +// 64-bit integer type to service as mutex-like guard. +__extension__ typedef int __guard __attribute__((mode(__DI__))); + +extern "C" { + +/* + * TODO: The functions below are required by the C++ ABI and should be thread + * safe. Since Polka currently has no threads, it should be fine to do this + * without any actual locking. Once/If I add threading, I need to come back here + * and add an actual mutex with a test-and-set. + * + * See http://wiki.osdev.org/C%2B%2B#Local_Static_Variables_.28GCC_Only.29 + * See the Intel XCHG instruction + */ + +int +__cxa_guard_acquire(__guard *g) +{ + return !*(g); +} + + +void +__cxa_guard_release(__guard *g) +{ + *g = 1; +} + + +void +__cxa_guard_abort(__guard *) +{ + // TODO: What would be useful to do here? +} + +} + +} /* namespace __cxxabiv1 */