interrupts.hh revision 9550
14997Sgblack@eecs.umich.edu/*
25268Sksewell@umich.edu * Copyright (c) 2006 The Regents of The University of Michigan
35222Sksewell@umich.edu * All rights reserved.
44997Sgblack@eecs.umich.edu *
54997Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
64997Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
74997Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
84997Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
94997Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
104997Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
114997Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
124997Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
134997Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
144997Sgblack@eecs.umich.edu * this software without specific prior written permission.
154997Sgblack@eecs.umich.edu *
164997Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
174997Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
184997Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
194997Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
204997Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
214997Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
224997Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234997Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
244997Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254997Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
264997Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274997Sgblack@eecs.umich.edu *
284997Sgblack@eecs.umich.edu * Authors: Steve Reinhardt
295268Sksewell@umich.edu *          Kevin Lim
305268Sksewell@umich.edu */
315268Sksewell@umich.edu
325268Sksewell@umich.edu#ifndef __ARCH_ALPHA_INTERRUPT_HH__
334997Sgblack@eecs.umich.edu#define __ARCH_ALPHA_INTERRUPT_HH__
344997Sgblack@eecs.umich.edu
354997Sgblack@eecs.umich.edu#include "arch/alpha/faults.hh"
364997Sgblack@eecs.umich.edu#include "arch/alpha/isa_traits.hh"
374997Sgblack@eecs.umich.edu#include "base/compiler.hh"
385222Sksewell@umich.edu#include "base/trace.hh"
395222Sksewell@umich.edu#include "cpu/thread_context.hh"
405222Sksewell@umich.edu#include "debug/Flow.hh"
415222Sksewell@umich.edu#include "debug/Interrupt.hh"
425222Sksewell@umich.edu#include "params/AlphaInterrupts.hh"
435222Sksewell@umich.edu#include "sim/sim_object.hh"
445222Sksewell@umich.edu
455222Sksewell@umich.edunamespace AlphaISA {
466022Sgblack@eecs.umich.edu
475222Sksewell@umich.educlass Interrupts : public SimObject
484997Sgblack@eecs.umich.edu{
495222Sksewell@umich.edu  private:
504997Sgblack@eecs.umich.edu    bool newInfoSet;
515222Sksewell@umich.edu    int newIpl;
525222Sksewell@umich.edu    int newSummary;
535222Sksewell@umich.edu    BaseCPU * cpu;
545222Sksewell@umich.edu
555222Sksewell@umich.edu  protected:
565222Sksewell@umich.edu    uint64_t interrupts[NumInterruptLevels];
575222Sksewell@umich.edu    uint64_t intstatus;
585222Sksewell@umich.edu
595222Sksewell@umich.edu  public:
604997Sgblack@eecs.umich.edu    typedef AlphaInterruptsParams Params;
615222Sksewell@umich.edu
625222Sksewell@umich.edu    const Params *
635222Sksewell@umich.edu    params() const
645222Sksewell@umich.edu    {
655222Sksewell@umich.edu        return dynamic_cast<const Params *>(_params);
665014Sgblack@eecs.umich.edu    }
675222Sksewell@umich.edu
685222Sksewell@umich.edu    Interrupts(Params * p) : SimObject(p), cpu(NULL)
695184Sgblack@eecs.umich.edu    {
705877Shsul@eecs.umich.edu        memset(interrupts, 0, sizeof(interrupts));
715877Shsul@eecs.umich.edu        intstatus = 0;
725877Shsul@eecs.umich.edu        newInfoSet = false;
735222Sksewell@umich.edu    }
745222Sksewell@umich.edu
755222Sksewell@umich.edu    void
765222Sksewell@umich.edu    setCPU(BaseCPU * _cpu)
775014Sgblack@eecs.umich.edu    {
785222Sksewell@umich.edu        cpu = _cpu;
795222Sksewell@umich.edu    }
805222Sksewell@umich.edu
815222Sksewell@umich.edu    void
825014Sgblack@eecs.umich.edu    post(int int_num, int index)
834997Sgblack@eecs.umich.edu    {
844997Sgblack@eecs.umich.edu        DPRINTF(Interrupt, "Interrupt %d:%d posted\n", int_num, index);
855358Sgblack@eecs.umich.edu
865222Sksewell@umich.edu        if (int_num < 0 || int_num >= NumInterruptLevels)
875222Sksewell@umich.edu            panic("int_num out of bounds\n");
885222Sksewell@umich.edu
895543Ssaidi@eecs.umich.edu        if (index < 0 || index >= (int)sizeof(uint64_t) * 8)
905222Sksewell@umich.edu            panic("int_num out of bounds\n");
915543Ssaidi@eecs.umich.edu
925543Ssaidi@eecs.umich.edu        interrupts[int_num] |= 1 << index;
935543Ssaidi@eecs.umich.edu        intstatus |= (ULL(1) << int_num);
945222Sksewell@umich.edu    }
955222Sksewell@umich.edu
965222Sksewell@umich.edu    void
975222Sksewell@umich.edu    clear(int int_num, int index)
985999Snate@binkert.org    {
995999Snate@binkert.org        DPRINTF(Interrupt, "Interrupt %d:%d cleared\n", int_num, index);
1005999Snate@binkert.org
1015999Snate@binkert.org        if (int_num < 0 || int_num >= NumInterruptLevels)
1025999Snate@binkert.org            panic("int_num out of bounds\n");
1035999Snate@binkert.org
1045999Snate@binkert.org        if (index < 0 || index >= (int)sizeof(uint64_t) * 8)
1055999Snate@binkert.org            panic("int_num out of bounds\n");
1065222Sksewell@umich.edu
1075222Sksewell@umich.edu        interrupts[int_num] &= ~(1 << index);
1085222Sksewell@umich.edu        if (interrupts[int_num] == 0)
1095222Sksewell@umich.edu            intstatus &= ~(ULL(1) << int_num);
1105222Sksewell@umich.edu    }
1115222Sksewell@umich.edu
1125222Sksewell@umich.edu    void
1135222Sksewell@umich.edu    clearAll()
1145222Sksewell@umich.edu    {
1155222Sksewell@umich.edu        DPRINTF(Interrupt, "Interrupts all cleared\n");
1165222Sksewell@umich.edu
1175222Sksewell@umich.edu        memset(interrupts, 0, sizeof(interrupts));
1185222Sksewell@umich.edu        intstatus = 0;
1195222Sksewell@umich.edu    }
1205222Sksewell@umich.edu
1215222Sksewell@umich.edu    void
1225222Sksewell@umich.edu    serialize(std::ostream &os)
1235222Sksewell@umich.edu    {
1245222Sksewell@umich.edu        SERIALIZE_ARRAY(interrupts, NumInterruptLevels);
1255358Sgblack@eecs.umich.edu        SERIALIZE_SCALAR(intstatus);
1265358Sgblack@eecs.umich.edu    }
1275358Sgblack@eecs.umich.edu
1285358Sgblack@eecs.umich.edu    void
1295222Sksewell@umich.edu    unserialize(Checkpoint *cp, const std::string &section)
1305222Sksewell@umich.edu    {
1315222Sksewell@umich.edu        UNSERIALIZE_ARRAY(interrupts, NumInterruptLevels);
1325222Sksewell@umich.edu        UNSERIALIZE_SCALAR(intstatus);
1335222Sksewell@umich.edu    }
1345222Sksewell@umich.edu
1355222Sksewell@umich.edu    bool
1365222Sksewell@umich.edu    checkInterrupts(ThreadContext *tc) const
1375222Sksewell@umich.edu    {
1385222Sksewell@umich.edu        return (intstatus != 0) && !(tc->pcState().pc() & 0x3);
1395222Sksewell@umich.edu    }
1405222Sksewell@umich.edu
1416023Snate@binkert.org    Fault
1425894Sgblack@eecs.umich.edu    getInterrupt(ThreadContext *tc)
1436023Snate@binkert.org    {
1445222Sksewell@umich.edu        uint64_t ipl = 0;
1456022Sgblack@eecs.umich.edu        uint64_t summary = 0;
1466022Sgblack@eecs.umich.edu
1476022Sgblack@eecs.umich.edu        if (tc->readMiscRegNoEffect(IPR_ASTRR))
1485222Sksewell@umich.edu            panic("asynchronous traps not implemented\n");
1495222Sksewell@umich.edu
1505222Sksewell@umich.edu        if (tc->readMiscRegNoEffect(IPR_SIRR)) {
1515222Sksewell@umich.edu            for (uint64_t i = INTLEVEL_SOFTWARE_MIN;
1525222Sksewell@umich.edu                 i < INTLEVEL_SOFTWARE_MAX; i++) {
1535222Sksewell@umich.edu                if (tc->readMiscRegNoEffect(IPR_SIRR) & (ULL(1) << i)) {
1545222Sksewell@umich.edu                    // See table 4-19 of 21164 hardware reference
155                    ipl = (i - INTLEVEL_SOFTWARE_MIN) + 1;
156                    summary |= (ULL(1) << i);
157                }
158            }
159        }
160
161        if (intstatus) {
162            for (uint64_t i = INTLEVEL_EXTERNAL_MIN;
163                 i < INTLEVEL_EXTERNAL_MAX; i++) {
164                if (intstatus & (ULL(1) << i)) {
165                    // See table 4-19 of 21164 hardware reference
166                    ipl = i;
167                    summary |= (ULL(1) << i);
168                }
169            }
170        }
171
172        if (ipl && ipl > tc->readMiscRegNoEffect(IPR_IPLR)) {
173            newIpl = ipl;
174            newSummary = summary;
175            newInfoSet = true;
176            DPRINTF(Flow, "Interrupt! IPLR=%d ipl=%d summary=%x\n",
177                    tc->readMiscRegNoEffect(IPR_IPLR), ipl, summary);
178
179            return new InterruptFault;
180        } else {
181            return NoFault;
182        }
183    }
184
185    void
186    updateIntrInfo(ThreadContext *tc)
187    {
188        assert(newInfoSet);
189        tc->setMiscRegNoEffect(IPR_ISR, newSummary);
190        tc->setMiscRegNoEffect(IPR_INTID, newIpl);
191        newInfoSet = false;
192    }
193};
194
195} // namespace AlphaISA
196
197#endif // __ARCH_ALPHA_INTERRUPT_HH__
198
199