Re: [PATCH v4 2/2] selftests/powerpc: Add a test of the switch_endian() syscall

2015-03-28 Thread Michael Ellerman
On Sat, 2015-03-28 at 10:17 +0100, Gabriel Paubert wrote:
> On Sat, Mar 28, 2015 at 12:19:10PM +1100, Michael Ellerman wrote:
> > This adds a test of the switch_endian() syscall we added in the previous
> > commit.

...

> > +
> > +   /* r9 - r12 are clobbered */
> > +
> > +   addir13, r15, 13
> > +   addir14, r15, 14
> > +
> > +   /* Skip r15 we're using it */
> > +
> > +   addir16, r15, 16
> > +   addir16, r15, 16
> 
> Duplicate?
 
Oh god damn it.

Yes :)

Thanks for reviewing.

cheers


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH v4 2/2] selftests/powerpc: Add a test of the switch_endian() syscall

2015-03-28 Thread Gabriel Paubert
On Sat, Mar 28, 2015 at 12:19:10PM +1100, Michael Ellerman wrote:
> This adds a test of the switch_endian() syscall we added in the previous
> commit.
> 
> We test it by calling the endian switch syscall, and then executing some
> code in the other endian to check everything went as expected. That code
> checks registers we expect to be maintained are. If the endian switch
> failed to happen that code sequence will be illegal and cause the test
> to abort.
> 
> We then switch back to the original endian, do the same checks and
> finally write a success message and exit(0).
> 
> Signed-off-by: Michael Ellerman 
> 
> ---
> v3: Have the test switch back to the original endian.
> v4: Add .gitignore.
> Drop the message write in the checking code - it clobbers some regs
> and breaks the second check.
> 
>  tools/testing/selftests/powerpc/Makefile   |  2 +-
>  .../selftests/powerpc/switch_endian/.gitignore |  2 +
>  .../selftests/powerpc/switch_endian/Makefile   | 23 +
>  .../selftests/powerpc/switch_endian/check.S| 98 
> ++
>  .../selftests/powerpc/switch_endian/common.h   |  6 ++
>  .../powerpc/switch_endian/switch_endian_test.S | 82 ++
>  6 files changed, 212 insertions(+), 1 deletion(-)
>  create mode 100644 tools/testing/selftests/powerpc/switch_endian/.gitignore
>  create mode 100644 tools/testing/selftests/powerpc/switch_endian/Makefile
>  create mode 100644 tools/testing/selftests/powerpc/switch_endian/check.S
>  create mode 100644 tools/testing/selftests/powerpc/switch_endian/common.h
>  create mode 100644 
> tools/testing/selftests/powerpc/switch_endian/switch_endian_test.S

[snipped]
> diff --git 
> a/tools/testing/selftests/powerpc/switch_endian/switch_endian_test.S 
> b/tools/testing/selftests/powerpc/switch_endian/switch_endian_test.S
> new file mode 100644
> index ..eee0e393600b
> --- /dev/null
> +++ b/tools/testing/selftests/powerpc/switch_endian/switch_endian_test.S
> @@ -0,0 +1,82 @@
> +#include "common.h"
> +
> + .data
> + .balign 8
> +message:
> + .ascii "success: switch_endian_test\n\0"
> +
> + .section ".toc"
> + .balign 8
> +pattern:
> + .llong 0x
> +
> + .text
> +FUNC_START(_start)
> + /* Load the pattern */
> + ld  r15, pattern@TOC(%r2)
> +
> + /* Setup CR, only CR2-CR4 are maintained */
> + lis r3, 0x00FF
> + ori r3, r3, 0xF000
> + mtcrr3
> +
> + /* Load the pattern slightly modified into the registers */
> + mr  r3, r15
> + addir4, r15, 4
> +
> + addir5, r15, 32
> + mtlrr5
> +
> + addir5, r15, 5
> + addir6, r15, 6
> + addir7, r15, 7
> + addir8, r15, 8
> +
> + /* r9 - r12 are clobbered */
> +
> + addir13, r15, 13
> + addir14, r15, 14
> +
> + /* Skip r15 we're using it */
> +
> + addir16, r15, 16
> + addir16, r15, 16

Duplicate?


> + addir17, r15, 17
> + addir18, r15, 18
> + addir19, r15, 19
> + addir20, r15, 20
> + addir21, r15, 21
> + addir22, r15, 22
> + addir23, r15, 23
> + addir24, r15, 24
> + addir25, r15, 25
> + addir26, r15, 26
> + addir27, r15, 27
> + addir28, r15, 28
> + addir29, r15, 29
> + addir30, r15, 30
> + addir31, r15, 31
> +
> + /*
> +  * Call the syscall to switch endian.
> +  * It clobbers r9-r12, XER, CTR and CR0-1,5-7.
> +  */
> + li r0, __NR_switch_endian
> + sc
> +
> +#include "check-reversed.S"
> +
> + /* Flip back, r0 already has the switch syscall number */
> + .long   0x0244  /* sc */
> +
> +#include "check.S"
> +
> + li  r0, __NR_write
> + li  r3, 1   /* stdout */
> + ld  r4, message@got(%r2)
> + li  r5, 28  /* strlen(message3) */
> + sc
> + li  r0, __NR_exit
> + li  r3, 0
> + sc
> + b   .
> -- 
> 2.1.0

Gabriel
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH v4 2/2] selftests/powerpc: Add a test of the switch_endian() syscall

2015-03-27 Thread Michael Ellerman
This adds a test of the switch_endian() syscall we added in the previous
commit.

