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