Browse Source

added fixup in AMD assembler (otherwise cannot refer to overal code size in ELF header)

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6499 8c9fc860-2736-0410-a75d-ab315db34111
felixf 9 years ago
parent
commit
db0bfa8b03
2 changed files with 40 additions and 15 deletions
  1. 37 13
      source/FoxAMD64Assembler.Mod
  2. 3 2
      source/FoxBinaryCode.Mod

+ 37 - 13
source/FoxAMD64Assembler.Mod

@@ -118,7 +118,8 @@ CONST
 	symNegate = 21;
 	symMod = 22;
 	symPeriod = 23;
-	symEnd = 24;
+	symAt = 24;
+	symEnd = 25;
 
 TYPE
 	Name = Scanner.IdentifierString;
@@ -268,6 +269,17 @@ TYPE
 			s.Get(msg);
 			ErrorSS(msg1,msg);
 		END ErrorSI;
+		
+		PROCEDURE AddFixup (mode: SHORTINT; size: SHORTINT; pc: LONGINT; symbol: ObjectFile.Identifier; symbolOffset, displacement: LONGINT);
+		VAR fixup: BinaryCode.Fixup; format: BinaryCode.FixupPatterns; id: ObjectFile.Identifier;
+		BEGIN
+			NEW(format,1);
+			format[0].bits:= size*8;
+			format[0].offset := 0;
+			fixup := BinaryCode.NewFixup(mode,pc,symbol,symbolOffset,displacement,0,format);
+			code.fixupList.AddFixup(fixup);
+		END AddFixup;
+
 
 		PROCEDURE EmitInstruction (mnem: LONGINT; VAR operands: ARRAY OF Operand; lastPass: BOOLEAN): BOOLEAN;
 		VAR instr, i, oppos, op: LONGINT;
@@ -319,16 +331,6 @@ TYPE
 				RETURN instr
 			END FindInstruction;
 
-			PROCEDURE AddFixup (mode: SHORTINT; size: SHORTINT; pc: LONGINT; symbol: ObjectFile.Identifier; symbolOffset, displacement: LONGINT);
-			VAR fixup: BinaryCode.Fixup; format: BinaryCode.FixupPatterns; id: ObjectFile.Identifier;
-			BEGIN
-				NEW(format,1);
-				format[0].bits:= size*8;
-				format[0].offset := 0;
-				fixup := BinaryCode.NewFixup(mode,pc,symbol,symbolOffset,displacement,0,format);
-				code.fixupList.AddFixup(fixup);
-			END AddFixup;
-
 			PROCEDURE GetRegOperand (): LONGINT;
 			VAR i: LONGINT;
 			BEGIN
@@ -1262,6 +1264,8 @@ TYPE
 					NextChar;
 				| '}': symbol := symRBrace;
 					NextChar;
+				| '@': symbol := symAt;
+					NextChar;
 				| '$': NextChar;
 					IF char = '$' THEN
 						symbol := symPCOffset; NextChar;
@@ -1437,7 +1441,7 @@ TYPE
 
 
 			PROCEDURE PutData (size: Size): BOOLEAN;
-			VAR i: LONGINT; type:SHORTINT;
+			VAR i: LONGINT; type:SHORTINT; ofs: Operand;
 			BEGIN
 				NextSymbol;
 
@@ -1454,6 +1458,26 @@ TYPE
 							WHILE i # 0 DO emitter.code.PutByte (0); DEC (i) END;
 						END;
 						NextSymbol;
+					ELSIF (scope # NIL) & (symbol = symAt) THEN
+						NextSymbol;
+						IF symbol # symIdent THEN Error("identifier missing") END;
+						GetOffsetFixup (idents, ofs);
+						NextSymbol;
+						IF symbol = symPlus THEN
+							NextSymbol;
+							IF Expression(i, FALSE, type) THEN
+								ofs.displacement := i
+							END;
+						ELSIF symbol = symMinus THEN
+							NextSymbol;
+							IF Expression(i, FALSE, type) THEN
+								ofs.displacement := - i
+							END;
+						END;
+						IF pass = maxPasses THEN
+						emitter.AddFixup(BinaryCode.Absolute,4, emitter.code.pc, ofs.symbol, ofs.symbolOffset,ofs.displacement);
+						END;
+						emitter.code.PutBytes (i, size );
 					ELSIF Expression (i, FALSE,type) THEN
 						emitter.code.PutBytes (i, size );
 					ELSE
@@ -1801,7 +1825,7 @@ TYPE
 							END;
 						ELSE
 							(* number or identifier (symbol) *)
-							InitImm(offset,size,0);
+						InitImm(offset,size,0);
 
 							IF (scope # NIL) & (symbol = symIdent) THEN (* identifier: must be a symbol *)
 								GetOffsetFixup (idents, offset);

+ 3 - 2
source/FoxBinaryCode.Mod

@@ -590,9 +590,10 @@ TYPE
 				i := from; nr := 0;
 				IF to >= pc THEN to := pc-1 END;
 				WHILE i <= to DO
-					w.String("["); w.Int(i,3); w.String("] ");
+					w.String("["); w.Hex(i,3); w.String("] ");
 					nr := 0;
-					WHILE (i<=to) & (nr<32) DO
+					WHILE (i<=to) & (nr<16) DO
+						IF i = 8 THEN w.Sring(" ") END;
 						DumpUnit(i);
 						w.String(" ");
 						INC(i); INC(nr);