/*
 * Copyright 2021 Google Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met: redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer;
 * redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution;
 * neither the name of the copyright holders nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __ARCH_SPARC_PSEUDO_INST_ABI_HH__
#define __ARCH_SPARC_PSEUDO_INST_ABI_HH__

#include "arch/sparc/regs/int.hh"
#include "cpu/thread_context.hh"
#include "sim/guest_abi.hh"

struct SparcPseudoInstABI
{
    using State = int;
};

GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi);
namespace guest_abi
{

template <typename T>
struct Result<SparcPseudoInstABI, T>
{
    static void
    store(ThreadContext *tc, const T &ret)
    {
        // This assumes that all pseudo ops have their return value set
        // by the pseudo op instruction. This may need to be revisited if we
        // modify the pseudo op ABI in util/m5/m5op_x86.S
        tc->setIntReg(SparcISA::INTREG_O0, ret);
    }
};

template <>
struct Argument<SparcPseudoInstABI, uint64_t>
{
    static uint64_t
    get(ThreadContext *tc, SparcPseudoInstABI::State &state)
    {
        panic_if(state >= 6, "Too many psuedo inst arguments.");
        return tc->readIntReg(SparcISA::INTREG_O0 + state++);
    }
};

} // namespace guest_abi

#endif // __ARCH_SPARC_PSEUDO_INST_ABI_HH__
