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 preliminary KGDB support for NetBSD/us...



details:   https://anonhg.NetBSD.org/src/rev/06914dd6aa37
branches:  trunk
changeset: 365105:06914dd6aa37
user:      reinoud <reinoud%NetBSD.org@localhost>
date:      Wed Aug 01 09:50:57 2018 +0000

description:
Add preliminary KGDB support for NetBSD/usermode, currently only under amd64

diffstat:

 sys/arch/usermode/conf/files.usermode   |    5 +-
 sys/arch/usermode/include/cpu.h         |    4 +-
 sys/arch/usermode/include/db_machdep.h  |  106 +++++++++++++++++++++++--------
 sys/arch/usermode/include/genheaders.sh |    1 +
 sys/arch/usermode/include/pmap.h        |    5 +-
 5 files changed, 88 insertions(+), 33 deletions(-)

diffs (179 lines):

diff -r f8f6be33f521 -r 06914dd6aa37 sys/arch/usermode/conf/files.usermode
--- a/sys/arch/usermode/conf/files.usermode     Wed Aug 01 09:46:46 2018 +0000
+++ b/sys/arch/usermode/conf/files.usermode     Wed Aug 01 09:50:57 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.usermode,v 1.17 2018/06/05 20:02:42 reinoud Exp $
+# $NetBSD: files.usermode,v 1.18 2018/08/01 09:50:57 reinoud Exp $
 
 maxpartitions 8
 maxusers 8 16 64
@@ -62,6 +62,9 @@
 file   arch/usermode/usermode/syscall.c
 file   arch/usermode/usermode/trap.c
 file   arch/usermode/usermode/vm_machdep.c
+file   arch/usermode/usermode/db_memrw.c       ddb | kgdb
+file   arch/usermode/usermode/kgdb_machdep.c   ddb | kgdb
+file   arch/usermode/usermode/cpufunc.S        ddb | kgdb
 file   dev/cons.c
 file   dev/md_root.c                           memory_disk_hooks
 file   kern/subr_disk_mbr.c                    disk
diff -r f8f6be33f521 -r 06914dd6aa37 sys/arch/usermode/include/cpu.h
--- a/sys/arch/usermode/include/cpu.h   Wed Aug 01 09:46:46 2018 +0000
+++ b/sys/arch/usermode/include/cpu.h   Wed Aug 01 09:50:57 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.10 2012/02/08 17:55:21 reinoud Exp $ */
+/* $NetBSD: cpu.h,v 1.11 2018/08/01 09:50:57 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -47,7 +47,7 @@
 extern int     astpending;
 #define aston(ci) (astpending++)
 extern void cpu_need_resched(struct cpu_info *ci, int flags);
-
+extern void kgdb_port_init(void);
 
 struct cpu_info {
        struct cpu_data ci_data;                /* MI per-cpu data */
diff -r f8f6be33f521 -r 06914dd6aa37 sys/arch/usermode/include/db_machdep.h
--- a/sys/arch/usermode/include/db_machdep.h    Wed Aug 01 09:46:46 2018 +0000
+++ b/sys/arch/usermode/include/db_machdep.h    Wed Aug 01 09:50:57 2018 +0000
@@ -1,32 +1,80 @@
-/* $NetBSD: db_machdep.h,v 1.2 2009/10/21 16:06:59 snj Exp $ */
+/* $NetBSD: db_machdep.h,v 1.3 2018/08/01 09:50:57 reinoud Exp $ */
+
+#ifndef _USERMODE_DB_MACHDEP_H
+#define _USERMODE_DB_MACHDEP_H
+
+#include <sys/ucontext.h>
+#include <machine/trap.h>
+#include <machine/psl.h>
+#include <machine/ucontext.h>
+
+typedef long int db_expr_t;
+typedef vaddr_t db_addr_t;
+typedef ucontext_t db_regs_t;
+
+extern void breakpoint(void);
+extern void kgdb_kernel_trap(int signo,
+       vaddr_t pc, vaddr_t va, ucontext_t *ucp);
+extern int db_validate_address(vaddr_t addr); 
+
+/* same as amd64 */
+#ifndef MULTIPROCESSOR
+extern db_regs_t ddb_regs;     /* register state */
+#define        DDB_REGS        (&ddb_regs)
+#else
+extern db_regs_t *ddb_regp;
+#define DDB_REGS       (ddb_regp)
+#define ddb_regs       (*ddb_regp)
+#endif
+
+#if defined(__i386__)
+
+#define BKPT_SIZE 1
+#define BKPT_INST 0xcc         /* breakpoint instruction */
+#define        BKPT_ADDR(addr) (addr)
+#define BKPT_SET(inst, addr) (BKPT_INST)
+
+#error append db_machdep.h for i386
+
+#elif defined(__x86_64__)
 
