# HG changeset patch # User lost # Date 1238338348 0 # Node ID 048ebb85f6ef8f2d989938abc993b85e237d3b2e # Parent 2c1afbdb2de0578c1cd0e0130655dd0de078cc22 Added 8 bit external references for base page addressing mode diff -r 2c1afbdb2de0 -r 048ebb85f6ef ChangeLog --- a/ChangeLog Sun Mar 22 22:11:12 2009 +0000 +++ b/ChangeLog Sun Mar 29 14:52:28 2009 +0000 @@ -24,6 +24,8 @@ global symbol (non-section) if it resolves to a constant [+] added operator ~ as a prefix operator for a 1s complement in LWASM [+] allow exporting multiple symbols (export sym,sym,sym...) +[+] allow extern references in base page addresing mode (LWASM) +[+] handle 8 bit external references (LWLINK) [b] arranged for output files for lwasm/lwlink to be removed if the assembly or linking fails [ ] DECB output of LWLINK now collapses contiguous output blocks into single diff -r 2c1afbdb2de0 -r 048ebb85f6ef lwasm/insn_gen.c --- a/lwasm/insn_gen.c Sun Mar 22 22:11:12 2009 +0000 +++ b/lwasm/insn_gen.c Sun Mar 29 14:52:28 2009 +0000 @@ -101,6 +101,8 @@ if (extra != -1) lwasm_emit(as, l, extra); lwasm_emit(as, l, v1 & 0xff); + l -> relocoff = as -> addr - l -> codeaddr; + l -> reloc8bit = 1; return; } else diff -r 2c1afbdb2de0 -r 048ebb85f6ef lwasm/lwasm.h --- a/lwasm/lwasm.h Sun Mar 22 22:11:12 2009 +0000 +++ b/lwasm/lwasm.h Sun Mar 29 14:52:28 2009 +0000 @@ -37,6 +37,7 @@ struct section_reloc_list_s { int offset; // offset into section + int relocsize; // size of relocation in bytes lwasm_expr_stack_t *expr; // value definition int context; // symbol context (for local syms) section_reloc_list_t *next; // next relocation @@ -113,6 +114,7 @@ // the following are used for obj format - for external references, inter-section // references, and intrasection relocations int relocoff; // offset into insn where relocation value goes + int reloc8bit; // size of relocation (0 = 16 bit, 1 = 8 bit) lwasm_expr_stack_t *exprs[4]; // non-constant expression values int exprvals[4]; // constant expression values char *exprends[4]; // pointer to character after end of expression diff -r 2c1afbdb2de0 -r 048ebb85f6ef lwasm/output.c --- a/lwasm/output.c Sun Mar 22 22:11:12 2009 +0000 +++ b/lwasm/output.c Sun Mar 29 14:52:28 2009 +0000 @@ -257,6 +257,9 @@ re -> offset = l -> codeaddr + l -> relocoff; re -> expr = l -> exprs[0]; re -> context = l -> context; + re -> relocsize = 2; + if (l -> reloc8bit) + re -> relocsize = 1; } } } @@ -331,6 +334,13 @@ // work through each term in the expression and output // the proper equivalent to the object file + if (re -> relocsize == 1) + { + // flag an 8 bit relocation (low 8 bits will be used) + buf[0] = 0xFF; + buf[1] = 0x01; + writebytes(buf, 2, 1, of); + } for (sn = re -> expr -> head; sn; sn = sn -> next) { switch (sn -> term -> term_type) diff -r 2c1afbdb2de0 -r 048ebb85f6ef lwlink/link.c --- a/lwlink/link.c Sun Mar 22 22:11:12 2009 +0000 +++ b/lwlink/link.c Sun Mar 29 14:52:28 2009 +0000 @@ -356,8 +356,15 @@ { // put the value into the relocation address rval = lw_expr_get_value(rl -> expr); - sectlist[sn].ptr -> code[rl -> offset] = (rval >> 8) & 0xff; - sectlist[sn].ptr -> code[rl -> offset + 1] = rval & 0xff; + if (rl -> flags & RELOC_8BIT) + { + sectlist[sn].ptr -> code[rl -> offset] = rval & 0xff; + } + else + { + sectlist[sn].ptr -> code[rl -> offset] = (rval >> 8) & 0xff; + sectlist[sn].ptr -> code[rl -> offset + 1] = rval & 0xff; + } } } } diff -r 2c1afbdb2de0 -r 048ebb85f6ef lwlink/lwlink.h --- a/lwlink/lwlink.h Sun Mar 22 22:11:12 2009 +0000 +++ b/lwlink/lwlink.h Sun Mar 29 14:52:28 2009 +0000 @@ -39,10 +39,13 @@ symtab_t *next; // next symbol }; +#define RELOC_NORM 0 // all default (16 bit) +#define RELOC_8BIT 1 // only use the low 8 bits for the reloc typedef struct reloc_s reloc_t; struct reloc_s { int offset; // where in the section + int flags; // flags for the relocation lw_expr_stack_t *expr; // the expression to calculate it reloc_t *next; // ptr to next relocation }; diff -r 2c1afbdb2de0 -r 048ebb85f6ef lwlink/objdump.c --- a/lwlink/objdump.c Sun Mar 22 22:11:12 2009 +0000 +++ b/lwlink/objdump.c Sun Mar 29 14:52:28 2009 +0000 @@ -257,6 +257,12 @@ // the section base address printf(" SB"); break; + + case 0xFF: + // section flags + printf(" FLAGS=%02X", CURBYTE()); + NEXTBYTE(); + break; default: printf(" ERR"); diff -r 2c1afbdb2de0 -r 048ebb85f6ef lwlink/readfiles.c --- a/lwlink/readfiles.c Sun Mar 22 22:11:12 2009 +0000 +++ b/lwlink/readfiles.c Sun Mar 29 14:52:28 2009 +0000 @@ -266,6 +266,7 @@ s -> incompletes = rp; rp -> offset = 0; rp -> expr = lw_expr_stack_create(); + rp -> flags = RELOC_NORM; // parse the expression while (CURBYTE()) @@ -274,6 +275,12 @@ NEXTBYTE(); switch (tt) { + case 0xFF: + // a flag specifier + tt = CURBYTE(); + rp -> flags = tt; + term = NULL; + case 0x01: // 16 bit integer tt = CURBYTE() << 8; @@ -312,8 +319,11 @@ fprintf(stderr, "%s (%s): bad relocation expression\n", fn -> filename, s -> name); exit(1); } - lw_expr_stack_push(rp -> expr, term); - lw_expr_term_free(term); + if (term) + { + lw_expr_stack_push(rp -> expr, term); + lw_expr_term_free(term); + } } // skip the NUL NEXTBYTE();