interrupts.hh revision 7720
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" 385647Sgblack@eecs.umich.edu#include "base/trace.hh" 393520Sgblack@eecs.umich.edu#include "cpu/thread_context.hh" 405647Sgblack@eecs.umich.edu#include "params/AlphaInterrupts.hh" 415647Sgblack@eecs.umich.edu#include "sim/sim_object.hh" 423520Sgblack@eecs.umich.edu 435565Snate@binkert.orgnamespace AlphaISA { 445565Snate@binkert.org 455647Sgblack@eecs.umich.educlass Interrupts : public SimObject 463520Sgblack@eecs.umich.edu{ 475565Snate@binkert.org private: 485565Snate@binkert.org bool newInfoSet; 495565Snate@binkert.org int newIpl; 505565Snate@binkert.org int newSummary; 515810Sgblack@eecs.umich.edu BaseCPU * cpu; 525565Snate@binkert.org 535565Snate@binkert.org protected: 545565Snate@binkert.org uint64_t interrupts[NumInterruptLevels]; 555565Snate@binkert.org uint64_t intstatus; 565565Snate@binkert.org 575565Snate@binkert.org public: 585647Sgblack@eecs.umich.edu typedef AlphaInterruptsParams Params; 595647Sgblack@eecs.umich.edu 605647Sgblack@eecs.umich.edu const Params * 615647Sgblack@eecs.umich.edu params() const 625647Sgblack@eecs.umich.edu { 635647Sgblack@eecs.umich.edu return dynamic_cast<const Params *>(_params); 645647Sgblack@eecs.umich.edu } 655647Sgblack@eecs.umich.edu 665810Sgblack@eecs.umich.edu Interrupts(Params * p) : SimObject(p), cpu(NULL) 673520Sgblack@eecs.umich.edu { 685565Snate@binkert.org memset(interrupts, 0, sizeof(interrupts)); 695565Snate@binkert.org intstatus = 0; 705565Snate@binkert.org newInfoSet = false; 715565Snate@binkert.org } 723520Sgblack@eecs.umich.edu 735565Snate@binkert.org void 745810Sgblack@eecs.umich.edu setCPU(BaseCPU * _cpu) 755810Sgblack@eecs.umich.edu { 765810Sgblack@eecs.umich.edu cpu = _cpu; 775810Sgblack@eecs.umich.edu } 785810Sgblack@eecs.umich.edu 795810Sgblack@eecs.umich.edu void 805565Snate@binkert.org post(int int_num, int index) 815565Snate@binkert.org { 825565Snate@binkert.org DPRINTF(Interrupt, "Interrupt %d:%d posted\n", int_num, index); 833520Sgblack@eecs.umich.edu 845565Snate@binkert.org if (int_num < 0 || int_num >= NumInterruptLevels) 855565Snate@binkert.org panic("int_num out of bounds\n"); 863520Sgblack@eecs.umich.edu 875565Snate@binkert.org if (index < 0 || index >= (int)sizeof(uint64_t) * 8) 885565Snate@binkert.org panic("int_num out of bounds\n"); 893520Sgblack@eecs.umich.edu 905565Snate@binkert.org interrupts[int_num] |= 1 << index; 915565Snate@binkert.org intstatus |= (ULL(1) << int_num); 925565Snate@binkert.org } 933520Sgblack@eecs.umich.edu 945565Snate@binkert.org void 955565Snate@binkert.org clear(int int_num, int index) 965565Snate@binkert.org { 975565Snate@binkert.org DPRINTF(Interrupt, "Interrupt %d:%d cleared\n", int_num, index); 983520Sgblack@eecs.umich.edu 995568Snate@binkert.org if (int_num < 0 || int_num >= NumInterruptLevels) 1005565Snate@binkert.org panic("int_num out of bounds\n"); 1013520Sgblack@eecs.umich.edu 1025565Snate@binkert.org if (index < 0 || index >= (int)sizeof(uint64_t) * 8) 1035565Snate@binkert.org panic("int_num out of bounds\n"); 1043520Sgblack@eecs.umich.edu 1055565Snate@binkert.org interrupts[int_num] &= ~(1 << index); 1065565Snate@binkert.org if (interrupts[int_num] == 0) 1075565Snate@binkert.org intstatus &= ~(ULL(1) << int_num); 1085565Snate@binkert.org } 1093520Sgblack@eecs.umich.edu 1105565Snate@binkert.org void 1115704Snate@binkert.org clearAll() 1125565Snate@binkert.org { 1135565Snate@binkert.org DPRINTF(Interrupt, "Interrupts all cleared\n"); 1143520Sgblack@eecs.umich.edu 1155565Snate@binkert.org memset(interrupts, 0, sizeof(interrupts)); 1165565Snate@binkert.org intstatus = 0; 1175565Snate@binkert.org } 1183520Sgblack@eecs.umich.edu 1195565Snate@binkert.org void 1205565Snate@binkert.org serialize(std::ostream &os) 1215565Snate@binkert.org { 1225565Snate@binkert.org SERIALIZE_ARRAY(interrupts, NumInterruptLevels); 1235565Snate@binkert.org SERIALIZE_SCALAR(intstatus); 1245565Snate@binkert.org } 1253520Sgblack@eecs.umich.edu 1265565Snate@binkert.org void 1275565Snate@binkert.org unserialize(Checkpoint *cp, const std::string §ion) 1285565Snate@binkert.org { 1295565Snate@binkert.org UNSERIALIZE_ARRAY(interrupts, NumInterruptLevels); 1305565Snate@binkert.org UNSERIALIZE_SCALAR(intstatus); 1315565Snate@binkert.org } 1323520Sgblack@eecs.umich.edu 1335565Snate@binkert.org bool 1345704Snate@binkert.org checkInterrupts(ThreadContext *tc) const 1355565Snate@binkert.org { 1367720Sgblack@eecs.umich.edu return (intstatus != 0) && !(tc->pcState().pc() & 0x3); 1375565Snate@binkert.org } 1383520Sgblack@eecs.umich.edu 1395565Snate@binkert.org Fault 1405565Snate@binkert.org getInterrupt(ThreadContext *tc) 1415565Snate@binkert.org { 1426227Snate@binkert.org uint64_t ipl = 0; 1436227Snate@binkert.org uint64_t summary = 0; 1443521Sgblack@eecs.umich.edu 1455565Snate@binkert.org if (tc->readMiscRegNoEffect(IPR_ASTRR)) 1465565Snate@binkert.org panic("asynchronous traps not implemented\n"); 1473520Sgblack@eecs.umich.edu 1485565Snate@binkert.org if (tc->readMiscRegNoEffect(IPR_SIRR)) { 1496227Snate@binkert.org for (uint64_t i = INTLEVEL_SOFTWARE_MIN; 1505565Snate@binkert.org i < INTLEVEL_SOFTWARE_MAX; i++) { 1515565Snate@binkert.org if (tc->readMiscRegNoEffect(IPR_SIRR) & (ULL(1) << i)) { 1525565Snate@binkert.org // See table 4-19 of 21164 hardware reference 1535565Snate@binkert.org ipl = (i - INTLEVEL_SOFTWARE_MIN) + 1; 1545565Snate@binkert.org summary |= (ULL(1) << i); 1553520Sgblack@eecs.umich.edu } 1563520Sgblack@eecs.umich.edu } 1573520Sgblack@eecs.umich.edu } 1583520Sgblack@eecs.umich.edu 1595565Snate@binkert.org uint64_t interrupts = intstatus; 1605565Snate@binkert.org if (interrupts) { 1616227Snate@binkert.org for (uint64_t i = INTLEVEL_EXTERNAL_MIN; 1625565Snate@binkert.org i < INTLEVEL_EXTERNAL_MAX; i++) { 1635565Snate@binkert.org if (interrupts & (ULL(1) << i)) { 1645565Snate@binkert.org // See table 4-19 of 21164 hardware reference 1655565Snate@binkert.org ipl = i; 1665565Snate@binkert.org summary |= (ULL(1) << i); 1675565Snate@binkert.org } 1685565Snate@binkert.org } 1693633Sktlim@umich.edu } 1703633Sktlim@umich.edu 1715565Snate@binkert.org if (ipl && ipl > tc->readMiscRegNoEffect(IPR_IPLR)) { 1725565Snate@binkert.org newIpl = ipl; 1735565Snate@binkert.org newSummary = summary; 1745565Snate@binkert.org newInfoSet = true; 1755565Snate@binkert.org DPRINTF(Flow, "Interrupt! IPLR=%d ipl=%d summary=%x\n", 1765565Snate@binkert.org tc->readMiscRegNoEffect(IPR_IPLR), ipl, summary); 1775565Snate@binkert.org 1785565Snate@binkert.org return new InterruptFault; 1795565Snate@binkert.org } else { 1805565Snate@binkert.org return NoFault; 1814103Ssaidi@eecs.umich.edu } 1825565Snate@binkert.org } 1834103Ssaidi@eecs.umich.edu 1845565Snate@binkert.org void 1855565Snate@binkert.org updateIntrInfo(ThreadContext *tc) 1865565Snate@binkert.org { 1875565Snate@binkert.org assert(newInfoSet); 1885565Snate@binkert.org tc->setMiscRegNoEffect(IPR_ISR, newSummary); 1895565Snate@binkert.org tc->setMiscRegNoEffect(IPR_INTID, newIpl); 1905565Snate@binkert.org newInfoSet = false; 1915565Snate@binkert.org } 1925565Snate@binkert.org}; 1933520Sgblack@eecs.umich.edu 1945565Snate@binkert.org} // namespace AlphaISA 1955565Snate@binkert.org 1965565Snate@binkert.org#endif // __ARCH_ALPHA_INTERRUPT_HH__ 1975565Snate@binkert.org 198