Module Name: src Committed By: jym Date: Mon May 7 17:45:29 UTC 2012
Modified Files: src/sys/arch/amd64/conf: files.amd64 src/sys/arch/i386/conf: files.i386 src/sys/arch/x86/conf: files.x86 src/sys/arch/xen/conf: files.xen Added Files: src/sys/arch/x86/x86: db_memrw.c Removed Files: src/sys/arch/amd64/amd64: db_memrw.c src/sys/arch/i386/i386: db_memrw.c Log Message: Merge i386 and amd64 version of db_memrw.c. Use this opportunity to skip calculating the VA of the page. Let the CPU deal with the invalidation itself through invlpg + destination address to avoid converting between canonical/non canonical forms. To generate a diff of this commit: cvs rdiff -u -r1.11 -r0 src/sys/arch/amd64/amd64/db_memrw.c cvs rdiff -u -r1.74 -r1.75 src/sys/arch/amd64/conf/files.amd64 cvs rdiff -u -r1.362 -r1.363 src/sys/arch/i386/conf/files.i386 cvs rdiff -u -r1.30 -r0 src/sys/arch/i386/i386/db_memrw.c cvs rdiff -u -r1.77 -r1.78 src/sys/arch/x86/conf/files.x86 cvs rdiff -u -r0 -r1.1 src/sys/arch/x86/x86/db_memrw.c cvs rdiff -u -r1.125 -r1.126 src/sys/arch/xen/conf/files.xen 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/amd64/conf/files.amd64 diff -u src/sys/arch/amd64/conf/files.amd64:1.74 src/sys/arch/amd64/conf/files.amd64:1.75 --- src/sys/arch/amd64/conf/files.amd64:1.74 Sun Nov 6 19:45:04 2011 +++ src/sys/arch/amd64/conf/files.amd64 Mon May 7 17:45:28 2012 @@ -1,4 +1,4 @@ -# $NetBSD: files.amd64,v 1.74 2011/11/06 19:45:04 christos Exp $ +# $NetBSD: files.amd64,v 1.75 2012/05/07 17:45:28 jym Exp $ # # new style config file for amd64 architecture # @@ -36,7 +36,6 @@ file arch/amd64/amd64/cpufunc.S file arch/amd64/amd64/db_disasm.c ddb file arch/amd64/amd64/db_interface.c ddb file arch/amd64/amd64/db_machdep.c ddb -file arch/amd64/amd64/db_memrw.c ddb | kgdb file arch/amd64/amd64/kobj_machdep.c modular file arch/amd64/amd64/kgdb_machdep.c kgdb file kern/subr_disk_mbr.c disk Index: src/sys/arch/i386/conf/files.i386 diff -u src/sys/arch/i386/conf/files.i386:1.362 src/sys/arch/i386/conf/files.i386:1.363 --- src/sys/arch/i386/conf/files.i386:1.362 Fri Nov 18 22:18:07 2011 +++ src/sys/arch/i386/conf/files.i386 Mon May 7 17:45:28 2012 @@ -1,4 +1,4 @@ -# $NetBSD: files.i386,v 1.362 2011/11/18 22:18:07 jmcneill Exp $ +# $NetBSD: files.i386,v 1.363 2012/05/07 17:45:28 jym Exp $ # # new style config file for i386 architecture # @@ -68,7 +68,6 @@ file arch/i386/i386/db_dbgreg.S ddb | ks file arch/i386/i386/db_disasm.c ddb file arch/i386/i386/db_interface.c ddb file arch/i386/i386/db_machdep.c ddb -file arch/i386/i386/db_memrw.c ddb | kgdb file arch/i386/i386/dumpsys.c file kern/subr_disk_mbr.c disk file kern/subr_spldebug.c spldebug Index: src/sys/arch/x86/conf/files.x86 diff -u src/sys/arch/x86/conf/files.x86:1.77 src/sys/arch/x86/conf/files.x86:1.78 --- src/sys/arch/x86/conf/files.x86:1.77 Fri Jan 13 21:46:00 2012 +++ src/sys/arch/x86/conf/files.x86 Mon May 7 17:45:29 2012 @@ -1,4 +1,4 @@ -# $NetBSD: files.x86,v 1.77 2012/01/13 21:46:00 martin Exp $ +# $NetBSD: files.x86,v 1.78 2012/05/07 17:45:29 jym Exp $ # options for MP configuration through the MP spec defflag opt_mpbios.h MPBIOS MPVERBOSE MPDEBUG MPBIOS_SCANPCI @@ -71,6 +71,7 @@ file arch/x86/x86/bus_space.c file arch/x86/x86/consinit.c file arch/x86/x86/core_machdep.c coredump file arch/x86/x86/cpu_topology.c +file arch/x86/x86/db_memrw.c ddb | kgdb file arch/x86/x86/db_trace.c ddb file arch/x86/x86/errata.c file arch/x86/x86/genfb_machdep.c Index: src/sys/arch/xen/conf/files.xen diff -u src/sys/arch/xen/conf/files.xen:1.125 src/sys/arch/xen/conf/files.xen:1.126 --- src/sys/arch/xen/conf/files.xen:1.125 Sat Jan 14 04:22:56 2012 +++ src/sys/arch/xen/conf/files.xen Mon May 7 17:45:29 2012 @@ -1,4 +1,4 @@ -# $NetBSD: files.xen,v 1.125 2012/01/14 04:22:56 pgoyette Exp $ +# $NetBSD: files.xen,v 1.126 2012/05/07 17:45:29 jym Exp $ # NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp # NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp @@ -43,7 +43,6 @@ file arch/i386/i386/db_dbgreg.S ddb | ks file arch/i386/i386/db_disasm.c ddb file arch/i386/i386/db_interface.c ddb file arch/i386/i386/db_machdep.c ddb -file arch/i386/i386/db_memrw.c ddb | kgdb file arch/i386/i386/dumpsys.c file arch/i386/i386/gdt.c file arch/i386/i386/ipkdb_glue.c ipkdb @@ -72,7 +71,6 @@ file arch/amd64/amd64/cpu_in_cksum.S (i file arch/amd64/amd64/db_disasm.c ddb file arch/amd64/amd64/db_interface.c ddb file arch/amd64/amd64/db_machdep.c ddb -file arch/amd64/amd64/db_memrw.c ddb | kgdb file arch/amd64/amd64/kgdb_machdep.c kgdb file arch/amd64/amd64/kobj_machdep.c modular file arch/amd64/amd64/gdt.c @@ -84,6 +82,7 @@ file arch/amd64/amd64/lock_stubs.S endif file kern/subr_disk_mbr.c disk +file arch/x86/x86/db_memrw.c ddb | kgdb file arch/x86/x86/db_trace.c ddb file arch/xen/x86/hypervisor_machdep.c # file arch/x86/x86/mtrr_i686.c mtrr Added files: Index: src/sys/arch/x86/x86/db_memrw.c diff -u /dev/null src/sys/arch/x86/x86/db_memrw.c:1.1 --- /dev/null Mon May 7 17:45:29 2012 +++ src/sys/arch/x86/x86/db_memrw.c Mon May 7 17:45:29 2012 @@ -0,0 +1,207 @@ +/* $NetBSD: db_memrw.c,v 1.1 2012/05/07 17:45:29 jym Exp $ */ + +/*- + * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Gordon W. Ross and Jason R. Thorpe. + * + * 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. + */ + +/* + * Interface to the debugger for virtual memory read/write. + * This file is shared by DDB and KGDB, and must work even + * when only KGDB is included (thus no db_printf calls). + * + * To write in the text segment, we have to first make + * the page writable, do the write, then restore the PTE. + * For writes outside the text segment, and all reads, + * just do the access -- if it causes a fault, the debugger + * will recover with a longjmp to an appropriate place. + * + * ALERT! If you want to access device registers with a + * specific size, then the read/write functions have to + * make sure to do the correct sized pointer access. + * + * Modified for i386 from hp300 version by + * Jason R. Thorpe <thor...@zembu.com>. + * + * Basic copy to amd64 by fvdl. + * + * i386 and amd64 merge by jym. + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.1 2012/05/07 17:45:29 jym Exp $"); + +#include <sys/param.h> +#include <sys/proc.h> +#include <sys/systm.h> + +#include <machine/db_machdep.h> + +#include <ddb/db_access.h> + +/* + * Read bytes from kernel address space for debugger. + */ +void +db_read_bytes(vaddr_t addr, size_t size, char *data) +{ + char *src; + + src = (char *)addr; + + if (size == 8) { + *((long *)data) = *((long *)src); + return; + } + + if (size == 4) { + *((int *)data) = *((int *)src); + return; + } + + if (size == 2) { + *((short *)data) = *((short *)src); + return; + } + + while (size-- > 0) + *data++ = *src++; +} + +/* + * Write bytes somewhere in the kernel text. Make the text + * pages writable temporarily. + */ +static void +db_write_text(vaddr_t addr, size_t size, const char *data) +{ + pt_entry_t *ppte, pte; + size_t limit; + char *dst; + + if (size == 0) + return; + + dst = (char *)addr; + + do { + addr = (vaddr_t)dst; + /* + * Get the PTE for the page. + */ + ppte = kvtopte(addr); + pte = *ppte; + + if ((pte & PG_V) == 0) { + printf(" address %p not a valid page\n", dst); + return; + } + + /* + * Compute number of bytes that can be written + * with this mapping and subtract it from the + * total size. + */ + if (pte & PG_PS) + limit = NBPD_L2 - (addr & (NBPD_L2 - 1)); + else + limit = PAGE_SIZE - (addr & PGOFSET); + if (limit > size) + limit = size; + size -= limit; + + /* + * Make the kernel text page writable. + */ + pmap_pte_clearbits(ppte, PG_KR); + pmap_pte_setbits(ppte, PG_KW); + pmap_update_pg(addr); + + /* + * MULTIPROCESSOR: no shootdown required as the PTE continues to + * map the same page and other CPUs do not need write access. + */ + + /* + * Page is now writable. Do as much access as we + * can in this page. + */ + for (; limit > 0; limit--) + *dst++ = *data++; + + /* + * Turn the page back to read-only. + */ + pmap_pte_clearbits(ppte, PG_KW); + pmap_pte_setbits(ppte, PG_KR); + pmap_update_pg(addr); + + /* + * MULTIPROCESSOR: no shootdown required as all other CPUs + * should be in CPUF_PAUSE state and will not cache the PTE + * with the write access set. + */ + } while (size != 0); +} + +/* + * Write bytes to kernel address space for debugger. + */ +void +db_write_bytes(vaddr_t addr, size_t size, const char *data) +{ + extern int __data_start; + char *dst; + + dst = (char *)addr; + + /* If any part is in kernel text, use db_write_text() */ + if (addr >= KERNBASE && addr < (vaddr_t)&__data_start) { + db_write_text(addr, size, data); + return; + } + + dst = (char *)addr; + + if (size == 8) { + *((long *)dst) = *((const long *)data); + return; + } + + if (size == 4) { + *((int *)dst) = *((const int *)data); + return; + } + + if (size == 2) { + *((short *)dst) = *((const short *)data); + return; + } + + while (size-- > 0) + *dst++ = *data++; +}