OSDN Git Service

powerpc/lib: Add alt patching test of branching past the last instruction
authorMichael Ellerman <mpe@ellerman.id.au>
Mon, 16 Apr 2018 14:39:05 +0000 (00:39 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 11 May 2018 13:29:03 +0000 (23:29 +1000)
Add a test of the relative branch patching logic in the alternate
section feature fixup code. This tests that if we branch past the last
instruction of the alternate section, the branch is not patched.
That's because the assembler will have created a branch that already
points to the first instruction after the patched section, which is
correct and needs no further patching.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/lib/feature-fixups-test.S
arch/powerpc/lib/feature-fixups.c

index dd05afc..f16cec9 100644 (file)
@@ -171,6 +171,42 @@ globl(ftr_fixup_test6_expected)
        or      2,2,2
        or      3,3,3
 
+globl(ftr_fixup_test7)
+       or      1,1,1
+BEGIN_FTR_SECTION
+       or      2,2,2
+       or      2,2,2
+       or      2,2,2
+       or      2,2,2
+       or      2,2,2
+       or      2,2,2
+       or      2,2,2
+FTR_SECTION_ELSE
+2:     b       3f
+3:     or      5,5,5
+       beq     3b
+       b       1f
+       or      6,6,6
+       b       2b
+       bdnz    3b
+1:
+ALT_FTR_SECTION_END(0, 1)
+       or      1,1,1
+       or      1,1,1
+
+globl(end_ftr_fixup_test7)
+       nop
+
+globl(ftr_fixup_test7_expected)
+       or      1,1,1
+2:     b       3f
+3:     or      5,5,5
+       beq     3b
+       b       1f
+       or      6,6,6
+       b       2b
+       bdnz    3b
+1:     or      1,1,1
 
 #if 0
 /* Test that if we have a larger else case the assembler spots it and
index 097b45b..f3e46d4 100644 (file)
@@ -425,6 +425,16 @@ static void test_alternative_case_with_external_branch(void)
        check(memcmp(ftr_fixup_test6, ftr_fixup_test6_expected, size) == 0);
 }
 
+static void test_alternative_case_with_branch_to_end(void)
+{
+       extern unsigned int ftr_fixup_test7[];
+       extern unsigned int end_ftr_fixup_test7[];
+       extern unsigned int ftr_fixup_test7_expected[];
+       int size = 4 * (end_ftr_fixup_test7 - ftr_fixup_test7);
+
+       check(memcmp(ftr_fixup_test7, ftr_fixup_test7_expected, size) == 0);
+}
+
 static void test_cpu_macros(void)
 {
        extern u8 ftr_fixup_test_FTR_macros[];
@@ -480,6 +490,7 @@ static int __init test_feature_fixups(void)
        test_alternative_case_too_small();
        test_alternative_case_with_branch();
        test_alternative_case_with_external_branch();
+       test_alternative_case_with_branch_to_end();
        test_cpu_macros();
        test_fw_macros();
        test_lwsync_macros();