1. Jason S
  2. file2obj28xx

Commits

Jason S  committed 5b310f4

hurray! bytes 44 and 45 hold a flag saying whether the section contains 8- or 16-bit data; you need 16-bit flag on real memory data and the 8-bit flag on debug info.

  • Participants
  • Parent commits 4df1343
  • Branches default

Comments (0)

Files changed (3)

File src/org/bitbucket/jason_s/file2obj/BasicCoffFile.java

View file
 		final private ByteBuffer data;
 		final private LazyRelocationEntryList lrelist;
 		final private int flags;
+		final private short reserved44;
 		
 		Section(Builder b) {
 			this.name = b.name;
 			this.data = b.data.asReadOnlyBuffer();
 			this.flags = b.flags;
 			this.lrelist = b.lrelist;
+			this.reserved44 = b.reserved44;
 		}
 		public String getName() { return this.name; }
 		public int getDataSize() { return this.data.remaining(); }
 		public int getHeaderLength() { return Coff.SECTIONHEADER_LENGTH; }
 		public ByteBuffer getData() { return this.data.duplicate(); }
 		public ByteBuffer getRelocationEntryData() { return this.lrelist.getBuffer(); }
+		public boolean isWord8() { return (this.reserved44 & 0x08) == 0x08; } 
+		public boolean isWord16() { return !isWord8(); } 
 
 		public ByteBuffer asSymbolTableEntry(StringTable stable, short sectionNumber, byte storageClass)
 		{
 		// on whether the section is a data/code section or just debug info. Grrr!
 		public int getSectionLength() {
 			int dataSize = getDataSize();			
-			if (getFlags() == STYP_COPY) 
+			if (isWord8()) 
 				return dataSize;
 			else
 				return (dataSize / 2);
 			private ByteBuffer data = getNullBuffer();
 			String name;
 			int flags;
+			short reserved44;
 			LazyRelocationEntryList lrelist = new LazyRelocationEntryList(null);
 
-			public Builder(StringTable stable) { this.stable = stable; }
+			public Builder(StringTable stable) { 
+				this.stable = stable; 
+				word8();
+			}
 			public Builder name(String name) { this.name = name; this.stable.add(name); return this; }
 			public Builder data(ByteBuffer data) { 	this.data = copyBuffer(data); return this; }
+			public Builder word8() { this.reserved44 = 0x08; return this; }
+			public Builder word16() { this.reserved44 = 0x00; return this; }
 			public Builder flagCopy() { this.flags = STYP_COPY; return this; }
 			public Builder flagText() { this.flags = STYP_TEXT; return this; }
 			public Builder flagData() { this.flags = STYP_DATA; return this; }
 			bbuf.putInt(reserved);
 			bbuf.putInt(getFlags());
 			
-			/* not sure why this is 08 (or whether it's always 08),
-			 * but this is a critical key word, without which this
-			 * file is not recognized by the TI tools.
+			/* 
+			 * bytes 44-45 seem to contain 0000 for normal 16-bit word sections,
+			 * and 0008 for 8-bit word sections (debug info).
+			 * This is a critical word, without which this
+			 * file's DWARF information is not recognized properly by the TI tools.
 			 */
-			short mysteryReserved = 8;  
-			bbuf.putShort(mysteryReserved);
+			bbuf.putShort(this.reserved44);
 			bbuf.putShort(getMemoryPageNumber());
 			bbuf.flip();
 			return bbuf;
 		addSection(Section.builder(stable)
 				.name("$build.attributes")
 				.dataHex("41 26 00 00 00 54 49 00 01 1f 00 00 00 05 41 73 73 65 6d 62 6c 65 72 00 08 07 0a 01 0c 03 80 02 02 82 02 02 84 02 02")
-				.flagCopy()
+				.flagCopy()				
 				.build());
-		addSection(Section.builder(stable).name(".text").flagText().build());
-		addSection(Section.builder(stable).name(".data").flagData().build());
-		addSection(Section.builder(stable).name(".bss").flagBss().build());
+		addSection(Section.builder(stable).name(".text").flagText().word16().build());
+		addSection(Section.builder(stable).name(".data").flagData().word16().build());
+		addSection(Section.builder(stable).name(".bss").flagBss().word16().build());
 		List<BinaryObjectReference> borlist = this.binaryObjectManager.addObjects(objects);
 		for (Map.Entry<String, ByteBuffer> entry : this.binaryObjectManager.getSections().entrySet())
 		{
 				.name(entry.getKey())
 				.data(entry.getValue())
 				.flagData()
+				.word16()
 				.build());				
 		}
 

File src/org/bitbucket/jason_s/file2obj/DwarfRegisterAssigner.java

View file
+package org.bitbucket.jason_s.file2obj;
+
+public class DwarfRegisterAssigner {
+	final private byte abbrevDWTagTIAssignRegister;
+	final private ByteBufferBuilder bbb;
+
+	public DwarfRegisterAssigner(byte abbrevDWTagTIAssignRegister,
+			ByteBufferBuilder bbb) {
+		this.abbrevDWTagTIAssignRegister = abbrevDWTagTIAssignRegister;
+		this.bbb = bbb;
+	}
+
+	public DwarfRegisterAssigner reg(int n, String registerName) {
+		if (n < 0 || n >= 32)
+			throw new IllegalArgumentException("DW_OP_reg[n] must be between 0 and 31, got "+n);
+		
+		this.bbb.writeU8(this.abbrevDWTagTIAssignRegister);
+		
+		// DW_AT_location:
+		this.bbb.writeU8((byte)1);             // length of remaining bytes = 1;
+		this.bbb.writeU8((byte) (0x50 + n));   // DW_OP_reg[n]
+		
+		this.bbb.writeNullTerminatedString(registerName);
+		return this;
+	}
+
+	public DwarfRegisterAssigner regx(int n, String registerName) {
+		
+		this.bbb.writeU8(this.abbrevDWTagTIAssignRegister);
+		int pos = this.bbb.position();
+		this.bbb.writeU8((byte)0);  // placeholder for length of remaining bytes
+		
+		this.bbb.writeU8((byte)0x90);  // DW_OP_regx
+		this.bbb.encodeLEB128U(n);     // register number
+		int nlength = this.bbb.position() - pos - 1;
+		this.bbb.writeU8((byte) nlength, pos);
+		
+		this.bbb.writeNullTerminatedString(registerName);
+		return this;
+	}
+
+}

File test/test1.obj

Binary file modified.