1// Copyright (c) 2009 The Regents of The University of Michigan
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met: redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer;
8// redistributions in binary form must reproduce the above copyright
9// notice, this list of conditions and the following disclaimer in the
10// documentation and/or other materials provided with the distribution;
11// neither the name of the copyright holders nor the names of its
12// contributors may be used to endorse or promote products derived from
13// this software without specific prior written permission.
14//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26//
27// Authors: Gabe Black
28
29////////////////////////////////////////////////////////////////////
30//
31// Decode opcodes with the lock prefix. Opcodes which shouldn't have that
32// prefix should effectively decode to UD2.
33//
34
35// All the memory references in these instructions happen through modrm bytes.
36// We therefore only need to make sure the modrm byte encodes a memory
37// reference to make sure these are the memory forms of these instructions.
380x1: decode MODRM_MOD {
39    format Inst {
40        0x3: UD2();
41        default: decode OPCODE_TYPE {
42            'X86ISA::OneByteOpcode': decode OPCODE_OP_TOP5 {
43                0x00: decode OPCODE_OP_BOTTOM3 {
44                    default: MultiInst::ADD_LOCKED(OPCODE_OP_BOTTOM3,
45                                            [Mb,Gb], [Mv,Gv]);
46                }
47                0x01: decode OPCODE_OP_BOTTOM3 {
48                    default: MultiInst::OR_LOCKED(OPCODE_OP_BOTTOM3,
49                                           [Mb,Gb], [Mv,Gv]);
50                }
51                0x02: decode OPCODE_OP_BOTTOM3 {
52                    default: MultiInst::ADC_LOCKED(OPCODE_OP_BOTTOM3,
53                                            [Mb,Gb], [Mv,Gv]);
54                }
55                0x03: decode OPCODE_OP_BOTTOM3 {
56                    default: MultiInst::SBB_LOCKED(OPCODE_OP_BOTTOM3,
57                                            [Mb,Gb], [Mv,Gv]);
58                }
59                0x04: decode OPCODE_OP_BOTTOM3 {
60                    default: MultiInst::AND_LOCKED(OPCODE_OP_BOTTOM3,
61                                            [Mb,Gb], [Mv,Gv]);
62                }
63                0x05: decode OPCODE_OP_BOTTOM3 {
64                    default: MultiInst::SUB_LOCKED(OPCODE_OP_BOTTOM3,
65                                            [Mb,Gb], [Mv,Gv]);
66                }
67                0x06: decode OPCODE_OP_BOTTOM3 {
68                    default: MultiInst::XOR_LOCKED(OPCODE_OP_BOTTOM3,
69                                            [Mb,Gb], [Mv,Gv]);
70                }
71                0x10: decode OPCODE_OP_BOTTOM3 {
72                    0x0: decode MODRM_REG {
73                        0x0: ADD_LOCKED(Mb,Ib);
74                        0x1: OR_LOCKED(Mb,Ib);
75                        0x2: ADC_LOCKED(Mb,Ib);
76                        0x3: SBB_LOCKED(Mb,Ib);
77                        0x4: AND_LOCKED(Mb,Ib);
78                        0x5: SUB_LOCKED(Mb,Ib);
79                        0x6: XOR_LOCKED(Mb,Ib);
80                    }
81                    0x1: decode MODRM_REG {
82                        0x0: ADD_LOCKED(Mv,Iz);
83                        0x1: OR_LOCKED(Mv,Iz);
84                        0x2: ADC_LOCKED(Mv,Iz);
85                        0x3: SBB_LOCKED(Mv,Iz);
86                        0x4: AND_LOCKED(Mv,Iz);
87                        0x5: SUB_LOCKED(Mv,Iz);
88                        0x6: XOR_LOCKED(Mv,Iz);
89                    }
90                    0x2: decode MODE_SUBMODE {
91                        0x0: UD2();
92                        default: decode MODRM_REG {
93                            0x0: ADD_LOCKED(Mb,Ib);
94                            0x1: OR_LOCKED(Mb,Ib);
95                            0x2: ADC_LOCKED(Mb,Ib);
96                            0x3: SBB_LOCKED(Mb,Ib);
97                            0x4: AND_LOCKED(Mb,Ib);
98                            0x5: SUB_LOCKED(Mb,Ib);
99                            0x6: XOR_LOCKED(Mb,Ib);
100                        }
101                    }
102                    //0x3: group1_Ev_Ib();
103                    0x3: decode MODRM_REG {
104                        0x0: ADD_LOCKED(Mv,Ib);
105                        0x1: OR_LOCKED(Mv,Ib);
106                        0x2: ADC_LOCKED(Mv,Ib);
107                        0x3: SBB_LOCKED(Mv,Ib);
108                        0x4: AND_LOCKED(Mv,Ib);
109                        0x5: SUB_LOCKED(Mv,Ib);
110                        0x6: XOR_LOCKED(Mv,Ib);
111                    }
112                    0x6: XCHG_LOCKED(Mb,Gb);
113                    0x7: XCHG_LOCKED(Mv,Gv);
114                }
115                0x1E: decode OPCODE_OP_BOTTOM3 {
116                    //0x6: group3_Eb();
117                    0x6: decode MODRM_REG {
118                        0x2: NOT_LOCKED(Mb);
119                        0x3: NEG_LOCKED(Mb);
120                    }
121                    //0x7: group3_Ev();
122                    0x7: decode MODRM_REG {
123                        0x2: NOT_LOCKED(Mv);
124                        0x3: NEG_LOCKED(Mv);
125                    }
126                }
127                0x1F: decode OPCODE_OP_BOTTOM3 {
128                    0x6: decode MODRM_REG {
129                        0x0: INC_LOCKED(Mb);
130                        0x1: DEC_LOCKED(Mb);
131                        default: UD2();
132                    }
133                    //0x7: group5();
134                    0x7: decode MODRM_REG {
135                        0x0: INC_LOCKED(Mv);
136                        0x1: DEC_LOCKED(Mv);
137                    }
138                }
139            }
140            'X86ISA::TwoByteOpcode': decode OPCODE_OP_TOP5 {
141                0x04: decode OPCODE_OP_BOTTOM3 {
142                    0x0: WarnUnimpl::mov_Rd_CR8D();
143                    0x2: WarnUnimpl::mov_CR8D_Rd();
144                }
145                0x15: decode OPCODE_OP_BOTTOM3 {
146                    0x3: BTS_LOCKED(Mv,Gv);
147                }
148                0x16: decode OPCODE_OP_BOTTOM3 {
149                    0x0: CMPXCHG_LOCKED(Mb,Gb);
150                    0x1: CMPXCHG_LOCKED(Mv,Gv);
151                    0x3: BTR_LOCKED(Mv,Gv);
152                }
153                0x17: decode OPCODE_OP_BOTTOM3 {
154                    0x2: decode MODRM_REG {
155                        0x5: BTS_LOCKED(Mv,Ib);
156                        0x6: BTR_LOCKED(Mv,Ib);
157                        0x7: BTC_LOCKED(Mv,Ib);
158                    }
159                    0x3: BTC_LOCKED(Mv,Gv);
160                }
161                0x18: decode OPCODE_OP_BOTTOM3 {
162                    0x0: XADD_LOCKED(Mb,Gb);
163                    0x1: XADD_LOCKED(Mv,Gv);
164                    //0x7: group9();
165                    0x7: decode MODRM_REG {
166                        //Also CMPXCHG16B
167                        0x1: CMPXCHG8B_LOCKED(Mdp);
168                    }
169                }
170            }
171        }
172    }
173}
174