From 0fccc4021d24c58c9439a8a56ab78708c366b687 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Fri, 29 Apr 2005 17:46:04 +0000 Subject: [PATCH] * gas/sb.c: Include as.h. (sb_to_scrub, scrub_position, scrub_from_sb): New statics. (sb_scrub_and_add_sb): New interface. * gas/sb.h: Declare sb_scrub_and_add_sb. * gas/input-scrub.c (input_scrub_include_sb): Use it. * gas/config/tc-arm.c (do_t_arit3c): Correct typo in expression. (do_t_mul): Allow dest to equal either source1 or source2 in 16-bit form; do not complain about dest == source1 in any case. * gas/testsuite/gas/arm/tcompat2.s: Test both dest==source1 and dest==source2 for commutative arithmetic instructions. * gas/testsuite/gas/arm/tcompat2.d: Update to match. * gas/testsuite/gas/arm/t16-bad.l: Adjust expected diagnostic. * gas/testsuite/gas/arm/macro1.s, gas/arm/macro1.d: New test pair. * gas/testsuite/gas/arm/arm.exp: Run it. --- ChangeLog.csl | 20 ++++++++++++++++++++ gas/config/tc-arm.c | 17 ++++++++++------- gas/input-scrub.c | 2 +- gas/sb.c | 32 ++++++++++++++++++++++++++++++++ gas/sb.h | 1 + gas/testsuite/gas/arm/arm.exp | 1 + gas/testsuite/gas/arm/macro1.d | 9 +++++++++ gas/testsuite/gas/arm/macro1.s | 6 ++++++ gas/testsuite/gas/arm/t16-bad.l | 2 +- gas/testsuite/gas/arm/tcompat2.d | 18 +++++++++++------- gas/testsuite/gas/arm/tcompat2.s | 18 ++++++++++++++++-- 11 files changed, 108 insertions(+), 18 deletions(-) create mode 100644 gas/testsuite/gas/arm/macro1.d create mode 100644 gas/testsuite/gas/arm/macro1.s diff --git a/ChangeLog.csl b/ChangeLog.csl index dc781404803..46afaf35937 100644 --- a/ChangeLog.csl +++ b/ChangeLog.csl @@ -1,3 +1,23 @@ +2005-04-29 Zack Weinberg + + * gas/sb.c: Include as.h. + (sb_to_scrub, scrub_position, scrub_from_sb): New statics. + (sb_scrub_and_add_sb): New interface. + * gas/sb.h: Declare sb_scrub_and_add_sb. + * gas/input-scrub.c (input_scrub_include_sb): Use it. + + * gas/config/tc-arm.c (do_t_arit3c): Correct typo in expression. + (do_t_mul): Allow dest to equal either source1 or source2 in + 16-bit form; do not complain about dest == source1 in any + case. + + * gas/testsuite/gas/arm/tcompat2.s: Test both dest==source1 and + dest==source2 for commutative arithmetic instructions. + * gas/testsuite/gas/arm/tcompat2.d: Update to match. + * gas/testsuite/gas/arm/t16-bad.l: Adjust expected diagnostic. + * gas/testsuite/gas/arm/macro1.s, gas/arm/macro1.d: New test pair. + * gas/testsuite/gas/arm/arm.exp: Run it. + 2005-04-25 Zack Weinberg Thumb32 assembler. diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c index 6fb4919a757..194259ccee4 100644 --- a/gas/config/tc-arm.c +++ b/gas/config/tc-arm.c @@ -6025,7 +6025,7 @@ do_t_arit3c (void) if (Rd == Rs) inst.instruction |= Rn << 3; else if (Rd == Rn) - inst.instruction |= Rn << 3; + inst.instruction |= Rs << 3; else constraint (1, _("dest must overlap one source register")); } @@ -6735,15 +6735,18 @@ do_t_mul (void) { constraint (!thumb32_mode && inst.instruction == T_MNEM_muls, BAD_THUMB32); - constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, BAD_HIREG); - constraint (inst.operands[0].reg != inst.operands[2].reg, - _("dest and source2 must be the same register")); - if (inst.operands[0].reg == inst.operands[1].reg) - as_tsktsk (_("dest and source must be different in MUL")); + constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, + BAD_HIREG); inst.instruction = THUMB_OP16 (inst.instruction); inst.instruction |= inst.operands[0].reg; - inst.instruction |= inst.operands[1].reg << 3; + + if (inst.operands[0].reg == inst.operands[1].reg) + inst.instruction |= inst.operands[2].reg << 3; + else if (inst.operands[0].reg == inst.operands[2].reg) + inst.instruction |= inst.operands[1].reg << 3; + else + constraint (1, _("dest must overlap one source register")); } } diff --git a/gas/input-scrub.c b/gas/input-scrub.c index 2657b8ac597..16b429ea1f2 100644 --- a/gas/input-scrub.c +++ b/gas/input-scrub.c @@ -280,7 +280,7 @@ input_scrub_include_sb (sb *from, char *position, int is_expansion) /* Add the sentinel required by read.c. */ sb_add_char (&from_sb, '\n'); } - sb_add_sb (&from_sb, from); + sb_scrub_and_add_sb (&from_sb, from); sb_index = 1; /* These variables are reset by input_scrub_push. Restore them diff --git a/gas/sb.c b/gas/sb.c index 41f827f567c..2886ef07a67 100644 --- a/gas/sb.c +++ b/gas/sb.c @@ -33,6 +33,7 @@ #endif #include "libiberty.h" #include "sb.h" +#include "as.h" /* These routines are about manipulating strings. @@ -121,6 +122,37 @@ sb_add_sb (sb *ptr, sb *s) ptr->len += s->len; } +/* helper for below */ +static sb *sb_to_scrub; +static char *scrub_position; +static int +scrub_from_sb (char *buf, int buflen) +{ + int copy; + copy = sb_to_scrub->len - (scrub_position - sb_to_scrub->ptr); + if (copy > buflen) + copy = buflen; + memcpy (buf, scrub_position, copy); + scrub_position += copy; + return copy; +} + +/* run the sb at s through do_scrub_chars and add the result to the sb + at ptr */ + +void +sb_scrub_and_add_sb (sb *ptr, sb *s) +{ + sb_to_scrub = s; + scrub_position = s->ptr; + + sb_check (ptr, s->len); + ptr->len += do_scrub_chars (scrub_from_sb, ptr->ptr + ptr->len, s->len); + + sb_to_scrub = 0; + scrub_position = 0; +} + /* make sure that the sb at ptr has room for another len characters, and grow it if it doesn't. */ diff --git a/gas/sb.h b/gas/sb.h index 3394eb6a60c..b4315a95600 100644 --- a/gas/sb.h +++ b/gas/sb.h @@ -82,6 +82,7 @@ extern void sb_build (sb *, int); extern void sb_new (sb *); extern void sb_kill (sb *); extern void sb_add_sb (sb *, sb *); +extern void sb_scrub_and_add_sb (sb *, sb *); extern void sb_reset (sb *); extern void sb_add_char (sb *, int); extern void sb_add_string (sb *, const char *); diff --git a/gas/testsuite/gas/arm/arm.exp b/gas/testsuite/gas/arm/arm.exp index 909fa6bc180..5fb82adaa54 100644 --- a/gas/testsuite/gas/arm/arm.exp +++ b/gas/testsuite/gas/arm/arm.exp @@ -55,6 +55,7 @@ if {[istarget *arm*-*-*] || [istarget "xscale-*-*"]} then { run_dump_test "tcompat" run_dump_test "tcompat2" run_dump_test "iwmmxt" + run_dump_test "macro1" run_errors_test "vfp-bad" "-mfpu=vfp" "VFP errors" run_errors_test "req" "-mcpu=arm7m" ".req errors" diff --git a/gas/testsuite/gas/arm/macro1.d b/gas/testsuite/gas/arm/macro1.d new file mode 100644 index 00000000000..b49f8cb42f0 --- /dev/null +++ b/gas/testsuite/gas/arm/macro1.d @@ -0,0 +1,9 @@ +# name: Macro scrubbing +# as: +# objdump: -dr --prefix-addresses --show-raw-insn + +[^:]+: +file format .*arm.* + +Disassembly of section .text: + +0+0 <[^>]*> e8bd8030 ? ldmia sp!, {r4, r5, pc} diff --git a/gas/testsuite/gas/arm/macro1.s b/gas/testsuite/gas/arm/macro1.s new file mode 100644 index 00000000000..f4ef7a96d88 --- /dev/null +++ b/gas/testsuite/gas/arm/macro1.s @@ -0,0 +1,6 @@ + @ Test that macro expansions are properly scrubbed. + .macro popret regs + ldmia sp!, {\regs, pc} + .endm + .text + popret "r4, r5" diff --git a/gas/testsuite/gas/arm/t16-bad.l b/gas/testsuite/gas/arm/t16-bad.l index 426490fe8a5..64dda5bccd7 100644 --- a/gas/testsuite/gas/arm/t16-bad.l +++ b/gas/testsuite/gas/arm/t16-bad.l @@ -70,7 +70,7 @@ [^:]*:53: Error: unshifted register required -- `sbc r0,#12' [^:]*:53: Error: unshifted register required -- `sbc r0,r1,lsl#2' [^:]*:53: Error: unshifted register required -- `sbc r0,r1,lsl r3' -[^:]*:54: Error: dest and source2 must be the same register -- `mul r1,r2,r3' +[^:]*:54: Error: dest must overlap one source register -- `mul r1,r2,r3' [^:]*:54: Error: lo register required -- `mul r8,r0' [^:]*:54: Error: lo register required -- `mul r0,r8' [^:]*:62: Error: lo register required -- `asr r8,r0,#12' diff --git a/gas/testsuite/gas/arm/tcompat2.d b/gas/testsuite/gas/arm/tcompat2.d index f1303b2dead..9985c336f14 100644 --- a/gas/testsuite/gas/arm/tcompat2.d +++ b/gas/testsuite/gas/arm/tcompat2.d @@ -9,10 +9,14 @@ Disassembly of section .text: 0+00 <[^>]*> 4148 * adcs r0, r1 -0+02 <[^>]*> 4008 * ands r0, r1 -0+04 <[^>]*> 4388 * bics r0, r1 -0+06 <[^>]*> 4048 * eors r0, r1 -0+08 <[^>]*> 4348 * muls r0, r1 -0+0a <[^>]*> 4308 * orrs r0, r1 -0+0c <[^>]*> 4188 * sbcs r0, r1 -0+0e <[^>]*> 46c0 * nop \(mov r8, r8\) +0+02 <[^>]*> 4148 * adcs r0, r1 +0+04 <[^>]*> 4008 * ands r0, r1 +0+06 <[^>]*> 4008 * ands r0, r1 +0+08 <[^>]*> 4048 * eors r0, r1 +0+0a <[^>]*> 4048 * eors r0, r1 +0+0c <[^>]*> 4348 * muls r0, r1 +0+0e <[^>]*> 4348 * muls r0, r1 +0+10 <[^>]*> 4308 * orrs r0, r1 +0+12 <[^>]*> 4308 * orrs r0, r1 +0+14 <[^>]*> 4388 * bics r0, r1 +0+16 <[^>]*> 4188 * sbcs r0, r1 diff --git a/gas/testsuite/gas/arm/tcompat2.s b/gas/testsuite/gas/arm/tcompat2.s index 0175b6e43f4..a9837353fbe 100644 --- a/gas/testsuite/gas/arm/tcompat2.s +++ b/gas/testsuite/gas/arm/tcompat2.s @@ -1,13 +1,27 @@ @ Three-argument forms of Thumb arithmetic instructions. + @ Commutative instructions allow either the second or third + @ operand to equal the first. + .text .global m .thumb_func m: adc r0,r0,r1 + adc r0,r1,r0 + and r0,r0,r1 - bic r0,r0,r1 + and r0,r1,r0 + eor r0,r0,r1 + eor r0,r1,r0 + + mul r0,r0,r1 mul r0,r1,r0 + orr r0,r0,r1 + orr r0,r1,r0 + + bic r0,r0,r1 + sbc r0,r0,r1 - nop + -- 2.39.5