No empty .Rs/.Re
[netbsd-mini2440.git] / sys / ddb / db_access.c
blob63d3650f7c7a042a0f86bffa7f3ed8c45d3c2718
1 /* $NetBSD: db_access.c,v 1.20 2009/09/27 18:24:23 bsh Exp $ */
3 /*
4 * Mach Operating System
5 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * All Rights Reserved.
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
28 * Author: David B. Golub, Carnegie Mellon University
29 * Date: 7/90
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: db_access.c,v 1.20 2009/09/27 18:24:23 bsh Exp $");
35 #if defined(_KERNEL_OPT)
36 #include "opt_kgdb.h"
37 #endif
39 #include <sys/param.h>
40 #include <sys/proc.h>
41 #include <sys/endian.h>
43 #include <ddb/ddb.h>
46 * Access unaligned data items on aligned (longword)
47 * boundaries.
49 * This file is shared by ddb, kgdb and crash(8).
52 #if defined(DDB) || !defined(DDB) && !defined(KGDB)
53 #define _COMPILE_THIS
54 #endif
56 #if defined(_COMPILE_THIS) || defined(KGDB) && defined(SOFTWARE_SSTEP)
58 const int db_extend[] = { /* table for sign-extending */
60 0xFFFFFF80,
61 0xFFFF8000,
62 0xFF800000
65 db_expr_t
66 db_get_value(db_addr_t addr, size_t size, bool is_signed)
68 char data[sizeof(db_expr_t)];
69 db_expr_t value;
70 size_t i;
72 db_read_bytes(addr, size, data);
74 value = 0;
75 #if BYTE_ORDER == LITTLE_ENDIAN
76 for (i = size; i-- > 0;)
77 #else /* BYTE_ORDER == BIG_ENDIAN */
78 for (i = 0; i < size; i++)
79 #endif /* BYTE_ORDER */
80 value = (value << 8) + (data[i] & 0xFF);
82 if (size < 4 && is_signed && (value & db_extend[size]) != 0)
83 value |= db_extend[size];
84 return (value);
87 void
88 db_put_value(db_addr_t addr, size_t size, db_expr_t value)
90 char data[sizeof(db_expr_t)];
91 size_t i;
93 #if BYTE_ORDER == LITTLE_ENDIAN
94 for (i = 0; i < size; i++)
95 #else /* BYTE_ORDER == BIG_ENDIAN */
96 for (i = size; i-- > 0;)
97 #endif /* BYTE_ORDER */
99 data[i] = value & 0xFF;
100 value >>= 8;
103 db_write_bytes(addr, size, data);
106 #endif /* _COMPILE_THIS || KGDB && SOFTWARE_SSTEP */
108 #ifdef _COMPILE_THIS
110 void *
111 db_read_ptr(const char *name)
113 db_expr_t val;
114 void *p;
116 if (!db_value_of_name(name, &val)) {
117 db_printf("db_read_ptr: cannot find `%s'\n", name);
118 db_error(NULL);
119 /* NOTREACHED */
121 db_read_bytes((db_addr_t)val, sizeof(p), (char *)&p);
122 return p;
126 db_read_int(const char *name)
128 db_expr_t val;
129 int p;
131 if (!db_value_of_name(name, &val)) {
132 db_printf("db_read_int: cannot find `%s'\n", name);
133 db_error(NULL);
134 /* NOTREACHED */
136 db_read_bytes((db_addr_t)val, sizeof(p), (char *)&p);
137 return p;
140 #endif /* _COMPILE_THIS */