From fbbb71d6d8aa93bccc87b17408a89432e4b8161c Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Sat, 15 Feb 2014 01:43:32 -0500 Subject: [PATCH] Replace disam.h with opcodes{h,c} Also rename opcode2c.pl -> opcodes2c.pl --- src/common/Makefile.am | 17 +-- src/common/cpu8051.c | 27 ++-- src/common/cpu8051.h | 3 - src/common/{opcode2c.pl => opcodes2c.pl} | 172 ++++++++++++++--------- src/gtk/pgmwin.c | 3 +- 5 files changed, 130 insertions(+), 92 deletions(-) rename src/common/{opcode2c.pl => opcodes2c.pl} (84%) diff --git a/src/common/Makefile.am b/src/common/Makefile.am index aa19efe..267c498 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -7,7 +7,8 @@ AM_CPPFLAGS = \ noinst_LIBRARIES = libemu8051.a libemu8051_a_SOURCES = \ - instructions_8051.c \ + instructions_8051.c instructions_8051.h \ + opcodes.c opcodes.h \ options.c options.h \ log.c log.h \ hexfile.c hexfile.h \ @@ -21,8 +22,9 @@ libemu8051_a_SOURCES = \ reg8051.h # These files are generated automatically by a perl script. -instructions_8051.c instructions_8051.h disasm.h : opcode2c.pl opcodes.lst - ./opcode2c.pl +instructions_8051.c instructions_8051.h opcodes.h opcodes.c : opcodes2c.pl opcodes.lst + @echo " PERL opcodes2c.pl" + @./opcodes2c.pl CLEANFILES = *~ @@ -30,10 +32,9 @@ MAINTAINERCLEANFILES = \ Makefile.in \ instructions_8051.c \ instructions_8051.h \ - disasm.h + opcodes.h \ + opcodes.c EXTRA_DIST = \ - opcode2c.pl \ - opcodes.lst \ - instructions_8051.h \ - disasm.h + opcodes2c.pl \ + opcodes.lst diff --git a/src/common/cpu8051.c b/src/common/cpu8051.c index fb387ee..288c11e 100644 --- a/src/common/cpu8051.c +++ b/src/common/cpu8051.c @@ -20,7 +20,7 @@ #include "memory.h" #include "psw.h" #include "timers.h" -#include "disasm.h" +#include "opcodes.h" #include "options.h" #include "instructions_8051.h" @@ -407,18 +407,11 @@ cpu8051_int_mem_bit_info(uint8_t bit_address, char *text) sprintf(&text[len], ".%X", bit_address); } -/* Get instruction size from opcode */ -int -cpu8051_get_instruction_size(unsigned char opcode) -{ - return instr_size[opcode]; -} - /* Display instruction mnemonic. */ int cpu8051_disasm_mnemonic(unsigned char opcode, char *buf) { - return sprintf(buf, "%s", instr_type_str[instr_type_id[opcode]]); + return sprintf(buf, "%s", opcodes_get_instr_type_str(opcode)); } /* Disasm instruction arguments starting at address into a text string */ @@ -452,8 +445,9 @@ cpu8051_disasm_args(unsigned int address, char *buf) return; } - for (i = 1; i <= instr_arg_type_id[args_table_offset]; i++) { - switch (instr_arg_type_id[args_table_offset + i]) { + for (i = 1; i <= opcodes_get_instr_arg_type_id(args_table_offset); + i++) { + switch (opcodes_get_instr_arg_type_id(args_table_offset + i)) { case ADDR11: { len += sprintf(&buf[len], "%.4XH", ((opcode << 3) & 0xF00) + @@ -517,13 +511,12 @@ cpu8051_disasm_args(unsigned int address, char *buf) break; } default: { - len += sprintf( - &buf[len], "%s", - instr_arg_type_str[instr_arg_type_id[ - args_table_offset + i]]); + len += sprintf(&buf[len], "%s", + opcodes_get_instr_arg_type_str( + args_table_offset + i)); } } - if (i < instr_arg_type_id[args_table_offset]) + if (i < opcodes_get_instr_arg_type_id(args_table_offset)) len += sprintf(&buf[len], ","); } } @@ -541,7 +534,7 @@ cpu8051_disasm(unsigned int address, char *text) len += sprintf(text, " %.4X ", address); opcode = mem_read8(PGM_MEM_ID, address); - inst_size = instr_size[opcode]; + inst_size = opcodes_get_instr_size(opcode); /* Display hex bytes. */ for (i = 0; i < inst_size; i++) diff --git a/src/common/cpu8051.h b/src/common/cpu8051.h index 3348aee..ae17ead 100644 --- a/src/common/cpu8051.h +++ b/src/common/cpu8051.h @@ -74,9 +74,6 @@ cpu8051_run(int instr_count, int (*interface_stop)(void)); void cpu8051_reset(void); -int -cpu8051_get_instruction_size(unsigned char opcode); - int cpu8051_disasm_mnemonic(unsigned char opcode, char *buf); diff --git a/src/common/opcode2c.pl b/src/common/opcodes2c.pl similarity index 84% rename from src/common/opcode2c.pl rename to src/common/opcodes2c.pl index 23800cc..2bc822a 100755 --- a/src/common/opcode2c.pl +++ b/src/common/opcodes2c.pl @@ -8,7 +8,8 @@ open INST_DEF, ">instructions_8051.h" or die "Error creating : $!\n"; open INST_IMP, ">instructions_8051.c" or die "Error creating : $!\n"; open OPCODELST, "opcodes.lst" or die "Error opening : $!\n"; -open DISASM_H, ">disasm.h" or die "Error creating : $!\n"; +open OPCODES_DEF, ">opcodes.h" or die "Error creating : $!\n"; +open OPCODES_IMP, ">opcodes.c" or die "Error creating : $!\n"; # Write GPL license # Argument 0 is file descriptor @@ -17,7 +18,7 @@ sub write_header my $fd = $_[0]; print $fd " *\n"; - print $fd " * Do not modify this file directly, as it was created by opcode2c.pl\n"; + print $fd " * Do not modify this file directly, as it was created by opcodes2c.pl\n"; print $fd " * Any modifications made directly to this file will be lost.\n"; print $fd " *\n"; print $fd " * Copyright (C) 1999 Jonathan St-André\n"; @@ -47,12 +48,27 @@ print INST_IMP "#include \"psw.h\"\n"; print INST_IMP "#include \"operations.h\"\n"; print INST_IMP "#include \"instructions_8051.h\"\n\n\n"; -# Header for disasm.h -print DISASM_H "/*\n"; -print DISASM_H " * disasm.h\n"; -write_header(DISASM_H); -print DISASM_H "#ifndef DISASM_H\n"; -print DISASM_H "#define DISASM_H 1\n\n"; +# Header for opcodes.h +print OPCODES_DEF "/*\n"; +print OPCODES_DEF " * opcodes.h\n"; +write_header(OPCODES_DEF); +print OPCODES_DEF "#ifndef OPCODES_H\n"; +print OPCODES_DEF "#define OPCODES_H 1\n\n"; + +print OPCODES_DEF "int\n"; +print OPCODES_DEF "opcodes_get_instr_size(uint8_t opcode);\n"; +print OPCODES_DEF "char *\n"; +print OPCODES_DEF "opcodes_get_instr_type_str(uint8_t opcode);\n"; +print OPCODES_DEF "int\n"; +print OPCODES_DEF "opcodes_get_instr_arg_type_id(unsigned int offset);\n"; +print OPCODES_DEF "char *\n"; +print OPCODES_DEF "opcodes_get_instr_arg_type_str(unsigned int offset);\n"; + +# opcodes.c +print OPCODES_IMP "/*\n"; +print OPCODES_IMP " * opcodes.c\n"; +write_header(OPCODES_IMP); +print OPCODES_IMP "#include \n\n"; # Column indexes in opcodes.lst table use constant COL_OPCODE => 0; @@ -130,112 +146,141 @@ while($ligne=) { } # ------------------------------------------------------------------------------ -print DISASM_H "/* Size(in bytes) of each instruction (offset in table is instruction opcode) */\n"; +print OPCODES_IMP "/* Size(in bytes) of each instruction (offset in table is instruction opcode) */\n"; $nbelement = @nbbytes; -print DISASM_H "static int instr_size[$nbelement] = {"; +print OPCODES_IMP "static int instr_size[$nbelement] = {"; for ($i = 0; $i < $nbelement; $i++) { if ($i % 16 == 0) { - print DISASM_H "\n\t"; + print OPCODES_IMP "\n\t"; } else { - print DISASM_H " "; + print OPCODES_IMP " "; } - print DISASM_H "$nbbytes[$i],"; + print OPCODES_IMP "$nbbytes[$i],"; } -print DISASM_H "\n"; -print DISASM_H "};\n"; -print DISASM_H "\n"; +print OPCODES_IMP "\n"; +print OPCODES_IMP "};\n"; +print OPCODES_IMP "\n"; # ------------------------------------------------------------------------------ -print DISASM_H "/*\n"; -print DISASM_H " * For all 256 opcodes, the value in this table gives the instruction type\n"; -print DISASM_H " * ex.: MOV, INC, CLR, CPL,...\n"; -print DISASM_H " * To know what is the instruction type, use\n"; -print DISASM_H " * the number as an offset in instr_type_str[]\n"; -print DISASM_H " */\n"; +print OPCODES_IMP "/*\n"; +print OPCODES_IMP " * For all 256 opcodes, the value in this table gives the instruction type\n"; +print OPCODES_IMP " * ex.: MOV, INC, CLR, CPL,...\n"; +print OPCODES_IMP " * To know what is the instruction type, use\n"; +print OPCODES_IMP " * the number as an offset in instr_type_str[]\n"; +print OPCODES_IMP " */\n"; $nbelement = @insttype; -print DISASM_H "static int instr_type_id[$nbelement] = {"; +print OPCODES_IMP "static int instr_type_id[$nbelement] = {"; for ($i = 0; $i < $nbelement; $i++) { if ($i % 16 == 0) { - print DISASM_H "\n\t"; + print OPCODES_IMP "\n\t"; } else { - print DISASM_H " "; + print OPCODES_IMP " "; } - print DISASM_H "$insttype[$i],"; + print OPCODES_IMP "$insttype[$i],"; } -print DISASM_H "\n"; -print DISASM_H "};\n"; -print DISASM_H "\n"; +print OPCODES_IMP "\n"; +print OPCODES_IMP "};\n"; +print OPCODES_IMP "\n"; # ------------------------------------------------------------------------------ -print DISASM_H "/* List of instructions types referenced by instr_type_id[] */\n"; +print OPCODES_IMP "/* List of instructions types referenced by instr_type_id[] */\n"; $nbelement = @insttext; $elementnb = 0; -print DISASM_H "static char *instr_type_str[$nbelement] = {\n"; +print OPCODES_IMP "static char *instr_type_str[$nbelement] = {\n"; foreach $instruc (@insttext) { - print DISASM_H "\t\"$instruc\""; + print OPCODES_IMP "\t\"$instruc\""; if ($elementnb++ < ($nbelement - 1)) { - print DISASM_H ","; + print OPCODES_IMP ","; } - print DISASM_H "\n"; + print OPCODES_IMP "\n"; } -print DISASM_H "};\n"; -print DISASM_H "\n"; +print OPCODES_IMP "};\n"; +print OPCODES_IMP "\n"; # ------------------------------------------------------------------------------ -print DISASM_H "/*\n"; -print DISASM_H " * Table describing all arguments types of an instruction\n"; -print DISASM_H " * The table is indexed instr_arg_type_id[ opcode * 4]\n"; -print DISASM_H " * instr_arg_type_id[opcode*4 + 1] gives number of instruction arguments\n"; -print DISASM_H " * instr_arg_type_id[opcode*4 + i] for i=1,2 and 3 gives type of each argument\n"; -print DISASM_H " * for most instructions, the 3rd argument isn't used\n"; -print DISASM_H " * the argument type is referecing to instr_arg_type_str[]\n"; -print DISASM_H " */\n"; +print OPCODES_IMP "/*\n"; +print OPCODES_IMP " * Table describing all arguments types of an instruction\n"; +print OPCODES_IMP " * The table is indexed instr_arg_type_id[ opcode * 4]\n"; +print OPCODES_IMP " * instr_arg_type_id[opcode*4 + 1] gives number of instruction arguments\n"; +print OPCODES_IMP " * instr_arg_type_id[opcode*4 + i] for i=1,2 and 3 gives type of each argument\n"; +print OPCODES_IMP " * for most instructions, the 3rd argument isn't used\n"; +print OPCODES_IMP " * the argument type is referenced to instr_arg_type_str[]\n"; +print OPCODES_IMP " */\n"; $nbelement = @instargs; -print DISASM_H "static int instr_arg_type_id[$nbelement] = {"; +print OPCODES_IMP "static int instr_arg_type_id[$nbelement] = {"; for ($i = 0; $i < $nbelement; $i++) { if ($i % 16 == 0) { - print DISASM_H "\n\t"; + print OPCODES_IMP "\n\t"; } else { - print DISASM_H " "; + print OPCODES_IMP " "; } - print DISASM_H "$instargs[$i],"; + print OPCODES_IMP "$instargs[$i],"; } -print DISASM_H "\n"; -print DISASM_H "};\n"; -print DISASM_H "\n"; +print OPCODES_IMP "\n"; +print OPCODES_IMP "};\n"; +print OPCODES_IMP "\n"; # ------------------------------------------------------------------------------ -print DISASM_H "/*\n"; -print DISASM_H " * List all types of arguments available to instructions\n"; -print DISASM_H " * Referenced by instr_arg_type_id[]\n"; -print DISASM_H " */\n"; +print OPCODES_IMP "/*\n"; +print OPCODES_IMP " * List all types of arguments available to instructions\n"; +print OPCODES_IMP " * Referenced by instr_arg_type_id[]\n"; +print OPCODES_IMP " */\n"; $nbelement = @argstypes; $elementnb = 0; -print DISASM_H "static char *instr_arg_type_str[$nbelement] = {\n"; +print OPCODES_IMP "static char *instr_arg_type_str[$nbelement] = {\n"; foreach $args (@argstypes) { - print DISASM_H "\t\"$args\""; + print OPCODES_IMP "\t\"$args\""; if ($elementnb++ < $nbelement-1) { - print DISASM_H ","; + print OPCODES_IMP ","; } - print DISASM_H "\n"; + print OPCODES_IMP "\n"; } -print DISASM_H "};\n"; -print DISASM_H "\n"; +print OPCODES_IMP "};\n"; +print OPCODES_IMP "\n"; + +print OPCODES_IMP "int\n"; +print OPCODES_IMP "opcodes_get_instr_size(uint8_t opcode)\n"; +print OPCODES_IMP "{\n"; +print OPCODES_IMP "\treturn instr_size[opcode];\n"; +print OPCODES_IMP "}\n"; +print OPCODES_IMP "\n"; + +print OPCODES_IMP "char *\n"; +print OPCODES_IMP "opcodes_get_instr_type_str(uint8_t opcode)\n"; +print OPCODES_IMP "{\n"; +print OPCODES_IMP "\treturn instr_type_str[instr_type_id[opcode]];\n"; +print OPCODES_IMP "}\n"; +print OPCODES_IMP "\n"; + +print OPCODES_IMP "int\n"; +print OPCODES_IMP "opcodes_get_instr_arg_type_id(unsigned int offset)\n"; +print OPCODES_IMP "{\n"; +print OPCODES_IMP "\treturn instr_arg_type_id[offset];\n"; +print OPCODES_IMP "}\n"; +print OPCODES_IMP "\n"; + +print OPCODES_IMP "char *\n"; +print OPCODES_IMP "opcodes_get_instr_arg_type_str(unsigned int offset)\n"; +print OPCODES_IMP "{\n"; +print OPCODES_IMP "\treturn instr_arg_type_str[instr_arg_type_id[offset]];\n"; +print OPCODES_IMP "}\n"; +print OPCODES_IMP "\n"; + # ------------------------------------------------------------------------------ for ($i = 0 ; $i < 256; $i++) { @@ -847,9 +892,10 @@ print INST_DEF "#endif\n\n\n"; print INST_DEF "#endif /* INSTRUCTIONS_8051_H */\n"; -print DISASM_H "#endif /* DISASM_H */\n"; +print OPCODES_DEF "#endif /* OPCODES_IMP */\n"; -close DISASM_H; +close OPCODES_DEF; +close OPCODES_IMP; close OPCODELST; close INST_DEF; close INST_IMP; diff --git a/src/gtk/pgmwin.c b/src/gtk/pgmwin.c index 6cec8fb..4c35d7f 100644 --- a/src/gtk/pgmwin.c +++ b/src/gtk/pgmwin.c @@ -16,6 +16,7 @@ #include "common.h" #include "memory.h" #include "cpu8051.h" +#include "opcodes.h" #include "pgmwin.h" #include "hexfile.h" @@ -262,7 +263,7 @@ pgmwin_refresh(void) gtk_list_store_set(store, &iter, COL_ADDR, str, -1); opcode = mem_read8(PGM_MEM_ID, address); - inst_size = cpu8051_get_instruction_size(opcode); + inst_size = opcodes_get_instr_size(opcode); /* Display instruction hex bytes. */ for (k = 0, col_id = COL_B0; k < 3; k++, col_id++) { -- 2.20.1