File: [local] / sys / arch / amd64 / amd64 / db_memrw.c (download)
Revision 1.1.1.1 (vendor branch), Tue Mar 4 16:04:58 2008 UTC (16 years, 6 months ago) by nbrk
Branch: OPENBSD_4_2_BASE, MAIN
CVS Tags: jornada-partial-support-wip, HEAD Changes since 1.1: +0 -0 lines
Import of OpenBSD 4.2 release kernel tree with initial code to support
Jornada 720/728, StrongARM 1110-based handheld PC.
At this point kernel roots on NFS and boots into vfs_mountroot() and traps.
What is supported:
- glass console, Jornada framebuffer (jfb) works in 16bpp direct color mode
(needs some palette tweaks for non black/white/blue colors, i think)
- saic, SA11x0 interrupt controller (needs cleanup)
- sacom, SA11x0 UART (supported only as boot console for now)
- SA11x0 GPIO controller fully supported (but can't handle multiple interrupt
handlers on one gpio pin)
- sassp, SSP port on SA11x0 that attaches spibus
- Jornada microcontroller (jmcu) to control kbd, battery, etc throught
the SPI bus (wskbd attaches on jmcu, but not tested)
- tod functions seem work
- initial code for SA-1111 (chip companion) : this is TODO
Next important steps, i think:
- gpio and intc on sa1111
- pcmcia support for sa11x0 (and sa1111 help logic)
- REAL root on nfs when we have PCMCIA support (we may use any of supported pccard NICs)
- root on wd0! (using already supported PCMCIA-ATA)
|
/* $OpenBSD: db_memrw.c,v 1.3 2005/10/21 18:55:00 martin Exp $ */
/* $NetBSD: db_memrw.c,v 1.1 2003/04/26 18:39:27 fvdl 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 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 <thorpej@zembu.com>.
*
* Basic copy to amd64 by fvdl.
*/
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/systm.h>
#include <uvm/uvm_extern.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, char *data)
{
pt_entry_t *pte, oldpte, tmppte;
vaddr_t pgva;
size_t limit;
char *dst;
if (size == 0)
return;
dst = (char *)addr;
do {
/*
* Get the PTE for the page.
*/
pte = kvtopte(addr);
oldpte = *pte;
if ((oldpte & PG_V) == 0) {
printf(" address %p not a valid page\n", dst);
return;
}
/*
* Get the VA for the page.
*/
if (oldpte & PG_PS)
pgva = (vaddr_t)dst & PG_LGFRAME;
else
pgva = trunc_page((vaddr_t)dst);
/*
* Compute number of bytes that can be written
* with this mapping and subtract it from the
* total size.
*/
if (oldpte & PG_PS)
limit = NBPD_L2 - ((vaddr_t)dst & (NBPD_L2 - 1));
else
limit = PAGE_SIZE - ((vaddr_t)dst & PGOFSET);
if (limit > size)
limit = size;
size -= limit;
tmppte = (oldpte & ~PG_KR) | PG_KW;
*pte = tmppte;
pmap_update_pg(pgva);
/*
* Page is now writable. Do as much access as we
* can in this page.
*/
for (; limit > 0; limit--)
*dst++ = *data++;
/*
* Restore the old PTE.
*/
*pte = oldpte;
pmap_update_pg(pgva);
} while (size != 0);
}
/*
* Write bytes to kernel address space for debugger.
*/
void
db_write_bytes(vaddr_t addr, size_t size, char *data)
{
extern char etext;
char *dst;
dst = (char *)addr;
/* If any part is in kernel text, use db_write_text() */
if (addr >= KERNBASE && addr < (vaddr_t)&etext) {
db_write_text(addr, size, data);
return;
}
dst = (char *)addr;
if (size == 8) {
*((long *)dst) = *((long *)data);
return;
}
if (size == 4) {
*((int *)dst) = *((int *)data);
return;
}
if (size == 2) {
*((short *)dst) = *((short *)data);
return;
}
while (size-- > 0)
*dst++ = *data++;
}