From owner-p4-projects@FreeBSD.ORG  Wed Nov  7 05:45:00 2012
Return-Path: <owner-p4-projects@FreeBSD.ORG>
Delivered-To: p4-projects@freebsd.org
Received: by hub.freebsd.org (Postfix, from userid 32767)
 id 1673E238; Wed,  7 Nov 2012 05:45:00 +0000 (UTC)
Delivered-To: perforce@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
 by hub.freebsd.org (Postfix) with ESMTP id A9EF0236
 for <perforce@freebsd.org>; Wed,  7 Nov 2012 05:44:59 +0000 (UTC)
 (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org)
Received: from skunkworks.freebsd.org (skunkworks.freebsd.org
 [IPv6:2001:4f8:fff6::2d])
 by mx1.freebsd.org (Postfix) with ESMTP id 74EB68FC12
 for <perforce@freebsd.org>; Wed,  7 Nov 2012 05:44:59 +0000 (UTC)
Received: from skunkworks.freebsd.org (localhost [127.0.0.1])
 by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id qA75ixaV004645
 for <perforce@freebsd.org>; Wed, 7 Nov 2012 05:44:59 GMT
 (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org)
Received: (from perforce@localhost)
 by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id qA75ixTO004642
 for perforce@freebsd.org; Wed, 7 Nov 2012 05:44:59 GMT
 (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org)
Date: Wed, 7 Nov 2012 05:44:59 GMT
Message-Id: <201211070544.qA75ixTO004642@skunkworks.freebsd.org>
X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to
 bb+lists.freebsd.perforce@cyrus.watson.org using -f
From: Robert Watson <rwatson@FreeBSD.org>
Subject: PERFORCE change 219642 for review
To: Perforce Change Reviews <perforce@freebsd.org>
Precedence: bulk
X-BeenThere: p4-projects@freebsd.org
X-Mailman-Version: 2.1.14
List-Id: p4 projects tree changes <p4-projects.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/p4-projects>,
 <mailto:p4-projects-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/p4-projects>
List-Post: <mailto:p4-projects@freebsd.org>
List-Help: <mailto:p4-projects-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/p4-projects>,
 <mailto:p4-projects-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Wed, 07 Nov 2012 05:45:00 -0000

http://p4web.freebsd.org/@@219642?ac=10

Change 219642 by rwatson@rwatson_svr_ctsrd_mipsbuild on 2012/11/07 05:44:49

	When a capability exception is thrown in userspace, display some
	additional information on the state of CHERI's capability registers.

Affected files ...

.. //depot/projects/ctsrd/cheribsd/src/sys/mips/cheri/cheri.c#6 edit

Differences ...

==== //depot/projects/ctsrd/cheribsd/src/sys/mips/cheri/cheri.c#6 (text+ko) ====

@@ -238,17 +238,49 @@
 	cheri_capability_set_user(&cfp->cf_pcc);
 }
 
+#define	CHERI_REG_PRINT(c, ctag, num) do {				\
+	printf("C%u t: %u u: %u perms %04jx otype %016jx\n", num,	\
+	    ctag, c.c_unsealed, (uintmax_t)c.c_perms,			\
+	    (uintmax_t)c.c_otype);					\
+	printf("\tbase %016jx length %016jx\n", (uintmax_t)c.c_base,	\
+	    (uintmax_t)c.c_length);					\
+} while (0)
+
 void
 cheri_log_exception(struct trapframe *frame, int trap_type)
 {
+	struct cheri_frame *cheriframe;
+	struct chericap c;
 	register_t cause;
+	u_int ctag;
+	uint8_t exccode, regnum;
 
 #ifdef SMP
 	printf("cpuid = %d\n", PCPU_GET(cpuid));
 #endif
 	CHERI_CGETCAUSE(cause);
-	printf("CHERI cause: ExcCode: %02x RegNum: %02x\n",
-	    (uint8_t)((cause >> 8) & 0xff), (uint8_t)(cause & 0x1f));
+	exccode = (cause >> 8) & 0xff;
+	regnum = cause & 0x1f;
+	printf("CHERI cause: ExcCode: %02x RegNum: %02x\n", exccode, regnum);
+
+	/* XXXRW: awkward and unmaintainable pointer construction. */
+	cheriframe = &(((struct pcb *)frame)->pcb_cheriframe);
+
+	/* C0 */
+	intr_disable();
+	CHERI_CLC(CHERI_CR_KR1C, CHERI_CR_KDC, &cheriframe->cf_c0, 0);
+	CHERI_GETCAPREG(CHERI_CR_KR1C, c);
+	CHERI_CGETTAG(ctag, 0);
+	intr_enable();
+	CHERI_REG_PRINT(c, ctag, 0);
+
+	/* EPCC */
+	intr_disable();
+	CHERI_CLC(CHERI_CR_KR1C, CHERI_CR_KDC, &cheriframe->cf_pcc, 0);
+	CHERI_GETCAPREG(CHERI_CR_KR1C, c);
+	CHERI_CGETTAG(ctag, 31);
+	intr_enable();
+	CHERI_REG_PRINT(c, ctag, 31);
 }
 
 #ifdef DDB