--- hatari/src/debug/68kDisass.c 2019/04/09 08:55:35 1.1.1.6 +++ hatari/src/debug/68kDisass.c 2019/04/09 08:59:19 1.1.1.9 @@ -5,16 +5,16 @@ * or at your option any later version. Read the file gpl.txt for details. ***/ -#include +#include "main.h" #include -#include -#include +#if HAVE_STRINGS_H +# include +#endif -#include "config.h" #include "sysdeps.h" -#include "main.h" #include "configuration.h" #include "newcpu.h" +#include "stMemory.h" #ifdef WINUAE_FOR_HATARI #include "debug.h" #endif @@ -130,11 +130,7 @@ static inline unsigned short Disass68kGe if ( ! valid_address ( addr , 2 ) ) return 0; -#ifndef WINUAE_FOR_HATARI - return get_word(addr); -#else - return get_word_debug(addr); -#endif + return STMemory_ReadWord ( addr ); } // Load a text file into memory, count the lines and replace the LF with 0-bytes. @@ -195,9 +191,17 @@ static void Disass68kLoadStructInfo(co if(!lineCount) return; - disStructEntries = realloc(disStructEntries, sizeof(disStructEntry) - * (disStructCounts + lineCount)); - if(!disStructEntries) { free(fbuf); return; } + se = realloc(disStructEntries, sizeof(disStructEntry) * (disStructCounts + lineCount)); + if (!se) + { + perror("Disass68kLoadStructInfo"); + free(disStructEntries); + disStructEntries = NULL; + free(fbuf); + return; + } + disStructEntries = se; + se = NULL; line = fbuf; @@ -269,10 +273,23 @@ static void Disass68kLoadSymbols(const char *nextLine; char *line; char *fbuf = NULL; - int lineCount = Disass68kLoadTextFile(filename, &fbuf); - if(!lineCount) return; - disSymbolEntries = realloc(disSymbolEntries, sizeof(disSymbolEntry) * (disSymbolCounts + lineCount)); - if(!disSymbolEntries) { free(fbuf); return; } + int lineCount = Disass68kLoadTextFile(filename, &fbuf); + disSymbolEntry *nde; + + if (!lineCount) + return; + + nde = realloc(disSymbolEntries, sizeof(disSymbolEntry) * (disSymbolCounts + lineCount)); + if (!nde) + { + perror("Disass68kLoadSymbols"); + free(disSymbolEntries); + disSymbolEntries = NULL; + free(fbuf); + return; + } + disSymbolEntries = nde; + line = fbuf; for(i=0; i= 0x0 && reg <= 0x7) + { + regName[0] = (options & doptRegisterSmall) ? 'd' : 'D'; + } + else if (reg >= 0x8 && reg <= 0xf) + { + regName[0] = (options & doptRegisterSmall) ? 'a' : 'A'; + } + else + { + regName[0] = '?'; } + + regName[1] = '0' + (reg & 7); + regName[2] = 0; + return regName; } @@ -829,6 +852,7 @@ static char *Disass68kEA(char *disassbu case 3: bd = Disass68kGetWord(*addr); *addr += 2; bd <<= 16; + /* fall through */ case 2: bd |= Disass68kGetWord(*addr); *addr += 2; break; @@ -899,6 +923,7 @@ static char *Disass68kEA(char *disassbu case 3: od = Disass68kGetWord(*addr); *addr += 2; od <<= 16; + /* fall through */ case 2: od |= Disass68kGetWord(*addr); *addr += 2; if(prefixComma) @@ -1017,6 +1042,7 @@ static char *Disass68kEA(char *disassbu switch(size) { case 1: eWord1 &= 0xFF; + /* fall through */ case 2: #if USE_SYMBOLS if(disassFlag) @@ -1529,26 +1555,26 @@ static OpcodeTableStruct OpcodeTable[] = { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x0800}, {0}, {ofEa,ofSpecReg}, "PMOVE",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_TT0} }, { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x0900}, {0}, {ofEa,ofSpecReg}, "PMOVEFD",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_TT0} }, - { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x0B00}, {0}, {ofSpecReg,ofEa}, "PMOVEFD",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_TT0} }, + { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x0B00}, {0}, {ofSpecReg,ofEa}, "PMOVEFD",{REG_TT0,EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel} }, { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x0C00}, {0}, {ofEa,ofSpecReg}, "PMOVE",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_TT1} }, - { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x0C00}, {0}, {ofSpecReg,ofEa}, "PMOVE",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_TT0} }, + { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x0C00}, {0}, {ofSpecReg,ofEa}, "PMOVE",{REG_TT0,EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel} }, { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x0D00}, {0}, {ofEa,ofSpecReg}, "PMOVEFD",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_TT1} }, - { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x0E00}, {0}, {ofSpecReg,ofEa}, "PMOVE",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_TT1} }, - { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x0F00}, {0}, {ofSpecReg,ofEa}, "PMOVEFD",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_TT1} }, + { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x0E00}, {0}, {ofSpecReg,ofEa}, "PMOVE",{REG_TT1,EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel} }, + { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x0F00}, {0}, {ofSpecReg,ofEa}, "PMOVEFD",{REG_TT1,EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel} }, { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4000}, {0}, {ofEa,ofSpecReg}, "PMOVE",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_TC} }, { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4100}, {0}, {ofEa,ofSpecReg}, "PMOVEFD",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_TC} }, - { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4200}, {0}, {ofSpecReg,ofEa}, "PMOVE",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_TC} }, - { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4300}, {0}, {ofSpecReg,ofEa}, "PMOVEFD",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_TC} }, + { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4200}, {0}, {ofSpecReg,ofEa}, "PMOVE",{REG_TC,EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel} }, + { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4300}, {0}, {ofSpecReg,ofEa}, "PMOVEFD",{REG_TC,EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel} }, { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4800}, {0}, {ofEa,ofSpecReg}, "PMOVE",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_SRP} }, { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4900}, {0}, {ofEa,ofSpecReg}, "PMOVEFD",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_SRP} }, - { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4A00}, {0}, {ofSpecReg,ofEa}, "PMOVE",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_SRP} }, - { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4B00}, {0}, {ofSpecReg,ofEa}, "PMOVEFD",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_SRP} }, + { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4A00}, {0}, {ofSpecReg,ofEa}, "PMOVE",{REG_SRP,EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_SRP} }, + { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4B00}, {0}, {ofSpecReg,ofEa}, "PMOVEFD",{REG_SRP,EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_SRP} }, { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4C00}, {0}, {ofEa,ofSpecReg}, "PMOVE",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_CRP} }, { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4D00}, {0}, {ofEa,ofSpecReg}, "PMOVEFD",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_CRP} }, - { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4e00}, {0}, {ofSpecReg,ofEa}, "PMOVE",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_CRP} }, - { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4f00}, {0}, {ofSpecReg,ofEa}, "PMOVEFD",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_CRP} }, + { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4e00}, {0}, {ofSpecReg,ofEa}, "PMOVE",{REG_CRP,EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel} }, + { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x4f00}, {0}, {ofSpecReg,ofEa}, "PMOVEFD",{REG_CRP,EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel} }, { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x6000}, {0}, {ofEa,ofSpecReg}, "PMOVE",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_MMUSR} }, - { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x6200}, {0}, {ofSpecReg,ofEa}, "PMOVE",{EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel,REG_MMUSR} }, + { MC_PMMU|MC68030, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x6200}, {0}, {ofSpecReg,ofEa}, "PMOVE",{REG_MMUSR,EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel} }, { MC_PMMU, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xffff, 0x2800}, {0}, {ofSpecReg,ofEa}, "PVALID",{REG_VAL,EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel} }, { MC_PMMU, {0xffc0, 0xf000|(PMMU_COPROC_ID<<9), 0xfff8, 0x2C00}, {0}, {ofExtRegA0,ofEa}, "PVALID",{0,EA_Dn|EA_An|EA_Anip|EA_piAn|EA_Immed|EA_PCRel} }, @@ -1733,7 +1759,6 @@ static OpcodeTableStruct OpcodeTable[] = static int Disass68k(long addr, char *labelBuffer, char *opcodeBuffer, char *operandBuffer, char *commentBuffer) { long baseAddr = addr; - int val; int i; int count = 0; char addressLabel[256]; @@ -1834,10 +1859,10 @@ static int Disass68k(long addr, char *la case dtASCString: { - int count = 1; - unsigned short val = Disass68kGetWord(addr+0); + unsigned short opcval = Disass68kGetWord(addr+0); + count = 1; strcpy(opcodeBuffer,"DC.B"); - if((val >> 8) == 0) + if ((opcval >> 8) == 0) { strcat(operandBuffer, "0"); } else { @@ -1874,6 +1899,7 @@ static int Disass68k(long addr, char *la case dtFunctionPointer: { const char *sp; + int val; val = (Disass68kGetWord(addr) << 16) | Disass68kGetWord(addr+2); sp = Disass68kSymbolName(val, 2); strcpy(opcodeBuffer,"DC.L"); @@ -1902,13 +1928,12 @@ more: while(1) { unsigned short opcode[5]; - unsigned int i; OpcodeTableStruct *ots = &OpcodeTable[index++]; int size; char sizeChar = 0; char *dbuf; int ea; - unsigned int maxop; + int maxop; if(ots->opcodeName == NULL) break; @@ -2030,10 +2055,10 @@ more: ea = opcode[0] & 0x3F; dbuf = operandBuffer; - maxop=(sizeof(ots->op)/sizeof(ots->op[0])); + maxop = (int)(sizeof(ots->op)/sizeof(ots->op[0])); for(i=0; iop[i]) { @@ -2463,10 +2488,10 @@ static void Disass68k_loop (FILE *f, uae char addressBuffer[32]; char hexdumpBuffer[256]; - char labelBuffer[256]; + char labelBuffer[258]; char opcodeBuffer[64]; char operandBuffer[256]; - char commentBuffer[256]; + char commentBuffer[258]; int plen, len, j; len = Disass68k(addr, labelBuffer, opcodeBuffer, operandBuffer, commentBuffer); @@ -2512,11 +2537,8 @@ static void Disass68k_loop (FILE *f, uae } if (optionPosComment >= 0) { - float percentage; - Uint32 count, cycles, i_misses, d_hits; - if (Profile_CpuAddressData(addr, &percentage, &count, &cycles, &i_misses, &d_hits)) + if (Profile_CpuAddressDataStr(commentBuffer, sizeof(commentBuffer), addr)) { - sprintf(commentBuffer, "%5.2f%% (%u, %u, %u, %u)", percentage, count, cycles, i_misses, d_hits); Disass68kComposeStr(lineBuffer, commentBuffer, optionPosComment+1, 0); } /* show comments only if profile data is missing */ @@ -2558,7 +2580,7 @@ void Disasm (FILE *f, uaecptr addr, uaec { if (ConfigureParams.Debugger.bDisasmUAE) #ifdef WINUAE_FOR_HATARI - m68k_disasm_file (f, addr, nextpc, cnt); + m68k_disasm_file (f, addr, nextpc, addr, cnt); #else m68k_disasm (f, addr, nextpc, cnt); #endif @@ -2641,22 +2663,23 @@ int Disasm_GetOptions(void) /** * Set CPU and FPU mask used for disassembly (when changed from the UI or the options) */ -void Disasm_SetCPUType ( int CPU , int FPU ) +void Disasm_SetCPUType(int CPU, int FPU, bool bMMU) { - optionCPUTypeMask = 0; + switch (CPU) + { + case 0: optionCPUTypeMask = MC68000; break; + case 1: optionCPUTypeMask = MC68010; break; + case 2: optionCPUTypeMask = MC68020; break; + case 3: optionCPUTypeMask = MC68030; break; + case 4: optionCPUTypeMask = MC68040; break; + default: optionCPUTypeMask = MC68000; break; + } - if ( ( FPU == 68881 ) || ( FPU == 68882 ) ) + if (FPU != 0) optionCPUTypeMask |= MC_FPU; - switch ( CPU ) - { - case 0 : optionCPUTypeMask |= MC68000 ; break; - case 1 : optionCPUTypeMask |= MC68010 ; break; - case 2 : optionCPUTypeMask |= MC68020 ; break; - case 3 : optionCPUTypeMask |= MC68030 ; break; - case 4 : optionCPUTypeMask |= MC68040 ; break; - default : optionCPUTypeMask |= MC68000 ; break; - } + if (bMMU) + optionCPUTypeMask |= MC_PMMU; } /** @@ -2689,7 +2712,7 @@ const char *Disasm_ParseOption(const cha assert(option[i].flag == (1 << i)); fprintf(stderr, "\t%d: %s\n", option[i].flag, option[i].desc); } - fprintf(stderr, "Current settings are:\n\t--disasm %s --disasm %d\n", + fprintf(stderr, "Current settings are:\n\t--disasm %s --disasm 0x%x\n", ConfigureParams.Debugger.bDisasmUAE ? "uae" : "ext", ConfigureParams.Debugger.nDisasmOptions); return ""; @@ -2709,7 +2732,12 @@ const char *Disasm_ParseOption(const cha } if (isdigit((unsigned char)*arg)) { - int newopt = atoi(arg); + char *end; + int newopt = strtol(arg, &end, 0); + if (*end) + { + return "not a number"; + } if ((newopt|optionsMask) != optionsMask) { return "unknown flags in the bitmask";