decode.c
来自「ppc750 system design simulator using sys」· C语言 代码 · 共 800 行 · 第 1/3 页
C
800 行
/*************************************************************************** decode.c - description ------------------- begin : Wed Sep 26 2001 copyright : (C) 2001 Universite Paris Sud and CEA author : Gilles Mouchard email : gilles.mouchard@lri.fr, gilles.mouchard@cea.fr ***************************************************************************//*************************************************************************** * * * 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. * * * ***************************************************************************/#include <ppcemul.h>#include <integer.h>#include <loadstore.h>#include <branch.h>#include <syscall.h>#include <floatingpoint.h>#include <systemregisters.h>#include <string.h>#include <stdio.h>#include <stdlib.h>#include <debug.h>#include <xmlize.h>void (*impl_table[64])(ppc_inst_t);void (*impl_table31[1024])(ppc_inst_t);void (*impl_table63[1024])(ppc_inst_t);void (*impl_table19[1024])(ppc_inst_t);void (*impl_table59[32])(ppc_inst_t);char *(*bin2c_table[64])(ppc_inst_t, addr_t, char *);char *(*bin2c_table31[1024])(ppc_inst_t, addr_t, char *);char *(*bin2c_table63[1024])(ppc_inst_t, addr_t, char *);char *(*bin2c_table19[1024])(ppc_inst_t, addr_t, char *);char *(*bin2c_table59[32])(ppc_inst_t, addr_t, char *);char *(*disasm_table[64])(ppc_inst_t, addr_t, char *);char *(*disasm_table31[1024])(ppc_inst_t, addr_t, char *);char *(*disasm_table63[1024])(ppc_inst_t, addr_t, char *);char *(*disasm_table19[1024])(ppc_inst_t, addr_t, char *);char *(*disasm_table59[32])(ppc_inst_t, addr_t, char *);void (*translate_table[64])(ppc_inst_t, struct DecodedInstruction *di);void (*translate_table31[1024])(ppc_inst_t, struct DecodedInstruction *di);void (*translate_table63[1024])(ppc_inst_t, struct DecodedInstruction *di);void (*translate_table19[1024])(ppc_inst_t, struct DecodedInstruction *di);void (*translate_table59[32])(ppc_inst_t, struct DecodedInstruction *di);void (*xml_table[64])(ppc_inst_t, addr_t, char *);void (*xml_table31[1024])(ppc_inst_t, addr_t, char *);void (*xml_table63[1024])(ppc_inst_t, addr_t, char *);void (*xml_table19[1024])(ppc_inst_t, addr_t, char *);void (*xml_table59[32])(ppc_inst_t, addr_t, char *);UInt64 index_table[64];UInt64 index_table31[1024];UInt64 index_table63[1024];UInt64 index_table19[1024];UInt64 index_table59[32];int ninstructions;UInt64 instruction_counter;char *mnemonic_table[1024];int counters[1024];void impl_31(ppc_inst_t inst){ impl_table31[XO_10](inst);#ifdef COUNT_INSTRUCTIONS counters[index_table31[XO_10]]++; instruction_counter++;#endif}void impl_63(ppc_inst_t inst){ impl_table63[XO_10](inst);#ifdef COUNT_INSTRUCTIONS counters[index_table63[XO_10]]++; instruction_counter++;#endif}void impl_19(ppc_inst_t inst){ impl_table19[XO_10](inst);#ifdef COUNT_INSTRUCTIONS counters[index_table19[XO_10]]++; instruction_counter++;#endif}void impl_59(ppc_inst_t inst){ impl_table59[XO_5](inst);#ifdef COUNT_INSTRUCTIONS counters[index_table59[XO_5]]++; instruction_counter++;#endif}void impl_default(ppc_inst_t inst){ fprintf(stderr, "Attempted to execute a bogus opcode at 0x%08x (OPCD = %d, XO_10 = %d, XO_9 = %d, XO_5 = %d)\n", PC, OPCD, XO_10, XO_9, XO_5); ppc_debug_disasm(stderr, PC); abort();}void ppc_execute(ppc_inst_t inst){ NPC = PC + sizeof(ppc_inst_t); impl_table[OPCD](inst);#ifdef COUNT_INSTRUCTIONS counters[index_table[OPCD]]++; instruction_counter++;#endif PC = NPC;}void ppc_execute_check_path(ppc_inst_t inst, addr_t pc){ if(pc != PC) { fprintf(stderr, "Not the good path (pc = 0x%08x instead of 0x%08x) !\n", pc, PC); abort(); } if(ppc_fetch(PC) != inst) { fprintf(stderr, "Emulator does not execute the good instruction !\n"); abort(); } NPC = PC + sizeof(ppc_inst_t); impl_table[OPCD](inst);#ifdef COUNT_INSTRUCTIONS counters[index_table[OPCD]]++; instruction_counter++;#endif PC = NPC;}char *bin2c_31(ppc_inst_t inst, addr_t pc, char *buf){ return bin2c_table31[XO_10](inst, pc, buf);}char *bin2c_63(ppc_inst_t inst, addr_t pc, char *buf){ return bin2c_table63[XO_10](inst, pc, buf);}char *bin2c_19(ppc_inst_t inst, addr_t pc, char *buf){ return bin2c_table19[XO_10](inst, pc, buf);}char *bin2c_59(ppc_inst_t inst, addr_t pc, char *buf){ return bin2c_table59[XO_5](inst, pc, buf);}char *bin2c_default(ppc_inst_t inst, addr_t pc, char *buf){// buf += sprintf(buf, "\tfprintf(stderr, \"Bogus opcode\\n\");\n");// buf += sprintf(buf, "\tabort();\n"); buf += sprintf(buf, ""); return buf;}char *ppc_bin2c(ppc_inst_t inst, addr_t pc, char *buf){ buf += sprintf(buf, "pc_%08x: /* ", pc); buf = ppc_disassemble(inst, pc, buf); buf += sprintf(buf, " */\n"); buf += sprintf(buf, "{\n"); buf = bin2c_table[OPCD](inst, pc, buf); buf += sprintf(buf, "}\n"); return buf;}void ppc_bin2c_to_stream(ppc_inst_t inst, addr_t pc, FILE *stream){ char buf[4096]; ppc_bin2c(inst, pc, buf); fprintf(stream, "%s", buf);}void xml_31(ppc_inst_t inst, addr_t pc, char *buf){ xml_table31[XO_10](inst, pc, buf);}void xml_63(ppc_inst_t inst, addr_t pc, char *buf){ xml_table63[XO_10](inst, pc, buf);}void xml_19(ppc_inst_t inst, addr_t pc, char *buf){ xml_table19[XO_10](inst, pc, buf);}void xml_59(ppc_inst_t inst, addr_t pc, char *buf){ xml_table59[XO_5](inst, pc, buf);}void xml_default(ppc_inst_t inst, addr_t pc, char *buf){ xmlf(buf, pc, "?", 0);}void ppc_xmlize(ppc_inst_t inst, addr_t pc, char *buf){ xml_table[OPCD](inst, pc, buf);}void ppc_xmlize_to_stream(ppc_inst_t inst, addr_t pc, FILE *stream){ char buf[4096]; ppc_xmlize(inst, pc, buf); fprintf(stream, "%s", buf);}char *disasm_31(ppc_inst_t inst, addr_t pc, char *buf){ return disasm_table31[XO_10](inst, pc, buf);}char *disasm_63(ppc_inst_t inst, addr_t pc, char *buf){ return disasm_table63[XO_10](inst, pc, buf);}char *disasm_19(ppc_inst_t inst, addr_t pc, char *buf){ return disasm_table19[XO_10](inst, pc, buf);}char *disasm_59(ppc_inst_t inst, addr_t pc, char *buf){ return disasm_table59[XO_5](inst, pc, buf);}char *disasm_default(ppc_inst_t inst, addr_t pc, char *buf){ buf += sprintf(buf, "????"); return buf;}char *ppc_disassemble(ppc_inst_t inst, addr_t pc, char *buf){ return disasm_table[OPCD](inst, pc, buf);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?