1/* SPDX-License-Identifier: GPL-2.0 */
2#include "common.h"
3
4	.data
5	.balign 8
6success_message:
7	.ascii "success: switch_endian_test\n\0"
8
9	.balign 8
10failure_message:
11	.ascii "failure: switch_endian_test\n\0"
12
13	.section ".toc"
14	.balign 8
15pattern:
16	.8byte 0x5555AAAA5555AAAA
17
18	.text
19FUNC_START(_start)
20	/* Load the pattern */
21	ld	r15, pattern@TOC(%r2)
22
23	/* Setup CR, only CR2-CR4 are maintained */
24	lis	r3, 0x00FF
25	ori	r3, r3, 0xF000
26	mtcr	r3
27
28	/* Load the pattern slightly modified into the registers */
29	mr	r3, r15
30	addi	r4, r15, 4
31
32	addi	r5, r15, 32
33	mtlr	r5
34
35	addi	r5, r15, 5
36	addi	r6, r15, 6
37	addi	r7, r15, 7
38	addi	r8, r15, 8
39
40	/* r9 - r12 are clobbered */
41
42	addi	r13, r15, 13
43	addi	r14, r15, 14
44
45	/* Skip r15 we're using it */
46
47	addi	r16, r15, 16
48	addi	r17, r15, 17
49	addi	r18, r15, 18
50	addi	r19, r15, 19
51	addi	r20, r15, 20
52	addi	r21, r15, 21
53	addi	r22, r15, 22
54	addi	r23, r15, 23
55	addi	r24, r15, 24
56	addi	r25, r15, 25
57	addi	r26, r15, 26
58	addi	r27, r15, 27
59	addi	r28, r15, 28
60	addi	r29, r15, 29
61	addi	r30, r15, 30
62	addi	r31, r15, 31
63
64	/*
65	 * Call the syscall to switch endian.
66	 * It clobbers r9-r12, XER, CTR and CR0-1,5-7.
67	 */
68	li r0, __NR_switch_endian
69	sc
70
71	tdi   0, 0, 0x48	// b +8 if the endian was switched
72	b     .Lfail	  	// exit if endian didn't switch
73
74#include "check-reversed.S"
75
76	/* Flip back, r0 already has the switch syscall number */
77	.long	0x02000044	/* sc */
78
79#include "check.S"
80
81	ld	r4, success_message@got(%r2)
82	li	r5, 28	// strlen(success_message)
83	li	r14, 0	// exit status
84.Lout:
85	li	r0, __NR_write
86	li	r3, 1	/* stdout */
87	sc
88	li      r0, __NR_exit
89	mr	r3, r14
90	sc
91	b       .
92
93.Lfail:
94	ld	r4, failure_message@got(%r2)
95	li	r5, 28	// strlen(failure_message)
96	li	r14, 1
97	b	.Lout
98