Changeset 483 for Whitix/branches/hybrid
- Timestamp:
- 05/12/08 12:20:25 (4 months ago)
- Location:
- Whitix/branches/hybrid/kernel
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
Whitix/branches/hybrid/kernel/load.c
r479 r483 53 53 * FUNCTION: ExecOpen 54 54 * 55 * DESCRIPTION: Opens an executable file, and does basic checks for it 's55 * DESCRIPTION: Opens an executable file, and does basic checks for its 56 56 * suitability. 57 57 * … … 59 59 * file - file structure. 60 60 * 61 ***********************************************************************/ 62 63 static int ExecOpen(char* pathName,struct File* file) 61 * RETURNS: 0 if successfully opened, the return value from DoOpenFile 62 * if it failed to open, or -EISDIR if the path name is a 63 * directory. 64 ***********************************************************************/ 65 66 static int ExecOpen(char* pathName, struct File* file) 64 67 { 65 68 int err; -
Whitix/branches/hybrid/kernel/module.c
r481 r483 17 17 */ 18 18 19 #include <config.h> 19 20 #include <console.h> 20 21 #include <elf.h> … … 27 28 #include <slab.h> 28 29 #include <sys.h> 30 #include <task.h> 29 31 30 32 LIST_HEAD(moduleList); … … 52 54 53 55 /* Handle data? */ 54 return (module->textAddr+symbol->symValue);56 return symbol->symValue; 55 57 } 56 58 57 59 return NULL; 58 60 } 61 62 #ifdef CONFIG_ALL_SYMBOLS 63 64 void ModuleSymbolPrint(DWORD address) 65 { 66 struct Module* curr, *module=NULL; 67 68 ListForEachEntry(curr, &moduleList, next) 69 { 70 if (address >= curr->textAddr && address < curr->textAddr+curr->textLength) 71 { 72 module=curr; 73 break; 74 } 75 } 76 77 if (module) 78 { 79 DWORD size, offset; 80 const char* SymbolLookup(char*, struct ElfSymbol*, int, DWORD, DWORD*, DWORD*); 81 82 const char* name=SymbolLookup(module->strTable, module->symTable, module->symTableSize, address, &size, &offset); 83 84 if (name) 85 printf("%s+%#X/%#X\n", name, offset, size); 86 else 87 printf("%#X\n", address); 88 }else 89 printf("%#X\n", address); 90 } 91 92 void ModuleSymbolAdd(struct Module* module) 93 { 94 int length=module->symTableSize+module->strTableSize; 95 char* dest=(void*)VirtMapPhysRange(MODULE_START, MODULE_END, PAGE_ALIGN_UP(length) >> PAGE_SHIFT, 3); 96 97 memcpy(dest, module->symTable, module->symTableSize); 98 module->symTable=(struct ElfSymbol*)dest; 99 100 dest+=module->symTableSize; 101 memcpy(dest, module->strTable, module->strTableSize); 102 module->strTable=dest; 103 } 104 105 #else 106 void ModuleSymbolPrint(DWORD address) 107 { 108 printf("%#X\n", address); 109 } 110 111 void ModuleSymbolAdd(struct Module* module) 112 { 113 } 114 #endif 59 115 60 116 DWORD ModuleResolveKernel(char* name) … … 97 153 } 98 154 99 int ModuleSymbolResolve(struct Module* module, char* file, int sec) 155 int ModuleSymbolPrepare(struct Module* module) 156 { 157 int i; 158 DWORD symSize=module->symTableSize/sizeof(struct ElfSymbol); 159 160 for (i=1; i<symSize; i++) 161 { 162 struct ElfSymbol* symbol=&module->symTable[i]; 163 char* symName=module->strTable+symbol->symName; 164 165 switch (symbol->symIndex) 166 { 167 case STN_UNDEF: 168 symbol->symValue=ModuleResolveKernel(symName); 169 170 if (symbol->symValue) 171 break; 172 173 printf("Could not resolve %s\n", symName); 174 return -ENOENT; 175 176 /* Absolute symbol. No relocation needed. */ 177 case STN_ABS: 178 break; 179 180 case STN_COMMON: 181 printf("Please recompile the module with -fno-common.\n"); 182 return -ENOENT; 183 184 default: 185 symbol->symValue+=module->sectionHeaders[symbol->symIndex].shAddr; 186 } 187 } 188 189 return 0; 190 } 191 192 /* TODO: Create a prepare symbols function, then remove symValue manipulation code here. */ 193 194 void ModuleSymbolResolve(struct Module* module, char* file, int sec) 100 195 { 101 196 int i; … … 107 202 { 108 203 reloc=&relTable[i]; 109 110 204 unsigned long* relAddr=(unsigned long*)(module->sectionHeaders[ module->sectionHeaders[sec].shInfo ].shAddr+reloc->addr); 111 205 int symTabIdx=ELF_R_SYM(reloc->info); 112 206 struct ElfSymbol* symbol=&module->symTable[symTabIdx]; 113 char* symName=module->strTable+symbol->symName;114 DWORD symbolAddr=0;115 116 if (symTabIdx && symName[0] != '.' && strlen(symName) && symbol->symIndex == STN_UNDEF)117 {118 symbolAddr=ModuleResolveKernel(symName);119 120 /* Could not resolve symbol address. */121 if (!symbolAddr)122 return -EINVAL;123 }124 207 125 208 switch (ELF_R_TYPE(reloc->info)) … … 129 212 130 213 case R_386_32: 131 { 132 if (symbol->symIndex == STN_UNDEF) 133 *relAddr+=symbolAddr; 134 135 if (symbol->symIndex > 0 && symbol->symIndex < 0xF000) 136 *relAddr+=module->sectionHeaders[symbol->symIndex].shAddr; 137 } 138 break; 214 *relAddr+=symbol->symValue; 215 break; 139 216 140 217 case R_386_PC32: 141 *relAddr+=symbol Addr-(DWORD)relAddr;218 *relAddr+=symbol->symValue-(DWORD)relAddr; 142 219 break; 143 220 144 221 default: 145 printf("ModuleSymbolResolve: type = %u\n", ELF_R_TYPE(reloc->info)); 146 } 147 } 148 149 return 0; 222 printf("ModuleSymbolResolve: type = %u, %u\n", ELF_R_TYPE(reloc->info), symbol->symIndex); 223 } 224 } 150 225 } 151 226 … … 186 261 if (!ELF_HEAD_CHECK(elfHeader) || (elfHeader->fileType != ELF_REL) || (elfHeader->shEntrySize != sizeof(struct ElfSectionHeader))) 187 262 return -EINVAL; 188 263 189 264 /* Iterate through section headers. */ 190 265 sectionHeaders=(struct ElfSectionHeader*)((char*)file+elfHeader->shOffset); … … 207 282 208 283 if (sectionHeaders[i].shType == SEC_TYPE_STRTAB) 284 { 209 285 module->strTable=(char*)file+sectionHeaders[i].shOffset; 286 module->strTableSize=sectionHeaders[i].shSize; 287 } 210 288 211 289 /* Align up sizes. */ … … 213 291 } 214 292 293 /* Copy over the module data into a new image. */ 215 294 char* dest; 216 217 295 dest=module->loadAddr; 218 296 … … 223 301 224 302 if (sectionHeaders[i].shFlags & SEC_FLAGS_EXEC) 303 { 225 304 module->textAddr=dest; 305 module->textLength=sectionHeaders[i].shSize; 306 } 226 307 227 308 sectionHeaders[i].shAddr=dest; … … 234 315 } 235 316 317 if (ModuleSymbolPrepare(module)) 318 return -ENOENT; 319 236 320 for (i=0; i<elfHeader->shEntries; i++) 237 321 { 238 322 if (sectionHeaders[i].shType == SEC_TYPE_REL) 239 { 240 /* Resolve entries in the module file. */ 241 if (ModuleSymbolResolve(module, file, i) < 0) 242 return -EINVAL; 243 } 323 /* Resolve entries in the module. */ 324 ModuleSymbolResolve(module, file, i); 244 325 } 245 326 -
Whitix/branches/hybrid/kernel/symbols.c
r474 r483 35 35 static int strTableSize DATA; 36 36 37 const char* SymbolLookup( DWORD address, DWORD* size, DWORD* offset)37 const char* SymbolLookup(char* stringTable, struct ElfSymbol* symbolTable, int symSize, DWORD address, DWORD* size, DWORD* offset) 38 38 { 39 39 int i=0; … … 42 42 DWORD currOffset=~0; 43 43 44 while (i < (sym TableSize/sizeof(struct ElfSymbol)))44 while (i < (symSize/sizeof(struct ElfSymbol))) 45 45 { 46 symbol=&sym Table[i++];46 symbol=&symbolTable[i++]; 47 47 48 48 if (ELF_ST_TYPE(symbol->symInfo) != STT_FUNC) … … 60 60 return NULL; 61 61 62 *offset= address-currSym->symValue;62 *offset=currOffset; 63 63 *size=currSym->symSize; 64 64 65 return strTable+currSym->symName; 65 if (*offset > *size) 66 { 67 printf("%#X-%#X = %#X %#X\n", address, symbol->symValue, *offset, *size); 68 while (1); 69 } 70 71 return stringTable+currSym->symName; 66 72 } 67 73 … … 70 76 DWORD size, offset; 71 77 72 const char* name=SymbolLookup( address, &size, &offset);78 const char* name=SymbolLookup(strTable, symTable, symTableSize, address, &size, &offset); 73 79 74 if (name)80 if (name) 75 81 printf("%s+%#X/%#X\n", name, offset, size); 76 82 else
