198944Sobrien/* Cache and manage the values of registers for GDB, the GNU debugger.
298944Sobrien
3130803Smarcel   Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
4130803Smarcel   2001, 2002 Free Software Foundation, Inc.
5130803Smarcel
698944Sobrien   This file is part of GDB.
798944Sobrien
898944Sobrien   This program is free software; you can redistribute it and/or modify
998944Sobrien   it under the terms of the GNU General Public License as published by
1098944Sobrien   the Free Software Foundation; either version 2 of the License, or
1198944Sobrien   (at your option) any later version.
1298944Sobrien
1398944Sobrien   This program is distributed in the hope that it will be useful,
1498944Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
1598944Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1698944Sobrien   GNU General Public License for more details.
1798944Sobrien
1898944Sobrien   You should have received a copy of the GNU General Public License
1998944Sobrien   along with this program; if not, write to the Free Software
2098944Sobrien   Foundation, Inc., 59 Temple Place - Suite 330,
2198944Sobrien   Boston, MA 02111-1307, USA.  */
2298944Sobrien
2398944Sobrien#ifndef REGCACHE_H
2498944Sobrien#define REGCACHE_H
2598944Sobrien
26130803Smarcelstruct regcache;
27130803Smarcelstruct gdbarch;
28130803Smarcel
29130803Smarcelextern struct regcache *current_regcache;
30130803Smarcel
31130803Smarcelvoid regcache_xfree (struct regcache *regcache);
32130803Smarcelstruct cleanup *make_cleanup_regcache_xfree (struct regcache *regcache);
33130803Smarcelstruct regcache *regcache_xmalloc (struct gdbarch *gdbarch);
34130803Smarcel
35130803Smarcel/* Return REGCACHE's architecture.  */
36130803Smarcel
37130803Smarcelextern struct gdbarch *get_regcache_arch (const struct regcache *regcache);
38130803Smarcel
3998944Sobrien/* Transfer a raw register [0..NUM_REGS) between core-gdb and the
4098944Sobrien   regcache. */
4198944Sobrien
42130803Smarcelvoid regcache_raw_read (struct regcache *regcache, int rawnum, void *buf);
43130803Smarcelvoid regcache_raw_write (struct regcache *regcache, int rawnum,
44130803Smarcel			 const void *buf);
45130803Smarcelextern void regcache_raw_read_signed (struct regcache *regcache,
46130803Smarcel				      int regnum, LONGEST *val);
47130803Smarcelextern void regcache_raw_read_unsigned (struct regcache *regcache,
48130803Smarcel					int regnum, ULONGEST *val);
49130803Smarcelextern void regcache_raw_write_signed (struct regcache *regcache,
50130803Smarcel				       int regnum, LONGEST val);
51130803Smarcelextern void regcache_raw_write_unsigned (struct regcache *regcache,
52130803Smarcel					 int regnum, ULONGEST val);
5398944Sobrien
54130803Smarcel/* Partial transfer of a raw registers.  These perform read, modify,
55130803Smarcel   write style operations.  */
56130803Smarcel
57130803Smarcelvoid regcache_raw_read_part (struct regcache *regcache, int regnum,
58130803Smarcel			     int offset, int len, void *buf);
59130803Smarcelvoid regcache_raw_write_part (struct regcache *regcache, int regnum,
60130803Smarcel			      int offset, int len, const void *buf);
61130803Smarcel
62130803Smarcelint regcache_valid_p (struct regcache *regcache, int regnum);
63130803Smarcel
64130803Smarcel/* Transfer a cooked register [0..NUM_REGS+NUM_PSEUDO_REGS).  */
65130803Smarcelvoid regcache_cooked_read (struct regcache *regcache, int rawnum, void *buf);
66130803Smarcelvoid regcache_cooked_write (struct regcache *regcache, int rawnum,
67130803Smarcel			    const void *buf);
68130803Smarcel
69130803Smarcel/* NOTE: cagney/2002-08-13: At present GDB has no reliable mechanism
70130803Smarcel   for indicating when a ``cooked'' register was constructed from
71130803Smarcel   invalid or unavailable ``raw'' registers.  One fairly easy way of
72130803Smarcel   adding such a mechanism would be for the cooked functions to return
73130803Smarcel   a register valid indication.  Given the possibility of such a
74130803Smarcel   change, the extract functions below use a reference parameter,
75130803Smarcel   rather than a function result.  */
76130803Smarcel
77130803Smarcel/* Read a register as a signed/unsigned quantity.  */
78130803Smarcelextern void regcache_cooked_read_signed (struct regcache *regcache,
79130803Smarcel					 int regnum, LONGEST *val);
80130803Smarcelextern void regcache_cooked_read_unsigned (struct regcache *regcache,
81130803Smarcel					   int regnum, ULONGEST *val);
82130803Smarcelextern void regcache_cooked_write_signed (struct regcache *regcache,
83130803Smarcel					  int regnum, LONGEST val);
84130803Smarcelextern void regcache_cooked_write_unsigned (struct regcache *regcache,
85130803Smarcel					    int regnum, ULONGEST val);
86130803Smarcel
87130803Smarcel/* Partial transfer of a cooked register.  These perform read, modify,
88130803Smarcel   write style operations.  */
89130803Smarcel
90130803Smarcelvoid regcache_cooked_read_part (struct regcache *regcache, int regnum,
91130803Smarcel				int offset, int len, void *buf);
92130803Smarcelvoid regcache_cooked_write_part (struct regcache *regcache, int regnum,
93130803Smarcel				 int offset, int len, const void *buf);
94130803Smarcel
9598944Sobrien/* Transfer a raw register [0..NUM_REGS) between the regcache and the
9698944Sobrien   target.  These functions are called by the target in response to a
9798944Sobrien   target_fetch_registers() or target_store_registers().  */
9898944Sobrien
99130803Smarcelextern void supply_register (int regnum, const void *val);
10098944Sobrienextern void regcache_collect (int regnum, void *buf);
101130803Smarcelextern void regcache_raw_supply (struct regcache *regcache,
102130803Smarcel				 int regnum, const void *buf);
103130803Smarcelextern void regcache_raw_collect (const struct regcache *regcache,
104130803Smarcel				  int regnum, void *buf);
10598944Sobrien
10698944Sobrien
107130803Smarcel/* The register's ``offset''.
10898944Sobrien
109130803Smarcel   FIXME: cagney/2002-11-07: The frame_register() function, when
110130803Smarcel   specifying the real location of a register, does so using that
111130803Smarcel   registers offset in the register cache.  That offset is then used
112130803Smarcel   by valops.c to determine the location of the register.  The code
113130803Smarcel   should instead use the register's number and a location expression
114130803Smarcel   to describe a value spread across multiple registers or memory.  */
11598944Sobrien
116130803Smarcelextern int register_offset_hack (struct gdbarch *gdbarch, int regnum);
11798944Sobrien
11898944Sobrien
119130803Smarcel/* The type of a register.  This function is slightly more efficient
120130803Smarcel   then its gdbarch vector counterpart since it returns a precomputed
121130803Smarcel   value stored in a table.
12298944Sobrien
123130803Smarcel   NOTE: cagney/2002-08-17: The original macro was called
124130803Smarcel   DEPRECATED_REGISTER_VIRTUAL_TYPE.  This was because the register
125130803Smarcel   could have different raw and cooked (nee virtual) representations.
126130803Smarcel   The CONVERTABLE methods being used to convert between the two
127130803Smarcel   representations.  Current code does not do this.  Instead, the
128130803Smarcel   first [0..NUM_REGS) registers are 1:1 raw:cooked, and the type
129130803Smarcel   exactly describes the register's representation.  Consequently, the
130130803Smarcel   ``virtual'' has been dropped.
13198944Sobrien
132130803Smarcel   FIXME: cagney/2002-08-17: A number of architectures, including the
133130803Smarcel   MIPS, are currently broken in this regard.  */
13498944Sobrien
135130803Smarcelextern struct type *register_type (struct gdbarch *gdbarch, int regnum);
13698944Sobrien
13798944Sobrien
138130803Smarcel/* Return the size of register REGNUM.  All registers should have only
139130803Smarcel   one size.
14098944Sobrien
141130803Smarcel   FIXME: cagney/2003-02-28:
14298944Sobrien
143130803Smarcel   Unfortunately, thanks to some legacy architectures, this doesn't
144130803Smarcel   hold.  A register's cooked (nee virtual) and raw size can differ
145130803Smarcel   (see MIPS).  Such architectures should be using different register
146130803Smarcel   numbers for the different sized views of identical registers.
14798944Sobrien
148130803Smarcel   Anyway, the up-shot is that, until that mess is fixed, core code
149130803Smarcel   can end up being very confused - should the RAW or VIRTUAL size be
150130803Smarcel   used?  As a rule of thumb, use DEPRECATED_REGISTER_VIRTUAL_SIZE in
151130803Smarcel   cooked code, but with the comment:
15298944Sobrien
153130803Smarcel   OK: REGISTER_VIRTUAL_SIZE
154130803Smarcel
155130803Smarcel   or just
156130803Smarcel
157130803Smarcel   OK
158130803Smarcel
159130803Smarcel   appended to the end of the line.  */
160130803Smarcel
161130803Smarcelextern int register_size (struct gdbarch *gdbarch, int regnum);
162130803Smarcel
163130803Smarcel
164130803Smarcel/* Save/restore a register cache.  The set of registers saved /
165130803Smarcel   restored into the DST regcache determined by the save_reggroup /
166130803Smarcel   restore_reggroup respectively.  COOKED_READ returns zero iff the
167130803Smarcel   register's value can't be returned.  */
168130803Smarcel
169130803Smarceltypedef int (regcache_cooked_read_ftype) (void *src, int regnum, void *buf);
170130803Smarcel
171130803Smarcelextern void regcache_save (struct regcache *dst,
172130803Smarcel			   regcache_cooked_read_ftype *cooked_read,
173130803Smarcel			   void *src);
174130803Smarcelextern void regcache_restore (struct regcache *dst,
175130803Smarcel			      regcache_cooked_read_ftype *cooked_read,
176130803Smarcel			      void *src);
177130803Smarcel
178130803Smarcel/* Copy/duplicate the contents of a register cache.  By default, the
179130803Smarcel   operation is pass-through.  Writes to DST and reads from SRC will
180130803Smarcel   go through to the target.
181130803Smarcel
182130803Smarcel   The ``cpy'' functions can not have overlapping SRC and DST buffers.
183130803Smarcel
184130803Smarcel   ``no passthrough'' versions do not go through to the target.  They
185130803Smarcel   only transfer values already in the cache.  */
186130803Smarcel
187130803Smarcelextern struct regcache *regcache_dup (struct regcache *regcache);
188130803Smarcelextern struct regcache *regcache_dup_no_passthrough (struct regcache *regcache);
189130803Smarcelextern void regcache_cpy (struct regcache *dest, struct regcache *src);
190130803Smarcelextern void regcache_cpy_no_passthrough (struct regcache *dest, struct regcache *src);
191130803Smarcel
192130803Smarcel/* NOTE: cagney/2002-11-02: The below have been superseded by the
193130803Smarcel   regcache_cooked_*() functions found above, and the frame_*()
194130803Smarcel   functions found in "frame.h".  Take care though, often more than a
195130803Smarcel   simple substitution is required when updating the code.  The
196130803Smarcel   change, as far as practical, should avoid adding references to
197130803Smarcel   global variables (e.g., current_regcache, current_frame,
198130803Smarcel   current_gdbarch or deprecated_selected_frame) and instead refer to
199130803Smarcel   the FRAME or REGCACHE that has been passed into the containing
200130803Smarcel   function as parameters.  Consequently, the change typically
201130803Smarcel   involves modifying the containing function so that it takes a FRAME
202130803Smarcel   or REGCACHE parameter.  In the case of an architecture vector
203130803Smarcel   method, there should already be a non-deprecated variant that is
204130803Smarcel   parameterized with FRAME or REGCACHE.  */
205130803Smarcel
206130803Smarcelextern char *deprecated_grub_regcache_for_registers (struct regcache *);
207130803Smarcelextern void deprecated_read_register_gen (int regnum, char *myaddr);
208130803Smarcelextern void deprecated_write_register_gen (int regnum, char *myaddr);
209130803Smarcelextern void deprecated_read_register_bytes (int regbyte, char *myaddr,
210130803Smarcel					    int len);
211130803Smarcelextern void deprecated_write_register_bytes (int regbyte, char *myaddr,
212130803Smarcel					     int len);
213130803Smarcel
214130803Smarcel/* Character array containing the current state of each register
215130803Smarcel   (unavailable<0, invalid=0, valid>0) for the most recently
216130803Smarcel   referenced thread.  This global is often found in close proximity
217130803Smarcel   to code that is directly manipulating the deprecated_registers[]
218130803Smarcel   array.  In such cases, it should be possible to replace the lot
219130803Smarcel   with a call to supply_register().  If you find yourself in dire
220130803Smarcel   straits, still needing access to the cache status bit, the
221130803Smarcel   regcache_valid_p() and set_register_cached() functions are
222130803Smarcel   available.  */
223130803Smarcelextern signed char *deprecated_register_valid;
224130803Smarcel
225130803Smarcel/* Character array containing an image of the inferior programs'
226130803Smarcel   registers for the most recently referenced thread.
227130803Smarcel
228130803Smarcel   NOTE: cagney/2002-11-14: Target side code should be using
229130803Smarcel   supply_register() and/or regcache_collect() while architecture side
230130803Smarcel   code should use the more generic regcache methods.  */
231130803Smarcel
232130803Smarcelextern char *deprecated_registers;
233130803Smarcel
234130803Smarcel/* NOTE: cagney/2002-11-05: This function, and its co-conspirator
235130803Smarcel   deprecated_registers[], have been superseeded by supply_register().  */
236130803Smarcelextern void deprecated_registers_fetched (void);
237130803Smarcel
238130803Smarcelextern int register_cached (int regnum);
239130803Smarcel
240130803Smarcelextern void set_register_cached (int regnum, int state);
241130803Smarcel
242130803Smarcelextern void registers_changed (void);
243130803Smarcel
244130803Smarcel
24598944Sobrien/* Rename to read_unsigned_register()? */
24698944Sobrienextern ULONGEST read_register (int regnum);
24798944Sobrien
24898944Sobrien/* Rename to read_unsigned_register_pid()? */
24998944Sobrienextern ULONGEST read_register_pid (int regnum, ptid_t ptid);
25098944Sobrien
25198944Sobrienextern void write_register (int regnum, LONGEST val);
25298944Sobrien
25398944Sobrienextern void write_register_pid (int regnum, CORE_ADDR val, ptid_t ptid);
25498944Sobrien
25598944Sobrien#endif /* REGCACHE_H */
256