Module Name:    src
Committed By:   reinoud
Date:           Wed Aug  1 09:44:32 UTC 2018

Modified Files:
        src/sys/arch/usermode/usermode: machdep.c pmap.c thunk.c trap.c

Log Message:
Oops, forgot a debug printf


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/usermode/usermode/machdep.c
cvs rdiff -u -r1.108 -r1.109 src/sys/arch/usermode/usermode/pmap.c
cvs rdiff -u -r1.90 -r1.91 src/sys/arch/usermode/usermode/thunk.c
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/usermode/usermode/trap.c

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/usermode/machdep.c
diff -u src/sys/arch/usermode/usermode/machdep.c:1.56 src/sys/arch/usermode/usermode/machdep.c:1.57
--- src/sys/arch/usermode/usermode/machdep.c:1.56	Mon Jun 11 19:35:56 2018
+++ src/sys/arch/usermode/usermode/machdep.c	Wed Aug  1 09:44:31 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.56 2018/06/11 19:35:56 reinoud Exp $ */
+/* $NetBSD: machdep.c,v 1.57 2018/08/01 09:44:31 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org>
@@ -37,7 +37,7 @@
 #include "opt_memsize.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.56 2018/06/11 19:35:56 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.57 2018/08/01 09:44:31 reinoud Exp $");
 
 #include <sys/types.h>
 #include <sys/systm.h>
@@ -59,6 +59,11 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 
 #include <machine/machdep.h>
 #include <machine/mainbus.h>
 #include <machine/thunk.h>
+#include <machine/cpu.h>
+#include <sys/kgdb.h>
+
+#include "opt_ddb.h"
+#include "opt_kgdb.h"
 
 #ifndef MAX_DISK_IMAGES
 #define MAX_DISK_IMAGES	4
@@ -272,6 +277,18 @@ main(int argc, char *argv[])
 	splinit();
 	splraise(IPL_HIGH);
 
+#ifdef DDB
+	if (boothowto & RB_KDB)
+		Debugger();
+#endif
+#ifdef KGDB
+	if (boothowto & RB_KDB) {
+		kgdb_port_init();
+		kgdb_debug_init = 1;
+		kgdb_connect(1);
+	}
+#endif
+
 	kernmain();
 }
 
@@ -297,6 +314,7 @@ setstatclockrate(int arg)
 void
 consinit(void)
 {
+//	kgdb_connect(0);
 	printf("NetBSD/usermode startup\n");
 }
 

Index: src/sys/arch/usermode/usermode/pmap.c
diff -u src/sys/arch/usermode/usermode/pmap.c:1.108 src/sys/arch/usermode/usermode/pmap.c:1.109
--- src/sys/arch/usermode/usermode/pmap.c:1.108	Wed Aug  1 09:43:17 2018
+++ src/sys/arch/usermode/usermode/pmap.c	Wed Aug  1 09:44:31 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.108 2018/08/01 09:43:17 reinoud Exp $ */
+/* $NetBSD: pmap.c,v 1.109 2018/08/01 09:44:31 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.108 2018/08/01 09:43:17 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.109 2018/08/01 09:44:31 reinoud Exp $");
 
 #include "opt_memsize.h"
 #include "opt_kmempages.h"
@@ -660,7 +660,6 @@ pmap_fault(pmap_t pmap, vaddr_t va, vm_p
 
 	/* not known! then it must be UVM's work */
 	if (pv == NULL) {
-thunk_printf("%s: no mapping yet for %p\n", __func__, (void *) va);
 		thunk_printf_debug("%s: no mapping yet\n", __func__);
 		*atype = VM_PROT_READ;		/* assume it was a read */
 		return false;

Index: src/sys/arch/usermode/usermode/thunk.c
diff -u src/sys/arch/usermode/usermode/thunk.c:1.90 src/sys/arch/usermode/usermode/thunk.c:1.91
--- src/sys/arch/usermode/usermode/thunk.c:1.90	Mon Jun  4 19:53:01 2018
+++ src/sys/arch/usermode/usermode/thunk.c	Wed Aug  1 09:44:31 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: thunk.c,v 1.90 2018/06/04 19:53:01 reinoud Exp $ */
+/* $NetBSD: thunk.c,v 1.91 2018/08/01 09:44:31 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcne...@invisible.ca>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifdef __NetBSD__
-__RCSID("$NetBSD: thunk.c,v 1.90 2018/06/04 19:53:01 reinoud Exp $");
+__RCSID("$NetBSD: thunk.c,v 1.91 2018/08/01 09:44:31 reinoud Exp $");
 #endif
 
 #define _KMEMUSER
@@ -92,6 +92,9 @@ __RCSID("$NetBSD: thunk.c,v 1.90 2018/06
 
 //#define RFB_DEBUG
 
+static ssize_t safe_recv(int s, void *buf, int len);
+static ssize_t safe_send(int s, const void *msg, int len);
+
 extern int boothowto;
 
 void
@@ -1017,6 +1020,78 @@ thunk_rfb_open(thunk_rfb_t *rfb, uint16_
 	return 0;
 }
 
+int
+thunk_gdb_open(void)
+{
+	struct sockaddr_in sin;
+	int sockfd;
+	int portnr = 5001;	/* XXX configurable or random */
+
+	/* create socket */
+	sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+	if (sockfd < 0) {
+		warn("kgdb stub: couldn't create socket");
+		return 0;
+	}
+
+	/* bind to requested port */
+	memset(&sin, 0, sizeof(sin));
+	sin.sin_family      = AF_INET;
+	sin.sin_addr.s_addr = htonl(INADDR_ANY);
+	sin.sin_port        = htons(portnr);
+
+	if (bind(sockfd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+		warn("kgdb stub: couldn't bind port %d", portnr);
+		close(sockfd);
+		return 0;
+	}
+
+	/* listen for connections */
+	if (listen(sockfd, 1) < 0) {
+		warn("kgdb stub: couldn't listen on socket");
+		close(sockfd);
+		return 0;
+	}
+	printf("kgdb stub: accepting connections on port %d\n", portnr);
+
+	return sockfd;
+}
+
+int
+thunk_gdb_accept(int sockfd)
+{
+	struct sockaddr_in client_addr;
+	socklen_t client_addrlen;
+	int fd, flags;
+
+	fd = accept(sockfd, (struct sockaddr *) &client_addr, &client_addrlen);
+	if (fd < 0) {
+		warn("kgdb_stub: connect error");
+		return 0;
+	}
+
+  	/* make FIFO unblocking */
+	flags = fcntl(fd, F_GETFL, 0);
+	if (flags == -1)
+		flags = 0;
+	if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
+		warn("kgdb_stub: can't make socket non blocking");
+	}
+	return fd;
+}
+
+int
+thunk_kgdb_getc(int fd, char *ch)
+{
+	return safe_recv(fd, ch, 1);
+}
+
+int
+thunk_kgdb_putc(int fd, char ch)
+{
+	return safe_send(fd, &ch, 1);
+}
+
 static ssize_t
 safe_send(int s, const void *msg, int len)
 {

Index: src/sys/arch/usermode/usermode/trap.c
diff -u src/sys/arch/usermode/usermode/trap.c:1.69 src/sys/arch/usermode/usermode/trap.c:1.70
--- src/sys/arch/usermode/usermode/trap.c:1.69	Sat Jul 28 17:17:38 2018
+++ src/sys/arch/usermode/usermode/trap.c	Wed Aug  1 09:44:31 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.69 2018/07/28 17:17:38 reinoud Exp $ */
+/* $NetBSD: trap.c,v 1.70 2018/08/01 09:44:31 reinoud Exp $ */
 
 /*-
  * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.69 2018/07/28 17:17:38 reinoud Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.70 2018/08/01 09:44:31 reinoud Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -46,6 +46,12 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.6
 #include <machine/intr.h>
 #include <machine/thunk.h>
 
+#include "opt_kgdb.h"
+
+#ifdef KGDB
+#include <sys/kgdb.h>
+#endif
+
 /* define maximum signal number */
 #ifndef NSIG
 #define NSIG 64
@@ -61,6 +67,8 @@ static sigfunc_t alarm;
 static sigfunc_t sigio;
 static sigfunc_t pass_on;
 
+void kgdb_kernel_trap(int signo, vaddr_t pc, vaddr_t va, ucontext_t *ctx);
+
 /* raw signal handlers */
 static char    sig_stack[SIGSTKSZ];
 static stack_t sigstk;
@@ -123,7 +131,7 @@ setup_signal_handlers(void)
 	/* INT */	/* ttycons ^C */
 	/* QUIT */
 	signal_intr_establish(SIGILL, illegal_instruction);
-	/* TRAP */
+	signal_intr_establish(SIGTRAP, pass_on); 	/* special */
 	/* ABRT */
 	/* SIGEMT */
 	signal_intr_establish(SIGFPE, pass_on);
@@ -317,9 +325,6 @@ handle_signal(int sig, siginfo_t *info, 
 	f = sig_funcs[sig];
 	KASSERT(f);
 
-	l = curlwp; KASSERT(l);
-	pcb = lwp_getpcb(l); KASSERT(pcb);
-
 	/* get address of possible faulted memory access and page align it */
 	va = (vaddr_t) info->si_addr;
 	va = trunc_page(va);
@@ -327,7 +332,22 @@ handle_signal(int sig, siginfo_t *info, 
 	/* get PC address of possibly faulted instruction */
 	pc = md_get_pc(ctx);
 
-	/* nest it on the stack */
+	/*
+	 * short-cut for SIGTRAP as we have NO indication anything is valid
+	 */
+#ifdef KGDB
+	if (sig == SIGTRAP) {
+		from_userland = 0;
+		if (pc < kmem_user_end)
+			from_userland = 1;
+		if (!from_userland) {
+			kgdb_kernel_trap(sig, pc, va, ucp);
+			return;
+		}
+	}
+#endif
+
+	/* get stack pointer for nesting */
 	sp = md_get_sp(ctx);
 
 	if (sig == SIGBUS || sig == SIGSEGV)
@@ -335,6 +355,10 @@ handle_signal(int sig, siginfo_t *info, 
 	if (sig == SIGILL)
 		print_illegal_instruction_siginfo(sig, info, ctx, pc, va, sp);
 
+	/* get thread */
+	l = curlwp; KASSERT(l);
+	pcb = lwp_getpcb(l); KASSERT(pcb);
+
 	/* currently running on the dedicated signal stack */
 
 	/* if we're running on a userland stack, switch to the system stack */

Reply via email to