faults.cc revision 4111
12221SN/A/*
22221SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan
32221SN/A * All rights reserved.
42221SN/A *
52221SN/A * Redistribution and use in source and binary forms, with or without
62221SN/A * modification, are permitted provided that the following conditions are
72221SN/A * met: redistributions of source code must retain the above copyright
82221SN/A * notice, this list of conditions and the following disclaimer;
92221SN/A * redistributions in binary form must reproduce the above copyright
102221SN/A * notice, this list of conditions and the following disclaimer in the
112221SN/A * documentation and/or other materials provided with the distribution;
122221SN/A * neither the name of the copyright holders nor the names of its
132221SN/A * contributors may be used to endorse or promote products derived from
142221SN/A * this software without specific prior written permission.
152221SN/A *
162221SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172221SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182221SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192221SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202221SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212221SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222221SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232221SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242221SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252221SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262221SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Gabe Black
292665Ssaidi@eecs.umich.edu *          Kevin Lim
302221SN/A */
312221SN/A
323415Sgblack@eecs.umich.edu#include <algorithm>
333415Sgblack@eecs.umich.edu
342223SN/A#include "arch/sparc/faults.hh"
353415Sgblack@eecs.umich.edu#include "arch/sparc/isa_traits.hh"
363578Sgblack@eecs.umich.edu#include "arch/sparc/types.hh"
373415Sgblack@eecs.umich.edu#include "base/bitfield.hh"
383415Sgblack@eecs.umich.edu#include "base/trace.hh"
393523Sgblack@eecs.umich.edu#include "config/full_system.hh"
403415Sgblack@eecs.umich.edu#include "cpu/base.hh"
412680Sktlim@umich.edu#include "cpu/thread_context.hh"
422800Ssaidi@eecs.umich.edu#if !FULL_SYSTEM
433523Sgblack@eecs.umich.edu#include "arch/sparc/process.hh"
443415Sgblack@eecs.umich.edu#include "mem/page_table.hh"
452800Ssaidi@eecs.umich.edu#include "sim/process.hh"
462800Ssaidi@eecs.umich.edu#endif
472221SN/A
483415Sgblack@eecs.umich.eduusing namespace std;
493415Sgblack@eecs.umich.edu
502223SN/Anamespace SparcISA
512221SN/A{
522221SN/A
533573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
543576Sgblack@eecs.umich.edu    SparcFault<PowerOnReset>::vals =
553576Sgblack@eecs.umich.edu    {"power_on_reset", 0x001, 0, {H, H, H}};
562221SN/A
573573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
583576Sgblack@eecs.umich.edu    SparcFault<WatchDogReset>::vals =
593576Sgblack@eecs.umich.edu    {"watch_dog_reset", 0x002, 120, {H, H, H}};
602221SN/A
613573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
623576Sgblack@eecs.umich.edu    SparcFault<ExternallyInitiatedReset>::vals =
633576Sgblack@eecs.umich.edu    {"externally_initiated_reset", 0x003, 110, {H, H, H}};
642221SN/A
653573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
663576Sgblack@eecs.umich.edu    SparcFault<SoftwareInitiatedReset>::vals =
673576Sgblack@eecs.umich.edu    {"software_initiated_reset", 0x004, 130, {SH, SH, H}};
682221SN/A
693573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
703576Sgblack@eecs.umich.edu    SparcFault<REDStateException>::vals =
713576Sgblack@eecs.umich.edu    {"RED_state_exception", 0x005, 1, {H, H, H}};
722221SN/A
733573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
743576Sgblack@eecs.umich.edu    SparcFault<StoreError>::vals =
753576Sgblack@eecs.umich.edu    {"store_error", 0x007, 201, {H, H, H}};
762221SN/A
773573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
783576Sgblack@eecs.umich.edu    SparcFault<InstructionAccessException>::vals =
793576Sgblack@eecs.umich.edu    {"instruction_access_exception", 0x008, 300, {H, H, H}};
803576Sgblack@eecs.umich.edu
813576Sgblack@eecs.umich.edu//XXX This trap is apparently dropped from ua2005
823576Sgblack@eecs.umich.edu/*template<> SparcFaultBase::FaultVals
833576Sgblack@eecs.umich.edu    SparcFault<InstructionAccessMMUMiss>::vals =
843576Sgblack@eecs.umich.edu    {"inst_mmu", 0x009, 2, {H, H, H}};*/
852221SN/A
863573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
873576Sgblack@eecs.umich.edu    SparcFault<InstructionAccessError>::vals =
883576Sgblack@eecs.umich.edu    {"instruction_access_error", 0x00A, 400, {H, H, H}};
892221SN/A
903573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
913576Sgblack@eecs.umich.edu    SparcFault<IllegalInstruction>::vals =
923576Sgblack@eecs.umich.edu    {"illegal_instruction", 0x010, 620, {H, H, H}};
932221SN/A
943573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
953576Sgblack@eecs.umich.edu    SparcFault<PrivilegedOpcode>::vals =
963576Sgblack@eecs.umich.edu    {"privileged_opcode", 0x011, 700, {P, SH, SH}};
973576Sgblack@eecs.umich.edu
983576Sgblack@eecs.umich.edu//XXX This trap is apparently dropped from ua2005
993576Sgblack@eecs.umich.edu/*template<> SparcFaultBase::FaultVals
1003576Sgblack@eecs.umich.edu    SparcFault<UnimplementedLDD>::vals =
1013576Sgblack@eecs.umich.edu    {"unimp_ldd", 0x012, 6, {H, H, H}};*/
1023576Sgblack@eecs.umich.edu
1033576Sgblack@eecs.umich.edu//XXX This trap is apparently dropped from ua2005
1043576Sgblack@eecs.umich.edu/*template<> SparcFaultBase::FaultVals
1053576Sgblack@eecs.umich.edu    SparcFault<UnimplementedSTD>::vals =
1063576Sgblack@eecs.umich.edu    {"unimp_std", 0x013, 6, {H, H, H}};*/
1072221SN/A
1083573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1093576Sgblack@eecs.umich.edu    SparcFault<FpDisabled>::vals =
1103576Sgblack@eecs.umich.edu    {"fp_disabled", 0x020, 800, {P, P, H}};
1112221SN/A
1123573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1133576Sgblack@eecs.umich.edu    SparcFault<FpExceptionIEEE754>::vals =
1143576Sgblack@eecs.umich.edu    {"fp_exception_ieee_754", 0x021, 1110, {P, P, H}};
1152221SN/A
1163573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1173576Sgblack@eecs.umich.edu    SparcFault<FpExceptionOther>::vals =
1183576Sgblack@eecs.umich.edu    {"fp_exception_other", 0x022, 1110, {P, P, H}};
1192221SN/A
1203573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1213576Sgblack@eecs.umich.edu    SparcFault<TagOverflow>::vals =
1223576Sgblack@eecs.umich.edu    {"tag_overflow", 0x023, 1400, {P, P, H}};
1232221SN/A
1243573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1253576Sgblack@eecs.umich.edu    SparcFault<CleanWindow>::vals =
1263576Sgblack@eecs.umich.edu    {"clean_window", 0x024, 1010, {P, P, H}};
1272221SN/A
1283573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1293576Sgblack@eecs.umich.edu    SparcFault<DivisionByZero>::vals =
1303576Sgblack@eecs.umich.edu    {"division_by_zero", 0x028, 1500, {P, P, H}};
1312223SN/A
1323573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1333576Sgblack@eecs.umich.edu    SparcFault<InternalProcessorError>::vals =
1343576Sgblack@eecs.umich.edu    {"internal_processor_error", 0x029, 4, {H, H, H}};
1352223SN/A
1363573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1373576Sgblack@eecs.umich.edu    SparcFault<InstructionInvalidTSBEntry>::vals =
1383576Sgblack@eecs.umich.edu    {"instruction_invalid_tsb_entry", 0x02A, 210, {H, H, SH}};
1392223SN/A
1403573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1413576Sgblack@eecs.umich.edu    SparcFault<DataInvalidTSBEntry>::vals =
1423576Sgblack@eecs.umich.edu    {"data_invalid_tsb_entry", 0x02B, 1203, {H, H, H}};
1432223SN/A
1443573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1453576Sgblack@eecs.umich.edu    SparcFault<DataAccessException>::vals =
1463576Sgblack@eecs.umich.edu    {"data_access_exception", 0x030, 1201, {H, H, H}};
1473576Sgblack@eecs.umich.edu
1483576Sgblack@eecs.umich.edu//XXX This trap is apparently dropped from ua2005
1493576Sgblack@eecs.umich.edu/*template<> SparcFaultBase::FaultVals
1503576Sgblack@eecs.umich.edu    SparcFault<DataAccessMMUMiss>::vals =
1513576Sgblack@eecs.umich.edu    {"data_mmu", 0x031, 12, {H, H, H}};*/
1522223SN/A
1533573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1543576Sgblack@eecs.umich.edu    SparcFault<DataAccessError>::vals =
1553576Sgblack@eecs.umich.edu    {"data_access_error", 0x032, 1210, {H, H, H}};
1562223SN/A
1573573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1583576Sgblack@eecs.umich.edu    SparcFault<DataAccessProtection>::vals =
1593576Sgblack@eecs.umich.edu    {"data_access_protection", 0x033, 1207, {H, H, H}};
1602223SN/A
1613573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1623576Sgblack@eecs.umich.edu    SparcFault<MemAddressNotAligned>::vals =
1633576Sgblack@eecs.umich.edu    {"mem_address_not_aligned", 0x034, 1020, {H, H, H}};
1642223SN/A
1653573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1663576Sgblack@eecs.umich.edu    SparcFault<LDDFMemAddressNotAligned>::vals =
1673576Sgblack@eecs.umich.edu    {"LDDF_mem_address_not_aligned", 0x035, 1010, {H, H, H}};
1682223SN/A
1693573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1703576Sgblack@eecs.umich.edu    SparcFault<STDFMemAddressNotAligned>::vals =
1713576Sgblack@eecs.umich.edu    {"STDF_mem_address_not_aligned", 0x036, 1010, {H, H, H}};
1722223SN/A
1733573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1743576Sgblack@eecs.umich.edu    SparcFault<PrivilegedAction>::vals =
1753576Sgblack@eecs.umich.edu    {"privileged_action", 0x037, 1110, {H, H, SH}};
1762223SN/A
1773573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1783576Sgblack@eecs.umich.edu    SparcFault<LDQFMemAddressNotAligned>::vals =
1793576Sgblack@eecs.umich.edu    {"LDQF_mem_address_not_aligned", 0x038, 1010, {H, H, H}};
1802223SN/A
1813573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1823576Sgblack@eecs.umich.edu    SparcFault<STQFMemAddressNotAligned>::vals =
1833576Sgblack@eecs.umich.edu    {"STQF_mem_address_not_aligned", 0x039, 1010, {H, H, H}};
1842223SN/A
1853573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1863576Sgblack@eecs.umich.edu    SparcFault<InstructionRealTranslationMiss>::vals =
1873576Sgblack@eecs.umich.edu    {"instruction_real_translation_miss", 0x03E, 208, {H, H, SH}};
1882223SN/A
1893573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1903576Sgblack@eecs.umich.edu    SparcFault<DataRealTranslationMiss>::vals =
1913576Sgblack@eecs.umich.edu    {"data_real_translation_miss", 0x03F, 1203, {H, H, H}};
1922223SN/A
1933576Sgblack@eecs.umich.edu//XXX This trap is apparently dropped from ua2005
1943576Sgblack@eecs.umich.edu/*template<> SparcFaultBase::FaultVals
1953576Sgblack@eecs.umich.edu    SparcFault<AsyncDataError>::vals =
1963576Sgblack@eecs.umich.edu    {"async_data", 0x040, 2, {H, H, H}};*/
1972527SN/A
1983573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
1993576Sgblack@eecs.umich.edu    SparcFault<InterruptLevelN>::vals =
2003890Ssaidi@eecs.umich.edu    {"interrupt_level_n", 0x040, 0, {P, P, SH}};
2012223SN/A
2023573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2033576Sgblack@eecs.umich.edu    SparcFault<HstickMatch>::vals =
2043576Sgblack@eecs.umich.edu    {"hstick_match", 0x05E, 1601, {H, H, H}};
2052223SN/A
2063573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2073576Sgblack@eecs.umich.edu    SparcFault<TrapLevelZero>::vals =
2083576Sgblack@eecs.umich.edu    {"trap_level_zero", 0x05F, 202, {H, H, SH}};
2092223SN/A
2103573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2113576Sgblack@eecs.umich.edu    SparcFault<PAWatchpoint>::vals =
2123576Sgblack@eecs.umich.edu    {"PA_watchpoint", 0x061, 1209, {H, H, H}};
2132223SN/A
2143573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2153576Sgblack@eecs.umich.edu    SparcFault<VAWatchpoint>::vals =
2163576Sgblack@eecs.umich.edu    {"VA_watchpoint", 0x062, 1120, {P, P, SH}};
2172223SN/A
2183573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2193576Sgblack@eecs.umich.edu    SparcFault<FastInstructionAccessMMUMiss>::vals =
2203576Sgblack@eecs.umich.edu    {"fast_instruction_access_MMU_miss", 0x064, 208, {H, H, SH}};
2213576Sgblack@eecs.umich.edu
2223576Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2233576Sgblack@eecs.umich.edu    SparcFault<FastDataAccessMMUMiss>::vals =
2243576Sgblack@eecs.umich.edu    {"fast_data_access_MMU_miss", 0x068, 1203, {H, H, H}};
2253576Sgblack@eecs.umich.edu
2263576Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2273576Sgblack@eecs.umich.edu    SparcFault<FastDataAccessProtection>::vals =
2283576Sgblack@eecs.umich.edu    {"fast_data_access_protection", 0x06C, 1207, {H, H, H}};
2293576Sgblack@eecs.umich.edu
2303576Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2313576Sgblack@eecs.umich.edu    SparcFault<InstructionBreakpoint>::vals =
2323576Sgblack@eecs.umich.edu    {"instruction_break", 0x076, 610, {H, H, H}};
2333576Sgblack@eecs.umich.edu
2343576Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2353576Sgblack@eecs.umich.edu    SparcFault<CpuMondo>::vals =
2363576Sgblack@eecs.umich.edu    {"cpu_mondo", 0x07C, 1608, {P, P, SH}};
2373576Sgblack@eecs.umich.edu
2383576Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2393576Sgblack@eecs.umich.edu    SparcFault<DevMondo>::vals =
2403576Sgblack@eecs.umich.edu    {"dev_mondo", 0x07D, 1611, {P, P, SH}};
2413576Sgblack@eecs.umich.edu
2423576Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2433893Shsul@eecs.umich.edu    SparcFault<ResumableError>::vals =
2443576Sgblack@eecs.umich.edu    {"resume_error", 0x07E, 3330, {P, P, SH}};
2453576Sgblack@eecs.umich.edu
2463576Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2473576Sgblack@eecs.umich.edu    SparcFault<SpillNNormal>::vals =
2483576Sgblack@eecs.umich.edu    {"spill_n_normal", 0x080, 900, {P, P, H}};
2493576Sgblack@eecs.umich.edu
2503576Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2513576Sgblack@eecs.umich.edu    SparcFault<SpillNOther>::vals =
2523576Sgblack@eecs.umich.edu    {"spill_n_other", 0x0A0, 900, {P, P, H}};
2533576Sgblack@eecs.umich.edu
2543576Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2553576Sgblack@eecs.umich.edu    SparcFault<FillNNormal>::vals =
2563576Sgblack@eecs.umich.edu    {"fill_n_normal", 0x0C0, 900, {P, P, H}};
2573576Sgblack@eecs.umich.edu
2583576Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2593576Sgblack@eecs.umich.edu    SparcFault<FillNOther>::vals =
2603576Sgblack@eecs.umich.edu    {"fill_n_other", 0x0E0, 900, {P, P, H}};
2613576Sgblack@eecs.umich.edu
2623576Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2633576Sgblack@eecs.umich.edu    SparcFault<TrapInstruction>::vals =
2643576Sgblack@eecs.umich.edu    {"trap_instruction", 0x100, 1602, {P, P, H}};
2652223SN/A
2662800Ssaidi@eecs.umich.edu#if !FULL_SYSTEM
2673573Sgblack@eecs.umich.edutemplate<> SparcFaultBase::FaultVals
2683576Sgblack@eecs.umich.edu    SparcFault<PageTableFault>::vals =
2693576Sgblack@eecs.umich.edu    {"page_table_fault", 0x0000, 0, {SH, SH, SH}};
2702800Ssaidi@eecs.umich.edu#endif
2712800Ssaidi@eecs.umich.edu
2723415Sgblack@eecs.umich.edu/**
2733578Sgblack@eecs.umich.edu * This causes the thread context to enter RED state. This causes the side
2743578Sgblack@eecs.umich.edu * effects which go with entering RED state because of a trap.
2753415Sgblack@eecs.umich.edu */
2763415Sgblack@eecs.umich.edu
2773578Sgblack@eecs.umich.eduvoid enterREDState(ThreadContext *tc)
2783415Sgblack@eecs.umich.edu{
2793578Sgblack@eecs.umich.edu    //@todo Disable the mmu?
2803578Sgblack@eecs.umich.edu    //@todo Disable watchpoints?
2813578Sgblack@eecs.umich.edu    MiscReg HPSTATE = tc->readMiscReg(MISCREG_HPSTATE);
2823578Sgblack@eecs.umich.edu    //HPSTATE.red = 1
2833578Sgblack@eecs.umich.edu    HPSTATE |= (1 << 5);
2843578Sgblack@eecs.umich.edu    //HPSTATE.hpriv = 1
2853578Sgblack@eecs.umich.edu    HPSTATE |= (1 << 2);
2863595Sgblack@eecs.umich.edu    tc->setMiscRegWithEffect(MISCREG_HPSTATE, HPSTATE);
2873746Sgblack@eecs.umich.edu    //PSTATE.priv is set to 1 here. The manual says it should be 0, but
2883746Sgblack@eecs.umich.edu    //Legion sets it to 1.
2893746Sgblack@eecs.umich.edu    MiscReg PSTATE = tc->readMiscReg(MISCREG_PSTATE);
2903746Sgblack@eecs.umich.edu    PSTATE |= (1 << 2);
2913746Sgblack@eecs.umich.edu    tc->setMiscRegWithEffect(MISCREG_PSTATE, PSTATE);
2923578Sgblack@eecs.umich.edu}
2933578Sgblack@eecs.umich.edu
2943578Sgblack@eecs.umich.edu/**
2953578Sgblack@eecs.umich.edu * This sets everything up for a RED state trap except for actually jumping to
2963578Sgblack@eecs.umich.edu * the handler.
2973578Sgblack@eecs.umich.edu */
2983578Sgblack@eecs.umich.edu
2993578Sgblack@eecs.umich.eduvoid doREDFault(ThreadContext *tc, TrapType tt)
3003578Sgblack@eecs.umich.edu{
3013578Sgblack@eecs.umich.edu    MiscReg TL = tc->readMiscReg(MISCREG_TL);
3023578Sgblack@eecs.umich.edu    MiscReg TSTATE = tc->readMiscReg(MISCREG_TSTATE);
3033578Sgblack@eecs.umich.edu    MiscReg PSTATE = tc->readMiscReg(MISCREG_PSTATE);
3043578Sgblack@eecs.umich.edu    MiscReg HPSTATE = tc->readMiscReg(MISCREG_HPSTATE);
3053761Sgblack@eecs.umich.edu    //MiscReg CCR = tc->readMiscReg(MISCREG_CCR);
3063761Sgblack@eecs.umich.edu    MiscReg CCR = tc->readIntReg(NumIntArchRegs + 2);
3073578Sgblack@eecs.umich.edu    MiscReg ASI = tc->readMiscReg(MISCREG_ASI);
3083578Sgblack@eecs.umich.edu    MiscReg CWP = tc->readMiscReg(MISCREG_CWP);
3093761Sgblack@eecs.umich.edu    //MiscReg CANSAVE = tc->readMiscReg(MISCREG_CANSAVE);
3103761Sgblack@eecs.umich.edu    MiscReg CANSAVE = tc->readMiscReg(NumIntArchRegs + 3);
3113578Sgblack@eecs.umich.edu    MiscReg GL = tc->readMiscReg(MISCREG_GL);
3123578Sgblack@eecs.umich.edu    MiscReg PC = tc->readPC();
3133578Sgblack@eecs.umich.edu    MiscReg NPC = tc->readNextPC();
3143578Sgblack@eecs.umich.edu
3153578Sgblack@eecs.umich.edu    TL++;
3163578Sgblack@eecs.umich.edu
3173928Ssaidi@eecs.umich.edu    if (bits(PSTATE, 3,3)) {
3183928Ssaidi@eecs.umich.edu        PC &= mask(32);
3193928Ssaidi@eecs.umich.edu        NPC &= mask(32);
3203928Ssaidi@eecs.umich.edu    }
3213928Ssaidi@eecs.umich.edu
3223578Sgblack@eecs.umich.edu    //set TSTATE.gl to gl
3233578Sgblack@eecs.umich.edu    replaceBits(TSTATE, 42, 40, GL);
3243578Sgblack@eecs.umich.edu    //set TSTATE.ccr to ccr
3253578Sgblack@eecs.umich.edu    replaceBits(TSTATE, 39, 32, CCR);
3263578Sgblack@eecs.umich.edu    //set TSTATE.asi to asi
3273578Sgblack@eecs.umich.edu    replaceBits(TSTATE, 31, 24, ASI);
3283578Sgblack@eecs.umich.edu    //set TSTATE.pstate to pstate
3293578Sgblack@eecs.umich.edu    replaceBits(TSTATE, 20, 8, PSTATE);
3303578Sgblack@eecs.umich.edu    //set TSTATE.cwp to cwp
3313578Sgblack@eecs.umich.edu    replaceBits(TSTATE, 4, 0, CWP);
3323578Sgblack@eecs.umich.edu
3333578Sgblack@eecs.umich.edu    //Write back TSTATE
3343578Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_TSTATE, TSTATE);
3353578Sgblack@eecs.umich.edu
3363578Sgblack@eecs.umich.edu    //set TPC to PC
3373578Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_TPC, PC);
3383578Sgblack@eecs.umich.edu    //set TNPC to NPC
3393578Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_TNPC, NPC);
3403578Sgblack@eecs.umich.edu
3413578Sgblack@eecs.umich.edu    //set HTSTATE.hpstate to hpstate
3423578Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_HTSTATE, HPSTATE);
3433578Sgblack@eecs.umich.edu
3443578Sgblack@eecs.umich.edu    //TT = trap type;
3453578Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_TT, tt);
3463578Sgblack@eecs.umich.edu
3473578Sgblack@eecs.umich.edu    //Update GL
3483578Sgblack@eecs.umich.edu    tc->setMiscRegWithEffect(MISCREG_GL, min<int>(GL+1, MaxGL));
3493578Sgblack@eecs.umich.edu
3503926Ssaidi@eecs.umich.edu    PSTATE = mbits(PSTATE, 2, 2); // just save the priv bit
3513926Ssaidi@eecs.umich.edu    PSTATE |= (1 << 4); //set PSTATE.pef to 1
3523578Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_PSTATE, PSTATE);
3533578Sgblack@eecs.umich.edu
3543578Sgblack@eecs.umich.edu    //set HPSTATE.red to 1
3553578Sgblack@eecs.umich.edu    HPSTATE |= (1 << 5);
3563578Sgblack@eecs.umich.edu    //set HPSTATE.hpriv to 1
3573578Sgblack@eecs.umich.edu    HPSTATE |= (1 << 2);
3583578Sgblack@eecs.umich.edu    //set HPSTATE.ibe to 0
3593578Sgblack@eecs.umich.edu    HPSTATE &= ~(1 << 10);
3603578Sgblack@eecs.umich.edu    //set HPSTATE.tlz to 0
3613578Sgblack@eecs.umich.edu    HPSTATE &= ~(1 << 0);
3623578Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_HPSTATE, HPSTATE);
3633578Sgblack@eecs.umich.edu
3643578Sgblack@eecs.umich.edu    bool changedCWP = true;
3653578Sgblack@eecs.umich.edu    if(tt == 0x24)
3663578Sgblack@eecs.umich.edu        CWP++;
3673578Sgblack@eecs.umich.edu    else if(0x80 <= tt && tt <= 0xbf)
3683578Sgblack@eecs.umich.edu        CWP += (CANSAVE + 2);
3693578Sgblack@eecs.umich.edu    else if(0xc0 <= tt && tt <= 0xff)
3703578Sgblack@eecs.umich.edu        CWP--;
3713578Sgblack@eecs.umich.edu    else
3723578Sgblack@eecs.umich.edu        changedCWP = false;
3733578Sgblack@eecs.umich.edu
3743578Sgblack@eecs.umich.edu    if(changedCWP)
3753578Sgblack@eecs.umich.edu    {
3763578Sgblack@eecs.umich.edu        CWP = (CWP + NWindows) % NWindows;
3773578Sgblack@eecs.umich.edu        tc->setMiscRegWithEffect(MISCREG_CWP, CWP);
3783578Sgblack@eecs.umich.edu    }
3793578Sgblack@eecs.umich.edu}
3803578Sgblack@eecs.umich.edu
3813578Sgblack@eecs.umich.edu/**
3823578Sgblack@eecs.umich.edu * This sets everything up for a normal trap except for actually jumping to
3833578Sgblack@eecs.umich.edu * the handler.
3843578Sgblack@eecs.umich.edu */
3853578Sgblack@eecs.umich.edu
3863578Sgblack@eecs.umich.eduvoid doNormalFault(ThreadContext *tc, TrapType tt, bool gotoHpriv)
3873578Sgblack@eecs.umich.edu{
3883578Sgblack@eecs.umich.edu    MiscReg TL = tc->readMiscReg(MISCREG_TL);
3893578Sgblack@eecs.umich.edu    MiscReg TSTATE = tc->readMiscReg(MISCREG_TSTATE);
3903578Sgblack@eecs.umich.edu    MiscReg PSTATE = tc->readMiscReg(MISCREG_PSTATE);
3913578Sgblack@eecs.umich.edu    MiscReg HPSTATE = tc->readMiscReg(MISCREG_HPSTATE);
3923761Sgblack@eecs.umich.edu    //MiscReg CCR = tc->readMiscReg(MISCREG_CCR);
3933761Sgblack@eecs.umich.edu    MiscReg CCR = tc->readIntReg(NumIntArchRegs + 2);
3943578Sgblack@eecs.umich.edu    MiscReg ASI = tc->readMiscReg(MISCREG_ASI);
3953578Sgblack@eecs.umich.edu    MiscReg CWP = tc->readMiscReg(MISCREG_CWP);
3963761Sgblack@eecs.umich.edu    //MiscReg CANSAVE = tc->readMiscReg(MISCREG_CANSAVE);
3973761Sgblack@eecs.umich.edu    MiscReg CANSAVE = tc->readIntReg(NumIntArchRegs + 3);
3983578Sgblack@eecs.umich.edu    MiscReg GL = tc->readMiscReg(MISCREG_GL);
3993578Sgblack@eecs.umich.edu    MiscReg PC = tc->readPC();
4003578Sgblack@eecs.umich.edu    MiscReg NPC = tc->readNextPC();
4013415Sgblack@eecs.umich.edu
4023928Ssaidi@eecs.umich.edu    if (bits(PSTATE, 3,3)) {
4033928Ssaidi@eecs.umich.edu        PC &= mask(32);
4043928Ssaidi@eecs.umich.edu        NPC &= mask(32);
4053928Ssaidi@eecs.umich.edu    }
4063928Ssaidi@eecs.umich.edu
4073415Sgblack@eecs.umich.edu    //Increment the trap level
4083415Sgblack@eecs.umich.edu    TL++;
4093415Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_TL, TL);
4103415Sgblack@eecs.umich.edu
4113415Sgblack@eecs.umich.edu    //Save off state
4123415Sgblack@eecs.umich.edu
4133415Sgblack@eecs.umich.edu    //set TSTATE.gl to gl
4143415Sgblack@eecs.umich.edu    replaceBits(TSTATE, 42, 40, GL);
4153415Sgblack@eecs.umich.edu    //set TSTATE.ccr to ccr
4163415Sgblack@eecs.umich.edu    replaceBits(TSTATE, 39, 32, CCR);
4173415Sgblack@eecs.umich.edu    //set TSTATE.asi to asi
4183415Sgblack@eecs.umich.edu    replaceBits(TSTATE, 31, 24, ASI);
4193415Sgblack@eecs.umich.edu    //set TSTATE.pstate to pstate
4203415Sgblack@eecs.umich.edu    replaceBits(TSTATE, 20, 8, PSTATE);
4213415Sgblack@eecs.umich.edu    //set TSTATE.cwp to cwp
4223415Sgblack@eecs.umich.edu    replaceBits(TSTATE, 4, 0, CWP);
4233415Sgblack@eecs.umich.edu
4243415Sgblack@eecs.umich.edu    //Write back TSTATE
4253415Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_TSTATE, TSTATE);
4263415Sgblack@eecs.umich.edu
4273415Sgblack@eecs.umich.edu    //set TPC to PC
4283415Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_TPC, PC);
4293415Sgblack@eecs.umich.edu    //set TNPC to NPC
4303415Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_TNPC, NPC);
4313415Sgblack@eecs.umich.edu
4323415Sgblack@eecs.umich.edu    //set HTSTATE.hpstate to hpstate
4333415Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_HTSTATE, HPSTATE);
4343415Sgblack@eecs.umich.edu
4353415Sgblack@eecs.umich.edu    //TT = trap type;
4363415Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_TT, tt);
4373415Sgblack@eecs.umich.edu
4383415Sgblack@eecs.umich.edu    //Update the global register level
4393893Shsul@eecs.umich.edu    if (!gotoHpriv)
4403578Sgblack@eecs.umich.edu        tc->setMiscRegWithEffect(MISCREG_GL, min<int>(GL+1, MaxPGL));
4413415Sgblack@eecs.umich.edu    else
4423578Sgblack@eecs.umich.edu        tc->setMiscRegWithEffect(MISCREG_GL, min<int>(GL+1, MaxGL));
4433415Sgblack@eecs.umich.edu
4443415Sgblack@eecs.umich.edu    //PSTATE.mm is unchanged
4453926Ssaidi@eecs.umich.edu    PSTATE |= (1 << 4); //PSTATE.pef = whether or not an fpu is present
4463926Ssaidi@eecs.umich.edu    PSTATE &= ~(1 << 3); //PSTATE.am = 0
4473926Ssaidi@eecs.umich.edu    PSTATE &= ~(1 << 1); //PSTATE.ie = 0
4483415Sgblack@eecs.umich.edu    //PSTATE.tle is unchanged
4493415Sgblack@eecs.umich.edu    //PSTATE.tct = 0
4503415Sgblack@eecs.umich.edu
4513893Shsul@eecs.umich.edu    if (gotoHpriv)
4523415Sgblack@eecs.umich.edu    {
4533926Ssaidi@eecs.umich.edu        PSTATE &= ~(1 << 9); // PSTATE.cle = 0
4543926Ssaidi@eecs.umich.edu        //The manual says PSTATE.priv should be 0, but Legion leaves it alone
4553926Ssaidi@eecs.umich.edu        HPSTATE &= ~(1 << 5); //HPSTATE.red = 0
4563926Ssaidi@eecs.umich.edu        HPSTATE |= (1 << 2); //HPSTATE.hpriv = 1
4573926Ssaidi@eecs.umich.edu        HPSTATE &= ~(1 << 10); //HPSTATE.ibe = 0
4583415Sgblack@eecs.umich.edu        //HPSTATE.tlz is unchanged
4593415Sgblack@eecs.umich.edu        tc->setMiscReg(MISCREG_HPSTATE, HPSTATE);
4603926Ssaidi@eecs.umich.edu    } else { // we are going to priv
4613926Ssaidi@eecs.umich.edu        PSTATE |= (1 << 2); //PSTATE.priv = 1
4623926Ssaidi@eecs.umich.edu        replaceBits(PSTATE, 9, 9, PSTATE >> 8); //PSTATE.cle = PSTATE.tle
4633415Sgblack@eecs.umich.edu    }
4643926Ssaidi@eecs.umich.edu    tc->setMiscReg(MISCREG_PSTATE, PSTATE);
4653926Ssaidi@eecs.umich.edu
4663415Sgblack@eecs.umich.edu
4673415Sgblack@eecs.umich.edu    bool changedCWP = true;
4683893Shsul@eecs.umich.edu    if (tt == 0x24)
4693415Sgblack@eecs.umich.edu        CWP++;
4703893Shsul@eecs.umich.edu    else if (0x80 <= tt && tt <= 0xbf)
4713415Sgblack@eecs.umich.edu        CWP += (CANSAVE + 2);
4723893Shsul@eecs.umich.edu    else if (0xc0 <= tt && tt <= 0xff)
4733415Sgblack@eecs.umich.edu        CWP--;
4743415Sgblack@eecs.umich.edu    else
4753415Sgblack@eecs.umich.edu        changedCWP = false;
4763420Sgblack@eecs.umich.edu
4773893Shsul@eecs.umich.edu    if (changedCWP)
4783415Sgblack@eecs.umich.edu    {
4793415Sgblack@eecs.umich.edu        CWP = (CWP + NWindows) % NWindows;
4803415Sgblack@eecs.umich.edu        tc->setMiscRegWithEffect(MISCREG_CWP, CWP);
4813415Sgblack@eecs.umich.edu    }
4823415Sgblack@eecs.umich.edu}
4833415Sgblack@eecs.umich.edu
4843595Sgblack@eecs.umich.eduvoid getREDVector(MiscReg TT, Addr & PC, Addr & NPC)
4853578Sgblack@eecs.umich.edu{
4863585Sgblack@eecs.umich.edu    //XXX The following constant might belong in a header file.
4873603Ssaidi@eecs.umich.edu    const Addr RSTVAddr = 0xFFF0000000ULL;
4883595Sgblack@eecs.umich.edu    PC = RSTVAddr | ((TT << 5) & 0xFF);
4893578Sgblack@eecs.umich.edu    NPC = PC + sizeof(MachInst);
4903578Sgblack@eecs.umich.edu}
4913578Sgblack@eecs.umich.edu
4923585Sgblack@eecs.umich.eduvoid getHyperVector(ThreadContext * tc, Addr & PC, Addr & NPC, MiscReg TT)
4933578Sgblack@eecs.umich.edu{
4943585Sgblack@eecs.umich.edu    Addr HTBA = tc->readMiscReg(MISCREG_HTBA);
4953578Sgblack@eecs.umich.edu    PC = (HTBA & ~mask(14)) | ((TT << 5) & mask(14));
4963578Sgblack@eecs.umich.edu    NPC = PC + sizeof(MachInst);
4973578Sgblack@eecs.umich.edu}
4983578Sgblack@eecs.umich.edu
4993585Sgblack@eecs.umich.eduvoid getPrivVector(ThreadContext * tc, Addr & PC, Addr & NPC, MiscReg TT, MiscReg TL)
5003578Sgblack@eecs.umich.edu{
5013585Sgblack@eecs.umich.edu    Addr TBA = tc->readMiscReg(MISCREG_TBA);
5023578Sgblack@eecs.umich.edu    PC = (TBA & ~mask(15)) |
5033578Sgblack@eecs.umich.edu        (TL > 1 ? (1 << 14) : 0) |
5043578Sgblack@eecs.umich.edu        ((TT << 5) & mask(14));
5053578Sgblack@eecs.umich.edu    NPC = PC + sizeof(MachInst);
5063578Sgblack@eecs.umich.edu}
5073578Sgblack@eecs.umich.edu
5082221SN/A#if FULL_SYSTEM
5092221SN/A
5103573Sgblack@eecs.umich.eduvoid SparcFaultBase::invoke(ThreadContext * tc)
5112221SN/A{
5123825Ssaidi@eecs.umich.edu    //panic("Invoking a second fault!\n");
5132680Sktlim@umich.edu    FaultBase::invoke(tc);
5142223SN/A    countStat()++;
5152221SN/A
5163578Sgblack@eecs.umich.edu    //We can refer to this to see what the trap level -was-, but something
5173578Sgblack@eecs.umich.edu    //in the middle could change it in the regfile out from under us.
5183893Shsul@eecs.umich.edu    MiscReg tl = tc->readMiscReg(MISCREG_TL);
5193893Shsul@eecs.umich.edu    MiscReg tt = tc->readMiscReg(MISCREG_TT);
5203893Shsul@eecs.umich.edu    MiscReg pstate = tc->readMiscReg(MISCREG_PSTATE);
5213893Shsul@eecs.umich.edu    MiscReg hpstate = tc->readMiscReg(MISCREG_HPSTATE);
5223578Sgblack@eecs.umich.edu
5233578Sgblack@eecs.umich.edu    Addr PC, NPC;
5243578Sgblack@eecs.umich.edu
5253578Sgblack@eecs.umich.edu    PrivilegeLevel current;
5263893Shsul@eecs.umich.edu    if (hpstate & HPSTATE::hpriv)
5273746Sgblack@eecs.umich.edu        current = Hyperprivileged;
5283893Shsul@eecs.umich.edu    else if (pstate & PSTATE::priv)
5293578Sgblack@eecs.umich.edu        current = Privileged;
5303578Sgblack@eecs.umich.edu    else
5313746Sgblack@eecs.umich.edu        current = User;
5323578Sgblack@eecs.umich.edu
5333578Sgblack@eecs.umich.edu    PrivilegeLevel level = getNextLevel(current);
5343578Sgblack@eecs.umich.edu
5353893Shsul@eecs.umich.edu    if ((hpstate & HPSTATE::red) || (tl == MaxTL - 1)) {
5363595Sgblack@eecs.umich.edu        getREDVector(5, PC, NPC);
5373893Shsul@eecs.umich.edu        doREDFault(tc, tt);
5383746Sgblack@eecs.umich.edu        //This changes the hpstate and pstate, so we need to make sure we
5393746Sgblack@eecs.umich.edu        //save the old version on the trap stack in doREDFault.
5403578Sgblack@eecs.umich.edu        enterREDState(tc);
5413893Shsul@eecs.umich.edu    } else if (tl == MaxTL) {
5423825Ssaidi@eecs.umich.edu        panic("Should go to error state here.. crap\n");
5433578Sgblack@eecs.umich.edu        //Do error_state somehow?
5443578Sgblack@eecs.umich.edu        //Probably inject a WDR fault using the interrupt mechanism.
5453578Sgblack@eecs.umich.edu        //What should the PC and NPC be set to?
5463893Shsul@eecs.umich.edu    } else if (tl > MaxPTL && level == Privileged) {
5473578Sgblack@eecs.umich.edu        //guest_watchdog fault
5483578Sgblack@eecs.umich.edu        doNormalFault(tc, trapType(), true);
5493585Sgblack@eecs.umich.edu        getHyperVector(tc, PC, NPC, 2);
5503893Shsul@eecs.umich.edu    } else if (level == Hyperprivileged ||
5513826Ssaidi@eecs.umich.edu            level == Privileged && trapType() >= 384) {
5523578Sgblack@eecs.umich.edu        doNormalFault(tc, trapType(), true);
5533585Sgblack@eecs.umich.edu        getHyperVector(tc, PC, NPC, trapType());
5543826Ssaidi@eecs.umich.edu    } else {
5553578Sgblack@eecs.umich.edu        doNormalFault(tc, trapType(), false);
5563893Shsul@eecs.umich.edu        getPrivVector(tc, PC, NPC, trapType(), tl+1);
5573578Sgblack@eecs.umich.edu    }
5583578Sgblack@eecs.umich.edu
5593578Sgblack@eecs.umich.edu    tc->setPC(PC);
5603578Sgblack@eecs.umich.edu    tc->setNextPC(NPC);
5613578Sgblack@eecs.umich.edu    tc->setNextNPC(NPC + sizeof(MachInst));
5623420Sgblack@eecs.umich.edu}
5632221SN/A
5643523Sgblack@eecs.umich.eduvoid PowerOnReset::invoke(ThreadContext * tc)
5653523Sgblack@eecs.umich.edu{
5663523Sgblack@eecs.umich.edu    //For SPARC, when a system is first started, there is a power
5673523Sgblack@eecs.umich.edu    //on reset Trap which sets the processor into the following state.
5683523Sgblack@eecs.umich.edu    //Bits that aren't set aren't defined on startup.
5693595Sgblack@eecs.umich.edu
5703595Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_TL, MaxTL);
5713595Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_TT, trapType());
5723595Sgblack@eecs.umich.edu    tc->setMiscRegWithEffect(MISCREG_GL, MaxGL);
5733595Sgblack@eecs.umich.edu
5743746Sgblack@eecs.umich.edu    //Turn on pef and priv, set everything else to 0
5753746Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_PSTATE, (1 << 4) | (1 << 2));
5763595Sgblack@eecs.umich.edu
5773595Sgblack@eecs.umich.edu    //Turn on red and hpriv, set everything else to 0
5783628Sgblack@eecs.umich.edu    MiscReg HPSTATE = tc->readMiscReg(MISCREG_HPSTATE);
5793628Sgblack@eecs.umich.edu    //HPSTATE.red = 1
5803628Sgblack@eecs.umich.edu    HPSTATE |= (1 << 5);
5813628Sgblack@eecs.umich.edu    //HPSTATE.hpriv = 1
5823628Sgblack@eecs.umich.edu    HPSTATE |= (1 << 2);
5833628Sgblack@eecs.umich.edu    //HPSTATE.ibe = 0
5843628Sgblack@eecs.umich.edu    HPSTATE &= ~(1 << 10);
5853628Sgblack@eecs.umich.edu    //HPSTATE.tlz = 0
5863628Sgblack@eecs.umich.edu    HPSTATE &= ~(1 << 0);
5873628Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_HPSTATE, HPSTATE);
5883595Sgblack@eecs.umich.edu
5893595Sgblack@eecs.umich.edu    //The tick register is unreadable by nonprivileged software
5903595Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_TICK, 1ULL << 63);
5913595Sgblack@eecs.umich.edu
5923746Sgblack@eecs.umich.edu    //Enter RED state. We do this last so that the actual state preserved in
5933746Sgblack@eecs.umich.edu    //the trap stack is the state from before this fault.
5943746Sgblack@eecs.umich.edu    enterREDState(tc);
5953746Sgblack@eecs.umich.edu
5963595Sgblack@eecs.umich.edu    Addr PC, NPC;
5973595Sgblack@eecs.umich.edu    getREDVector(trapType(), PC, NPC);
5983595Sgblack@eecs.umich.edu    tc->setPC(PC);
5993595Sgblack@eecs.umich.edu    tc->setNextPC(NPC);
6003595Sgblack@eecs.umich.edu    tc->setNextNPC(NPC + sizeof(MachInst));
6013595Sgblack@eecs.umich.edu
6023595Sgblack@eecs.umich.edu    //These registers are specified as "undefined" after a POR, and they
6033595Sgblack@eecs.umich.edu    //should have reasonable values after the miscregfile is reset
6043523Sgblack@eecs.umich.edu    /*
6053595Sgblack@eecs.umich.edu    // Clear all the soft interrupt bits
6063595Sgblack@eecs.umich.edu    softint = 0;
6073595Sgblack@eecs.umich.edu    // disable timer compare interrupts, reset tick_cmpr
6083595Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_
6093595Sgblack@eecs.umich.edu    tick_cmprFields.int_dis = 1;
6103523Sgblack@eecs.umich.edu    tick_cmprFields.tick_cmpr = 0; // Reset to 0 for pretty printing
6113523Sgblack@eecs.umich.edu    stickFields.npt = 1; //The TICK register is unreadable by by !priv
6123523Sgblack@eecs.umich.edu    stick_cmprFields.int_dis = 1; // disable timer compare interrupts
6133523Sgblack@eecs.umich.edu    stick_cmprFields.tick_cmpr = 0; // Reset to 0 for pretty printing
6143523Sgblack@eecs.umich.edu
6153523Sgblack@eecs.umich.edu    tt[tl] = _trapType;
6163523Sgblack@eecs.umich.edu
6173523Sgblack@eecs.umich.edu    hintp = 0; // no interrupts pending
6183523Sgblack@eecs.umich.edu    hstick_cmprFields.int_dis = 1; // disable timer compare interrupts
6193523Sgblack@eecs.umich.edu    hstick_cmprFields.tick_cmpr = 0; // Reset to 0 for pretty printing
6203523Sgblack@eecs.umich.edu    */
6212221SN/A}
6222221SN/A
6233578Sgblack@eecs.umich.edu#else // !FULL_SYSTEM
6242612SN/A
6253415Sgblack@eecs.umich.eduvoid SpillNNormal::invoke(ThreadContext *tc)
6263415Sgblack@eecs.umich.edu{
6273578Sgblack@eecs.umich.edu    doNormalFault(tc, trapType(), false);
6283415Sgblack@eecs.umich.edu
6293415Sgblack@eecs.umich.edu    Process *p = tc->getProcessPtr();
6303415Sgblack@eecs.umich.edu
6313578Sgblack@eecs.umich.edu    //XXX This will only work in faults from a SparcLiveProcess
6323415Sgblack@eecs.umich.edu    SparcLiveProcess *lp = dynamic_cast<SparcLiveProcess *>(p);
6333415Sgblack@eecs.umich.edu    assert(lp);
6343415Sgblack@eecs.umich.edu
6353415Sgblack@eecs.umich.edu    //Then adjust the PC and NPC
6363415Sgblack@eecs.umich.edu    Addr spillStart = lp->readSpillStart();
6373415Sgblack@eecs.umich.edu    tc->setPC(spillStart);
6383415Sgblack@eecs.umich.edu    tc->setNextPC(spillStart + sizeof(MachInst));
6393415Sgblack@eecs.umich.edu    tc->setNextNPC(spillStart + 2*sizeof(MachInst));
6403415Sgblack@eecs.umich.edu}
6413415Sgblack@eecs.umich.edu
6423415Sgblack@eecs.umich.eduvoid FillNNormal::invoke(ThreadContext *tc)
6433415Sgblack@eecs.umich.edu{
6443578Sgblack@eecs.umich.edu    doNormalFault(tc, trapType(), false);
6453415Sgblack@eecs.umich.edu
6463415Sgblack@eecs.umich.edu    Process * p = tc->getProcessPtr();
6473415Sgblack@eecs.umich.edu
6483578Sgblack@eecs.umich.edu    //XXX This will only work in faults from a SparcLiveProcess
6493415Sgblack@eecs.umich.edu    SparcLiveProcess *lp = dynamic_cast<SparcLiveProcess *>(p);
6503415Sgblack@eecs.umich.edu    assert(lp);
6513415Sgblack@eecs.umich.edu
6523578Sgblack@eecs.umich.edu    //Then adjust the PC and NPC
6533415Sgblack@eecs.umich.edu    Addr fillStart = lp->readFillStart();
6543415Sgblack@eecs.umich.edu    tc->setPC(fillStart);
6553415Sgblack@eecs.umich.edu    tc->setNextPC(fillStart + sizeof(MachInst));
6563415Sgblack@eecs.umich.edu    tc->setNextNPC(fillStart + 2*sizeof(MachInst));
6573415Sgblack@eecs.umich.edu}
6583415Sgblack@eecs.umich.edu
6594111Sgblack@eecs.umich.eduvoid TrapInstruction::invoke(ThreadContext *tc)
6604111Sgblack@eecs.umich.edu{
6614111Sgblack@eecs.umich.edu    //In SE, this mechanism is how the process requests a service from the
6624111Sgblack@eecs.umich.edu    //operating system. We'll get the process object from the thread context
6634111Sgblack@eecs.umich.edu    //and let it service the request.
6644111Sgblack@eecs.umich.edu
6654111Sgblack@eecs.umich.edu    Process *p = tc->getProcessPtr();
6664111Sgblack@eecs.umich.edu
6674111Sgblack@eecs.umich.edu    SparcLiveProcess *lp = dynamic_cast<SparcLiveProcess *>(p);
6684111Sgblack@eecs.umich.edu    assert(lp);
6694111Sgblack@eecs.umich.edu
6704111Sgblack@eecs.umich.edu    lp->handleTrap(_n, tc);
6714111Sgblack@eecs.umich.edu
6724111Sgblack@eecs.umich.edu    //We need to explicitly advance the pc, since that's not done for us
6734111Sgblack@eecs.umich.edu    //on a faulting instruction
6744111Sgblack@eecs.umich.edu    tc->setPC(tc->readNextPC());
6754111Sgblack@eecs.umich.edu    tc->setNextPC(tc->readNextNPC());
6764111Sgblack@eecs.umich.edu    tc->setNextNPC(tc->readNextNPC() + sizeof(MachInst));
6774111Sgblack@eecs.umich.edu}
6784111Sgblack@eecs.umich.edu
6792800Ssaidi@eecs.umich.eduvoid PageTableFault::invoke(ThreadContext *tc)
6802800Ssaidi@eecs.umich.edu{
6812800Ssaidi@eecs.umich.edu    Process *p = tc->getProcessPtr();
6822800Ssaidi@eecs.umich.edu
6833786Sgblack@eecs.umich.edu    // We've accessed the next page of the stack, so extend the stack
6843786Sgblack@eecs.umich.edu    // to cover it.
6853786Sgblack@eecs.umich.edu    if(vaddr < p->stack_min && vaddr >= p->stack_min - PageBytes)
6863786Sgblack@eecs.umich.edu    {
6872800Ssaidi@eecs.umich.edu        p->stack_min -= PageBytes;
6883786Sgblack@eecs.umich.edu        if(p->stack_base - p->stack_min > 8*1024*1024)
6892800Ssaidi@eecs.umich.edu            fatal("Over max stack size for one thread\n");
6902800Ssaidi@eecs.umich.edu        p->pTable->allocate(p->stack_min, PageBytes);
6912800Ssaidi@eecs.umich.edu        warn("Increasing stack size by one page.");
6923786Sgblack@eecs.umich.edu    }
6933786Sgblack@eecs.umich.edu    // Otherwise, we have an unexpected page fault. Report that fact,
6943786Sgblack@eecs.umich.edu    // and what address was accessed to cause the fault.
6953786Sgblack@eecs.umich.edu    else
6963786Sgblack@eecs.umich.edu    {
6973786Sgblack@eecs.umich.edu        panic("Page table fault when accessing virtual address %#x\n", vaddr);
6982800Ssaidi@eecs.umich.edu    }
6992800Ssaidi@eecs.umich.edu}
7003415Sgblack@eecs.umich.edu
7012221SN/A#endif
7022221SN/A
7032223SN/A} // namespace SparcISA
7042221SN/A
705