Esempio n. 1
0
        private void Init()
        {
            memoryManager = new SimpleMemoryManager(this);
            PauseEvent = new ManualResetEvent(true);
            hooks = hooks ?? new Dictionary<uint, HookDescriptor>();
            sync = new Synchronizer();
            haltedFinishedEvent = new AutoResetEvent(false);
            waitHandles = interruptEvents.Cast<WaitHandle>().Union(new EventWaitHandle[] { PauseEvent, haltedFinishedEvent }).ToArray();

            if(currentMappings == null)
            {
                currentMappings = new List<SegmentMapping>();
            }
            onTranslationBlockFetch = OnTranslationBlockFetch;

            var libraryResource = string.Format("Emul8.translate_{0}-{1}-{2}.so", IntPtr.Size * 8, Architecture, Endianness == Endianess.BigEndian ? "be" : "le");
            libraryFile = GetType().Assembly.FromResourceToTemporaryFile(libraryResource);

            binder = new NativeBinder(this, libraryFile);
            TlibSetTranslationCacheSize(checked((IntPtr)translationCacheSize));
            MaximumBlockSize = DefaultMaximumBlockSize;
            var result = TlibInit(cpuType);
            if(result == -1)
            {
                throw new InvalidOperationException("Unknown cpu type");
            }
            if(cpuState != null)
            {
                var statePtr = TlibExportState();
                Marshal.Copy(cpuState, 0, statePtr, cpuState.Length);
                AfterLoad(statePtr);
            }
            HandleRamSetup();
            foreach(var hook in hooks)
            {
                TlibAddBreakpoint(hook.Key);
            }
            EmulSetCountThreshold(currentCountThreshold);
        }
Esempio n. 2
0
        private void Init()
        {
            memoryManager = new SimpleMemoryManager(this);
            PauseEvent = new ManualResetEvent(true);
            breakpoints = breakpoints ?? new List<uint>();
            hooks = hooks ?? new Dictionary<uint, Action<uint>>();
            inactiveHooks = inactiveHooks ?? new List<uint>();
            pauseFinishedEvent = new ManualResetEventSlim(false);
            stepDoneEvent = new AutoResetEvent(false);
            stepEvent = new AutoResetEvent(false);
            haltedFinishedEvent = new AutoResetEvent(false);
            waitHandles = interruptEvents.Cast<WaitHandle>().Union(new EventWaitHandle[] { PauseEvent, haltedFinishedEvent }).ToArray();

            if(currentMappings == null)
            {
                currentMappings = new List<SegmentMapping>();
            }
            onTranslationBlockFetch = OnTranslationBlockFetch;

            var libraryResource = string.Format("Emul8.translate-{0}.zip", Architecture);

            libraryFile = GetType().Assembly.FromResourceToTemporaryFile(libraryResource, string.Format("lib{0}{1}translate-{2}-{3}.so",
                Marshal.SizeOf(typeof(IntPtr)) * 8, Path.DirectorySeparatorChar, Architecture, Endianness == EndiannessEnum.BigEndian ? "be" : "le"));

            binder = new NativeBinder(this, libraryFile);
            TlibSetTranslationCacheSize(checked((IntPtr)translationCacheSize));
            MaximumBlockSize = DefaultMaximumBlockSize;
            var result = TlibInit(cpuType);
            if(result == -1)
            {
                throw new InvalidOperationException("Unknown cpu type");
            }
            if(cpuState != null)
            {
                var statePtr = TlibExportState();
                Marshal.Copy(cpuState, 0, statePtr, cpuState.Length);
                AfterLoad(statePtr);
            }
            HandleRamSetup();
            foreach(var bpoint in breakpoints)
            {
                TlibAddBreakpoint(bpoint);
            }
            foreach(var hook in hooks)
            {
                TlibAddBreakpoint(hook.Key);
            }
            EmulSetCountThreshold(currentCountThreshold);
        }