1// Copyright (c) AMD
2// All rights reserved.
3//
4// Authors: Marc Orr
5
6// Monitor Instruction
7
8output header {{
9    class MonitorInst : public X86ISA::X86StaticInst
10    {
11      public:
12        static const RegIndex foldOBit = 0;
13        /// Constructor
14        MonitorInst(const char *_mnemonic, ExtMachInst _machInst,
15                OpClass __opClass) :
16            X86ISA::X86StaticInst(_mnemonic, _machInst, __opClass)
17        { }
18
19        std::string generateDisassembly(Addr pc,
20                const SymbolTable *symtab) const;
21    };
22}};
23
24output decoder {{
25    std::string MonitorInst::generateDisassembly(Addr PC,
26            const SymbolTable *symtab) const
27    {
28        std::stringstream response;
29
30        printMnemonic(response, mnemonic);
31        ccprintf(response, " ");
32        printReg(response, _srcRegIdx[0], machInst.opSize);
33        return response.str();
34    }
35}};
36
37def format MonitorInst(code, *opt_flags) {{
38    iop = InstObjParams(name, Name, 'MonitorInst', code, opt_flags)
39    header_output = BasicDeclare.subst(iop)
40    decoder_output = BasicConstructor.subst(iop)
41    decode_block = BasicDecode.subst(iop)
42    exec_output = BasicExecute.subst(iop)
43}};
44
45
46// Mwait instruction
47
48def template MwaitDeclare {{
49    class %(class_name)s : public %(base_class)s
50    {
51        public:
52        // Constructor.
53        %(class_name)s(ExtMachInst machInst);
54        Fault execute(ExecContext *, Trace::InstRecord *) const;
55        Fault initiateAcc(ExecContext *, Trace::InstRecord *) const;
56        Fault completeAcc(PacketPtr, ExecContext *, Trace::InstRecord *) const;
57    };
58}};
59
60def template MwaitInitiateAcc {{
61    Fault %(class_name)s::initiateAcc(ExecContext * xc,
62            Trace::InstRecord * traceData) const
63    {
64        unsigned s = 0x8;        //size
65        unsigned f = 0;          //flags
66        initiateMemRead(xc, traceData, xc->getAddrMonitor()->vAddr, s, f);
67        return NoFault;
68    }
69}};
70
71def template MwaitCompleteAcc {{
72    Fault %(class_name)s::completeAcc(PacketPtr pkt, ExecContext *xc,
73            Trace::InstRecord *traceData) const
74    {
75        MicroHalt hltObj(machInst, mnemonic, 0x0);
76        if(xc->mwait(pkt)) {
77            hltObj.execute(xc, traceData);
78        }
79        return NoFault;
80    }
81}};
82
83output header {{
84    class MwaitInst : public X86ISA::X86StaticInst
85    {
86      public:
87        static const RegIndex foldOBit = 0;
88        /// Constructor
89        MwaitInst(const char *_mnemonic, ExtMachInst _machInst,
90                OpClass __opClass) :
91            X86ISA::X86StaticInst(_mnemonic, _machInst, __opClass)
92        {
93            flags[IsMemRef] = 1;
94            flags[IsLoad] = 1;
95        }
96
97        std::string generateDisassembly(Addr pc,
98                const SymbolTable *symtab) const;
99    };
100}};
101
102output decoder {{
103    std::string MwaitInst::generateDisassembly(Addr PC,
104            const SymbolTable *symtab) const
105    {
106        std::stringstream response;
107
108        // Although mwait could take hints from eax and ecx, the _srcRegIdx
109        // is not set, and thus should not be printed here
110        printMnemonic(response, mnemonic);
111        return response.str();
112    }
113}};
114
115def format MwaitInst(code, *opt_flags) {{
116    iop = InstObjParams(name, Name, 'MwaitInst', code, opt_flags)
117    header_output = MwaitDeclare.subst(iop)
118    decoder_output = BasicConstructor.subst(iop)
119    decode_block = BasicDecode.subst(iop)
120    exec_output = BasicExecute.subst(iop)
121    exec_output += MwaitInitiateAcc.subst(iop)
122    exec_output += MwaitCompleteAcc.subst(iop)
123}};
124
125