xref: /kvm-unit-tests/lib/ppc64/opal-calls.S (revision dc0a3a769728a3345b0fc6d9c29bc62ab3ae1587)
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Copyright (c) 2016 IBM Corporation.
4 */
5
6#include <asm/ppc_asm.h>
7
8	.text
9	.globl opal_call
10opal_call:
11	mr	r0,r3
12	mr	r3,r4
13	mr	r4,r5
14	mr	r5,r6
15	mr	r6,r7
16	mflr	r11
17	std	r11,16(r1)
18	mfcr	r12
19	stw	r12,8(r1)
20	std	r2,-8(r1) /* use redzone */
21
22	/* Set opal return address */
23	LOAD_REG_ADDR(r11, opal_return)
24	mtlr	r11
25	mfmsr	r12
26	std	r12,-16(r1) /* use redzone */
27
28	/* switch to BE and real-mode when we enter OPAL */
29	li	r11,(1 << MSR_LE_BIT) | MSR_IR | MSR_DR
30	ori	r11,r11,(1 << MSR_EE_BIT)
31	andc	r12,r12,r11
32	mtspr	SPR_HSRR1,r12
33
34	/* load the opal call entry point and base */
35	LOAD_REG_ADDR(r11, opal)
36	ld	r12,8(r11)
37	ld	r2,0(r11)
38	mtspr	SPR_HSRR0,r12
39	hrfid
40
41opal_return:
42	FIXUP_ENDIAN
43	ld	r12,-16(r1) /* use redzone */
44	mtmsrd	r12
45	ld	r2,-8(r1) /* use redzone */
46	lwz	r11,8(r1);
47	ld	r12,16(r1)
48	mtcr	r11;
49	mtlr	r12
50	blr
51