From a63e9c28b53f20ce1c4bdc0b81da59957a17f4f0 Mon Sep 17 00:00:00 2001 From: Tulio Magno Quites Machado Filho Date: Fri, 20 Aug 2021 19:07:09 -0300 Subject: [PATCH] powerpc: Add .machine directives for scv, copy, paste, cpabort instructions GCC is no longer passing the "-many" flag to the assembler. So, the inline assembly instructions statements need to use the .machine directives for the specific platform. (gcc commit e154242724b084380e3221df7c08fcdbd8460674 ; "[RS6000] Don't pass -many to the assembler". Hardware sync instruction (hwsync) added after the copy, paste and cpabort instructions to improve the reliability of the test. --- Makefile.all.am | 4 ++-- VEX/priv/guest_ppc_helpers.c | 15 ++++++++++++--- coregrind/m_syscall.c | 4 ++++ none/tests/ppc64/Makefile.am | 4 ++-- none/tests/ppc64/test_copy_paste.c | 25 ++++++++++++++++++------- 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Makefile.all.am b/Makefile.all.am index 1b66f82ea4..06b23c99e0 100644 --- a/Makefile.all.am +++ b/Makefile.all.am @@ -126,9 +126,9 @@ AM_CFLAGS_BASE = \ # Power ISA flag for use by guest_ppc_helpers.c if HAS_XSCVHPDP if HAS_DARN -ISA_3_0_BUILD_FLAG = -DHAS_XSCVHPDP -DHAS_DARN +ISA_3_0_BUILD_FLAG = -DHAS_XSCVHPDP -DHAS_DARN -DHAS_ISA_3_00 else -ISA_3_0_BUILD_FLAG = -DHAS_XSCVHPDP +ISA_3_0_BUILD_FLAG = -DHAS_XSCVHPDP -DHAS_ISA_3_00 endif else ISA_3_0_BUILD_FLAG = diff --git a/VEX/priv/guest_ppc_helpers.c b/VEX/priv/guest_ppc_helpers.c index 87f094c670..689aa8f34e 100644 --- a/VEX/priv/guest_ppc_helpers.c +++ b/VEX/priv/guest_ppc_helpers.c @@ -3170,13 +3170,22 @@ UInt copy_paste_abort_dirty_helper(UInt addr, UInt op) { UInt cr; if (op == COPY_INST) - __asm__ __volatile__ ("copy 0,%0" :: "r" (addr)); + __asm__ __volatile__ (".machine push;\n" + ".machine power9;\n" + "copy 0,%0;\n" + ".machine pop" :: "r" (addr)); else if (op == PASTE_INST) - __asm__ __volatile__ ("paste. 0,%0" :: "r" (addr)); + __asm__ __volatile__ (".machine push;\n" + ".machine power9;\n" + "paste. 0,%0\n" + ".machine pop" :: "r" (addr)); else if (op == CPABORT_INST) - __asm__ __volatile__ ("cpabort"); + __asm__ __volatile__ (".machine push;\n" + ".machine power9;\n" + "cpabort\n" + ".machine pop"); else /* Unknown operation */ diff --git a/coregrind/m_syscall.c b/coregrind/m_syscall.c index 80e2af4397..c12632d366 100644 --- a/coregrind/m_syscall.c +++ b/coregrind/m_syscall.c @@ -599,7 +599,11 @@ asm( " ld 4, 16(3)\n" /* sc arg 2 */ " ld 0, 0(3)\n" /* sc number */ " ld 3, 8(3)\n" /* sc arg 1 */ + +" .machine push\n" +" .machine \"power9\"\n" " scv 0\n" +" .machine pop\n" " ld 5,-16(1)\n" /* reacquire argblock ptr (r5 is caller-save) */ " std 3,0(5)\n" /* argblock[0] = r3 */ diff --git a/none/tests/ppc64/Makefile.am b/none/tests/ppc64/Makefile.am index 9527cdf1e8..15e90ebfdb 100644 --- a/none/tests/ppc64/Makefile.am +++ b/none/tests/ppc64/Makefile.am @@ -218,8 +218,8 @@ test_isa_3_1_AT_CFLAGS = $(test_isa_3_1_CFLAGS) subnormal_test_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(VSX_FLAG) $(ISA_2_06_FLAG) \ @FLAG_M64@ $(ALTIVEC_FLAG) $(BUILD_FLAG_VSX) $(BUILD_FLAGS_ISA_2_06) -test_copy_paste_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(HTM_FLAG) $(ISA_3_00_FLAG) \ - @FLAG_M64@ $(BUILD_FLAGS_ISA_3_00) +test_copy_paste_CFLAGS = $(AM_CFLAGS) -Winline -Wall -O -g -mregnames $(HTM_FLAG) $(ISA_3_1_FLAG) \ + @FLAG_M64@ $(BUILD_FLAGS_ISA_3_1) test_isa_2_06_part3_LDADD = -lm test_dfp1_LDADD = -lm diff --git a/none/tests/ppc64/test_copy_paste.c b/none/tests/ppc64/test_copy_paste.c index dc5f42c1a0..339ff8b6f7 100644 --- a/none/tests/ppc64/test_copy_paste.c +++ b/none/tests/ppc64/test_copy_paste.c @@ -1,5 +1,9 @@ /* The copy, paste, cpabort are ISA 3.0 instructions. However, the memory - to memory copy is only supported on ISA 3.1 era machines. */ + to memory copy is only supported on ISA 3.1 era machines. + + The following test does a memory to memory copy test, an out of order + paste test, and a copy paste abort test. This test is only supported + ISA 3.1 systems. */ #include #include @@ -7,7 +11,7 @@ #include #include -#ifdef HAS_ISA_3_00 +#ifdef HAS_ISA_3_1 #include /* return CR0 in least significant bits */ @@ -17,17 +21,20 @@ void test_copy (uint8_t *reg) { - __asm__ __volatile__ ("copy 0,%0" : : "r" (reg)); + __asm__ __volatile__ (".machine push; .machine power9; " \ + "copy 0,%0; hwsync; .machine pop;" : : "r" (reg)); } void test_paste (uint8_t *reg) { - __asm__ __volatile__ ("paste. 0,%0" : : "r" (reg)); + __asm__ __volatile__ (".machine push; .machine power9; " \ + "paste. 0,%0; hwsync; .machine pop;" : : "r" (reg)); } void test_cpabort (void) { - __asm__ __volatile__ ("cpabort"); + __asm__ __volatile__ (".machine push; .machine power9; " \ + "cpabort; hwsync; .machine pop;"); } #define NUM_ELEMENTS 128 @@ -39,7 +46,7 @@ void test_cpabort (void) int main() { -#ifdef HAS_ISA_3_00 +#ifdef HAS_ISA_3_1 int i; unsigned int cc_value; int result = SUCCESS; @@ -66,6 +73,10 @@ int main() test_paste (dst_buffer); GET_CR0(cc_value); +#if DEBUG + printf("CR0 = 0x%x\n", cc_value); +#endif + #if DEBUG printf("AFTER COPY/PASTE Contents of src/dst buffer\n"); for (i=0; i