Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/amd64/amd64 Add disasm support for amd64 (x86-64).



details:   https://anonhg.NetBSD.org/src/rev/40341c943c2a
branches:  trunk
changeset: 574488:40341c943c2a
user:      matt <matt%NetBSD.org@localhost>
date:      Tue Mar 01 18:08:42 2005 +0000

description:
Add disasm support for amd64 (x86-64).
>From Cliff Neighbors.

diffstat:

 sys/arch/amd64/amd64/db_disasm.c |  1438 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 1435 insertions(+), 3 deletions(-)

diffs (truncated from 1464 to 300 lines):

diff -r 264bfb37a867 -r 40341c943c2a sys/arch/amd64/amd64/db_disasm.c
--- a/sys/arch/amd64/amd64/db_disasm.c  Tue Mar 01 16:42:53 2005 +0000
+++ b/sys/arch/amd64/amd64/db_disasm.c  Tue Mar 01 18:08:42 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_disasm.c,v 1.1 2003/04/26 18:39:27 fvdl Exp $       */
+/*     $NetBSD: db_disasm.c,v 1.2 2005/03/01 18:08:42 matt Exp $       */
 
 /* 
  * Mach Operating System
@@ -33,7 +33,15 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.1 2003/04/26 18:39:27 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_disasm.c,v 1.2 2005/03/01 18:08:42 matt Exp $");
+
+#ifndef _KERNEL
+#include "stubs.h"
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/ksyms.h>
+#include <machine/stdarg.h>
+#endif /* _KERNEL */
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -44,6 +52,1105 @@
 #include <ddb/db_output.h>
 #include <ddb/db_interface.h>
 
