1 /*---------------------------------------------------------------------------* 2 Project: Dolphin OS Module API 3 File: OSModule.h 4 5 Copyright 1999-2001 Nintendo. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Log: OSModule.h,v $ 14 Revision 1.2.40.2 2008/07/30 06:28:47 yasuh-to 15 Added comments about OSNotify* functions(by nakano-san's fix). 16 17 Revision 1.2.40.1 2008/07/09 05:16:25 nakano_yoshinobu 18 Added OSNotifyPreLink and OSNotifyPostLink. 19 20 Revision 1.2 2006/02/04 11:56:47 hashida 21 (none) 22 23 Revision 1.1.1.1 2005/12/29 06:53:28 hiratsu 24 Initial import. 25 26 Revision 1.1.1.1 2005/05/12 02:41:07 yasuh-to 27 Ported from dolphin source tree. 28 29 30 11 2002/09/27 13:59 Shiki 31 Added R_DOLPHIN_MRKREF. 32 33 10 2002/09/25 16:46 Shiki 34 Added support for fixSize and OSLinkFixed (version 3). 35 36 9 2002/09/02 11:12 Shiki 37 Added bssSection field to OSModuleHeader{} using previous padding0 38 field. 39 40 8 2002/08/30 9:00 Shiki 41 Changed OSNotify*() interface for speeding up the loads and unloads 42 under the debugger. 43 44 7 2002/08/05 18:04 Shiki 45 Added const keywords to relevant function prototypes. 46 47 6 2001/11/27 21:23 Shiki 48 Added OSSearchModule(). 49 50 5 2001/09/04 20:32 Shiki 51 Added support for align and bssAlign (version 2). 52 53 4 2002/01/04 13:06 Shiki 54 Separated OSModuleInfo into OSModuleInfo and OSModuleHeader. 55 56 3 2000/10/31 4:41p Shiki 57 Fixed OSUnlink() declaration. 58 59 2 2000/04/13 11:14p Shiki 60 Fixed copyright. 61 62 1 2000/04/13 11:13p Shiki 63 Initial check-in. 64 $NoKeywords: $ 65 *---------------------------------------------------------------------------*/ 66 67 #ifndef __OSMODULE_H__ 68 #define __OSMODULE_H__ 69 70 #include <revolution/types.h> 71 72 #ifdef __cplusplus 73 extern "C" { 74 #endif 75 76 #define OS_MODULE_VERSION 3 77 typedef struct OSModuleHeader OSModuleHeader; 78 79 typedef u32 OSModuleID; 80 typedef struct OSModuleQueue OSModuleQueue; 81 typedef struct OSModuleLink OSModuleLink; 82 typedef struct OSModuleInfo OSModuleInfo; 83 typedef struct OSSectionInfo OSSectionInfo; 84 typedef struct OSImportInfo OSImportInfo; 85 typedef struct OSRel OSRel; 86 87 struct OSModuleQueue 88 { 89 OSModuleInfo* head; 90 OSModuleInfo* tail; 91 }; 92 93 struct OSModuleLink 94 { 95 OSModuleInfo* next; 96 OSModuleInfo* prev; 97 }; 98 99 struct OSModuleInfo 100 { 101 OSModuleID id; // Unique identifier for the module 102 OSModuleLink link; // Doubly linked list of modules 103 u32 numSections; // # of sections 104 u32 sectionInfoOffset; // Offset to section info table 105 u32 nameOffset; // Offset to module name 106 u32 nameSize; // Size of module name 107 u32 version; // Version number 108 }; 109 110 struct OSModuleHeader 111 { 112 // CAUTION: Info must be the 1st member 113 OSModuleInfo info; 114 115 // OS_MODULE_VERSION == 1 116 u32 bssSize; // Total size of bss sections in bytes 117 u32 relOffset; 118 u32 impOffset; 119 u32 impSize; // Size in bytes 120 u8 prologSection; // Section # for prolog function 121 u8 epilogSection; // Section # for epilog function 122 u8 unresolvedSection; // Section # for unresolved function 123 u8 bssSection; // Section # for bss section (set at run time) 124 u32 prolog; // Prolog function offset 125 u32 epilog; // Epilog function offset 126 u32 unresolved; // Unresolved function offset 127 128 // OS_MODULE_VERSION == 2 129 #if (2 <= OS_MODULE_VERSION) 130 u32 align; // Module alignment constraint 131 u32 bssAlign; // bss alignment constraint 132 #endif 133 134 // OS_MODULE_VERSION == 3 135 #if (3 <= OS_MODULE_VERSION) 136 u32 fixSize; 137 #endif 138 }; 139 140 #define OSGetSectionInfo(module) \ 141 ((OSSectionInfo*) (((OSModuleInfo*) (module))->sectionInfoOffset)) 142 143 /*---------------------------------------------------------------------------* 144 Name: OSSectionInfo 145 146 Description: Section information that corresponds to Elf32_Shdr. 147 148 Members: offset : Byte offset from the beginning of the file. 149 150 The OS_SECTIONINFO_EXEC bit is set for a 151 section that contains executable machine 152 instructions. 153 154 The offset can be zero for unused sections and 155 also for BSS sections. BSS sections have non- 156 zero size but unused sections do not. 157 158 size : Section size in bytes. For BSS sections, the 159 sections occupy no space in the file. 160 161 Note: Unused sections are required to use same section indices 162 as the original ELF file. (for debugging purpose) 163 164 *---------------------------------------------------------------------------*/ 165 struct OSSectionInfo 166 { 167 u32 offset; 168 u32 size; 169 }; 170 171 // OSSectionInfo.offset bit 172 #define OS_SECTIONINFO_EXEC 0x1 173 #define OS_SECTIONINFO_OFFSET(offset) ((offset) & ~0x1) 174 175 struct OSImportInfo 176 { 177 OSModuleID id; // External module id 178 u32 offset; // Offset to OSRel instructions 179 }; 180 181 struct OSRel 182 { 183 u16 offset; // Byte offset from the previous entry 184 u8 type; 185 u8 section; 186 u32 addend; 187 }; 188 189 #define R_DOLPHIN_NOP 201 // C9h current offset += OSRel.offset 190 #define R_DOLPHIN_SECTION 202 // CAh current section = OSRel.section 191 #define R_DOLPHIN_END 203 // CBh 192 #define R_DOLPHIN_MRKREF 204 // CCh 193 194 /*---------------------------------------------------------------------------* 195 Function Prototypes 196 *---------------------------------------------------------------------------*/ 197 198 void OSSetStringTable( const void* stringTable ); 199 BOOL OSLink ( OSModuleInfo* newModule, void* bss ); 200 #if (3 <= OS_MODULE_VERSION) 201 BOOL OSLinkFixed ( OSModuleInfo* newModule, void* bss ); 202 #endif 203 BOOL OSUnlink ( OSModuleInfo* oldModule ); 204 205 OSModuleInfo* OSSearchModule(void* ptr, u32* section, u32* offset); 206 207 // OSNotify* are notification functions for the debugger. 208 // The developer never touches these functions. 209 void OSNotifyLink ( OSModuleInfo* module ); 210 void OSNotifyUnlink ( OSModuleInfo* module ); 211 void OSNotifyPreLink ( OSModuleHeader* newModule, OSModuleHeader* module ); 212 void OSNotifyPostLink( OSModuleHeader* newModule, OSModuleHeader* module ); 213 214 #ifdef __cplusplus 215 } 216 #endif 217 218 #endif // __OSMODULE_H__ 219