locked_mem.hh revision 4027
112726Snikos.nikoleris@arm.com/*
212726Snikos.nikoleris@arm.com * Copyright (c) 2006 The Regents of The University of Michigan
312726Snikos.nikoleris@arm.com * All rights reserved.
412726Snikos.nikoleris@arm.com *
512726Snikos.nikoleris@arm.com * Redistribution and use in source and binary forms, with or without
612726Snikos.nikoleris@arm.com * modification, are permitted provided that the following conditions are
712726Snikos.nikoleris@arm.com * met: redistributions of source code must retain the above copyright
812726Snikos.nikoleris@arm.com * notice, this list of conditions and the following disclaimer;
912726Snikos.nikoleris@arm.com * redistributions in binary form must reproduce the above copyright
1012726Snikos.nikoleris@arm.com * notice, this list of conditions and the following disclaimer in the
1112726Snikos.nikoleris@arm.com * documentation and/or other materials provided with the distribution;
1212726Snikos.nikoleris@arm.com * neither the name of the copyright holders nor the names of its
1312726Snikos.nikoleris@arm.com * contributors may be used to endorse or promote products derived from
1412726Snikos.nikoleris@arm.com * this software without specific prior written permission.
1512726Snikos.nikoleris@arm.com *
1612726Snikos.nikoleris@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712726Snikos.nikoleris@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812726Snikos.nikoleris@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912726Snikos.nikoleris@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012726Snikos.nikoleris@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112726Snikos.nikoleris@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212726Snikos.nikoleris@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312726Snikos.nikoleris@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412726Snikos.nikoleris@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512726Snikos.nikoleris@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612726Snikos.nikoleris@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712726Snikos.nikoleris@arm.com *
2812726Snikos.nikoleris@arm.com * Authors: Steve Reinhardt
2912726Snikos.nikoleris@arm.com */
3012726Snikos.nikoleris@arm.com
3112726Snikos.nikoleris@arm.com#ifndef __ARCH_ALPHA_LOCKED_MEM_HH__
3212726Snikos.nikoleris@arm.com#define __ARCH_ALPHA_LOCKED_MEM_HH__
3312726Snikos.nikoleris@arm.com
3412726Snikos.nikoleris@arm.com/**
3512726Snikos.nikoleris@arm.com * @file
3612726Snikos.nikoleris@arm.com *
3712726Snikos.nikoleris@arm.com * ISA-specific helper functions for locked memory accesses.
3812726Snikos.nikoleris@arm.com *
3912726Snikos.nikoleris@arm.com * Note that these functions are not embedded in the ISA description
4012726Snikos.nikoleris@arm.com * because they operate on the *physical* address rather than the
4112726Snikos.nikoleris@arm.com * virtual address.  In the current M5 design, the physical address is
4212726Snikos.nikoleris@arm.com * not accessible from the ISA description, only from the CPU model.
4312726Snikos.nikoleris@arm.com * Thus the CPU is responsible for calling back to the ISA (here)
4412726Snikos.nikoleris@arm.com * after the address translation has been performed to allow the ISA
4512726Snikos.nikoleris@arm.com * to do these manipulations based on the physical address.
4612726Snikos.nikoleris@arm.com */
4712726Snikos.nikoleris@arm.com
4812726Snikos.nikoleris@arm.com#include "arch/alpha/miscregfile.hh"
4912726Snikos.nikoleris@arm.com#include "base/misc.hh"
5012726Snikos.nikoleris@arm.com#include "mem/request.hh"
5112726Snikos.nikoleris@arm.com
5212726Snikos.nikoleris@arm.com
5312726Snikos.nikoleris@arm.comnamespace AlphaISA
5412726Snikos.nikoleris@arm.com{
5512726Snikos.nikoleris@arm.comtemplate <class XC>
5612726Snikos.nikoleris@arm.cominline void
5712726Snikos.nikoleris@arm.comhandleLockedRead(XC *xc, Request *req)
5812726Snikos.nikoleris@arm.com{
5912726Snikos.nikoleris@arm.com    xc->setMiscReg(MISCREG_LOCKADDR, req->getPaddr() & ~0xf);
6012726Snikos.nikoleris@arm.com    xc->setMiscReg(MISCREG_LOCKFLAG, true);
6112726Snikos.nikoleris@arm.com}
6212726Snikos.nikoleris@arm.com
6312726Snikos.nikoleris@arm.com
6412726Snikos.nikoleris@arm.comtemplate <class XC>
6512726Snikos.nikoleris@arm.cominline bool
6612726Snikos.nikoleris@arm.comhandleLockedWrite(XC *xc, Request *req)
6712726Snikos.nikoleris@arm.com{
6812726Snikos.nikoleris@arm.com    if (req->isUncacheable()) {
6912726Snikos.nikoleris@arm.com        // Funky Turbolaser mailbox access...don't update
7012726Snikos.nikoleris@arm.com        // result register (see stq_c in decoder.isa)
7112726Snikos.nikoleris@arm.com        req->setScResult(2);
7212726Snikos.nikoleris@arm.com    } else {
7312726Snikos.nikoleris@arm.com        // standard store conditional
7412726Snikos.nikoleris@arm.com        bool lock_flag = xc->readMiscReg(MISCREG_LOCKFLAG);
7512726Snikos.nikoleris@arm.com        Addr lock_addr = xc->readMiscReg(MISCREG_LOCKADDR);
7612726Snikos.nikoleris@arm.com        if (!lock_flag || (req->getPaddr() & ~0xf) != lock_addr) {
7712726Snikos.nikoleris@arm.com            // Lock flag not set or addr mismatch in CPU;
7812726Snikos.nikoleris@arm.com            // don't even bother sending to memory system
7912726Snikos.nikoleris@arm.com            req->setScResult(0);
8012726Snikos.nikoleris@arm.com            xc->setMiscReg(MISCREG_LOCKFLAG, false);
8112726Snikos.nikoleris@arm.com            // the rest of this code is not architectural;
8212726Snikos.nikoleris@arm.com            // it's just a debugging aid to help detect
8312726Snikos.nikoleris@arm.com            // livelock by warning on long sequences of failed
8412726Snikos.nikoleris@arm.com            // store conditionals
8512726Snikos.nikoleris@arm.com            int stCondFailures = xc->readStCondFailures();
8612726Snikos.nikoleris@arm.com            stCondFailures++;
8712726Snikos.nikoleris@arm.com            xc->setStCondFailures(stCondFailures);
8812726Snikos.nikoleris@arm.com            if (stCondFailures % 100000 == 0) {
8912726Snikos.nikoleris@arm.com                warn("cpu %d: %d consecutive "
9012726Snikos.nikoleris@arm.com                     "store conditional failures\n",
9112726Snikos.nikoleris@arm.com                     xc->readCpuId(), stCondFailures);
9212726Snikos.nikoleris@arm.com            }
9312726Snikos.nikoleris@arm.com
9412726Snikos.nikoleris@arm.com            // store conditional failed already, so don't issue it to mem
9512726Snikos.nikoleris@arm.com            return false;
9612726Snikos.nikoleris@arm.com        }
9712726Snikos.nikoleris@arm.com    }
9812726Snikos.nikoleris@arm.com
9912726Snikos.nikoleris@arm.com    return true;
10012726Snikos.nikoleris@arm.com}
10113017Snikos.nikoleris@arm.com
10212726Snikos.nikoleris@arm.com
10312726Snikos.nikoleris@arm.com} // namespace AlphaISA
10412726Snikos.nikoleris@arm.com
10512726Snikos.nikoleris@arm.com#endif
10612726Snikos.nikoleris@arm.com