faults.hh revision 11723:0596db108c53
16498Snate@binkert.org/* 22632SN/A * Copyright (c) 2016 RISC-V Foundation 32632SN/A * Copyright (c) 2016 The University of Virginia 46498Snate@binkert.org * All rights reserved. 56498Snate@binkert.org * 66498Snate@binkert.org * Redistribution and use in source and binary forms, with or without 72632SN/A * modification, are permitted provided that the following conditions are 86498Snate@binkert.org * met: redistributions of source code must retain the above copyright 96498Snate@binkert.org * notice, this list of conditions and the following disclaimer; 106498Snate@binkert.org * redistributions in binary form must reproduce the above copyright 116498Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 126498Snate@binkert.org * documentation and/or other materials provided with the distribution; 136498Snate@binkert.org * neither the name of the copyright holders nor the names of its 146498Snate@binkert.org * contributors may be used to endorse or promote products derived from 156498Snate@binkert.org * this software without specific prior written permission. 166498Snate@binkert.org * 176498Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 186498Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 196498Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202632SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 216498Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 226498Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 236498Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 246498Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 256498Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 266498Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 276498Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 286498Snate@binkert.org * 296498Snate@binkert.org * Authors: Alec Roelke 306498Snate@binkert.org */ 316498Snate@binkert.org 326498Snate@binkert.org#ifndef __ARCH_RISCV_FAULTS_HH__ 332632SN/A#define __ARCH_RISCV_FAULTS_HH__ 342632SN/A 354479Sbinkertn@umich.edu#include <string> 364479Sbinkertn@umich.edu 374479Sbinkertn@umich.edu#include "cpu/thread_context.hh" 384479Sbinkertn@umich.edu#include "sim/faults.hh" 392632SN/A 402632SN/Anamespace RiscvISA 412632SN/A{ 422632SN/A 432632SN/Aenum ExceptionCode { 442632SN/A INST_ADDR_MISALIGNED = 0, 452632SN/A INST_ACCESS = 1, 464479Sbinkertn@umich.edu INST_ILLEGAL = 2, 474479Sbinkertn@umich.edu BREAKPOINT = 3, 484479Sbinkertn@umich.edu LOAD_ADDR_MISALIGNED = 4, 494479Sbinkertn@umich.edu LOAD_ACCESS = 5, 504479Sbinkertn@umich.edu STORE_ADDR_MISALIGNED = 6, 514479Sbinkertn@umich.edu AMO_ADDR_MISALIGNED = 6, 524479Sbinkertn@umich.edu STORE_ACCESS = 7, 534479Sbinkertn@umich.edu AMO_ACCESS = 7, 544479Sbinkertn@umich.edu ECALL_USER = 8, 554479Sbinkertn@umich.edu ECALL_SUPER = 9, 564479Sbinkertn@umich.edu ECALL_HYPER = 10, 574479Sbinkertn@umich.edu ECALL_MACH = 11 584479Sbinkertn@umich.edu}; 594479Sbinkertn@umich.edu 604479Sbinkertn@umich.eduenum InterruptCode { 612632SN/A SOFTWARE, 626498Snate@binkert.org TIMER 636498Snate@binkert.org}; 642632SN/A 652632SN/Aclass RiscvFault : public FaultBase 662632SN/A{ 672632SN/A protected: 682632SN/A const FaultName _name; 692632SN/A const ExceptionCode _code; 702632SN/A const InterruptCode _int; 712632SN/A 722632SN/A RiscvFault(FaultName n, ExceptionCode c, InterruptCode i) 732632SN/A : _name(n), _code(c), _int(i) 742632SN/A {} 752632SN/A 764479Sbinkertn@umich.edu FaultName 772632SN/A name() const 782632SN/A { 792632SN/A return _name; 806498Snate@binkert.org } 816498Snate@binkert.org 826498Snate@binkert.org ExceptionCode 836498Snate@binkert.org exception() const 846498Snate@binkert.org { 856498Snate@binkert.org return _code; 866498Snate@binkert.org } 876498Snate@binkert.org 886498Snate@binkert.org InterruptCode 896498Snate@binkert.org interrupt() const 906498Snate@binkert.org { 916498Snate@binkert.org return _int; 926498Snate@binkert.org } 936498Snate@binkert.org 946498Snate@binkert.org virtual void 956498Snate@binkert.org invoke_se(ThreadContext *tc, const StaticInstPtr &inst); 966498Snate@binkert.org 976498Snate@binkert.org void 986498Snate@binkert.org invoke(ThreadContext *tc, const StaticInstPtr &inst); 996498Snate@binkert.org}; 1006498Snate@binkert.org 1016498Snate@binkert.org 1026498Snate@binkert.orgclass UnknownInstFault : public RiscvFault 1036498Snate@binkert.org{ 1046498Snate@binkert.org public: 1056498Snate@binkert.org UnknownInstFault() : RiscvFault("Unknown instruction", INST_ILLEGAL, 1066498Snate@binkert.org SOFTWARE) 1076498Snate@binkert.org {} 1086498Snate@binkert.org 1096498Snate@binkert.org void 1106498Snate@binkert.org invoke_se(ThreadContext *tc, const StaticInstPtr &inst); 1116498Snate@binkert.org}; 1126498Snate@binkert.org 1136498Snate@binkert.orgclass UnimplementedFault : public RiscvFault 1146498Snate@binkert.org{ 1156498Snate@binkert.org private: 1166498Snate@binkert.org const std::string instName; 1176498Snate@binkert.org public: 1186498Snate@binkert.org UnimplementedFault(std::string name) 1196498Snate@binkert.org : RiscvFault("Unimplemented instruction", INST_ILLEGAL, SOFTWARE), 1206498Snate@binkert.org instName(name) 1216498Snate@binkert.org {} 1226498Snate@binkert.org 1236498Snate@binkert.org void 1246498Snate@binkert.org invoke_se(ThreadContext *tc, const StaticInstPtr &inst); 1256498Snate@binkert.org}; 1266498Snate@binkert.org 1276498Snate@binkert.orgclass BreakpointFault : public RiscvFault 1286498Snate@binkert.org{ 1296498Snate@binkert.org public: 1306498Snate@binkert.org BreakpointFault() : RiscvFault("Breakpoint", BREAKPOINT, SOFTWARE) 1316498Snate@binkert.org {} 1326498Snate@binkert.org 1336498Snate@binkert.org void 1346498Snate@binkert.org invoke_se(ThreadContext *tc, const StaticInstPtr &inst); 1356498Snate@binkert.org}; 1366498Snate@binkert.org 1376498Snate@binkert.orgclass SyscallFault : public RiscvFault 1386498Snate@binkert.org{ 1392632SN/A public: 1402632SN/A // TODO: replace ECALL_USER with the appropriate privilege level of the 1412632SN/A // caller 1426498Snate@binkert.org SyscallFault() : RiscvFault("System call", ECALL_USER, SOFTWARE) 1436498Snate@binkert.org {} 1446498Snate@binkert.org 1456498Snate@binkert.org void 1466498Snate@binkert.org invoke_se(ThreadContext *tc, const StaticInstPtr &inst); 1476498Snate@binkert.org}; 1486498Snate@binkert.org 1496498Snate@binkert.org} // namespace RiscvISA 1506498Snate@binkert.org 1516498Snate@binkert.org#endif // __ARCH_RISCV_FAULTS_HH__ 1526498Snate@binkert.org