Index: src/amiga-glue.h ================================================================== --- src/amiga-glue.h +++ src/amiga-glue.h @@ -43,11 +43,11 @@ #else # define PPC_PARAMS(...) (__VA_ARGS__) # define M68K_ARG(...) #endif -extern bool glue_OFInit PPC_PARAMS(unsigned int version, struct OFLibC *_Nonnull libc); +extern bool glue_OFInit PPC_PARAMS(unsigned int version, struct OFLibC *_Nonnull libc, struct Library *_Nonnull RTBase); extern void *_Nullable glue_OFAllocMemory PPC_PARAMS(size_t count, size_t size); extern void *_Nullable glue_OFAllocZeroedMemory PPC_PARAMS(size_t count, size_t size); extern void *_Nullable glue_OFResizeMemory PPC_PARAMS(void *_Nullable pointer, size_t count, size_t size); extern void glue_OFFreeMemory PPC_PARAMS(void *_Nullable pointer); extern void glue_OFHashInit PPC_PARAMS(unsigned long *_Nonnull hash); Index: src/amiga-glue.m ================================================================== --- src/amiga-glue.m +++ src/amiga-glue.m @@ -29,16 +29,17 @@ " blr\n" ); #endif bool __saveds -glue_OFInit PPC_PARAMS(unsigned int version, struct OFLibC *_Nonnull libc) +glue_OFInit PPC_PARAMS(unsigned int version, struct OFLibC *_Nonnull libc, struct Library *_Nonnull RTBase) { M68K_ARG(unsigned int, version, d0) M68K_ARG(struct OFLibC *_Nonnull, libc, a0) + M68K_ARG(struct Library *_Nonnull, RTBase, a0) - return OFInit(version, libc); + return OFInit(version, libc, RTBase); } void *_Nullable __saveds glue_OFAllocMemory PPC_PARAMS(size_t count, size_t size) { Index: src/amiga-library.h ================================================================== --- src/amiga-library.h +++ src/amiga-library.h @@ -15,10 +15,12 @@ #import "macros.h" #import "OFPBKDF2.h" #import "OFScrypt.h" +#include + #ifdef OF_MORPHOS # include # define OF_M68K_ARG(type, name, reg) type name = (type)REG_##reg; #else # define OF_M68K_ARG(type, name, reg) \ @@ -107,9 +109,10 @@ int (*_Nonnull setjmp)(jmp_buf); void __dead2 (*_Nonnull longjmp)(jmp_buf, int); #endif }; -extern bool OFInit(unsigned int version, struct OFLibC *_Nonnull libC); +extern bool OFInit(unsigned int version, struct OFLibC *_Nonnull libC, + struct Library *_Nonnull RTBase); extern unsigned long *OFHashSeedRef(void); extern void OFPBKDF2Wrapper(const OFPBKDF2Parameters *_Nonnull parameters); extern void OFScryptWrapper(const OFScryptParameters *_Nonnull parameters); Index: src/amiga-library.m ================================================================== --- src/amiga-library.m +++ src/amiga-library.m @@ -79,10 +79,11 @@ #ifdef OF_MORPHOS const ULONG __abox__ = 1; #endif struct ExecBase *SysBase; struct OFLibC libC; +struct Library *ObjFWRTBase; #if defined(OF_AMIGAOS_M68K) __asm__ ( ".text\n" ".globl ___restore_a4\n" @@ -325,13 +326,28 @@ static void * libNull(void) { return NULL; } + +static void __saveds +OFInitPart2(uintptr_t *iter0, struct Library *RTBase) +{ + uintptr_t *iter; + + ObjFWRTBase = RTBase; + + for (iter = iter0; *iter != 0; iter++); + + while (iter > iter0) { + void (*ctor)(void) = (void (*)(void))*--iter; + ctor(); + } +} bool -OFInit(unsigned int version, struct OFLibC *libC_) +OFInit(unsigned int version, struct OFLibC *libC_, struct Library *RTBase) { #ifdef OF_AMIGAOS_M68K OF_M68K_ARG(struct ObjFWBase *, base, a6) #else register struct ObjFWBase *r12 __asm__("r12"); @@ -338,11 +354,11 @@ struct ObjFWBase *base = r12; #endif #ifdef OF_MORPHOS void *frame; #endif - uintptr_t *iter, *iter0; + uintptr_t *iter0; if (version > 1) return false; if (base->initialized) @@ -366,16 +382,11 @@ ); libC.__register_frame(frame); #endif - for (iter = iter0; *iter != 0; iter++); - - while (iter > iter0) { - void (*ctor)(void) = (void (*)(void))*--iter; - ctor(); - } + OFInitPart2(iter0, RTBase); base->initialized = true; return true; } Index: src/amiga-library.xml ================================================================== --- src/amiga-library.xml +++ src/amiga-library.xml @@ -2,10 +2,11 @@ amiga-library.h + OFObject.h Index: src/linklib/Makefile ================================================================== --- src/linklib/Makefile +++ src/linklib/Makefile @@ -8,5 +8,6 @@ include ../../buildsys.mk CPPFLAGS += -I.. -I../.. -I../exceptions -I../runtime \ -DOBJFW_AMIGA_LIB=\"${OBJFW_AMIGA_LIB}\" \ -DOBJFW_LIB_MINOR=${OBJFW_LIB_MINOR} +AMIGA_LIB_CFLAGS += -DOF_AMIGA_LIB Index: src/linklib/init.m ================================================================== --- src/linklib/init.m +++ src/linklib/init.m @@ -32,18 +32,17 @@ #define USE_INLINE_STDARG #include #include -struct ObjFWBase; - #if defined(OF_AMIGAOS_M68K) # include #elif defined(OF_MORPHOS) # include #endif +extern struct Library *ObjFWRTBase; #ifdef HAVE_SJLJ_EXCEPTIONS extern int _Unwind_SjLj_RaiseException(void *); #else extern int _Unwind_RaiseException(void *); #endif @@ -273,10 +272,13 @@ void *__objc_class_name_OFMutableUTF8String; void *__objc_class_name_OFRangeCharacterSet; void *__objc_class_name_OFSelectKernelEventObserver; void *__objc_class_name_OFUTF8String; +#ifndef OF_AMIGA_LIB +struct Library *ObjFWBase; + static void error(const char *string, ULONG arg) { struct Library *IntuitionBase = OpenLibrary("intuition.library", 0); @@ -368,11 +370,11 @@ if ((ObjFWBase = OpenLibrary(OBJFW_AMIGA_LIB, OBJFW_LIB_MINOR)) == NULL) error("Failed to open " OBJFW_AMIGA_LIB " version %lu!", OBJFW_LIB_MINOR); - if (!OFInit(1, &libC)) + if (!OFInit(1, &libC, ObjFWRTBase)) error("Failed to initialize " OBJFW_AMIGA_LIB "!", 0); initialized = true; } @@ -380,14 +382,14 @@ dtor(void) { CloseLibrary(ObjFWBase); } -#if defined(OF_AMIGAOS_M68K) +# if defined(OF_AMIGAOS_M68K) ADD2INIT(ctor, -2); ADD2EXIT(dtor, -2); -#elif defined(OF_MORPHOS) +# elif defined(OF_MORPHOS) CONSTRUCTOR_P(ObjFW, 5000) { ctor(); return 0; @@ -395,10 +397,11 @@ DESTRUCTOR_P(ObjFW, 5000) { dtor(); } +# endif #endif extern void OFPBKDF2Wrapper(const OFPBKDF2Parameters *parameters); extern void OFScryptWrapper(const OFScryptParameters *parameters); Index: src/linklib/linklib.m ================================================================== --- src/linklib/linklib.m +++ src/linklib/linklib.m @@ -42,23 +42,23 @@ #if OF_GCC_VERSION >= 1100 # pragma GCC diagnostic ignored "-Warray-parameter" #endif bool -OFInit(unsigned int version, struct OFLibC *_Nonnull libc) +OFInit(unsigned int version, struct OFLibC *_Nonnull libc, struct Library *_Nonnull RTBase) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; - return ((bool (*)(unsigned int __asm__("d0"), struct OFLibC *_Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 30))(version, libc); + return ((bool (*)(unsigned int __asm__("d0"), struct OFLibC *_Nonnull __asm__("a0"), struct Library *_Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 30))(version, libc, RTBase); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); - return __extension__ ((bool (*)(unsigned int, struct OFLibC *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 28))(version, libc); + return __extension__ ((bool (*)(unsigned int, struct OFLibC *_Nonnull, struct Library *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 28))(version, libc, RTBase); #endif } void *_Nullable OFAllocMemory(size_t count, size_t size) Index: src/runtime/linklib/Makefile ================================================================== --- src/runtime/linklib/Makefile +++ src/runtime/linklib/Makefile @@ -9,5 +9,6 @@ CPPFLAGS += -I.. -I../.. -I../../.. \ -DOBJC_COMPILING_AMIGA_LINKLIB \ -DOBJFWRT_AMIGA_LIB=\"${OBJFWRT_AMIGA_LIB}\" \ -DOBJFWRT_LIB_MINOR=${OBJFWRT_LIB_MINOR} +AMIGA_LIB_CFLAGS += -DOBJC_AMIGA_LIB Index: src/runtime/linklib/init.m ================================================================== --- src/runtime/linklib/init.m +++ src/runtime/linklib/init.m @@ -21,12 +21,10 @@ #define USE_INLINE_STDARG #include #include -struct ObjFWRTBase; - #include #include #if defined(OF_AMIGAOS_M68K) # include @@ -60,14 +58,16 @@ #ifdef OF_MORPHOS extern void __register_frame(void *); extern void __deregister_frame(void *); #endif -struct Library *ObjFWRTBase; void *__objc_class_name_Protocol; +#ifndef OBJC_AMIGA_LIB extern bool objc_init(unsigned int version, struct objc_libC *libC); + +struct Library *ObjFWRTBase; static void error(const char *string, ULONG arg) { struct Library *IntuitionBase = OpenLibrary("intuition.library", 0); @@ -151,14 +151,14 @@ dtor(void) { CloseLibrary(ObjFWRTBase); } -#if defined(OF_AMIGAOS_M68K) +# if defined(OF_AMIGAOS_M68K) ADD2INIT(ctor, -5) ADD2EXIT(dtor, -5) -#elif defined(OF_MORPHOS) +# elif defined(OF_MORPHOS) CONSTRUCTOR_P(ObjFWRT, 4000) { ctor(); return 0; @@ -166,10 +166,11 @@ DESTRUCTOR_P(ObjFWRT, 0) { dtor(); } +# endif #endif extern int __gnu_objc_personality(int version, int actions, uint64_t *exClass, void *ex, void *ctx);