Home | History | Annotate | Line # | Download | only in sun3
db_memrw.c revision 1.3
      1  1.3  gwr /*	$NetBSD: db_memrw.c,v 1.3 1994/11/28 19:17:07 gwr Exp $	*/
      2  1.1  gwr 
      3  1.1  gwr /*
      4  1.1  gwr  * Copyright (c) 1994 Gordon W. Ross
      5  1.1  gwr  * All rights reserved.
      6  1.1  gwr  *
      7  1.1  gwr  * Redistribution and use in source and binary forms, with or without
      8  1.1  gwr  * modification, are permitted provided that the following conditions
      9  1.1  gwr  * are met:
     10  1.1  gwr  * 1. Redistributions of source code must retain the above copyright
     11  1.1  gwr  *    notice, this list of conditions and the following disclaimer.
     12  1.1  gwr  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  gwr  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  gwr  *    documentation and/or other materials provided with the distribution.
     15  1.1  gwr  * 3. The name of the author may not be used to endorse or promote products
     16  1.1  gwr  *    derived from this software without specific prior written permission.
     17  1.1  gwr  *
     18  1.1  gwr  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1  gwr  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1  gwr  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1  gwr  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1  gwr  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.1  gwr  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.1  gwr  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.1  gwr  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.1  gwr  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  1.1  gwr  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.1  gwr  */
     29  1.1  gwr 
     30  1.1  gwr /*
     31  1.1  gwr  * Interface to the debugger for writing in the kernel.
     32  1.1  gwr  * To write in the text segment, we have to first make
     33  1.1  gwr  * the page writable, do the write, then restore the PTE.
     34  1.2  gwr  *
     35  1.2  gwr  * XXX - Should do db_read_bytes() here too so it can
     36  1.2  gwr  * make sure the address is valid (mapped) first...
     37  1.1  gwr  */
     38  1.1  gwr 
     39  1.1  gwr #include <sys/param.h>
     40  1.1  gwr #include <sys/proc.h>
     41  1.1  gwr 
     42  1.1  gwr #include <vm/vm.h>
     43  1.1  gwr 
     44  1.1  gwr #include <machine/db_machdep.h>
     45  1.1  gwr #include <machine/pte.h>
     46  1.1  gwr 
     47  1.1  gwr /*
     48  1.3  gwr  * Read one byte somewhere in the kernel.
     49  1.3  gwr  * It does not matter if this is slow. -gwr
     50  1.3  gwr  */
     51  1.3  gwr static char
     52  1.3  gwr db_read_data(src)
     53  1.3  gwr 	char *src;
     54  1.3  gwr {
     55  1.3  gwr 	int		oldpte;
     56  1.3  gwr 	vm_offset_t pgva;
     57  1.3  gwr 	int ch;
     58  1.3  gwr 
     59  1.3  gwr 	pgva = sun3_trunc_page((long)src);
     60  1.3  gwr 	oldpte = get_pte(pgva);
     61  1.3  gwr 
     62  1.3  gwr 	if ((oldpte & PG_VALID) == 0) {
     63  1.3  gwr 		db_printf(" address 0x%x not a valid page\n", src);
     64  1.3  gwr 		return 0;
     65  1.3  gwr 	}
     66  1.3  gwr 	return (*src);
     67  1.3  gwr }
     68  1.3  gwr 
     69  1.3  gwr /*
     70  1.3  gwr  * Read bytes from kernel address space for debugger.
     71  1.3  gwr  * It does not matter if this is slow. -gwr
     72  1.3  gwr  */
     73  1.3  gwr void
     74  1.3  gwr db_read_bytes(addr, size, data)
     75  1.3  gwr 	vm_offset_t	addr;
     76  1.3  gwr 	register int	size;
     77  1.3  gwr 	register char	*data;
     78  1.3  gwr {
     79  1.3  gwr 	char	*src, *limit;
     80  1.3  gwr 
     81  1.3  gwr 	src = (char *)addr;
     82  1.3  gwr 	limit = src + size;
     83  1.3  gwr 
     84  1.3  gwr 	while (src < limit) {
     85  1.3  gwr 		*data = db_read_data(src);
     86  1.3  gwr 		data++;
     87  1.3  gwr 		src++;
     88  1.3  gwr 	}
     89  1.3  gwr }
     90  1.3  gwr 
     91  1.3  gwr /*
     92  1.1  gwr  * Write one byte somewhere in kernel text.
     93  1.1  gwr  * It does not matter if this is slow. -gwr
     94  1.1  gwr  */
     95  1.1  gwr static void
     96  1.1  gwr db_write_text(dst, ch)
     97  1.1  gwr 	char *dst;
     98  1.1  gwr 	int ch;
     99  1.1  gwr {
    100  1.1  gwr 	int		oldpte, tmppte;
    101  1.1  gwr 	vm_offset_t pgva;
    102  1.1  gwr 
    103  1.1  gwr 	pgva = sun3_trunc_page((long)dst);
    104  1.1  gwr 	oldpte = get_pte(pgva);
    105  1.1  gwr 
    106  1.1  gwr 	if ((oldpte & PG_VALID) == 0) {
    107  1.1  gwr 		db_printf(" address 0x%x not a valid page\n", dst);
    108  1.1  gwr 		return;
    109  1.1  gwr 	}
    110  1.1  gwr 
    111  1.1  gwr 	tmppte = oldpte | PG_WRITE;
    112  1.1  gwr 	set_pte(pgva, tmppte);
    113  1.1  gwr 
    114  1.1  gwr 	*dst = (char) ch;
    115  1.1  gwr 
    116  1.1  gwr 	set_pte(pgva, oldpte);
    117  1.1  gwr }
    118  1.1  gwr 
    119  1.1  gwr /*
    120  1.3  gwr  * Write one byte somewhere outside kernel text.
    121  1.3  gwr  * It does not matter if this is slow. -gwr
    122  1.3  gwr  */
    123  1.3  gwr static void
    124  1.3  gwr db_write_data(dst, ch)
    125  1.3  gwr 	char *dst;
    126  1.3  gwr 	int ch;
    127  1.3  gwr {
    128  1.3  gwr 	int		oldpte;
    129  1.3  gwr 	vm_offset_t pgva;
    130  1.3  gwr 
    131  1.3  gwr 	pgva = sun3_trunc_page((long)dst);
    132  1.3  gwr 	oldpte = get_pte(pgva);
    133  1.3  gwr 
    134  1.3  gwr 	if ((oldpte & (PG_VALID | PG_WRITE)) == 0) {
    135  1.3  gwr 		db_printf(" address 0x%x not a valid page\n", dst);
    136  1.3  gwr 		return;
    137  1.3  gwr 	}
    138  1.3  gwr 	*dst = (char) ch;
    139  1.3  gwr }
    140  1.3  gwr 
    141  1.3  gwr /*
    142  1.1  gwr  * Write bytes to kernel address space for debugger.
    143  1.1  gwr  */
    144  1.1  gwr void
    145  1.1  gwr db_write_bytes(addr, size, data)
    146  1.1  gwr 	vm_offset_t	addr;
    147  1.1  gwr 	int	size;
    148  1.1  gwr 	char	*data;
    149  1.1  gwr {
    150  1.3  gwr 	extern char	start[], etext[] ;
    151  1.1  gwr 	char	*dst, *limit;
    152  1.1  gwr 
    153  1.1  gwr 	dst = (char *)addr;
    154  1.1  gwr 	limit = dst + size;
    155  1.1  gwr 
    156  1.1  gwr 	while (dst < limit) {
    157  1.1  gwr 		if ((dst >= start) && (dst < etext))
    158  1.1  gwr 			db_write_text(dst, *data);
    159  1.1  gwr 		else
    160  1.3  gwr 			db_write_data(dst, *data);
    161  1.1  gwr 		dst++;
    162  1.1  gwr 		data++;
    163  1.1  gwr 	}
    164  1.1  gwr }
    165