Index: branches/xZenu/src/modules/ModuleSystem/linker.c =================================================================== --- branches/xZenu/src/modules/ModuleSystem/linker.c (revision 0) +++ branches/xZenu/src/modules/ModuleSystem/linker.c (revision 1274) @@ -0,0 +1,162 @@ +/* + * Copyright 2010 Evan Lojewski. All rights reserved. + * + */ +#include +#include +#include +#include "modules.h" + +//extern void start_built_in_modules(); + +void* symbols_module_start = (void*)0xFFFFFFFF; // Global, value is populated by the makefile with actual address + +/** Internal symbols, however there are accessor methods **/ +moduleHook_t* moduleCallbacks = NULL; +moduleList_t* loadedModules = NULL; + +int init_module_system() +{ + // Start any modules that were compiled in first. + extern void start_built_in_modules(); + start_built_in_modules(); + + return 1; +} + +void start_built_in_module(const char* name, + const char* author, + const char* description, + UInt32 version, + UInt32 compat, + void(*start_function)(void)) +{ + start_function(); + // Notify the module system that this module really exists, specificaly, let other module link with it + module_loaded(name, author, description, version, compat); +} + + + +/* + * print out the information about the loaded module + */ +void module_loaded(const char* name, const char* author, const char* description, UInt32 version, UInt32 compat) +{ + moduleList_t* new_entry = (moduleList_t*)malloc(sizeof(moduleList_t)); + new_entry->next = loadedModules; + + loadedModules = new_entry; + + if(!name) name = "Unknown"; + if(!author) author = "Unknown"; + if(!description) description = ""; + + new_entry->name = name; + new_entry->author = author; + new_entry->description = description; + new_entry->version = version; + new_entry->compat = compat; +} + + +/********************************************************************************/ +/* Module Hook Interface */ +/********************************************************************************/ + + +/* + * execute_hook( const char* name ) + * name - Name of the module hook + * If any callbacks have been registered for this hook + * they will be executed now in the same order that the + * hooks were added. +*/ +int execute_hook(const char* name, void* arg1, void* arg2, void* arg3, void* arg4) +{ + moduleHook_t* hook = (moduleHook_t*)hook_exists(name); + + if(hook) + { + // Loop through all callbacks for this module + callbackList_t* callbacks = hook->callbacks; + + while(callbacks) + { + // Execute callback + callbacks->callback(arg1, arg2, arg3, arg4); + callbacks = callbacks->next; + } + return 1; + } + else + { + // Callback for this hook doesn't exist; + return 0; + } +} + + + +/* + * register_hook_callback( const char* name, void(*callback)()) + * name - Name of the module hook to attach to. + * callbacks - The funciton pointer that will be called when the + * hook is executed. When registering a new callback name, the callback is added sorted. + * NOTE: the hooks take four void* arguments. + */ +void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*)) +{ + moduleHook_t* hook = hook_exists(name); + + if(hook) + { + // append + callbackList_t* newCallback = (callbackList_t*)malloc(sizeof(callbackList_t)); + newCallback->next = hook->callbacks; + hook->callbacks = newCallback; + newCallback->callback = callback; + } + else + { + // create new hook + moduleHook_t* newHook = (moduleHook_t*)malloc(sizeof(moduleHook_t)); + newHook->name = name; + newHook->callbacks = (callbackList_t*)malloc(sizeof(callbackList_t)); + newHook->callbacks->callback = callback; + newHook->callbacks->next = NULL; + + newHook->next = moduleCallbacks; + moduleCallbacks = newHook; + + } +} + + +moduleHook_t* hook_exists(const char* name) +{ + moduleHook_t* hooks = moduleCallbacks; + + // look for a hook. If it exists, return the moduleHook_t*, + // If not, return NULL. + while(hooks) + { + if(strcmp(name, hooks->name) == 0) + { + return hooks; + } + hooks = hooks->next; + } + return NULL; + +} + +/********************************************************************************/ +/* dyld / Linker Interface */ +/********************************************************************************/ + +void dyld_stub_binder() +{ + printf("ERROR: dyld_stub_binder was called, should have been take care of by the linker.\n"); + getchar(); +} \ No newline at end of file Index: branches/xZenu/src/modules/ModuleSystem/macho.c =================================================================== --- branches/xZenu/src/modules/ModuleSystem/macho.c (revision 1273) +++ branches/xZenu/src/modules/ModuleSystem/macho.c (revision 1274) @@ -7,7 +7,7 @@ #endif -#include "boot.h" +#include #include "modules.h" extern void start_built_in_modules(); Index: branches/xZenu/src/modules/ModuleSystem/Makefile =================================================================== --- branches/xZenu/src/modules/ModuleSystem/Makefile (revision 1273) +++ branches/xZenu/src/modules/ModuleSystem/Makefile (revision 1274) @@ -8,6 +8,7 @@ DIR = ModuleSystem -MODULE_OBJS = macho modules_support modules +MODULE_OBJS = modules_support linker +#macho modules include ../MakeInc.dir \ No newline at end of file Index: branches/xZenu/src/modules/Makefile =================================================================== --- branches/xZenu/src/modules/Makefile (revision 1273) +++ branches/xZenu/src/modules/Makefile (revision 1274) @@ -9,7 +9,7 @@ include ${ROOT}/Make.rules # The order of building is important. -SUBDIRS = klibc uClibcxx Disk FileSystem +SUBDIRS = klibc uClibcxx ModuleSystem Disk FileSystem # ModuleSystem CFLAGS= -O3 $(MORECPP) -g -static Index: branches/xZenu/src/arch/i386/boot2/Makefile =================================================================== --- branches/xZenu/src/arch/i386/boot2/Makefile (revision 1273) +++ branches/xZenu/src/arch/i386/boot2/Makefile (revision 1274) @@ -8,12 +8,12 @@ OPTIM = -Oz -CFLAGS := $(RC_CFLAGS) $(OPTIM) $(MORECPP) -g -Wmost -Werror \ +CFLAGS := $(RC_CFLAGS) $(OPTIM) $(MORECPP) -g -Wmost -Werror -static \ -fno-builtin -DSAIO_INTERNAL_USER $(OMIT_FRAME_POINTER_CFLAG) \ -fno-align-functions -fno-stack-protector \ -msoft-float -nostdinc -include $(SRCROOT)/autoconf.h -CPPFLAGS := $(CPPFLAGS) -nostdinc++ -Wmost -Werror \ +CPPFLAGS := $(CPPFLAGS) -nostdinc++ -Wmost -Werror -static \ -fno-builtin -msoft-float \ -fno-rtti -fno-exceptions \ -include $(SRCROOT)/autoconf.h @@ -65,7 +65,7 @@ @echo "\t[LD] boot.sys" @$(CC) -Wl,-segaddr,__INIT,$(BOOT2ADDR) -Wl,-segalign,20 -Wl,-preload \ -nostdlib -arch ${ARCH} -static \ - -o $(SYMROOT)/boot.sys $(filter %.o,$^) `find $(OBJROOT)/../../boot2_modules/ -name \*.${ARCH}o` $(LIBS) + -o $(SYMROOT)/boot.sys $(filter %.${ARCH}o,$^) `find $(OBJROOT)/../../boot2_modules/ -name \*.${ARCH}o` $(LIBS) @cp $(SYMROOT)/boot.sys $(SYMROOT)/boot2.sys @@ -78,7 +78,7 @@ @$(CC) -static -Wl,-preload -Wl,-segaddr,__INIT,$(BOOT2ADDR) \ -nostdlib -arch ${ARCH} -Wl,-segalign,20 \ -Wl,-sectcreate,__DATA,__Symbols,$(SYMROOT)/Symbols.dylib \ - -o $(SYMROOT)/boot.sys $(filter %.o,$^) `find $(OBJROOT)/../../boot2_modules/ -name \*.${ARCH}o` $(LIBS) + -o $(SYMROOT)/boot.sys $(filter %.${ARCH}o,$^) `find $(OBJROOT)/../../boot2_modules/ -name \*.${ARCH}o` $(LIBS) @# Second pass, fixup global var locations @${RM} $(SYMROOT)/${SYMBOLS_MODULE} @@ -92,7 +92,7 @@ @$(CC) -static -Wl,-preload -Wl,-segaddr,__INIT,$(BOOT2ADDR) \ -nostdlib -arch ${ARCH} -Wl,-segalign,20 \ -Wl,-sectcreate,__DATA,__Symbols,$(SYMROOT)/Symbols.dylib \ - -o $(SYMROOT)/boot.sys $(filter %.o,$^) `find $(OBJROOT)/../../boot2_modules/ -name \*.${ARCH}o` $(LIBS) -lcc_kext + -o $(SYMROOT)/boot.sys $(filter %.${ARCH}o,$^) `find $(OBJROOT)/../../boot2_modules/ -name \*.${ARCH}o` $(LIBS) -lcc_kext @${RM} $(SYMROOT)/${SYMBOLS_MODULE} @@ -101,7 +101,7 @@ -dylib -read_only_relocs suppress \ -S -x -Z -dead_strip_dylibs \ -no_uuid \ - $(filter %.${ARCH}o,$^) $(LIBS) \ + $(filter %.${ARCH}o,$^) `find $(OBJROOT)/../../boot2_modules/ -name \*.${ARCH}o` $(LIBS) \ -final_output Symbols \ -macosx_version_min 10.6 \ -o $(OBJROOT)/Symbols_LINKER_ONLY.dylib Index: branches/xZenu/src/arch/i386/libsa/zalloc.c =================================================================== --- branches/xZenu/src/arch/i386/libsa/zalloc.c (revision 1273) +++ branches/xZenu/src/arch/i386/libsa/zalloc.c (revision 1274) @@ -69,6 +69,8 @@ #endif } + + // define the block of memory that the allocator will use void malloc_init(char * start, int size, int nodes, void (*malloc_err_fn)(char *, size_t, const char *, int)) { @@ -87,6 +89,12 @@ #define BEST_FIT 1 +#undef malloc +void *malloc(size_t size) +{ + return safe_malloc(size, __FILE__, __LINE__); +} + void * safe_malloc(size_t size, const char *file, int line) { int i;