xref: /netbsd-src/sys/arch/hppa/hppa/db_memrw.c (revision 32381fa0ddffc642f11f43fe9ecc402f5ec8408d)
1 /*	$NetBSD: db_memrw.c,v 1.7 2009/11/03 05:07:26 snj Exp $	*/
2 
3 /*	$OpenBSD: db_interface.c,v 1.16 2001/03/22 23:31:45 mickey Exp $	*/
4 
5 /*
6  * Copyright (c) 1999-2003 Michael Shalayeff
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.7 2009/11/03 05:07:26 snj Exp $");
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 
37 #include <machine/db_machdep.h>
38 #include <machine/frame.h>
39 #include <machine/cpufunc.h>
40 
41 #include <hppa/hppa/machdep.h>
42 
43 #include <ddb/db_access.h>
44 
45 void
db_read_bytes(vaddr_t addr,size_t size,char * data)46 db_read_bytes(vaddr_t addr, size_t size, char *data)
47 {
48 	char *src = (char *)addr;
49 
50 	while (size--)
51 		*data++ = *src++;
52 }
53 
54 void
db_write_bytes(vaddr_t addr,size_t size,const char * data)55 db_write_bytes(vaddr_t addr, size_t size, const char *data)
56 {
57 	char *dst = (char *)addr;
58 	extern int etext;
59 
60 	/*
61 	 * Since (most of) the text segment is mapped unwritable,
62 	 * (but directly), we need to use a special function when
63 	 * dst is less than etext.
64 	 */
65 	while (size--) {
66 		if (dst < (char *) &etext) {
67 			hppa_ktext_stb((vaddr_t)dst, *data);
68 			dst++;
69 			data++;
70 		} else
71 			*dst++ = *data++;
72 	}
73 
74 	fcacheall();
75 	__asm volatile(
76 			"	nop	\n"
77 			"	nop	\n"
78 			"	nop	\n"
79 			"	nop	\n"
80 			"	nop	\n"
81 			"	nop	\n"
82 			"	nop	\n");
83 }
84