18dffb485Schristos /* Cache and manage the values of registers 28dffb485Schristos 3*5ba1f45fSchristos Copyright (C) 2014-2024 Free Software Foundation, Inc. 48dffb485Schristos 58dffb485Schristos This file is part of GDB. 68dffb485Schristos 78dffb485Schristos This program is free software; you can redistribute it and/or modify 88dffb485Schristos it under the terms of the GNU General Public License as published by 98dffb485Schristos the Free Software Foundation; either version 3 of the License, or 108dffb485Schristos (at your option) any later version. 118dffb485Schristos 128dffb485Schristos This program is distributed in the hope that it will be useful, 138dffb485Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 148dffb485Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 158dffb485Schristos GNU General Public License for more details. 168dffb485Schristos 178dffb485Schristos You should have received a copy of the GNU General Public License 188dffb485Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 198dffb485Schristos 208dffb485Schristos #ifndef COMMON_COMMON_REGCACHE_H 218dffb485Schristos #define COMMON_COMMON_REGCACHE_H 228dffb485Schristos 23*5ba1f45fSchristos struct reg_buffer_common; 24*5ba1f45fSchristos 258dffb485Schristos /* This header is a stopgap until we have an independent regcache. */ 268dffb485Schristos 278dffb485Schristos enum register_status : signed char 288dffb485Schristos { 298dffb485Schristos /* The register value is not in the cache, and we don't know yet 308dffb485Schristos whether it's available in the target (or traceframe). */ 318dffb485Schristos REG_UNKNOWN = 0, 328dffb485Schristos 338dffb485Schristos /* The register value is valid and cached. */ 348dffb485Schristos REG_VALID = 1, 358dffb485Schristos 368dffb485Schristos /* The register value is unavailable. E.g., we're inspecting a 378dffb485Schristos traceframe, and this register wasn't collected. Note that this 388dffb485Schristos is different a different "unavailable" from saying the register 398dffb485Schristos does not exist in the target's architecture --- in that case, 408dffb485Schristos the target should have given us a target description that does 418dffb485Schristos not include the register in the first place. */ 428dffb485Schristos REG_UNAVAILABLE = -1 438dffb485Schristos }; 448dffb485Schristos 458dffb485Schristos /* Return a pointer to the register cache associated with the 468dffb485Schristos thread specified by PTID. This function must be provided by 478dffb485Schristos the client. */ 488dffb485Schristos 49*5ba1f45fSchristos extern reg_buffer_common *get_thread_regcache_for_ptid (ptid_t ptid); 508dffb485Schristos 518dffb485Schristos /* Return the size of register numbered N in REGCACHE. This function 528dffb485Schristos must be provided by the client. */ 538dffb485Schristos 54*5ba1f45fSchristos extern int regcache_register_size (const reg_buffer_common *regcache, int n); 558dffb485Schristos 568dffb485Schristos /* Read the PC register. This function must be provided by the 578dffb485Schristos client. */ 588dffb485Schristos 59*5ba1f45fSchristos extern CORE_ADDR regcache_read_pc (reg_buffer_common *regcache); 608dffb485Schristos 618dffb485Schristos /* Read the PC register. If PC cannot be read, return 0. 628dffb485Schristos This is a wrapper around 'regcache_read_pc'. */ 638dffb485Schristos 64*5ba1f45fSchristos extern CORE_ADDR regcache_read_pc_protected (reg_buffer_common *regcache); 658dffb485Schristos 668dffb485Schristos /* Read a raw register into a unsigned integer. */ 67*5ba1f45fSchristos extern enum register_status 68*5ba1f45fSchristos regcache_raw_read_unsigned (reg_buffer_common *regcache, int regnum, 69*5ba1f45fSchristos ULONGEST *val); 708dffb485Schristos 71*5ba1f45fSchristos ULONGEST regcache_raw_get_unsigned (reg_buffer_common *regcache, int regnum); 728dffb485Schristos 738dffb485Schristos struct reg_buffer_common 748dffb485Schristos { 758dffb485Schristos virtual ~reg_buffer_common () = default; 768dffb485Schristos 778dffb485Schristos /* Get the availability status of the value of register REGNUM in this 788dffb485Schristos buffer. */ 798dffb485Schristos virtual register_status get_register_status (int regnum) const = 0; 808dffb485Schristos 81*5ba1f45fSchristos /* Supply register REGNUM, whose contents are stored in SRC, to this register 82*5ba1f45fSchristos buffer. */ 83*5ba1f45fSchristos virtual void raw_supply (int regnum, gdb::array_view<const gdb_byte> src) 84*5ba1f45fSchristos = 0; 858dffb485Schristos 86*5ba1f45fSchristos void raw_supply (int regnum, const uint64_t *src) 87*5ba1f45fSchristos { 88*5ba1f45fSchristos raw_supply (regnum, 89*5ba1f45fSchristos gdb::make_array_view ((const gdb_byte *) src, sizeof (*src))); 90*5ba1f45fSchristos } 91*5ba1f45fSchristos 92*5ba1f45fSchristos void raw_supply (int regnum, const gdb_byte *src) 93*5ba1f45fSchristos { 94*5ba1f45fSchristos raw_supply (regnum, 95*5ba1f45fSchristos gdb::make_array_view (src, 96*5ba1f45fSchristos regcache_register_size (this, regnum))); 97*5ba1f45fSchristos } 98*5ba1f45fSchristos 99*5ba1f45fSchristos /* Collect register REGNUM from this register buffer and store its contents in 100*5ba1f45fSchristos DST. */ 101*5ba1f45fSchristos virtual void raw_collect (int regnum, gdb::array_view<gdb_byte> dst) const 102*5ba1f45fSchristos = 0; 103*5ba1f45fSchristos 104*5ba1f45fSchristos void raw_collect (int regnum, uint64_t *dst) const 105*5ba1f45fSchristos { 106*5ba1f45fSchristos raw_collect (regnum, 107*5ba1f45fSchristos gdb::make_array_view ((gdb_byte *) dst, sizeof (*dst))); 108*5ba1f45fSchristos }; 109*5ba1f45fSchristos 110*5ba1f45fSchristos void raw_collect (int regnum, gdb_byte *dst) 111*5ba1f45fSchristos { 112*5ba1f45fSchristos raw_collect (regnum, 113*5ba1f45fSchristos gdb::make_array_view (dst, 114*5ba1f45fSchristos regcache_register_size (this, regnum))); 115*5ba1f45fSchristos } 1168dffb485Schristos 1178dffb485Schristos /* Compare the contents of the register stored in the regcache (ignoring the 1188dffb485Schristos first OFFSET bytes) to the contents of BUF (without any offset). Returns 1198dffb485Schristos true if the same. */ 1208dffb485Schristos virtual bool raw_compare (int regnum, const void *buf, int offset) const = 0; 1218dffb485Schristos }; 1228dffb485Schristos 1238dffb485Schristos #endif /* COMMON_COMMON_REGCACHE_H */ 124