Blame SOURCES/gdb-rhbz1480496-power-atomic-step-5of5.patch

8f6b9e
commit 2039d74e780db6659c87cd3c426d526615cfe703
8f6b9e
Author: Edjunior Barbosa Machado <emachado@linux.vnet.ibm.com>
8f6b9e
Date:   Tue Feb 21 11:14:56 2017 -0300
8f6b9e
8f6b9e
    [ppc64] Add POWER8/ISA 2.07 atomic sequences single-stepping support
8f6b9e
    
8f6b9e
    gdb/
8f6b9e
    2017-02-21  Edjunior Barbosa Machado  <emachado@linux.vnet.ibm.com>
8f6b9e
    
8f6b9e
            * rs6000-tdep.c (LOAD_AND_RESERVE_MASK): Rename from LWARX_MASK.
8f6b9e
            (STORE_CONDITIONAL_MASK): Rename from STWCX_MASK.
8f6b9e
            (LBARX_INSTRUCTION, LHARX_INSTRUCTION, LQARX_INSTRUCTION,
8f6b9e
            STBCX_INSTRUCTION, STHCX_INSTRUCTION, STQCX_INSTRUCTION): New defines.
8f6b9e
            (IS_LOAD_AND_RESERVE_INSN, IS_STORE_CONDITIONAL_INSN): New macros.
8f6b9e
            (ppc_displaced_step_copy_insn): Use IS_LOAD_AND_RESERVE_INSN.
8f6b9e
            (ppc_deal_with_atomic_sequence): Use IS_LOAD_AND_RESERVE_INSN and
8f6b9e
            IS_STORE_CONDITIONAL_INSN.
8f6b9e
    
8f6b9e
    gdb/testsuite/
8f6b9e
    2017-02-21  Edjunior Barbosa Machado  <emachado@linux.vnet.ibm.com>
8f6b9e
    
8f6b9e
            * gdb.arch/ppc64-isa207-atomic-inst.exp: New testcase based on
8f6b9e
            gdb.arch/ppc64-atomic-inst.exp.  Add tests for lbarx/stbcx, lharx/sthcx
8f6b9e
            and lqarx/stqcx.
8f6b9e
            * gdb.arch/ppc64-isa207-atomic-inst.S: New file.
8f6b9e
            * gdb.arch/ppc64-isa207-atomic-inst.c: Likewise.
8f6b9e
8f6b9e
### a/gdb/ChangeLog
8f6b9e
### b/gdb/ChangeLog
8f6b9e
## -1,3 +1,14 @@
8f6b9e
+2017-02-21  Edjunior Barbosa Machado  <emachado@linux.vnet.ibm.com>
8f6b9e
+
8f6b9e
+	* rs6000-tdep.c (LOAD_AND_RESERVE_MASK): Rename from LWARX_MASK.
8f6b9e
+	(STORE_CONDITIONAL_MASK): Rename from STWCX_MASK.
8f6b9e
+	(LBARX_INSTRUCTION, LHARX_INSTRUCTION, LQARX_INSTRUCTION,
8f6b9e
+	STBCX_INSTRUCTION, STHCX_INSTRUCTION, STQCX_INSTRUCTION): New defines.
8f6b9e
+	(IS_LOAD_AND_RESERVE_INSN, IS_STORE_CONDITIONAL_INSN): New macros.
8f6b9e
+	(ppc_displaced_step_copy_insn): Use IS_LOAD_AND_RESERVE_INSN.
8f6b9e
+	(ppc_deal_with_atomic_sequence): Use IS_LOAD_AND_RESERVE_INSN and
8f6b9e
+	IS_STORE_CONDITIONAL_INSN.
8f6b9e
+
8f6b9e
 2017-02-21  Jan Kratochvil  <jan.kratochvil@redhat.com>
8f6b9e
 
8f6b9e
 	* dwarf2_rnglists_process: Initialize range_beginning and range_end.
