Commits

Jason S committed 4df1343

hurray, it links (I'd forgotten to add relocation entries for the array_type tags). Some of the data shows up in the final executable, but some seems to be missing.

  • Participants
  • Parent commits 002e395

Comments (0)

Files changed (4)

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

 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.bitbucket.jason_s.file2obj.BasicCoffFile.RelocationEntry.Type;
-import org.bitbucket.jason_s.file2obj.BasicCoffFile.Section.Builder;
 
 public class BasicCoffFile implements StreamWritable
 {
 	private static final String SECTION_DEBUG_INFO = ".debug_info";
 	private static final String SECTION_DEBUG_ABBREV = ".debug_abbrev";
+	private static final String VERSION = "0.1.0";
 	
 	final private ByteBufferBuilder bytes = new ByteBufferBuilder();
 	final private SectionManager sectionManager = new SectionManager();
 
 	static class LazyRelocationEntry implements Function<SectionNumberFinder, RelocationEntry>
 	{
-		final private Type type;
+		final private RelocationEntry.Type type;
 		final private int startAddress;
 		final private String sectionName;
 		
 		addSection(Section.builder(stable)
 				.name(SECTION_DEBUG_INFO)
 				.data(createDebugInfo("abc", "def", 
-						"Jason's spiffy object file creator v1.0.0 for "+magic_TI_words+" 28xx DSP",
+						"Jason's spiffy object file creator v"+VERSION+" for "+magic_TI_words+" 28xx DSP",
 						borlist, lrelist))
 				.relocationEntries(lrelist)
 				.flagCopy()
 	static final private byte C_FILE = 103;
 	static final private byte C_EXT = 2;
 	static final private byte C_STAT = 3;
+	static final boolean writeRegisterAssignments = false;
 	private int writeSymbolTableEntries(StringTable stable, List<BinaryObjectReference> borlist) {
 		int pos = this.bytes.position();
 		Map<String, Integer> sectionNumberMap = new HashMap<String, Integer>();
 
 			0x08,
 			(byte)0x80, (byte) 0x81, 0x01, 0x00,   // DW_TAG_TI_far_type
-			0x49, 0x10,               //   ref_addr type
+			0x49, 0x10,       //   ref_addr type
 			0x00, 0x00,
-
+			
 			0x09,
 			0x26, 0x00,       // DW_TAG_const_type
 			0x49, 0x10,       //   ref_addr type
 			0x00, 0x00,
 
+			0x0a,
+			(byte)0x82, (byte) 0x81, 0x01, 0x00,   // DW_TAG_TI_assign_register
+			0x02, 0x0a,       //   block1 location
+			0x03, 0x08,       //   string name
+			0x00, 0x00,
+
 			0x00
 		};			
 		return ByteBuffer.wrap(b).asReadOnlyBuffer();
 			else
 			{
 				int basetypeofs = baseTypeOffsets.get(st);
-				int arraytypeofs = writeArrayType(bbb, basetypeofs, bobj.getObject().getStorageSizeBytes() / 2);
+				int arraytypeofs = writeArrayType(bbb, basetypeofs, bobj.getObject().getStorageSizeBytes() / 2, lrelist);
 				// divide-by-2 !!! C2800 16-bit words
 				writeVariable(bbb, arraytypeofs, bobj, lrelist);				
 			}			
 		}
+		
+		// This doesn't look necessary, but in case it is, we have this here.
+		if (writeRegisterAssignments)
+		{
+			byte abbrevDWTagTIAssignRegister = 0x0a;
+			new DwarfRegisterAssigner(abbrevDWTagTIAssignRegister, bbb)
+				.reg(0, "AL")
+				.reg(1, "AH")
+				.reg(2, "PL")
+				.reg(3, "PH")
+				.reg(22, "T")
+				.regx(37, "IER")
+				.regx(36, "IFR")
+				.reg(23, "ST0")
+				.reg(30, "SXM")
+				.reg(31, "PM")
+				.regx(32, "OVM")
+				.regx(38, "V")
+				.regx(75, "PSEUDO")
+				.reg(24, "ST1")
+				.regx(33, "PAGE0")
+				.regx(35, "INTM")
+				.regx(34, "AMODE")
+				.regx(76, "PSEUDOH")
+				.reg(21, "XT")
+				.reg(20, "SP")
+				.reg(28, "FP")
+				.reg(29, "DP")
+				.reg(25, "PC")
+				.regx(77, "VOL")
+				.reg(4, "AR0")
+				.reg(6, "AR1")
+				.reg(8, "AR2")
+				.reg(10, "AR3")
+				.reg(12, "AR4")
+				.reg(14, "AR5")
+				.reg(16, "AR6")
+				.reg(16, "AR6")
+				.reg(17, "XAR6")
+				.reg(18, "AR7")
+				.reg(19, "XAR7")
+				.reg(5, "XAR0")
+				.reg(7, "XAR1")
+				.reg(9, "XAR2")
+				.reg(11, "XAR3")
+				.reg(13, "XAR4")
+				.reg(15, "XAR5")
+				.regx(78, "CIE_RETA")
+				;
+		}
 
 		bbb.writeU8((byte) 0);  // END
 		
 		return addrofs;
 	}
 
-	static private int writeArrayType(ByteBufferBuilder bbb, int basetypeofs, int length) {
+	static private int writeArrayType(ByteBufferBuilder bbb, int basetypeofs, int length, LazyRelocationEntryList lrelist) {
 		int ofs = bbb.position();
 		
 		bbb.writeU8((byte) 4); // array type abbrev
 		bbb.encodeLEB128U(length);
 		byte language = 4;
 		bbb.writeU8(language);
+		
+		int reloc_basetypeofs = bbb.position();
 		bbb.writeU32(basetypeofs);
 		
 		if (length <= 256)
 		
 		bbb.writeU8((byte) 0); // end of array type children
 		
+		lrelist.add(LazyRelocationEntry.of(RelocationEntry.Type.R_RELLONG, reloc_basetypeofs, SECTION_DEBUG_INFO));
 		return ofs;
 	}
 

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

 package org.bitbucket.jason_s.file2obj;
 
-import java.io.BufferedOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.regex.Matcher;
 		this.bytes.add(n);
 		return this;
 	}
+	public ByteBufferBuilder writeU8(byte n, int pos)
+	{
+		this.bytes.set(pos, n);
+		return this;
+	}
 	public ByteBufferBuilder writeU16(int n)
 	{
 		writeU8((byte) (n >> 0));

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

 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 	}
 	
 	public static void main(String[] args) {
-		BinaryObject bobj1 = BinaryObject.builder()
+		List<BinaryObject> objlist = new ArrayList<BinaryObject>();
+		objlist.add(BinaryObject.builder()
 				.name("foo")
 				.section("bar")
 				.type(StorageType.U8)
-				.fromString("This is a test. This is only a test.")
-				.build();
-		BinaryObject bobj2 = BinaryObject.builder()
+				.fromString("foo says 'This is a test. This is only a test.'")
+				.build());
+		objlist.add(BinaryObject.builder()
 				.name("father::of::invention")
 				.section("bar")
 				.type(StorageType.S8)
-				.fromString("This is a test. This is only a test.")
-				.build();
-		BinaryObject bobj3 = BinaryObject.builder()
+				.fromString("invention says 'This is a test. This is only a test.'")
+				.build());
+		objlist.add(BinaryObject.builder()
 				.name("quux")
 				.section("baz")
 				.type(StorageType.U16_LE)
-				.fromString("This is a test. This is only a test.")
-				.build();
-		BinaryObject bobj4 = BinaryObject.builder()
+				.fromString("quux says 'This is a test. This is only a test.'")
+				.build());
+		objlist.add(BinaryObject.builder()
 				.name("bountiful::cornucopia")
 				.section("baz")
 				.type(StorageType.S16_BE)
-				.fromString("This is a test. This is only a test.")
-				.build();
-		List<BinaryObject> objlist = Arrays.asList(bobj4, bobj2, bobj1, bobj3);
+				.fromString("cornucopia says 'This is a test. This is only a test.'")
+				.build());
+		objlist.add(BinaryObject.builder()
+				.name("what::a::beautiful::day")
+				.section("gconst:s1")
+				.type(StorageType.U16_BE)
+				.fromString("day says 'This is a test. This is only a test.'")
+				.build());
+		objlist.add(BinaryObject.builder()
+				.name("so::long::and::thanks::for::all::the::fish")
+				.section("gconst:hhg")
+				.type(StorageType.S16_LE)
+				.fromString("fish says 'This is a test. This is only a test.'")
+				.build());
 		Parameters p = new Parameters(args);
 		try
 		{

File test/test1.obj

Binary file modified.