Skip to content

Commit 5d8a142

Browse files
committed
target/armv4_5: mark registers as 'save-restore'
gdb uses this mark when creating a dummy frame for manual call of a function by gdb command. With the original setting all registers as caller_save = false call command in gdb always clobbers r0, r1 and pc and some other registers depending on the called function. Set 'save-restore' for all registers but banked ones. Change-Id: I16c49e4bf8001e38d18ce8861ca65988b08ccc88 Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: https://review.openocd.org/c/openocd/+/9208 Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Tested-by: jenkins
1 parent d044aff commit 5d8a142

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/target/armv4_5.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,6 @@ struct reg_cache *arm_build_reg_cache(struct target *target, struct arm *arm)
691691
&& arm->core_type != ARM_CORE_TYPE_VIRT_EXT)
692692
continue;
693693

694-
/* REVISIT handle Cortex-M, which only shadows R13/SP */
695-
696694
reg_arch_info[i].num = arm_core_regs[i].cookie;
697695
reg_arch_info[i].mode = arm_core_regs[i].mode;
698696
reg_arch_info[i].target = target;
@@ -706,9 +704,6 @@ struct reg_cache *arm_build_reg_cache(struct target *target, struct arm *arm)
706704
reg_list[i].arch_info = &reg_arch_info[i];
707705
reg_list[i].exist = true;
708706

709-
/* This really depends on the calling convention in use */
710-
reg_list[i].caller_save = false;
711-
712707
/* Registers data type, as used by GDB target description */
713708
reg_list[i].reg_data_type = malloc(sizeof(struct reg_data_type));
714709
switch (arm_core_regs[i].cookie) {
@@ -729,9 +724,16 @@ struct reg_cache *arm_build_reg_cache(struct target *target, struct arm *arm)
729724
if (reg_list[i].number <= 15 || reg_list[i].number == 25) {
730725
reg_list[i].feature->name = "org.gnu.gdb.arm.core";
731726
reg_list[i].group = "general";
727+
/* Registers which should be preserved across GDB inferior function calls.
728+
* Avoid saving banked registers as GDB (version 16.2 in time of writing)
729+
* does not take the current mode into account and messes the value
730+
* by restoring both the not banked register and the banked alias of it
731+
* in the current mode. */
732+
reg_list[i].caller_save = true;
732733
} else {
733734
reg_list[i].feature->name = "net.sourceforge.openocd.banked";
734735
reg_list[i].group = "banked";
736+
reg_list[i].caller_save = false;
735737
}
736738

737739
cache->num_regs++;
@@ -751,7 +753,8 @@ struct reg_cache *arm_build_reg_cache(struct target *target, struct arm *arm)
751753
reg_list[i].arch_info = &reg_arch_info[i];
752754
reg_list[i].exist = true;
753755

754-
reg_list[i].caller_save = false;
756+
/* Mark d0 - d31 and fpscr as save-restore for GDB */
757+
reg_list[i].caller_save = true;
755758

756759
reg_list[i].reg_data_type = malloc(sizeof(struct reg_data_type));
757760
reg_list[i].reg_data_type->type = arm_vfp_v3_regs[j].type;

0 commit comments

Comments
 (0)