8f6b9e
Index: gdb-7.6.1/gdb/rs6000-tdep.c
8f6b9e
===================================================================
8f6b9e
--- gdb-7.6.1.orig/gdb/rs6000-tdep.c	2017-08-29 21:41:48.797481976 +0200
8f6b9e
+++ gdb-7.6.1/gdb/rs6000-tdep.c	2017-08-29 21:44:12.643863483 +0200
8f6b9e
@@ -977,12 +977,33 @@
8f6b9e
 
8f6b9e
 /* Instruction masks used during single-stepping of atomic
8f6b9e
    sequences.  */
8f6b9e
-#define LWARX_MASK 0xfc0007fe
8f6b9e
+#define LOAD_AND_RESERVE_MASK 0xfc0007fe
8f6b9e
 #define LWARX_INSTRUCTION 0x7c000028
8f6b9e
 #define LDARX_INSTRUCTION 0x7c0000A8
8f6b9e
-#define STWCX_MASK 0xfc0007ff
8f6b9e
+#define LBARX_INSTRUCTION 0x7c000068
8f6b9e
+#define LHARX_INSTRUCTION 0x7c0000e8
8f6b9e
+#define LQARX_INSTRUCTION 0x7c000228
8f6b9e
+#define STORE_CONDITIONAL_MASK 0xfc0007ff
8f6b9e
 #define STWCX_INSTRUCTION 0x7c00012d
8f6b9e
 #define STDCX_INSTRUCTION 0x7c0001ad
8f6b9e
+#define STBCX_INSTRUCTION 0x7c00056d
8f6b9e
+#define STHCX_INSTRUCTION 0x7c0005ad
8f6b9e
+#define STQCX_INSTRUCTION 0x7c00016d
8f6b9e
+
8f6b9e
+/* Check if insn is one of the Load And Reserve instructions used for atomic
8f6b9e
+   sequences.  */
8f6b9e
+#define IS_LOAD_AND_RESERVE_INSN(insn)	((insn & LOAD_AND_RESERVE_MASK) == LWARX_INSTRUCTION \
8f6b9e
+					 || (insn & LOAD_AND_RESERVE_MASK) == LDARX_INSTRUCTION \
8f6b9e
+					 || (insn & LOAD_AND_RESERVE_MASK) == LBARX_INSTRUCTION \
8f6b9e
+					 || (insn & LOAD_AND_RESERVE_MASK) == LHARX_INSTRUCTION \
8f6b9e
+					 || (insn & LOAD_AND_RESERVE_MASK) == LQARX_INSTRUCTION)
8f6b9e
+/* Check if insn is one of the Store Conditional instructions used for atomic
8f6b9e
+   sequences.  */
8f6b9e
+#define IS_STORE_CONDITIONAL_INSN(insn)	((insn & STORE_CONDITIONAL_MASK) == STWCX_INSTRUCTION \
8f6b9e
+					 || (insn & STORE_CONDITIONAL_MASK) == STDCX_INSTRUCTION \
8f6b9e
+					 || (insn & STORE_CONDITIONAL_MASK) == STBCX_INSTRUCTION \
8f6b9e
+					 || (insn & STORE_CONDITIONAL_MASK) == STHCX_INSTRUCTION \
8f6b9e
+					 || (insn & STORE_CONDITIONAL_MASK) == STQCX_INSTRUCTION)
8f6b9e
 
8f6b9e
 /* We can't displaced step atomic sequences.  Otherwise this is just
8f6b9e
    like simple_displaced_step_copy_insn.  */
8f6b9e
@@ -1002,9 +1023,8 @@
8f6b9e
 
8f6b9e
   insn = extract_signed_integer (buf, PPC_INSN_SIZE, byte_order);
8f6b9e
 
