xref: /freebsd/stand/powerpc/ofw/trampolineLE.S (revision 4e8d558c)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2020 Brandon Bergren <bdragon@FreeBSD.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD$
28 */
29
30#include <machine/asm.h>
31
32/**
33 * int openfirmware_trampoline(void *buf, int (*cb)(void *));
34 */
35ASENTRY_NOPROF(openfirmware_trampoline)
36	mflr	%r0
37	stw	%r0, 4(%r1)
38	stwu	%r1, -16(%r1)
39	stw	%r30, 8(%r1)
40	/* Save current MSR for restoration post-call. */
41	mfmsr	%r30
42	mr	%r5, %r30
43	/* Remove LE bit from MSR. */
44	clrrwi	%r5, %r5, 1
45	mtsrr0	%r4
46	mtsrr1	%r5
47	LOAD_LR_NIA
481:
49	mflr	%r4
50	addi	%r4, %r4, (2f - 1b)
51	mtlr	%r4
52	/* Switch to BE and transfer control to OF entry */
53	rfid
542:
55	/* Control is returned here, but in BE. */
56	.long	0x05009f42	/* LOAD_LR_NIA				*/
57				/* 0:					*/
58	.long	0xa603db7f	/* mtsrr1 	%r30			*/
59	.long	0xa602c87f	/* mflr		%r30			*/
60	.long	0x1400de3b	/* addi		%r30, %r30, (1f - 0b)	*/
61	.long	0xa603da7f	/* mtsrr0	%r30			*/
62	.long	0x2400004c	/* rfid					*/
63				/* 1:					*/
641:
65	/* Back to normal. Tidy up for return. */
66	lwz	%r30, 8(%r1)
67	lwz	%r0, 20(%r1)
68	addi	%r1, %r1, 16
69	mtlr	%r0
70	blr
71ASEND(openfirmware_trampoline)
72