mmapped_ipr.hh revision 8902
112608Sjason@lowepower.com/*
212608Sjason@lowepower.com * Copyright (c) 2007-2008 The Hewlett-Packard Development Company
312608Sjason@lowepower.com * All rights reserved.
412608Sjason@lowepower.com *
512608Sjason@lowepower.com * The license below extends only to copyright in the software and shall
612608Sjason@lowepower.com * not be construed as granting a license to any other intellectual
712608Sjason@lowepower.com * property including but not limited to intellectual property relating
812608Sjason@lowepower.com * to a hardware implementation of the functionality of the software
912608Sjason@lowepower.com * licensed hereunder.  You may use the software subject to the license
1012608Sjason@lowepower.com * terms below provided that you ensure that this notice is replicated
1112608Sjason@lowepower.com * unmodified and in its entirety in all distributions of the software,
1212608Sjason@lowepower.com * modified or unmodified, in source code or in binary form.
1312608Sjason@lowepower.com *
1412608Sjason@lowepower.com * Redistribution and use in source and binary forms, with or without
1512608Sjason@lowepower.com * modification, are permitted provided that the following conditions are
1612608Sjason@lowepower.com * met: redistributions of source code must retain the above copyright
1712608Sjason@lowepower.com * notice, this list of conditions and the following disclaimer;
1812608Sjason@lowepower.com * redistributions in binary form must reproduce the above copyright
1912608Sjason@lowepower.com * notice, this list of conditions and the following disclaimer in the
2012608Sjason@lowepower.com * documentation and/or other materials provided with the distribution;
2112608Sjason@lowepower.com * neither the name of the copyright holders nor the names of its
2212608Sjason@lowepower.com * contributors may be used to endorse or promote products derived from
2312608Sjason@lowepower.com * this software without specific prior written permission.
2412608Sjason@lowepower.com *
2512608Sjason@lowepower.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2612608Sjason@lowepower.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2712608Sjason@lowepower.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2812608Sjason@lowepower.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2912608Sjason@lowepower.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3012608Sjason@lowepower.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3112608Sjason@lowepower.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3212608Sjason@lowepower.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3312608Sjason@lowepower.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3412608Sjason@lowepower.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3512608Sjason@lowepower.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3612608Sjason@lowepower.com *
3712608Sjason@lowepower.com * Authors: Gabe Black
3812608Sjason@lowepower.com */
3912608Sjason@lowepower.com
4012608Sjason@lowepower.com#ifndef __ARCH_X86_MMAPPEDIPR_HH__
4112608Sjason@lowepower.com#define __ARCH_X86_MMAPPEDIPR_HH__
4212608Sjason@lowepower.com
4312608Sjason@lowepower.com/**
4412608Sjason@lowepower.com * @file
4512608Sjason@lowepower.com *
4612608Sjason@lowepower.com * ISA-specific helper functions for memory mapped IPR accesses.
4712608Sjason@lowepower.com */
4812608Sjason@lowepower.com
4912608Sjason@lowepower.com#include "arch/x86/regs/misc.hh"
5012608Sjason@lowepower.com#include "cpu/base.hh"
5112608Sjason@lowepower.com#include "cpu/thread_context.hh"
5212608Sjason@lowepower.com#include "mem/packet.hh"
5312608Sjason@lowepower.com
5412608Sjason@lowepower.comnamespace X86ISA
5512608Sjason@lowepower.com{
5612608Sjason@lowepower.com    inline Tick
5712608Sjason@lowepower.com    handleIprRead(ThreadContext *xc, Packet *pkt)
5812608Sjason@lowepower.com    {
5912608Sjason@lowepower.com        Addr offset = pkt->getAddr() & mask(3);
6012608Sjason@lowepower.com        MiscRegIndex index = (MiscRegIndex)(pkt->getAddr() / sizeof(MiscReg));
6112608Sjason@lowepower.com        MiscReg data = htog(xc->readMiscReg(index));
6212608Sjason@lowepower.com        // Make sure we don't trot off the end of data.
6312608Sjason@lowepower.com        assert(offset + pkt->getSize() <= sizeof(MiscReg));
6412608Sjason@lowepower.com        pkt->setData(((uint8_t *)&data) + offset);
6512608Sjason@lowepower.com        return xc->getCpuPtr()->ticks(1);
6612608Sjason@lowepower.com    }
6712608Sjason@lowepower.com
6812608Sjason@lowepower.com    inline Tick
6912608Sjason@lowepower.com    handleIprWrite(ThreadContext *xc, Packet *pkt)
7012608Sjason@lowepower.com    {
7112608Sjason@lowepower.com        Addr offset = pkt->getAddr() & mask(3);
7212608Sjason@lowepower.com        MiscRegIndex index = (MiscRegIndex)(pkt->getAddr() / sizeof(MiscReg));
7312608Sjason@lowepower.com        MiscReg data;
7412608Sjason@lowepower.com        data = htog(xc->readMiscRegNoEffect(index));
7512608Sjason@lowepower.com        // Make sure we don't trot off the end of data.
7612608Sjason@lowepower.com        assert(offset + pkt->getSize() <= sizeof(MiscReg));
7712608Sjason@lowepower.com        pkt->writeData(((uint8_t *)&data) + offset);
7812608Sjason@lowepower.com        xc->setMiscReg(index, gtoh(data));
7912608Sjason@lowepower.com        return xc->getCpuPtr()->ticks(1);
8012608Sjason@lowepower.com    }
8112608Sjason@lowepower.com}
8212608Sjason@lowepower.com
8312608Sjason@lowepower.com#endif // __ARCH_X86_MMAPPEDIPR_HH__
8412608Sjason@lowepower.com