8f6b9e
-  /* Assume all atomic sequences start with a lwarx/ldarx instruction.  */
8f6b9e
-  if ((insn & LWARX_MASK) == LWARX_INSTRUCTION
8f6b9e
-      || (insn & LWARX_MASK) == LDARX_INSTRUCTION)
8f6b9e
+  /* Assume all atomic sequences start with a Load and Reserve instruction.  */
8f6b9e
+  if (IS_LOAD_AND_RESERVE_INSN (insn))
8f6b9e
     {
8f6b9e
       if (debug_displaced)
8f6b9e
 	{
8f6b9e
@@ -1132,11 +1152,10 @@
8f6b9e
   return 1;
8f6b9e
 }
8f6b9e
 
8f6b9e
-/* Checks for an atomic sequence of instructions beginning with a LWARX/LDARX
8f6b9e
-   instruction and ending with a STWCX/STDCX instruction.  If such a sequence
8f6b9e
-   is found, attempt to step through it.  A breakpoint is placed at the end of 
8f6b9e
-   the sequence.  */
8f6b9e
-
8f6b9e
+/* Checks for an atomic sequence of instructions beginning with a
8f6b9e
+   Load And Reserve instruction and ending with a Store Conditional
8f6b9e
+   instruction.  If such a sequence is found, attempt to step through it.
8f6b9e
+   A breakpoint is placed at the end of the sequence.  */
8f6b9e
 int 
8f6b9e
 ppc_deal_with_atomic_sequence (struct frame_info *frame)
8f6b9e
 {
8f6b9e
@@ -1155,9 +1174,8 @@
8f6b9e
   int opcode; /* Branch instruction's OPcode.  */
8f6b9e
   int bc_insn_count = 0; /* Conditional branch instruction count.  */
8f6b9e
 
8f6b9e
-  /* Assume all atomic sequences start with a lwarx/ldarx instruction.  */
8f6b9e
-  if ((insn & LWARX_MASK) != LWARX_INSTRUCTION
8f6b9e
-      && (insn & LWARX_MASK) != LDARX_INSTRUCTION)
8f6b9e
+  /* Assume all atomic sequences start with a Load And Reserve instruction.  */
8f6b9e
+  if (!IS_LOAD_AND_RESERVE_INSN (insn))
8f6b9e
     return 0;
8f6b9e
 
8f6b9e
   /* Assume that no atomic sequence is longer than "atomic_sequence_length" 
8f6b9e
@@ -1188,14 +1206,13 @@
8f6b9e
 	  last_breakpoint++;
8f6b9e
         }
8f6b9e
 
8f6b9e
-      if ((insn & STWCX_MASK) == STWCX_INSTRUCTION
8f6b9e
-          || (insn & STWCX_MASK) == STDCX_INSTRUCTION)
8f6b9e
+      if (IS_STORE_CONDITIONAL_INSN (insn))
8f6b9e
         break;
8f6b9e
     }
8f6b9e
 
8f6b9e
-  /* Assume that the atomic sequence ends with a stwcx/stdcx instruction.  */
8f6b9e
-  if ((insn & STWCX_MASK) != STWCX_INSTRUCTION
8f6b9e
-      && (insn & STWCX_MASK) != STDCX_INSTRUCTION)
8f6b9e
+  /* Assume that the atomic sequence ends with a Store Conditional
8f6b9e
+     instruction.  */
8f6b9e
+  if (!IS_STORE_CONDITIONAL_INSN (insn))
8f6b9e
     return 0;
8f6b9e
 
8f6b9e
   closing_insn = loc;
8f6b9e
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/ppc64-isa207-atomic-inst.S
8f6b9e
===================================================================
8f6b9e
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
8f6b9e
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/ppc64-isa207-atomic-inst.S	2017-08-29 21:41:50.528498600 +0200
8f6b9e
@@ -0,0 +1,100 @@
8f6b9e
+/* This file is part of GDB, the GNU debugger.
8f6b9e
+
8f6b9e
+   Copyright 2017 Free Software Foundation, Inc.
8f6b9e
+
8f6b9e
+   This program is free software; you can redistribute it and/or modify
8f6b9e
+   it under the terms of the GNU General Public License as published by
8f6b9e
+   the Free Software Foundation; either version 3 of the License, or
8f6b9e
+   (at your option) any later version.
8f6b9e
+
8f6b9e
+   This program is distributed in the hope that it will be useful,
8f6b9e
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
8f6b9e
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8f6b9e
+   GNU General Public License for more details.
8f6b9e
+
8f6b9e
+   You should have received a copy of the GNU General Public License
8f6b9e
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
8f6b9e
+
8f6b9e
+	.align 2
8f6b9e
+	.globl test_atomic_sequences
8f6b9e
+#if _CALL_ELF == 2
8f6b9e
+	.type test_atomic_sequences,@function
8f6b9e
+test_atomic_sequences:
8f6b9e
+#else
8f6b9e
+	.section ".opd","aw"
8f6b9e
+	.align 3
8f6b9e
+test_atomic_sequences:
8f6b9e
+	.quad .test_atomic_sequences,.TOC.@tocbase,0
8f6b9e
+	.size test_atomic_sequences,.-test_atomic_sequences
8f6b9e
+	.previous
8f6b9e
+	.globl .test_atomic_sequences
8f6b9e
+	.type .test_atomic_sequences,@function
8f6b9e
+.test_atomic_sequences:
8f6b9e
+#endif
8f6b9e
+
8f6b9e
+	li	0,0
8f6b9e
+	addi	4,1,-8
8f6b9e
+
8f6b9e
+	stb	0,0(4)
8f6b9e
+1:	lbarx	5,0,4
8f6b9e
+	cmpdi	5,0
8f6b9e
+	bne	2f
8f6b9e
+	addi	5,5,1
8f6b9e
+	stbcx.	5,0,4
8f6b9e
+	bne	1b
8f6b9e
+
8f6b9e
+	sth	0,0(4)
8f6b9e
+2:	lharx	5,0,4
8f6b9e
+	cmpdi	5,0
8f6b9e
+	bne	3f
8f6b9e
+	addi	5,5,1
8f6b9e
+	sthcx.	5,0,4
8f6b9e
+	bne	2b
8f6b9e
+
8f6b9e
+#ifdef	__BIG_ENDIAN__
8f6b9e
+	li 10,0
8f6b9e
+	li 6,0
8f6b9e
+	li 7,1
8f6b9e
+	std 10,-16(1)
8f6b9e
+	li 10,1
8f6b9e
+	std 10,-8(1)
8f6b9e
+	addi 4,1,-16
8f6b9e
+#else
8f6b9e
+	std 9,40(1)
8f6b9e
+	li 9,1
8f6b9e
+	addi 4,1,32
8f6b9e
+	std 9,32(1)
8f6b9e
+	mr 8,9
8f6b9e
+	ld 3,8(4)
8f6b9e
+#endif
8f6b9e
+3:	lqarx 10,0,4
8f6b9e
+#ifdef	__BIG_ENDIAN__
8f6b9e
+	li 8,0
8f6b9e
+	li 9,2
8f6b9e
+	mr 5,10
8f6b9e
+	xor 10,11,7
8f6b9e
+	xor 5,5,6
8f6b9e
+	or. 4,5,10
8f6b9e
+	bne 4f
8f6b9e
+	addi 10,1,-16
8f6b9e
+	stqcx. 8,0,10
8f6b9e
+#else
8f6b9e
+	xor 9,11,8
8f6b9e
+	mr 6,11
8f6b9e
+	xor 11,10,3
8f6b9e
+	or. 0,9,11
8f6b9e
+	bne 4f
8f6b9e
+	li 14,0
8f6b9e
+	li 15,2
8f6b9e
+	stqcx. 14,0,4
8f6b9e
+#endif
8f6b9e
+	bne 3b
8f6b9e
+
8f6b9e
+4:	li	3,0
8f6b9e
+	blr
8f6b9e
+
8f6b9e
+#if _CALL_ELF == 2
8f6b9e
+	.size test_atomic_sequences,.-test_atomic_sequences
8f6b9e
+#else
8f6b9e
+	.size .test_atomic_sequences,.-.test_atomic_sequences
8f6b9e
+#endif
8f6b9e
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/ppc64-isa207-atomic-inst.c
8f6b9e
===================================================================
8f6b9e
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
8f6b9e
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/ppc64-isa207-atomic-inst.c	2017-08-29 21:41:50.528498600 +0200
8f6b9e
@@ -0,0 +1,42 @@
8f6b9e
+/* Copyright 2017 Free Software Foundation, Inc.
8f6b9e
+
8f6b9e
+   This file is part of GDB.
8f6b9e
+
8f6b9e
+   This program is free software; you can redistribute it and/or modify
8f6b9e
+   it under the terms of the GNU General Public License as published by
8f6b9e
+   the Free Software Foundation; either version 3 of the License, or
8f6b9e
+   (at your option) any later version.
8f6b9e
+
8f6b9e
+   This program is distributed in the hope that it will be useful,
8f6b9e
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
8f6b9e
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8f6b9e
+   GNU General Public License for more details.
8f6b9e
+
8f6b9e
+   You should have received a copy of the GNU General Public License
8f6b9e
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
8f6b9e
+
8f6b9e
+#include <elf.h>
8f6b9e
+
8f6b9e
+typedef Elf64_auxv_t auxv_t;
8f6b9e
+
8f6b9e
+#ifndef PPC_FEATURE2_ARCH_2_07
8f6b9e
+#define PPC_FEATURE2_ARCH_2_07	0x80000000
8f6b9e
+#endif
8f6b9e
+
8f6b9e
+extern void test_atomic_sequences (void);
8f6b9e
+
8f6b9e
+int
8f6b9e
+main (int argc, char *argv[], char *envp[], auxv_t auxv[])
8f6b9e
+{
8f6b9e
+  int i;
8f6b9e
+
8f6b9e
+  for (i = 0; auxv[i].a_type != AT_NULL; i++)
8f6b9e
+    if (auxv[i].a_type == AT_HWCAP2) {
8f6b9e
+      if (!(auxv[i].a_un.a_val & PPC_FEATURE2_ARCH_2_07))
8f6b9e
+        return 1;
8f6b9e
+      break;
8f6b9e
+    }
8f6b9e
+
8f6b9e
+  test_atomic_sequences ();
8f6b9e
+  return 0;
8f6b9e
+}
8f6b9e
Index: gdb-7.6.1/gdb/testsuite/gdb.arch/ppc64-isa207-atomic-inst.exp
8f6b9e
===================================================================
8f6b9e
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
8f6b9e
+++ gdb-7.6.1/gdb/testsuite/gdb.arch/ppc64-isa207-atomic-inst.exp	2017-08-29 21:41:50.528498600 +0200
8f6b9e
@@ -0,0 +1,99 @@
8f6b9e
+# Copyright 2017 Free Software Foundation, Inc.
8f6b9e
+#
8f6b9e
+# This program is free software; you can redistribute it and/or modify
8f6b9e
+# it under the terms of the GNU General Public License as published by
8f6b9e
+# the Free Software Foundation; either version 3 of the License, or
8f6b9e
+# (at your option) any later version.
8f6b9e
+#
8f6b9e
+# This program is distributed in the hope that it will be useful,
8f6b9e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
8f6b9e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8f6b9e
+# GNU General Public License for more details.
8f6b9e
+#
8f6b9e
+# You should have received a copy of the GNU General Public License
8f6b9e
+# along with this program; if not, write to the Free Software
8f6b9e
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
8f6b9e
+#
8f6b9e
+# This file is part of the gdb testsuite.
8f6b9e
+
8f6b9e
+# Test single stepping through POWER8/ISA 2.07 atomic sequences beginning with
8f6b9e
+# a lbarx/lharx/lqarx instruction and ending with a stbcx/sthcx/stqxc
8f6b9e
+# instruction.  Note that although lbarx, lharx, stbcx and sthcx instructions
8f6b9e
+# were introduced in ISA 2.06, they were implemented only in POWER8 (ISA 2.07).
8f6b9e
+
8f6b9e
+
8f6b9e
+if {![istarget "powerpc*"] || ![is_lp64_target]} {
8f6b9e
+    untested "skipping powerpc isa 207 atomic sequences test"
8f6b9e
+    return
8f6b9e
+}
8f6b9e
+
8f6b9e
+standard_testfile  .c .S
8f6b9e
+
8f6b9e
+if { [prepare_for_testing "failed to prepare" $testfile "$srcfile $srcfile2" \
8f6b9e
+      {debug quiet}] } {
8f6b9e
+    return -1
8f6b9e
+}
8f6b9e
+
8f6b9e
+# The test proper.  DISPLACED is true if we should try with displaced
8f6b9e
+# stepping.
8f6b9e
+
8f6b9e
+proc do_test { displaced } {
8f6b9e
+    global decimal hex
8f6b9e
+    global gdb_prompt inferior_exited_re srcfile srcfile2
8f6b9e
+
8f6b9e
+    if ![runto_main] then {
8f6b9e
+	untested "could not run to main"
8f6b9e
+	return -1
8f6b9e
+    }
8f6b9e
+
8f6b9e
+    gdb_test_no_output "set displaced-stepping $displaced"
8f6b9e
+
8f6b9e
+    gdb_breakpoint "test_atomic_sequences" "Breakpoint $decimal at $hex" \
8f6b9e
+	"set the breakpoint at the start of the test function"
8f6b9e
+
8f6b9e
+    gdb_test_multiple "continue" "Continue until lbarx/stbcx start breakpoint" {
8f6b9e
+      -re "$inferior_exited_re with code 01.\[\r\n\]+$gdb_prompt $" {
8f6b9e
+	unsupported "POWER8/ISA 2.07 atomic instructions not supported."
8f6b9e
+	return -1
8f6b9e
+      }
8f6b9e
+      -re "Continuing.*Breakpoint $decimal.*$gdb_prompt $" {
8f6b9e
+	pass "continue until test_atomic_sequences function"
8f6b9e
+      }
8f6b9e
+    }
8f6b9e
+
8f6b9e
+    set bp1 [gdb_get_line_number "lbarx" "$srcfile2"]
8f6b9e
+    gdb_breakpoint "$bp1" "Breakpoint $decimal at $hex" \
8f6b9e
+	"set the breakpoint at the start of the lbarx/stbcx sequence"
8f6b9e
+
8f6b9e
+    set bp2 [gdb_get_line_number "lharx" "$srcfile2"]
8f6b9e
+    gdb_breakpoint "$bp2" "Breakpoint $decimal at $hex" \
8f6b9e
+	"set the breakpoint at the start of the lharx/sthcx sequence"
8f6b9e
+
8f6b9e
+    set bp3 [gdb_get_line_number "lqarx" "$srcfile2"]
8f6b9e
+    gdb_breakpoint "$bp3" "Breakpoint $decimal at $hex" \
8f6b9e
+	"set the breakpoint at the start of the lqarx/stqcx sequence"
8f6b9e
+
8f6b9e
+    gdb_test continue "Continuing.*Breakpoint $decimal.*" \
8f6b9e
+	"continue until lbarx/stbcx start breakpoint"
8f6b9e
+
8f6b9e
+    gdb_test nexti "bne.*1b" \
8f6b9e
+	"step through the lbarx/stbcx sequence"
8f6b9e
+
8f6b9e
+    gdb_test continue "Continuing.*Breakpoint $decimal.*" \
8f6b9e
+	"continue until lharx/sthcx start breakpoint"
8f6b9e
+
8f6b9e
+    gdb_test nexti "bne.*2b" \
8f6b9e
+	"step through the lharx/sthcx sequence"
8f6b9e
+
8f6b9e
+    gdb_test continue "Continuing.*Breakpoint $decimal.*" \
8f6b9e
+	"continue until ldqrx/stqcx start breakpoint"
8f6b9e
+
8f6b9e
+    gdb_test nexti "bne.*3b" \
8f6b9e
+	"step through the lqarx/stqcx sequence"
8f6b9e
+}
8f6b9e
+
8f6b9e
+foreach displaced { "off" "on" } {
8f6b9e
+    with_test_prefix "displaced=$displaced" {
8f6b9e
+	do_test $displaced
8f6b9e
+    }
8f6b9e
+}