From b77a133c96560fe3709d191aebc5337b766ffb28 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 3 Apr 2000 14:17:43 +0000 Subject: Tidy some code. Print pc rel addresses as signed. --- opcodes/ChangeLog | 6 ++++ opcodes/avr-dis.c | 83 +++++++++++++++---------------------------------------- 2 files changed, 29 insertions(+), 60 deletions(-) diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index c6d1fea..8df6679 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,9 @@ +2000-04-03 Denis Chertykov + + * avr-dis.c: Syntax cleanup. + (add0fff): Print the pc relative address as a signed number. + (add03f8): Likewise. + 2000-04-01 Ian Lance Taylor * disassemble.c (disassembler_usage): Don't use a prototype. Mark diff --git a/opcodes/avr-dis.c b/opcodes/avr-dis.c index 2d7eb94..7876686 100644 --- a/opcodes/avr-dis.c +++ b/opcodes/avr-dis.c @@ -26,7 +26,6 @@ typedef unsigned short u16; typedef unsigned long u32; #define IFMASK(a,b) ((opcode & (a)) == (b)) -#define CODE_MAX 65537 static char* SREG_flags = "CZNVSHTI"; static char* sect94[] = {"COM","NEG","SWAP","INC","NULL","ASR","LSR","ROR", @@ -38,8 +37,8 @@ static char* branchs[] = { "BRCC","BRNE","BRPL","BRVC", "BRGE","BRHC","BRTC","BRID" }; -static char* last4[] = {"BLD","BST","SBRC","SBRS"}; +static char* last4[] = {"BLD","BST","SBRC","SBRS"}; static void dispLDD PARAMS ((u16, char *)); @@ -147,8 +146,8 @@ add0fff (op, dest, pc) char *dest; int pc; { - int opcode = op & 0x0fff; - sprintf(dest, ".%+-8d ; 0x%06X", opcode * 2, pc + 2 + opcode * 2); + int rel_addr = (((op & 0xfff) ^ 0x800) - 0x800) * 2; + sprintf(dest, ".%+-8d ; 0x%06X", rel_addr, pc + 2 + rel_addr); } @@ -160,8 +159,8 @@ add03f8 (op, dest, pc) char *dest; int pc; { - int opcode = (op >> 3) & 0x7f; - sprintf(dest, ".%+-8d ; 0x%06X", opcode * 2, pc + 2 + opcode * 2); + int rel_addr = ((((op >> 3) & 0x7f) ^ 0x40) - 0x40) * 2; + sprintf(dest, ".%+-8d ; 0x%06X", rel_addr, pc + 2 + rel_addr); } @@ -331,49 +330,31 @@ print_insn_avr(addr, info) } break; case 0x1: - { - (*prin) (stream, " LD %s,Z+", rd); - } + (*prin) (stream, " LD %s,Z+", rd); break; case 0x2: - { - (*prin) (stream, " LD %s,-Z", rd); - } + (*prin) (stream, " LD %s,-Z", rd); break; case 0x9: - { - (*prin) (stream, " LD %s,Y+", rd); - } + (*prin) (stream, " LD %s,Y+", rd); break; case 0xa: - { - (*prin) (stream, " LD %s,-Y", rd); - } + (*prin) (stream, " LD %s,-Y", rd); break; case 0xc: - { - (*prin) (stream, " LD %s,X", rd); - } + (*prin) (stream, " LD %s,X", rd); break; case 0xd: - { - (*prin) (stream, " LD %s,X+", rd); - } + (*prin) (stream, " LD %s,X+", rd); break; case 0xe: - { - (*prin) (stream, " LD %s,-X", rd); - } + (*prin) (stream, " LD %s,-X", rd); break; case 0xf: - { - (*prin) (stream, " POP %s", rd); - } + (*prin) (stream, " POP %s", rd); break; default: - { - (*prin) (stream, " ????"); - } + (*prin) (stream, " ????"); break; } } @@ -391,49 +372,31 @@ print_insn_avr(addr, info) } break; case 0x1: - { - (*prin) (stream, " ST Z+,%s", rd); - } + (*prin) (stream, " ST Z+,%s", rd); break; case 0x2: - { - (*prin) (stream, " ST -Z,%s", rd); - } + (*prin) (stream, " ST -Z,%s", rd); break; case 0x9: - { - (*prin) (stream, " ST Y+,%s", rd); - } + (*prin) (stream, " ST Y+,%s", rd); break; case 0xa: - { - (*prin) (stream, " ST -Y,%s", rd); - } + (*prin) (stream, " ST -Y,%s", rd); break; case 0xc: - { - (*prin) (stream, " ST X,%s", rd); - } + (*prin) (stream, " ST X,%s", rd); break; case 0xd: - { - (*prin) (stream, " ST X+,%s", rd); - } + (*prin) (stream, " ST X+,%s", rd); break; case 0xe: - { - (*prin) (stream, " ST -X,%s", rd); - } + (*prin) (stream, " ST -X,%s", rd); break; case 0xf: - { - (*prin) (stream, " PUSH %s", rd); - } + (*prin) (stream, " PUSH %s", rd); break; default: - { - (*prin) (stream, " ????"); - } + (*prin) (stream, " ????"); break; } } -- cgit v1.1