예제 #1
0
        private static OpcodeInfo FindOpcode(PhysicalMemory memory, Processor processor)
        {
            unsafe
            {
                uint* eip = (uint*)processor.PIP;
                uint startEIP = *eip;
                processor.StartEIP = startEIP;

                byte* ip = processor.CachedInstruction;
                memory.FetchInstruction(processor.segmentBases[(int)SegmentIndex.CS] + startEIP, ip);

                byte byte1 = ip[0];
                var inst = oneByteCodes[byte1];
                if (inst != null)
                {
                    *eip = startEIP + 1;
                    processor.CachedIP = ip + 1;
                    return inst;
                }

                var instSet = twoByteCodes[byte1];
                if (instSet != null)
                {
                    inst = instSet[ip[1]];
                    if (inst != null)
                    {
                        *eip = startEIP + 2;
                        processor.CachedIP = ip + 2;
                        return inst;
                    }
                }

                instSet = rmCodes[byte1];
                if (instSet != null)
                {
                    inst = instSet[(ip[1] & ModRmMask) >> 3];
                    if (inst == null)
                        ThrowGetOpcodeException(ip);

                    *eip = startEIP + 1;
                    processor.CachedIP = ip + 1;
                    return inst;
                }

                var instSetSet = twoByteRmCodes[byte1];
                if (instSetSet != null)
                {
                    instSet = instSetSet[ip[1]];
                    if (instSet != null)
                    {
                        inst = instSet[(ip[2] & ModRmMask) >> 3];
                        if (inst != null)
                        {
                            *eip = startEIP + 2;
                            processor.CachedIP = ip + 2;
                            return inst;
                        }
                    }
                }

                ThrowGetOpcodeException(ip);
                return null;
            }
        }