Changeset 14
- Timestamp:
- 09/05/05 15:02:10 (3 years ago)
- Files:
-
- trunk/ddl/all.d (modified) (1 diff)
- trunk/ddl/omf/OMFBinary.d (modified) (13 diffs)
- trunk/ddl/omf/OMFLibrary.d (modified) (4 diffs)
- trunk/ddl/omf/OMFLoader.d (modified) (1 diff)
- trunk/ddl/omf/OMFModule.d (modified) (3 diffs)
- trunk/ddl/omf/RecordCursor.d (modified) (1 diff)
- trunk/ddltest.d (modified) (1 diff)
- trunk/test/all.d (modified) (1 diff)
- trunk/test/test1.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ddl/all.d
r10 r14 31 31 32 32 interface DynamicModule{ 33 public char[] getName(); 33 34 public char[][] getDependencies(); 34 35 public void resolveDependency(char[] name,void* address); trunk/ddl/omf/OMFBinary.d
r13 r14 98 98 } 99 99 100 public char[] getName(){ 101 return libraryName; 102 } 103 100 104 public char[] toString(){ 101 105 char[] output; … … 148 152 return output; 149 153 } 150 151 protected void parseTHeader(RecordCursor cursor){ 154 protected void parseTHEADR(RecordCursor cursor){ 152 155 char[] name = cursor.getLString(); 153 debug writefln(" Header: %s",name);156 debug writefln("Library Name: %s",name); 154 157 this.libraryName = name; 155 158 } 156 159 157 protected void parseC omment(RecordCursor cursor){160 protected void parseCOMENT(RecordCursor cursor){ 158 161 ubyte commentType = cursor.getByte(); 159 162 ubyte commentClass = cursor.getByte(); … … 180 183 } 181 184 182 protected void parseM oduleEnd(RecordCursor cursor){183 // completely and totally ignored as it is only useful for finding a module start address184 } 185 186 protected void parseE xternNames(RecordCursor cursor){185 protected void parseMODEND(RecordCursor cursor){ 186 //NOTE: this is completely and totally ignored. The main loop exits after this call. 187 } 188 189 protected void parseEXTDEF(RecordCursor cursor){ 187 190 while(cursor.hasMore()){ 188 191 ExternalSymbol ext; … … 228 231 Get names for the names list 229 232 */ 230 protected void parseL istOfNames(RecordCursor cursor){233 protected void parseLNAMES(RecordCursor cursor){ 231 234 while(cursor.hasMore()){ 232 235 char[] name = cursor.getLString(); 233 debug writefln(" name: %s",name);236 debug writefln("LNAME: %s",name); 234 237 235 238 this.names ~= name; … … 241 244 - really doesn't do all that much aside from marking the length, alignment and reserve an array index 242 245 */ 243 protected void parseS egmentDefinition(RecordCursor cursor){246 protected void parseSEGDEF(RecordCursor cursor){ 244 247 // record segment information 245 248 Segment seg; … … 279 282 Parse the group definition - verifies that the group specified is indeed named 'FLAT'. 280 283 */ 281 protected void parseG roupDefinition(RecordCursor cursor){284 protected void parseGRPDEF(RecordCursor cursor){ 282 285 uint nameIndex = cursor.getIndex(); 283 286 char[] name = this.names[nameIndex]; … … 295 298 Gather fixup data 296 299 */ 297 protected void parseF ixupData(RecordCursor cursor){300 protected void parseFIXUPP(RecordCursor cursor){ 298 301 while(cursor.hasMore()){ 299 302 ushort type = cursor.getByte(); … … 398 401 399 402 400 protected void parseL ogicalEnumeratedData(RecordCursor cursor){403 protected void parseLEDATA(RecordCursor cursor){ 401 404 uint segmentIndex = cursor.getIndex(); 402 405 uint offsetAddress = cursor.getVWord(); … … 408 411 this.enumData.offset = offsetAddress; 409 412 410 debug writefln(" enum data: segmentIndex %d | offset %d | length %d",segmentIndex,offsetAddress,rawData.length);413 debug writefln("LEDATA: segmentIndex %d | offset %d | length %d",segmentIndex,offsetAddress,rawData.length); 411 414 } 412 415 413 416 // add raw data to a segment 414 protected void parseL ogicalIteratedData(RecordCursor cursor){417 protected void parseLIDATA(RecordCursor cursor){ 415 418 uint segmentIndex = cursor.getIndex(); 416 419 uint offsetAddress = cursor.getVWord(); … … 471 474 472 475 473 protected void parse ExternalNames(RecordCursor cursor){476 protected void parseCEXTDEF(RecordCursor cursor){ 474 477 while(cursor.hasMore()){ 475 478 // get the name index for this external reference … … 485 488 } 486 489 490 protected void parseCOMDEF(RecordCursor cursor){ 491 //TODO: make sure that the COMDEF is actually defined somewhere after linking 492 //TODO: may have to create it here on the fly, flagged as 'common' so that duplicates can be eliminated 493 while(cursor.hasMore()){ 494 char[] communalName = cursor.getLString(); 495 cursor.getVByte(); // throw out type index 496 ubyte dataType = cursor.getByte(); 497 498 uint getNumericValue(){ 499 ubyte indicator = cursor.getByte(); 500 if(indicator <= 128){ 501 return indicator; 502 } 503 else if(indicator == 0x81){ 504 return cursor.getWord(); 505 } 506 else if(indicator == 0x84){ 507 return (cursor.getByte() << 16) | cursor.getWord(); 508 } 509 else if(indicator == 0x88){ 510 return cursor.getDWord(); 511 } 512 else throw new FeatureNotSupportedException( 513 std.string.format("COMDEF numeric type %0.2X is not supported",indicator) 514 ); 515 } 516 517 if(dataType < 0x51){ 518 debug writefln("COMDEF %s: segment #%d",communalName,dataType); 519 } 520 else if(dataType == 0x61){ 521 uint elements = getNumericValue(); 522 uint size = getNumericValue(); 523 debug writefln("COMDEF %s: FAR data - %d elements, %d bytes each",communalName,elements,size); 524 } 525 else if(dataType == 0x62){ 526 uint bytes = getNumericValue(); 527 debug writefln("COMDEF %s: NEAR data - %d bytes",communalName,bytes); 528 } 529 else{ 530 throw new FeatureNotSupportedException( 531 std.string.format("COMDEF type %0.2X is not supported",dataType) 532 ); 533 } 534 535 ExternalSymbol ext; 536 ext.name = communalName; 537 debug writefln("COMDEF extern: %s",ext.name); 538 this.externs ~= ext; 539 } 540 } 541 487 542 //discrete bits of data for code 488 protected void parseC ommonData(RecordCursor cursor){543 protected void parseCOMDAT(RecordCursor cursor){ 489 544 ubyte flags = cursor.getByte(); 490 545 … … 581 636 //NOTE: the specification is organized by the type number, simply search it on xxH. 582 637 switch(type){ 583 case 0x80: parseTH eader(cursor); break;584 case 0x88: parseC omment(cursor); break;585 case 0x8A: parseM oduleEnd(cursor); return; // last record586 case 0x8C: parseE xternNames(cursor); break;638 case 0x80: parseTHEADR(cursor); break; 639 case 0x88: parseCOMENT(cursor); break; 640 case 0x8A: parseMODEND(cursor); return; // last record 641 case 0x8C: parseEXTDEF(cursor); break; 587 642 case 0x90: parsePUBDEF(cursor); break; 588 case 0x96: parseListOfNames(cursor); break; 589 case 0x98: parseSegmentDefinition(cursor); break; 590 case 0x9A: parseGroupDefinition(cursor); break; 591 case 0x9C: parseFixupData(cursor); break; 592 case 0xA0: parseLogicalEnumeratedData(cursor); break; 593 case 0xA2: parseLogicalIteratedData(cursor); break; 594 case 0xBC: parseExternalNames(cursor); break; 595 case 0xC2: parseCommonData(cursor); break; 643 case 0x96: parseLNAMES(cursor); break; 644 case 0x98: parseSEGDEF(cursor); break; 645 case 0x9A: parseGRPDEF(cursor); break; 646 case 0x9C: parseFIXUPP(cursor); break; 647 case 0xA0: parseLEDATA(cursor); break; 648 case 0xA2: parseLIDATA(cursor); break; 649 case 0xB0: parseCOMDEF(cursor); break; 650 case 0xBC: parseCEXTDEF(cursor); break; 651 case 0xC2: parseCOMDAT(cursor); break; 596 652 default: 597 653 throw new FeatureNotSupportedException( … … 633 689 634 690 if(fix.isExternStyleFixup){ 691 debug writefln("extern %d of %d",fix.targetIndex,externs.length); 635 692 ExternalSymbol* target = &(this.externs[fix.targetIndex]); 636 693 trunk/ddl/omf/OMFLibrary.d
r13 r14 49 49 50 50 package void addModule(OMFModule mod){ 51 printf("adding module %d to library\n",this.modules.length); 52 this.modules ~= mod; 51 53 foreach(ExportSymbol exp; mod.getExports()){ 52 54 dictionary[exp.name] = exp; … … 72 74 libFile.read(flags); 73 75 74 printf("Dictionary: %0.8X\n",dictionaryOffset);76 debug writefln("Dictionary: %0.8X\n",dictionaryOffset); 75 77 76 78 assert(type == 0xF0); // assert OMF library … … 86 88 OMFModule mod; 87 89 while(!libFile.eof()){ 88 printf("offset: %0.8X\n",libFile.position);90 debug writefln("offset: %0.8X\n",libFile.position); 89 91 90 92 mod = new OMFModule(); … … 97 99 libFile.seek(delta,SeekPos.Current); 98 100 } 99 101 102 // determine if we're at the end of the module list 100 103 ubyte next; 101 104 libFile.read(next); 102 printf("next: %0.2X\n",next); 103 assert(next != 0xF1); 105 debug writefln("next: %0.2X\n",next); 104 106 libFile.seek(-1,SeekPos.Current); 105 107 if(next == 0xF1) break; 106 108 } 107 108 109 //skip the dictionary (redundant) 109 110 libFile.close(); trunk/ddl/omf/OMFLoader.d
r10 r14 47 47 OMFModule mod = new OMFModule(); 48 48 mod.loadFromFile(filename); 49 lib.addModule(mod); 49 printf("%.*s ==> %d exports\n",mod.getName(),mod.getExports.length); 50 lib.addModule(mod); 51 printf("%.*s ==> %d exports\n",lib.getModules[0].getName(),mod.getExports.length); 50 52 } 51 53 return lib; trunk/ddl/omf/OMFModule.d
r10 r14 32 32 33 33 class OMFModule : DynamicModule{ 34 char[] moduleName; 34 35 char[][] dependencies; 35 36 ExportSymbol[char[]] exports; … … 38 39 package this(){ 39 40 /* module-only constructor */ 41 } 42 43 char[] getName(){ 44 return this.moduleName; 40 45 } 41 46 … … 56 61 return exports[name]; 57 62 } 58 63 59 64 package void loadFromFile(char[] filename){ 60 65 binary = new OMFBinary(); 61 66 binary.loadFromFile(filename); 62 63 debug writefln("Binary: %s",binary.toString());64 67 syncronizeSymbols(); 65 68 } 66 69 67 p ublicvoid loadFromFile(char[] filename,File fileStream){70 package void loadFromFile(char[] filename,File fileStream){ 68 71 binary = new OMFBinary(); 69 72 binary.loadFromFile(filename,fileStream); 70 71 debug writefln("Binary: %s",binary.toString());72 73 syncronizeSymbols(); 73 74 } 74 75 75 76 protected void syncronizeSymbols(){ 77 this.dependencies.length = 0; 78 this.moduleName = binary.getName(); 79 76 80 foreach(ExternalSymbol ext; binary.getExterns()){ 77 81 if(ext.isResolved()){ trunk/ddl/omf/RecordCursor.d
r9 r14 80 80 } 81 81 82 public ushort getDWord(){ 83 ushort result = *cast(uint*)cast(void*)data[position..position+4].ptr; 84 position+=4; 85 return result; 86 } 87 82 88 public char[] getLString(){ 83 89 char[] result; 84 90 uint len = getByte(); 85 91 86 92 if(len == 0) return result; 87 // debug writefln("getLString() pos: %s length: %s len: %s",position,data.length,len); 93 94 //NOTE: this is an undocumented extension to OMF for supporting names greater than 254 chars in length!!! 95 if(len == 255){ 96 getByte(); // throw away next byte (possibly high-order bytes in little-endian format - usually zero) 97 len = getWord(); // get the actual 16-bit length 98 } 88 99 89 100 result = cast(char[])data[position..position+len]; trunk/ddltest.d
r13 r14 28 28 29 29 void main(){ 30 test 1();30 test2(); 31 31 } trunk/test/all.d
r13 r14 26 26 27 27 import test.test1; 28 import test.test2; trunk/test/test1.d
r13 r14 26 26 27 27 private import ddl.all; 28 private import std.stdio; 28 29 29 30 void test1(){ 30 loadDDL(r"c:\dev\dm\lib\phobos.lib"); 31 DynamicLibrary lib = loadDDL(r"c:\dev\dm\lib\phobos.lib"); 32 33 writefln("Phobos modules (%d):",lib.getModules().length); 34 foreach(DynamicModule mod; lib.getModules()){ 35 writefln("%s",mod.getName()); 36 } 31 37 }
