locked_mem.hh revision 8232
13170Sstever@eecs.umich.edu/*
25254Sksewell@umich.edu * Copyright (c) 2006-2007 The Regents of The University of Michigan
35254Sksewell@umich.edu * All rights reserved.
43170Sstever@eecs.umich.edu *
55254Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without
65254Sksewell@umich.edu * modification, are permitted provided that the following conditions are
75254Sksewell@umich.edu * met: redistributions of source code must retain the above copyright
85254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer;
95254Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright
105254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the
115254Sksewell@umich.edu * documentation and/or other materials provided with the distribution;
125254Sksewell@umich.edu * neither the name of the copyright holders nor the names of its
135254Sksewell@umich.edu * contributors may be used to endorse or promote products derived from
145254Sksewell@umich.edu * this software without specific prior written permission.
153170Sstever@eecs.umich.edu *
165254Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175254Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185254Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195254Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205254Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215254Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225254Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235254Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245254Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255254Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265254Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273170Sstever@eecs.umich.edu *
285254Sksewell@umich.edu * Authors: Steve Reinhardt
293170Sstever@eecs.umich.edu */
303170Sstever@eecs.umich.edu
313170Sstever@eecs.umich.edu#ifndef __ARCH_MIPS_LOCKED_MEM_HH__
323170Sstever@eecs.umich.edu#define __ARCH_MIPS_LOCKED_MEM_HH__
333170Sstever@eecs.umich.edu
343170Sstever@eecs.umich.edu/**
353170Sstever@eecs.umich.edu * @file
363170Sstever@eecs.umich.edu *
373170Sstever@eecs.umich.edu * ISA-specific helper functions for locked memory accesses.
383170Sstever@eecs.umich.edu */
393170Sstever@eecs.umich.edu
406329Sgblack@eecs.umich.edu#include "arch/registers.hh"
414661Sksewell@umich.edu#include "base/misc.hh"
424661Sksewell@umich.edu#include "base/trace.hh"
438232Snate@binkert.org#include "debug/LLSC.hh"
443170Sstever@eecs.umich.edu#include "mem/request.hh"
453170Sstever@eecs.umich.edu
463170Sstever@eecs.umich.edunamespace MipsISA
473170Sstever@eecs.umich.edu{
486378Sgblack@eecs.umich.edu
493170Sstever@eecs.umich.edutemplate <class XC>
503170Sstever@eecs.umich.eduinline void
513170Sstever@eecs.umich.eduhandleLockedRead(XC *xc, Request *req)
523170Sstever@eecs.umich.edu{
537783SGiacomo.Gabrielli@arm.com    xc->setMiscReg(MISCREG_LLADDR, req->getPaddr() & ~0xf);
547783SGiacomo.Gabrielli@arm.com    xc->setMiscReg(MISCREG_LLFLAG, true);
556378Sgblack@eecs.umich.edu    DPRINTF(LLSC, "[tid:%i]: Load-Link Flag Set & Load-Link"
566378Sgblack@eecs.umich.edu                  " Address set to %x.\n",
575715Shsul@eecs.umich.edu            req->threadId(), req->getPaddr() & ~0xf);
583170Sstever@eecs.umich.edu}
593170Sstever@eecs.umich.edu
603170Sstever@eecs.umich.edutemplate <class XC>
613170Sstever@eecs.umich.eduinline bool
623170Sstever@eecs.umich.eduhandleLockedWrite(XC *xc, Request *req)
633170Sstever@eecs.umich.edu{
644661Sksewell@umich.edu    if (req->isUncacheable()) {
654661Sksewell@umich.edu        // Funky Turbolaser mailbox access...don't update
664661Sksewell@umich.edu        // result register (see stq_c in decoder.isa)
674661Sksewell@umich.edu        req->setExtraData(2);
684661Sksewell@umich.edu    } else {
694661Sksewell@umich.edu        // standard store conditional
707783SGiacomo.Gabrielli@arm.com        bool lock_flag = xc->readMiscReg(MISCREG_LLFLAG);
717783SGiacomo.Gabrielli@arm.com        Addr lock_addr = xc->readMiscReg(MISCREG_LLADDR);
724661Sksewell@umich.edu
734661Sksewell@umich.edu        if (!lock_flag || (req->getPaddr() & ~0xf) != lock_addr) {
744661Sksewell@umich.edu            // Lock flag not set or addr mismatch in CPU;
754661Sksewell@umich.edu            // don't even bother sending to memory system
764661Sksewell@umich.edu            req->setExtraData(0);
777783SGiacomo.Gabrielli@arm.com            xc->setMiscReg(MISCREG_LLFLAG, false);
784661Sksewell@umich.edu
794661Sksewell@umich.edu            // the rest of this code is not architectural;
804661Sksewell@umich.edu            // it's just a debugging aid to help detect
814661Sksewell@umich.edu            // livelock by warning on long sequences of failed
824661Sksewell@umich.edu            // store conditionals
834661Sksewell@umich.edu            int stCondFailures = xc->readStCondFailures();
844661Sksewell@umich.edu            stCondFailures++;
854661Sksewell@umich.edu            xc->setStCondFailures(stCondFailures);
866425Sksewell@umich.edu            if (stCondFailures % 100000 == 0) {
875714Shsul@eecs.umich.edu                warn("%i: context %d: %d consecutive "
884661Sksewell@umich.edu                     "store conditional failures\n",
897823Ssteve.reinhardt@amd.com                     curTick(), xc->contextId(), stCondFailures);
904661Sksewell@umich.edu            }
914661Sksewell@umich.edu
924661Sksewell@umich.edu            if (!lock_flag){
936378Sgblack@eecs.umich.edu                DPRINTF(LLSC, "[tid:%i]: Lock Flag Set, "
946378Sgblack@eecs.umich.edu                              "Store Conditional Failed.\n",
955715Shsul@eecs.umich.edu                        req->threadId());
964661Sksewell@umich.edu            } else if ((req->getPaddr() & ~0xf) != lock_addr) {
976378Sgblack@eecs.umich.edu                DPRINTF(LLSC, "[tid:%i]: Load-Link Address Mismatch, "
986378Sgblack@eecs.umich.edu                              "Store Conditional Failed.\n",
995715Shsul@eecs.umich.edu                        req->threadId());
1004661Sksewell@umich.edu            }
1014661Sksewell@umich.edu            // store conditional failed already, so don't issue it to mem
1024661Sksewell@umich.edu            return false;
1034661Sksewell@umich.edu        }
1044661Sksewell@umich.edu    }
1054661Sksewell@umich.edu
1063170Sstever@eecs.umich.edu    return true;
1073170Sstever@eecs.umich.edu}
1083170Sstever@eecs.umich.edu
1093170Sstever@eecs.umich.edu} // namespace MipsISA
1103170Sstever@eecs.umich.edu
1113170Sstever@eecs.umich.edu#endif
112