From 2c43c994d8b7f600672d269eb1ee3c60d8e6d86f Mon Sep 17 00:00:00 2001 From: tangxiaolin Date: Fri, 12 Aug 2022 15:59:56 +0800 Subject: [PATCH] LoongArch: gas: add support using variable for li.w/d Macro instruction li.w/d support using variable like ".equ var, 123 li.w/d resgister, var". gas/ * config/loongarch-parse.y * config/tc-loongarch.c Add two testcases. gas/ * testsuite/gas/loongarch/li.d * testsuite/gas/loongarch/li.s * testsuite/gas/loongarch/li2.d * testsuite/gas/loongarch/li2.s --- gas/config/loongarch-parse.y | 18 ++++++++++++++++++ gas/config/tc-loongarch.c | 18 ------------------ gas/testsuite/gas/loongarch/li.d | 14 ++++++++++++++ gas/testsuite/gas/loongarch/li.s | 7 +++++++ gas/testsuite/gas/loongarch/li2.d | 20 ++++++++++++++++++++ gas/testsuite/gas/loongarch/li2.s | 22 ++++++++++++++++++++++ 6 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 gas/testsuite/gas/loongarch/li.d create mode 100644 gas/testsuite/gas/loongarch/li.s create mode 100644 gas/testsuite/gas/loongarch/li2.d create mode 100644 gas/testsuite/gas/loongarch/li2.s diff --git a/gas/config/loongarch-parse.y b/gas/config/loongarch-parse.y index 902d7204e8e5..9048f3256a65 100644 --- a/gas/config/loongarch-parse.y +++ b/gas/config/loongarch-parse.y @@ -100,6 +100,23 @@ my_getExpression (expressionS *ep, const char *str) return ret; } +/* op is var name? */ +static void +emit_const_var (const char *op) +{ + expressionS ep; + if (end <= top) + as_fatal (_("expr too huge")); + my_getExpression(&ep, op); + if (ep.X_op != O_constant) + as_bad("illegal operand: %s", op); + top->value.X_op = O_constant; + top->value.X_add_number = ep.X_add_number; + top->type = BFD_RELOC_LARCH_SOP_PUSH_ABSOLUTE; + top++; +} + + static void reloc (const char *op_c_str, const char *id_c_str, offsetT addend) { @@ -318,6 +335,7 @@ offsetT imm; primary_expression : INTEGER {emit_const ($1);} + | IDENTIFIER {emit_const_var ($1);} | '(' expression ')' | '%' IDENTIFIER '(' IDENTIFIER addend ')' {reloc ($2, $4, $5); free ($2); free ($4);} | '%' IDENTIFIER '(' INTEGER addend ')' {reloc ($2, NULL, $4 + $5); free ($2);} diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index fbbaca550857..963428e95d9e 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -582,24 +582,6 @@ loongarch_args_parser_can_match_arg_helper (char esc_ch1, char esc_ch2, if (!ip->match_now) break; - if (esc_ch1 == 's') - switch (esc_ch2) - { - case 'c': - ip->match_now = reloc_num == 0; - break; - } - else - switch (esc_ch2) - { - case 'c': - ip->match_now = reloc_num == 0 && 0 <= imm; - break; - } - - if (!ip->match_now) - break; - ret = imm; if (reloc_num) { diff --git a/gas/testsuite/gas/loongarch/li.d b/gas/testsuite/gas/loongarch/li.d new file mode 100644 index 000000000000..c856e7650161 --- /dev/null +++ b/gas/testsuite/gas/loongarch/li.d @@ -0,0 +1,14 @@ +#as: +#objdump: -dr + +.*:[ ]+file format .* + + +Disassembly of section .text: + +00000000.* <.text>: +[ ]+0:[ ]+03848c0c[ ]+ori[ ]+\$t0,[ ]+\$zero,[ ]+0x123 +[ ]+4:[ ]+15ffe00d[ ]+lu12i.w[ ]+\$t1,[ ]+-256\(0xfff00\) +[ ]+8:[ ]+16001fed[ ]+lu32i.d[ ]+\$t1,[ ]+255\(0xff\) +[ ]+c:[ ]+02bffc0e[ ]+addi.w[ ]+\$t2,[ ]+\$zero,[ ]+-1\(0xfff\) +[ ]+10:[ ]+1601ffee[ ]+lu32i.d[ ]+\$t2,[ ]+4095\(0xfff\) diff --git a/gas/testsuite/gas/loongarch/li.s b/gas/testsuite/gas/loongarch/li.s new file mode 100644 index 000000000000..30c9a0f25abe --- /dev/null +++ b/gas/testsuite/gas/loongarch/li.s @@ -0,0 +1,7 @@ +.equ a, 0x123 +.equ b, 0xfffff00000 +.equ c, 0xfffffffffff + +li.w $r12, a +li.d $r13, b +li.d $r14, c diff --git a/gas/testsuite/gas/loongarch/li2.d b/gas/testsuite/gas/loongarch/li2.d new file mode 100644 index 000000000000..eae7a2f877ee --- /dev/null +++ b/gas/testsuite/gas/loongarch/li2.d @@ -0,0 +1,20 @@ +#as: +#objdump: -dr + +.*:[ ]+file format .* + + +Disassembly of section .text: + +00000000.* <_start>: +[ ]+0:[ ]+03803c06[ ]+ori[ ]+\$a2,[ ]+\$zero,[ ]+0xf +[ ]+4:[ ]+1a000005[ ]+pcalau12i[ ]+\$a1,[ ]+0 +[ ]+4:[ ]+R_LARCH_PCALA_HI20[ ]+.rodata +[ ]+8:[ ]+02c000a5[ ]+addi.d[ ]+\$a1,[ ]+\$a1,[ ]+0 +[ ]+8:[ ]+R_LARCH_PCALA_LO12[ ]+.rodata +[ ]+c:[ ]+03800404[ ]+ori[ ]+\$a0,[ ]+\$zero,[ ]+0x1 +[ ]+10:[ ]+0381000b[ ]+ori[ ]+\$a7,[ ]+\$zero,[ ]+0x40 +[ ]+14:[ ]+002b0000[ ]+syscall[ ]+0x0 +[ ]+18:[ ]+00150004[ ]+move[ ]+\$a0,[ ]+\$zero +[ ]+1c:[ ]+0381740b[ ]+ori[ ]+\$a7,[ ]+\$zero,[ ]+0x5d +[ ]+20:[ ]+002b0000[ ]+syscall[ ]+0x0 diff --git a/gas/testsuite/gas/loongarch/li2.s b/gas/testsuite/gas/loongarch/li2.s new file mode 100644 index 000000000000..e95a527fc107 --- /dev/null +++ b/gas/testsuite/gas/loongarch/li2.s @@ -0,0 +1,22 @@ +.equ EXIT_SUCCESS, 0 +.equ STDOUT, 1 +.equ SYS_exit, 93 +.equ SYS_write, 64 + +.section .rodata +msg: + .string "hello, world!\n" + len = . - msg + +.text + .globl _start +_start: + li.w $a2, len + la.local $a1, msg + li.w $a0, STDOUT + li.w $a7, SYS_write + syscall 0x0 + + li.w $a0, EXIT_SUCCESS + li.w $a7, SYS_exit + syscall 0x0