?? avr.c
字號:
/* Program: revava - Atmel Dis-Assembler File: Avr.C Parts of this are Copyright (C) 1997-1999 Uros Platise The rest of it is Copyright (C) 2001 Daniel J. Winker 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, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/#include <stdio.h>#include <string.h>#include "Avr.h"#include "Error.h"#define FALSE 0#define TRUE (!FALSE)//#define DEBUG_3// The "---" entry at the end is necessary because of the way// TAvr::Word2Instruction signals the calling function that no matching entry// was found. It returns 0 to do that. If TAvr::InstSet[] had the "wdr" entry// just before the NULL entry then an actual "wdr" causes 0 to be returned.TAvr::TInstSet TAvr::InstSet [] = { { "rol", "d", "000111CdddddCCCC", ARG_0_31, ARG_copyArg }, // rol is a special case of adc { "adc", "dr", "000111rdddddrrrr", ARG_0_31, ARG_0_31 }, // rol is a special case of adc { "add", "dr", "000011rdddddrrrr", ARG_0_31, ARG_0_31 }, // Complement of lsl { "adiw", "dK", "10010110KKddKKKK", ARG_24_26_28_30, ARG_0_63 }, { "and", "dr", "001000rdddddrrrr", ARG_0_31, ARG_0_31 }, // tst is a special case of and { "andi", "dK", "0111KKKKddddKKKK", ARG_16_31, ARG_0_255 }, // Complement of cbr { "asr", "d", "1001010ddddd0101", ARG_0_31, ARG_none }, { "bclr", "s", "100101001sss1000", ARG_0_7, ARG_none }, // clz is a special case of bclr { "bld", "db", "1111100ddddd0bbb", ARG_0_31, ARG_0_7 }, { "brlo", "k", "111100kkkkkkk000", ARG_neg64_63, ARG_none }, // brlo is a special case of brbs { "brcs", "k", "111100kkkkkkk000", ARG_neg64_63, ARG_none }, // brcs is a special case of brbs { "breq", "k", "111100kkkkkkk001", ARG_neg64_63, ARG_none }, // breq is a special case of brbs { "brge", "k", "111101kkkkkkk100", ARG_neg64_63, ARG_none }, // brge is a special case of brbc { "brhc", "k", "111101kkkkkkk101", ARG_neg64_63, ARG_none }, { "brhs", "k", "111100kkkkkkk101", ARG_neg64_63, ARG_none }, // brhs is a special case of brbs { "brid", "k", "111101kkkkkkk111", ARG_neg64_63, ARG_none }, { "brie", "k", "111100kkkkkkk111", ARG_neg64_63, ARG_none }, // brie is a special case of brbs { "brlt", "k", "111100kkkkkkk100", ARG_neg64_63, ARG_none }, // brlt is a special case of brbs { "brmi", "k", "111100kkkkkkk010", ARG_neg64_63, ARG_none }, { "brne", "k", "111101kkkkkkk001", ARG_neg64_63, ARG_none }, { "brpl", "k", "111101kkkkkkk010", ARG_neg64_63, ARG_none }, // brpl is a special case of brbc { "brsh", "k", "111101kkkkkkk000", ARG_neg64_63, ARG_none }, { "brcc", "k", "111101kkkkkkk000", ARG_neg64_63, ARG_none }, { "brtc", "k", "111101kkkkkkk110", ARG_neg64_63, ARG_none }, // brtc is a special case of brbc { "brts", "k", "111100kkkkkkk110", ARG_neg64_63, ARG_none }, // brts is a special case of brbs { "brvc", "k", "111101kkkkkkk011", ARG_neg64_63, ARG_none }, { "brvs", "k", "111100kkkkkkk011", ARG_neg64_63, ARG_none }, { "brbc", "sk", "111101kkkkkkksss", ARG_0_7, ARG_neg64_63 }, // brge, brid, brpl, brtc is a special case of brbc { "brbs", "sk", "111100kkkkkkksss", ARG_0_7, ARG_neg64_63 }, // brcs, breq, brhs, brie, brlo, brlt, brts is a special case of brbs { "bset", "s", "100101000sss1000", ARG_0_7, ARG_none }, { "bst", "db", "1111101ddddd0bbb", ARG_0_31, ARG_0_7 },// { "call", "k", "1001010kkkkk111k", ARG_longCall, ARG_none }, // from ava: "Instruction not supported by selected model: call" { "cbi", "Pb", "10011000PPPPPbbb", ARG_0_31, ARG_0_7 }, { "cbr", "dK", "0111KKKKddddKKKK", ARG_16_31, ARG_cm0_cm255 }, // Complement of andi (Really Complement) { "clc", "", "1001010010001000", ARG_none, ARG_none }, { "clh", "", "1001010011011000", ARG_none, ARG_none }, { "cli", "", "1001010011111000", ARG_none, ARG_none }, { "cln", "", "1001010010101000", ARG_none, ARG_none }, { "clr", "d", "001001CdddddCCCC", ARG_0_31, ARG_copyArg }, // Complement of eor { "cls", "", "1001010011001000", ARG_none, ARG_none }, { "clt", "", "1001010011101000", ARG_none, ARG_none }, { "clv", "", "1001010010111000", ARG_none, ARG_none }, { "clz", "", "1001010010011000", ARG_none, ARG_none }, // clz is a special case of bclr { "com", "d", "1001010ddddd0000", ARG_0_31, ARG_none }, { "cp", "dr", "000101rdddddrrrr", ARG_0_31, ARG_0_31 }, { "cpc", "dr", "000001rdddddrrrr", ARG_0_31, ARG_0_31 }, { "cpi", "dK", "0011KKKKddddKKKK", ARG_16_31, ARG_0_255 }, { "cpse", "dr", "000100rdddddrrrr", ARG_0_31, ARG_0_31 }, { "dec", "d", "1001010ddddd1010", ARG_0_31, ARG_none }, { "eor", "dr", "001001rdddddrrrr", ARG_0_31, ARG_0_31 }, // Complement of clr { "icall","", "1001010100001001", ARG_none, ARG_none }, { "ijmp", "", "1001010000001001", ARG_none, ARG_none }, { "in", "dP", "10110PPdddddPPPP", ARG_0_31, ARG_0_63 }, { "inc", "d", "1001010ddddd0011", ARG_0_31, ARG_none },// { "jmp", "k", "1001010kkkkk110k", ARG_longCall, ARG_none }, // from ava: "Instruction not supported by selected model: jmp" { "ld", "dX", "1001000ddddd1100", ARG_0_31, ARG_specialX }, { "ld", "dX", "1001000ddddd1101", ARG_0_31, ARG_specialIncX }, { "ld", "dX", "1001000ddddd1110", ARG_0_31, ARG_specialDecX }, { "ld", "dY", "1000000ddddd1000", ARG_0_31, ARG_specialY }, // ld4 is a special case of ldd1 { "ld", "dY", "1001000ddddd1001", ARG_0_31, ARG_specialIncY }, { "ld", "dY", "1001000ddddd1010", ARG_0_31, ARG_specialDecY }, { "ld", "dZ", "1000000ddddd0000", ARG_0_31, ARG_specialZ }, // ld7 is a special case of ldd2 { "ld", "dZ", "1001000ddddd0001", ARG_0_31, ARG_specialIncZ }, { "ld", "dZ", "1001000ddddd0010", ARG_0_31, ARG_specialDecZ }, { "ldd", "dY", "10Y0YY0ddddd1YYY", ARG_0_31, ARG_0_63 }, { "ldd", "dZ", "10Z0ZZ0ddddd0ZZZ", ARG_0_31, ARG_0_63 }, { "ldi", "dK", "1110KKKKddddKKKK", ARG_16_31, ARG_0_255 }, { "lds", "dK", "1001000ddddd0000", ARG_0_31, ARG_longCall }, { "lpm", "", "1001010111001000", ARG_none, ARG_none }, { "lpm", "dZ", "1001000ddddd0100", ARG_0_31, ARG_specialZ }, { "lpm", "dZ", "1001000ddddd0101", ARG_0_31, ARG_specialIncZ }, { "lsl", "d", "000011CdddddCCCC", ARG_0_31, ARG_copyArg }, // Complement of add { "lsr", "d", "1001010ddddd0110", ARG_0_31, ARG_none }, { "mov", "dr", "001011rdddddrrrr", ARG_0_31, ARG_0_31 }, { "movw", "dr", "00000001ddddrrrr", ARG_0_PAIR, ARG_0_PAIR }, //todo: { "mul", "dr", "100111rdddddrrrr", ARG_0_31, ARG_0_31 }, // from ava: "Instruction not supported by selected model: mul" { "neg", "d", "1001010ddddd0001", ARG_0_31, ARG_none }, { "nop", "", "0000000000000000", ARG_none, ARG_none }, { "or", "dr", "001010rdddddrrrr", ARG_0_31, ARG_0_31 }, { "ori", "dK", "0110KKKKddddKKKK", ARG_16_31, ARG_0_255 }, // Complement of sbr { "out", "Pr", "10111PPrrrrrPPPP", ARG_0_63, ARG_0_31 }, { "pop", "d", "1001000ddddd1111", ARG_0_31, ARG_none }, { "push", "d", "1001001ddddd1111", ARG_0_31, ARG_none }, { "rcall","k", "1101kkkkkkkkkkkk", ARG_neg2KB_2KB, ARG_none }, { "ret", "", "1001010100001000", ARG_none, ARG_none }, { "reti", "", "1001010100011000", ARG_none, ARG_none }, { "rjmp", "k", "1100kkkkkkkkkkkk", ARG_neg2KB_2KB, ARG_none }, { "ror", "d", "1001010ddddd0111", ARG_0_31, ARG_none }, { "sbc", "dr", "000010rdddddrrrr", ARG_0_31, ARG_0_31 }, { "sbci", "dK", "0100KKKKddddKKKK", ARG_16_31, ARG_0_255 }, { "sbi", "pb", "10011010pppppbbb", ARG_0_31, ARG_0_7 }, { "sbic", "pb", "10011001pppppbbb", ARG_0_31, ARG_0_7 }, { "sbis", "pb", "10011011pppppbbb", ARG_0_31, ARG_0_7 }, { "sbiw", "dK", "10010111KKddKKKK", ARG_24_26_28_30, ARG_0_63 }, { "sbr", "dK", "0110KKKKddddKKKK", ARG_16_31, ARG_0_255 }, // Complement of ori { "sbrc", "rb", "1111110rrrrr0bbb", ARG_0_31, ARG_0_7 }, { "sbrs", "rb", "1111111rrrrr0bbb", ARG_0_31, ARG_0_7 }, { "sec", "", "1001010000001000", ARG_none, ARG_none }, { "seh", "", "1001010001011000", ARG_none, ARG_none }, { "sei", "", "1001010001111000", ARG_none, ARG_none }, { "sen", "", "1001010000101000", ARG_none, ARG_none }, { "ser", "d", "11101111dddd1111", ARG_16_31, ARG_none }, { "ses", "", "1001010001001000", ARG_none, ARG_none }, { "set", "", "1001010001101000", ARG_none, ARG_none }, { "sev", "", "1001010000111000", ARG_none, ARG_none }, { "sez", "", "1001010000011000", ARG_none, ARG_none }, { "sleep","", "1001010110001000", ARG_none, ARG_none }, { "st", "Xr", "1001001rrrrr1100", ARG_specialX, ARG_0_31 }, /*DO NOT CHANGE THE ORDER!*/ { "st", "Xr", "1001001rrrrr1101", ARG_specialIncX, ARG_0_31 }, { "st", "Xr", "1001001rrrrr1110", ARG_specialDecX, ARG_0_31 }, { "st", "Yr", "1000001rrrrr1000", ARG_specialY, ARG_0_31 }, // st4 is a special case of std1 { "st", "Yr", "1001001rrrrr1001", ARG_specialIncY, ARG_0_31 }, { "st", "Yr", "1001001rrrrr1010", ARG_specialDecY, ARG_0_31 }, { "st", "Zr", "1000001rrrrr0000", ARG_specialZ, ARG_0_31 }, // st7 is a special case of std2 { "st", "Zr", "1001001rrrrr0001", ARG_specialIncZ, ARG_0_31 }, { "st", "Zr", "1001001rrrrr0010", ARG_specialDecZ, ARG_0_31 }, { "std", "Yr", "10Y0YY1rrrrr1YYY", ARG_0_63, ARG_0_31 }, // st4 is a special case of std1 { "std", "Zr", "10Z0ZZ1rrrrr0ZZZ", ARG_0_63, ARG_0_31 }, // st7 is a special case of std2 { "sts", "Kd", "1001001ddddd0000", ARG_longCall, ARG_0_31 }, { "sub", "dr", "000110rdddddrrrr", ARG_0_31, ARG_0_31 }, { "subi", "dK", "0101KKKKddddKKKK", ARG_16_31, ARG_0_255 }, { "swap", "d", "1001010ddddd0010", ARG_0_31, ARG_none }, { "tst", "d", "001000CdddddCCCC", ARG_0_31, ARG_copyArg }, // tst is a special case of and { "wdr", "", "1001010110101000", ARG_none, ARG_none }, { "---", "", "", ARG_none, ARG_none }, { "", "", "", ARG_none, ARG_none }};int TAvr::Word2Instruction( TInstruction* pInstruction, unsigned short code_word, int index ){ TInstSet* pInstSet; int match; unsigned short mask; unsigned short mask0; unsigned short mask1; unsigned short maskC; int haveC; unsigned short arg0 = 0; unsigned short arg1 = 0; unsigned short argC = 0; char* pc; #ifdef DEBUG printf( "DEBUG - Word2Instruction: Entering Function With index = %d\n", index ); #endif // Look through the instruction set starting at index until we find a // pInstSet->opcode[] that matches with our code_word. Return // ( index + 1 ) of the Instruction found, or return 0 if there was // no matching instruction between index passed in and the end of the // array. if( index < 0 || index >= (int)( sizeof( InstSet ) / sizeof( InstSet[ 0 ] ))){ char msg[ 80 ]; // FIXME - Magic Number sprintf( msg, "Word2Instruction: illegal index: %d\n", index ); throw TGenericError( msg ); } pInstSet = &InstSet[ index ]; match = FALSE; while( !match && '\0' != pInstSet->name[ 0 ] ){ // Kludgy fix for the kludgy "---" instruction thing. We have to // increment pInstSet and bust out of this loop to avoid matching on // "---". if( 0 == strcmp( "---", pInstSet->name ) ){ pInstSet++; break; } haveC = FALSE; match = TRUE; pc = pInstSet->opcode;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -