Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/usermode Add KGDB definitions for i386



details:   https://anonhg.NetBSD.org/src/rev/54cd99feb66e
branches:  trunk
changeset: 365200:54cd99feb66e
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Sun Aug 05 18:42:48 2018 +0000

description:
Add KGDB definitions for i386

diffstat:

 sys/arch/usermode/include/db_machdep.h    |  27 +++++++++-
 sys/arch/usermode/include/ucontext.h      |   4 +-
 sys/arch/usermode/usermode/cpufunc.S      |   8 ++-
 sys/arch/usermode/usermode/kgdb_machdep.c |  82 ++++++++++++------------------
 4 files changed, 68 insertions(+), 53 deletions(-)

diffs (199 lines):

diff -r b0ee4447e05e -r 54cd99feb66e sys/arch/usermode/include/db_machdep.h
--- a/sys/arch/usermode/include/db_machdep.h    Sun Aug 05 17:39:55 2018 +0000
+++ b/sys/arch/usermode/include/db_machdep.h    Sun Aug 05 18:42:48 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: db_machdep.h,v 1.3 2018/08/01 09:50:57 reinoud Exp $ */
+/* $NetBSD: db_machdep.h,v 1.4 2018/08/05 18:42:48 reinoud Exp $ */
 
 #ifndef _USERMODE_DB_MACHDEP_H
 #define _USERMODE_DB_MACHDEP_H
@@ -27,6 +27,7 @@
 #define ddb_regs       (*ddb_regp)
 #endif
 
+/* copied here in verbatim to remove dependencies */
 #if defined(__i386__)
 
 #define BKPT_SIZE 1
@@ -34,8 +35,30 @@
 #define        BKPT_ADDR(addr) (addr)
 #define BKPT_SET(inst, addr) (BKPT_INST)
 
-#error append db_machdep.h for i386
+#define        db_clear_single_step(regs)      _UC_MACHINE_EFLAGS(regs) &= ~PSL_T
+#define        db_set_single_step(regs)        _UC_MACHINE_EFLAGS(regs) |= PSL_T
+
+#define        IS_BREAKPOINT_TRAP(type, code)  ((type) == T_BPTFLT)
+#define IS_WATCHPOINT_TRAP(type, code) ((type) == T_TRCTRAP && (code) & 15)
+
+#define        I_CALL          0xe8
+#define        I_CALLI         0xff
+#define        I_RET           0xc3
+#define        I_IRET          0xcf
 
+#define        inst_trap_return(ins)   (((ins)&0xff) == I_IRET)
+#define        inst_return(ins)        (((ins)&0xff) == I_RET)
+#define        inst_call(ins)          (((ins)&0xff) == I_CALL || \
+                                (((ins)&0xff) == I_CALLI && \
+                                 ((ins)&0x3800) == 0x1000))
+#define inst_load(ins)         0
+#define inst_store(ins)                0
+
+typedef        int             kgdb_reg_t;
+#define        KGDB_NUMREGS    16
+#define        KGDB_BUFLEN     512
+
+/* copied here in verbatim to remove dependencies */
 #elif defined(__x86_64__)
 
 #define        DDB_EXPR_FMT    "l"     /* expression is long */
diff -r b0ee4447e05e -r 54cd99feb66e sys/arch/usermode/include/ucontext.h
--- a/sys/arch/usermode/include/ucontext.h      Sun Aug 05 17:39:55 2018 +0000
+++ b/sys/arch/usermode/include/ucontext.h      Sun Aug 05 18:42:48 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ucontext.h,v 1.1 2018/08/01 09:52:15 reinoud Exp $ */
+/* $NetBSD: ucontext.h,v 1.2 2018/08/05 18:42:48 reinoud Exp $ */
 
 #ifndef _USERMODE_UCONTEXT_H
 #define _USERMODE_UCONTEXT_H
@@ -9,6 +9,8 @@
 
 #if defined(__i386__)
 
+#define _UC_MACHINE_EFLAGS(uc) ((uc)->uc_mcontext.__gregs[_REG_EFL])
+
 #elif defined(__x86_64__)
 
 #define _UC_MACHINE_RFLAGS(uc) ((uc)->uc_mcontext.__gregs[26])
diff -r b0ee4447e05e -r 54cd99feb66e sys/arch/usermode/usermode/cpufunc.S
--- a/sys/arch/usermode/usermode/cpufunc.S      Sun Aug 05 17:39:55 2018 +0000
+++ b/sys/arch/usermode/usermode/cpufunc.S      Sun Aug 05 18:42:48 2018 +0000
@@ -5,10 +5,14 @@
 #if defined(__i386__)
 
 ENTRY(breakpoint)
-       .byte 0xcc      // BKPT_INST
+       pushl   %ebp
+       movl    %esp, %ebp
+       int     $0x03           /* paranoid, not 'int3' */
+       popl    %ebp
        ret
+END(breakpoint)
 
-#error implement setjmp/longjmp for i386
+//#error TODO implement setjmp/longjmp for i386?
 
 #elif defined(__amd64__)
 ENTRY(breakpoint)
