1*6881a400Schristos /* Copyright (C) 1999-2023 Free Software Foundation, Inc. 2ed8eb4c2Schristos 3ed8eb4c2Schristos This file is part of GDB. 4ed8eb4c2Schristos 5ed8eb4c2Schristos This program is free software; you can redistribute it and/or modify 6ed8eb4c2Schristos it under the terms of the GNU General Public License as published by 7ed8eb4c2Schristos the Free Software Foundation; either version 3 of the License, or 8ed8eb4c2Schristos (at your option) any later version. 9ed8eb4c2Schristos 10ed8eb4c2Schristos This program is distributed in the hope that it will be useful, 11ed8eb4c2Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 12ed8eb4c2Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13ed8eb4c2Schristos GNU General Public License for more details. 14ed8eb4c2Schristos 15ed8eb4c2Schristos You should have received a copy of the GNU General Public License 16ed8eb4c2Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17ed8eb4c2Schristos 18ed8eb4c2Schristos #include "defs.h" 19ed8eb4c2Schristos 20ed8eb4c2Schristos #include "regcache.h" 21ed8eb4c2Schristos #include "arm-tdep.h" 22ed8eb4c2Schristos #include "arm-linux-tdep.h" 23ed8eb4c2Schristos #include "arch/arm-linux.h" 24ed8eb4c2Schristos 25ed8eb4c2Schristos #include "aarch32-linux-nat.h" 26ed8eb4c2Schristos 27ed8eb4c2Schristos /* Supply GP registers contents, stored in REGS, to REGCACHE. ARM_APCS_32 28ed8eb4c2Schristos is true if the 32-bit mode is in use, otherwise, it is false. */ 29ed8eb4c2Schristos 30ed8eb4c2Schristos void 31ed8eb4c2Schristos aarch32_gp_regcache_supply (struct regcache *regcache, uint32_t *regs, 32ed8eb4c2Schristos int arm_apcs_32) 33ed8eb4c2Schristos { 34ed8eb4c2Schristos int regno; 35ed8eb4c2Schristos 36ed8eb4c2Schristos for (regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++) 377f2ac410Schristos regcache->raw_supply (regno, ®s[regno]); 38ed8eb4c2Schristos 39ed8eb4c2Schristos if (arm_apcs_32) 40ed8eb4c2Schristos { 41ed8eb4c2Schristos /* Clear reserved bits bit 20 to bit 23. */ 42ed8eb4c2Schristos regs[ARM_CPSR_GREGNUM] &= 0xff0fffff; 437f2ac410Schristos regcache->raw_supply (ARM_PS_REGNUM, ®s[ARM_CPSR_GREGNUM]); 44ed8eb4c2Schristos } 45ed8eb4c2Schristos else 467f2ac410Schristos regcache->raw_supply (ARM_PS_REGNUM, ®s[ARM_PC_REGNUM]); 47ed8eb4c2Schristos 48ed8eb4c2Schristos regs[ARM_PC_REGNUM] = gdbarch_addr_bits_remove 497f2ac410Schristos (regcache->arch (), regs[ARM_PC_REGNUM]); 507f2ac410Schristos regcache->raw_supply (ARM_PC_REGNUM, ®s[ARM_PC_REGNUM]); 51ed8eb4c2Schristos } 52ed8eb4c2Schristos 53ed8eb4c2Schristos /* Collect GP registers from REGCACHE to buffer REGS. ARM_APCS_32 is 54ed8eb4c2Schristos true if the 32-bit mode is in use, otherwise, it is false. */ 55ed8eb4c2Schristos 56ed8eb4c2Schristos void 57ed8eb4c2Schristos aarch32_gp_regcache_collect (const struct regcache *regcache, uint32_t *regs, 58ed8eb4c2Schristos int arm_apcs_32) 59ed8eb4c2Schristos { 60ed8eb4c2Schristos int regno; 61ed8eb4c2Schristos 62ed8eb4c2Schristos for (regno = ARM_A1_REGNUM; regno <= ARM_PC_REGNUM; regno++) 63ed8eb4c2Schristos { 647f2ac410Schristos if (REG_VALID == regcache->get_register_status (regno)) 657f2ac410Schristos regcache->raw_collect (regno, ®s[regno]); 66ed8eb4c2Schristos } 67ed8eb4c2Schristos 68ed8eb4c2Schristos if (arm_apcs_32 697f2ac410Schristos && REG_VALID == regcache->get_register_status (ARM_PS_REGNUM)) 70ed8eb4c2Schristos { 71ed8eb4c2Schristos uint32_t cpsr = regs[ARM_CPSR_GREGNUM]; 72ed8eb4c2Schristos 737f2ac410Schristos regcache->raw_collect (ARM_PS_REGNUM, ®s[ARM_CPSR_GREGNUM]); 74ed8eb4c2Schristos /* Keep reserved bits bit 20 to bit 23. */ 75ed8eb4c2Schristos regs[ARM_CPSR_GREGNUM] = ((regs[ARM_CPSR_GREGNUM] & 0xff0fffff) 76ed8eb4c2Schristos | (cpsr & 0x00f00000)); 77ed8eb4c2Schristos } 78ed8eb4c2Schristos } 79ed8eb4c2Schristos 80ed8eb4c2Schristos /* Supply VFP registers contents, stored in REGS, to REGCACHE. 81ed8eb4c2Schristos VFP_REGISTER_COUNT is the number of VFP registers. */ 82ed8eb4c2Schristos 83ed8eb4c2Schristos void 84ed8eb4c2Schristos aarch32_vfp_regcache_supply (struct regcache *regcache, gdb_byte *regs, 85ed8eb4c2Schristos const int vfp_register_count) 86ed8eb4c2Schristos { 87ed8eb4c2Schristos int regno; 88ed8eb4c2Schristos 89ed8eb4c2Schristos for (regno = 0; regno < vfp_register_count; regno++) 907f2ac410Schristos regcache->raw_supply (regno + ARM_D0_REGNUM, regs + regno * 8); 91ed8eb4c2Schristos 927f2ac410Schristos regcache->raw_supply (ARM_FPSCR_REGNUM, regs + 32 * 8); 93ed8eb4c2Schristos } 94ed8eb4c2Schristos 95ed8eb4c2Schristos /* Collect VFP registers from REGCACHE to buffer REGS. 96ed8eb4c2Schristos VFP_REGISTER_COUNT is the number VFP registers. */ 97ed8eb4c2Schristos 98ed8eb4c2Schristos void 99ed8eb4c2Schristos aarch32_vfp_regcache_collect (const struct regcache *regcache, gdb_byte *regs, 100ed8eb4c2Schristos const int vfp_register_count) 101ed8eb4c2Schristos { 102ed8eb4c2Schristos int regno; 103ed8eb4c2Schristos 104ed8eb4c2Schristos for (regno = 0; regno < vfp_register_count; regno++) 1057f2ac410Schristos regcache->raw_collect (regno + ARM_D0_REGNUM, regs + regno * 8); 106ed8eb4c2Schristos 1077f2ac410Schristos regcache->raw_collect (ARM_FPSCR_REGNUM, regs + 32 * 8); 108ed8eb4c2Schristos } 109