/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2020 Brandon Bergren <[email protected]>4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#include <machine/asm.h>2829/**30* int openfirmware_trampoline(void *buf, int (*cb)(void *));31*/32ASENTRY_NOPROF(openfirmware_trampoline)33mflr %r034stw %r0, 4(%r1)35stwu %r1, -16(%r1)36stw %r30, 8(%r1)37/* Save current MSR for restoration post-call. */38mfmsr %r3039mr %r5, %r3040/* Remove LE bit from MSR. */41clrrwi %r5, %r5, 142mtsrr0 %r443mtsrr1 %r544LOAD_LR_NIA451:46mflr %r447addi %r4, %r4, (2f - 1b)48mtlr %r449/* Switch to BE and transfer control to OF entry */50rfid512:52/* Control is returned here, but in BE. */53.long 0x05009f42 /* LOAD_LR_NIA */54/* 0: */55.long 0xa603db7f /* mtsrr1 %r30 */56.long 0xa602c87f /* mflr %r30 */57.long 0x1400de3b /* addi %r30, %r30, (1f - 0b) */58.long 0xa603da7f /* mtsrr0 %r30 */59.long 0x2400004c /* rfid */60/* 1: */611:62/* Back to normal. Tidy up for return. */63lwz %r30, 8(%r1)64lwz %r0, 20(%r1)65addi %r1, %r1, 1666mtlr %r067blr68ASEND(openfirmware_trampoline)697071