diff -r b0ee4447e05e -r 54cd99feb66e sys/arch/usermode/usermode/kgdb_machdep.c
--- a/sys/arch/usermode/usermode/kgdb_machdep.c Sun Aug 05 17:39:55 2018 +0000
+++ b/sys/arch/usermode/usermode/kgdb_machdep.c Sun Aug 05 18:42:48 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kgdb_machdep.c,v 1.3 2018/08/01 10:24:41 reinoud Exp $ */
+/*     $NetBSD: kgdb_machdep.c,v 1.4 2018/08/05 18:42:48 reinoud Exp $ */
 
 /*
  * Copyright (c) 1996 Matthias Pfaller.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kgdb_machdep.c,v 1.3 2018/08/01 10:24:41 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kgdb_machdep.c,v 1.4 2018/08/05 18:42:48 reinoud Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -127,34 +127,25 @@
        gdb_regs[19] = gregs[_REG_SS];
                
 #elif defined(__i386)
-       gdb_regs[ 0] = regs->tf_eax;
-       gdb_regs[ 1] = regs->tf_ecx;
-       gdb_regs[ 2] = regs->tf_edx;
-       gdb_regs[ 3] = regs->tf_ebx;
-       gdb_regs[ 4] = regs->tf_esp;
-       gdb_regs[ 5] = regs->tf_ebp;
-       gdb_regs[ 6] = regs->tf_esi;
-       gdb_regs[ 7] = regs->tf_edi;
-       gdb_regs[ 8] = regs->tf_eip;
-       gdb_regs[ 9] = regs->tf_eflags;
-       gdb_regs[10] = regs->tf_cs;
-       gdb_regs[11] = regs->tf_ss;
-       gdb_regs[12] = regs->tf_ds;
-       gdb_regs[13] = regs->tf_es;
-       gdb_regs[14] = regs->tf_fs;
-       gdb_regs[15] = regs->tf_gs;
+       kgdb_reg_t *gregs = regs->uc_mcontext.__gregs;
 
-/*XXX OOPS XXX? */
-#if 0
-       if (KERNELMODE(regs->tf_cs)) {
-               /*
-                * Kernel mode - esp and ss not saved.
-                */
-               gdb_regs[ 4] = (kgdb_reg_t)&regs->tf_esp; /* kernel stack
-                                                            pointer */
-               gdb_regs[11] = x86_getss();
-       }
-#endif
+       gdb_regs[ 0] = gregs[_REG_EAX];
+       gdb_regs[ 1] = gregs[_REG_ECX];
+       gdb_regs[ 2] = gregs[_REG_EDX];
+       gdb_regs[ 3] = gregs[_REG_EBX];
+       gdb_regs[ 4] = gregs[_REG_ESP];
+       gdb_regs[ 5] = gregs[_REG_EBP];
+       gdb_regs[ 6] = gregs[_REG_ESI];
+       gdb_regs[ 7] = gregs[_REG_EDI];
+       gdb_regs[ 8] = gregs[_REG_EIP];
+       gdb_regs[ 9] = gregs[_REG_EFL];
+       gdb_regs[10] = gregs[_REG_CS];
+       gdb_regs[11] = gregs[_REG_SS];
+       gdb_regs[12] = gregs[_REG_DS];
+       gdb_regs[13] = gregs[_REG_ES];
+       gdb_regs[14] = gregs[_REG_FS];
+       gdb_regs[15] = gregs[_REG_GS];
+
 #else
 #error port kgdb_machdep.c kgdb_getregs
 #endif
@@ -192,26 +183,21 @@
        gregs[_REG_SS ] = gdb_regs[19];
 #elif defined(__i386)
 panic("%s", __func__);
-       regs->tf_eax    = gdb_regs[ 0];
-       regs->tf_ecx    = gdb_regs[ 1];
-       regs->tf_edx    = gdb_regs[ 2];
-       regs->tf_ebx    = gdb_regs[ 3];
-       regs->tf_ebp    = gdb_regs[ 5];
-       regs->tf_esi    = gdb_regs[ 6];
-       regs->tf_edi    = gdb_regs[ 7];
-       regs->tf_eip    = gdb_regs[ 8];
-       regs->tf_eflags = gdb_regs[ 9];
-       regs->tf_cs     = gdb_regs[10];
-       regs->tf_ds     = gdb_regs[12];
-       regs->tf_es     = gdb_regs[13];
+       kgdb_reg_t *gregs = regs->uc_mcontext.__gregs;
 
-       if (KERNELMODE(regs->tf_cs) == 0) {
-               /*
-                * Trapped in user mode - restore esp and ss.
-                */
-               regs->tf_esp = gdb_regs[ 4];
-               regs->tf_ss  = gdb_regs[11];
-       }
+       gregs[_REG_EAX] = gdb_regs[ 0];
+       gregs[_REG_ECX] = gdb_regs[ 1];
+       gregs[_REG_EDX] = gdb_regs[ 2];
+       gregs[_REG_EBX] = gdb_regs[ 3];
+       gregs[_REG_EBP] = gdb_regs[ 5];
+       gregs[_REG_ESI] = gdb_regs[ 6];
+       gregs[_REG_EDI] = gdb_regs[ 7];
+       gregs[_REG_EIP] = gdb_regs[ 8];
+       gregs[_REG_EFL] = gdb_regs[ 9];
+       gregs[_REG_CS]  = gdb_regs[10];
+       gregs[_REG_DS]  = gdb_regs[12];
+       gregs[_REG_ES]  = gdb_regs[13];
+
 #else
 panic("%s", __func__);
 #endif



Home | Main Index | Thread Index | Old Index