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