mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-21 05:18:38 +00:00
This commit is contained in:
parent
d013d61cfb
commit
dda4b2f028
10 changed files with 187 additions and 223 deletions
|
|
@ -155,7 +155,7 @@ namespace Cosmos.Build.MSBuild {
|
|||
DebugCom = 0;
|
||||
}
|
||||
|
||||
var xAsm = new AppAssemblerNasm(DebugCom);
|
||||
var xAsm = new AppAssembler(DebugCom);
|
||||
using (var xDebugInfo = new DebugInfo(xOutputFilename + ".mdf", true)) {
|
||||
xAsm.DebugInfo = xDebugInfo;
|
||||
xAsm.DebugEnabled = DebugEnabled;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ using Mono.Cecil;
|
|||
using Cosmos.Assembler.x86;
|
||||
using System.Diagnostics.SymbolStore;
|
||||
using Microsoft.Samples.Debugging.CorSymbolStore;
|
||||
using System.IO;
|
||||
|
||||
namespace Cosmos.IL2CPU {
|
||||
public class AppAssembler {
|
||||
|
|
@ -39,7 +40,7 @@ namespace Cosmos.IL2CPU {
|
|||
public Dictionary<Assembly, Guid> Assemblies = new Dictionary<Assembly, Guid>();
|
||||
|
||||
protected Cosmos.Assembler.Assembler mAssembler;
|
||||
protected AppAssembler(int aComPort) {
|
||||
public AppAssembler(int aComPort) {
|
||||
mAssembler = new Cosmos.Assembler.Assembler(aComPort);
|
||||
mLog = new System.IO.StreamWriter("Cosmos.Assembler.Log");
|
||||
InitILOps();
|
||||
|
|
@ -57,11 +58,127 @@ namespace Cosmos.IL2CPU {
|
|||
new Comment("Name: " + aMethod.MethodBase.Name);
|
||||
new Comment("Plugged: " + (aMethod.PlugMethod == null ? "No" : "Yes"));
|
||||
|
||||
//var xMethod = new Cosmos.Debug.Common.Method() {
|
||||
// MethodToken = aMethod.MethodBase.MetadataToken,
|
||||
// TypeToken = aMethod.MethodBase.DeclaringType.MetadataToken
|
||||
//};
|
||||
//DebugInfo.AddMethod(xMethod);
|
||||
if (aMethod.PluggedMethod != null) {
|
||||
new Cosmos.Assembler.Label("PLUG_FOR___" + MethodInfoLabelGenerator.GenerateLabelName(aMethod.PluggedMethod.MethodBase));
|
||||
} else {
|
||||
new Cosmos.Assembler.Label(aMethod.MethodBase);
|
||||
}
|
||||
var xMethodLabel = Cosmos.Assembler.Label.LastFullLabel;
|
||||
if (aMethod.MethodBase.IsStatic && aMethod.MethodBase is ConstructorInfo) {
|
||||
new Comment("This is a static constructor. see if it has been called already, and if so, return.");
|
||||
var xName = DataMember.FilterStringForIncorrectChars("CCTOR_CALLED__" + MethodInfoLabelGenerator.GetFullName(aMethod.MethodBase.DeclaringType));
|
||||
var xAsmMember = new DataMember(xName, (byte)0);
|
||||
Assembler.DataMembers.Add(xAsmMember);
|
||||
new Compare { DestinationRef = Cosmos.Assembler.ElementReference.New(xName), DestinationIsIndirect = true, Size = 8, SourceValue = 1 };
|
||||
new ConditionalJump { Condition = ConditionalTestEnum.Equal, DestinationLabel = ".BeforeQuickReturn" };
|
||||
new Mov { DestinationRef = Cosmos.Assembler.ElementReference.New(xName), DestinationIsIndirect = true, Size = 8, SourceValue = 1 };
|
||||
new Jump { DestinationLabel = ".AfterCCTorAlreadyCalledCheck" };
|
||||
new Cosmos.Assembler.Label(".BeforeQuickReturn");
|
||||
new Mov { DestinationReg = RegistersEnum.ECX, SourceValue = 0 };
|
||||
new Return { };
|
||||
new Cosmos.Assembler.Label(".AfterCCTorAlreadyCalledCheck");
|
||||
}
|
||||
|
||||
new Push { DestinationReg = Registers.EBP };
|
||||
new Mov { DestinationReg = Registers.EBP, SourceReg = Registers.ESP };
|
||||
//new CPUx86.Push("0");
|
||||
//if (!(aLabelName.Contains("Cosmos.Kernel.Serial") || aLabelName.Contains("Cosmos.Kernel.Heap"))) {
|
||||
// new CPUx86.Push(LdStr.GetContentsArrayName(aAssembler, aLabelName));
|
||||
// MethodBase xTempMethod = Engine.GetMethodBase(Engine.GetType("Cosmos.Kernel", "Cosmos.Kernel.Serial"), "Write", "System.Byte", "System.String");
|
||||
// new CPUx86.Call(MethodInfoLabelGenerator.GenerateLabelName(xTempMethod));
|
||||
// Engine.QueueMethod(xTempMethod);
|
||||
//}
|
||||
#region Load CodeOffset
|
||||
ISymbolMethod xMethodSymbols;
|
||||
if (DebugMode == DebugMode.Source) {
|
||||
var xSymbolReader = GetSymbolReaderForAssembly(aMethod.MethodBase.DeclaringType.Assembly);
|
||||
if (xSymbolReader != null) {
|
||||
xMethodSymbols = xSymbolReader.GetMethod(new SymbolToken(aMethod.MethodBase.MetadataToken));
|
||||
// This gets the Sequence Points.
|
||||
// Sequence Points are spots that identify what the compiler/debugger says is a spot
|
||||
// that a breakpoint can occur one. Essentially, an atomic source line in C#
|
||||
if (xMethodSymbols != null) {
|
||||
xCodeOffsets = new int[xMethodSymbols.SequencePointCount];
|
||||
var xCodeDocuments = new ISymbolDocument[xMethodSymbols.SequencePointCount];
|
||||
xCodeLineNumbers = new int[xMethodSymbols.SequencePointCount];
|
||||
var xCodeColumns = new int[xMethodSymbols.SequencePointCount];
|
||||
var xCodeEndLines = new int[xMethodSymbols.SequencePointCount];
|
||||
var xCodeEndColumns = new int[xMethodSymbols.SequencePointCount];
|
||||
xMethodSymbols.GetSequencePoints(xCodeOffsets, xCodeDocuments
|
||||
, xCodeLineNumbers, xCodeColumns, xCodeEndLines, xCodeEndColumns);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
if (aMethod.MethodAssembler == null && aMethod.PlugMethod == null && !aMethod.IsInlineAssembler) {
|
||||
// the body of aMethod is getting emitted
|
||||
var xBody = aMethod.MethodBase.GetMethodBody();
|
||||
if (xBody != null) {
|
||||
var xLocalsOffset = mLocals_Arguments_Infos.Count;
|
||||
foreach (var xLocal in xBody.LocalVariables) {
|
||||
var xInfo = new LOCAL_ARGUMENT_INFO {
|
||||
METHODLABELNAME = xMethodLabel,
|
||||
IsArgument = false,
|
||||
INDEXINMETHOD = xLocal.LocalIndex,
|
||||
NAME = "Local" + xLocal.LocalIndex,
|
||||
OFFSET = 0 - (int)X86.ILOp.GetEBPOffsetForLocalForDebugger(aMethod, xLocal.LocalIndex),
|
||||
TYPENAME = xLocal.LocalType.AssemblyQualifiedName
|
||||
};
|
||||
mLocals_Arguments_Infos.Add(xInfo);
|
||||
|
||||
var xSize = ILOp.Align(X86.ILOp.SizeOfType(xLocal.LocalType), 4);
|
||||
new Comment(String.Format("Local {0}, Size {1}", xLocal.LocalIndex, xSize));
|
||||
for (int i = 0; i < xSize / 4; i++) {
|
||||
new Push { DestinationValue = 0 };
|
||||
}
|
||||
//new Sub { DestinationReg = Registers.ESP, SourceValue = ILOp.Align(ILOp.SizeOfType(xLocal.LocalType), 4) };
|
||||
}
|
||||
var xCecilMethod = GetCecilMethodDefinitionForSymbolReading(aMethod.MethodBase);
|
||||
if (xCecilMethod != null && xCecilMethod.Body != null) {
|
||||
// mLocals_Arguments_Infos is one huge list, so ourlatest additions are at the end
|
||||
for (int i = 0; i < xCecilMethod.Body.Variables.Count; i++) {
|
||||
mLocals_Arguments_Infos[xLocalsOffset + i].NAME = xCecilMethod.Body.Variables[i].Name;
|
||||
}
|
||||
for (int i = xLocalsOffset + xCecilMethod.Body.Variables.Count - 1; i >= xLocalsOffset; i--) {
|
||||
if (mLocals_Arguments_Infos[i].NAME.Contains('$')) {
|
||||
mLocals_Arguments_Infos.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// debug info:
|
||||
var xIdxOffset = 0u;
|
||||
if (!aMethod.MethodBase.IsStatic) {
|
||||
mLocals_Arguments_Infos.Add(new LOCAL_ARGUMENT_INFO {
|
||||
METHODLABELNAME = xMethodLabel,
|
||||
IsArgument = true,
|
||||
NAME = "this:" + X86.IL.Ldarg.GetArgumentDisplacement(aMethod, 0),
|
||||
INDEXINMETHOD = 0,
|
||||
OFFSET = X86.IL.Ldarg.GetArgumentDisplacement(aMethod, 0),
|
||||
TYPENAME = aMethod.MethodBase.DeclaringType.AssemblyQualifiedName
|
||||
});
|
||||
|
||||
xIdxOffset++;
|
||||
}
|
||||
|
||||
var xParams = aMethod.MethodBase.GetParameters();
|
||||
var xParamCount = (ushort)xParams.Length;
|
||||
|
||||
for (ushort i = 0; i < xParamCount; i++) {
|
||||
var xOffset = X86.IL.Ldarg.GetArgumentDisplacement(aMethod, (ushort)(i + xIdxOffset));
|
||||
// if last argument is 8 byte long, we need to add 4, so that debugger could read all 8 bytes from this variable in positiv direction
|
||||
xOffset -= (int)Cosmos.IL2CPU.ILOp.Align(X86.ILOp.SizeOfType(xParams[i].ParameterType), 4) - 4;
|
||||
mLocals_Arguments_Infos.Add(new LOCAL_ARGUMENT_INFO {
|
||||
METHODLABELNAME = xMethodLabel,
|
||||
IsArgument = true,
|
||||
INDEXINMETHOD = (int)(i + xIdxOffset),
|
||||
NAME = xParams[i].Name,
|
||||
OFFSET = xOffset,
|
||||
TYPENAME = xParams[i].ParameterType.AssemblyQualifiedName
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void MethodBegin(string aMethodName) {
|
||||
|
|
@ -888,5 +1005,43 @@ namespace Cosmos.IL2CPU {
|
|||
new INT3();
|
||||
}
|
||||
|
||||
protected MethodDefinition GetCecilMethodDefinitionForSymbolReading(MethodBase methodBase) {
|
||||
var xMethodBase = methodBase;
|
||||
if (xMethodBase.IsGenericMethod) {
|
||||
var xMethodInfo = (System.Reflection.MethodInfo)xMethodBase;
|
||||
xMethodBase = xMethodInfo.GetGenericMethodDefinition();
|
||||
if (xMethodBase.IsGenericMethod) {
|
||||
// apparently, a generic method can be derived from a generic method..
|
||||
throw new Exception("Make recursive");
|
||||
}
|
||||
}
|
||||
var xLocation = xMethodBase.DeclaringType.Assembly.Location;
|
||||
ModuleDefinition xModule = null;
|
||||
if (!mLoadedModules.TryGetValue(xLocation, out xModule)) {
|
||||
// if not in cache, try loading.
|
||||
if (xMethodBase.DeclaringType.Assembly.GlobalAssemblyCache || !File.Exists(xLocation)) {
|
||||
// file doesn't exist, so assume no symbols
|
||||
mLoadedModules.Add(xLocation, null);
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
xModule = ModuleDefinition.ReadModule(xLocation, new ReaderParameters { ReadSymbols = true, SymbolReaderProvider = new Mono.Cecil.Pdb.PdbReaderProvider() });
|
||||
} catch (InvalidOperationException) {
|
||||
throw new Exception("Please check that dll and pdb file is matching on location: " + xLocation);
|
||||
}
|
||||
if (xModule.HasSymbols) {
|
||||
mLoadedModules.Add(xLocation, xModule);
|
||||
} else {
|
||||
mLoadedModules.Add(xLocation, null);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (xModule == null) {
|
||||
return null;
|
||||
}
|
||||
// todo: cache MethodDefinition ?
|
||||
return xModule.LookupToken(xMethodBase.MetadataToken) as MethodDefinition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,7 +181,6 @@
|
|||
<Compile Include="SkipList.cs" />
|
||||
<Compile Include="VTablesImpl.cs" />
|
||||
<Compile Include="VTablesImplRefs.cs" />
|
||||
<Compile Include="x86\AppAssemblerNasm.cs" />
|
||||
<Compile Include="x86\ILOp.cs" />
|
||||
<Compile Include="x86\IL\Add.cs" />
|
||||
<Compile Include="x86\IL\Add_Ovf.cs" />
|
||||
|
|
|
|||
|
|
@ -1,190 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using CPU = Cosmos.Assembler;
|
||||
using Cosmos.Assembler.x86;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics.SymbolStore;
|
||||
using Microsoft.Samples.Debugging.CorSymbolStore;
|
||||
using Cosmos.Debug.Common;
|
||||
using Cosmos.Build.Common;
|
||||
using CPUx86 = Cosmos.Assembler.x86;
|
||||
using Mono.Cecil;
|
||||
using System.IO;
|
||||
|
||||
namespace Cosmos.IL2CPU.X86 {
|
||||
public class AppAssemblerNasm : IL2CPU.AppAssembler {
|
||||
|
||||
public AppAssemblerNasm(byte aComPort)
|
||||
: base(aComPort) {
|
||||
}
|
||||
|
||||
protected override void MethodBegin(MethodInfo aMethod) {
|
||||
base.MethodBegin(aMethod);
|
||||
if (aMethod.PluggedMethod != null) {
|
||||
new Cosmos.Assembler.Label("PLUG_FOR___" + CPU.MethodInfoLabelGenerator.GenerateLabelName(aMethod.PluggedMethod.MethodBase));
|
||||
} else {
|
||||
new Cosmos.Assembler.Label(aMethod.MethodBase);
|
||||
}
|
||||
var xMethodLabel = Cosmos.Assembler.Label.LastFullLabel;
|
||||
if (aMethod.MethodBase.IsStatic && aMethod.MethodBase is ConstructorInfo) {
|
||||
new CPU.Comment("This is a static constructor. see if it has been called already, and if so, return.");
|
||||
var xName = CPU.DataMember.FilterStringForIncorrectChars("CCTOR_CALLED__" + CPU.MethodInfoLabelGenerator.GetFullName(aMethod.MethodBase.DeclaringType));
|
||||
var xAsmMember = new CPU.DataMember(xName, (byte)0);
|
||||
Assembler.DataMembers.Add(xAsmMember);
|
||||
new Compare { DestinationRef = Cosmos.Assembler.ElementReference.New(xName), DestinationIsIndirect = true, Size = 8, SourceValue = 1 };
|
||||
new ConditionalJump { Condition = ConditionalTestEnum.Equal, DestinationLabel = ".BeforeQuickReturn" };
|
||||
new Mov { DestinationRef = Cosmos.Assembler.ElementReference.New(xName), DestinationIsIndirect = true, Size = 8, SourceValue = 1 };
|
||||
new Jump { DestinationLabel = ".AfterCCTorAlreadyCalledCheck" };
|
||||
new Cosmos.Assembler.Label(".BeforeQuickReturn");
|
||||
new Mov { DestinationReg = RegistersEnum.ECX, SourceValue = 0 };
|
||||
new Return { };
|
||||
new Cosmos.Assembler.Label(".AfterCCTorAlreadyCalledCheck");
|
||||
}
|
||||
|
||||
new Push { DestinationReg = Registers.EBP };
|
||||
new Mov { DestinationReg = Registers.EBP, SourceReg = Registers.ESP };
|
||||
//new CPUx86.Push("0");
|
||||
//if (!(aLabelName.Contains("Cosmos.Kernel.Serial") || aLabelName.Contains("Cosmos.Kernel.Heap"))) {
|
||||
// new CPUx86.Push(LdStr.GetContentsArrayName(aAssembler, aLabelName));
|
||||
// MethodBase xTempMethod = Engine.GetMethodBase(Engine.GetType("Cosmos.Kernel", "Cosmos.Kernel.Serial"), "Write", "System.Byte", "System.String");
|
||||
// new CPUx86.Call(MethodInfoLabelGenerator.GenerateLabelName(xTempMethod));
|
||||
// Engine.QueueMethod(xTempMethod);
|
||||
//}
|
||||
#region Load CodeOffset
|
||||
ISymbolMethod xMethodSymbols;
|
||||
if (DebugMode == DebugMode.Source) {
|
||||
var xSymbolReader = GetSymbolReaderForAssembly(aMethod.MethodBase.DeclaringType.Assembly);
|
||||
if (xSymbolReader != null) {
|
||||
xMethodSymbols = xSymbolReader.GetMethod(new SymbolToken(aMethod.MethodBase.MetadataToken));
|
||||
// This gets the Sequence Points.
|
||||
// Sequence Points are spots that identify what the compiler/debugger says is a spot
|
||||
// that a breakpoint can occur one. Essentially, an atomic source line in C#
|
||||
if (xMethodSymbols != null) {
|
||||
xCodeOffsets = new int[xMethodSymbols.SequencePointCount];
|
||||
var xCodeDocuments = new ISymbolDocument[xMethodSymbols.SequencePointCount];
|
||||
xCodeLineNumbers = new int[xMethodSymbols.SequencePointCount];
|
||||
var xCodeColumns = new int[xMethodSymbols.SequencePointCount];
|
||||
var xCodeEndLines = new int[xMethodSymbols.SequencePointCount];
|
||||
var xCodeEndColumns = new int[xMethodSymbols.SequencePointCount];
|
||||
xMethodSymbols.GetSequencePoints(xCodeOffsets, xCodeDocuments
|
||||
, xCodeLineNumbers, xCodeColumns, xCodeEndLines, xCodeEndColumns);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
if (aMethod.MethodAssembler == null && aMethod.PlugMethod == null && !aMethod.IsInlineAssembler) {
|
||||
// the body of aMethod is getting emitted
|
||||
var xBody = aMethod.MethodBase.GetMethodBody();
|
||||
if (xBody != null) {
|
||||
var xLocalsOffset = mLocals_Arguments_Infos.Count;
|
||||
foreach (var xLocal in xBody.LocalVariables) {
|
||||
var xInfo = new LOCAL_ARGUMENT_INFO {
|
||||
METHODLABELNAME = xMethodLabel,
|
||||
IsArgument = false,
|
||||
INDEXINMETHOD = xLocal.LocalIndex,
|
||||
NAME = "Local" + xLocal.LocalIndex,
|
||||
OFFSET = 0 - (int)ILOp.GetEBPOffsetForLocalForDebugger(aMethod, xLocal.LocalIndex),
|
||||
TYPENAME = xLocal.LocalType.AssemblyQualifiedName
|
||||
};
|
||||
mLocals_Arguments_Infos.Add(xInfo);
|
||||
|
||||
var xSize = ILOp.Align(ILOp.SizeOfType(xLocal.LocalType), 4);
|
||||
new CPU.Comment(String.Format("Local {0}, Size {1}", xLocal.LocalIndex, xSize));
|
||||
for (int i = 0; i < xSize / 4; i++) {
|
||||
new Push { DestinationValue = 0 };
|
||||
}
|
||||
//new Sub { DestinationReg = Registers.ESP, SourceValue = ILOp.Align(ILOp.SizeOfType(xLocal.LocalType), 4) };
|
||||
}
|
||||
var xCecilMethod = GetCecilMethodDefinitionForSymbolReading(aMethod.MethodBase);
|
||||
if (xCecilMethod != null && xCecilMethod.Body != null) {
|
||||
// mLocals_Arguments_Infos is one huge list, so ourlatest additions are at the end
|
||||
for (int i = 0; i < xCecilMethod.Body.Variables.Count; i++) {
|
||||
mLocals_Arguments_Infos[xLocalsOffset + i].NAME = xCecilMethod.Body.Variables[i].Name;
|
||||
}
|
||||
for (int i = xLocalsOffset + xCecilMethod.Body.Variables.Count - 1; i >= xLocalsOffset; i--) {
|
||||
if (mLocals_Arguments_Infos[i].NAME.Contains('$')) {
|
||||
mLocals_Arguments_Infos.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// debug info:
|
||||
var xIdxOffset = 0u;
|
||||
if (!aMethod.MethodBase.IsStatic) {
|
||||
mLocals_Arguments_Infos.Add(new LOCAL_ARGUMENT_INFO {
|
||||
METHODLABELNAME = xMethodLabel,
|
||||
IsArgument = true,
|
||||
NAME = "this:" + IL.Ldarg.GetArgumentDisplacement(aMethod, 0),
|
||||
INDEXINMETHOD = 0,
|
||||
OFFSET = IL.Ldarg.GetArgumentDisplacement(aMethod, 0),
|
||||
TYPENAME = aMethod.MethodBase.DeclaringType.AssemblyQualifiedName
|
||||
});
|
||||
|
||||
xIdxOffset++;
|
||||
}
|
||||
|
||||
var xParams = aMethod.MethodBase.GetParameters();
|
||||
var xParamCount = (ushort)xParams.Length;
|
||||
|
||||
for (ushort i = 0; i < xParamCount; i++) {
|
||||
var xOffset = IL.Ldarg.GetArgumentDisplacement(aMethod, (ushort)(i + xIdxOffset));
|
||||
// if last argument is 8 byte long, we need to add 4, so that debugger could read all 8 bytes from this variable in positiv direction
|
||||
xOffset -= (int)Cosmos.IL2CPU.X86.ILOp.Align(Cosmos.IL2CPU.X86.ILOp.SizeOfType(xParams[i].ParameterType), 4) - 4;
|
||||
mLocals_Arguments_Infos.Add(new LOCAL_ARGUMENT_INFO {
|
||||
METHODLABELNAME = xMethodLabel,
|
||||
IsArgument = true,
|
||||
INDEXINMETHOD = (int)(i + xIdxOffset),
|
||||
NAME = xParams[i].Name,
|
||||
OFFSET = xOffset,
|
||||
TYPENAME = xParams[i].ParameterType.AssemblyQualifiedName
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected MethodDefinition GetCecilMethodDefinitionForSymbolReading(MethodBase methodBase) {
|
||||
var xMethodBase = methodBase;
|
||||
if (xMethodBase.IsGenericMethod) {
|
||||
var xMethodInfo = (System.Reflection.MethodInfo)xMethodBase;
|
||||
xMethodBase = xMethodInfo.GetGenericMethodDefinition();
|
||||
if (xMethodBase.IsGenericMethod) {
|
||||
// apparently, a generic method can be derived from a generic method..
|
||||
throw new Exception("Make recursive");
|
||||
}
|
||||
}
|
||||
var xLocation = xMethodBase.DeclaringType.Assembly.Location;
|
||||
ModuleDefinition xModule = null;
|
||||
if (!mLoadedModules.TryGetValue(xLocation, out xModule)) {
|
||||
// if not in cache, try loading.
|
||||
if (xMethodBase.DeclaringType.Assembly.GlobalAssemblyCache || !File.Exists(xLocation)) {
|
||||
// file doesn't exist, so assume no symbols
|
||||
mLoadedModules.Add(xLocation, null);
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
xModule = ModuleDefinition.ReadModule(xLocation, new ReaderParameters { ReadSymbols = true, SymbolReaderProvider = new Mono.Cecil.Pdb.PdbReaderProvider() });
|
||||
}
|
||||
catch (InvalidOperationException) {
|
||||
throw new Exception("Please check that dll and pdb file is matching on location: " + xLocation);
|
||||
}
|
||||
if (xModule.HasSymbols) {
|
||||
mLoadedModules.Add(xLocation, xModule);
|
||||
} else {
|
||||
mLoadedModules.Add(xLocation, null);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (xModule == null) {
|
||||
return null;
|
||||
}
|
||||
// todo: cache MethodDefinition ?
|
||||
return xModule.LookupToken(xMethodBase.MetadataToken) as MethodDefinition;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ namespace Cosmos.IL2CPU.X86.IL
|
|||
|
||||
public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
|
||||
{
|
||||
new CPU.Jump { DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.Jump { DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ namespace Cosmos.IL2CPU.X86.IL
|
|||
new CPU.Pop { DestinationReg = CPU.Registers.EAX };
|
||||
new CPU.Pop { DestinationReg = CPU.Registers.EBX };
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.EBX, SourceReg = CPU.Registers.EAX };
|
||||
new CPU.ConditionalJump { Condition = xTestOp, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = xTestOp, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
//}
|
||||
}
|
||||
else
|
||||
|
|
@ -133,64 +133,64 @@ namespace Cosmos.IL2CPU.X86.IL
|
|||
case ConditionalTestEnum.Zero: // Equal
|
||||
case ConditionalTestEnum.NotEqual: // NotZero
|
||||
new CPU.Xor { DestinationReg = CPU.Registers.EAX, SourceReg = CPU.Registers.ECX };
|
||||
new CPU.ConditionalJump { Condition = xTestOp, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = xTestOp, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.Xor { DestinationReg = CPU.Registers.EBX, SourceReg = CPU.Registers.EDX };
|
||||
new CPU.ConditionalJump { Condition = xTestOp, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = xTestOp, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
break;
|
||||
case ConditionalTestEnum.GreaterThanOrEqualTo:
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.EDX, SourceReg = CPU.Registers.EBX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.LessThan, DestinationLabel = xNoJump };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.GreaterThan, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.GreaterThan, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.ECX, SourceReg = CPU.Registers.EAX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Below, DestinationLabel = xNoJump };
|
||||
break;
|
||||
case ConditionalTestEnum.GreaterThan:
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.EDX, SourceReg = CPU.Registers.EBX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.LessThan, DestinationLabel = xNoJump };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.GreaterThan, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.GreaterThan, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.ECX, SourceReg = CPU.Registers.EAX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.BelowOrEqual, DestinationLabel = xNoJump };
|
||||
break;
|
||||
case ConditionalTestEnum.LessThanOrEqualTo:
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.EDX, SourceReg = CPU.Registers.EBX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.LessThan, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.LessThan, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.GreaterThan, DestinationLabel = xNoJump };
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.ECX, SourceReg = CPU.Registers.EAX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.BelowOrEqual, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.BelowOrEqual, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
break;
|
||||
case ConditionalTestEnum.LessThan:
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.EDX, SourceReg = CPU.Registers.EBX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.LessThan, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.LessThan, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.GreaterThan, DestinationLabel = xNoJump };
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.ECX, SourceReg = CPU.Registers.EAX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Below, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Below, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
break;
|
||||
// from here all unsigned
|
||||
case ConditionalTestEnum.AboveOrEqual:
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.EDX, SourceReg = CPU.Registers.EBX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Above, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Above, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.ECX, SourceReg = CPU.Registers.EAX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Below, DestinationLabel = xNoJump };
|
||||
break;
|
||||
case ConditionalTestEnum.Above:
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.EDX, SourceReg = CPU.Registers.EBX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Above, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Above, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.ECX, SourceReg = CPU.Registers.EAX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.BelowOrEqual, DestinationLabel = xNoJump };
|
||||
break;
|
||||
case ConditionalTestEnum.BelowOrEqual:
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.EDX, SourceReg = CPU.Registers.EBX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Above, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Above, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Below, DestinationLabel = xNoJump };
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.ECX, SourceReg = CPU.Registers.EAX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Above, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Above, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
break;
|
||||
case ConditionalTestEnum.Below:
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.EDX, SourceReg = CPU.Registers.EBX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Above, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Above, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.Below, DestinationLabel = xNoJump };
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.ECX, SourceReg = CPU.Registers.EAX };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.AboveOrEqual, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = CPU.ConditionalTestEnum.AboveOrEqual, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unknown OpCode for conditional branch in 64-bit.");
|
||||
|
|
@ -216,12 +216,12 @@ namespace Cosmos.IL2CPU.X86.IL
|
|||
if (xTestOp == ConditionalTestEnum.Zero)
|
||||
{
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.EAX, SourceValue = 0 };
|
||||
new CPU.ConditionalJump { Condition = ConditionalTestEnum.Equal, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = ConditionalTestEnum.Equal, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
}
|
||||
else if (xTestOp == ConditionalTestEnum.NotZero)
|
||||
{
|
||||
new CPU.Compare { DestinationReg = CPU.Registers.EAX, SourceValue = 0 };
|
||||
new CPU.ConditionalJump { Condition = ConditionalTestEnum.NotEqual, DestinationLabel = AppAssemblerNasm.TmpBranchLabel(aMethod, aOpCode) };
|
||||
new CPU.ConditionalJump { Condition = ConditionalTestEnum.NotEqual, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode) };
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Cosmos.IL2CPU.X86.IL
|
|||
|
||||
public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
|
||||
{
|
||||
new CPUx86.Jump { DestinationLabel = AppAssemblerNasm.TmpBranchLabel( aMethod, aOpCode ) };
|
||||
new CPUx86.Jump { DestinationLabel = AppAssembler.TmpBranchLabel( aMethod, aOpCode ) };
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace Cosmos.IL2CPU.X86.IL
|
|||
}
|
||||
else
|
||||
throw new NotSupportedException("A size bigger 8 not supported at Shr!");
|
||||
/*string xLabelName = AppAssemblerNasm.TmpPosLabel(aMethod, aOpCode);
|
||||
/*string xLabelName = AppAssembler.TmpPosLabel(aMethod, aOpCode);
|
||||
var xStackItem_ShiftAmount = Assembler.Stack.Pop();
|
||||
var xStackItem_Value = Assembler.Stack.Peek();
|
||||
if( xStackItem_Value.Size <= 4 )
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace Cosmos.IL2CPU.X86.IL
|
|||
{
|
||||
new CPUx86.Compare { DestinationReg = CPUx86.Registers.EAX, SourceValue = ( uint )i };
|
||||
//string DestLabel = AssemblerNasm.TmpBranchLabel( aMethod, new ILOpCodes.OpBranch( ILOpCode.Code.Jmp, aOpCode.Position, OpSw.BranchLocations[ i ] ) );
|
||||
string xDestLabel = AppAssemblerNasm.TmpPosLabel(aMethod, OpSw.BranchLocations[i]);
|
||||
string xDestLabel = AppAssembler.TmpPosLabel(aMethod, OpSw.BranchLocations[i]);
|
||||
new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.Equal
|
||||
, DestinationLabel = xDestLabel
|
||||
};
|
||||
|
|
|
|||
|
|
@ -24,11 +24,11 @@ namespace Cosmos.IL2CPU.X86 {
|
|||
|
||||
protected static void Jump_Exception(MethodInfo aMethod) {
|
||||
// todo: port to numeric labels
|
||||
new CPU.Jump { DestinationLabel = GetMethodLabel(aMethod) + AppAssemblerNasm.EndOfMethodLabelNameException };
|
||||
new CPU.Jump { DestinationLabel = GetMethodLabel(aMethod) + AppAssembler.EndOfMethodLabelNameException };
|
||||
}
|
||||
|
||||
protected static void Jump_End(MethodInfo aMethod) {
|
||||
new CPU.Jump { DestinationLabel = GetMethodLabel(aMethod) + AppAssemblerNasm.EndOfMethodLabelNameNormal };
|
||||
new CPU.Jump { DestinationLabel = GetMethodLabel(aMethod) + AppAssembler.EndOfMethodLabelNameNormal };
|
||||
}
|
||||
|
||||
public static uint GetStackCountForLocal(MethodInfo aMethod, LocalVariableInfo aField) {
|
||||
|
|
@ -221,13 +221,13 @@ namespace Cosmos.IL2CPU.X86 {
|
|||
new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.Equal, DestinationLabel = aJumpTargetNoException };
|
||||
aCleanup();
|
||||
if (xJumpTo == null) {
|
||||
new CPU.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.NotEqual, DestinationLabel = GetMethodLabel(aMethodInfo) + AppAssemblerNasm.EndOfMethodLabelNameException };
|
||||
new CPU.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.NotEqual, DestinationLabel = GetMethodLabel(aMethodInfo) + AppAssembler.EndOfMethodLabelNameException };
|
||||
} else {
|
||||
new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.NotEqual, DestinationLabel = xJumpTo };
|
||||
}
|
||||
} else {
|
||||
if (xJumpTo == null) {
|
||||
new CPU.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.NotEqual, DestinationLabel = GetMethodLabel(aMethodInfo) + AppAssemblerNasm.EndOfMethodLabelNameException };
|
||||
new CPU.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.NotEqual, DestinationLabel = GetMethodLabel(aMethodInfo) + AppAssembler.EndOfMethodLabelNameException };
|
||||
} else {
|
||||
new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.NotEqual, DestinationLabel = xJumpTo };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue