mmapped_ipr.hh revision 5417
111988Sandreas.sandberg@arm.com/*
28839Sandreas.hansson@arm.com * Copyright (c) 2007-2008 The Hewlett-Packard Development Company
38839Sandreas.hansson@arm.com * All rights reserved.
48839Sandreas.hansson@arm.com *
58839Sandreas.hansson@arm.com * Redistribution and use of this software in source and binary forms,
68839Sandreas.hansson@arm.com * with or without modification, are permitted provided that the
78839Sandreas.hansson@arm.com * following conditions are met:
88839Sandreas.hansson@arm.com *
98839Sandreas.hansson@arm.com * The software must be used only for Non-Commercial Use which means any
108839Sandreas.hansson@arm.com * use which is NOT directed to receiving any direct monetary
118839Sandreas.hansson@arm.com * compensation for, or commercial advantage from such use.  Illustrative
128839Sandreas.hansson@arm.com * examples of non-commercial use are academic research, personal study,
133101Sstever@eecs.umich.edu * teaching, education and corporate research & development.
148579Ssteve.reinhardt@amd.com * Illustrative examples of commercial use are distributing products for
153101Sstever@eecs.umich.edu * commercial advantage and providing services using the software for
163101Sstever@eecs.umich.edu * commercial advantage.
173101Sstever@eecs.umich.edu *
183101Sstever@eecs.umich.edu * If you wish to use this software or functionality therein that may be
193101Sstever@eecs.umich.edu * covered by patents for commercial use, please contact:
203101Sstever@eecs.umich.edu *     Director of Intellectual Property Licensing
213101Sstever@eecs.umich.edu *     Office of Strategy and Technology
223101Sstever@eecs.umich.edu *     Hewlett-Packard Company
233101Sstever@eecs.umich.edu *     1501 Page Mill Road
243101Sstever@eecs.umich.edu *     Palo Alto, California  94304
253101Sstever@eecs.umich.edu *
263101Sstever@eecs.umich.edu * Redistributions of source code must retain the above copyright notice,
273101Sstever@eecs.umich.edu * this list of conditions and the following disclaimer.  Redistributions
283101Sstever@eecs.umich.edu * in binary form must reproduce the above copyright notice, this list of
293101Sstever@eecs.umich.edu * conditions and the following disclaimer in the documentation and/or
303101Sstever@eecs.umich.edu * other materials provided with the distribution.  Neither the name of
313101Sstever@eecs.umich.edu * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
323101Sstever@eecs.umich.edu * contributors may be used to endorse or promote products derived from
333101Sstever@eecs.umich.edu * this software without specific prior written permission.  No right of
343101Sstever@eecs.umich.edu * sublicense is granted herewith.  Derivatives of the software and
353101Sstever@eecs.umich.edu * output created using the software may be prepared, but only for
363101Sstever@eecs.umich.edu * Non-Commercial Uses.  Derivatives of the software may be shared with
373101Sstever@eecs.umich.edu * others provided: (i) the others agree to abide by the list of
383101Sstever@eecs.umich.edu * conditions herein which includes the Non-Commercial Use restrictions;
393101Sstever@eecs.umich.edu * and (ii) such Derivatives of the software include the above copyright
403101Sstever@eecs.umich.edu * notice to acknowledge the contribution from this software where
413101Sstever@eecs.umich.edu * applicable, this list of conditions and the disclaimer below.
427778Sgblack@eecs.umich.edu *
438839Sandreas.hansson@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
443101Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
453101Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
463101Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
473101Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
483101Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
493101Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
503101Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
513101Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
523101Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
533101Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
543101Sstever@eecs.umich.edu *
553101Sstever@eecs.umich.edu * Authors: Gabe Black
563101Sstever@eecs.umich.edu */
573101Sstever@eecs.umich.edu
583101Sstever@eecs.umich.edu#ifndef __ARCH_X86_MMAPEDIPR_HH__
593101Sstever@eecs.umich.edu#define __ARCH_X86_MMAPEDIPR_HH__
603101Sstever@eecs.umich.edu
613101Sstever@eecs.umich.edu/**
623885Sbinkertn@umich.edu * @file
633885Sbinkertn@umich.edu *
644762Snate@binkert.org * ISA-specific helper functions for memory mapped IPR accesses.
653885Sbinkertn@umich.edu */
663885Sbinkertn@umich.edu
677528Ssteve.reinhardt@amd.com#include "arch/x86/miscregs.hh"
683885Sbinkertn@umich.edu#include "config/full_system.hh"
694380Sbinkertn@umich.edu#include "cpu/base.hh"
704167Sbinkertn@umich.edu#include "cpu/thread_context.hh"
713102Sstever@eecs.umich.edu#include "mem/packet.hh"
723101Sstever@eecs.umich.edu
734762Snate@binkert.orgnamespace X86ISA
744762Snate@binkert.org{
754762Snate@binkert.org    inline Tick
764762Snate@binkert.org    handleIprRead(ThreadContext *xc, Packet *pkt)
774762Snate@binkert.org    {
784762Snate@binkert.org#if !FULL_SYSTEM
794762Snate@binkert.org        panic("Shouldn't have a memory mapped register in SE\n");
804762Snate@binkert.org#else
814762Snate@binkert.org        Addr offset = pkt->getAddr() & mask(3);
825033Smilesck@eecs.umich.edu        MiscRegIndex index = (MiscRegIndex)(pkt->getAddr() / sizeof(MiscReg));
835033Smilesck@eecs.umich.edu        MiscReg data = htog(xc->readMiscReg(index));
845033Smilesck@eecs.umich.edu        // Make sure we don't trot off the end of data.
855033Smilesck@eecs.umich.edu        assert(offset + pkt->getSize() <= sizeof(MiscReg));
865033Smilesck@eecs.umich.edu        pkt->setData(((uint8_t *)&data) + offset);
875033Smilesck@eecs.umich.edu#endif
885033Smilesck@eecs.umich.edu        return xc->getCpuPtr()->ticks(1);
895033Smilesck@eecs.umich.edu    }
905033Smilesck@eecs.umich.edu
915033Smilesck@eecs.umich.edu    inline Tick
923101Sstever@eecs.umich.edu    handleIprWrite(ThreadContext *xc, Packet *pkt)
933101Sstever@eecs.umich.edu    {
943101Sstever@eecs.umich.edu#if !FULL_SYSTEM
955033Smilesck@eecs.umich.edu        panic("Shouldn't have a memory mapped register in SE\n");
9610267SGeoffrey.Blake@arm.com#else
978596Ssteve.reinhardt@amd.com        Addr offset = pkt->getAddr() & mask(3);
988596Ssteve.reinhardt@amd.com        MiscRegIndex index = (MiscRegIndex)(pkt->getAddr() / sizeof(MiscReg));
998596Ssteve.reinhardt@amd.com        MiscReg data = htog(xc->readMiscRegNoEffect(index));
1008596Ssteve.reinhardt@amd.com        // Make sure we don't trot off the end of data.
1017673Snate@binkert.org        assert(offset + pkt->getSize() <= sizeof(MiscReg));
1027673Snate@binkert.org        pkt->writeData(((uint8_t *)&data) + offset);
1037673Snate@binkert.org        xc->setMiscReg(index, gtoh(data));
1047673Snate@binkert.org#endif
10511988Sandreas.sandberg@arm.com        return xc->getCpuPtr()->ticks(1);
10611988Sandreas.sandberg@arm.com    }
10711988Sandreas.sandberg@arm.com};
10811988Sandreas.sandberg@arm.com
1093101Sstever@eecs.umich.edu#endif // __ARCH_X86_MMAPEDIPR_HH__
1103101Sstever@eecs.umich.edu