15796c8dcSSimon Schubert /* Cache and manage the values of registers for GDB, the GNU debugger. 25796c8dcSSimon Schubert 3*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc. 45796c8dcSSimon Schubert 55796c8dcSSimon Schubert This file is part of GDB. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 95796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 105796c8dcSSimon Schubert (at your option) any later version. 115796c8dcSSimon Schubert 125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 155796c8dcSSimon Schubert GNU General Public License for more details. 165796c8dcSSimon Schubert 175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 185796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 195796c8dcSSimon Schubert 205796c8dcSSimon Schubert #ifndef REGCACHE_H 215796c8dcSSimon Schubert #define REGCACHE_H 225796c8dcSSimon Schubert 235796c8dcSSimon Schubert struct regcache; 245796c8dcSSimon Schubert struct gdbarch; 25cf7f2e2dSJohn Marino struct address_space; 265796c8dcSSimon Schubert 275796c8dcSSimon Schubert extern struct regcache *get_current_regcache (void); 285796c8dcSSimon Schubert extern struct regcache *get_thread_regcache (ptid_t ptid); 295796c8dcSSimon Schubert extern struct regcache *get_thread_arch_regcache (ptid_t, struct gdbarch *); 30a45ae5f8SJohn Marino extern struct regcache *get_thread_arch_aspace_regcache (ptid_t, 31a45ae5f8SJohn Marino struct gdbarch *, 32a45ae5f8SJohn Marino struct address_space *); 335796c8dcSSimon Schubert 345796c8dcSSimon Schubert void regcache_xfree (struct regcache *regcache); 355796c8dcSSimon Schubert struct cleanup *make_cleanup_regcache_xfree (struct regcache *regcache); 36cf7f2e2dSJohn Marino struct regcache *regcache_xmalloc (struct gdbarch *gdbarch, 37cf7f2e2dSJohn Marino struct address_space *aspace); 385796c8dcSSimon Schubert 395796c8dcSSimon Schubert /* Return REGCACHE's architecture. */ 405796c8dcSSimon Schubert 415796c8dcSSimon Schubert extern struct gdbarch *get_regcache_arch (const struct regcache *regcache); 425796c8dcSSimon Schubert 43cf7f2e2dSJohn Marino /* Return REGCACHE's address space. */ 44cf7f2e2dSJohn Marino 45c50c785cSJohn Marino extern struct address_space *get_regcache_aspace (const struct regcache *); 46c50c785cSJohn Marino 47c50c785cSJohn Marino enum register_status 48c50c785cSJohn Marino { 49c50c785cSJohn Marino /* The register value is not in the cache, and we don't know yet 50c50c785cSJohn Marino whether it's available in the target (or traceframe). */ 51c50c785cSJohn Marino REG_UNKNOWN = 0, 52c50c785cSJohn Marino 53c50c785cSJohn Marino /* The register value is valid and cached. */ 54c50c785cSJohn Marino REG_VALID = 1, 55c50c785cSJohn Marino 56c50c785cSJohn Marino /* The register value is unavailable. E.g., we're inspecting a 57c50c785cSJohn Marino traceframe, and this register wasn't collected. Note that this 58c50c785cSJohn Marino is different a different "unavailable" from saying the register 59c50c785cSJohn Marino does not exist in the target's architecture --- in that case, 60c50c785cSJohn Marino the target should have given us a target description that does 61c50c785cSJohn Marino not include the register in the first place. */ 62c50c785cSJohn Marino REG_UNAVAILABLE = -1 63c50c785cSJohn Marino }; 64c50c785cSJohn Marino 65c50c785cSJohn Marino enum register_status regcache_register_status (const struct regcache *regcache, 66c50c785cSJohn Marino int regnum); 67cf7f2e2dSJohn Marino 685796c8dcSSimon Schubert /* Transfer a raw register [0..NUM_REGS) between core-gdb and the 69c50c785cSJohn Marino regcache. The read variants return the status of the register. */ 705796c8dcSSimon Schubert 71c50c785cSJohn Marino enum register_status regcache_raw_read (struct regcache *regcache, 72c50c785cSJohn Marino int rawnum, gdb_byte *buf); 735796c8dcSSimon Schubert void regcache_raw_write (struct regcache *regcache, int rawnum, 745796c8dcSSimon Schubert const gdb_byte *buf); 75c50c785cSJohn Marino extern enum register_status 76c50c785cSJohn Marino regcache_raw_read_signed (struct regcache *regcache, 775796c8dcSSimon Schubert int regnum, LONGEST *val); 78c50c785cSJohn Marino extern enum register_status 79c50c785cSJohn Marino regcache_raw_read_unsigned (struct regcache *regcache, 805796c8dcSSimon Schubert int regnum, ULONGEST *val); 815796c8dcSSimon Schubert extern void regcache_raw_write_signed (struct regcache *regcache, 825796c8dcSSimon Schubert int regnum, LONGEST val); 835796c8dcSSimon Schubert extern void regcache_raw_write_unsigned (struct regcache *regcache, 845796c8dcSSimon Schubert int regnum, ULONGEST val); 855796c8dcSSimon Schubert 86c50c785cSJohn Marino /* Partial transfer of raw registers. These perform read, modify, 87c50c785cSJohn Marino write style operations. The read variant returns the status of the 88c50c785cSJohn Marino register. */ 895796c8dcSSimon Schubert 90c50c785cSJohn Marino extern enum register_status 91c50c785cSJohn Marino regcache_raw_read_part (struct regcache *regcache, int regnum, 925796c8dcSSimon Schubert int offset, int len, gdb_byte *buf); 935796c8dcSSimon Schubert void regcache_raw_write_part (struct regcache *regcache, int regnum, 945796c8dcSSimon Schubert int offset, int len, const gdb_byte *buf); 955796c8dcSSimon Schubert 965796c8dcSSimon Schubert void regcache_invalidate (struct regcache *regcache, int regnum); 975796c8dcSSimon Schubert 98c50c785cSJohn Marino /* Transfer of pseudo-registers. The read variants return a register 99c50c785cSJohn Marino status, as an indication of when a ``cooked'' register was 100c50c785cSJohn Marino constructed from valid, invalid or unavailable ``raw'' 101c50c785cSJohn Marino registers. */ 102c50c785cSJohn Marino 1035796c8dcSSimon Schubert /* Transfer a cooked register [0..NUM_REGS+NUM_PSEUDO_REGS). */ 104c50c785cSJohn Marino enum register_status regcache_cooked_read (struct regcache *regcache, 105c50c785cSJohn Marino int rawnum, gdb_byte *buf); 1065796c8dcSSimon Schubert void regcache_cooked_write (struct regcache *regcache, int rawnum, 1075796c8dcSSimon Schubert const gdb_byte *buf); 1085796c8dcSSimon Schubert 109a45ae5f8SJohn Marino /* Read register REGNUM from REGCACHE and return a new value. This 110a45ae5f8SJohn Marino will call mark_value_bytes_unavailable as appropriate. */ 111a45ae5f8SJohn Marino 112a45ae5f8SJohn Marino struct value *regcache_cooked_read_value (struct regcache *regcache, 113a45ae5f8SJohn Marino int regnum); 114a45ae5f8SJohn Marino 1155796c8dcSSimon Schubert /* Read a register as a signed/unsigned quantity. */ 116c50c785cSJohn Marino extern enum register_status 117c50c785cSJohn Marino regcache_cooked_read_signed (struct regcache *regcache, 1185796c8dcSSimon Schubert int regnum, LONGEST *val); 119c50c785cSJohn Marino extern enum register_status 120c50c785cSJohn Marino regcache_cooked_read_unsigned (struct regcache *regcache, 1215796c8dcSSimon Schubert int regnum, ULONGEST *val); 1225796c8dcSSimon Schubert extern void regcache_cooked_write_signed (struct regcache *regcache, 1235796c8dcSSimon Schubert int regnum, LONGEST val); 1245796c8dcSSimon Schubert extern void regcache_cooked_write_unsigned (struct regcache *regcache, 1255796c8dcSSimon Schubert int regnum, ULONGEST val); 1265796c8dcSSimon Schubert 1275796c8dcSSimon Schubert /* Partial transfer of a cooked register. These perform read, modify, 1285796c8dcSSimon Schubert write style operations. */ 1295796c8dcSSimon Schubert 130c50c785cSJohn Marino enum register_status regcache_cooked_read_part (struct regcache *regcache, 131c50c785cSJohn Marino int regnum, int offset, 132c50c785cSJohn Marino int len, gdb_byte *buf); 1335796c8dcSSimon Schubert void regcache_cooked_write_part (struct regcache *regcache, int regnum, 1345796c8dcSSimon Schubert int offset, int len, const gdb_byte *buf); 1355796c8dcSSimon Schubert 1365796c8dcSSimon Schubert /* Special routines to read/write the PC. */ 1375796c8dcSSimon Schubert 1385796c8dcSSimon Schubert extern CORE_ADDR regcache_read_pc (struct regcache *regcache); 1395796c8dcSSimon Schubert extern void regcache_write_pc (struct regcache *regcache, CORE_ADDR pc); 1405796c8dcSSimon Schubert 1415796c8dcSSimon Schubert /* Transfer a raw register [0..NUM_REGS) between the regcache and the 1425796c8dcSSimon Schubert target. These functions are called by the target in response to a 1435796c8dcSSimon Schubert target_fetch_registers() or target_store_registers(). */ 1445796c8dcSSimon Schubert 1455796c8dcSSimon Schubert extern void regcache_raw_supply (struct regcache *regcache, 1465796c8dcSSimon Schubert int regnum, const void *buf); 1475796c8dcSSimon Schubert extern void regcache_raw_collect (const struct regcache *regcache, 1485796c8dcSSimon Schubert int regnum, void *buf); 1495796c8dcSSimon Schubert 1505796c8dcSSimon Schubert 1515796c8dcSSimon Schubert /* The type of a register. This function is slightly more efficient 1525796c8dcSSimon Schubert then its gdbarch vector counterpart since it returns a precomputed 1535796c8dcSSimon Schubert value stored in a table. */ 1545796c8dcSSimon Schubert 1555796c8dcSSimon Schubert extern struct type *register_type (struct gdbarch *gdbarch, int regnum); 1565796c8dcSSimon Schubert 1575796c8dcSSimon Schubert 1585796c8dcSSimon Schubert /* Return the size of register REGNUM. All registers should have only 1595796c8dcSSimon Schubert one size. */ 1605796c8dcSSimon Schubert 1615796c8dcSSimon Schubert extern int register_size (struct gdbarch *gdbarch, int regnum); 1625796c8dcSSimon Schubert 1635796c8dcSSimon Schubert 1645796c8dcSSimon Schubert /* Save/restore a register cache. The set of registers saved / 1655796c8dcSSimon Schubert restored into the DST regcache determined by the save_reggroup / 1665796c8dcSSimon Schubert restore_reggroup respectively. COOKED_READ returns zero iff the 1675796c8dcSSimon Schubert register's value can't be returned. */ 1685796c8dcSSimon Schubert 169c50c785cSJohn Marino typedef enum register_status (regcache_cooked_read_ftype) (void *src, 170c50c785cSJohn Marino int regnum, 1715796c8dcSSimon Schubert gdb_byte *buf); 1725796c8dcSSimon Schubert 1735796c8dcSSimon Schubert extern void regcache_save (struct regcache *dst, 1745796c8dcSSimon Schubert regcache_cooked_read_ftype *cooked_read, 1755796c8dcSSimon Schubert void *cooked_read_context); 1765796c8dcSSimon Schubert 1775796c8dcSSimon Schubert /* Copy/duplicate the contents of a register cache. By default, the 1785796c8dcSSimon Schubert operation is pass-through. Writes to DST and reads from SRC will 1795796c8dcSSimon Schubert go through to the target. 1805796c8dcSSimon Schubert 1815796c8dcSSimon Schubert The ``cpy'' functions can not have overlapping SRC and DST buffers. 1825796c8dcSSimon Schubert 1835796c8dcSSimon Schubert ``no passthrough'' versions do not go through to the target. They 1845796c8dcSSimon Schubert only transfer values already in the cache. */ 1855796c8dcSSimon Schubert 1865796c8dcSSimon Schubert extern struct regcache *regcache_dup (struct regcache *regcache); 1875796c8dcSSimon Schubert extern void regcache_cpy (struct regcache *dest, struct regcache *src); 188c50c785cSJohn Marino extern void regcache_cpy_no_passthrough (struct regcache *dest, 189c50c785cSJohn Marino struct regcache *src); 1905796c8dcSSimon Schubert 1915796c8dcSSimon Schubert extern void registers_changed (void); 192cf7f2e2dSJohn Marino extern void registers_changed_ptid (ptid_t); 1935796c8dcSSimon Schubert 1945796c8dcSSimon Schubert #endif /* REGCACHE_H */ 195