-/*-
- * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
+#define        DDB_EXPR_FMT    "l"     /* expression is long */
+#define BKPT_SIZE 1
+#define BKPT_INST 0xcc         /* breakpoint instruction */
+#define        BKPT_ADDR(addr) (addr)
+#define BKPT_SET(inst, addr) (BKPT_INST)
+
+#define db_clear_single_step(regs) _UC_MACHINE_RFLAGS(regs) &= ~PSL_T
+#define db_set_single_step(regs)   _UC_MACHINE_RFLAGS(regs) |=  PSL_T
+#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BPTFLT)
+#define IS_WATCHPOINT_TRAP(type, code) (0)
+
+#define        I_CALL          0xe8
+#define        I_CALLI         0xff
+#define        I_RET           0xc3
+#define        I_IRET          0xcf
 
-#ifndef _ARCH_USERMODE_INCLUDE_DB_MACHDEP_H
-#define _ARCH_USERMODE_INCLUDE_DB_MACHDEP_H
+#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)         (__USE(ins), 0)
+#define inst_store(ins)                (__USE(ins), 0)
+
+typedef        long            kgdb_reg_t;
+#define        KGDB_NUMREGS    20
+#define        KGDB_BUFLEN     1024
 
-#endif /* !_ARCH_USERMODE_INCLUDE_DB_MACHDEP_H */
+#elif defined(__arm__)
+#error port kgdb for arm
+#else
+#error port me
+#endif
+
+/* commonly #define'd in db_machdep.h */
+#define PC_REGS(regs)  (_UC_MACHINE_PC(regs))
+#define PC_ADVANCE(r)  (_UC_MACHINE_PC(r) += BKPT_SIZE)
+#define FIXUP_PC_AFTER_BREAK(r) (_UC_MACHINE_PC(r) -= BKPT_SIZE)
+
+#endif
diff -r f8f6be33f521 -r 06914dd6aa37 sys/arch/usermode/include/genheaders.sh
--- a/sys/arch/usermode/include/genheaders.sh   Wed Aug 01 09:46:46 2018 +0000
+++ b/sys/arch/usermode/include/genheaders.sh   Wed Aug 01 09:50:57 2018 +0000
@@ -23,6 +23,7 @@
 HDRS="$HDRS cdefs.h"
 HDRS="$HDRS mcontext.h"
 HDRS="$HDRS frame_regs.h"
+HDRS="$HDRS cpufunc.h"
 
 for hdr in ${HDRS}; do
        G="_USERMODE_$(echo ${hdr} | sed 's/\./_/g' | tr [a-z] [A-Z])"
diff -r f8f6be33f521 -r 06914dd6aa37 sys/arch/usermode/include/pmap.h
--- a/sys/arch/usermode/include/pmap.h  Wed Aug 01 09:46:46 2018 +0000
+++ b/sys/arch/usermode/include/pmap.h  Wed Aug 01 09:50:57 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.5 2011/08/24 19:59:26 reinoud Exp $ */
+/* $NetBSD: pmap.h,v 1.6 2018/08/01 09:50:57 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -30,5 +30,8 @@
 #define _ARCH_USERMODE_INCLUDE_PMAP_H
 
 #define        PMAP_GROWKERNEL         1
+#define VTOPHYS_FAILED ((paddr_t)-1L)  /* POOL_PADDR_INVALID */
+
+paddr_t vtophys(vaddr_t);
 
 #endif /* !_ARCH_USERMODE_INCLUDE_PMAP_H */



Home | Main Index | Thread Index | Old Index