From 009ef50c60a203d779c4cce160cc3e76c3b75a98 Mon Sep 17 00:00:00 2001 From: notaz Date: Thu, 11 Jul 2013 04:08:33 +0300 Subject: [PATCH] rm dupe file --- cpu/sh2/compiler.c | 2 +- platform/common/common.mak | 2 +- platform/linux/host_dasm.c | 232 ------------------------------------- platform/linux/host_dasm.h | 4 - 4 files changed, 2 insertions(+), 238 deletions(-) delete mode 100644 platform/linux/host_dasm.c delete mode 100644 platform/linux/host_dasm.h diff --git a/cpu/sh2/compiler.c b/cpu/sh2/compiler.c index b55f3e5..d1a07af 100644 --- a/cpu/sh2/compiler.c +++ b/cpu/sh2/compiler.c @@ -61,7 +61,7 @@ } #include "mame/sh2dasm.h" -#include +#include static int insns_compiled, hash_collisions, host_insn_count; #define COUNT_OP \ host_insn_count++ diff --git a/platform/common/common.mak b/platform/common/common.mak index f4730d7..8d6b792 100644 --- a/platform/common/common.mak +++ b/platform/common/common.mak @@ -139,7 +139,7 @@ SRCS_COMMON += $(R)cpu/sh2/compiler.c ifdef drc_debug DEFINES += DRC_DEBUG=$(drc_debug) SRCS_COMMON += $(R)cpu/sh2/mame/sh2dasm.c -SRCS_COMMON += $(R)platform/linux/host_dasm.c +SRCS_COMMON += $(R)platform/libpicofe/linux/host_dasm.c LDFLAGS += -lbfd -lopcodes -liberty endif ifeq "$(drc_debug_interp)" "1" diff --git a/platform/linux/host_dasm.c b/platform/linux/host_dasm.c deleted file mode 100644 index 5117a24..0000000 --- a/platform/linux/host_dasm.c +++ /dev/null @@ -1,232 +0,0 @@ -/* - * PicoDrive - * (C) notaz, 2009,2010 - * - * This work is licensed under the terms of MAME license. - * See COPYING file in the top-level directory. - */ -#include -#include -#include -#include -#include -#include - -#include "host_dasm.h" - -extern char **g_argv; - -static struct disassemble_info di; - -#ifdef __arm__ -#define print_insn_func print_insn_little_arm -#define BFD_ARCH bfd_arch_arm -#define BFD_MACH bfd_mach_arm_4T -#else -#define print_insn_func print_insn_i386_intel -#define BFD_ARCH bfd_arch_i386 -#define BFD_MACH bfd_mach_i386_i386_intel_syntax -#endif - -/* symbols */ -static asymbol **symbols; -static long symcount, symstorage; -static int init_done; - -/* Filter out (in place) symbols that are useless for disassembly. - COUNT is the number of elements in SYMBOLS. - Return the number of useful symbols. */ -static long -remove_useless_symbols (asymbol **symbols, long count) -{ - asymbol **in_ptr = symbols, **out_ptr = symbols; - - while (--count >= 0) - { - asymbol *sym = *in_ptr++; - - if (sym->name == NULL || sym->name[0] == '\0' || sym->name[0] == '$') - continue; - if (sym->flags & (BSF_DEBUGGING | BSF_SECTION_SYM)) - continue; - if (bfd_is_und_section (sym->section) - || bfd_is_com_section (sym->section)) - continue; - if (sym->value + sym->section->vma == 0) - continue; -/* - printf("sym: %08lx %04x %08x v %08x \"%s\"\n", - (unsigned int)sym->value, (unsigned int)sym->flags, (unsigned int)sym->udata.i, - (unsigned int)sym->section->vma, sym->name); -*/ - *out_ptr++ = sym; - } - - return out_ptr - symbols; -} - -static void slurp_symtab(const char *filename) -{ - bfd *abfd; - - symcount = 0; - - abfd = bfd_openr(filename, NULL); - if (abfd == NULL) { - fprintf(stderr, "failed to open: %s\n", filename); - goto no_symbols; - } - - if (!bfd_check_format(abfd, bfd_object)) - goto no_symbols; - - if (!(bfd_get_file_flags(abfd) & HAS_SYMS)) - goto no_symbols; - - symstorage = bfd_get_symtab_upper_bound(abfd); - if (symstorage <= 0) - goto no_symbols; - - symbols = malloc(symstorage); - if (symbols == NULL) - goto no_symbols; - - symcount = bfd_canonicalize_symtab(abfd, symbols); - if (symcount < 0) - goto no_symbols; - - symcount = remove_useless_symbols(symbols, symcount); -// bfd_close(abfd); - return; - -no_symbols: - fprintf(stderr, "no symbols in %s\n", bfd_get_filename(abfd)); - if (symbols != NULL) - free(symbols); - symbols = NULL; - if (abfd != NULL) - bfd_close(abfd); -} - -static const char *lookup_name(bfd_vma addr) -{ - asymbol **sptr = symbols; - int i; - - for (i = 0; i < symcount; i++) { - asymbol *sym = *sptr++; - - if (addr == sym->value + sym->section->vma) - return sym->name; - } - - return NULL; -} - -/* Like target_read_memory, but slightly different parameters. */ -static int -dis_asm_read_memory(bfd_vma memaddr, bfd_byte *myaddr, unsigned int len, - struct disassemble_info *info) -{ - memcpy(myaddr, (void *)(int)memaddr, len); - return 0; -} - -static void -dis_asm_memory_error(int status, bfd_vma memaddr, - struct disassemble_info *info) -{ - fprintf(stderr, "memory_error %p\n", (void *)(int)memaddr); -} - -static void -dis_asm_print_address(bfd_vma addr, struct disassemble_info *info) -{ - const char *name; - - printf("%08x", (int)addr); - - name = lookup_name(addr); - if (name != NULL) - printf(" <%s>", name); -} - -static int insn_printf(void *f, const char *format, ...) -{ - va_list args; - size_t n; - - va_start(args, format); - n = vprintf(format, args); - va_end(args); - - return n; -} - -static void host_dasm_init(void) -{ - bfd_init(); - slurp_symtab(g_argv[0]); - - init_disassemble_info(&di, NULL, insn_printf); - di.flavour = bfd_target_unknown_flavour; - di.memory_error_func = dis_asm_memory_error; - di.print_address_func = dis_asm_print_address; -// di.symbol_at_address_func = dis_asm_symbol_at_address; - di.read_memory_func = dis_asm_read_memory; - di.arch = BFD_ARCH; - di.mach = BFD_MACH; - di.endian = BFD_ENDIAN_LITTLE; - disassemble_init_for_target(&di); - init_done = 1; -} - -void host_dasm(void *addr, int len) -{ - bfd_vma vma_end, vma = (bfd_vma)(long)addr; - const char *name; - - if (!init_done) - host_dasm_init(); - - vma_end = vma + len; - while (vma < vma_end) { - name = lookup_name(vma); - if (name != NULL) - printf("%s:\n", name); - - printf(" %08lx ", (long)vma); - vma += print_insn_func(vma, &di); - printf("\n"); - } -} - -void host_dasm_new_symbol_(void *addr, const char *name) -{ - bfd_vma vma = (bfd_vma)(long)addr; - asymbol *sym, **tmp; - - if (!init_done) - host_dasm_init(); - if (symbols == NULL) - return; - if (symstorage <= symcount * sizeof(symbols[0])) { - tmp = realloc(symbols, symstorage * 2); - if (tmp == NULL) - return; - symstorage *= 2; - symbols = tmp; - } - - symbols[symcount] = calloc(sizeof(*symbols[0]), 1); - if (symbols[symcount] == NULL) - return; - - // a HACK (should use correct section), but ohwell - sym = symbols[symcount]; - sym->section = symbols[0]->section; - sym->value = vma - sym->section->vma; - sym->name = name; - symcount++; -} - diff --git a/platform/linux/host_dasm.h b/platform/linux/host_dasm.h deleted file mode 100644 index 490547d..0000000 --- a/platform/linux/host_dasm.h +++ /dev/null @@ -1,4 +0,0 @@ -void host_dasm(void *addr, int len); -void host_dasm_new_symbol_(void *addr, const char *name); -#define host_dasm_new_symbol(sym) \ - host_dasm_new_symbol_(sym, #sym) -- 2.39.2