From 4916b699fa54ba2ce3db502850f399576759146e Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Fri, 28 Apr 2017 22:39:51 +0200 Subject: [PATCH] Add ^pl and ^ph expressions from 2.11BSD's m11. I hope I understood what this is doing! --- parse.c | 36 ++++++++++++++++++++++++++++++++++++ tests/RunTests | 1 + tests/test-ua-pl.lst.ok | 35 +++++++++++++++++++++++++++++++++++ tests/test-ua-pl.mac | 21 +++++++++++++++++++++ tests/test-ua-pl.objd.ok | 29 +++++++++++++++++++++++++++++ 5 files changed, 122 insertions(+) create mode 100644 tests/test-ua-pl.lst.ok create mode 100644 tests/test-ua-pl.mac create mode 100644 tests/test-ua-pl.objd.ok diff --git a/parse.c b/parse.c index 78a3119..843cb40 100644 --- a/parse.c +++ b/parse.c @@ -755,6 +755,42 @@ EX_TREE *parse_unary( tp = new_ex_lit(flt[0]); tp->cp = endcp; } + return tp; + } + case 'p': + /* psect limits, low or high */ { + char bound = tolower((unsigned char)cp[2]); + char *cp2 = skipwhite(cp + 3); + int islocal = 0; + char *endcp; + char *psectname = get_symbol(cp2, &endcp, &islocal); + SYMBOL *sectsym = lookup_sym(psectname, §ion_st); + + if (sectsym && !islocal) { + SECTION *psect = sectsym->section; + + tp = new_ex_tree(); + tp->type = EX_SYM; + tp->data.symbol = sectsym; + tp->cp = cp; + + if (bound == 'l') { + ; /* that's it */ + } else if (bound == 'h') { + EX_TREE *rightp = new_ex_lit(psect->size); + tp = new_ex_bin(EX_ADD, tp, rightp); + } else { + tp = ex_err(tp, endcp); + /* report(stack->top, "^p: %c not recognized", bound); */ + } + } else { + /* report(stack->top, "psect name %s not found"); */ + tp = ex_err(new_ex_lit(0), endcp); + } + free(psectname); + tp->cp = endcp; + cp = endcp; + return tp; } } diff --git a/tests/RunTests b/tests/RunTests index 76e506e..df7532b 100755 --- a/tests/RunTests +++ b/tests/RunTests @@ -21,6 +21,7 @@ TESTS="test-asciz \ test-prec \ test-psect \ test-rad50 \ + test-ua-pl \ test-undef \ test-word-comma" diff --git a/tests/test-ua-pl.lst.ok b/tests/test-ua-pl.lst.ok new file mode 100644 index 0000000..db5836e --- /dev/null +++ b/tests/test-ua-pl.lst.ok @@ -0,0 +1,35 @@ + 1 ;;;;; + 2 ; + 3 ; Test ^pl and ^ph + 4 + 5 000000 .PSECT section + 6 + 7 000000 000000' .word <^pl section> + 8 000002 000014' .word <^ph section> + 9 000004 000000' .word <^pl code> + 10 000006 000010' .word <^ph code> + 11 000010 010' .byte <^ph code> + 12 000011 000C .byte <^ph code> / 256 + 13 + 14 000000 .PSECT code + 15 + 16 000000 000000' .word <^pl section> + 17 000002 000014' .word <^ph section> + 18 000004 000000' .word <^pl code> + 19 000006 000010' .word <^ph code> + 20 + 21 .end + 21 + + +Symbol table + +. ******R 003 + + +Program sections: + +. ABS. 000000 000 (RW,I,GBL,ABS,OVR,NOSAV) + 000000 001 (RW,I,LCL,REL,CON,NOSAV) +SECTIO 000014 002 (RW,I,LCL,REL,CON,NOSAV) +CODE 000010 003 (RW,I,LCL,REL,CON,NOSAV) diff --git a/tests/test-ua-pl.mac b/tests/test-ua-pl.mac new file mode 100644 index 0000000..60106a9 --- /dev/null +++ b/tests/test-ua-pl.mac @@ -0,0 +1,21 @@ +;;;;; +; +; Test ^pl and ^ph + + .PSECT section + + .word <^pl section> + .word <^ph section> + .word <^pl code> + .word <^ph code> + .byte <^ph code> + .byte <^ph code> / 256 + + .PSECT code + + .word <^pl section> + .word <^ph section> + .word <^pl code> + .word <^ph code> + + .end diff --git a/tests/test-ua-pl.objd.ok b/tests/test-ua-pl.objd.ok new file mode 100644 index 0000000..7c487c5 --- /dev/null +++ b/tests/test-ua-pl.objd.ok @@ -0,0 +1,29 @@ +GSD: + MODNAME .MAIN.=0 flags=0 + PSECT =0 CON RW REL LCL I flags=40 + PSECT . ABS.=0 OVR RW ABS GBL I flags=104 + PSECT CODE =10 CON RW REL LCL I flags=40 + PSECT SECTIO=14 CON RW REL LCL I flags=40 + XFER . ABS.=1 flags=10 +ENDGSD +RLD + Location counter definition SECTIO+0 +TEXT ADDR=0 LEN=12 + 000000: 000000 000014 000000 000010 ........ + 000010: 000010 .. +RLD + Internal 0=0 + Internal 2=14 + PSECT plus offset 4=CODE+0 + PSECT plus offset 6=CODE+10 + PSECT plus offset byte 10=CODE+10 + Complex byte 11=CODE:10 256 / store + Location counter definition CODE+0 +TEXT ADDR=0 LEN=10 + 000000: 000000 000014 000000 000010 ........ +RLD + PSECT plus offset 0=SECTIO+0 + PSECT plus offset 2=SECTIO+14 + Internal 4=0 + Internal 6=10 +ENDMOD