+#ifndef _KERNEL
+#define db_printsym(a, x, fn) fn("%lx ", (a))
+#endif
+
+/*
+ * Size attributes
+ */
+#define        BYTE    0
+#define        WORD    1
+#define        LONG    2
+#define        QUAD    3
+#define        SNGL    4
+#define        DBLR    5
+#define        EXTR    6
+#define        SDEP    7
+#define        NONE    8
+
+/*
+ * Addressing modes
+ */
+#define        E       1                       /* general effective address */
+#define        Eind    2                       /* indirect address (jump, call) */
+#define        Ew      3                       /* address, word size */
+#define        Eb      4                       /* address, byte size */
+#define        R       5                       /* register, in 'reg' field */
+#define        Rw      6                       /* word register, in 'reg' field */
+#define        Ri      7                       /* register in instruction */
+#define        S       8                       /* segment reg, in 'reg' field */
+#define        Si      9                       /* segment reg, in instruction */
+#define        A       10                      /* accumulator */
+#define        BX      11                      /* (bx) */
+#define        CL      12                      /* cl, for shifts */
+#define        DX      13                      /* dx, for IO */
+#define        SI      14                      /* si */
+#define        DI      15                      /* di */
+#define        CR      16                      /* control register */
+#define        DR      17                      /* debug register */
+#define        TR      18                      /* test register */
+#define        I       19                      /* immediate, unsigned */
+#define        Is      20                      /* immediate, signed */
+#define        Ib      21                      /* byte immediate, unsigned */
+#define        Ibs     22                      /* byte immediate, signed */
+#define        Iw      23                      /* word immediate, unsigned */
+#define        Il      24                      /* long immediate */
+#define        O       25                      /* direct address */
+#define        Db      26                      /* byte displacement from EIP */
+#define        Dl      27                      /* long displacement from EIP */
+#define        o1      28                      /* constant 1 */
+#define        o3      29                      /* constant 3 */
+#define        OS      30                      /* immediate offset/segment */
+#define        ST      31                      /* FP stack top */
+#define        STI     32                      /* FP stack */
+#define        X       33                      /* extended FP op */
+#define        XA      34                      /* for 'fstcw %ax' */
+#define        Ed      35                      /* address, double size */
+
+struct inst {
+       char *  i_name;                 /* name */
+       short   i_has_modrm;            /* has regmodrm byte */
+       short   i_size;                 /* operand size */
+       int     i_mode;                 /* addressing modes */
+       char *  i_extra;                /* pointer to extra opcode table */
+};
+
+#define        op1(x)          (x)
+#define        op2(x,y)        ((x)|((y)<<8))
+#define        op3(x,y,z)      ((x)|((y)<<8)|((z)<<16))
+
+struct finst {
+       char *  f_name;                 /* name for memory instruction */
+       int     f_size;                 /* size for memory instruction */
+       int     f_rrmode;               /* mode for rr instruction */
+       char *  f_rrname;               /* name for rr instruction
+                                          (or pointer to table) */
+};
+
+const char * const db_Grp6[] = {
+       "sldt",
+       "str",
+       "lldt",
+       "ltr",
+       "verr",
+       "verw",
+       "",
+       ""
+};
+
+const char * const db_Grp7[] = {
+       "sgdt",
+       "sidt",
+       "lgdt",
+       "lidt",
+       "smsw",
+       "",
+       "lmsw",
+       "invlpg"
+};
+
+const char * const db_Grp8[] = {
+       "",
+       "",
+       "",
+       "",
+       "bt",
+       "bts",
+       "btr",
+       "btc"
+};
+
+const char * const db_Grp9[] = {
+       "",
+       "cmpxchg8b",
+       "",
+       "",
+       "",
+       "",
+       "",
+       "",
+};
+
+const struct inst db_inst_0f0x[] = {
+/*00*/ { "",      TRUE,  NONE,  op1(Ew),     (char *)db_Grp6 },
+/*01*/ { "",      TRUE,  NONE,  op1(Ew),     (char *)db_Grp7 },
+/*02*/ { "lar",   TRUE,  LONG,  op2(E,R),    0 },
+/*03*/ { "lsl",   TRUE,  LONG,  op2(E,R),    0 },
+/*04*/ { "",      FALSE, NONE,  0,           0 },
+/*05*/ { "",      FALSE, NONE,  0,           0 },
+/*06*/ { "clts",  FALSE, NONE,  0,           0 },
+/*07*/ { "",      FALSE, NONE,  0,           0 },
+
+/*08*/ { "invd",  FALSE, NONE,  0,           0 },
+/*09*/ { "wbinvd",FALSE, NONE,  0,           0 },
+/*0a*/ { "",      FALSE, NONE,  0,           0 },
+/*0b*/ { "",      FALSE, NONE,  0,           0 },
+/*0c*/ { "",      FALSE, NONE,  0,           0 },
+/*0d*/ { "",      FALSE, NONE,  0,           0 },
+/*0e*/ { "",      FALSE, NONE,  0,           0 },
+/*0f*/ { "",      FALSE, NONE,  0,           0 },
+};
+
+const struct inst      db_inst_0f2x[] = {
+/*20*/ { "mov",   TRUE,  LONG,  op2(CR,E),   0 }, /* use E for reg */
+/*21*/ { "mov",   TRUE,  LONG,  op2(DR,E),   0 }, /* since mod == 11 */
+/*22*/ { "mov",   TRUE,  LONG,  op2(E,CR),   0 },
+/*23*/ { "mov",   TRUE,  LONG,  op2(E,DR),   0 },
+/*24*/ { "mov",   TRUE,  LONG,  op2(TR,E),   0 },
+/*25*/ { "",      FALSE, NONE,  0,           0 },
+/*26*/ { "mov",   TRUE,  LONG,  op2(E,TR),   0 },
+/*27*/ { "",      FALSE, NONE,  0,           0 },
+
+/*28*/ { "",      FALSE, NONE,  0,           0 },
+/*29*/ { "",      FALSE, NONE,  0,           0 },
+/*2a*/ { "",      FALSE, NONE,  0,           0 },
+/*2b*/ { "",      FALSE, NONE,  0,           0 },
+/*2c*/ { "",      FALSE, NONE,  0,           0 },
+/*2d*/ { "",      FALSE, NONE,  0,           0 },
+/*2e*/ { "",      FALSE, NONE,  0,           0 },
+/*2f*/ { "",      FALSE, NONE,  0,           0 },
+};
+
+const struct inst      db_inst_0f3x[] = {
+/*30*/ { "wrmsr", FALSE, NONE,  0,           0 },
+/*31*/ { "rdtsc", FALSE, NONE,  0,           0 },
+/*32*/ { "rdmsr", FALSE, NONE,  0,           0 },
+/*33*/ { "rdpmc", FALSE, NONE,  0,           0 },
+/*34*/ { "",      FALSE, NONE,  0,           0 },
+/*35*/ { "",      FALSE, NONE,  0,           0 },
+/*36*/ { "",      FALSE, NONE,  0,           0 },
+/*37*/ { "",      FALSE, NONE,  0,           0 },
+
+/*38*/ { "",      FALSE, NONE,  0,           0 },
+/*39*/ { "",      FALSE, NONE,  0,           0 },
+/*3a*/ { "",      FALSE, NONE,  0,           0 },
+/*3v*/ { "",      FALSE, NONE,  0,           0 },
+/*3c*/ { "",      FALSE, NONE,  0,           0 },
+/*3d*/ { "",      FALSE, NONE,  0,           0 },
+/*3e*/ { "",      FALSE, NONE,  0,           0 },
+/*3f*/ { "",      FALSE, NONE,  0,           0 },
+};
+
+const struct inst      db_inst_0f8x[] = {
+/*80*/ { "jo",    FALSE, NONE,  op1(Dl),     0 },
+/*81*/ { "jno",   FALSE, NONE,  op1(Dl),     0 },
+/*82*/ { "jb",    FALSE, NONE,  op1(Dl),     0 },
+/*83*/ { "jnb",   FALSE, NONE,  op1(Dl),     0 },
+/*84*/ { "jz",    FALSE, NONE,  op1(Dl),     0 },
+/*85*/ { "jnz",   FALSE, NONE,  op1(Dl),     0 },
+/*86*/ { "jbe",   FALSE, NONE,  op1(Dl),     0 },
+/*87*/ { "jnbe",  FALSE, NONE,  op1(Dl),     0 },
+
+/*88*/ { "js",    FALSE, NONE,  op1(Dl),     0 },
+/*89*/ { "jns",   FALSE, NONE,  op1(Dl),     0 },
+/*8a*/ { "jp",    FALSE, NONE,  op1(Dl),     0 },
+/*8b*/ { "jnp",   FALSE, NONE,  op1(Dl),     0 },
+/*8c*/ { "jl",    FALSE, NONE,  op1(Dl),     0 },
+/*8d*/ { "jnl",   FALSE, NONE,  op1(Dl),     0 },
+/*8e*/ { "jle",   FALSE, NONE,  op1(Dl),     0 },
+/*8f*/ { "jnle",  FALSE, NONE,  op1(Dl),     0 },
+};
+
+const struct inst      db_inst_0f9x[] = {
+/*90*/ { "seto",  TRUE,  NONE,  op1(Eb),     0 },
+/*91*/ { "setno", TRUE,  NONE,  op1(Eb),     0 },
+/*92*/ { "setb",  TRUE,  NONE,  op1(Eb),     0 },
+/*93*/ { "setnb", TRUE,  NONE,  op1(Eb),     0 },
+/*94*/ { "setz",  TRUE,  NONE,  op1(Eb),     0 },
+/*95*/ { "setnz", TRUE,  NONE,  op1(Eb),     0 },
+/*96*/ { "setbe", TRUE,  NONE,  op1(Eb),     0 },
+/*97*/ { "setnbe",TRUE,  NONE,  op1(Eb),     0 },
+
+/*98*/ { "sets",  TRUE,  NONE,  op1(Eb),     0 },
+/*99*/ { "setns", TRUE,  NONE,  op1(Eb),     0 },
+/*9a*/ { "setp",  TRUE,  NONE,  op1(Eb),     0 },
+/*9b*/ { "setnp", TRUE,  NONE,  op1(Eb),     0 },
+/*9c*/ { "setl",  TRUE,  NONE,  op1(Eb),     0 },
+/*9d*/ { "setnl", TRUE,  NONE,  op1(Eb),     0 },
+/*9e*/ { "setle", TRUE,  NONE,  op1(Eb),     0 },
+/*9f*/ { "setnle",TRUE,  NONE,  op1(Eb),     0 },
+};
+
+const struct inst      db_inst_0fax[] = {
+/*a0*/ { "push",  FALSE, NONE,  op1(Si),     0 },
+/*a1*/ { "pop",   FALSE, NONE,  op1(Si),     0 },
+/*a2*/ { "cpuid", FALSE, NONE,  0,           0 },
+/*a3*/ { "bt",    TRUE,  LONG,  op2(R,E),    0 },
+/*a4*/ { "shld",  TRUE,  LONG,  op3(Ib,E,R), 0 },
+/*a5*/ { "shld",  TRUE,  LONG,  op3(CL,E,R), 0 },
+/*a6*/ { "",      FALSE, NONE,  0,           0 },
+/*a7*/ { "",      FALSE, NONE,  0,           0 },
+
+/*a8*/ { "push",  FALSE, NONE,  op1(Si),     0 },
+/*a9*/ { "pop",   FALSE, NONE,  op1(Si),     0 },
+/*aa*/ { "rsm",   FALSE, NONE,  0,           0 },
+/*ab*/ { "bts",   TRUE,  LONG,  op2(R,E),    0 },
+/*ac*/ { "shrd",  TRUE,  LONG,  op3(Ib,E,R), 0 },
+/*ad*/ { "shrd",  TRUE,  LONG,  op3(CL,E,R), 0 },
+/*ae*/ { "fxsave",TRUE,  LONG,  0,           0 },
+/*af*/ { "imul",  TRUE,  LONG,  op2(E,R),    0 },
+};
+
+const struct inst      db_inst_0fbx[] = {
+/*b0*/ { "cmpxchg",TRUE, BYTE, op2(R, E),   0 },
+/*b1*/ { "cmpxchg",TRUE, LONG, op2(R, E),   0 },
+/*b2*/ { "lss",   TRUE,  LONG,  op2(E, R),   0 },
+/*b3*/ { "btr",   TRUE,  LONG,  op2(R, E),   0 },
+/*b4*/ { "lfs",   TRUE,  LONG,  op2(E, R),   0 },
+/*b5*/ { "lgs",   TRUE,  LONG,  op2(E, R),   0 },
+/*b6*/ { "movzb", TRUE,  LONG,  op2(E, R),   0 },
+/*b7*/ { "movzw", TRUE,  LONG,  op2(E, R),   0 },
+
+/*b8*/ { "",      FALSE, NONE,  0,           0 },
+/*b9*/ { "",      FALSE, NONE,  0,           0 },
+/*ba*/ { "",      TRUE,  LONG,  op2(Ib, E),  (char *)db_Grp8 },
+/*bb*/ { "btc",   TRUE,  LONG,  op2(R, E),   0 },
+/*bc*/ { "bsf",   TRUE,  LONG,  op2(E, R),   0 },
+/*bd*/ { "bsr",   TRUE,  LONG,  op2(E, R),   0 },
+/*be*/ { "movsb", TRUE,  LONG,  op2(E, R),   0 },
+/*bf*/ { "movsw", TRUE,  LONG,  op2(E, R),   0 },
+};
+
+const struct inst      db_inst_0fcx[] = {
+/*c0*/ { "xadd",  TRUE,  BYTE, op2(R, E),   0 },
+/*c1*/ { "xadd",  TRUE,  LONG, op2(R, E),   0 },
+/*c2*/ { "",      FALSE, NONE, 0,            0 },
+/*c3*/ { "",      FALSE, NONE, 0,            0 },
+/*c4*/ { "",      FALSE, NONE, 0,            0 },
+/*c5*/ { "",      FALSE, NONE, 0,            0 },
+/*c6*/ { "",      FALSE, NONE, 0,            0 },
+/*c7*/ { "",      TRUE,  NONE, op1(E),      (char *)db_Grp9 },
+/*c8*/ { "bswap", FALSE, LONG,  op1(Ri),     0 },



Home | Main Index | Thread Index | Old Index