* Removed all Id tags.
[cacao.git] / src / vm / jit / i386 / disass.c
index 6f42daffad77e37ac481697a2bfe9233c426830c..1d39b72715c2d5d9606841dfc426a0d9a79191ac 100644 (file)
@@ -1,9 +1,9 @@
 /* src/vm/jit/i386/disass.c - wrapper functions for GNU binutils disassembler
 
-   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
-   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
-   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
-   Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+   J. Wenninger, Institut f. Computersprachen - TU Wien
 
    This file is part of CACAO.
 
 
    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.
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
-   Contact: cacao@complang.tuwien.ac.at
+   Contact: cacao@cacaojvm.org
 
    Authors: Andreas  Krall
             Reinhard Grafl
 
    Changes: Christian Thalinger
 
-   $Id: disass.c 4031 2006-01-01 18:21:30Z twisti $
-
 */
 
 
 #include "config.h"
 
 #include <assert.h>
-/* #include <dis-asm.h> */
+#include <dis-asm.h>
 #include <stdarg.h>
-#include <string.h>
 
 #include "vm/types.h"
 
-#include "vm/jit/i386/dis-asm.h"
-
-#include "mm/memory.h"
+#include "vm/global.h"
 #include "vm/jit/disass.h"
 
 
-char mylinebuf[512];
-int mylen;
-
-
-char *regs[] = {
-       "eax",
-       "ecx",
-       "edx",
-       "ebx",
-       "esp",
-       "ebp",
-       "esi",
-       "edi"
-};
-
-
-/* myprintf ********************************************************************
-
-   Required by i386-dis.c, prints the stuff into a buffer.
-
-*******************************************************************************/
-
-void myprintf(PTR p, const char *fmt, ...)
-{
-       va_list ap;
-       va_start(ap, fmt);
-       mylen += vsprintf(mylinebuf + mylen, fmt, ap);
-       va_end(ap);
-}
-
-/* buffer_read_memory **********************************************************
-
-   Required by i386-dis.c, copy some stuff to another memory.
-
-*******************************************************************************/
-
-int buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, struct disassemble_info *info)
-{
-       MCOPY(myaddr, (void *) memaddr, u1, length);
-
-       return 0;
-}
-
-
-/* generic_symbol_at_address ***************************************************
-
-   Required by i386-dis.c, just return 1.
-
-*******************************************************************************/
-
-int generic_symbol_at_address(bfd_vma addr, struct disassemble_info *info)
-{
-       return 1;
-}
-
-
-/* generic_print_address *******************************************************
-
-   Required by i386-dis.c, just print the address.
-
-*******************************************************************************/
-
-void generic_print_address(bfd_vma addr, struct disassemble_info *info)
-{
-       myprintf(info->stream, "0x%016lx", addr);
-}
-
-
-/* perror_memory ***************************************************************
-
-   Required by i386-dis.c, jsut assert in case.
-
-*******************************************************************************/
-
-void perror_memory(int status, bfd_vma memaddr, struct disassemble_info *info)
-{
-       assert(0);
-}
-
-
 /* disassinstr *****************************************************************
 
    Outputs a disassembler listing of one machine code instruction on
@@ -140,20 +55,26 @@ void perror_memory(int status, bfd_vma memaddr, struct disassemble_info *info)
 
 u1 *disassinstr(u1 *code)
 {
-       static disassemble_info info;
-       static int dis_initialized;
        s4 seqlen;
        s4 i;
 
-       if (!dis_initialized) {
-               INIT_DISASSEMBLE_INFO(info, NULL, myprintf);
-               info.mach = bfd_mach_i386_i386;
-               dis_initialized = 1;
+       if (!disass_initialized) {
+               INIT_DISASSEMBLE_INFO(info, NULL, disass_printf);
+
+               /* setting the struct members must be done after
+                  INIT_DISASSEMBLE_INFO */
+
+               info.mach             = bfd_mach_i386_i386;
+               info.read_memory_func = &disass_buffer_read_memory;
+
+               disass_initialized = 1;
        }
 
        printf("0x%08x:   ", (s4) code);
-       mylen = 0;
-       seqlen = print_insn_i386((bfd_vma) code, &info);
+
+       disass_len = 0;
+
+       seqlen = print_insn_i386((bfd_vma) (ptrint) code, &info);
 
        for (i = 0; i < seqlen; i++, code++) {
                printf("%02x ", *code);
@@ -163,35 +84,12 @@ u1 *disassinstr(u1 *code)
                printf("   ");
        }
 
-       printf("   %s\n", mylinebuf);
+       printf("   %s\n", disass_buf);
 
        return code;
 }
 
 
-
-/* disassemble *****************************************************************
-
-   Outputs a disassembler listing of some machine code on 'stdout'.
-
-   start: pointer to first machine instruction
-   end:   pointer after last machine instruction
-
-*******************************************************************************/
-
-void disassemble(u1 *start, u1 *end)
-{
-       disassemble_info info;
-
-       INIT_DISASSEMBLE_INFO(info, NULL, myprintf);
-       info.mach = bfd_mach_i386_i386;
-
-       printf("  --- disassembler listing ---\n");
-       for (; start < end; )
-               start = disassinstr(start);
-}
-
-
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where