本文整理汇总了C#中Mosa.Runtime.CompilerFramework.Operands.RegisterOperand类的典型用法代码示例。如果您正苦于以下问题:C# RegisterOperand类的具体用法?C# RegisterOperand怎么用?C# RegisterOperand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RegisterOperand类属于Mosa.Runtime.CompilerFramework.Operands命名空间,在下文中一共展示了RegisterOperand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateISRMethods
/// <summary>
/// Creates the ISR methods.
/// </summary>
/// <param name="compiler">The compiler.</param>
private void CreateISRMethods(AssemblyCompiler compiler)
{
// Create Interrupt Service Routines (ISR)
RuntimeMethod InterruptMethod = compiler.Assembly.EntryPoint; // TODO: replace with another entry point
SigType I1 = new SigType(CilElementType.I1);
SigType I4 = new SigType(CilElementType.I4);
RegisterOperand eax = new RegisterOperand(I4, GeneralPurposeRegister.EAX);
for (int i = 0; i <= 256; i++) {
InstructionSet set = new InstructionSet(100);
Context ctx = new Context(set, -1);
ctx.SetInstruction(CPUx86.Instruction.CliInstruction);
if ((i != 8) && (i < 10 || i > 14)) // For IRQ 8, 10, 11, 12, 13, 14 the cpu automatically pushed the error code
ctx.AppendInstruction(CPUx86.Instruction.PushInstruction, null, new ConstantOperand(I4, 0x0));
ctx.AppendInstruction(CPUx86.Instruction.PushadInstruction);
ctx.AppendInstruction(CPUx86.Instruction.PushInstruction, null, new ConstantOperand(I4, i));
// TODO: Set method parameters
ctx.AppendInstruction(CPUx86.Instruction.CallInstruction, InterruptMethod);
ctx.AppendInstruction(CPUx86.Instruction.PopInstruction, eax);
ctx.AppendInstruction(CPUx86.Instruction.PopadInstruction);
ctx.AppendInstruction(CPUx86.Instruction.PopInstruction, eax);
ctx.AppendInstruction(CPUx86.Instruction.StiInstruction);
//ctx.AppendInstruction(CPUx86.Instruction.IRetdInstruction);
CompilerGeneratedMethod method = LinkTimeCodeGenerator.Compile(compiler, @"InterruptISR" + i.ToString(), set);
}
}
示例2: CreateISRMethods
/// <summary>
/// Creates the ISR methods.
/// </summary>
/// <param name="compiler">The compiler.</param>
private void CreateISRMethods(AssemblyCompiler compiler)
{
// Get RuntimeMethod for the Mosa.Kernel.X86.IDT.InterruptHandler
RuntimeType rt = RuntimeBase.Instance.TypeLoader.GetType(@"Mosa.Kernel.X86.IDT");
RuntimeMethod InterruptMethod = FindMethod(rt, "InterruptHandler");
SigType I1 = new SigType(CilElementType.I1);
SigType I2 = new SigType(CilElementType.I4);
RegisterOperand ecx1 = new RegisterOperand(I1, GeneralPurposeRegister.ECX);
RegisterOperand ecx2 = new RegisterOperand(I2, GeneralPurposeRegister.ECX);
for (int i = 0; i <= 256; i++) {
InstructionSet set = new InstructionSet(100);
Context ctx = new Context(set, -1);
ctx.AppendInstruction(CPUx86.Instruction.CliInstruction);
ctx.AppendInstruction(CPUx86.Instruction.PushadInstruction);
if ((i != 8) && (i < 10 || i > 14)) // For IRQ 8, 10, 11, 12, 13, 14 the cpu automatically pushed the error code
ctx.AppendInstruction(CPUx86.Instruction.PushInstruction, null, new ConstantOperand(I1, 0x0));
ctx.AppendInstruction(CPUx86.Instruction.PushInstruction, null, new ConstantOperand(I2, i));
ctx.AppendInstruction(CPUx86.Instruction.CallInstruction, InterruptMethod);
// TODO: Replace next two instructions with add esp, 5 ;Stack clearing
ctx.AppendInstruction(CPUx86.Instruction.PopInstruction, ecx2);
ctx.AppendInstruction(CPUx86.Instruction.PopInstruction, ecx1);
ctx.AppendInstruction(CPUx86.Instruction.PopadInstruction);
ctx.AppendInstruction(CPUx86.Instruction.StiInstruction);
ctx.AppendInstruction(CPUx86.Instruction.IRetdInstruction);
CompilerGeneratedMethod method = LinkTimeCodeGenerator.Compile(compiler, @"InterruptISR" + i.ToString(), set);
}
}
示例3: ReplaceIntrinsicCall
/// <summary>
/// Replaces the instrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
public void ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem)
{
Operand result = context.Result;
RegisterOperand imm = new RegisterOperand(new SigType(CilElementType.U4), GeneralPurposeRegister.EAX);
context.SetInstruction(IR.Instruction.MoveInstruction, imm, new RegisterOperand(new SigType(CilElementType.U4), _control));
context.AppendInstruction(IR.Instruction.MoveInstruction, result, imm);
}
示例4: RegisterOperand
/// <summary>
/// Visitation function for <see cref="IR.IIRVisitor.AddressOfInstruction"/> instruction.
/// </summary>
/// <param name="ctx">The context.</param>
void IR.IIRVisitor.AddressOfInstruction(Context ctx)
{
Operand opRes = ctx.Result;
RegisterOperand eax = new RegisterOperand (opRes.Type, GeneralPurposeRegister.EAX);
ctx.Result = eax;
ctx.ReplaceInstructionOnly (CPUx86.Instruction.LeaInstruction);
// ctx.Ignore = true;
ctx.AppendInstruction (CPUx86.Instruction.MovInstruction, opRes, eax);
}
示例5: ReplaceIntrinsicCall
/// <summary>
/// Replaces the instrinsic call site
/// </summary>
/// <param name="context">The context.</param>
public void ReplaceIntrinsicCall(Context context)
{
Operand operand1 = context.Operand1;
RegisterOperand imm = new RegisterOperand(new SigType(CilElementType.U4), GeneralPurposeRegister.EAX);
context.SetInstruction(IR.Instruction.MoveInstruction, imm, operand1);
context.AppendInstruction(IR.Instruction.MoveInstruction, new RegisterOperand(new SigType(CilElementType.U4), _control), imm);
}
示例6: ReplaceIntrinsicCall
/// <summary>
/// Replaces the instrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
public void ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem)
{
Operand result = context.Result;
RegisterOperand tmp = new RegisterOperand(new Mosa.Runtime.Metadata.Signatures.SigType(Mosa.Runtime.Metadata.CilElementType.Ptr), GeneralPurposeRegister.EDX);
MemoryOperand operand = new MemoryOperand(context.Operand1.Type, GeneralPurposeRegister.EDX, new System.IntPtr(0));
context.SetInstruction(CPUx86.Instruction.MovInstruction, tmp, context.Operand1);
context.AppendInstruction(CPUx86.Instruction.MovInstruction, result, operand);
}
示例7: ReplaceIntrinsicCall
/// <summary>
/// Replaces the instrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
public void ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem)
{
SigType I4 = new SigType(CilElementType.I4);
RegisterOperand esp = new RegisterOperand(I4, GeneralPurposeRegister.ESP);
context.SetInstruction(CPUx86.Instruction.MovInstruction, esp, context.Operand1);
context.AppendInstruction(CPUx86.Instruction.PopadInstruction);
context.AppendInstruction(CPUx86.Instruction.AddInstruction, esp, new ConstantOperand(I4, 0x08));
context.AppendInstruction(CPUx86.Instruction.StiInstruction);
context.AppendInstruction(CPUx86.Instruction.IRetdInstruction);
}
示例8: ThreeTwoAddressConversion
/// <summary>
/// Converts the given instruction from three address format to a two address format.
/// </summary>
/// <param name="ctx">The conversion context.</param>
private static void ThreeTwoAddressConversion(Context ctx)
{
Operand result = ctx.Result;
Operand op1 = ctx.Operand1;
Operand op2 = ctx.Operand2;
if (ctx.Instruction is IR.FloatingPointCompareInstruction)
return;
if (ctx.Instruction is CIL.MulInstruction /*|| ctx.Instruction is CIL.DivInstruction*/)
if (!(op1 is ConstantOperand) && (op2 is ConstantOperand))
{
Operand temp = op1;
op1 = op2;
op2 = temp;
}
// Create registers for different data types
RegisterOperand eax = new RegisterOperand(op1.Type, op1.StackType == StackTypeCode.F ? (Register)SSE2Register.XMM0 : GeneralPurposeRegister.EAX);
RegisterOperand storeOperand = new RegisterOperand(result.Type, result.StackType == StackTypeCode.F ? (Register)SSE2Register.XMM0 : GeneralPurposeRegister.EAX);
// RegisterOperand eaxL = new RegisterOperand(op1.Type, GeneralPurposeRegister.EAX);
ctx.Result = storeOperand;
ctx.Operand1 = op2;
ctx.Operand2 = null;
ctx.OperandCount = 1;
if (op1.StackType != StackTypeCode.F)
{
if (IsSigned(op1) && !(op1 is ConstantOperand))
ctx.InsertBefore().SetInstruction(IR.Instruction.SignExtendedMoveInstruction, eax, op1);
else if (IsUnsigned(op1) && !(op1 is ConstantOperand))
ctx.InsertBefore().SetInstruction(IR.Instruction.ZeroExtendedMoveInstruction, eax, op1);
else
ctx.InsertBefore().SetInstruction(CPUx86.Instruction.MovInstruction, eax, op1);
}
else
{
if (op1.Type.Type == CilElementType.R4)
{
if (op1 is ConstantOperand)
{
Context before = ctx.InsertBefore();
before.SetInstruction(CPUx86.Instruction.MovInstruction, eax, op1);
before.AppendInstruction(CPUx86.Instruction.Cvtss2sdInstruction, eax, eax);
}
else
ctx.InsertBefore().SetInstruction(CPUx86.Instruction.Cvtss2sdInstruction, eax, op1);
}
else
ctx.InsertBefore().SetInstruction(CPUx86.Instruction.MovInstruction, eax, op1);
}
ctx.AppendInstruction(CPUx86.Instruction.MovInstruction, result, eax);
}
示例9: ReplaceIntrinsicCall
/// <summary>
/// Replaces the instrinsic call site
/// </summary>
/// <param name="context">The context.</param>
public void ReplaceIntrinsicCall(Context context)
{
Operand result = context.Result;
Operand operand = context.Operand1;
RegisterOperand eax = new RegisterOperand(new Mosa.Runtime.Metadata.Signatures.SigType(Mosa.Runtime.Metadata.CilElementType.I4), GeneralPurposeRegister.EAX);
RegisterOperand ecx = new RegisterOperand(new Mosa.Runtime.Metadata.Signatures.SigType(Mosa.Runtime.Metadata.CilElementType.I4), GeneralPurposeRegister.ECX);
RegisterOperand reg = new RegisterOperand(new Mosa.Runtime.Metadata.Signatures.SigType(Mosa.Runtime.Metadata.CilElementType.I4), GeneralPurposeRegister.EBX);
context.SetInstruction(CPUx86.Instruction.MovInstruction, eax, operand);
context.AppendInstruction(CPUx86.Instruction.XorInstruction, ecx, ecx);
context.AppendInstruction(CPUx86.Instruction.CpuIdEbxInstruction);
context.AppendInstruction(CPUx86.Instruction.MovInstruction, result, reg);
}
示例10: ReplaceIntrinsicCall
/// <summary>
/// Replaces the instrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
public void ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem)
{
Operand result = context.Result;
SigType u4 = new SigType(CilElementType.U4);
RegisterOperand eax = new RegisterOperand(u4, GeneralPurposeRegister.EAX);
context.SetInstruction(CPUx86.Instruction.PopInstruction, eax);
context.AppendInstruction(CPUx86.Instruction.AddInstruction, eax, new RegisterOperand(u4, GeneralPurposeRegister.ESP));
context.AppendInstruction(CPUx86.Instruction.MovInstruction, eax, new MemoryOperand(u4, GeneralPurposeRegister.EAX, new IntPtr(0)));
context.AppendInstruction(CPUx86.Instruction.MovInstruction, result, eax);
context.AppendInstruction(CPUx86.Instruction.PushInstruction, null, eax);
}
示例11: ReplaceIntrinsicCall
/// <summary>
/// Replaces the instrinsic call site
/// </summary>
/// <param name="context">The context.</param>
public void ReplaceIntrinsicCall(Context context)
{
Operand operand1 = context.Operand1;
Operand operand2 = context.Operand2;
RegisterOperand edx = new RegisterOperand (operand1.Type, GeneralPurposeRegister.EDX);
RegisterOperand eax = new RegisterOperand (operand2.Type, GeneralPurposeRegister.EAX);
context.SetInstruction (CPUx86.Instruction.MovInstruction, edx, operand1);
context.AppendInstruction (CPUx86.Instruction.MovInstruction, eax, operand2);
context.AppendInstruction (CPUx86.Instruction.OutInstruction, null, edx, eax);
}
示例12: ReplaceIntrinsicCall
/// <summary>
/// Replaces the instrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
public void ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem)
{
Operand result = context.Result;
Operand operand1 = context.Operand1;
RegisterOperand edx = new RegisterOperand(operand1.Type, GeneralPurposeRegister.EDX);
RegisterOperand eax = new RegisterOperand(result.Type, GeneralPurposeRegister.EAX);
context.SetInstruction(CPUx86.Instruction.MovInstruction, edx, operand1);
context.AppendInstruction(CPUx86.Instruction.InInstruction, eax, edx);
context.AppendInstruction(CPUx86.Instruction.MovInstruction, result, eax);
}
示例13: ReplaceIntrinsicCall
/// <summary>
/// Replaces the instrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
public void ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem)
{
Operand dest = context.Operand1;
Operand value = context.Operand2;
RegisterOperand edx = new RegisterOperand(dest.Type, GeneralPurposeRegister.EDX);
RegisterOperand eax = new RegisterOperand(value.Type, GeneralPurposeRegister.EAX);
MemoryOperand memory = new MemoryOperand(new SigType(context.InvokeTarget.Signature.Parameters[1].Type), GeneralPurposeRegister.EDX, new IntPtr(0));
context.SetInstruction(CPUx86.Instruction.MovInstruction, edx, dest);
context.AppendInstruction(CPUx86.Instruction.MovInstruction, eax, value);
context.AppendInstruction(CPUx86.Instruction.MovInstruction, memory, eax);
}
示例14: ReplaceIntrinsicCall
/// <summary>
/// Replaces the instrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
public void ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem)
{
SigType u4 = new SigType(Runtime.Metadata.CilElementType.U4);
RegisterOperand ebp = new RegisterOperand(u4, GeneralPurposeRegister.EBP);
RegisterOperand esp = new RegisterOperand(u4, GeneralPurposeRegister.ESP);
RegisterOperand eax = new RegisterOperand(u4, GeneralPurposeRegister.EAX);
RegisterOperand ebx = new RegisterOperand(u4, GeneralPurposeRegister.EBX);
RegisterOperand ecx = new RegisterOperand(u4, GeneralPurposeRegister.ECX);
RegisterOperand edx = new RegisterOperand(u4, GeneralPurposeRegister.EDX);
RegisterOperand esi = new RegisterOperand(u4, GeneralPurposeRegister.ESI);
RegisterOperand edi = new RegisterOperand(u4, GeneralPurposeRegister.EDI);
context.SetInstruction(CPUx86.Instruction.PushInstruction, null, ebp);
context.AppendInstruction(CPUx86.Instruction.MovInstruction, ebp, esp);
context.AppendInstruction(CPUx86.Instruction.PushInstruction, null, ebx);
context.AppendInstruction(CPUx86.Instruction.PushInstruction, null, esi);
context.AppendInstruction(CPUx86.Instruction.PushInstruction, null, edi);
// Load register context
context.AppendInstruction(CPUx86.Instruction.MovInstruction, eax, new MemoryOperand(u4, GeneralPurposeRegister.ESP, new IntPtr(28)));
// Load exception handler
context.AppendInstruction(CPUx86.Instruction.MovInstruction, ecx, new MemoryOperand(u4, GeneralPurposeRegister.ESP, new IntPtr(32)));
// Save EBP
context.AppendInstruction(CPUx86.Instruction.PushInstruction, null, ebp);
// Restore register values
context.AppendInstruction(CPUx86.Instruction.MovInstruction, ebp, new MemoryOperand(u4, GeneralPurposeRegister.EAX, new IntPtr(24)));
context.AppendInstruction(CPUx86.Instruction.MovInstruction, ebx, new MemoryOperand(u4, GeneralPurposeRegister.EAX, new IntPtr(4)));
context.AppendInstruction(CPUx86.Instruction.MovInstruction, esi, new MemoryOperand(u4, GeneralPurposeRegister.EAX, new IntPtr(16)));
context.AppendInstruction(CPUx86.Instruction.MovInstruction, edi, new MemoryOperand(u4, GeneralPurposeRegister.EAX, new IntPtr(20)));
// Align ESP
context.AppendInstruction(CPUx86.Instruction.MovInstruction, edx, esp);
context.AppendInstruction(CPUx86.Instruction.AndInstruction, esp, new ConstantOperand(u4, 0xFFFFFFF0u));
context.AppendInstruction(CPUx86.Instruction.SubInstruction, esp, new ConstantOperand(u4, 0x8u));
// Save original ESP
context.AppendInstruction(CPUx86.Instruction.PushInstruction, null, edx);
// Call catch handler
context.AppendInstruction(CPUx86.Instruction.CallInstruction, ecx);
// Restore registers
context.AppendInstruction(CPUx86.Instruction.PopInstruction, esp);
context.AppendInstruction(CPUx86.Instruction.PopInstruction, ebp);
context.AppendInstruction(CPUx86.Instruction.PopInstruction, esi);
context.AppendInstruction(CPUx86.Instruction.PopInstruction, edi);
context.AppendInstruction(CPUx86.Instruction.PopInstruction, ebx);
context.AppendInstruction(CPUx86.Instruction.LeaveInstruction);
context.AppendInstruction(CPUx86.Instruction.RetInstruction);
}
示例15: ReplaceIntrinsicCall
/// <summary>
/// Replaces the instrinsic call site
/// </summary>
/// <param name="context">The context.</param>
public void ReplaceIntrinsicCall(Context context)
{
if (!(context.Operand1 is ConstantOperand))
throw new InvalidOperationException();
Operand result = context.Result;
ControlRegister control;
switch ((int)(context.Operand1 as ConstantOperand).Value) {
case 0: control = ControlRegister.CR0; break;
case 2: control = ControlRegister.CR2; break;
case 3: control = ControlRegister.CR3; break;
case 4: control = ControlRegister.CR4; break;
default: throw new InvalidOperationException();
}
RegisterOperand imm = new RegisterOperand(new SigType(CilElementType.U4), GeneralPurposeRegister.EAX);
context.SetInstruction(IR.Instruction.MoveInstruction, imm, new RegisterOperand(new SigType(CilElementType.U4), control));
context.AppendInstruction(IR.Instruction.MoveInstruction, result, imm);
}