Home | History | Annotate | Line # | Download | only in sun3
db_memrw.c revision 1.7
      1  1.7  gwr /*	$NetBSD: db_memrw.c,v 1.7 1995/02/07 04:37:48 gwr Exp $	*/
      2  1.1  gwr 
      3  1.1  gwr /*
      4  1.7  gwr  * Copyright (c) 1994, 1995 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.7  gwr  * 4. All advertising materials mentioning features or use of this software
     18  1.7  gwr  *    must display the following acknowledgement:
     19  1.7  gwr  *      This product includes software developed by Gordon Ross
     20  1.1  gwr  *
     21  1.1  gwr  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.1  gwr  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.1  gwr  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.1  gwr  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.1  gwr  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.1  gwr  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.1  gwr  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1  gwr  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.1  gwr  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.1  gwr  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1  gwr  */
     32  1.1  gwr 
     33  1.1  gwr /*
     34  1.7  gwr  * Machine-dependent functions used by ddb
     35  1.1  gwr  */
     36  1.1  gwr 
     37  1.1  gwr #include <sys/param.h>
     38  1.1  gwr #include <sys/proc.h>
     39  1.1  gwr 
     40  1.1  gwr #include <vm/vm.h>
     41  1.1  gwr 
     42  1.1  gwr #include <machine/db_machdep.h>
     43  1.7  gwr #include <ddb/db_command.h>
     44  1.7  gwr 
     45  1.1  gwr #include <machine/pte.h>
     46  1.1  gwr 
     47  1.1  gwr /*
     48  1.7  gwr  * Interface to the debugger for virtual memory read/write.
     49  1.7  gwr  *
     50  1.7  gwr  * To write in the text segment, we have to first make
     51  1.7  gwr  * the page writable, do the write, then restore the PTE.
     52  1.7  gwr  * For writes outside the text segment, and all reads,
     53  1.7  gwr  * just do the access -- if it causes a fault, the debugger
     54  1.7  gwr  * will recover with a longjmp to an appropriate place.
     55  1.7  gwr  */
     56  1.7  gwr 
     57  1.7  gwr /*
     58  1.3  gwr  * Read bytes from kernel address space for debugger.
     59  1.5  gwr  * This used to check for valid PTEs, but now that
     60  1.5  gwr  * traps in DDB work correctly, "Just Do It!"
     61  1.3  gwr  */
     62  1.3  gwr void
     63  1.3  gwr db_read_bytes(addr, size, data)
     64  1.3  gwr 	vm_offset_t	addr;
     65  1.3  gwr 	register int	size;
     66  1.3  gwr 	register char	*data;
     67  1.3  gwr {
     68  1.5  gwr 	register char	*src;
     69  1.3  gwr 
     70  1.3  gwr 	src = (char *)addr;
     71  1.5  gwr 	while (--size >= 0)
     72  1.5  gwr 		*data++ = *src++;
     73  1.3  gwr }
     74  1.3  gwr 
     75  1.3  gwr /*
     76  1.1  gwr  * Write one byte somewhere in kernel text.
     77  1.1  gwr  * It does not matter if this is slow. -gwr
     78  1.1  gwr  */
     79  1.1  gwr static void
     80  1.1  gwr db_write_text(dst, ch)
     81  1.1  gwr 	char *dst;
     82  1.1  gwr 	int ch;
     83  1.1  gwr {
     84  1.1  gwr 	int		oldpte, tmppte;
     85  1.1  gwr 	vm_offset_t pgva;
     86  1.1  gwr 
     87  1.1  gwr 	pgva = sun3_trunc_page((long)dst);
     88  1.1  gwr 	oldpte = get_pte(pgva);
     89  1.1  gwr 
     90  1.1  gwr 	if ((oldpte & PG_VALID) == 0) {
     91  1.1  gwr 		db_printf(" address 0x%x not a valid page\n", dst);
     92  1.1  gwr 		return;
     93  1.1  gwr 	}
     94  1.1  gwr 
     95  1.1  gwr 	tmppte = oldpte | PG_WRITE;
     96  1.1  gwr 	set_pte(pgva, tmppte);
     97  1.1  gwr 
     98  1.1  gwr 	*dst = (char) ch;
     99  1.1  gwr 
    100  1.1  gwr 	set_pte(pgva, oldpte);
    101  1.1  gwr }
    102  1.1  gwr 
    103  1.1  gwr /*
    104  1.1  gwr  * Write bytes to kernel address space for debugger.
    105  1.1  gwr  */
    106  1.1  gwr void
    107  1.1  gwr db_write_bytes(addr, size, data)
    108  1.1  gwr 	vm_offset_t	addr;
    109  1.1  gwr 	int	size;
    110  1.1  gwr 	char	*data;
    111  1.1  gwr {
    112  1.3  gwr 	extern char	start[], etext[] ;
    113  1.5  gwr 	char	*dst;
    114  1.1  gwr 
    115  1.1  gwr 	dst = (char *)addr;
    116  1.5  gwr 	while (--size >= 0) {
    117  1.1  gwr 		if ((dst >= start) && (dst < etext))
    118  1.1  gwr 			db_write_text(dst, *data);
    119  1.1  gwr 		else
    120  1.5  gwr 			*dst = *data;
    121  1.5  gwr 		dst++; data++;
    122  1.1  gwr 	}
    123  1.7  gwr }
    124  1.7  gwr 
    125  1.7  gwr 
    126  1.7  gwr /*
    127  1.7  gwr  * Machine-specific ddb commands for the sun3:
    128  1.7  gwr  *    abort:	Drop into monitor via abort (allows continue)
    129  1.7  gwr  *    halt: 	Exit to monitor as in halt(8)
    130  1.7  gwr  *    reboot:	Reboot the machine as in reboot(8)
    131  1.7  gwr  */
    132  1.7  gwr 
    133  1.7  gwr extern void sun3_mon_abort();
    134  1.7  gwr extern void sun3_mon_halt();
    135  1.7  gwr 
    136  1.7  gwr void
    137  1.7  gwr db_mon_reboot()
    138  1.7  gwr {
    139  1.7  gwr 	sun3_mon_reboot("");
    140  1.7  gwr }
    141  1.7  gwr 
    142  1.7  gwr struct db_command db_machine_cmds[] = {
    143  1.7  gwr 	{ "abort",	sun3_mon_abort,	0,	0 },
    144  1.7  gwr 	{ "halt",	sun3_mon_halt,	0,	0 },
    145  1.7  gwr 	{ "reboot",	db_mon_reboot,	0,	0 },
    146  1.7  gwr 	{ (char *)0, }
    147  1.7  gwr };
    148  1.7  gwr 
    149  1.7  gwr /*
    150  1.7  gwr  * This is called before ddb_init() to install the
    151  1.7  gwr  * machine-specific command table. (see machdep.c)
    152  1.7  gwr  */
    153  1.7  gwr void
    154  1.7  gwr db_machine_init()
    155  1.7  gwr {
    156  1.7  gwr 	db_machine_commands_install(db_machine_cmds);
    157  1.1  gwr }
    158