1*56bb7041Schristos /* Cache and manage the values of registers
2*56bb7041Schristos 
3*56bb7041Schristos    Copyright (C) 2014-2020 Free Software Foundation, Inc.
4*56bb7041Schristos 
5*56bb7041Schristos    This file is part of GDB.
6*56bb7041Schristos 
7*56bb7041Schristos    This program is free software; you can redistribute it and/or modify
8*56bb7041Schristos    it under the terms of the GNU General Public License as published by
9*56bb7041Schristos    the Free Software Foundation; either version 3 of the License, or
10*56bb7041Schristos    (at your option) any later version.
11*56bb7041Schristos 
12*56bb7041Schristos    This program is distributed in the hope that it will be useful,
13*56bb7041Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*56bb7041Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*56bb7041Schristos    GNU General Public License for more details.
16*56bb7041Schristos 
17*56bb7041Schristos    You should have received a copy of the GNU General Public License
18*56bb7041Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19*56bb7041Schristos 
20*56bb7041Schristos #ifndef COMMON_COMMON_REGCACHE_H
21*56bb7041Schristos #define COMMON_COMMON_REGCACHE_H
22*56bb7041Schristos 
23*56bb7041Schristos /* This header is a stopgap until we have an independent regcache.  */
24*56bb7041Schristos 
25*56bb7041Schristos enum register_status : signed char
26*56bb7041Schristos   {
27*56bb7041Schristos     /* The register value is not in the cache, and we don't know yet
28*56bb7041Schristos        whether it's available in the target (or traceframe).  */
29*56bb7041Schristos     REG_UNKNOWN = 0,
30*56bb7041Schristos 
31*56bb7041Schristos     /* The register value is valid and cached.  */
32*56bb7041Schristos     REG_VALID = 1,
33*56bb7041Schristos 
34*56bb7041Schristos     /* The register value is unavailable.  E.g., we're inspecting a
35*56bb7041Schristos        traceframe, and this register wasn't collected.  Note that this
36*56bb7041Schristos        is different a different "unavailable" from saying the register
37*56bb7041Schristos        does not exist in the target's architecture --- in that case,
38*56bb7041Schristos        the target should have given us a target description that does
39*56bb7041Schristos        not include the register in the first place.  */
40*56bb7041Schristos     REG_UNAVAILABLE = -1
41*56bb7041Schristos   };
42*56bb7041Schristos 
43*56bb7041Schristos /* Return a pointer to the register cache associated with the
44*56bb7041Schristos    thread specified by PTID.  This function must be provided by
45*56bb7041Schristos    the client.  */
46*56bb7041Schristos 
47*56bb7041Schristos extern struct regcache *get_thread_regcache_for_ptid (ptid_t ptid);
48*56bb7041Schristos 
49*56bb7041Schristos /* Return the size of register numbered N in REGCACHE.  This function
50*56bb7041Schristos    must be provided by the client.  */
51*56bb7041Schristos 
52*56bb7041Schristos extern int regcache_register_size (const struct regcache *regcache, int n);
53*56bb7041Schristos 
54*56bb7041Schristos /* Read the PC register.  This function must be provided by the
55*56bb7041Schristos    client.  */
56*56bb7041Schristos 
57*56bb7041Schristos extern CORE_ADDR regcache_read_pc (struct regcache *regcache);
58*56bb7041Schristos 
59*56bb7041Schristos /* Read the PC register.  If PC cannot be read, return 0.
60*56bb7041Schristos    This is a wrapper around 'regcache_read_pc'.  */
61*56bb7041Schristos 
62*56bb7041Schristos extern CORE_ADDR regcache_read_pc_protected (regcache *regcache);
63*56bb7041Schristos 
64*56bb7041Schristos /* Read a raw register into a unsigned integer.  */
65*56bb7041Schristos extern enum register_status regcache_raw_read_unsigned
66*56bb7041Schristos   (struct regcache *regcache, int regnum, ULONGEST *val);
67*56bb7041Schristos 
68*56bb7041Schristos ULONGEST regcache_raw_get_unsigned (struct regcache *regcache, int regnum);
69*56bb7041Schristos 
70*56bb7041Schristos struct reg_buffer_common
71*56bb7041Schristos {
72*56bb7041Schristos   virtual ~reg_buffer_common () = default;
73*56bb7041Schristos 
74*56bb7041Schristos   /* Get the availability status of the value of register REGNUM in this
75*56bb7041Schristos      buffer.  */
76*56bb7041Schristos   virtual register_status get_register_status (int regnum) const = 0;
77*56bb7041Schristos 
78*56bb7041Schristos   /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE.  */
79*56bb7041Schristos   virtual void raw_supply (int regnum, const void *buf) = 0;
80*56bb7041Schristos 
81*56bb7041Schristos   /* Collect register REGNUM from REGCACHE and store its contents in BUF.  */
82*56bb7041Schristos   virtual void raw_collect (int regnum, void *buf) const = 0;
83*56bb7041Schristos 
84*56bb7041Schristos   /* Compare the contents of the register stored in the regcache (ignoring the
85*56bb7041Schristos      first OFFSET bytes) to the contents of BUF (without any offset).  Returns
86*56bb7041Schristos      true if the same.  */
87*56bb7041Schristos   virtual bool raw_compare (int regnum, const void *buf, int offset) const = 0;
88*56bb7041Schristos };
89*56bb7041Schristos 
90*56bb7041Schristos #endif /* COMMON_COMMON_REGCACHE_H */
91