priv.isa revision 12287
12SN/A// Copyright (c) 2006-2007 The Regents of The University of Michigan
21762SN/A// All rights reserved.
32SN/A//
42SN/A// Redistribution and use in source and binary forms, with or without
52SN/A// modification, are permitted provided that the following conditions are
62SN/A// met: redistributions of source code must retain the above copyright
72SN/A// notice, this list of conditions and the following disclaimer;
82SN/A// redistributions in binary form must reproduce the above copyright
92SN/A// notice, this list of conditions and the following disclaimer in the
102SN/A// documentation and/or other materials provided with the distribution;
112SN/A// neither the name of the copyright holders nor the names of its
122SN/A// contributors may be used to endorse or promote products derived from
132SN/A// this software without specific prior written permission.
142SN/A//
152SN/A// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
162SN/A// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
172SN/A// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
182SN/A// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
192SN/A// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
202SN/A// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
212SN/A// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
222SN/A// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
232SN/A// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
242SN/A// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
252SN/A// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
262SN/A//
272665Ssaidi@eecs.umich.edu// Authors: Ali Saidi
282665Ssaidi@eecs.umich.edu//          Gabe Black
292665Ssaidi@eecs.umich.edu//          Steve Reinhardt
302665Ssaidi@eecs.umich.edu
312665Ssaidi@eecs.umich.edu////////////////////////////////////////////////////////////////////
322SN/A//
332SN/A// Privilege mode instructions
342SN/A//
352SN/A
367349SAli.Saidi@ARM.comdef template ControlRegConstructor {{
377680Sgblack@eecs.umich.edu%(class_name)s::%(class_name)s(ExtMachInst machInst) :
3856SN/A        %(base_class)s("%(mnemonic)s", machInst, %(op_class)s, "%(reg_name)s")
398229Snate@binkert.org{
401717SN/A    %(constructor)s;
412518SN/A}
4256SN/A}};
434776Sgblack@eecs.umich.edu
448232Snate@binkert.orgdef template PrivExecute {{
454762Snate@binkert.orgFault
463065Sgblack@eecs.umich.edu%(class_name)s::execute(ExecContext *xc, Trace::InstRecord *traceData) const
472SN/A{
482973Sgblack@eecs.umich.edu    %(op_decl)s;
492SN/A    %(op_rd)s;
503506Ssaidi@eecs.umich.edu
514054Sbinkertn@umich.edu    // If the processor isn't in privileged mode, fault out right away
524054Sbinkertn@umich.edu    if (%(check)s)
535866Sksewell@umich.edu        return std::make_shared<PrivilegedAction>();
545866Sksewell@umich.edu
555866Sksewell@umich.edu    %(tl_check)s
565866Sksewell@umich.edu
575866Sksewell@umich.edu    Fault fault = NoFault;
585866Sksewell@umich.edu    %(code)s;
595784Sgblack@eecs.umich.edu    %(op_wb)s;
604054Sbinkertn@umich.edu    return fault;
614776Sgblack@eecs.umich.edu}
624054Sbinkertn@umich.edu}};
638300Schander.sudanthi@arm.com
648300Schander.sudanthi@arm.comlet {{
658300Schander.sudanthi@arm.com    tl_check_code = '''
668300Schander.sudanthi@arm.com    if (Tl == 0)
678300Schander.sudanthi@arm.com        return std::make_shared<IllegalInstruction>();
688300Schander.sudanthi@arm.com'''
698232Snate@binkert.org
705866Sksewell@umich.edu    def doPrivFormat(code, check_code, name, Name, opt_flags, check_tl=False):
714054Sbinkertn@umich.edu        (uses_imm, code, imm_code, r_string, i_string) = splitOutImm(code)
724776Sgblack@eecs.umich.edu        tl_check = tl_check_code if check_tl else ''
734054Sbinkertn@umich.edu        # If these are rd, rdpr, rdhpr, wr, wrpr, or wrhpr instructions,
748232Snate@binkert.org        # cut any other info out of the mnemonic. Also pick a different
754776Sgblack@eecs.umich.edu        # base class.
764054Sbinkertn@umich.edu        reg_base = 'Priv'
778300Schander.sudanthi@arm.com        reg_name = ''
788300Schander.sudanthi@arm.com        for mnem in ["rdhpr", "rdpr", "rd"]:
798300Schander.sudanthi@arm.com            if name.startswith(mnem):
808232Snate@binkert.org                reg_name = name[len(mnem):]
815715Shsul@eecs.umich.edu                name = mnem
824776Sgblack@eecs.umich.edu                reg_base = 'RdPriv'
834776Sgblack@eecs.umich.edu                break
844776Sgblack@eecs.umich.edu        for mnem in ["wrhpr", "wrpr", "wr"]:
857720Sgblack@eecs.umich.edu            if name.startswith(mnem):
868793Sgblack@eecs.umich.edu                reg_name = name[len(mnem):]
877349SAli.Saidi@ARM.com                name = mnem
887349SAli.Saidi@ARM.com                reg_base = 'WrPriv'
897349SAli.Saidi@ARM.com                break
905784Sgblack@eecs.umich.edu        iop = InstObjParams(name, Name, reg_base,
917720Sgblack@eecs.umich.edu                {"code": code, "check": check_code,
927349SAli.Saidi@ARM.com                 "tl_check": tl_check, "reg_name": reg_name},
934776Sgblack@eecs.umich.edu                opt_flags)
944776Sgblack@eecs.umich.edu        header_output = BasicDeclare.subst(iop)
955784Sgblack@eecs.umich.edu        if reg_name == '':
967720Sgblack@eecs.umich.edu            decoder_output = BasicConstructor.subst(iop)
975784Sgblack@eecs.umich.edu        else:
985784Sgblack@eecs.umich.edu            decoder_output = ControlRegConstructor.subst(iop)
995784Sgblack@eecs.umich.edu        exec_output = PrivExecute.subst(iop)
1005784Sgblack@eecs.umich.edu        if uses_imm:
1015784Sgblack@eecs.umich.edu            imm_iop = InstObjParams(name, Name + 'Imm', reg_base + 'Imm',
1025784Sgblack@eecs.umich.edu                    {"code": imm_code, "check": check_code,
1034776Sgblack@eecs.umich.edu                     "tl_check": tl_check, "reg_name": reg_name},
1044776Sgblack@eecs.umich.edu                    opt_flags)
1054776Sgblack@eecs.umich.edu            header_output += BasicDeclare.subst(imm_iop)
1064776Sgblack@eecs.umich.edu            if reg_name == '':
1074776Sgblack@eecs.umich.edu                decoder_output += BasicConstructor.subst(imm_iop)
1087349SAli.Saidi@ARM.com            else:
1094776Sgblack@eecs.umich.edu                decoder_output += ControlRegConstructor.subst(imm_iop)
1105784Sgblack@eecs.umich.edu            exec_output += PrivExecute.subst(imm_iop)
1115784Sgblack@eecs.umich.edu            decode_block = ROrImmDecode.subst(iop)
1125784Sgblack@eecs.umich.edu        else:
1138232Snate@binkert.org            decode_block = BasicDecode.subst(iop)
1145784Sgblack@eecs.umich.edu        return (header_output, decoder_output, exec_output, decode_block)
1155784Sgblack@eecs.umich.edu}};
1165784Sgblack@eecs.umich.edu
1178232Snate@binkert.orgdef format Priv(code, extraCond=true, check_tl=false, *opt_flags) {{
1187600Sminkyu.jeong@arm.com    check_code = "(%s) && !(Pstate.priv || Hpstate.hpriv)" % extraCond
1197600Sminkyu.jeong@arm.com    (header_output, decoder_output, exec_output, decode_block) = \
1207600Sminkyu.jeong@arm.com            doPrivFormat(code, check_code, name, Name, opt_flags,
1218232Snate@binkert.org                         check_tl=(check_tl != 'false'))
1225784Sgblack@eecs.umich.edu}};
1235784Sgblack@eecs.umich.edu
1245784Sgblack@eecs.umich.edudef format NoPriv(code, *opt_flags) {{
1258232Snate@binkert.org    # Instructions which use this format don't really check for any
1265784Sgblack@eecs.umich.edu    # particular mode, but the disassembly is performed using the control
1275784Sgblack@eecs.umich.edu    # register's actual name
1288232Snate@binkert.org    check_code = "false"
1295784Sgblack@eecs.umich.edu    (header_output, decoder_output, exec_output, decode_block) = \
1305784Sgblack@eecs.umich.edu            doPrivFormat(code, check_code, name, Name, opt_flags)
1318232Snate@binkert.org}};
1325784Sgblack@eecs.umich.edu
1334776Sgblack@eecs.umich.edudef format HPriv(code, check_tl=false, *opt_flags) {{
1344776Sgblack@eecs.umich.edu    check_code = "!Hpstate.hpriv"
1354776Sgblack@eecs.umich.edu    (header_output, decoder_output, exec_output, decode_block) = \
1364776Sgblack@eecs.umich.edu            doPrivFormat(code, check_code, name, Name, opt_flags,
1374776Sgblack@eecs.umich.edu                         check_tl=(check_tl != 'false'))
1384776Sgblack@eecs.umich.edu}};
1393506Ssaidi@eecs.umich.edu
1403506Ssaidi@eecs.umich.edu