/*-1* Copyright (C) 2015 Nathan Whitehorn2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR14* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES15* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,17* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,18* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;19* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,20* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR21* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF22* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.23*/2425#include <machine/asm.h>2627#include "opt_platform.h"2829GLOBAL(opal_entrypoint)30.llong 031GLOBAL(opal_data)32.llong 033GLOBAL(opal_msr)34.llong 03536TOC_ENTRY(opal_entrypoint)37TOC_ENTRY(opal_data)38TOC_ENTRY(opal_msr)3940ASENTRY(opal_call)41/* Args:42* r3: opal token43* r4-r10 opal arguments44*/4546/* Save call stuff on stack */47mflr %r048std %r0,16(%r1)49std %r2,-16(%r1)50mfcr %r051std %r0,8(%r1)5253/* Load OPAL entry information */54mr %r0,%r355addis %r3,%r2,TOC_REF(opal_entrypoint)@ha56ld %r3,TOC_REF(opal_entrypoint)@l(%r3)57ld %r3,0(%r3)58mtctr %r35960/* Save MSR in non-volatile scratch register and turn off translation */61std %r31,-8(%r1)62mfmsr %r316364/* Load last bits from the TOC */65addis %r3,%r2,TOC_REF(opal_msr)@ha66ld %r3,TOC_REF(opal_msr)@l(%r3)67ld %r3,0(%r3)68addis %r2,%r2,TOC_REF(opal_data)@ha69ld %r2,TOC_REF(opal_data)@l(%r2)70ld %r2,0(%r2)717273#if defined(__LITTLE_ENDIAN__) && defined(QEMU)74/* QEMU hack: qemu does not emulate mtmsrd correctly! */75ori %r3,%r3,1 /* Leave PSR_LE set */76#endif77mtmsrd %r378isync79#if defined(__LITTLE_ENDIAN__) && defined(QEMU)80/* Clean up from qemu hack */81xori %r3,%r3,182#endif8384#ifdef __LITTLE_ENDIAN__85mtsrr1 %r386#endif8788/* Shift registers over */89mr %r3,%r490mr %r4,%r591mr %r5,%r692mr %r6,%r793mr %r7,%r894mr %r8,%r995mr %r9,%r109697#ifdef __LITTLE_ENDIAN__98/* We need to rfid to switch endian. */99mfctr %r11100mtsrr0 %r11101LOAD_LR_NIA1021:103mflr %r11104addi %r11, %r11, (2f-1b)105mtlr %r11106/* Call OPAL */107rfid1082:109RETURN_TO_NATIVE_ENDIAN110#else111/* Call OPAL */112bctrl113#endif114115/* Restore MSR */116mtmsrd %r31117isync118ld %r31,-8(%r1)119120/* Restore call stuff from stack */121ld %r0,16(%r1)122mtlr %r0123ld %r2,-16(%r1)124ld %r0,8(%r1)125mtcr %r0126127/* And return */128blr129ASEND(opal_call)130131132