The Pedigree Project  0.1
Module.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
85 #ifndef MODULE_H
86 #define MODULE_H
87 
88 #include "pedigree/kernel/compiler.h"
89 #include "pedigree/kernel/utilities/utility.h"
90 
91 #ifndef __cplusplus
92 #include <stdbool.h>
93 #endif
94 
95 typedef bool (*ModuleEntry)();
96 typedef void (*ModuleExit)();
97 
98 #ifdef STATIC_DRIVERS
99 
100 #define MODULE_TAG 0xdeadbaba
101 
102 struct ModuleInfo
103 {
104  ModuleInfo(
105  const char *newName, ModuleEntry newEntry, ModuleExit newExit,
106  const char **newDeps)
107  {
108  tag = MODULE_TAG;
109  name = newName;
110  entry = newEntry;
111  exit = newExit;
112  dependencies = newDeps;
113  }
114 
115  uint32_t tag;
116  const char *name;
117  ModuleEntry entry;
118  ModuleExit exit;
119  const char **dependencies;
120 } PACKED;
121 
122 #define MODULE_INFO2(name, entry, exit, ...) \
123  static const char *__mod_deps[] = {__VA_ARGS__, 0}; \
124  static ModuleInfo __module SECTION(".modinfo") \
125  USED(name, entry, exit, __mod_deps);
126 
127 #define MODULE_OPTIONAL_DEPENDS(...)
128 
129 #else
130 
131 #define MODULE_NAME(x) const char *g_pModuleName SECTION(".modinfo") USED = x
132 #define MODULE_ENTRY(x) ModuleEntry g_pModuleEntry SECTION(".modinfo") USED = x
133 #define MODULE_EXIT(x) ModuleExit g_pModuleExit SECTION(".modinfo") USED = x
134 #define MODULE_DEPENDS(...) \
135  const char *g_pDepends[] SECTION(".modinfo") USED = {__VA_ARGS__, 0}
136 #define MODULE_DEPENDS2(...) \
137  const char *g_pDepends[] SECTION(".modinfo") USED = {__VA_ARGS__}
138 
139 #define MODULE_OPTIONAL_DEPENDS(...) \
140  const char *g_pOptionalDepends[] SECTION(".modinfo") USED = {__VA_ARGS__, 0}
141 
142 #define MODULE_INFO2(name, entry, exit, ...) \
143  MODULE_NAME(name); \
144  MODULE_ENTRY(entry); \
145  MODULE_EXIT(exit); \
146  MODULE_DEPENDS2(__VA_ARGS__);
147 
148 extern const char *g_pModuleName;
149 extern ModuleEntry g_pModuleEntry;
150 extern ModuleExit g_pModuleExit;
151 extern const char *g_pDepends[];
152 extern const char *g_pOptionalDepends[];
153 
154 #endif
155 
156 #define MODULE_INFO(...) MODULE_INFO2(__VA_ARGS__, 0)
157 
158 #endif