# HG changeset patch # User William Astle # Date 1519965110 25200 # Node ID 7577bfee48bb725c0bb60be13a89f3b01bd74300 # Parent 51bed8c8dc5334c5308f16894043ba2379367638# Parent a6c9129e594838fc38a964d630c3d86ce856a932 Merge changeset a6c9129e5948 from lwasm5 development branch diff -r a6c9129e5948 -r 7577bfee48bb lwasm/insn_indexed.c --- 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); } diff -r a6c9129e5948 -r 7577bfee48bb lwasm/pass1.c --- 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); } } } diff -r a6c9129e5948 -r 7577bfee48bb lwasm/pragma.c --- 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; } diff -r a6c9129e5948 -r 7577bfee48bb lwasm/section.c --- 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;