Chameleon

Chameleon Commit Details

Date:2011-08-05 04:36:39 (12 years 8 months ago)
Author:Evan Lojewski
Commit:1274
Parents: 1273
Message:Module changes, makefile changes.
Changes:
A/branches/xZenu/src/modules/ModuleSystem/linker.c
M/branches/xZenu/src/modules/ModuleSystem/Makefile
M/branches/xZenu/src/arch/i386/libsa/zalloc.c
M/branches/xZenu/src/modules/Makefile
M/branches/xZenu/src/arch/i386/boot2/Makefile
M/branches/xZenu/src/modules/ModuleSystem/macho.c

File differences

branches/xZenu/src/modules/ModuleSystem/linker.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* Copyright 2010 Evan Lojewski. All rights reserved.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#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();
}
branches/xZenu/src/modules/ModuleSystem/macho.c
77
88
99
10
10
1111
1212
1313
#endif
#include "boot.h"
#include <stdlib.h>
#include "modules.h"
extern void start_built_in_modules();
branches/xZenu/src/modules/ModuleSystem/Makefile
88
99
1010
11
11
12
1213
1314
DIR = ModuleSystem
MODULE_OBJS = macho modules_support modules
MODULE_OBJS = modules_support linker
#macho modules
include ../MakeInc.dir
branches/xZenu/src/modules/Makefile
99
1010
1111
12
12
1313
1414
1515
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
branches/xZenu/src/arch/i386/boot2/Makefile
88
99
1010
11
11
1212
1313
1414
1515
16
16
1717
1818
1919
......
6565
6666
6767
68
68
6969
7070
7171
......
7878
7979
8080
81
81
8282
8383
8484
......
9292
9393
9494
95
95
9696
9797
9898
......
101101
102102
103103
104
104
105105
106106
107107
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
@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
@$(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}
@$(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}
-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
branches/xZenu/src/arch/i386/libsa/zalloc.c
6969
7070
7171
72
73
7274
7375
7476
......
8789
8890
8991
92
93
94
95
96
97
9098
9199
92100
#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))
{
#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;

Archive Download the corresponding diff file

Revision: 1274