interrupts.hh revision 5568
13520Sgblack@eecs.umich.edu/*
23520Sgblack@eecs.umich.edu * Copyright (c) 2006 The Regents of The University of Michigan
33520Sgblack@eecs.umich.edu * All rights reserved.
43520Sgblack@eecs.umich.edu *
53520Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
63520Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
73520Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
83520Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
93520Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
103520Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
113520Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
123520Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
133520Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
143520Sgblack@eecs.umich.edu * this software without specific prior written permission.
153520Sgblack@eecs.umich.edu *
163520Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173520Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183520Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193520Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
203520Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
213520Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223520Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233520Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243520Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253520Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
263520Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273520Sgblack@eecs.umich.edu *
283520Sgblack@eecs.umich.edu * Authors: Steve Reinhardt
293520Sgblack@eecs.umich.edu *          Kevin Lim
303520Sgblack@eecs.umich.edu */
313520Sgblack@eecs.umich.edu
323520Sgblack@eecs.umich.edu#ifndef __ARCH_ALPHA_INTERRUPT_HH__
333520Sgblack@eecs.umich.edu#define __ARCH_ALPHA_INTERRUPT_HH__
343520Sgblack@eecs.umich.edu
353520Sgblack@eecs.umich.edu#include "arch/alpha/faults.hh"
363520Sgblack@eecs.umich.edu#include "arch/alpha/isa_traits.hh"
374103Ssaidi@eecs.umich.edu#include "base/compiler.hh"
383520Sgblack@eecs.umich.edu#include "cpu/thread_context.hh"
393520Sgblack@eecs.umich.edu
405565Snate@binkert.orgnamespace AlphaISA {
415565Snate@binkert.org
425565Snate@binkert.orgclass Interrupts
433520Sgblack@eecs.umich.edu{
445565Snate@binkert.org  private:
455565Snate@binkert.org    bool newInfoSet;
465565Snate@binkert.org    int newIpl;
475565Snate@binkert.org    int newSummary;
485565Snate@binkert.org
495565Snate@binkert.org  protected:
505565Snate@binkert.org    uint64_t interrupts[NumInterruptLevels];
515565Snate@binkert.org    uint64_t intstatus;
525565Snate@binkert.org
535565Snate@binkert.org  public:
545565Snate@binkert.org    Interrupts()
553520Sgblack@eecs.umich.edu    {
565565Snate@binkert.org        memset(interrupts, 0, sizeof(interrupts));
575565Snate@binkert.org        intstatus = 0;
585565Snate@binkert.org        newInfoSet = false;
595565Snate@binkert.org    }
603520Sgblack@eecs.umich.edu
615565Snate@binkert.org    void
625565Snate@binkert.org    post(int int_num, int index)
635565Snate@binkert.org    {
645565Snate@binkert.org        DPRINTF(Interrupt, "Interrupt %d:%d posted\n", int_num, index);
653520Sgblack@eecs.umich.edu
665565Snate@binkert.org        if (int_num < 0 || int_num >= NumInterruptLevels)
675565Snate@binkert.org            panic("int_num out of bounds\n");
683520Sgblack@eecs.umich.edu
695565Snate@binkert.org        if (index < 0 || index >= (int)sizeof(uint64_t) * 8)
705565Snate@binkert.org            panic("int_num out of bounds\n");
713520Sgblack@eecs.umich.edu
725565Snate@binkert.org        interrupts[int_num] |= 1 << index;
735565Snate@binkert.org        intstatus |= (ULL(1) << int_num);
745565Snate@binkert.org    }
753520Sgblack@eecs.umich.edu
765565Snate@binkert.org    void
775565Snate@binkert.org    clear(int int_num, int index)
785565Snate@binkert.org    {
795565Snate@binkert.org        DPRINTF(Interrupt, "Interrupt %d:%d cleared\n", int_num, index);
803520Sgblack@eecs.umich.edu
815568Snate@binkert.org        if (int_num < 0 || int_num >= NumInterruptLevels)
825565Snate@binkert.org            panic("int_num out of bounds\n");
833520Sgblack@eecs.umich.edu
845565Snate@binkert.org        if (index < 0 || index >= (int)sizeof(uint64_t) * 8)
855565Snate@binkert.org            panic("int_num out of bounds\n");
863520Sgblack@eecs.umich.edu
875565Snate@binkert.org        interrupts[int_num] &= ~(1 << index);
885565Snate@binkert.org        if (interrupts[int_num] == 0)
895565Snate@binkert.org            intstatus &= ~(ULL(1) << int_num);
905565Snate@binkert.org    }
913520Sgblack@eecs.umich.edu
925565Snate@binkert.org    void
935565Snate@binkert.org    clear_all()
945565Snate@binkert.org    {
955565Snate@binkert.org        DPRINTF(Interrupt, "Interrupts all cleared\n");
963520Sgblack@eecs.umich.edu
975565Snate@binkert.org        memset(interrupts, 0, sizeof(interrupts));
985565Snate@binkert.org        intstatus = 0;
995565Snate@binkert.org    }
1003520Sgblack@eecs.umich.edu
1015565Snate@binkert.org    void
1025565Snate@binkert.org    serialize(std::ostream &os)
1035565Snate@binkert.org    {
1045565Snate@binkert.org        SERIALIZE_ARRAY(interrupts, NumInterruptLevels);
1055565Snate@binkert.org        SERIALIZE_SCALAR(intstatus);
1065565Snate@binkert.org    }
1073520Sgblack@eecs.umich.edu
1085565Snate@binkert.org    void
1095565Snate@binkert.org    unserialize(Checkpoint *cp, const std::string &section)
1105565Snate@binkert.org    {
1115565Snate@binkert.org        UNSERIALIZE_ARRAY(interrupts, NumInterruptLevels);
1125565Snate@binkert.org        UNSERIALIZE_SCALAR(intstatus);
1135565Snate@binkert.org    }
1143520Sgblack@eecs.umich.edu
1155565Snate@binkert.org    bool
1165565Snate@binkert.org    check_interrupts(ThreadContext *tc) const
1175565Snate@binkert.org    {
1185565Snate@binkert.org        return (intstatus != 0) && !(tc->readPC() & 0x3);
1195565Snate@binkert.org    }
1203520Sgblack@eecs.umich.edu
1215565Snate@binkert.org    Fault
1225565Snate@binkert.org    getInterrupt(ThreadContext *tc)
1235565Snate@binkert.org    {
1245565Snate@binkert.org        int ipl = 0;
1255565Snate@binkert.org        int summary = 0;
1263521Sgblack@eecs.umich.edu
1275565Snate@binkert.org        if (tc->readMiscRegNoEffect(IPR_ASTRR))
1285565Snate@binkert.org            panic("asynchronous traps not implemented\n");
1293520Sgblack@eecs.umich.edu
1305565Snate@binkert.org        if (tc->readMiscRegNoEffect(IPR_SIRR)) {
1315565Snate@binkert.org            for (int i = INTLEVEL_SOFTWARE_MIN;
1325565Snate@binkert.org                 i < INTLEVEL_SOFTWARE_MAX; i++) {
1335565Snate@binkert.org                if (tc->readMiscRegNoEffect(IPR_SIRR) & (ULL(1) << i)) {
1345565Snate@binkert.org                    // See table 4-19 of 21164 hardware reference
1355565Snate@binkert.org                    ipl = (i - INTLEVEL_SOFTWARE_MIN) + 1;
1365565Snate@binkert.org                    summary |= (ULL(1) << i);
1373520Sgblack@eecs.umich.edu                }
1383520Sgblack@eecs.umich.edu            }
1393520Sgblack@eecs.umich.edu        }
1403520Sgblack@eecs.umich.edu
1415565Snate@binkert.org        uint64_t interrupts = intstatus;
1425565Snate@binkert.org        if (interrupts) {
1435565Snate@binkert.org            for (int i = INTLEVEL_EXTERNAL_MIN;
1445565Snate@binkert.org                 i < INTLEVEL_EXTERNAL_MAX; i++) {
1455565Snate@binkert.org                if (interrupts & (ULL(1) << i)) {
1465565Snate@binkert.org                    // See table 4-19 of 21164 hardware reference
1475565Snate@binkert.org                    ipl = i;
1485565Snate@binkert.org                    summary |= (ULL(1) << i);
1495565Snate@binkert.org                }
1505565Snate@binkert.org            }
1513633Sktlim@umich.edu        }
1523633Sktlim@umich.edu
1535565Snate@binkert.org        if (ipl && ipl > tc->readMiscRegNoEffect(IPR_IPLR)) {
1545565Snate@binkert.org            newIpl = ipl;
1555565Snate@binkert.org            newSummary = summary;
1565565Snate@binkert.org            newInfoSet = true;
1575565Snate@binkert.org            DPRINTF(Flow, "Interrupt! IPLR=%d ipl=%d summary=%x\n",
1585565Snate@binkert.org                    tc->readMiscRegNoEffect(IPR_IPLR), ipl, summary);
1595565Snate@binkert.org
1605565Snate@binkert.org            return new InterruptFault;
1615565Snate@binkert.org        } else {
1625565Snate@binkert.org            return NoFault;
1634103Ssaidi@eecs.umich.edu        }
1645565Snate@binkert.org    }
1654103Ssaidi@eecs.umich.edu
1665565Snate@binkert.org    void
1675565Snate@binkert.org    updateIntrInfo(ThreadContext *tc)
1685565Snate@binkert.org    {
1695565Snate@binkert.org        assert(newInfoSet);
1705565Snate@binkert.org        tc->setMiscRegNoEffect(IPR_ISR, newSummary);
1715565Snate@binkert.org        tc->setMiscRegNoEffect(IPR_INTID, newIpl);
1725565Snate@binkert.org        newInfoSet = false;
1735565Snate@binkert.org    }
1743520Sgblack@eecs.umich.edu
1755565Snate@binkert.org    uint64_t
1765565Snate@binkert.org    get_vec(int int_num)
1775565Snate@binkert.org    {
1785565Snate@binkert.org        panic("Shouldn't be called for Alpha\n");
1795565Snate@binkert.org        M5_DUMMY_RETURN;
1805565Snate@binkert.org    }
1815565Snate@binkert.org};
1823520Sgblack@eecs.umich.edu
1835565Snate@binkert.org} // namespace AlphaISA
1845565Snate@binkert.org
1855565Snate@binkert.org#endif // __ARCH_ALPHA_INTERRUPT_HH__
1865565Snate@binkert.org
187