Usermode/libc++ - Basic C++ runtime implementation
authorJohn Hodge <[email protected]>
Sun, 9 Mar 2014 07:44:45 +0000 (15:44 +0800)
committerJohn Hodge <[email protected]>
Sun, 9 Mar 2014 07:44:45 +0000 (15:44 +0800)
Usermode/Libraries/libc++.so_src/Makefile [new file with mode: 0644]
Usermode/Libraries/libc++.so_src/cxxabi.cc [new file with mode: 0644]
Usermode/Libraries/libc++.so_src/guard.cc [new file with mode: 0644]
Usermode/Libraries/libc++.so_src/include_exp/cxxabi.h [new file with mode: 0644]
Usermode/Libraries/libc++.so_src/include_exp/typeinfo [new file with mode: 0644]
Usermode/Libraries/libc++.so_src/misc.cc [new file with mode: 0644]
Usermode/Libraries/libc++.so_src/new.cc [new file with mode: 0644]
Usermode/Libraries/libc++.so_src/typeinfo.cc [new file with mode: 0644]

diff --git a/Usermode/Libraries/libc++.so_src/Makefile b/Usermode/Libraries/libc++.so_src/Makefile
new file mode 100644 (file)
index 0000000..6cec94f
--- /dev/null
@@ -0,0 +1,20 @@
+# Acess2 C++ Library\r
+# Makefile\r
+\r
+-include ../Makefile.cfg\r
+\r
+CPPFLAGS += \r
+CFLAGS   += -Wall -Werror -Wextra\r
+CXXFLAGS += -Wall -Werror -Wextra\r
+ASFLAGS  +=\r
+LDFLAGS  += -Map map.txt -lc\r
+\r
+OBJ  = misc.o new.o guard.o cxxabi.o typeinfo.o\r
+DEPFILES := $(OBJ:%.o=%.d)\r
+BIN = libc++.so\r
+ifeq ($(ARCHDIR),native)\r
+ OBJ := $(filter-out heap.o,$(OBJ))\r
+ BIN = libc++_acess.so\r
+endif\r
+\r
+include ../Makefile.tpl\r
diff --git a/Usermode/Libraries/libc++.so_src/cxxabi.cc b/Usermode/Libraries/libc++.so_src/cxxabi.cc
new file mode 100644 (file)
index 0000000..adda291
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Acess2 C++ Library
+ * - By John Hodge (thePowersGang)
+ *
+ * cxxabi.cc
+ * - C++ ABI Namespace
+ */
+#include <cxxabi.h>
+
+namespace __cxxabiv1 {
+
+// --- RTTI --
+// - No inheritance class
+__class_type_info::~__class_type_info()
+{
+       // nop
+}
+
+// - Single inheritance class
+__si_class_type_info::~__si_class_type_info()
+{
+       
+}
+
+// - Multiple inheritance class
+__vmi_class_type_info::~__vmi_class_type_info()
+{
+       
+}
+
+};     // namespace __cxxabiv1
+
diff --git a/Usermode/Libraries/libc++.so_src/guard.cc b/Usermode/Libraries/libc++.so_src/guard.cc
new file mode 100644 (file)
index 0000000..a075a7b
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Acess2 C++ Library
+ * - By John Hodge (thePowersGang)
+ *
+ * guard.cc
+ * - One-time construction API
+ */
+#include <stdint.h>
+
+extern "C" int __cxa_guard_acquire ( int64_t *guard_object )
+{
+       // TODO: Mutex!
+       if( *guard_object )
+               return 1;
+       *guard_object = 1;
+       return 0;
+}
+
+extern "C" void __cxa_guard_release ( int64_t *guard_object )
+{
+       *guard_object = 0;
+}
+
+extern "C" void __cxa_guard_abort ( int64_t *guard_object )
+{
+       *guard_object = 0;
+       // TODO: abort
+}
+
diff --git a/Usermode/Libraries/libc++.so_src/include_exp/cxxabi.h b/Usermode/Libraries/libc++.so_src/include_exp/cxxabi.h
new file mode 100644 (file)
index 0000000..a8e1f5c
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Acess2 C++ Library
+ * - By John Hodge (thePowersGang)
+ *
+ * cxxabi.h
+ * - C++ ABI Namespace
+ */
+#ifndef _LIBCXX__CXXABI_H_
+#define _LIBCXX__CXXABI_H_
+
+#include <typeinfo>
+
+namespace __cxxabiv1 {
+
+class __class_type_info : public std::type_info
+{
+public:
+       virtual ~__class_type_info();
+};
+
+class __si_class_type_info : public __class_type_info
+{
+public:
+       virtual ~__si_class_type_info();
+       
+       const __class_type_info *__base_type;
+};
+
+struct __base_class_type_info
+{
+public:
+       
+       const __class_type_info *__base_type;
+       long __offset_flags;
+
+       enum __offset_flags_masks {
+               __virtual_mask = 0x1,
+               __public_mask = 0x2,
+               __offset_shift = 8
+       };
+
+};
+
+class __vmi_class_type_info : public __class_type_info
+{
+public:
+       virtual ~__vmi_class_type_info();
+       
+       unsigned int    __flags;
+       unsigned int    __base_count;
+       __base_class_type_info  __base_info[1];
+       
+       enum __flags_masks {
+               __non_diamond_repeat_mask = 0x1,
+               __diamond_shaped_mask = 0x2,
+       };
+};
+
+class __pbase_type_info : public std::type_info
+{
+public:
+       unsigned int __flags;
+       const std::type_info *__pointee;
+
+       enum __masks {
+               __const_mask = 0x1,
+               __volatile_mask = 0x2,
+               __restrict_mask = 0x4,
+               __incomplete_mask = 0x8,
+               __incomplete_class_mask = 0x10
+       };
+};
+
+};     // namespace __cxxabiv1
+
+#endif
diff --git a/Usermode/Libraries/libc++.so_src/include_exp/typeinfo b/Usermode/Libraries/libc++.so_src/include_exp/typeinfo
new file mode 100644 (file)
index 0000000..c02d388
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Acess2 C++ Library
+ * - By John Hodge (thePowersGang)
+ *
+ * typeinfo (header)
+ * - typeid and dynamic_cast
+ */
+#ifndef _LIBCXX__TYPEINFO_
+#define _LIBCXX__TYPEINFO_
+
+namespace std {
+
+// Type information class
+class type_info
+{
+public:
+       virtual ~type_info();
+       bool operator==(const type_info &) const;
+       bool operator!=(const type_info &) const;
+       bool before(const type_info &) const;
+       const char* name() const;
+private:
+       type_info (const type_info& rhs);
+       type_info& operator= (const type_info& rhs);
+       
+       // CXX ABI
+       const char *__type_name;
+};
+
+};
+
+#endif
+
+// vim: ft=cpp
+
diff --git a/Usermode/Libraries/libc++.so_src/misc.cc b/Usermode/Libraries/libc++.so_src/misc.cc
new file mode 100644 (file)
index 0000000..ed0a2eb
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Acess2 C++ Library
+ * - By John Hodge (thePowersGang)
+ *
+ * misc.cc
+ * - Miscelanious functions
+ */
+#include <string.h>
+
+extern "C" int SoMain()
+{
+       // nope
+       return 0;
+}
+
+extern "C" void __cxa_pure_virtual()
+{
+       // dunno
+}
+
+extern "C" void __gxx_personality_v0()
+{
+       // TODO: Handle __gxx_personality_v0 somehow
+}
+
+
+// DSO Support 
+#define MAX_ATEXIT     32
+static struct {
+       void (*destructor) (void *);
+       void    *arg;
+       void    *dso_handle;
+} __cxa_atexit_funcs[MAX_ATEXIT];
+static int     __cxa_atexit_func_count;
+
+extern "C" int __cxa_atexit(void (*destructor) (void *), void *arg, void *dso_handle)
+{
+       if( __cxa_atexit_func_count == MAX_ATEXIT )
+       {
+               return 1;
+       }
+       
+       __cxa_atexit_funcs[__cxa_atexit_func_count].destructor = destructor;
+       __cxa_atexit_funcs[__cxa_atexit_func_count].arg = arg;
+       __cxa_atexit_funcs[__cxa_atexit_func_count].dso_handle = dso_handle;
+       __cxa_atexit_func_count ++;
+       return 0;
+}
+
+extern "C" void __cxa_finalize(void *f)
+{
+       if( f == 0 )
+       {
+               for( int i = __cxa_atexit_func_count; i --; )
+               {
+                       if( __cxa_atexit_funcs[i].dso_handle == f )
+                       {
+                               __cxa_atexit_funcs[i].destructor(__cxa_atexit_funcs[i].arg);
+                               memmove(
+                                       &__cxa_atexit_funcs[i],
+                                       &__cxa_atexit_funcs[i+1],
+                                       (__cxa_atexit_func_count-i)*sizeof(__cxa_atexit_funcs[0])
+                                       );
+                               i ++;
+                               __cxa_atexit_func_count --;
+                       }
+               }
+       }
+       else
+       {
+               for( int i = __cxa_atexit_func_count; i --; )
+               {
+                       __cxa_atexit_funcs[i].destructor(__cxa_atexit_funcs[i].arg);
+               }
+               __cxa_atexit_func_count = 0;
+       }
+}
+
diff --git a/Usermode/Libraries/libc++.so_src/new.cc b/Usermode/Libraries/libc++.so_src/new.cc
new file mode 100644 (file)
index 0000000..1d09fbc
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Acess2 C++ Library
+ * - By John Hodge (thePowersGang)
+ *
+ * new.cc
+ * - new/delete
+ */
+#include <stddef.h>
+#include <stdlib.h>
+
+// === CODE ===
+void *operator new( size_t size )
+{
+       return malloc( size );
+}
+
+void *operator new[]( size_t size )
+{
+       return malloc( size );
+}
+
+void operator delete(void *ptr)
+{
+       free(ptr);
+}
+
+void operator delete[](void *ptr)
+{
+       free(ptr);
+}
+
diff --git a/Usermode/Libraries/libc++.so_src/typeinfo.cc b/Usermode/Libraries/libc++.so_src/typeinfo.cc
new file mode 100644 (file)
index 0000000..b0a9b3e
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Acess2 C++ Library
+ * - By John Hodge (thePowersGang)
+ *
+ * typeinfo.cc
+ * - typeid and dynamic_cast
+ */
+#include <typeinfo>
+
+namespace std {
+
+type_info::~type_info()
+{
+       // nop
+}
+
+bool type_info::operator==(const type_info& other) const
+{
+       return this->__type_name == other.__type_name;
+}
+
+bool type_info::operator!=(const type_info& other) const
+{
+       return this->__type_name != other.__type_name;
+}
+
+bool type_info::before(const type_info& other) const
+{
+       return this->__type_name < other.__type_name;
+}
+
+const char *type_info::name() const
+{
+       return this->__type_name;
+}
+
+// Private
+type_info::type_info(const type_info& rhs):
+       __type_name(rhs.__type_name)
+{
+}
+type_info& type_info::operator=(const type_info& rhs)
+{
+       __type_name = rhs.__type_name;
+       return *this;
+}
+
+
+};     // namespace std
+

UCC git Repository :: git.ucc.asn.au