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