From baab44f9f58315c1d365bce9933e221331380816 Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Tue, 16 Jul 2024 22:21:26 +0100 Subject: [PATCH] Provide avr_opcodes[] table --- src/CMakeLists.txt | 3 +- src/Makefile.am | 3 +- src/avr_opcodes.c | 199 +++++++++++++ src/disasm.c | 74 +++-- src/disasm_callbacks_assembly.c | 371 +++++++++++++------------ src/disasm_callbacks_assembly.h | 292 +++++++++---------- src/disasm_callbacks_pseudocode.c | 173 ++++++------ src/disasm_callbacks_pseudocode.h | 158 +++++------ src/disasm_globals.h | 140 +--------- src/disasm_jumpcall.c | 5 +- src/disasm_mnemonics.c | 447 ------------------------------ src/disasm_mnemonics.h | 29 -- src/libavrdude.h | 69 ++++- 13 files changed, 819 insertions(+), 1144 deletions(-) create mode 100644 src/avr_opcodes.c delete mode 100644 src/disasm_mnemonics.c delete mode 100644 src/disasm_mnemonics.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index abab7c60..287bd927 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -166,6 +166,7 @@ add_library(libavrdude avrftdi_tpi.h avrintel.c libavrdude-avrintel.h + avr_opcodes.c avrpart.c bitbang.c bitbang.h @@ -190,8 +191,6 @@ add_library(libavrdude disasm_ioregisters.h disasm_jumpcall.c disasm_jumpcall.h - disasm_mnemonics.c - disasm_mnemonics.h disasm_tagfile.c disasm_tagfile.h dfu.c diff --git a/src/Makefile.am b/src/Makefile.am index f0b76811..a7fb916b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -105,6 +105,7 @@ libavrdude_a_SOURCES = \ avrintel.c \ libavrdude-avrintel.h \ avrpart.c \ + avr_opcodes.c \ bitbang.c \ bitbang.h \ buspirate.c \ @@ -128,8 +129,6 @@ libavrdude_a_SOURCES = \ disasm_ioregisters.h \ disasm_jumpcall.c \ disasm_jumpcall.h \ - disasm_mnemonics.c \ - disasm_mnemonics.h \ disasm_tagfile.c \ disasm_tagfile.h \ dfu.c \ diff --git a/src/avr_opcodes.c b/src/avr_opcodes.c new file mode 100644 index 00000000..07089cce --- /dev/null +++ b/src/avr_opcodes.c @@ -0,0 +1,199 @@ +/* + * AVRDUDE - A Downloader/Uploader for AVR device programmers + * Copyright (C) 2024 Stefan Rueger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "libavrdude.h" + +const AVR_opcode_data avr_opcodes[164] = { + // Arithmetic and Logic Instructions + {0xfc00, 0x0c00, 1, "0000 11rd dddd rrrr", OPCODE_add, "ADD", "Rd, Rr", "Add without Carry", "Rd <-- Rd+Rr", "Z,C,N,V,S,H", "1", "1", "1", "1", "", ""}, + {0xfc00, 0x1c00, 1, "0001 11rd dddd rrrr", OPCODE_adc, "ADC", "Rd, Rr", "Add with Carry", "Rd <-- Rd+Rr+C", "Z,C,N,V,S,H", "1", "1", "1", "1", "", ""}, + {0xff00, 0x9600, 1, "1001 0110 KKdd KKKK", OPCODE_adiw, "ADIW", "Rd, K", "Add Immediate to Word", "Rd <-- Rd+1:Rd+K", "Z,C,N,V,S", "2", "2", "2", "n/a", "(1)", "d in {24, 26, 28, 30}"}, + {0xfc00, 0x1800, 1, "0001 10rd dddd rrrr", OPCODE_sub, "SUB", "Rd, Rr", "Subtract without Carry", "Rd <-- Rd-Rr", "Z,C,N,V,S,H", "1", "1", "1", "1", "", ""}, + {0xf000, 0x5000, 1, "0101 KKKK dddd KKKK", OPCODE_subi, "SUBI", "Rd, K", "Subtract Immediate", "Rd <-- Rd-K", "Z,C,N,V,S,H", "1", "1", "1", "1", "", ""}, + {0xfc00, 0x0800, 1, "0000 10rd dddd rrrr", OPCODE_sbc, "SBC", "Rd, Rr", "Subtract with Carry", "Rd <-- Rd-Rr-C", "Z,C,N,V,S,H", "1", "1", "1", "1", "", ""}, + {0xf000, 0x4000, 1, "0100 KKKK dddd KKKK", OPCODE_sbci, "SBCI", "Rd, K", "Subtract Immediate with Carry", "Rd <-- Rd-K-C", "Z,C,N,V,S,H", "1", "1", "1", "1", "", "d=16..31"}, + {0xff00, 0x9700, 1, "1001 0111 KKdd KKKK", OPCODE_sbiw, "SBIW", "Rd, K", "Subtract Immediate from Word", "Rd+1:Rd <-- Rd+1:Rd-K", "Z,C,N,V,S", "2", "2", "2", "n/a", "(1)", "d in {24, 26, 28, 30}"}, + {0xfc00, 0x2000, 1, "0010 00rd dddd rrrr", OPCODE_and, "AND", "Rd, Rr", "Logical AND", "Rd <-- Rd & Rr", "Z,N,V,S", "1", "1", "1", "1", "", ""}, + {0xf000, 0x7000, 1, "0111 KKKK dddd KKKK", OPCODE_andi, "ANDI", "Rd, K", "Logical AND with Immediate", "Rd <-- Rd & K", "Z,N,V,S", "1", "1", "1", "1", "", "d = 16..31"}, + {0xfc00, 0x2800, 1, "0010 10rd dddd rrrr", OPCODE_or, "OR", "Rd, Rr", "Logical OR", "Rd <-- Rd|Rr", "Z,N,V,S", "1", "1", "1", "1", "", ""}, + {0xf000, 0x6000, 1, "0110 KKKK dddd KKKK", OPCODE_ori, "ORI", "Rd, K", "Logical OR with Immediate", "Rd <-- Rd|K", "Z,N,V,S", "1", "1", "1", "1", "", ""}, + {0xfc00, 0x2400, 1, "0010 01rd dddd rrrr", OPCODE_eor, "EOR", "Rd, Rr", "Exclusive OR", "Rd <-- Rd^Rr", "Z,N,V,S", "1", "1", "1", "1", "", ""}, + {0xfe0f, 0x9400, 1, "1001 010d dddd 0000", OPCODE_com, "COM", "Rd", "One's Complement", "Rd <-- $FF-Rd", "Z,C,N,V,S", "1", "1", "1", "1", "", ""}, + {0xfe0f, 0x9401, 1, "1001 010d dddd 0001", OPCODE_neg, "NEG", "Rd", "Two's Complement", "Rd <-- $00-Rd", "Z,C,N,V,S,H", "1", "1", "1", "1", "", ""}, + {0xf000, 0x6000, 1, "0110 KKKK dddd KKKK", OPCODE_sbr, "SBR", "Rd, K", "Set Bit(s) in Register", "Rd <-- Rd or K", "Z,N,V,S", "1", "1", "1", "1", "", "alias for ORI Rd, K"}, + {0xf000, 0x7000, 1, "0111 KKKK dddd KKKK", OPCODE_cbr, "CBR", "Rd, K", "Clear Bit(s) in Register", "Rd <-- Rd & ($FFh-K)", "Z,N,V,S", "1", "1", "1", "1", "", "alias for ANDI Rd, (0xFF - K)"}, + {0xfe0f, 0x9403, 1, "1001 010d dddd 0011", OPCODE_inc, "INC", "Rd", "Increment", "Rd <-- Rd+1", "Z,N,V,S", "1", "1", "1", "1", "", ""}, + {0xfe0f, 0x940a, 1, "1001 010d dddd 1010", OPCODE_dec, "DEC", "Rd", "Decrement", "Rd <-- Rd-1", "Z,N,V,S", "1", "1", "1", "1", "", ""}, + {0xfc00, 0x2000, 1, "0010 00dd dddd dddd", OPCODE_tst, "TST", "Rd", "Test for Zero or Minus", "Rd <-- Rd & Rd", "Z,N,V,S", "1", "1", "1", "1", "", "alias for AND Rd, Rd"}, + {0xfc00, 0x2400, 1, "0010 01dd dddd dddd", OPCODE_clr, "CLR", "Rd", "Clear Register", "Rd <-- Rd xor Rd", "Z,N,V,S", "1", "1", "1", "1", "", "alias for EOR Rd, Rd"}, + {0xff0f, 0xef0f, 1, "1110 1111 dddd 1111", OPCODE_ser, "SER", "Rd", "Set Register", "Rd <-- $FF", "None", "1", "1", "1", "1", "", "alias for LDI Rd, 0xFF"}, + {0xfc00, 0x9c00, 1, "1001 11rd dddd rrrr", OPCODE_mul, "MUL", "Rd, Rr", "Multiply Unsigned", "R1:R0 <-- Rd x Rr (UU)", "Z,C", "2", "2", "2", "n/a", "(1)", ""}, + {0xff00, 0x0200, 1, "0000 0010 dddd rrrr", OPCODE_muls, "MULS", "Rd, Rr", "Multiply Signed", "R1:R0 <-- Rd x Rr (SS)", "Z,C", "2", "2", "2", "n/a", "(1)", "d, r=16..31"}, + {0xff88, 0x0300, 1, "0000 0011 0ddd 0rrr", OPCODE_mulsu, "MULSU", "Rd, Rr", "Multiply Signed with Unsigned", "R1:R0 <-- Rd x Rr (SU)", "Z,C", "2", "2", "2", "n/a", "(1)", "d, r=16..23"}, + {0xff88, 0x0308, 1, "0000 0011 0ddd 1rrr", OPCODE_fmul, "FMUL", "Rd, Rr", "Fractional Multiply Unsigned", "R1:R0 <-- Rd x Rr<<1 (UU)", "Z,C", "2", "2", "2", "n/a", "(1) ", "r, d = 16..23"}, + {0xff88, 0x0380, 1, "0000 0011 1ddd 0rrr", OPCODE_fmuls, "FMULS", "Rd, Rr", "Fractional Multiply Signed", "R1:R0 <-- Rd x Rr<<1 (SS)", "Z,C", "2", "2", "2", "n/a", "(1) ", "r, d = 16..23"}, + {0xff88, 0x0388, 1, "0000 0011 1ddd 1rrr", OPCODE_fmulsu, "FMULSU", "Rd, Rr", "Fractional Multiply Signed with Unsigned", "R1:R0 <-- Rd x Rr<<1 (SU)", "Z,C", "2", "2", "2", "n/a", "(1) ", "r, d = 16..23"}, + {0xff0f, 0x940b, 1, "1001 0100 KKKK 1011", OPCODE_des, "DES", "K", "Data Encryption", "if (H = 0) then R15:R0 <-- Encrypt(R15:R0, K) if (H = 1) then R15:R0 <-- Decrypt(R15:R0, K)", "-", "n/a", "1/2", "n/a", "n/a", "", ""}, + + // Branch Instructions + {0xf000, 0xc000, 1, "1100 kkkk kkkk kkkk", OPCODE_rjmp, "RJMP", "k", "Relative Jump", "PC <-- PC+k+1", "None", "2", "2", "2", "2", "", ""}, + {0xffff, 0x9409, 1, "1001 0100 0000 1001", OPCODE_ijmp, "IJMP", "Z", "Indirect Jump to (Z)", "PC(15:0) <-- Z, PC(21:16) <-- 0", "None", "2", "2", "2", "2", "(1)", ""}, + {0xffff, 0x9419, 1, "1001 0100 0001 1001", OPCODE_eijmp, "EIJMP", "EIND:Z", "Extended Indirect Jump to (Z)", "PC(15:0) <-- Z, PC(21:16) <-- EIND", "None", "2", "2", "2", "n/a", "(1)", ""}, + {0xfe0e, 0x940c, 2, "1001 010k kkkk 110k kkkk kkkk kkkk kkkk", OPCODE_jmp, "JMP", "k", "Jump", "PC <-- k", "None", "3", "3", "3", "n/a", "(1)", ""}, + {0xf000, 0xd000, 1, "1101 kkkk kkkk kkkk", OPCODE_rcall, "RCALL", "k", "Relative Call Subroutine", "PC <-- PC+k+1", "None", "3/4", "2/3", "2/3", "3", "", ""}, + {0xffff, 0x9509, 1, "1001 0101 0000 1001", OPCODE_icall, "ICALL", "Z", "Indirect Call to (Z)", "PC(15:0) <-- Z, PC(21:16) <-- 0", "None", "3/4", "2/3", "2/3", "3", "(1)", ""}, + {0xffff, 0x9519, 1, "1001 0101 0001 1001", OPCODE_eicall, "EICALL", "EIND:Z", "Extended Indirect Call to (Z)", "PC(15:0) <-- Z, PC(21:16) <-- EIND", "None", "4", "3", "3", "n/a", "(1)", ""}, + {0xfe0e, 0x940e, 2, "1001 010k kkkk 111k kkkk kkkk kkkk kkkk", OPCODE_call, "CALL", "k", "call Subroutine", "PC <-- k, STACK <-- PC, SP <-- SP-2", "None", "4/5", "3/4", "3/4", "n/a", "(1)", ""}, + {0xffff, 0x9508, 1, "1001 0101 0000 1000", OPCODE_ret, "RET", "-", "Subroutine Return", "PC <-- STACK", "None", "4/5", "4/5", "4/5", "6", "", ""}, + {0xffff, 0x9518, 1, "1001 0101 0001 1000", OPCODE_reti, "RETI", "-", "Interrupt Return", "PC <-- STACK", "I", "4/5", "4/5", "4/5", "6", "", ""}, + {0xfc00, 0x1000, 1, "0001 00rd dddd rrrr", OPCODE_cpse, "CPSE", "Rd, Rr", "Compare, Skip if Equal", "if(Rd=Rr)PC <-- PC+2or3", "None", "1/2/3", "1/2/3", "1/2/3", "1/2", "", ""}, + {0xfc00, 0x1400, 1, "0001 01rd dddd rrrr", OPCODE_cp, "CP", "Rd, Rr", "Compare", "Rd - Rr", "Z,C,N,V,S,H", "1", "1", "1", "1", "", ""}, + {0xfc00, 0x0400, 1, "0000 01rd dddd rrrr", OPCODE_cpc, "CPC", "Rd, Rr", "Compare with Carry", "Rd - Rr - C", "Z,C,N,V,S,H", "1", "1", "1", "1", "", ""}, + {0xf000, 0x3000, 1, "0011 KKKK dddd KKKK", OPCODE_cpi, "CPI", "Rd, K", "Compare with Immediate", "Rd - K", "Z,C,N,V,S,H", "1", "1", "1", "1", "", "d = 16..31"}, + {0xfe08, 0xfc00, 1, "1111 110r rrrr 0bbb", OPCODE_sbrc, "SBRC", "Rr, b", "Skip if Bit in Register Cleared", "if(Rr(b)=0)PC <-- PC+2or3", "None", "1/2/3", "1/2/3", "1/2/3", "1/2", "", ""}, + {0xfe08, 0xfe00, 1, "1111 111r rrrr 0bbb", OPCODE_sbrs, "SBRS", "Rr, b", "Skip if Bit in Register Set", "if(Rr(b)=1)PC <-- PC+2or3", "None", "1/2/3", "1/2/3", "1/2/3", "1/2", "", ""}, + {0xff00, 0x9900, 1, "1001 1001 AAAA Abbb", OPCODE_sbic, "SBIC", "A, b", "Skip if Bit in I/O Register Cleared", "if(I/O(A,b)=0)PC <-- PC+2or3", "None", "1/2/3", "2/3/4", "1/2/3", "1/2", "", ""}, + {0xff00, 0x9b00, 1, "1001 1011 AAAA Abbb", OPCODE_sbis, "SBIS", "A, b", "Skip if Bit in I/O Register Set", "If(I/O(A,b)=1)PC <-- PC+2or3", "None", "1/2/3", "2/3/4", "1/2/3", "1/2", "", ""}, + {0xfc07, 0xf000, 1, "1111 00kk kkkk k000", OPCODE_brcs, "BRCS", "k", "Branch if Carry Set", "if(C=1)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBS 0, k (C Carry)"}, + {0xfc07, 0xf000, 1, "1111 00kk kkkk k000", OPCODE_brlo, "BRLO", "k", "Branch if Lower", "if(C=1)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBS 0, k (C Carry)"}, + {0xfc07, 0xf001, 1, "1111 00kk kkkk k001", OPCODE_breq, "BREQ", "k", "Branch if Equal", "if(Z=1)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBS 1, k (Z Zero)"}, + {0xfc07, 0xf002, 1, "1111 00kk kkkk k010", OPCODE_brmi, "BRMI", "k", "Branch if Minus", "if(N=1)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBS 2, k (N Negative)"}, + {0xfc07, 0xf003, 1, "1111 00kk kkkk k011", OPCODE_brvs, "BRVS", "k", "Branch if Overflow Flag is Set", "if(V=1)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBS 3, k (V Overflow in two's complement)"}, + {0xfc07, 0xf004, 1, "1111 00kk kkkk k100", OPCODE_brlt, "BRLT", "k", "Branch if Less Than, Signed", "if(N^V=1)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBS 4, k (S Sign)"}, + {0xfc07, 0xf005, 1, "1111 00kk kkkk k101", OPCODE_brhs, "BRHS", "k", "Branch if Half Carry Flag Set", "if(H=1)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBS 5, k (H Half carry)"}, + {0xfc07, 0xf006, 1, "1111 00kk kkkk k110", OPCODE_brts, "BRTS", "k", "Branch if T Flag Set", "if(T=1)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBS 6, k (T Transfer bit)"}, + {0xfc07, 0xf007, 1, "1111 00kk kkkk k111", OPCODE_brie, "BRIE", "k", "Branch if Interrupt Enabled", "if(I=1)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBS 7, k (I Interrupt enable)"}, + {0xfc00, 0xf000, 1, "1111 00kk kkkk ksss", OPCODE_brbs, "BRBS", "s, k", "Branch if Status Flag Set", "if(SREG(s)=1)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", ""}, + {0xfc07, 0xf400, 1, "1111 01kk kkkk k000", OPCODE_brcc, "BRCC", "k", "Branch if Carry Cleared", "if(C=0)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBC 0, k (C Carry)"}, + {0xfc07, 0xf400, 1, "1111 01kk kkkk k000", OPCODE_brsh, "BRSH", "k", "Branch if Same or Higher", "if(C=0)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBC 0, k (C Carry)"}, + {0xfc07, 0xf401, 1, "1111 01kk kkkk k001", OPCODE_brne, "BRNE", "k", "Branch if Not Equal", "if(Z=0)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBC 1, k (Z Zero)"}, + {0xfc07, 0xf402, 1, "1111 01kk kkkk k010", OPCODE_brpl, "BRPL", "k", "Branch if Plus", "if(N=0)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBC 2, k (N Negative)"}, + {0xfc07, 0xf403, 1, "1111 01kk kkkk k011", OPCODE_brvc, "BRVC", "k", "Branch if Overflow Flag is Cleared", "if(V=0)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBC 3, k (V Overflow in two's complement)"}, + {0xfc07, 0xf404, 1, "1111 01kk kkkk k100", OPCODE_brge, "BRGE", "k", "Branch if Greater or Equal, Signed", "if(N^V=0)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBC 4, k (S Sign)"}, + {0xfc07, 0xf405, 1, "1111 01kk kkkk k101", OPCODE_brhc, "BRHC", "k", "Branch if Half Carry Flag Cleared", "if(H=0)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBC 5, k (H Half carry)"}, + {0xfc07, 0xf406, 1, "1111 01kk kkkk k110", OPCODE_brtc, "BRTC", "k", "Branch if T Flag Cleared", "if(T=0)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBC 6, k (T Transfer bit)"}, + {0xfc07, 0xf407, 1, "1111 01kk kkkk k111", OPCODE_brid, "BRID", "k", "Branch if Interrupt Disabled", "if(I=0)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", "alias for BRBC 7, k (I Interrupt enable)"}, + {0xfc00, 0xf400, 1, "1111 01kk kkkk ksss", OPCODE_brbc, "BRBC", "s, k", "Branch if Status Flag Cleared", "if(SREG(s)=0)thenPC <-- PC+k+1", "None", "1/2", "1/2", "1/2", "1/2", "", ""}, + + // Data Transfer Instructions + {0xfc00, 0x2c00, 1, "0010 11rd dddd rrrr", OPCODE_mov, "MOV", "Rd, Rr", "Copy Register", "Rd <-- Rr", "None", "1", "1", "1", "1", "", ""}, + {0xff00, 0x0100, 1, "0000 0001 dddd rrrr", OPCODE_movw, "MOVW", "Rd, Rr", "Copy Register Pair", "Rd+1:Rd <-- Rr+1:Rr", "None", "1", "1", "1", "n/a", "(1)", ""}, + {0xf000, 0xe000, 1, "1110 KKKK dddd KKKK", OPCODE_ldi, "LDI", "Rd, K", "Load Immediate", "Rd <-- K", "None", "1", "1", "1", "1", "", "d=16..31"}, + {0xfe0f, 0x9000, 2, "1001 000d dddd 0000 kkkk kkkk kkkk kkkk", OPCODE_lds, "LDS", "Rd, k", "Load Direct from data space", "Rd <-- (k)", "None", "2", "3", "3", "2", "(1)", ""}, + {0xf800, 0xa000, 1, "1010 0kkk dddd kkkk", OPCODE_lds_rc, "LDS", "Rd, k", "Load Direct from data space", "Rd <-- (k)", "None", "n/a", "n/a", "n/a", "2", "(1)", "attiny only"}, + {0xfe0f, 0x900c, 1, "1001 000d dddd 1100", OPCODE_ld_1, "LD", "Rd, X", "Load Indirect", "Rd <-- (X)", "None", "2", "2", "2", "1/2", "(2)", ""}, + {0xfe0f, 0x900d, 1, "1001 000d dddd 1101", OPCODE_ld_2, "LD", "Rd, X+", "Load Indirect and Post-Increment", "Rd <-- (X) X <-- X+1", "None", "2", "2", "2", "2/3", "(2)", ""}, + {0xfe0f, 0x900e, 1, "1001 000d dddd 1110", OPCODE_ld_3, "LD", "Rd, -X", "Load Indirect and Pre-Decrement", "X <-- X-1, <-- X-1 Rd <-- (X) <-- (X)", "None", "2", "3", "2", "2/3", "(2)", ""}, + {0xfe0f, 0x8008, 1, "1000 000d dddd 1000", OPCODE_ld_4, "LD", "Rd, Y", "Load Indirect", "Rd <-- (Y) <-- (Y)", "None", "2", "2", "2", "1/2", "(2)", "alias for LDD Rd, Y+0"}, + {0xfe0f, 0x9009, 1, "1001 000d dddd 1001", OPCODE_ld_5, "LD", "Rd, Y+", "Load Indirect and Post-Increment", "Rd <-- (Y) Y <-- Y+1", "None", "2", "2", "2", "2/3", "(2)", ""}, + {0xfe0f, 0x900a, 1, "1001 000d dddd 1010", OPCODE_ld_6, "LD", "Rd, -Y", "Load Indirect and Pre-Decrement", "Y <-- Y-1 Rd <-- (Y)", "None", "2", "3", "2", "2/3", "(2)", ""}, + {0xd208, 0x8008, 1, "10q0 qq0d dddd 1qqq", OPCODE_ldd_1, "LDD", "Rd, Y+q", "Load Indirect with Displacement", "Rd <-- (Y+q)", "None", "2", "3", "2", "n/a", "(1)", ""}, + {0xfe0f, 0x8000, 1, "1000 000d dddd 0000", OPCODE_ld_7, "LD", "Rd, Z", "Load Indirect", "Rd <-- (Z)", "None", "2", "2", "2", "1/2", "(2)", "alias for LDD Rd,Z+0"}, + {0xfe0f, 0x9001, 1, "1001 000d dddd 0001", OPCODE_ld_8, "LD", "Rd, Z+", "Load Indirect and Post-Increment", "Rd <-- (Z), Z <-- Z+1", "None", "2", "2", "2", "2/3", "(2)", ""}, + {0xfe0f, 0x9002, 1, "1001 000d dddd 0010", OPCODE_ld_9, "LD", "Rd, -Z", "Load Indirect and Pre-Decrement", "Z <-- Z-1, Rd <-- (Z)", "None", "2", "3", "2", "2/3", "(2)", ""}, + {0xd208, 0x8000, 1, "10q0 qq0d dddd 0qqq", OPCODE_ldd_2, "LDD", "Rd, Z+q", "Load Indirect with Displacement", "Rd <-- (Z+q)", "None", "2", "3", "2", "n/a", "(1)", ""}, + {0xfe0f, 0x9200, 2, "1001 001d dddd 0000 kkkk kkkk kkkk kkkk", OPCODE_sts, "STS", "k, Rr", "Store Direct to Data Space", "(k) <-- Rd", "None", "2", "2", "2", "1", "(1)", ""}, + {0xf800, 0xa800, 1, "1010 1kkk dddd kkkk", OPCODE_sts_rc, "STS", "k, Rr", "Store Direct to Data Space", "(k) <-- Rd", "None", "n/a", "n/a", "n/a", "1", "(1)", "attiny only"}, + {0xfe0f, 0x920c, 1, "1001 001r rrrr 1100", OPCODE_st_1, "ST", "X, Rr", "Store Indirect", "(X) <-- Rr", "None", "2", "1", "1", "1", "(2)", ""}, + {0xfe0f, 0x920d, 1, "1001 001r rrrr 1101", OPCODE_st_2, "ST", "X+, Rr", "Store Indirect and Post-Increment", "(X) <-- Rr, X <-- X+1", "None", "2", "1", "1", "1", "(2)", ""}, + {0xfe0f, 0x920e, 1, "1001 001r rrrr 1110", OPCODE_st_3, "ST", "-X, Rr", "Store Indirect and Pre-Decrement", "X <-- X-1, (X) <-- Rr", "None", "2", "2", "1", "1", "(2)", ""}, + {0xfe0f, 0x8208, 1, "1000 001r rrrr 1000", OPCODE_st_4, "ST", "Y, Rr", "Store Indirect", "(Y) <-- Rr", "None", "2", "1", "1", "1", "(2)", "alias for STD Y+0, Rr"}, + {0xfe0f, 0x9209, 1, "1001 001r rrrr 1001", OPCODE_st_5, "ST", "Y+, Rr", "Store Indirect and Post-Increment", "(Y) <-- Rr, Y <-- Y+1", "None", "2", "1", "1", "1", "(2)", ""}, + {0xfe0f, 0x920a, 1, "1001 001r rrrr 1010", OPCODE_st_6, "ST", "-Y, Rr", "Store Indirect and Pre-Decrement", "Y <-- Y-1, (Y) <-- Rr", "None", "2", "2", "1", "1", "(2)", ""}, + {0xd208, 0x8208, 1, "10q0 qq1r rrrr 1qqq", OPCODE_std_1, "STD", "Y+q, Rr", "Store Indirect with Displacement", "(Y+q) <-- Rr", "None", "2", "2", "1", "n/a", "(1)", ""}, + {0xfe0f, 0x8200, 1, "1000 001r rrrr 0000", OPCODE_st_7, "ST", "Z, Rr", "Store Indirect", "(Z) <-- Rr", "None", "2", "1", "1", "1", "(2)", "alias for STD Z+0, Rr"}, + {0xfe0f, 0x9201, 1, "1001 001r rrrr 0001", OPCODE_st_8, "ST", "Z+, Rr", "Store Indirect and Post-Increment", "(Z) <-- Rr Z <-- Z+1", "None", "2", "1", "1", "1", "(2)", ""}, + {0xfe0f, 0x9202, 1, "1001 001r rrrr 0010", OPCODE_st_9, "ST", "-Z, Rr", "Store Indirect and Pre-Decrement", "Z <-- Z-1", "None", "2", "2", "1", "1", "(2)", ""}, + {0xd208, 0x8200, 1, "10q0 qq1r rrrr 0qqq", OPCODE_std_2, "STD", "Z+q, Rr", "Store Indirect with Displacement", "(Z+q) <-- Rr", "None", "2", "2", "1", "n/a", "(1)", ""}, + {0xffff, 0x95c8, 1, "1001 0101 1100 1000", OPCODE_lpm_1, "LPM", "-", "Load Program Memory", "R0 <-- (Z)", "None", "3", "3", "3", "n/a", "(1)(2)", ""}, + {0xfe0f, 0x9004, 1, "1001 000d dddd 0100", OPCODE_lpm_2, "LPM", "Rd, Z", "Load Program Memory", "Rd <-- (Z)", "None", "3", "3", "3", "n/a", "(1)(2)", ""}, + {0xfe0f, 0x9005, 1, "1001 000d dddd 0101", OPCODE_lpm_3, "LPM", "Rd, Z+", "Load Program Memory and Post- Increment", "Rd <-- (Z), Z <-- Z+1", "None", "3", "3", "3", "n/a", "(1)(2)", ""}, + {0xffff, 0x95d8, 1, "1001 0101 1101 1000", OPCODE_elpm_1, "ELPM", "R0, Z", "Extended Load Program Memory", "R0 <-- (RAMPZ:Z)", "None", "3", "3", "3", "n/a", "(1)", ""}, + {0xfe0f, 0x9006, 1, "1001 000d dddd 0110", OPCODE_elpm_2, "ELPM", "Rd, Z", "Extended Load Program Memory", "Rd <-- (RAMPZ:Z)", "None", "3", "3", "3", "n/a", "(1)", ""}, + {0xfe0f, 0x9007, 1, "1001 000d dddd 0111", OPCODE_elpm_3, "ELPM", "Rd, Z+", "Extended Load Program Memory and Post-Increment", "Rd <-- (RAMPZ:Z), Z <-- Z+1", "None", "3", "3", "3", "n/a", "(1)", ""}, + {0xffff, 0x95e8, 1, "1001 0101 1110 1000", OPCODE_spm, "SPM", "Z", "Store Program Memory", "(RAMPZ:Z) <-- R1:R0", "None", "-", "-", "-", "-", "(1)", ""}, + {0xffff, 0x95f8, 1, "1001 0101 1111 1000", OPCODE_spm_zz, "SPM", "Z+", "Store Program Memory and Post- Increment by 2", "(RAMPZ:Z) <-- R1:R0, Z <-- Z+2", "None", "n/a", "-", "-", "n/a", "(1)", ""}, + {0xf800, 0xb000, 1, "1011 0AAd dddd AAAA", OPCODE_in, "IN", "Rd, A", "In From I/O Location", "Rd <-- I/O(A)", "None", "1", "1", "1", "1", "", ""}, + {0xf800, 0xb800, 1, "1011 1AAr rrrr AAAA", OPCODE_out, "OUT", "A, Rr", "Out To I/O Location", "I/O(A) <-- Rr", "None", "1", "1", "1", "1", "", ""}, + {0xfe0f, 0x920f, 1, "1001 001d dddd 1111", OPCODE_push, "PUSH", "Rr", "Push Register on Stack", "STACK <-- Rr", "None", "2", "1", "1", "1", "(1)", ""}, + {0xfe0f, 0x900f, 1, "1001 000d dddd 1111", OPCODE_pop, "POP", "Rd", "Pop Register from Stack", "Rd <-- STACK", "None", "2", "2", "2", "3", "(1)", ""}, + {0xfe0f, 0x9204, 1, "1001 001r rrrr 0100", OPCODE_xch, "XCH", "Z, Rd", "Exchange", "(Z) <-- Rd, Rd <-- (Z)", "None", "n/a", "1", "n/a", "n/a", "", ""}, + {0xfe0f, 0x9205, 1, "1001 001r rrrr 0101", OPCODE_las, "LAS", "Z, Rd", "Load and Set", "(Z) <-- Rd|(Z), Rd <-- (Z)", "None", "n/a", "1", "n/a", "n/a", "", ""}, + {0xfe0f, 0x9206, 1, "1001 001r rrrr 0110", OPCODE_lac, "LAC", "Z, Rd", "Load and Clear", "(Z) <-- ($FF - Rd) & (Z), Rd <-- (Z)", "None", "n/a", "1", "n/a", "n/a", "", ""}, + {0xfe0f, 0x9207, 1, "1001 001r rrrr 0111", OPCODE_lat, "LAT", "Z, Rd", "Load and Toggle", "(Z) <-- Rd^(Z), Rd <-- (Z)", "None", "n/a", "1", "n/a", "n/a", "", ""}, + + // Bit and Bit-test Instructions + {0xfc00, 0x0c00, 1, "0000 11dd dddd dddd", OPCODE_lsl, "LSL", "Rd", "Logical Shift Left", "C <-- Rd(7) <-- Rd(6) ... Rd(1) <-- Rd(0) <-- 0", "Z,C,N,V,H", "1", "1", "1", "1", "", "alias for ADD Rd, Rd"}, + {0xfe0f, 0x9406, 1, "1001 010d dddd 0110", OPCODE_lsr, "LSR", "Rd", "Logical Shift Right", "0 --> Rd(7) --> Rd(6) ... Rd(1) --> Rd(0) --> C", "Z,C,N,V", "1", "1", "1", "1", "", ""}, + {0xfc00, 0x1c00, 1, "0001 11dd dddd dddd", OPCODE_rol, "ROL", "Rd", "Rotate Left Through Carry", "C <-- Rd(7) <-- Rd(6) ... Rd(1) <-- Rd(0) <-- C", "Z,C,N,V,H", "1", "1", "1", "1", "", "alias for ADC Rd, Rd"}, + {0xfe0f, 0x9407, 1, "1001 010d dddd 0111", OPCODE_ror, "ROR", "Rd", "Rotate Right Through Carry", "C --> Rd(7) --> Rd(6) ... Rd(1) --> Rd(0) --> C", "Z,C,N,V", "1", "1", "1", "1", "", ""}, + {0xfe0f, 0x9405, 1, "1001 010d dddd 0101", OPCODE_asr, "ASR", "Rd", "Arithmetic Shift Right", "Rd(7) --> Rd(7) --> Rd(6) ... Rd(1) --> Rd(0) --> C", "Z,C,N,V", "1", "1", "1", "1", "", ""}, + {0xfe0f, 0x9402, 1, "1001 010d dddd 0010", OPCODE_swap, "SWAP", "Rd", "Swap Nibbles", "Rd(3..0) <--> Rd(7..4)", "None", "1", "1", "1", "1", "", ""}, + {0xff8f, 0x9408, 1, "1001 0100 0sss 1000", OPCODE_bset, "BSET", "s", "Flag Set", "SREG(s) <-- 1", "SREG(s)", "1", "1", "1", "1", "", ""}, + {0xff8f, 0x9488, 1, "1001 0100 1sss 1000", OPCODE_bclr, "BCLR", "s", "Flag Clear", "SREG(s) <-- 0", "SREG(s)", "1", "1", "1", "1", "", "s = 0-7 = C,Z,N,V,S,H,T,I"}, + {0xff00, 0x9a00, 1, "1001 1010 AAAA Abbb", OPCODE_sbi, "SBI", "A, b", "Set Bit in I/O Register", "I/O(A,b) <-- 1", "None", "2", "1", "1", "1", "", ""}, + {0xff00, 0x9800, 1, "1001 1000 AAAA Abbb", OPCODE_cbi, "CBI", "A, b", "Clear Bit in I/O Register", "I/O(A,b) <-- 0", "None", "2", "1", "1", "1", "", ""}, + {0xfe08, 0xfa00, 1, "1111 101d dddd 0bbb", OPCODE_bst, "BST", "Rr, b", "Bit Store from Register to T", "T <-- Rr(b)", "T", "1", "1", "1", "1", "", ""}, + {0xfe08, 0xf800, 1, "1111 100d dddd 0bbb", OPCODE_bld, "BLD", "Rd, b", "Bit load from T to Register", "Rd(b) <-- T", "None", "1", "1", "1", "1", "", ""}, + {0xffff, 0x9408, 1, "1001 0100 0000 1000", OPCODE_sec, "SEC", "-", "Set Carry", "C <-- 1", "C", "1", "1", "1", "1", "", "alias for BSET 0"}, + {0xffff, 0x9488, 1, "1001 0100 1000 1000", OPCODE_clc, "CLC", "-", "Clear Carry", "C <-- 0", "C", "1", "1", "1", "1", "", "alias for BCLR 0"}, + {0xffff, 0x9428, 1, "1001 0100 0010 1000", OPCODE_sen, "SEN", "-", "Set Negative Flag", "N <-- 1", "N", "1", "1", "1", "1", "", "alias for BSET 2"}, + {0xffff, 0x94a8, 1, "1001 0100 1010 1000", OPCODE_cln, "CLN", "-", "Clear Negative Flag", "N <-- 0", "N", "1", "1", "1", "1", "", "alias for BCLR 2"}, + {0xffff, 0x9418, 1, "1001 0100 0001 1000", OPCODE_sez, "SEZ", "-", "Set Zero Flag", "Z <-- 1", "Z", "1", "1", "1", "1", "", "alias for BSET 1"}, + {0xffff, 0x9498, 1, "1001 0100 1001 1000", OPCODE_clz, "CLZ", "-", "Clear Zero Flag", "Z <-- 0", "Z", "1", "1", "1", "1", "", "alias for BCLR 1"}, + {0xffff, 0x9478, 1, "1001 0100 0111 1000", OPCODE_sei, "SEI", "-", "Global Interrupt Enable", "I <-- 1", "I", "1", "1", "1", "1", "", "alias for BSET 7"}, + {0xffff, 0x94f8, 1, "1001 0100 1111 1000", OPCODE_cli, "CLI", "-", "Global Interrupt Disable", "I <-- 0", "I", "1", "1", "1", "1", "", "alias for BCLR 7"}, + {0xffff, 0x9448, 1, "1001 0100 0100 1000", OPCODE_ses, "SES", "-", "Set Signed Test Flag", "S <-- 1", "S", "1", "1", "1", "1", "", "alias for BSET 4"}, + {0xffff, 0x94c8, 1, "1001 0100 1100 1000", OPCODE_cls, "CLS", "-", "Clear Signed Test Flag", "S <-- 0", "S", "1", "1", "1", "1", "", "alias for BCLR 4"}, + {0xffff, 0x9438, 1, "1001 0100 0011 1000", OPCODE_sev, "SEV", "-", "Set Two's Complement Overflow", "V <-- 1", "V", "1", "1", "1", "1", "", "alias for BSET 3"}, + {0xffff, 0x94b8, 1, "1001 0100 1011 1000", OPCODE_clv, "CLV", "-", "Clear Two's Complement Overflow", "V <-- 0", "V", "1", "1", "1", "1", "", "alias for BCLR 3"}, + {0xffff, 0x9468, 1, "1001 0100 0110 1000", OPCODE_set, "SET", "-", "Set T in SREG", "T <-- 1", "T", "1", "1", "1", "1", "", "alias for BSET 6"}, + {0xffff, 0x94e8, 1, "1001 0100 1110 1000", OPCODE_clt, "CLT", "-", "Clear T in SREG", "T <-- 0", "T", "1", "1", "1", "1", "", "alias for BCLR 6"}, + {0xffff, 0x9458, 1, "1001 0100 0101 1000", OPCODE_seh, "SEH", "-", "Set Half Carry Flag in SREG", "H <-- 1", "H", "1", "1", "1", "1", "", "alias for BSET 5"}, + {0xffff, 0x94d8, 1, "1001 0100 1101 1000", OPCODE_clh, "CLH", "-", "Clear Half Carry Flag in SREG", "H <-- 0", "H", "1", "1", "1", "1", "", "alias for BCLR 5"}, + + // MCU Control Instructions + {0xffff, 0x9598, 1, "1001 0101 1001 1000", OPCODE_break, "BREAK", "-", "Break", "(cf documentation)", "None", "-", "-", "-", "-", "(1)", ""}, + {0xffff, 0x0000, 1, "0000 0000 0000 0000", OPCODE_nop, "NOP", "-", "No Operation", "-", "None", "1", "1", "1", "1", "", ""}, + {0xffff, 0x9588, 1, "1001 0101 1000 1000", OPCODE_sleep, "SLEEP", "-", "Sleep", "(cf documentation)", "None", "-", "-", "-", "-", "", ""}, + {0xffff, 0x95a8, 1, "1001 0101 1010 1000", OPCODE_wdr, "WDR", "-", "Watchdog Reset", "(cf documentation)", "None", "1", "1", "1", "1", "", ""}, + + // Unallocated codes + {0xff00, 0x0000, 1, "0000 0000 xxxx xxxx", OPCODE_x_nop_1, "NOP", "", "", "", "", "", "", "", "", "", "xxxx xxxx != 0000 0000"}, + {0xfe0f, 0x9003, 1, "1001 000x xxxx 0011", OPCODE_x_nop_2, "NOP", "", "", "", "", "", "", "", "", "", ""}, + {0xfe0f, 0x9008, 1, "1001 000x xxxx 1000", OPCODE_x_nop_3, "NOP", "", "", "", "", "", "", "", "", "", ""}, + {0xfe0f, 0x900b, 1, "1001 000x xxxx 1011", OPCODE_x_nop_4, "NOP", "", "", "", "", "", "", "", "", "", ""}, + {0xfe0f, 0x9203, 1, "1001 001x xxxx 0011", OPCODE_x_nop_5, "NOP", "", "", "", "", "", "", "", "", "", ""}, + {0xfe0f, 0x9208, 1, "1001 001x xxxx 1000", OPCODE_x_nop_6, "NOP", "", "", "", "", "", "", "", "", "", ""}, + {0xfe0f, 0x920b, 1, "1001 001x xxxx 1011", OPCODE_x_nop_7, "NOP", "", "", "", "", "", "", "", "", "", ""}, + {0xff1f, 0x9509, 1, "1001 0101 xxx0 1001", OPCODE_x_icall, "ICALL", "", "", "", "", "", "", "", "", "", "xxx != 000"}, + {0xff1f, 0x9519, 1, "1001 0101 xxx1 1001", OPCODE_x_eicall, "EICALL", "", "", "", "", "", "", "", "", "", "xxx != 000"}, + {0xff9f, 0x9508, 1, "1001 0101 0xx0 1000", OPCODE_x_ret, "RET", "", "", "", "", "", "", "", "", "", "xx != 00"}, + {0xff9f, 0x9518, 1, "1001 0101 0xx1 1000", OPCODE_x_reti, "RETI", "", "", "", "", "", "", "", "", "", "xx != 00"}, + {0xffff, 0x95b8, 1, "1001 0101 1011 1000", OPCODE_x_nop_8, "NOP", "", "", "", "", "", "", "", "", "", ""}, + {0xfe0f, 0x9404, 1, "1001 010x xxxx 0100", OPCODE_x_nop_9, "NOP", "", "", "", "", "", "", "", "", "", ""}, + {0xff0f, 0x950b, 1, "1001 0101 xxxx 1011", OPCODE_x_nop_a, "NOP", "", "", "", "", "", "", "", "", "", ""}, + {0xff1f, 0x9409, 1, "1001 0100 xxx0 1001", OPCODE_x_ijmp, "IJMP", "", "", "", "", "", "", "", "", "", "xxx != 000"}, + {0xff1f, 0x9419, 1, "1001 0100 xxx1 1001", OPCODE_x_eijmp, "EIJMP", "", "", "", "", "", "", "", "", "", "xxx != 000"}, + {0xfe08, 0xf808, 1, "1111 100x xxxx 1xxx", OPCODE_x_bld, "BLD", "Rd, b", "", "", "", "", "", "", "", "", ""}, + {0xfe08, 0xfa08, 1, "1111 101x xxxx 1xxx", OPCODE_x_bst, "BST", "Rd, b", "", "", "", "", "", "", "", "", ""}, + {0xfe08, 0xfc08, 1, "1111 110x xxxx 1xxx", OPCODE_x_sbrc, "SBRC", "Rr, b", "", "", "", "", "", "", "", "", ""}, + {0xfe08, 0xfe08, 1, "1111 111x xxxx 1xxx", OPCODE_x_sbrs, "SBRS", "Rr, b", "", "", "", "", "", "", "", "", ""}, +}; diff --git a/src/disasm.c b/src/disasm.c index 885c3b94..42cfd8b1 100644 --- a/src/disasm.c +++ b/src/disasm.c @@ -33,6 +33,7 @@ #include #include +#include "avrdude.h" #include "libavrdude.h" #include "disasm_globals.h" @@ -40,7 +41,6 @@ #include "disasm_callbacks_pseudocode.h" #include "disasm_jumpcall.h" #include "disasm_ioregisters.h" -#include "disasm_mnemonics.h" #include "disasm_tagfile.h" void Display_Registers() { @@ -80,25 +80,24 @@ int Compare_Opcode(const char *Bitstream, const char *Bitmask) { return 1; // Match } -void Register_Opcode(void (*Callback)(const char *, int, int), const char *New_Opcode_String, int New_MNemonic) { +void Register_Opcode(void (*Callback)(const char *, int, AVR_opcode), const char *New_Opcode_String, AVR_opcode mnemo) { cx->dis_n_ops++; cx->dis_op[cx->dis_n_ops - 1].Opcode_String = malloc(strlen(New_Opcode_String) + 1); strcpy(cx->dis_op[cx->dis_n_ops - 1].Opcode_String, New_Opcode_String); - cx->dis_op[cx->dis_n_ops - 1].MNemonic = New_MNemonic; + cx->dis_op[cx->dis_n_ops - 1].mnemo = mnemo; cx->dis_op[cx->dis_n_ops - 1].Callback = Callback; } -void Supersede_Opcode(void (*Callback)(const char *, int, int), int New_MNemonic) { +void Supersede_Opcode(void (*Callback)(const char *, int, AVR_opcode), AVR_opcode mnemo) { int i; for(i = 0; i < cx->dis_n_ops; i++) { - if(cx->dis_op[i].MNemonic == New_MNemonic) { - // Supersede callback + if(cx->dis_op[i].mnemo == mnemo) { cx->dis_op[i].Callback = Callback; return; } } - fprintf(stderr, "Error: No callback to supersede opcode %d found (%s).\n", New_MNemonic, MNemonic[New_MNemonic]); + fprintf(stderr, "Error: No callback fund to supersede opcode %d (%s).\n", mnemo, avr_opcodes[mnemo].opcode); } int Get_Bitmask_Length(const char *Bitmask) { @@ -230,7 +229,7 @@ void Disassemble(const char *Bitstream, int Read, int addr) { if(Opcode == -1) { Pos += 2; } else { - cx->dis_op[Opcode].Callback(Bitstream + Pos, Pos, cx->dis_op[Opcode].MNemonic); + cx->dis_op[Opcode].Callback(Bitstream + Pos, Pos, cx->dis_op[Opcode].mnemo); Pos += Get_Bitmask_Length(cx->dis_op[Opcode].Opcode_String) / 8; } } @@ -258,7 +257,7 @@ void Disassemble(const char *Bitstream, int Read, int addr) { cx->dis_code[0] = 0; cx->dis_comment[0] = 0; cx->dis_after_code[0] = 0; - cx->dis_op[Opcode].Callback(Bitstream + Pos, Pos, cx->dis_op[Opcode].MNemonic); + cx->dis_op[Opcode].Callback(Bitstream + Pos, Pos, cx->dis_op[Opcode].mnemo); if(cx->dis_opts.Process_Labels) { Print_JumpCalls(Pos); @@ -266,14 +265,8 @@ void Disassemble(const char *Bitstream, int Read, int addr) { if(cx->dis_opts.Show_Addresses) printf("%4x: ", Pos); - if(cx->dis_opts.Show_Cycles) { - const char *Cycle = Cycles[cx->dis_op[Opcode].MNemonic]; - - if(!Cycle) - printf(" "); - else - printf("[%-3s] ", Cycle); - } + if(cx->dis_opts.Show_Cycles) // @@@ select correct clocks_xx + printf("[%-3s] ", avr_opcodes[cx->dis_op[Opcode].mnemo].clocks_e); if(cx->dis_opts.Show_Opcodes) { // Now display the Opcode @@ -289,7 +282,7 @@ void Disassemble(const char *Bitstream, int Read, int addr) { if(cx->dis_code[0] == 0) { // No code was generated? - printf("; - Not implemented opcode: %d -\n", cx->dis_op[Opcode].MNemonic); + printf("; - Not implemented opcode: %d -\n", cx->dis_op[Opcode].mnemo); } else { if((cx->dis_comment[0] == 0) || (!cx->dis_opts.Show_Comments)) { // No comment @@ -360,6 +353,41 @@ int disasm(const char *Bitstream, int Read, int addr) { if(!Read_Tagfile(cx->dis_opts.Tagfile)) return 0; + /* + * 8 untreated opcodes and 20 "unofficial" ones + * + * OPCODE_des + * OPCODE_xch + * OPCODE_lac + * OPCODE_las + * OPCODE_lat + * + * OPCODE_lds_rc + * OPCODE_spm_zz + * OPCODE_sts_rc + * + * OPCODE_x_bld + * OPCODE_x_bst + * OPCODE_x_eicall + * OPCODE_x_eijmp + * OPCODE_x_icall + * OPCODE_x_ijmp + * OPCODE_x_nop_1 + * OPCODE_x_nop_2 + * OPCODE_x_nop_3 + * OPCODE_x_nop_4 + * OPCODE_x_nop_5 + * OPCODE_x_nop_6 + * OPCODE_x_nop_7 + * OPCODE_x_nop_8 + * OPCODE_x_nop_9 + * OPCODE_x_nop_a + * OPCODE_x_ret + * OPCODE_x_reti + * OPCODE_x_sbrc + * OPCODE_x_sbrs + */ + cx->dis_n_ops = 0; Register_Opcode(adc_Callback, "0001 11rd dddd rrrr", OPCODE_adc); @@ -399,7 +427,6 @@ int disasm(const char *Bitstream, int Read, int addr) { Register_Opcode(clh_Callback, "1001 0100 1101 1000", OPCODE_clh); Register_Opcode(cli_Callback, "1001 0100 1111 1000", OPCODE_cli); Register_Opcode(cln_Callback, "1001 0100 1010 1000", OPCODE_cln); - // Register_Opcode(clr_Callback, "0010 01dd dddd dddd", OPCODE_clr); // Implied by eor Register_Opcode(cls_Callback, "1001 0100 1100 1000", OPCODE_cls); Register_Opcode(clt_Callback, "1001 0100 1110 1000", OPCODE_clt); @@ -441,7 +468,6 @@ int disasm(const char *Bitstream, int Read, int addr) { Register_Opcode(lpm1_Callback, "1001 0101 1100 1000", OPCODE_lpm_1); Register_Opcode(lpm2_Callback, "1001 000d dddd 0100", OPCODE_lpm_2); Register_Opcode(lpm3_Callback, "1001 000d dddd 0101", OPCODE_lpm_3); - // Register_Opcode(lsl_Callback, "0000 11dd dddd dddd", OPCODE_lsl); // Implied by add Register_Opcode(lsr_Callback, "1001 010d dddd 0110", OPCODE_lsr); Register_Opcode(mov_Callback, "0010 11rd dddd rrrr", OPCODE_mov); @@ -460,7 +486,6 @@ int disasm(const char *Bitstream, int Read, int addr) { Register_Opcode(ret_Callback, "1001 0101 0000 1000", OPCODE_ret); Register_Opcode(reti_Callback, "1001 0101 0001 1000", OPCODE_reti); Register_Opcode(rjmp_Callback, "1100 kkkk kkkk kkkk", OPCODE_rjmp); - // Register_Opcode(rol_Callback, "0001 11dd dddd dddd", OPCODE_rol); // Implied by adc Register_Opcode(ror_Callback, "1001 010d dddd 0111", OPCODE_ror); Register_Opcode(sbc_Callback, "0000 10rd dddd rrrr", OPCODE_sbc); @@ -498,7 +523,6 @@ int disasm(const char *Bitstream, int Read, int addr) { Register_Opcode(sub_Callback, "0001 10rd dddd rrrr", OPCODE_sub); Register_Opcode(subi_Callback, "0101 KKKK dddd KKKK", OPCODE_subi); Register_Opcode(swap_Callback, "1001 010d dddd 0010", OPCODE_swap); - // Register_Opcode(tst_Callback, "0010 00dd dddd dddd", OPCODE_tst); // Implied by and Register_Opcode(wdr_Callback, "1001 0101 1010 1000", OPCODE_wdr); @@ -571,6 +595,12 @@ int disasm(const char *Bitstream, int Read, int addr) { qsort(cx->dis_op, cx->dis_n_ops, sizeof(Disasm_opcode), Comparison); + for(size_t i = 0; i < sizeof avr_opcodes/sizeof*avr_opcodes; i++) + if(avr_opcodes[i].mnemo != i) { + msg_error("avr_opcodes[] table broken (this should never happen)\n"); + return -1; + } + Disassemble(Bitstream, Read, addr); return 0; } diff --git a/src/disasm_callbacks_assembly.c b/src/disasm_callbacks_assembly.c index c190c4dd..b00ef89b 100644 --- a/src/disasm_callbacks_assembly.c +++ b/src/disasm_callbacks_assembly.c @@ -30,7 +30,6 @@ #include "libavrdude.h" -#include "disasm_mnemonics.h" #include "disasm_globals.h" #include "disasm_callbacks_assembly.h" #include "disasm_jumpcall.h" @@ -48,54 +47,54 @@ static unsigned BitCount(unsigned n) { return ret; } -void Operation_Simple(int MNemonic_Int) { - snprintf(cx->dis_code, 255, "%s", MNemonic[MNemonic_Int]); +void Operation_Simple(AVR_opcode mnemo) { + snprintf(cx->dis_code, 255, "%s", avr_opcodes[mnemo].opcode); } -void Operation_Rd(int MNemonic_Int) { - snprintf(cx->dis_code, 255, "%-7s r%d", MNemonic[MNemonic_Int], Rd); +void Operation_Rd(AVR_opcode mnemo) { + snprintf(cx->dis_code, 255, "%-7s r%d", avr_opcodes[mnemo].opcode, Rd); } -void Operation_Rd16(int MNemonic_Int) { - snprintf(cx->dis_code, 255, "%-7s r%d", MNemonic[MNemonic_Int], Rd + 16); +void Operation_Rd16(AVR_opcode mnemo) { + snprintf(cx->dis_code, 255, "%-7s r%d", avr_opcodes[mnemo].opcode, Rd + 16); } -void Operation_Rd_Rr(int MNemonic_Int) { - snprintf(cx->dis_code, 255, "%-7s r%d, r%d", MNemonic[MNemonic_Int], Rd, Rr); +void Operation_Rd_Rr(AVR_opcode mnemo) { + snprintf(cx->dis_code, 255, "%-7s r%d, r%d", avr_opcodes[mnemo].opcode, Rd, Rr); } -void Operation_Rd16_Rr16(int MNemonic_Int) { - snprintf(cx->dis_code, 255, "%-7s r%d, r%d", MNemonic[MNemonic_Int], Rd + 16, Rr + 16); +void Operation_Rd16_Rr16(AVR_opcode mnemo) { + snprintf(cx->dis_code, 255, "%-7s r%d, r%d", avr_opcodes[mnemo].opcode, Rd + 16, Rr + 16); } -void Operation_Rd16_K(int MNemonic_Int) { - snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", MNemonic[MNemonic_Int], Rd + 16, RK); +void Operation_Rd16_K(AVR_opcode mnemo) { + snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", avr_opcodes[mnemo].opcode, Rd + 16, RK); snprintf(cx->dis_comment, 255, "%d", RK); } -void Operation_Rd_K(int MNemonic_Int) { - snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", MNemonic[MNemonic_Int], Rd, RK); +void Operation_Rd_K(AVR_opcode mnemo) { + snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", avr_opcodes[mnemo].opcode, Rd, RK); snprintf(cx->dis_comment, 255, "%d", RK); } -void Operation_RdW_K(int MNemonic_Int) { +void Operation_RdW_K(AVR_opcode mnemo) { if(cx->dis_opts.CodeStyle == CODESTYLE_AVR_INSTRUCTION_SET) { - snprintf(cx->dis_code, 255, "%-7s r%d:%d, 0x%02x", MNemonic[MNemonic_Int], Rd + 1, Rd, RK); + snprintf(cx->dis_code, 255, "%-7s r%d:%d, 0x%02x", avr_opcodes[mnemo].opcode, Rd + 1, Rd, RK); } else { - snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", MNemonic[MNemonic_Int], Rd, RK); + snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", avr_opcodes[mnemo].opcode, Rd, RK); } snprintf(cx->dis_comment, 255, "%d", RK); } -void Operation_RdW_RrW(int MNemonic_Int) { +void Operation_RdW_RrW(AVR_opcode mnemo) { if(cx->dis_opts.CodeStyle == CODESTYLE_AVR_INSTRUCTION_SET) { - snprintf(cx->dis_code, 255, "%-7s r%d:%d, r%d:%d", MNemonic[MNemonic_Int], (2 * Rd) + 1, 2 * Rd, (2 * Rr) + 1, 2 * Rr); + snprintf(cx->dis_code, 255, "%-7s r%d:%d, r%d:%d", avr_opcodes[mnemo].opcode, (2 * Rd) + 1, 2 * Rd, (2 * Rr) + 1, 2 * Rr); } else { - snprintf(cx->dis_code, 255, "%-7s r%d, r%d", MNemonic[MNemonic_Int], 2 * Rd, 2 * Rr); + snprintf(cx->dis_code, 255, "%-7s r%d, r%d", avr_opcodes[mnemo].opcode, 2 * Rd, 2 * Rr); } } -void Operation_s_k(int MNemonic_Int, int Position) { +void Operation_s_k(AVR_opcode mnemo, int Position) { int Bits, Offset; int Target; @@ -105,39 +104,39 @@ void Operation_s_k(int MNemonic_Int, int Position) { Offset -= 256; Target = FixTargetAddress(Position + Offset + 2); - Register_JumpCall(Position, Target, MNemonic_Int, 0); + Register_JumpCall(Position, Target, mnemo, 0); if(cx->dis_opts.Process_Labels == 0) { if(Offset > 0) { - snprintf(cx->dis_code, 255, "%-7s %d, .+%d", MNemonic[MNemonic_Int], Bits, Offset); + snprintf(cx->dis_code, 255, "%-7s %d, .+%d", avr_opcodes[mnemo].opcode, Bits, Offset); } else { - snprintf(cx->dis_code, 255, "%-7s %d, .%d", MNemonic[MNemonic_Int], Bits, Offset); + snprintf(cx->dis_code, 255, "%-7s %d, .%d", avr_opcodes[mnemo].opcode, Bits, Offset); } snprintf(cx->dis_comment, 255, "0x%02x = %d -> 0x%02x", (1 << Bits), (1 << Bits), Target); } else { - snprintf(cx->dis_code, 255, "%-7s %d, %s", MNemonic[MNemonic_Int], Bits, Get_Label_Name(Target, NULL)); + snprintf(cx->dis_code, 255, "%-7s %d, %s", avr_opcodes[mnemo].opcode, Bits, Get_Label_Name(Target, NULL)); snprintf(cx->dis_comment, 255, "0x%02x = %d", (1 << Bits), (1 << Bits)); } } -void Operation_r_b(int MNemonic_Int) { +void Operation_r_b(AVR_opcode mnemo) { int Register, Bit; Register = Rr; Bit = Rb; - snprintf(cx->dis_code, 255, "%-7s r%d, %d", MNemonic[MNemonic_Int], Register, Bit); + snprintf(cx->dis_code, 255, "%-7s r%d, %d", avr_opcodes[mnemo].opcode, Register, Bit); snprintf(cx->dis_comment, 255, "0x%02x = %d", (1 << Bit), (1 << Bit)); } -void Operation_Rd_b(int MNemonic_Int) { +void Operation_Rd_b(AVR_opcode mnemo) { int Register, Bit; Register = Rd; Bit = Rb; - snprintf(cx->dis_code, 255, "%-7s r%d, %d", MNemonic[MNemonic_Int], Register, Bit); + snprintf(cx->dis_code, 255, "%-7s r%d, %d", avr_opcodes[mnemo].opcode, Register, Bit); snprintf(cx->dis_comment, 255, "0x%02x = %d", (1 << Bit), (1 << Bit)); } -void Operation_A_b(int MNemonic_Int) { +void Operation_A_b(AVR_opcode mnemo) { int Register, Bit; const char *Register_Name; @@ -145,23 +144,23 @@ void Operation_A_b(int MNemonic_Int) { Bit = Rb; Register_Name = Resolve_IO_Register(Register); if(Register_Name == NULL) { - snprintf(cx->dis_code, 255, "%-7s 0x%02x, %d", MNemonic[MNemonic_Int], Register, Bit); + snprintf(cx->dis_code, 255, "%-7s 0x%02x, %d", avr_opcodes[mnemo].opcode, Register, Bit); snprintf(cx->dis_comment, 255, "0x%02x = %d", (1 << Bit), (1 << Bit)); } else { - snprintf(cx->dis_code, 255, "%-7s %s, %d", MNemonic[MNemonic_Int], Register_Name, Bit); + snprintf(cx->dis_code, 255, "%-7s %s, %d", avr_opcodes[mnemo].opcode, Register_Name, Bit); snprintf(cx->dis_comment, 255, "0x%02x = %d", (1 << Bit), (1 << Bit)); } } -void Operation_s(int MNemonic_Int) { +void Operation_s(AVR_opcode mnemo) { int Bit; Bit = Rs; - snprintf(cx->dis_code, 255, "%-7s %d", MNemonic[MNemonic_Int], Bit); + snprintf(cx->dis_code, 255, "%-7s %d", avr_opcodes[mnemo].opcode, Bit); snprintf(cx->dis_comment, 255, "0x%02x = %d", (1 << Bit), (1 << Bit)); } -void Operation_k(int MNemonic_Int, int Position, const char *Pseudocode) { +void Operation_k(AVR_opcode mnemo, int Position, const char *Pseudocode) { int Offset; int Target; @@ -170,16 +169,16 @@ void Operation_k(int MNemonic_Int, int Position, const char *Pseudocode) { Offset -= 256; Target = FixTargetAddress(Position + Offset + 2); - Register_JumpCall(Position, Target, MNemonic_Int, 0); + Register_JumpCall(Position, Target, mnemo, 0); if(cx->dis_opts.Process_Labels == 0) { if(Offset > 0) { - snprintf(cx->dis_code, 255, "%-7s .+%d", MNemonic[MNemonic_Int], Offset); + snprintf(cx->dis_code, 255, "%-7s .+%d", avr_opcodes[mnemo].opcode, Offset); } else { - snprintf(cx->dis_code, 255, "%-7s .%d", MNemonic[MNemonic_Int], Offset); + snprintf(cx->dis_code, 255, "%-7s .%d", avr_opcodes[mnemo].opcode, Offset); } snprintf(cx->dis_comment, 255, "0x%02x", Target); } else { - snprintf(cx->dis_code, 255, "%-7s %s", MNemonic[MNemonic_Int], Get_Label_Name(Target, NULL)); + snprintf(cx->dis_code, 255, "%-7s %s", avr_opcodes[mnemo].opcode, Get_Label_Name(Target, NULL)); } } @@ -189,7 +188,7 @@ CALLBACK(adc_Callback) { if(Rd == Rr) { Operation_Rd(OPCODE_rol); } else { - Operation_Rd_Rr(MNemonic_Int); + Operation_Rd_Rr(mnemo); } } @@ -197,15 +196,15 @@ CALLBACK(add_Callback) { if(Rd == Rr) { Operation_Rd(OPCODE_lsl); } else { - Operation_Rd_Rr(MNemonic_Int); + Operation_Rd_Rr(mnemo); } } CALLBACK(adiw_Callback) { if(cx->dis_opts.CodeStyle == CODESTYLE_AVR_INSTRUCTION_SET) { - snprintf(cx->dis_code, 255, "%-7s r%d:%d, 0x%02x", MNemonic[MNemonic_Int], 2 * Rd + 25, 2 * Rd + 24, RK); + snprintf(cx->dis_code, 255, "%-7s r%d:%d, 0x%02x", avr_opcodes[mnemo].opcode, 2 * Rd + 25, 2 * Rd + 24, RK); } else { - snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", MNemonic[MNemonic_Int], 2 * Rd + 24, RK); + snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", avr_opcodes[mnemo].opcode, 2 * Rd + 24, RK); } snprintf(cx->dis_comment, 255, "%d", RK); } @@ -214,13 +213,13 @@ CALLBACK(and_Callback) { if(Rd == Rr) { Operation_Rd(OPCODE_tst); } else { - Operation_Rd_Rr(MNemonic_Int); + Operation_Rd_Rr(mnemo); } } CALLBACK(andi_Callback) { if(BitCount(RK) < 4) { - Operation_Rd16_K(MNemonic_Int); + Operation_Rd16_K(mnemo); } else { RK = ~RK; RK &= 0xff; @@ -229,233 +228,233 @@ CALLBACK(andi_Callback) { } CALLBACK(asr_Callback) { - Operation_Rd(MNemonic_Int); + Operation_Rd(mnemo); } CALLBACK(bclr_Callback) { - Operation_s(MNemonic_Int); + Operation_s(mnemo); } CALLBACK(bld_Callback) { - Operation_Rd_b(MNemonic_Int); + Operation_Rd_b(mnemo); } CALLBACK(brbc_Callback) { - Operation_s_k(MNemonic_Int, Position); + Operation_s_k(mnemo, Position); } CALLBACK(brbs_Callback) { - Operation_s_k(MNemonic_Int, Position); + Operation_s_k(mnemo, Position); } CALLBACK(brcc_Callback) { - Operation_k(MNemonic_Int, Position, "Carry == 0"); + Operation_k(mnemo, Position, "Carry == 0"); } CALLBACK(brcs_Callback) { - Operation_k(MNemonic_Int, Position, "Carry == 1"); + Operation_k(mnemo, Position, "Carry == 1"); } CALLBACK(break_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(breq_Callback) { - Operation_k(MNemonic_Int, Position, "c1 == c2"); + Operation_k(mnemo, Position, "c1 == c2"); } CALLBACK(brge_Callback) { - Operation_k(MNemonic_Int, Position, "c1 (signed)>= c2"); + Operation_k(mnemo, Position, "c1 (signed)>= c2"); } CALLBACK(brhc_Callback) { - Operation_k(MNemonic_Int, Position, "HalfCarry == 0"); + Operation_k(mnemo, Position, "HalfCarry == 0"); } CALLBACK(brhs_Callback) { - Operation_k(MNemonic_Int, Position, "HalfCarry == 1"); + Operation_k(mnemo, Position, "HalfCarry == 1"); } CALLBACK(brid_Callback) { - Operation_k(MNemonic_Int, Position, "Global_Interrupts_Disabled()"); + Operation_k(mnemo, Position, "Global_Interrupts_Disabled()"); } CALLBACK(brie_Callback) { - Operation_k(MNemonic_Int, Position, "Global_Interrupts_Enabled()"); + Operation_k(mnemo, Position, "Global_Interrupts_Enabled()"); } CALLBACK(brlo_Callback) { - Operation_k(MNemonic_Int, Position, "c1 (unsigned)< c2"); + Operation_k(mnemo, Position, "c1 (unsigned)< c2"); } CALLBACK(brlt_Callback) { - Operation_k(MNemonic_Int, Position, "c1 (signed)< c2"); + Operation_k(mnemo, Position, "c1 (signed)< c2"); } CALLBACK(brmi_Callback) { - Operation_k(MNemonic_Int, Position, "< 0"); + Operation_k(mnemo, Position, "< 0"); } CALLBACK(brne_Callback) { - Operation_k(MNemonic_Int, Position, "c1 != c2"); + Operation_k(mnemo, Position, "c1 != c2"); } CALLBACK(brpl_Callback) { - Operation_k(MNemonic_Int, Position, "> 0"); + Operation_k(mnemo, Position, "> 0"); } CALLBACK(brsh_Callback) { - Operation_k(MNemonic_Int, Position, "c1 (unsigned)>= c2"); + Operation_k(mnemo, Position, "c1 (unsigned)>= c2"); } CALLBACK(brtc_Callback) { - Operation_k(MNemonic_Int, Position, "T == 0"); + Operation_k(mnemo, Position, "T == 0"); } CALLBACK(brts_Callback) { - Operation_k(MNemonic_Int, Position, "T == 1"); + Operation_k(mnemo, Position, "T == 1"); } CALLBACK(brvc_Callback) { - Operation_k(MNemonic_Int, Position, "Overflow == 0"); + Operation_k(mnemo, Position, "Overflow == 0"); } CALLBACK(brvs_Callback) { - Operation_k(MNemonic_Int, Position, "Overflow == 1"); + Operation_k(mnemo, Position, "Overflow == 1"); } CALLBACK(bset_Callback) { - Operation_s(MNemonic_Int); + Operation_s(mnemo); } CALLBACK(bst_Callback) { - Operation_Rd_b(MNemonic_Int); + Operation_Rd_b(mnemo); } CALLBACK(call_Callback) { int Pos; Pos = FixTargetAddress(2 * Rk); - Register_JumpCall(Position, Pos, MNemonic_Int, 1); + Register_JumpCall(Position, Pos, mnemo, 1); if(!cx->dis_opts.Process_Labels) { - snprintf(cx->dis_code, 255, "%-7s 0x%02x", MNemonic[MNemonic_Int], Pos); + snprintf(cx->dis_code, 255, "%-7s 0x%02x", avr_opcodes[mnemo].opcode, Pos); } else { char *LabelName; char *LabelComment = NULL; LabelName = Get_Label_Name(Pos, &LabelComment); - snprintf(cx->dis_code, 255, "%-7s %s", MNemonic[MNemonic_Int], LabelName); + snprintf(cx->dis_code, 255, "%-7s %s", avr_opcodes[mnemo].opcode, LabelName); if(LabelComment != NULL) snprintf(cx->dis_comment, 255, "%s", LabelComment); } } CALLBACK(cbi_Callback) { - Operation_A_b(MNemonic_Int); + Operation_A_b(mnemo); } CALLBACK(clc_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(clh_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(cli_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(cln_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(cls_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(clt_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(clv_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(clz_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(com_Callback) { - Operation_Rd(MNemonic_Int); + Operation_Rd(mnemo); } CALLBACK(cp_Callback) { - Operation_Rd_Rr(MNemonic_Int); + Operation_Rd_Rr(mnemo); } CALLBACK(cpc_Callback) { - Operation_Rd_Rr(MNemonic_Int); + Operation_Rd_Rr(mnemo); } CALLBACK(cpi_Callback) { - Operation_Rd16_K(MNemonic_Int); + Operation_Rd16_K(mnemo); } CALLBACK(cpse_Callback) { - Operation_Rd_Rr(MNemonic_Int); + Operation_Rd_Rr(mnemo); } CALLBACK(dec_Callback) { - Operation_Rd(MNemonic_Int); + Operation_Rd(mnemo); } CALLBACK(eicall_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(eijmp_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(elpm1_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(elpm2_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, Z", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d, Z", avr_opcodes[mnemo].opcode, Rd); } CALLBACK(elpm3_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, Z+", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d, Z+", avr_opcodes[mnemo].opcode, Rd); } CALLBACK(eor_Callback) { if(Rd == Rr) { Operation_Rd(OPCODE_clr); } else { - Operation_Rd_Rr(MNemonic_Int); + Operation_Rd_Rr(mnemo); } } CALLBACK(fmul_Callback) { - Operation_Rd16_Rr16(MNemonic_Int); + Operation_Rd16_Rr16(mnemo); } CALLBACK(fmuls_Callback) { - Operation_Rd16_Rr16(MNemonic_Int); + Operation_Rd16_Rr16(mnemo); } CALLBACK(fmulsu_Callback) { - Operation_Rd16_Rr16(MNemonic_Int); + Operation_Rd16_Rr16(mnemo); } CALLBACK(icall_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(ijmp_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(in_Callback) { @@ -465,15 +464,15 @@ CALLBACK(in_Callback) { Register_Number = RA; Register_Name = Resolve_IO_Register(Register_Number); if(Register_Name != NULL) { - snprintf(cx->dis_code, 255, "%-7s r%d, %s", MNemonic[MNemonic_Int], Rd, Register_Name); + snprintf(cx->dis_code, 255, "%-7s r%d, %s", avr_opcodes[mnemo].opcode, Rd, Register_Name); } else { - snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", MNemonic[MNemonic_Int], Rd, Register_Number); + snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", avr_opcodes[mnemo].opcode, Rd, Register_Number); snprintf(cx->dis_comment, 255, "%d", RA); } } CALLBACK(inc_Callback) { - Operation_Rd(MNemonic_Int); + Operation_Rd(mnemo); } CALLBACK(jmp_Callback) { @@ -481,122 +480,122 @@ CALLBACK(jmp_Callback) { Pos = FixTargetAddress(2 * Rk); if(!cx->dis_opts.Process_Labels) { - snprintf(cx->dis_code, 255, "%-7s 0x%02x", MNemonic[MNemonic_Int], Pos); + snprintf(cx->dis_code, 255, "%-7s 0x%02x", avr_opcodes[mnemo].opcode, Pos); } else { - snprintf(cx->dis_code, 255, "%-7s %s", MNemonic[MNemonic_Int], Get_Label_Name(Pos, NULL)); + snprintf(cx->dis_code, 255, "%-7s %s", avr_opcodes[mnemo].opcode, Get_Label_Name(Pos, NULL)); } - Register_JumpCall(Position, Pos, MNemonic_Int, 0); + Register_JumpCall(Position, Pos, mnemo, 0); } CALLBACK(ld1_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, X", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d, X", avr_opcodes[mnemo].opcode, Rd); } CALLBACK(ld2_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, X+", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d, X+", avr_opcodes[mnemo].opcode, Rd); } CALLBACK(ld3_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, -X", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d, -X", avr_opcodes[mnemo].opcode, Rd); } CALLBACK(ldy1_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, Y", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d, Y", avr_opcodes[mnemo].opcode, Rd); } CALLBACK(ldy2_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, Y+", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d, Y+", avr_opcodes[mnemo].opcode, Rd); } CALLBACK(ldy3_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, -Y", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d, -Y", avr_opcodes[mnemo].opcode, Rd); } CALLBACK(ldy4_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, Y+%d", MNemonic[MNemonic_Int], Rd, Rq); + snprintf(cx->dis_code, 255, "%-7s r%d, Y+%d", avr_opcodes[mnemo].opcode, Rd, Rq); } CALLBACK(ldz1_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, Z", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d, Z", avr_opcodes[mnemo].opcode, Rd); } CALLBACK(ldz2_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, Z+", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d, Z+", avr_opcodes[mnemo].opcode, Rd); } CALLBACK(ldz3_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, -Z", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d, -Z", avr_opcodes[mnemo].opcode, Rd); } CALLBACK(ldz4_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, Z+%d", MNemonic[MNemonic_Int], Rd, Rq); + snprintf(cx->dis_code, 255, "%-7s r%d, Z+%d", avr_opcodes[mnemo].opcode, Rd, Rq); } CALLBACK(ldi_Callback) { - Operation_Rd16_K(MNemonic_Int); + Operation_Rd16_K(mnemo); } CALLBACK(lds_Callback) { const char *MemAddress; - snprintf(cx->dis_code, 255, "%-7s r%d, 0x%04x", MNemonic[MNemonic_Int], Rd, Rk); + snprintf(cx->dis_code, 255, "%-7s r%d, 0x%04x", avr_opcodes[mnemo].opcode, Rd, Rk); MemAddress = Tagfile_Resolve_Mem_Address(Rk); - snprintf(cx->dis_code, 255, "%-7s 0x%04x, r%d", MNemonic[MNemonic_Int], Rk, Rd); + snprintf(cx->dis_code, 255, "%-7s 0x%04x, r%d", avr_opcodes[mnemo].opcode, Rk, Rd); if(MemAddress) { snprintf(cx->dis_comment, 255, "%s", MemAddress); } } CALLBACK(lpm1_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(lpm2_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, Z", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d, Z", avr_opcodes[mnemo].opcode, Rd); } CALLBACK(lpm3_Callback) { - snprintf(cx->dis_code, 255, "%-7s r%d, Z+", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d, Z+", avr_opcodes[mnemo].opcode, Rd); } CALLBACK(lsr_Callback) { - Operation_Rd(MNemonic_Int); + Operation_Rd(mnemo); } CALLBACK(mov_Callback) { - Operation_Rd_Rr(MNemonic_Int); + Operation_Rd_Rr(mnemo); } CALLBACK(movw_Callback) { - Operation_RdW_RrW(MNemonic_Int); + Operation_RdW_RrW(mnemo); } CALLBACK(mul_Callback) { - Operation_Rd_Rr(MNemonic_Int); + Operation_Rd_Rr(mnemo); } CALLBACK(muls_Callback) { - Operation_Rd16_Rr16(MNemonic_Int); + Operation_Rd16_Rr16(mnemo); } CALLBACK(mulsu_Callback) { - Operation_Rd16_Rr16(MNemonic_Int); + Operation_Rd16_Rr16(mnemo); } CALLBACK(neg_Callback) { - Operation_Rd(MNemonic_Int); + Operation_Rd(mnemo); } CALLBACK(nop_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(or_Callback) { - Operation_Rd_Rr(MNemonic_Int); + Operation_Rd_Rr(mnemo); } CALLBACK(ori_Callback) { - Operation_Rd16_K(MNemonic_Int); + Operation_Rd16_K(mnemo); } CALLBACK(out_Callback) { @@ -606,19 +605,19 @@ CALLBACK(out_Callback) { Register_Number = RA; Register_Name = Resolve_IO_Register(Register_Number); if(Register_Name != NULL) { - snprintf(cx->dis_code, 255, "%-7s %s, r%d", MNemonic[MNemonic_Int], Register_Name, Rr); + snprintf(cx->dis_code, 255, "%-7s %s, r%d", avr_opcodes[mnemo].opcode, Register_Name, Rr); } else { - snprintf(cx->dis_code, 255, "%-7s 0x%02x, r%d", MNemonic[MNemonic_Int], Register_Number, Rr); + snprintf(cx->dis_code, 255, "%-7s 0x%02x, r%d", avr_opcodes[mnemo].opcode, Register_Number, Rr); snprintf(cx->dis_comment, 255, "%d", RA); } } CALLBACK(pop_Callback) { - Operation_Rd(MNemonic_Int); + Operation_Rd(mnemo); } CALLBACK(push_Callback) { - Operation_Rd(MNemonic_Int); + Operation_Rd(mnemo); } CALLBACK(rcall_Callback) { @@ -630,12 +629,12 @@ CALLBACK(rcall_Callback) { Offset -= 8192; Target = FixTargetAddress(Position + Offset + 2); - Register_JumpCall(Position, Target, MNemonic_Int, 1); + Register_JumpCall(Position, Target, mnemo, 1); if(cx->dis_opts.Process_Labels == 0) { if(Offset > 0) { - snprintf(cx->dis_code, 255, "%-7s .+%d", MNemonic[MNemonic_Int], Offset); + snprintf(cx->dis_code, 255, "%-7s .+%d", avr_opcodes[mnemo].opcode, Offset); } else { - snprintf(cx->dis_code, 255, "%-7s .%d", MNemonic[MNemonic_Int], Offset); + snprintf(cx->dis_code, 255, "%-7s .%d", avr_opcodes[mnemo].opcode, Offset); } snprintf(cx->dis_comment, 255, "0x%02x", Target); } else { @@ -643,19 +642,19 @@ CALLBACK(rcall_Callback) { char *LabelComment = NULL; LabelName = Get_Label_Name(Target, &LabelComment); - snprintf(cx->dis_code, 255, "%-7s %s", MNemonic[MNemonic_Int], LabelName); + snprintf(cx->dis_code, 255, "%-7s %s", avr_opcodes[mnemo].opcode, LabelName); if(LabelComment != NULL) snprintf(cx->dis_comment, 255, "%s", LabelComment); } } CALLBACK(ret_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); snprintf(cx->dis_after_code, 255, "\n"); } CALLBACK(reti_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(rjmp_Callback) { @@ -667,13 +666,13 @@ CALLBACK(rjmp_Callback) { Offset -= 8192; Target = FixTargetAddress(Position + Offset + 2); - Register_JumpCall(Position, Target, MNemonic_Int, 0); + Register_JumpCall(Position, Target, mnemo, 0); if(cx->dis_opts.Process_Labels == 0) { if(Offset > 0) { - snprintf(cx->dis_code, 255, "%-7s .+%d", MNemonic[MNemonic_Int], Offset); + snprintf(cx->dis_code, 255, "%-7s .+%d", avr_opcodes[mnemo].opcode, Offset); } else { - snprintf(cx->dis_code, 255, "%-7s .%d", MNemonic[MNemonic_Int], Offset); + snprintf(cx->dis_code, 255, "%-7s .%d", avr_opcodes[mnemo].opcode, Offset); } if(Target >= 0) { snprintf(cx->dis_comment, 255, "0x%02x", Target); @@ -681,141 +680,141 @@ CALLBACK(rjmp_Callback) { snprintf(cx->dis_comment, 255, "-0x%02x - Illegal jump position -- specify flash size!", -Target); } } else { - snprintf(cx->dis_code, 255, "%-7s %s", MNemonic[MNemonic_Int], Get_Label_Name(Target, NULL)); + snprintf(cx->dis_code, 255, "%-7s %s", avr_opcodes[mnemo].opcode, Get_Label_Name(Target, NULL)); } } CALLBACK(ror_Callback) { - Operation_Rd(MNemonic_Int); + Operation_Rd(mnemo); } CALLBACK(sbc_Callback) { - Operation_Rd_Rr(MNemonic_Int); + Operation_Rd_Rr(mnemo); } CALLBACK(sbci_Callback) { - Operation_Rd16_K(MNemonic_Int); + Operation_Rd16_K(mnemo); } CALLBACK(sbi_Callback) { - Operation_A_b(MNemonic_Int); + Operation_A_b(mnemo); } CALLBACK(sbic_Callback) { - Operation_A_b(MNemonic_Int); + Operation_A_b(mnemo); } CALLBACK(sbis_Callback) { - Operation_A_b(MNemonic_Int); + Operation_A_b(mnemo); } CALLBACK(sbiw_Callback) { if(cx->dis_opts.CodeStyle == CODESTYLE_AVR_INSTRUCTION_SET) { - snprintf(cx->dis_code, 255, "%-7s r%d:%d, 0x%02x", MNemonic[MNemonic_Int], 2 * Rd + 25, 2 * Rd + 24, RK); + snprintf(cx->dis_code, 255, "%-7s r%d:%d, 0x%02x", avr_opcodes[mnemo].opcode, 2 * Rd + 25, 2 * Rd + 24, RK); } else { - snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", MNemonic[MNemonic_Int], 2 * Rd + 24, RK); + snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", avr_opcodes[mnemo].opcode, 2 * Rd + 24, RK); } snprintf(cx->dis_comment, 255, "%d", RK); } CALLBACK(sbr_Callback) { - Operation_Rd16_K(MNemonic_Int); + Operation_Rd16_K(mnemo); } CALLBACK(sbrc_Callback) { - Operation_r_b(MNemonic_Int); + Operation_r_b(mnemo); } CALLBACK(sbrs_Callback) { - Operation_r_b(MNemonic_Int); + Operation_r_b(mnemo); } CALLBACK(sec_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(seh_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(sei_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(sen_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(ser_Callback) { - Operation_Rd16(MNemonic_Int); + Operation_Rd16(mnemo); } CALLBACK(ses_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(set_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(sev_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(sez_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(sleep_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(spm_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } CALLBACK(st1_Callback) { - snprintf(cx->dis_code, 255, "%-7s X, r%d", MNemonic[MNemonic_Int], Rr); + snprintf(cx->dis_code, 255, "%-7s X, r%d", avr_opcodes[mnemo].opcode, Rr); } CALLBACK(st2_Callback) { - snprintf(cx->dis_code, 255, "%-7s X+, r%d", MNemonic[MNemonic_Int], Rr); + snprintf(cx->dis_code, 255, "%-7s X+, r%d", avr_opcodes[mnemo].opcode, Rr); } CALLBACK(st3_Callback) { - snprintf(cx->dis_code, 255, "%-7s -X, r%d", MNemonic[MNemonic_Int], Rr); + snprintf(cx->dis_code, 255, "%-7s -X, r%d", avr_opcodes[mnemo].opcode, Rr); } CALLBACK(sty1_Callback) { - snprintf(cx->dis_code, 255, "%-7s Y, r%d", MNemonic[MNemonic_Int], Rr); + snprintf(cx->dis_code, 255, "%-7s Y, r%d", avr_opcodes[mnemo].opcode, Rr); } CALLBACK(sty2_Callback) { - snprintf(cx->dis_code, 255, "%-7s Y+, r%d", MNemonic[MNemonic_Int], Rr); + snprintf(cx->dis_code, 255, "%-7s Y+, r%d", avr_opcodes[mnemo].opcode, Rr); } CALLBACK(sty3_Callback) { - snprintf(cx->dis_code, 255, "%-7s -Y, r%d", MNemonic[MNemonic_Int], Rr); + snprintf(cx->dis_code, 255, "%-7s -Y, r%d", avr_opcodes[mnemo].opcode, Rr); } CALLBACK(sty4_Callback) { - snprintf(cx->dis_code, 255, "%-7s Y+%d, r%d", MNemonic[MNemonic_Int], Rq, Rr); + snprintf(cx->dis_code, 255, "%-7s Y+%d, r%d", avr_opcodes[mnemo].opcode, Rq, Rr); } CALLBACK(stz1_Callback) { - snprintf(cx->dis_code, 255, "%-7s Z, r%d", MNemonic[MNemonic_Int], Rr); + snprintf(cx->dis_code, 255, "%-7s Z, r%d", avr_opcodes[mnemo].opcode, Rr); } CALLBACK(stz2_Callback) { - snprintf(cx->dis_code, 255, "%-7s Z+, r%d", MNemonic[MNemonic_Int], Rr); + snprintf(cx->dis_code, 255, "%-7s Z+, r%d", avr_opcodes[mnemo].opcode, Rr); } CALLBACK(stz3_Callback) { - snprintf(cx->dis_code, 255, "%-7s -Z, r%d", MNemonic[MNemonic_Int], Rr); + snprintf(cx->dis_code, 255, "%-7s -Z, r%d", avr_opcodes[mnemo].opcode, Rr); } CALLBACK(stz4_Callback) { - snprintf(cx->dis_code, 255, "%-7s Z+%d, r%d", MNemonic[MNemonic_Int], Rq, Rr); + snprintf(cx->dis_code, 255, "%-7s Z+%d, r%d", avr_opcodes[mnemo].opcode, Rq, Rr); } CALLBACK(sts_Callback) { @@ -823,24 +822,24 @@ CALLBACK(sts_Callback) { const char *MemAddress; MemAddress = Tagfile_Resolve_Mem_Address(Rk); - snprintf(cx->dis_code, 255, "%-7s 0x%04x, r%d", MNemonic[MNemonic_Int], Rk, Rd); + snprintf(cx->dis_code, 255, "%-7s 0x%04x, r%d", avr_opcodes[mnemo].opcode, Rk, Rd); if(MemAddress) { snprintf(cx->dis_comment, 255, "%s", MemAddress); } } CALLBACK(sub_Callback) { - Operation_Rd_Rr(MNemonic_Int); + Operation_Rd_Rr(mnemo); } CALLBACK(subi_Callback) { - Operation_Rd16_K(MNemonic_Int); + Operation_Rd16_K(mnemo); } CALLBACK(swap_Callback) { - Operation_Rd(MNemonic_Int); + Operation_Rd(mnemo); } CALLBACK(wdr_Callback) { - Operation_Simple(MNemonic_Int); + Operation_Simple(mnemo); } diff --git a/src/disasm_callbacks_assembly.h b/src/disasm_callbacks_assembly.h index b97206d7..a9923f33 100644 --- a/src/disasm_callbacks_assembly.h +++ b/src/disasm_callbacks_assembly.h @@ -25,149 +25,149 @@ JohannesBauer@gmx.de */ -void Operation_Simple(int MNemonic_Int); -void Operation_Rd(int MNemonic_Int); -void Operation_Rd16(int MNemonic_Int); -void Operation_Rd_Rr(int MNemonic_Int); -void Operation_Rd16_Rr16(int MNemonic_Int); -void Operation_Rd16_K(int MNemonic_Int); -void Operation_Rd_K(int MNemonic_Int); -void Operation_RdW_K(int MNemonic_Int); -void Operation_RdW_RrW(int MNemonic_Int); -void Operation_s_k(int MNemonic_Int, int Position); -void Operation_r_b(int MNemonic_Int); -void Operation_Rd_b(int MNemonic_Int); -void Operation_A_b(int MNemonic_Int); -void Operation_s(int MNemonic_Int); -void Operation_k(int MNemonic_Int, int Position, const char *Pseudocode); -void adc_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void add_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void adiw_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void and_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void andi_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void asr_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void bclr_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void bld_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brbc_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brbs_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brcc_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brcs_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void break_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void breq_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brge_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brhc_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brhs_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brid_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brie_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brlo_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brlt_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brmi_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brne_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brpl_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brsh_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brtc_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brts_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brvc_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void brvs_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void bset_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void bst_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void call_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void cbi_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void clc_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void clh_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void cli_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void cln_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void cls_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void clt_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void clv_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void clz_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void com_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void cp_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void cpc_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void cpi_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void cpse_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void dec_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void eicall_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void eijmp_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void elpm1_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void elpm2_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void elpm3_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void eor_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void fmul_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void fmuls_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void fmulsu_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void icall_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ijmp_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void in_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void inc_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void jmp_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ld1_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ld2_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ld3_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ldy1_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ldy2_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ldy3_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ldy4_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ldz1_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ldz2_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ldz3_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ldz4_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ldi_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void lds_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void lpm1_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void lpm2_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void lpm3_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void lsr_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void mov_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void movw_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void mul_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void muls_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void mulsu_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void neg_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void nop_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void or_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ori_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void out_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void pop_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void push_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void rcall_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ret_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void reti_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void rjmp_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ror_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sbc_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sbci_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sbi_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sbic_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sbis_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sbiw_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sbr_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sbrc_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sbrs_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sec_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void seh_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sei_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sen_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ser_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void ses_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void set_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sev_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sez_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sleep_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void spm_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void st1_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void st2_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void st3_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sty1_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sty2_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sty3_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sty4_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void stz1_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void stz2_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void stz3_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void stz4_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sts_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void sub_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void subi_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void swap_Callback(const char *Bitstream, int Position, int MNemonic_Int); -void wdr_Callback(const char *Bitstream, int Position, int MNemonic_Int); +void Operation_Simple(AVR_opcode mnemo); +void Operation_Rd(AVR_opcode mnemo); +void Operation_Rd16(AVR_opcode mnemo); +void Operation_Rd_Rr(AVR_opcode mnemo); +void Operation_Rd16_Rr16(AVR_opcode mnemo); +void Operation_Rd16_K(AVR_opcode mnemo); +void Operation_Rd_K(AVR_opcode mnemo); +void Operation_RdW_K(AVR_opcode mnemo); +void Operation_RdW_RrW(AVR_opcode mnemo); +void Operation_s_k(AVR_opcode mnemo, int Position); +void Operation_r_b(AVR_opcode mnemo); +void Operation_Rd_b(AVR_opcode mnemo); +void Operation_A_b(AVR_opcode mnemo); +void Operation_s(AVR_opcode mnemo); +void Operation_k(AVR_opcode mnemo, int Position, const char *Pseudocode); +void adc_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void add_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void adiw_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void and_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void andi_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void asr_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void bclr_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void bld_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brbc_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brbs_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brcc_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brcs_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void break_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void breq_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brge_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brhc_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brhs_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brid_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brie_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brlo_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brlt_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brmi_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brne_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brpl_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brsh_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brtc_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brts_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brvc_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void brvs_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void bset_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void bst_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void call_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void cbi_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void clc_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void clh_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void cli_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void cln_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void cls_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void clt_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void clv_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void clz_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void com_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void cp_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void cpc_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void cpi_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void cpse_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void dec_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void eicall_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void eijmp_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void elpm1_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void elpm2_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void elpm3_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void eor_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void fmul_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void fmuls_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void fmulsu_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void icall_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ijmp_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void in_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void inc_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void jmp_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ld1_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ld2_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ld3_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ldy1_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ldy2_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ldy3_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ldy4_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ldz1_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ldz2_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ldz3_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ldz4_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ldi_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void lds_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void lpm1_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void lpm2_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void lpm3_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void lsr_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void mov_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void movw_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void mul_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void muls_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void mulsu_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void neg_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void nop_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void or_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ori_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void out_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void pop_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void push_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void rcall_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ret_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void reti_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void rjmp_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ror_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbc_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbci_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbi_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbic_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbis_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbiw_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbr_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbrc_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbrs_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sec_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void seh_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sei_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sen_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ser_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void ses_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void set_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sev_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sez_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sleep_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void spm_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void st1_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void st2_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void st3_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sty1_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sty2_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sty3_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sty4_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void stz1_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void stz2_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void stz3_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void stz4_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sts_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void sub_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void subi_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void swap_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); +void wdr_Callback(const char *Bitstream, int Position, AVR_opcode mnemo); diff --git a/src/disasm_callbacks_pseudocode.c b/src/disasm_callbacks_pseudocode.c index fa420871..a7842113 100644 --- a/src/disasm_callbacks_pseudocode.c +++ b/src/disasm_callbacks_pseudocode.c @@ -30,19 +30,18 @@ #include "libavrdude.h" -#include "disasm_mnemonics.h" #include "disasm_globals.h" #include "disasm_callbacks_pseudocode.h" #include "disasm_jumpcall.h" #include "disasm_ioregisters.h" #include "disasm_tagfile.h" -void PC_Operation_Simple(int MNemonic_Int) { - snprintf(cx->dis_code, 255, "%s", MNemonic[MNemonic_Int]); +void PC_Operation_Simple(AVR_opcode mnemo) { + snprintf(cx->dis_code, 255, "%s", avr_opcodes[mnemo].opcode); } -void PC_Operation_Rd(int MNemonic_Int) { - switch (MNemonic_Int) { +void PC_Operation_Rd(AVR_opcode mnemo) { + switch (mnemo) { case OPCODE_lsl: snprintf(cx->dis_code, 255, "r%d <<= 1;", Rd); snprintf(cx->dis_comment, 255, "_BV(0) = 0 (logical shift)"); @@ -72,16 +71,16 @@ void PC_Operation_Rd(int MNemonic_Int) { snprintf(cx->dis_comment, 255, "0"); break; default: - snprintf(cx->dis_code, 255, "%-7s r%d", MNemonic[MNemonic_Int], Rd); + snprintf(cx->dis_code, 255, "%-7s r%d", avr_opcodes[mnemo].opcode, Rd); } } -void PC_Operation_Rd16(int MNemonic_Int) { - snprintf(cx->dis_code, 255, "%-7s r%d", MNemonic[MNemonic_Int], Rd + 16); +void PC_Operation_Rd16(AVR_opcode mnemo) { + snprintf(cx->dis_code, 255, "%-7s r%d", avr_opcodes[mnemo].opcode, Rd + 16); } -void PC_Operation_Rd_Rr(int MNemonic_Int) { - switch (MNemonic_Int) { +void PC_Operation_Rd_Rr(AVR_opcode mnemo) { + switch (mnemo) { case OPCODE_add: if(Rd != Rr) { snprintf(cx->dis_code, 255, "r%d += r%d;", Rd, Rr); @@ -134,16 +133,16 @@ void PC_Operation_Rd_Rr(int MNemonic_Int) { snprintf(cx->dis_code, 255, "skipif (r%d == r%d)", Rd, Rr); break; default: - snprintf(cx->dis_code, 255, "%-7s r%d, r%d", MNemonic[MNemonic_Int], Rd, Rr); + snprintf(cx->dis_code, 255, "%-7s r%d, r%d", avr_opcodes[mnemo].opcode, Rd, Rr); } } -void PC_Operation_Rd16_Rr16(int MNemonic_Int) { - snprintf(cx->dis_code, 255, "%-7s r%d, r%d", MNemonic[MNemonic_Int], Rd + 16, Rr + 16); +void PC_Operation_Rd16_Rr16(AVR_opcode mnemo) { + snprintf(cx->dis_code, 255, "%-7s r%d, r%d", avr_opcodes[mnemo].opcode, Rd + 16, Rr + 16); } -void PC_Operation_Rd16_K(int MNemonic_Int) { - switch (MNemonic_Int) { +void PC_Operation_Rd16_K(AVR_opcode mnemo) { + switch (mnemo) { case OPCODE_andi: snprintf(cx->dis_code, 255, "r%d &= %d;", Rd + 16, RK); snprintf(cx->dis_comment, 255, "0x%02x", RK); @@ -162,34 +161,34 @@ void PC_Operation_Rd16_K(int MNemonic_Int) { snprintf(cx->dis_comment, 255, "0x%02x", RK); break; default: - snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", MNemonic[MNemonic_Int], Rd + 16, RK); + snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", avr_opcodes[mnemo].opcode, Rd + 16, RK); snprintf(cx->dis_comment, 255, "%d", RK); } } -void PC_Operation_Rd_K(int MNemonic_Int) { - snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", MNemonic[MNemonic_Int], Rd, RK); +void PC_Operation_Rd_K(AVR_opcode mnemo) { + snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", avr_opcodes[mnemo].opcode, Rd, RK); snprintf(cx->dis_comment, 255, "%d", RK); } -void PC_Operation_RdW_K(int MNemonic_Int) { +void PC_Operation_RdW_K(AVR_opcode mnemo) { if(cx->dis_opts.CodeStyle == CODESTYLE_AVR_INSTRUCTION_SET) { - snprintf(cx->dis_code, 255, "%-7s r%d:%d, 0x%02x", MNemonic[MNemonic_Int], Rd + 1, Rd, RK); + snprintf(cx->dis_code, 255, "%-7s r%d:%d, 0x%02x", avr_opcodes[mnemo].opcode, Rd + 1, Rd, RK); } else { - snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", MNemonic[MNemonic_Int], Rd, RK); + snprintf(cx->dis_code, 255, "%-7s r%d, 0x%02x", avr_opcodes[mnemo].opcode, Rd, RK); } snprintf(cx->dis_comment, 255, "%d", RK); } -void PC_Operation_RdW_RrW(int MNemonic_Int) { +void PC_Operation_RdW_RrW(AVR_opcode mnemo) { if(cx->dis_opts.CodeStyle == CODESTYLE_AVR_INSTRUCTION_SET) { - snprintf(cx->dis_code, 255, "%-7s r%d:%d, r%d:%d", MNemonic[MNemonic_Int], (2 * Rd) + 1, 2 * Rd, (2 * Rr) + 1, 2 * Rr); + snprintf(cx->dis_code, 255, "%-7s r%d:%d, r%d:%d", avr_opcodes[mnemo].opcode, (2 * Rd) + 1, 2 * Rd, (2 * Rr) + 1, 2 * Rr); } else { - snprintf(cx->dis_code, 255, "%-7s r%d, r%d", MNemonic[MNemonic_Int], 2 * Rd, 2 * Rr); + snprintf(cx->dis_code, 255, "%-7s r%d, r%d", avr_opcodes[mnemo].opcode, 2 * Rd, 2 * Rr); } } -void PC_Operation_s_k(int MNemonic_Int, int Position) { +void PC_Operation_s_k(AVR_opcode mnemo, int Position) { int Bits, Offset; Bits = Rs; @@ -199,39 +198,39 @@ void PC_Operation_s_k(int MNemonic_Int, int Position) { int Target = FixTargetAddress(Position + Offset + 2); - Register_JumpCall(Position, Target, MNemonic_Int, 0); + Register_JumpCall(Position, Target, mnemo, 0); if(cx->dis_opts.Process_Labels == 0) { if(Offset > 0) { - snprintf(cx->dis_code, 255, "%-7s %d, .+%d", MNemonic[MNemonic_Int], Bits, Offset); + snprintf(cx->dis_code, 255, "%-7s %d, .+%d", avr_opcodes[mnemo].opcode, Bits, Offset); } else { - snprintf(cx->dis_code, 255, "%-7s %d, .%d", MNemonic[MNemonic_Int], Bits, Offset); + snprintf(cx->dis_code, 255, "%-7s %d, .%d", avr_opcodes[mnemo].opcode, Bits, Offset); } snprintf(cx->dis_comment, 255, "0x%02x = %d -> 0x%02x", (1 << Bits), (1 << Bits), Target); } else { - snprintf(cx->dis_code, 255, "%-7s %d, %s", MNemonic[MNemonic_Int], Bits, Get_Label_Name(Target, NULL)); + snprintf(cx->dis_code, 255, "%-7s %d, %s", avr_opcodes[mnemo].opcode, Bits, Get_Label_Name(Target, NULL)); snprintf(cx->dis_comment, 255, "0x%02x = %d", (1 << Bits), (1 << Bits)); } } -void PC_Operation_r_b(int MNemonic_Int) { +void PC_Operation_r_b(AVR_opcode mnemo) { int Register, Bit; Register = Rr; Bit = Rb; - snprintf(cx->dis_code, 255, "%-7s r%d, %d", MNemonic[MNemonic_Int], Register, Bit); + snprintf(cx->dis_code, 255, "%-7s r%d, %d", avr_opcodes[mnemo].opcode, Register, Bit); snprintf(cx->dis_comment, 255, "0x%02x = %d", (1 << Bit), (1 << Bit)); } -void PC_Operation_Rd_b(int MNemonic_Int) { +void PC_Operation_Rd_b(AVR_opcode mnemo) { int Register, Bit; Register = Rd; Bit = Rb; - snprintf(cx->dis_code, 255, "%-7s r%d, %d", MNemonic[MNemonic_Int], Register, Bit); + snprintf(cx->dis_code, 255, "%-7s r%d, %d", avr_opcodes[mnemo].opcode, Register, Bit); snprintf(cx->dis_comment, 255, "0x%02x = %d", (1 << Bit), (1 << Bit)); } -void PC_Operation_A_b(int MNemonic_Int) { +void PC_Operation_A_b(AVR_opcode mnemo) { int Register, Bit; const char *Register_Name; char Register_Value[5]; @@ -243,7 +242,7 @@ void PC_Operation_A_b(int MNemonic_Int) { snprintf(Register_Value, sizeof(Register_Value), "0x%02x", Register); Register_Name = Register_Value; } - switch (MNemonic_Int) { + switch (mnemo) { case OPCODE_cbi: snprintf(cx->dis_code, 255, "IO[%s] &= ~(_BV(%d));", Register_Name, Bit); break; @@ -257,20 +256,20 @@ void PC_Operation_A_b(int MNemonic_Int) { snprintf(cx->dis_code, 255, "skipif (!(IO[%s] & _BV(%d)))", Register_Name, Bit); break; default: - snprintf(cx->dis_code, 255, "%-7s %s, %d", MNemonic[MNemonic_Int], Register_Name, Bit); + snprintf(cx->dis_code, 255, "%-7s %s, %d", avr_opcodes[mnemo].opcode, Register_Name, Bit); } snprintf(cx->dis_comment, 255, "0x%02x = %d", (1 << Bit), (1 << Bit)); } -void PC_Operation_s(int MNemonic_Int) { +void PC_Operation_s(AVR_opcode mnemo) { int Bit; Bit = Rs; - snprintf(cx->dis_code, 255, "%-7s %d", MNemonic[MNemonic_Int], Bit); + snprintf(cx->dis_code, 255, "%-7s %d", avr_opcodes[mnemo].opcode, Bit); snprintf(cx->dis_comment, 255, "0x%02x = %d", (1 << Bit), (1 << Bit)); } -void PC_Operation_k(int MNemonic_Int, int Position, char *Pseudocode) { +void PC_Operation_k(AVR_opcode mnemo, int Position, char *Pseudocode) { int Offset; Offset = (2 * Rk); @@ -279,7 +278,7 @@ void PC_Operation_k(int MNemonic_Int, int Position, char *Pseudocode) { int Target = FixTargetAddress(Position + Offset + 2); - Register_JumpCall(Position, Target, MNemonic_Int, 0); + Register_JumpCall(Position, Target, mnemo, 0); if(cx->dis_opts.Process_Labels == 0) { if(Offset > 0) { snprintf(cx->dis_code, 255, "if (%s) goto .+%d;", Pseudocode, Offset); @@ -295,95 +294,95 @@ void PC_Operation_k(int MNemonic_Int, int Position, char *Pseudocode) { /************* Now to the callback functions *************/ CALLBACK(adc_Callback_PC) { - PC_Operation_Rd_Rr(MNemonic_Int); + PC_Operation_Rd_Rr(mnemo); } CALLBACK(add_Callback_PC) { - PC_Operation_Rd_Rr(MNemonic_Int); + PC_Operation_Rd_Rr(mnemo); } CALLBACK(sub_Callback_PC) { - PC_Operation_Rd_Rr(MNemonic_Int); + PC_Operation_Rd_Rr(mnemo); } CALLBACK(sbc_Callback_PC) { - PC_Operation_Rd_Rr(MNemonic_Int); + PC_Operation_Rd_Rr(mnemo); } CALLBACK(mov_Callback_PC) { - PC_Operation_Rd_Rr(MNemonic_Int); + PC_Operation_Rd_Rr(mnemo); } CALLBACK(brcc_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "!Carry"); + PC_Operation_k(mnemo, Position, "!Carry"); } CALLBACK(brcs_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "Carry"); + PC_Operation_k(mnemo, Position, "Carry"); } CALLBACK(breq_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "c1 == c2"); + PC_Operation_k(mnemo, Position, "c1 == c2"); } CALLBACK(brge_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "c1 (signed)>= c2"); + PC_Operation_k(mnemo, Position, "c1 (signed)>= c2"); } CALLBACK(brhc_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "!HalfCarry"); + PC_Operation_k(mnemo, Position, "!HalfCarry"); } CALLBACK(brhs_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "HalfCarry"); + PC_Operation_k(mnemo, Position, "HalfCarry"); } CALLBACK(brid_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "Global_Interrupts_Disabled()"); + PC_Operation_k(mnemo, Position, "Global_Interrupts_Disabled()"); } CALLBACK(brie_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "Global_Interrupts_Enabled()"); + PC_Operation_k(mnemo, Position, "Global_Interrupts_Enabled()"); } CALLBACK(brlo_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "c1 (unsigned)< c2"); + PC_Operation_k(mnemo, Position, "c1 (unsigned)< c2"); } CALLBACK(brlt_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "c1 (signed)< c2"); + PC_Operation_k(mnemo, Position, "c1 (signed)< c2"); } CALLBACK(brmi_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "< 0"); + PC_Operation_k(mnemo, Position, "< 0"); } CALLBACK(brne_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "c1 != c2"); + PC_Operation_k(mnemo, Position, "c1 != c2"); } CALLBACK(brpl_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "> 0"); + PC_Operation_k(mnemo, Position, "> 0"); } CALLBACK(brsh_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "c1 (unsigned)>= c2"); + PC_Operation_k(mnemo, Position, "c1 (unsigned)>= c2"); } CALLBACK(brtc_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "T == 0"); + PC_Operation_k(mnemo, Position, "T == 0"); } CALLBACK(brts_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "T == 1"); + PC_Operation_k(mnemo, Position, "T == 1"); } CALLBACK(brvc_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "Overflow == 0"); + PC_Operation_k(mnemo, Position, "Overflow == 0"); } CALLBACK(brvs_Callback_PC) { - PC_Operation_k(MNemonic_Int, Position, "Overflow == 1"); + PC_Operation_k(mnemo, Position, "Overflow == 1"); } CALLBACK(out_Callback_PC) { @@ -433,23 +432,23 @@ CALLBACK(reti_Callback_PC) { } CALLBACK(andi_Callback_PC) { - PC_Operation_Rd16_K(MNemonic_Int); + PC_Operation_Rd16_K(mnemo); } CALLBACK(subi_Callback_PC) { - PC_Operation_Rd16_K(MNemonic_Int); + PC_Operation_Rd16_K(mnemo); } CALLBACK(sbci_Callback_PC) { - PC_Operation_Rd16_K(MNemonic_Int); + PC_Operation_Rd16_K(mnemo); } CALLBACK(sbr_Callback_PC) { - PC_Operation_Rd16_K(MNemonic_Int); + PC_Operation_Rd16_K(mnemo); } CALLBACK(ori_Callback_PC) { - PC_Operation_Rd16_K(MNemonic_Int); + PC_Operation_Rd16_K(mnemo); } CALLBACK(ldi_Callback_PC) { @@ -487,7 +486,7 @@ CALLBACK(call_Callback_PC) { int Pos; Pos = FixTargetAddress(2 * Rk); - Register_JumpCall(Position, Pos, MNemonic_Int, 1); + Register_JumpCall(Position, Pos, mnemo, 1); if(cx->dis_opts.Process_Labels == 0) { snprintf(cx->dis_code, 255, "0x%02x();", Pos); } else { @@ -511,7 +510,7 @@ CALLBACK(rcall_Callback_PC) { int Target = FixTargetAddress(Position + Offset + 2); - Register_JumpCall(Position, Target, MNemonic_Int, 1); + Register_JumpCall(Position, Target, mnemo, 1); if(!cx->dis_opts.Process_Labels) { snprintf(cx->dis_comment, 255, "0x%02x();", Target); } else { @@ -527,22 +526,22 @@ CALLBACK(rcall_Callback_PC) { } CALLBACK(ror_Callback_PC) { - PC_Operation_Rd(MNemonic_Int); + PC_Operation_Rd(mnemo); } CALLBACK(lsr_Callback_PC) { - PC_Operation_Rd(MNemonic_Int); + PC_Operation_Rd(mnemo); } CALLBACK(swap_Callback_PC) { - PC_Operation_Rd(MNemonic_Int); + PC_Operation_Rd(mnemo); } CALLBACK(eor_Callback_PC) { if(Rd == Rr) { PC_Operation_Rd(OPCODE_clr); } else { - PC_Operation_Rd_Rr(MNemonic_Int); + PC_Operation_Rd_Rr(mnemo); } } @@ -555,7 +554,7 @@ CALLBACK(jmp_Callback_PC) { } else { snprintf(cx->dis_code, 255, "goto %s;", Get_Label_Name(Pos, NULL)); } - Register_JumpCall(Position, Pos, MNemonic_Int, 0); + Register_JumpCall(Position, Pos, mnemo, 0); } CALLBACK(rjmp_Callback_PC) { @@ -567,7 +566,7 @@ CALLBACK(rjmp_Callback_PC) { int Target = FixTargetAddress(Position + Offset + 2); - Register_JumpCall(Position, Target, MNemonic_Int, 0); + Register_JumpCall(Position, Target, mnemo, 0); if(cx->dis_opts.Process_Labels == 0) { if(Offset > 0) { @@ -595,7 +594,7 @@ CALLBACK(cpi_Callback_PC) { } CALLBACK(asr_Callback_PC) { - PC_Operation_Rd(MNemonic_Int); + PC_Operation_Rd(mnemo); } CALLBACK(dec_Callback_PC) { @@ -607,43 +606,43 @@ CALLBACK(inc_Callback_PC) { } CALLBACK(cp_Callback_PC) { - PC_Operation_Rd_Rr(MNemonic_Int); + PC_Operation_Rd_Rr(mnemo); } CALLBACK(cpc_Callback_PC) { - PC_Operation_Rd_Rr(MNemonic_Int); + PC_Operation_Rd_Rr(mnemo); } CALLBACK(cpse_Callback_PC) { - PC_Operation_Rd_Rr(MNemonic_Int); + PC_Operation_Rd_Rr(mnemo); } CALLBACK(and_Callback_PC) { - PC_Operation_Rd_Rr(MNemonic_Int); + PC_Operation_Rd_Rr(mnemo); } CALLBACK(or_Callback_PC) { - PC_Operation_Rd_Rr(MNemonic_Int); + PC_Operation_Rd_Rr(mnemo); } CALLBACK(mul_Callback_PC) { - PC_Operation_Rd_Rr(MNemonic_Int); + PC_Operation_Rd_Rr(mnemo); } CALLBACK(sbi_Callback_PC) { - PC_Operation_A_b(MNemonic_Int); + PC_Operation_A_b(mnemo); } CALLBACK(sbic_Callback_PC) { - PC_Operation_A_b(MNemonic_Int); + PC_Operation_A_b(mnemo); } CALLBACK(sbis_Callback_PC) { - PC_Operation_A_b(MNemonic_Int); + PC_Operation_A_b(mnemo); } CALLBACK(cbi_Callback_PC) { - PC_Operation_A_b(MNemonic_Int); + PC_Operation_A_b(mnemo); } CALLBACK(ser_Callback_PC) { diff --git a/src/disasm_callbacks_pseudocode.h b/src/disasm_callbacks_pseudocode.h index 36bf2f01..0d3fc92d 100644 --- a/src/disasm_callbacks_pseudocode.h +++ b/src/disasm_callbacks_pseudocode.h @@ -25,82 +25,82 @@ JohannesBauer@gmx.de */ -void PC_Operation_Simple(int MNemonic_Int); -void PC_Operation_Rd(int MNemonic_Int); -void PC_Operation_Rd16(int MNemonic_Int); -void PC_Operation_Rd_Rr(int MNemonic_Int); -void PC_Operation_Rd16_Rr16(int MNemonic_Int); -void PC_Operation_Rd16_K(int MNemonic_Int); -void PC_Operation_Rd_K(int MNemonic_Int); -void PC_Operation_RdW_K(int MNemonic_Int); -void PC_Operation_RdW_RrW(int MNemonic_Int); -void PC_Operation_s_k(int MNemonic_Int, int Position); -void PC_Operation_r_b(int MNemonic_Int); -void PC_Operation_Rd_b(int MNemonic_Int); -void PC_Operation_A_b(int MNemonic_Int); -void PC_Operation_s(int MNemonic_Int); -void PC_Operation_k(int MNemonic_Int, int Position, char *Pseudocode); -void adc_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void add_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void sub_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void sbc_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void mov_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brcc_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brcs_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void breq_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brge_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brhc_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brhs_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brid_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brie_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brlo_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brlt_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brmi_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brne_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brpl_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brsh_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brtc_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brts_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brvc_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void brvs_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void out_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void in_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void cli_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void sei_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void ret_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void reti_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void andi_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void subi_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void sbci_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void sbr_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void ori_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void ldi_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void lds_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void sts_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void call_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void rcall_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void ror_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void lsr_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void swap_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void eor_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void jmp_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void rjmp_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void cpi_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void asr_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void dec_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void inc_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void cp_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void cpc_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void cpse_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void and_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void or_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void mul_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void sbi_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void sbic_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void sbis_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void cbi_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void ser_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void adiw_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void movw_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void lpm1_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); -void st2_Callback_PC(const char *Bitstream, int Position, int MNemonic_Int); +void PC_Operation_Simple(AVR_opcode mnemo); +void PC_Operation_Rd(AVR_opcode mnemo); +void PC_Operation_Rd16(AVR_opcode mnemo); +void PC_Operation_Rd_Rr(AVR_opcode mnemo); +void PC_Operation_Rd16_Rr16(AVR_opcode mnemo); +void PC_Operation_Rd16_K(AVR_opcode mnemo); +void PC_Operation_Rd_K(AVR_opcode mnemo); +void PC_Operation_RdW_K(AVR_opcode mnemo); +void PC_Operation_RdW_RrW(AVR_opcode mnemo); +void PC_Operation_s_k(AVR_opcode mnemo, int Position); +void PC_Operation_r_b(AVR_opcode mnemo); +void PC_Operation_Rd_b(AVR_opcode mnemo); +void PC_Operation_A_b(AVR_opcode mnemo); +void PC_Operation_s(AVR_opcode mnemo); +void PC_Operation_k(AVR_opcode mnemo, int Position, char *Pseudocode); +void adc_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void add_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void sub_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbc_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void mov_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brcc_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brcs_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void breq_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brge_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brhc_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brhs_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brid_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brie_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brlo_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brlt_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brmi_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brne_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brpl_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brsh_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brtc_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brts_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brvc_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void brvs_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void out_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void in_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void cli_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void sei_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void ret_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void reti_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void andi_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void subi_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbci_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbr_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void ori_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void ldi_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void lds_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void sts_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void call_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void rcall_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void ror_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void lsr_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void swap_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void eor_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void jmp_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void rjmp_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void cpi_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void asr_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void dec_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void inc_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void cp_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void cpc_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void cpse_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void and_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void or_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void mul_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbi_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbic_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void sbis_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void cbi_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void ser_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void adiw_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void movw_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void lpm1_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); +void st2_Callback_PC(const char *Bitstream, int Position, AVR_opcode mnemo); diff --git a/src/disasm_globals.h b/src/disasm_globals.h index be61bddb..8aa8ba9a 100644 --- a/src/disasm_globals.h +++ b/src/disasm_globals.h @@ -34,7 +34,7 @@ #define Rb (cx->dis_regs['b']) #define Rq (cx->dis_regs['q']) -#define CALLBACK(name) void name(const char *Bitstream, int Position, int MNemonic_Int) +#define CALLBACK(name) void name(const char *Bitstream, int Position, AVR_opcode mnemo) struct JumpCall { int From; @@ -50,141 +50,3 @@ struct IO_Register { unsigned char Used; }; -enum { - OPCODE_adc, - OPCODE_add, - OPCODE_adiw, - OPCODE_and, - OPCODE_andi, - OPCODE_asr, - OPCODE_bclr, - OPCODE_bld, - OPCODE_brbc, - OPCODE_brbs, - OPCODE_brcc, - OPCODE_brcs, - OPCODE_break, - OPCODE_breq, - OPCODE_brge, - OPCODE_brhc, - OPCODE_brhs, - OPCODE_brid, - OPCODE_brie, - OPCODE_brlo, - OPCODE_brlt, - OPCODE_brmi, - OPCODE_brne, - OPCODE_brpl, - OPCODE_brsh, - OPCODE_brtc, - OPCODE_brts, - OPCODE_brvc, - OPCODE_brvs, - OPCODE_bset, - OPCODE_bst, - OPCODE_call, - OPCODE_cbi, - OPCODE_cbr, - OPCODE_clc, - OPCODE_clh, - OPCODE_cli, - OPCODE_cln, - OPCODE_clr, - OPCODE_cls, - OPCODE_clt, - OPCODE_clv, - OPCODE_clz, - OPCODE_com, - OPCODE_cp, - OPCODE_cpc, - OPCODE_cpi, - OPCODE_cpse, - OPCODE_dec, - OPCODE_eicall, - OPCODE_eijmp, - OPCODE_elpm_1, - OPCODE_elpm_2, - OPCODE_elpm_3, - OPCODE_eor, - OPCODE_fmul, - OPCODE_fmuls, - OPCODE_fmulsu, - OPCODE_icall, - OPCODE_ijmp, - OPCODE_in, - OPCODE_inc, - OPCODE_jmp, - OPCODE_ld_1, - OPCODE_ld_2, - OPCODE_ld_3, - OPCODE_ld_4, - OPCODE_ld_5, - OPCODE_ld_6, - OPCODE_ldd_1, - OPCODE_ld_7, - OPCODE_ld_8, - OPCODE_ld_9, - OPCODE_ldd_2, - OPCODE_ldi, - OPCODE_lds, - OPCODE_lpm_1, - OPCODE_lpm_2, - OPCODE_lpm_3, - OPCODE_lsl, - OPCODE_lsr, - OPCODE_mov, - OPCODE_movw, - OPCODE_mul, - OPCODE_muls, - OPCODE_mulsu, - OPCODE_neg, - OPCODE_nop, - OPCODE_or, - OPCODE_ori, - OPCODE_out, - OPCODE_pop, - OPCODE_push, - OPCODE_rcall, - OPCODE_ret, - OPCODE_reti, - OPCODE_rjmp, - OPCODE_rol, - OPCODE_ror, - OPCODE_sbc, - OPCODE_sbci, - OPCODE_sbi, - OPCODE_sbic, - OPCODE_sbis, - OPCODE_sbiw, - OPCODE_sbr, - OPCODE_sbrc, - OPCODE_sbrs, - OPCODE_sec, - OPCODE_seh, - OPCODE_sei, - OPCODE_sen, - OPCODE_ser, - OPCODE_ses, - OPCODE_set, - OPCODE_sev, - OPCODE_sez, - OPCODE_sleep, - OPCODE_spm, - OPCODE_st_1, - OPCODE_st_2, - OPCODE_st_3, - OPCODE_st_4, - OPCODE_st_5, - OPCODE_st_6, - OPCODE_std_1, - OPCODE_st_7, - OPCODE_st_8, - OPCODE_st_9, - OPCODE_std_2, - OPCODE_sts, - OPCODE_sub, - OPCODE_subi, - OPCODE_swap, - OPCODE_tst, - OPCODE_wdr, -}; diff --git a/src/disasm_jumpcall.c b/src/disasm_jumpcall.c index 80355032..116076ed 100644 --- a/src/disasm_jumpcall.c +++ b/src/disasm_jumpcall.c @@ -32,7 +32,6 @@ #include "libavrdude.h" #include "disasm_globals.h" -#include "disasm_mnemonics.h" #include "disasm_tagfile.h" #include "disasm_jumpcall.h" @@ -45,7 +44,7 @@ void Display_JumpCalls() { printf("%d jumps/calls found:\n", JumpCall_Count); for(i = 0; i < JumpCall_Count; i++) { printf("%3d: 0x%-4x -> 0x%-4x %s (%d)\n", i, (unsigned int) JumpCalls[i].From, (unsigned int) JumpCalls[i].To, - MNemonic[JumpCalls[i].Type], JumpCalls[i].FunctionCall); + avr_opcodes[JumpCalls[i].Type].opcode, JumpCalls[i].FunctionCall); } } @@ -180,7 +179,7 @@ void Print_JumpCalls(int Position) { printf("\n"); Match = 1; } - printf("; Referenced from offset 0x%02x by %s\n", JumpCalls[i].From, MNemonic[JumpCalls[i].Type]); + printf("; Referenced from offset 0x%02x by %s\n", JumpCalls[i].From, avr_opcodes[JumpCalls[i].Type].opcode); } } if(Match == 1) { diff --git a/src/disasm_mnemonics.c b/src/disasm_mnemonics.c deleted file mode 100644 index c660f7e9..00000000 --- a/src/disasm_mnemonics.c +++ /dev/null @@ -1,447 +0,0 @@ - -/* - avrdisas - A disassembler for AVR microcontroller units - Copyright (C) 2007 Johannes Bauer - - This file is part of avrdisas. - - avrdisas is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - avrdisas is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with avrdisas; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Johannes Bauer - Mussinanstr. 140 - 92318 Neumarkt/Opf. - JohannesBauer@gmx.de -*/ - -#include - -#include "libavrdude.h" - -const char *MNemonic[] = { - "adc", - "add", - "adiw", - "and", - "andi", - "asr", - "bclr", - "bld", - "brbc", - "brbs", - "brcc", - "brcs", - "break", - "breq", - "brge", - "brhc", - "brhs", - "brid", - "brie", - "brlo", - "brlt", - "brmi", - "brne", - "brpl", - "brsh", - "brtc", - "brts", - "brvc", - "brvs", - "bset", - "bst", - "call", - "cbi", - "cbr", - "clc", - "clh", - "cli", - "cln", - "clr", - "cls", - "clt", - "clv", - "clz", - "com", - "cp", - "cpc", - "cpi", - "cpse", - "dec", - "eicall", - "eijmp", - "elpm", - "elpm", - "elpm", - "eor", - "fmul", - "fmuls", - "fmulsu", - "icall", - "ijmp", - "in", - "inc", - "jmp", - "ld", - "ld", - "ld", - "ld", - "ld", - "ld", - "ldd", - "ld", - "ld", - "ld", - "ldd", - "ldi", - "lds", - "lpm", - "lpm", - "lpm", - "lsl", - "lsr", - "mov", - "movw", - "mul", - "muls", - "mulsu", - "neg", - "nop", - "or", - "ori", - "out", - "pop", - "push", - "rcall", - "ret", - "reti", - "rjmp", - "rol", - "ror", - "sbc", - "sbci", - "sbi", - "sbic", - "sbis", - "sbiw", - "sbr", - "sbrc", - "sbrs", - "sec", - "seh", - "sei", - "sen", - "ser", - "ses", - "set", - "sev", - "sez", - "sleep", - "spm", - "st", - "st", - "st", - "st", - "st", - "st", - "std", - "st", - "st", - "st", - "std", - "sts", - "sub", - "subi", - "swap", - "tst", - "wdr" -}; - -const char *Cycles[] = { - "1", // adc - "1", // add - "2", // adiw - "1", // and - "1", // andi - "1", // asr - "1", // bclr - "1", // bld - "1/2", // brbc - "1/2", // brbs - "1/2", // brcc - "1/2", // brcs - "N/A", // break - "1/2", // breq - "1/2", // brge - "1/2", // brhc - "1/2", // brhs - "1/2", // brid - "1/2", // brie - "1/2", // brlo - "1/2", // brlt - "1/2", // brmi - "1/2", // brne - "1/2", // brpl - "1/2", // brsh - "1/2", // brtc - "1/2", // brts - "1/2", // brvc - "1/2", // brvs - "1", // bset - "1", // bst - "4", // call - "2", // cbi - "1", // cbr - "1", // clc - "", // clh - "1", // cli - "1", // cln - "1", // clr - "1", // cls - "1", // clt - "1", // clv - "1", // clz - "1", // com - "1", // cp - "1", // cpc - "1", // cpi - "1-3", // cpse - "1", // dec - NULL, - NULL, - NULL, - NULL, - NULL, - "1", // eor - "2", // fmul - "2", // fmuls - "2", // fmulsu - "3", // icall - "2", // ijmp - "1", // in - "1", // inc - "3", // jmp - "2", // ld - "2", // ld - "2", // ld - "2", // ld - "2", // ld - "2", // ld - "2", // ldd - "2", // ld - "2", // ld - "2", // ld - "2", // ldd - "1", // ldi - "2", // lds - "3", // lpm - "3", // lpm - "3", // lpm - "1", // lsl - "1", // lsr - "1", // mov - "1", // movw - "2", // mul - "2", // muls - "2", // mulsu - "1", // neg - "1", // nop - "1", // or - "1", // ori - "1", // out - "2", // pop - "2", // push - "3", // rcall - "4", // ret - "4", // reti - "2", // rjmp - "1", // rol - "1", // ror - "1", // sbc - "1", // sbci - "2", // sbi - "1-3", // sbic - "1-3", // sbis - "2", // sbiw - "1", // sbr - "1-3", // sbrc - "1-3", // sbrs - "1", // sec - "1", // seh - "1", // sei - "1", // sen - "1", // ser - "1", // ses - "1", // set - "1", // sev - "1", // sez - "1", // sleep - "-", // spm - "2", // st - "2", // st - "2", // st - "2", // st - "2", // st - "2", // st - "2", // std - "2", // st - "2", // st - "2", // st - "2", // std - "2", // sts - "1", // sub - "1", // subi - "1", // swap - "1", // tst - "1" // wdr -}; - -/* -adc -add -adiw -and -andi -asr -bclr -bld -brbc -brbs -brcc -brcs -break -breq -brge -brhc -brhs -brid -brie -brlo -brlt -brmi -brne -brpl -brsh -brtc -brts -brvc -brvs -bset -bst -call -cbi -cbr -clc -clh -cli -cln -clr -cls -clt -clv -clz -com -cp -cpc -cpi -cpse -dec -eicall -eijmp -elpm -elpm -elpm -eor -fmul -fmuls -fmulsu -icall -ijmp -in -inc -jmp -ld -ld -ld -ld -ld -ld -ldd -ld -ld -ld -ldd -ldi -lds -lpm -lpm -lpm -lsl -lsr -mov -movw -mul -muls -mulsu -neg -nop -or -ori -out -pop -push -rcall -ret -reti -rjmp -rol -ror -sbc -sbci -sbi -sbic -sbis -sbiw -sbr -sbrc -sbrs -sec -seh -sei -sen -ser -ses -set -sev -sez -sleep -spm -st -st -st -st -st -st -std -st -st -st -std -sts -sub -subi -swap -tst -wdr -*/ diff --git a/src/disasm_mnemonics.h b/src/disasm_mnemonics.h deleted file mode 100644 index 516fd4a4..00000000 --- a/src/disasm_mnemonics.h +++ /dev/null @@ -1,29 +0,0 @@ - -/* - avrdisas - A disassembler for AVR microcontroller units - Copyright (C) 2007 Johannes Bauer - - This file is part of avrdisas. - - avrdisas is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - avrdisas is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with avrdisas; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Johannes Bauer - Mussinanstr. 140 - 92318 Neumarkt/Opf. - JohannesBauer@gmx.de -*/ - -extern const char *MNemonic[]; -extern const char *Cycles[]; diff --git a/src/libavrdude.h b/src/libavrdude.h index f3b07c4b..707b6eb5 100644 --- a/src/libavrdude.h +++ b/src/libavrdude.h @@ -1460,12 +1460,77 @@ typedef struct { int FlashSize; } Disasm_options; +typedef enum { + OPCODE_add, OPCODE_adc, OPCODE_adiw, OPCODE_sub, + OPCODE_subi, OPCODE_sbc, OPCODE_sbci, OPCODE_sbiw, + OPCODE_and, OPCODE_andi, OPCODE_or, OPCODE_ori, + OPCODE_eor, OPCODE_com, OPCODE_neg, OPCODE_sbr, + OPCODE_cbr, OPCODE_inc, OPCODE_dec, OPCODE_tst, + OPCODE_clr, OPCODE_ser, OPCODE_mul, OPCODE_muls, + OPCODE_mulsu, OPCODE_fmul, OPCODE_fmuls, OPCODE_fmulsu, + OPCODE_des, OPCODE_rjmp, OPCODE_ijmp, OPCODE_eijmp, + OPCODE_jmp, OPCODE_rcall, OPCODE_icall, OPCODE_eicall, + OPCODE_call, OPCODE_ret, OPCODE_reti, OPCODE_cpse, + OPCODE_cp, OPCODE_cpc, OPCODE_cpi, OPCODE_sbrc, + OPCODE_sbrs, OPCODE_sbic, OPCODE_sbis, OPCODE_brcs, + OPCODE_brlo, OPCODE_breq, OPCODE_brmi, OPCODE_brvs, + OPCODE_brlt, OPCODE_brhs, OPCODE_brts, OPCODE_brie, + OPCODE_brbs, OPCODE_brcc, OPCODE_brsh, OPCODE_brne, + OPCODE_brpl, OPCODE_brvc, OPCODE_brge, OPCODE_brhc, + OPCODE_brtc, OPCODE_brid, OPCODE_brbc, OPCODE_mov, + OPCODE_movw, OPCODE_ldi, OPCODE_lds, OPCODE_lds_rc, + OPCODE_ld_1, OPCODE_ld_2, OPCODE_ld_3, OPCODE_ld_4, + OPCODE_ld_5, OPCODE_ld_6, OPCODE_ldd_1, OPCODE_ld_7, + OPCODE_ld_8, OPCODE_ld_9, OPCODE_ldd_2, OPCODE_sts, + OPCODE_sts_rc, OPCODE_st_1, OPCODE_st_2, OPCODE_st_3, + OPCODE_st_4, OPCODE_st_5, OPCODE_st_6, OPCODE_std_1, + OPCODE_st_7, OPCODE_st_8, OPCODE_st_9, OPCODE_std_2, + OPCODE_lpm_1, OPCODE_lpm_2, OPCODE_lpm_3, OPCODE_elpm_1, + OPCODE_elpm_2, OPCODE_elpm_3, OPCODE_spm, OPCODE_spm_zz, + OPCODE_in, OPCODE_out, OPCODE_push, OPCODE_pop, + OPCODE_xch, OPCODE_las, OPCODE_lac, OPCODE_lat, + OPCODE_lsl, OPCODE_lsr, OPCODE_rol, OPCODE_ror, + OPCODE_asr, OPCODE_swap, OPCODE_bset, OPCODE_bclr, + OPCODE_sbi, OPCODE_cbi, OPCODE_bst, OPCODE_bld, + OPCODE_sec, OPCODE_clc, OPCODE_sen, OPCODE_cln, + OPCODE_sez, OPCODE_clz, OPCODE_sei, OPCODE_cli, + OPCODE_ses, OPCODE_cls, OPCODE_sev, OPCODE_clv, + OPCODE_set, OPCODE_clt, OPCODE_seh, OPCODE_clh, + OPCODE_break, OPCODE_nop, OPCODE_sleep, OPCODE_wdr, + OPCODE_x_nop_1, OPCODE_x_nop_2, OPCODE_x_nop_3, OPCODE_x_nop_4, + OPCODE_x_nop_5, OPCODE_x_nop_6, OPCODE_x_nop_7, OPCODE_x_icall, + OPCODE_x_eicall, OPCODE_x_ret, OPCODE_x_reti, OPCODE_x_nop_8, + OPCODE_x_nop_9, OPCODE_x_nop_a, OPCODE_x_ijmp, OPCODE_x_eijmp, + OPCODE_x_bld, OPCODE_x_bst, OPCODE_x_sbrc, OPCODE_x_sbrs, +} AVR_opcode; + typedef struct { char *Opcode_String; - void (*Callback)(const char *, int, int); - int MNemonic; + void (*Callback)(const char *, int, AVR_opcode); + AVR_opcode mnemo; } Disasm_opcode; + + +typedef struct { + int mask, value, nwords; + const char *opcode_bits; // Eg, "0000 11rd dddd rrrr" + AVR_opcode mnemo; // OPCODE_add, ... + const char + *opcode, // "add" + *operands, // "Rd, Rr" + *description, // "Add without Carry" + *operation, // "Rd ← Rd+Rr" + *flags, // "Z,C,N,V,S,H" + *clocks_e, // Timing for AVRe (extended AVR opcode set) + *clocks_xm, // Timing for AVRxm (XMEGA) + *clocks_xt, // Timing for AVRxt (modern UPDI) + *clocks_rc, // Timing for AVRrc (reduced core) + *note, *remarks; +} AVR_opcode_data; + +extern const AVR_opcode_data avr_opcodes[164]; + #define CODESTYLE_AVR_INSTRUCTION_SET 0 #define CODESTYLE_AVRGCC 1