14120SN/A/*
25417SN/A * Copyright (c) 2007-2008 The Hewlett-Packard Development Company
34120SN/A * All rights reserved.
44120SN/A *
57087SN/A * The license below extends only to copyright in the software and shall
67087SN/A * not be construed as granting a license to any other intellectual
77087SN/A * property including but not limited to intellectual property relating
87087SN/A * to a hardware implementation of the functionality of the software
97087SN/A * licensed hereunder.  You may use the software subject to the license
107087SN/A * terms below provided that you ensure that this notice is replicated
117087SN/A * unmodified and in its entirety in all distributions of the software,
127087SN/A * modified or unmodified, in source code or in binary form.
134120SN/A *
147087SN/A * Redistribution and use in source and binary forms, with or without
157087SN/A * modification, are permitted provided that the following conditions are
167087SN/A * met: redistributions of source code must retain the above copyright
177087SN/A * notice, this list of conditions and the following disclaimer;
187087SN/A * redistributions in binary form must reproduce the above copyright
197087SN/A * notice, this list of conditions and the following disclaimer in the
207087SN/A * documentation and/or other materials provided with the distribution;
217087SN/A * neither the name of the copyright holders nor the names of its
224120SN/A * contributors may be used to endorse or promote products derived from
237087SN/A * this software without specific prior written permission.
244120SN/A *
254120SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
264120SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
274120SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
284120SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
294120SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
304120SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
314120SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
324120SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
334120SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
344120SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
354120SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
364120SN/A *
374120SN/A * Authors: Gabe Black
384120SN/A */
394120SN/A
408105Sgblack@eecs.umich.edu#ifndef __ARCH_X86_MMAPPEDIPR_HH__
418105Sgblack@eecs.umich.edu#define __ARCH_X86_MMAPPEDIPR_HH__
424120SN/A
434152SN/A/**
444152SN/A * @file
454152SN/A *
464152SN/A * ISA-specific helper functions for memory mapped IPR accesses.
474152SN/A */
484152SN/A
499897Sandreas@sandberg.pp.se#include "arch/generic/mmapped_ipr.hh"
507629SN/A#include "arch/x86/regs/misc.hh"
515182SN/A#include "cpu/base.hh"
524152SN/A#include "cpu/thread_context.hh"
534152SN/A#include "mem/packet.hh"
544120SN/A
554120SN/Anamespace X86ISA
564120SN/A{
579180Sandreas.hansson@arm.com    inline Cycles
584152SN/A    handleIprRead(ThreadContext *xc, Packet *pkt)
594152SN/A    {
609897Sandreas@sandberg.pp.se        if (GenericISA::isGenericIprAccess(pkt)) {
619897Sandreas@sandberg.pp.se            return GenericISA::handleGenericIprRead(xc, pkt);
629897Sandreas@sandberg.pp.se        } else {
639897Sandreas@sandberg.pp.se            Addr offset = pkt->getAddr() & mask(3);
649897Sandreas@sandberg.pp.se            MiscRegIndex index = (MiscRegIndex)(
6513613Sgabeblack@google.com                pkt->getAddr() / sizeof(RegVal));
6613613Sgabeblack@google.com            RegVal data = htog(xc->readMiscReg(index));
679897Sandreas@sandberg.pp.se            // Make sure we don't trot off the end of data.
6813613Sgabeblack@google.com            assert(offset + pkt->getSize() <= sizeof(RegVal));
699897Sandreas@sandberg.pp.se            pkt->setData(((uint8_t *)&data) + offset);
709897Sandreas@sandberg.pp.se            return Cycles(1);
719897Sandreas@sandberg.pp.se        }
724152SN/A    }
734152SN/A
749180Sandreas.hansson@arm.com    inline Cycles
754152SN/A    handleIprWrite(ThreadContext *xc, Packet *pkt)
764152SN/A    {
779897Sandreas@sandberg.pp.se        if (GenericISA::isGenericIprAccess(pkt)) {
789897Sandreas@sandberg.pp.se            return GenericISA::handleGenericIprWrite(xc, pkt);
799897Sandreas@sandberg.pp.se        } else {
809897Sandreas@sandberg.pp.se            Addr offset = pkt->getAddr() & mask(3);
819897Sandreas@sandberg.pp.se            MiscRegIndex index = (MiscRegIndex)(
8213613Sgabeblack@google.com                pkt->getAddr() / sizeof(RegVal));
8313613Sgabeblack@google.com            RegVal data = htog(xc->readMiscRegNoEffect(index));
849897Sandreas@sandberg.pp.se            // Make sure we don't trot off the end of data.
8513613Sgabeblack@google.com            assert(offset + pkt->getSize() <= sizeof(RegVal));
869897Sandreas@sandberg.pp.se            pkt->writeData(((uint8_t *)&data) + offset);
879897Sandreas@sandberg.pp.se            xc->setMiscReg(index, gtoh(data));
889897Sandreas@sandberg.pp.se            return Cycles(1);
899897Sandreas@sandberg.pp.se        }
904152SN/A    }
918902Sandreas.hansson@arm.com}
924120SN/A
938105Sgblack@eecs.umich.edu#endif // __ARCH_X86_MMAPPEDIPR_HH__
94