We test it by calling the endian switch syscall, and then executing some
code in the other endian to check everything went as expected. That code
checks registers we expect to be maintained are. If the endian switch
failed to happen that code sequence will be illegal and cause the test
to abort.

We then switch back to the original endian, do the same checks and
finally write a success message and exit(0).

Signed-off-by: Michael Ellerman 

---
v3: Have the test switch back to the original endian.
v4: Add .gitignore.
Drop the message write in the checking code - it clobbers some regs
and breaks the second check.

 tools/testing/selftests/powerpc/Makefile   |  2 +-
 .../selftests/powerpc/switch_endian/.gitignore |  2 +
 .../selftests/powerpc/switch_endian/Makefile   | 23 +
 .../selftests/powerpc/switch_endian/check.S| 98 ++
 .../selftests/powerpc/switch_endian/common.h   |  6 ++
 .../powerpc/switch_endian/switch_endian_test.S | 82 ++
 6 files changed, 212 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/switch_endian/.gitignore
 create mode 100644 tools/testing/selftests/powerpc/switch_endian/Makefile
 create mode 100644 tools/testing/selftests/powerpc/switch_endian/check.S
 create mode 100644 tools/testing/selftests/powerpc/switch_endian/common.h
 create mode 100644 
tools/testing/selftests/powerpc/switch_endian/switch_endian_test.S

diff --git a/tools/testing/selftests/powerpc/Makefile 
b/tools/testing/selftests/powerpc/Makefile
index 1d5e7ad2c460..85c24a2210b5 100644
--- a/tools/testing/selftests/powerpc/Makefile
+++ b/tools/testing/selftests/powerpc/Makefile
@@ -13,7 +13,7 @@ CFLAGS := -Wall -O2 -flto -Wall -Werror 
-DGIT_VERSION='"$(GIT_VERSION)"' -I$(CUR
 
 export CC CFLAGS
 
-TARGETS = pmu copyloops mm tm primitives stringloops
+TARGETS = pmu copyloops mm tm primitives stringloops switch_endian
 
 endif
 
diff --git a/tools/testing/selftests/powerpc/switch_endian/.gitignore 
b/tools/testing/selftests/powerpc/switch_endian/.gitignore
new file mode 100644
index ..89e762eab676
--- /dev/null
+++ b/tools/testing/selftests/powerpc/switch_endian/.gitignore
@@ -0,0 +1,2 @@
+switch_endian_test
+check-reversed.S
diff --git a/tools/testing/selftests/powerpc/switch_endian/Makefile 
b/tools/testing/selftests/powerpc/switch_endian/Makefile
new file mode 100644
index ..c7fefbf880b5
--- /dev/null
+++ b/tools/testing/selftests/powerpc/switch_endian/Makefile
@@ -0,0 +1,23 @@
+PROGS := switch_endian_test
+
+ASFLAGS += -O2 -Wall -g -nostdlib -m64
+
+all: $(PROGS)
+
+switch_endian_test: check-reversed.S
+
+check-reversed.o: check.o
+   objcopy -j .text --reverse-bytes=4 -O binary $< $@
+
+check-reversed.S: check-reversed.o
+   hexdump -v -e '/1 ".byte 0x%02X\n"' $< > $@
+
+run_tests: all
+   @-for PROG in $(PROGS); do \
+   ./$$PROG; \
+   done;
+
+clean:
+   rm -f $(PROGS) *.o check-reversed.S
+
+.PHONY: all run_tests clean
diff --git a/tools/testing/selftests/powerpc/switch_endian/check.S 
b/tools/testing/selftests/powerpc/switch_endian/check.S
new file mode 100644
index ..026bd151a16b
--- /dev/null
+++ b/tools/testing/selftests/powerpc/switch_endian/check.S
@@ -0,0 +1,98 @@
+#include "common.h"
+
+/*
+ * Checks that registers contain what we expect, ie. they were not clobbered by
+ * the syscall.
+ *
+ * r15: pattern to check registers against.
+ *
+ * At the end r3 == 0 if everything's OK.
+ */
+   nop # guaranteed to be illegal in reverse-endian
+   cmpdr15,r3  # check r3
+   bne 1f
+   addir9,r15,4# check r4
+   cmpdr9,r4
+   bne 1f
+   lis r9,0x00FF   # check CR
+   ori r9,r9,0xF000
+   mfcrr10
+   and r10,r10,r9
+   cmpwr9,r10
+   addir9,r15,34
+   bne 1f
+   addir9,r15,32   # check LR
+   mflrr10
+   cmpdr9,r10
+   bne 1f
+   addir9,r15,5# check r5
+   cmpdr9,r5
+   bne 1f
+   addir9,r15,6# check r6
+   cmpdr9,r6
+   bne 1f
+   addir9,r15,7# check r7
+   cmpdr9,r7
+   bne 1f
+   addir9,r15,8# check r8
+   cmpdr9,r8
+   bne 1f
+   addir9,r15,13   # check r13
+   cmpdr9,r13
+   bne 1f
+   addir9,r15,14   # check r14
+   cmpdr9,r14
+   bne 1f
+   addir9,r15,16   # check r16
+   cmpdr9,r16
+   bne 1f
+   addir9,r15,17   # check r17
+   cmpdr9,r17
+   bne 1f
+   addir9,r15,18   # check r18
+   cmpdr9,r18
+   bne 1f
+   addir9,r15,19   # check r19
+   cmpdr9,r19
+   bne 1f
+   addir9,r15,20