From owner-svn-src-head@freebsd.org Sat Aug 13 18:46:51 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 35A30BB8508; Sat, 13 Aug 2016 18:46:51 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EB499181E; Sat, 13 Aug 2016 18:46:50 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7DIkoaU004121; Sat, 13 Aug 2016 18:46:50 GMT (envelope-from jhibbits@FreeBSD.org) Received: (from jhibbits@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7DIknwl004117; Sat, 13 Aug 2016 18:46:49 GMT (envelope-from jhibbits@FreeBSD.org) Message-Id: <201608131846.u7DIknwl004117@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhibbits set sender to jhibbits@FreeBSD.org using -f From: Justin Hibbits Date: Sat, 13 Aug 2016 18:46:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r304051 - in head/sys/powerpc: aim booke powerpc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Aug 2016 18:46:51 -0000 Author: jhibbits Date: Sat Aug 13 18:46:49 2016 New Revision: 304051 URL: https://svnweb.freebsd.org/changeset/base/304051 Log: Add a kdb show command to print arbitrary SPRs on PowerPC Summary: There is often a need at the debugger to print arbitrary special purpose registers (SPRs) on PowerPC. Using a rewritable asm stub, print any SPR provided on the command line. Note, as there is no checking in this, attempting to print a nonexistent SPR may cause a Program exception (illegal instruction, or boundedly undefined). Note also that this relies on the kernel text pages being writable. If in the future this is made not the case, this will need to be reworked. Test Plan: Printing the Processor Version Register (PVR, SPR 287): db> show spr 11f SPR 287(11f): 80240012 Differential Revision: https://reviews.freebsd.org/D7403 Modified: head/sys/powerpc/aim/locore.S head/sys/powerpc/booke/locore.S head/sys/powerpc/powerpc/machdep.c Modified: head/sys/powerpc/aim/locore.S ============================================================================== --- head/sys/powerpc/aim/locore.S Sat Aug 13 18:10:32 2016 (r304050) +++ head/sys/powerpc/aim/locore.S Sat Aug 13 18:46:49 2016 (r304051) @@ -6,3 +6,10 @@ #include #endif +/* + * XXX: This should be moved to a shared AIM/booke asm file, if one ever is + * created. + */ +ENTRY(get_spr) + mfspr %r3, 0 + blr Modified: head/sys/powerpc/booke/locore.S ============================================================================== --- head/sys/powerpc/booke/locore.S Sat Aug 13 18:10:32 2016 (r304050) +++ head/sys/powerpc/booke/locore.S Sat Aug 13 18:46:49 2016 (r304051) @@ -848,6 +848,14 @@ ENTRY(dataloss_erratum_access) blr +/* + * XXX: This should be moved to a shared AIM/booke asm file, if one ever is + * created. + */ +ENTRY(get_spr) + mfspr %r3, 0 + blr + /************************************************************************/ /* Data section */ /************************************************************************/ Modified: head/sys/powerpc/powerpc/machdep.c ============================================================================== --- head/sys/powerpc/powerpc/machdep.c Sat Aug 13 18:10:32 2016 (r304050) +++ head/sys/powerpc/powerpc/machdep.c Sat Aug 13 18:46:49 2016 (r304051) @@ -516,3 +516,31 @@ spinlock_exit(void) } } +/* + * Simple ddb(4) command/hack to view any SPR on the running CPU. + * Uses a trivial asm function to perform the mfspr, and rewrites the mfspr + * instruction each time. + * XXX: Since it uses code modification, it won't work if the kernel code pages + * are marked RO. + */ +extern register_t get_spr(int); + +DB_SHOW_COMMAND(spr, db_show_spr) +{ + register_t spr; + volatile uint32_t *p; + int sprno, saved_sprno; + + if (!have_addr) + return; + + saved_sprno = sprno = (intptr_t) addr; + sprno = ((sprno & 0x3e0) >> 5) | ((sprno & 0x1f) << 5); + p = (uint32_t *)(void *)&get_spr; + *p = (*p & ~0x001ff800) | (sprno << 11); + __syncicache(get_spr, cacheline_size); + spr = get_spr(sprno); + + db_printf("SPR %d(%x): %lx\n", saved_sprno, saved_sprno, + (unsigned long)spr); +}