public void ConfigureServices(IServiceCollection services) { services .AddRazorPages() .AddApplicationPart(Assembly.GetEntryAssembly()) .AddApplicationPart(Assembly.GetExecutingAssembly()); services .AddSignalR() .AddNewtonsoftJsonProtocol(); services.AddSingleton( provider => new Processor.x86.CSharpExecutor.Cpu( ConfigurationDto.Processor, provider.GetRequiredService <IHostApplicationLifetime>().ApplicationStopping)); services.AddSingleton(p => MethodInfoCollection.Load(ConfigurationDto.BinToCSharp)); services.AddSingleton( p => { var definitionCollection = new DefinitionCollection(); definitionCollection.AddDefinitionsFromAssembly(typeof(Definitions).Assembly); return(definitionCollection); }); services.AddSingleton( p => new RawProgramMain( p.GetRequiredService <Processor.x86.CSharpExecutor.Cpu>(), ConfigurationDto, p.GetRequiredService <MethodInfoCollection>(), p.GetRequiredService <DefinitionCollection>(), p)); }
public const ushort PspSeg = ImageLoadSeg - 16; // 0x192 public RawProgramMain( Processor.x86.CSharpExecutor.Cpu implementation, ConfigurationDto configuration, MethodInfoCollection methodInfoCollection, DefinitionCollection definitionCollection, IServiceProvider serviceProvider) : base(implementation) { MethodInfoCollection = methodInfoCollection; Configuration = configuration; Implementation = implementation; DefinitionCollection = definitionCollection; ServiceProvider = serviceProvider; DosMemory = new DosMemory(implementation, this); DosInterrupt = new DosInterrupt(implementation, this); DosTimer = new DosTimer(implementation, this); DosPort = new DosPort(implementation, this); DosDma = new DosDma(implementation, this); DosPic = new DosPic(implementation, this); Implementation.MethodInfoCollection = MethodInfoCollection; implementation.CompiledMethodCollection = this; implementation.runIrqs += (sender, args) => DosPic.RunIrqs(); DosPort.SubscribeToCpuPortEvents(); }
private static MethodInfoCollection GetMethodCollectionAndCache(InvokeContextBase context, Type type) { MethodCache cache = GetMethodCache(type); MethodInfoCollection infos = GetMethodCollection(cache, type, context.MethodName); if (infos == null) { lock (_syncMethodObject) { infos = GetMethodCollection(cache, type, context.MethodName); if (infos == null) { infos = new MethodInfoCollection(); MemberInfo[] methods = type.GetMembers(_defaultBinding); int index = 0; if (methods != null && methods.Length > 0) { foreach (MemberInfo info in methods) { index++; if (index < 0) { break; } if (info.MemberType == MemberTypes.Method) { MethodInfo method = (MethodInfo)info; MethodAttribute attr = GetMethodAttribute(method); if (attr != null && string.Compare(attr.MethodName, context.MethodName, true) == 0) { infos.Add(method); } else if (string.Compare(info.Name, context.MethodName, true) == 0) { infos.Add(method); } } } } cache[context.MethodName] = infos; } } } return(infos); }
private void ConnectDecodedMethods(Assembly assembly) { foreach (var bridgeProcessorType in assembly.GetTypes().Where(x => typeof(BridgeCpu).IsAssignableFrom(x))) { object instance = null; foreach (var methodInfo in bridgeProcessorType.GetMethods(BindingFlags.Instance | BindingFlags.Public)) { var attribute = methodInfo.GetCustomAttribute <MethodInfoAttribute>(); if (attribute == null) { continue; } var mi = MethodInfoCollection.GetByIdOrNull(attribute.Id); if (mi == null) { continue; } if (instance == null) { instance = Activator.CreateInstance(bridgeProcessorType, Implementation); foreach (var pi in bridgeProcessorType.GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(x => x.PropertyType == typeof(RawProgramMain))) { pi.SetValue(instance, this); } } var fi = new MyMethodInfo(); fi.MethodInfo = mi; fi.Action = (Action)methodInfo.CreateDelegate(typeof(Action), instance); MethodsByAddress.Add(mi.Address, fi); } } }
protected static MethodInfo FindMethodInfo(InvokeContextBase context) { if (context != null && !string.IsNullOrEmpty(context.TypeName) && !string.IsNullOrEmpty(context.MethodName)) { Type type = ActivatorEx.GetType(context.TypeName); if (type == null) { return(null); } MethodInfoCollection methods = GetMethodCollectionAndCache(context, type); if (methods != null && methods.Count > 0) { if (methods.Count == 1) { return(CreateMethodEx(methods[0])); } object[] args = context.Arguments; if (args == null) { args = _emptyArgs; context.Arguments = args; } int len = args.Length; Type[] argTypes = context.ArgumentTypes; bool selectedTypes = true; if (argTypes == null) { selectedTypes = false; argTypes = new Type[len]; for (int i = 0; i < len; i++) { if (args[i] != null) { argTypes[i] = args[i].GetType(); } } } BindingFlags binding = _defaultBinding; ArrayList list = new ArrayList(methods.Count); for (int i = 0; i < methods.Count; i++) { if (FilterApplyMethodBaseInfo(methods[i], binding, CallingConventions.Any, argTypes)) { list.Add(methods[i]); } } len = list.Count; if (len >= 1) { MethodInfoEx info = null; if (len == 1) { info = CreateMethodEx(list[0] as MethodInfo); } else { Binder binder = Type.DefaultBinder; MethodBase methodBase = null; MethodBase[] array = new MethodBase[len]; list.CopyTo(array); try { if (!selectedTypes) { object state; methodBase = binder.BindToMethod(binding, array, ref args, null, null, null, out state); } else { methodBase = binder.SelectMethod(binding, array, argTypes, null); } } catch (MissingMethodException) { methodBase = null; } if (methodBase != null) { info = CreateMethodEx(methodBase as MethodInfo); } } return(info); } } } return(null); }