changeset 468:7577bfee48bb

Merge changeset a6c9129e5948 from lwasm5 development branch
author William Astle <lost@l-w.ca>
date Thu, 01 Mar 2018 21:31:50 -0700
parents 51bed8c8dc53 (diff) a6c9129e5948 (current diff)
children 9393a6b8886c
files lwlib/lw_version.h
diffstat 4 files changed, 47 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/insn_indexed.c	Thu Mar 01 21:25:51 2018 -0700
+++ b/lwasm/insn_indexed.c	Thu Mar 01 21:31:50 2018 -0700
@@ -571,6 +571,38 @@
 				return;
 			}
 		}
+		else
+		{
+			if ((l -> pb & 0x07) == 5 || (l -> pb & 0x07) == 6)
+			{
+				// NOTE: this will break in some particularly obscure corner cases
+				// which are not likely to show up in normal code. Notably, if, for
+				// some reason, the target gets *farther* away if shorter addressing
+				// modes are chosen, which should only happen if the symbol is before
+				// the instruction in the source file and there is some sort of ORG
+				// statement or similar in between which forces the address of this
+				// instruction, and the differences happen to cross the 8 bit boundary.
+				// For this reason, we use a heuristic and allow a margin on the 8
+				// bit boundary conditions.
+				v = as -> pretendmax;
+				as -> pretendmax = 1;
+				lwasm_reduce_expr(as, e2);
+				as -> pretendmax = v;
+				if (lw_expr_istype(e2, lw_expr_type_int))
+				{
+					v = lw_expr_intval(e2);
+					// Actual range is -128 <= offset <= 127; we're allowing a fudge
+					// factor of 25 or so bytes so that we're less likely to accidentally
+					// cross into the 16 bit boundary in weird corner cases.
+					if (v >= -100 || v <= 100)
+					{
+						l -> lint = 1;
+						l -> pb = (l -> pb & 0x80) ? 0x9C : 0x8C;
+						return;
+					}
+				}
+			}
+		}
 		lw_expr_destroy(e2);
 	}
 		
--- a/lwasm/pass1.c	Thu Mar 01 21:25:51 2018 -0700
+++ b/lwasm/pass1.c	Thu Mar 01 21:31:50 2018 -0700
@@ -330,7 +330,11 @@
         			goto linedone;
         		}
         	}
-			if (instab[opnum].opcode == NULL)
+        	
+			if (instab[opnum].opcode == NULL ||
+				(CURPRAGMA(cl, PRAGMA_6809) && (instab[opnum].flags & lwasm_insn_is6309)) ||
+				(!CURPRAGMA(cl, PRAGMA_6809) && (instab[opnum].flags & lwasm_insn_is6809))
+			)
 			{
 				cl -> insn = -1;
 				if (*tok != ';' && *tok != '*')
@@ -343,7 +347,12 @@
 						if (expand_struct(as, cl, &p1, sym) != 0)
 						{
 							// structure expansion failed
-							lwasm_register_error(as, cl, E_OPCODE_BAD);
+							if (CURPRAGMA(cl, PRAGMA_6809) && (instab[opnum].flags & lwasm_insn_is6309))
+								lwasm_register_error2(as, cl, E_6309_INVALID, "(%s)", sym);
+							else if (!CURPRAGMA(cl, PRAGMA_6809) && (instab[opnum].flags & lwasm_insn_is6809))
+								lwasm_register_error2(as, cl, E_6809_INVALID, "(%s)", sym);
+							else
+								lwasm_register_error(as, cl, E_OPCODE_BAD);
 						}
 					}
 				}
--- a/lwasm/pragma.c	Thu Mar 01 21:25:51 2018 -0700
+++ b/lwasm/pragma.c	Thu Mar 01 21:31:50 2018 -0700
@@ -110,6 +110,7 @@
 		p = lw_token(np, ',', &np);
 		debug_message(as, 200, "Setting/resetting pragma %s", p);
 		pragma = parse_pragma_helper(p);
+		debug_message(as, 200, "Got pragma code %08X", pragma);
 		lw_free(p);
 
 		if (pragma == 0 && !ignoreerr)
@@ -119,6 +120,8 @@
 			as->pragmas &= ~pragma;
 		else
 			as->pragmas |= pragma;
+		
+		debug_message(as, 200, "New pragma state: %08X", as -> pragmas);
 	}
 	return 1;
 }
--- a/lwasm/section.c	Thu Mar 01 21:25:51 2018 -0700
+++ b/lwasm/section.c	Thu Mar 01 21:31:50 2018 -0700
@@ -171,7 +171,7 @@
 
 PARSEFUNC(pseudo_parse_endsection)
 {
-	if (as -> output_format != OUTPUT_OBJ)
+	if (as -> output_format != OUTPUT_OBJ && as -> output_format != OUTPUT_LWMOD)
 	{
 		lwasm_register_error(as, l, E_SECTION_TARGET);
 		return;