Module Name: src
Committed By: reinoud
Date: Wed Aug 1 09:50:57 UTC 2018
Modified Files:
src/sys/arch/usermode/conf: files.usermode
src/sys/arch/usermode/include: cpu.h db_machdep.h genheaders.sh pmap.h
Log Message:
Add preliminary KGDB support for NetBSD/usermode, currently only under amd64
To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/usermode/conf/files.usermode
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/usermode/include/cpu.h \
src/sys/arch/usermode/include/genheaders.sh
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/usermode/include/db_machdep.h
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/usermode/include/pmap.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/usermode/conf/files.usermode
diff -u src/sys/arch/usermode/conf/files.usermode:1.17 src/sys/arch/usermode/conf/files.usermode:1.18
--- src/sys/arch/usermode/conf/files.usermode:1.17 Tue Jun 5 20:02:42 2018
+++ src/sys/arch/usermode/conf/files.usermode Wed Aug 1 09:50:57 2018
@@ -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/sys_machdep.
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
Index: src/sys/arch/usermode/include/cpu.h
diff -u src/sys/arch/usermode/include/cpu.h:1.10 src/sys/arch/usermode/include/cpu.h:1.11
--- src/sys/arch/usermode/include/cpu.h:1.10 Wed Feb 8 17:55:21 2012
+++ src/sys/arch/usermode/include/cpu.h Wed Aug 1 09:50:57 2018
@@ -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 <[email protected]>
@@ -47,7 +47,7 @@ struct cpu_info;
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 */
Index: src/sys/arch/usermode/include/genheaders.sh
diff -u src/sys/arch/usermode/include/genheaders.sh:1.10 src/sys/arch/usermode/include/genheaders.sh:1.11
--- src/sys/arch/usermode/include/genheaders.sh:1.10 Wed May 16 12:40:26 2018
+++ src/sys/arch/usermode/include/genheaders.sh Wed Aug 1 09:50:57 2018
@@ -23,6 +23,7 @@ HDRS="$HDRS wchar_limits.h"
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])"
Index: src/sys/arch/usermode/include/db_machdep.h
diff -u src/sys/arch/usermode/include/db_machdep.h:1.2 src/sys/arch/usermode/include/db_machdep.h:1.3
--- src/sys/arch/usermode/include/db_machdep.h:1.2 Wed Oct 21 16:06:59 2009
+++ src/sys/arch/usermode/include/db_machdep.h Wed Aug 1 09:50:57 2018
@@ -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 $ */
-/*-
- * Copyright (c) 2007 Jared D. McNeill <[email protected]>
- * 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.
- */
+#ifndef _USERMODE_DB_MACHDEP_H
+#define _USERMODE_DB_MACHDEP_H
-#ifndef _ARCH_USERMODE_INCLUDE_DB_MACHDEP_H
-#define _ARCH_USERMODE_INCLUDE_DB_MACHDEP_H
+#include <sys/ucontext.h>
+#include <machine/trap.h>
+#include <machine/psl.h>
+#include <machine/ucontext.h>
-#endif /* !_ARCH_USERMODE_INCLUDE_DB_MACHDEP_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__)
+
+#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
+
+#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
+
+#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
Index: src/sys/arch/usermode/include/pmap.h
diff -u src/sys/arch/usermode/include/pmap.h:1.5 src/sys/arch/usermode/include/pmap.h:1.6
--- src/sys/arch/usermode/include/pmap.h:1.5 Wed Aug 24 19:59:26 2011
+++ src/sys/arch/usermode/include/pmap.h Wed Aug 1 09:50:57 2018
@@ -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 <[email protected]>
@@ -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 */