Root/
Source at commit 1317 created 12 years 10 months ago. By meklort, Update ppc boot2 file. File now compiles. | |
---|---|
1 | /*␊ |
2 | * Copyright 2010 Evan Lojewski. All rights reserved.␊ |
3 | *␊ |
4 | */␊ |
5 | #include <stdlib.h>␊ |
6 | #include <stdio.h>␊ |
7 | #include <string.h>␊ |
8 | #include "modules.h"␊ |
9 | ␊ |
10 | //extern void start_built_in_modules();␊ |
11 | ␊ |
12 | void* symbols_module_start = (void*)0xFFFFFFFF;␉// Global, value is populated by the makefile with actual address␊ |
13 | ␊ |
14 | /** Internal symbols, however there are accessor methods **/␊ |
15 | moduleHook_t* moduleCallbacks = NULL;␊ |
16 | moduleList_t* loadedModules = NULL;␊ |
17 | ␊ |
18 | int init_module_system()␊ |
19 | {␊ |
20 | // Start any modules that were compiled in first.␊ |
21 | ␉extern void start_built_in_modules();␊ |
22 | start_built_in_modules();␊ |
23 | ␉␊ |
24 | ␉return 1;␊ |
25 | }␉␊ |
26 | ␊ |
27 | void start_built_in_module(const char* name, ␊ |
28 | const char* author, ␊ |
29 | const char* description,␊ |
30 | UInt32 version,␊ |
31 | UInt32 compat,␊ |
32 | void(*start_function)(void))␊ |
33 | {␊ |
34 | start_function();␊ |
35 | // Notify the module system that this module really exists, specificaly, let other module link with it␊ |
36 | module_loaded(name, author, description, version, compat);␊ |
37 | }␊ |
38 | ␊ |
39 | ␊ |
40 | ␊ |
41 | /*␊ |
42 | * print out the information about the loaded module␊ |
43 | */␊ |
44 | void module_loaded(const char* name, const char* author, const char* description, UInt32 version, UInt32 compat)␊ |
45 | {␊ |
46 | ␉moduleList_t* new_entry = (moduleList_t*)malloc(sizeof(moduleList_t));␊ |
47 | ␉new_entry->next = loadedModules;␊ |
48 | ␊ |
49 | ␉loadedModules = new_entry;␊ |
50 | ␉␊ |
51 | if(!name) name = "Unknown";␊ |
52 | if(!author) author = "Unknown";␊ |
53 | if(!description) description = "";␊ |
54 | ␊ |
55 | ␉new_entry->name = name;␊ |
56 | new_entry->author = author;␊ |
57 | new_entry->description = description;␊ |
58 | ␉new_entry->version = version;␊ |
59 | new_entry->compat = compat;␊ |
60 | }␊ |
61 | ␊ |
62 | ␊ |
63 | /********************************************************************************/␊ |
64 | /*␉Module Hook Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
65 | /********************************************************************************/␊ |
66 | ␊ |
67 | ␊ |
68 | /*␊ |
69 | *␉execute_hook( const char* name )␊ |
70 | *␉␉name - Name of the module hook␊ |
71 | *␉␉␉If any callbacks have been registered for this hook␊ |
72 | *␉␉␉they will be executed now in the same order that the␊ |
73 | *␉␉␉hooks were added.␊ |
74 | */␊ |
75 | int execute_hook(const char* name, void* arg1, void* arg2, void* arg3, void* arg4)␊ |
76 | {␊ |
77 | ␉moduleHook_t* hook = (moduleHook_t*)hook_exists(name);␊ |
78 | ␉␊ |
79 | ␉if(hook)␊ |
80 | ␉{␊ |
81 | ␉␉// Loop through all callbacks for this module␊ |
82 | ␉␉callbackList_t* callbacks = hook->callbacks;␊ |
83 | ␊ |
84 | ␉␉while(callbacks)␊ |
85 | ␉␉{␊ |
86 | ␉␉␉// Execute callback␊ |
87 | ␉␉␉callbacks->callback(arg1, arg2, arg3, arg4);␊ |
88 | ␉␉␉callbacks = callbacks->next;␊ |
89 | ␉␉}␊ |
90 | ␉␉return 1;␊ |
91 | ␉}␊ |
92 | ␉else␊ |
93 | ␉{␊ |
94 | ␉␉// Callback for this hook doesn't exist;␊ |
95 | ␉␉return 0;␊ |
96 | ␉}␊ |
97 | }␊ |
98 | ␊ |
99 | ␊ |
100 | ␊ |
101 | /*␊ |
102 | *␉register_hook_callback( const char* name, void(*callback)())␊ |
103 | *␉␉name - Name of the module hook to attach to.␊ |
104 | *␉␉callbacks - The funciton pointer that will be called when the␊ |
105 | *␉␉␉hook is executed. When registering a new callback name, the callback is added sorted.␊ |
106 | *␉␉␉NOTE: the hooks take four void* arguments.␊ |
107 | */␊ |
108 | void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*))␊ |
109 | {␉␉␊ |
110 | ␉moduleHook_t* hook = hook_exists(name);␊ |
111 | ␉␊ |
112 | ␉if(hook)␊ |
113 | ␉{␊ |
114 | ␉␉// append␊ |
115 | ␉␉callbackList_t* newCallback = (callbackList_t*)malloc(sizeof(callbackList_t));␊ |
116 | ␉␉newCallback->next = hook->callbacks;␊ |
117 | ␉␉hook->callbacks = newCallback;␊ |
118 | ␉␉newCallback->callback = callback;␊ |
119 | ␉}␊ |
120 | ␉else␊ |
121 | ␉{␊ |
122 | ␉␉// create new hook␊ |
123 | ␉␉moduleHook_t* newHook = (moduleHook_t*)malloc(sizeof(moduleHook_t));␉␉␊ |
124 | ␉␉newHook->name = name;␊ |
125 | ␉␉newHook->callbacks = (callbackList_t*)malloc(sizeof(callbackList_t));␊ |
126 | ␉␉newHook->callbacks->callback = callback;␊ |
127 | ␉␉newHook->callbacks->next = NULL;␊ |
128 | ␉␉␊ |
129 | ␉␉newHook->next = moduleCallbacks;␊ |
130 | ␉␉moduleCallbacks = newHook;␊ |
131 | ␉␉␊ |
132 | ␉}␊ |
133 | }␊ |
134 | ␊ |
135 | ␊ |
136 | moduleHook_t* hook_exists(const char* name)␊ |
137 | {␊ |
138 | ␉moduleHook_t* hooks = moduleCallbacks;␊ |
139 | ␉␊ |
140 | ␉// look for a hook. If it exists, return the moduleHook_t*,␊ |
141 | ␉// If not, return NULL.␊ |
142 | ␉while(hooks)␊ |
143 | ␉{␊ |
144 | ␉␉if(strcmp(name, hooks->name) == 0)␊ |
145 | ␉␉{␊ |
146 | ␉␉␉return hooks;␊ |
147 | ␉␉}␊ |
148 | ␉␉hooks = hooks->next;␊ |
149 | ␉}␊ |
150 | ␉return NULL;␊ |
151 | ␉␊ |
152 | }␊ |
153 | ␊ |
154 | /********************************************************************************/␊ |
155 | /*␉dyld / Linker Interface␉␉␉␉␉␉␉␉␉␉␉␉␉␉*/␊ |
156 | /********************************************************************************/␊ |
157 | void dyld_stub_binder() ␊ |
158 | {␊ |
159 | ␉printf("ERROR: dyld_stub_binder was called, should have been take care of by the linker.\n");␊ |
160 | ␉getchar();␊ |
161 | } |