OSDN Git Service

2004-07-09 Michael Snyder <msnyder@redhat.com>
[pf3gnuchains/pf3gnuchains4x.git] / rda / include / gdbserv-utils.h
1 /* gdbserv-utils.h
2
3    Copyright 1998, 2000, 2002 Red Hat, Inc.
4
5    This file is part of RDA, the Red Hat Debug Agent (and library).
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330,
20    Boston, MA 02111-1307, USA.
21    
22    Alternative licenses for RDA may be arranged by contacting Red Hat,
23    Inc.  */
24
25 #ifdef __cplusplus
26 extern "C" {
27 #elif 0
28 }
29 #endif
30
31 struct gdbserv;
32 struct gdbserv_reg;
33
34 /* Return the ASCII equivalent of C (C>=0 && C<=15). The result will be 
35    lower-case. */
36
37 extern unsigned char gdbserv_to_hex (int c);
38 extern int gdbserv_hex_to (unsigned char c);
39
40 extern unsigned int gdbserv_ulong_to_hex (char *ptr, unsigned long val, int num_bits);
41
42
43 extern unsigned int gdbserv_raw_to_hex (char **ptr, char *mem, int nr_bytes);
44
45 /* Convert between a REG and the native unsigned long/long-long. */
46
47 extern void gdbserv_reg_to_ulong (struct gdbserv *gdbserv,
48                                   const struct gdbserv_reg *reg,
49                                   unsigned long *val);
50
51 extern void gdbserv_reg_to_ulonglong (struct gdbserv *gdbserv,
52                                       const struct gdbserv_reg *reg,
53                                       unsigned long long *val);
54
55 extern void gdbserv_ulong_to_reg (struct gdbserv *gdbserv,
56                                   unsigned long val,
57                                   struct gdbserv_reg *reg);
58
59 extern void gdbserv_ulonglong_to_reg (struct gdbserv *gdbserv,
60                                       unsigned long long val,
61                                       struct gdbserv_reg *reg);
62
63 /* Convert between a REG and a buffer representing a (possibly signed)
64    numeric type.  Handle big endian and little endian cases explicitly.
65    When the source buffer is bigger than the destination buffer, the
66    least significant bytes (as appropriate for the endianess) are
67    transferred.  When the source buffer is smaller than the destination,
68    the most significant bytes of the destination are padded appropriately.
69    
70    Note that gdbserv_be_bytes_from_reg() and gdbserv_le_bytes_from_reg()
71    have a buffer length parameter, but not a register length
72    parameter.  This is because the register length was obtained from a
73    register packet sent by the debug client.  On the other hand,
74    gdbserv_be_bytes_to_reg() and gdbserv_le_bytes_to_reg() take both a
75    buffer length and the register length.  This is because we're
76    constructing a register (which will likely be sent to the client)
77    of a particular size.  */
78
79 extern void gdbserv_be_bytes_to_reg (struct gdbserv *gdbserv,
80                                      const void *buf,
81                                      int buflen,
82                                      struct gdbserv_reg *reg,
83                                      int reglen,
84                                      int sign_extend);
85
86 extern void gdbserv_le_bytes_to_reg (struct gdbserv *gdbserv,
87                                      const void *buf,
88                                      int len,
89                                      struct gdbserv_reg *reg,
90                                      int reglen,
91                                      int sign_extend);
92
93 extern void gdbserv_be_bytes_from_reg (struct gdbserv *gdbserv,
94                                        void *buf,
95                                        int buflen,
96                                        const struct gdbserv_reg *reg,
97                                        int sign_extend);
98
99 extern void gdbserv_le_bytes_from_reg (struct gdbserv *gdbserv,
100                                        void *buf,
101                                        int buflen,
102                                        const struct gdbserv_reg *reg,
103                                        int sign_extend);
104
105 /* Convert between a REG and a buffer representing a native unsigned
106    numeric type.  These are just wrappers for the routines above, but
107    are useful nonetheless since they free the caller from having to
108    worry about byte order issues.  */
109
110 extern void gdbserv_host_bytes_to_reg (struct gdbserv *gdbserv,
111                                        const void *buf,
112                                        int buflen,
113                                        struct gdbserv_reg *reg,
114                                        int reglen,
115                                        int sign_extend);
116
117 extern void gdbserv_host_bytes_from_reg (struct gdbserv *gdbserv,
118                                          void *buf,
119                                          int buflen,
120                                          const struct gdbserv_reg *reg,
121                                          int sign_extend);
122
123 #ifdef __cplusplus
124 }
125 #endif