本文整理汇总了C#中Mosa.Compiler.Framework.Context.AppendInstruction方法的典型用法代码示例。如果您正苦于以下问题:C# Context.AppendInstruction方法的具体用法?C# Context.AppendInstruction怎么用?C# Context.AppendInstruction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mosa.Compiler.Framework.Context
的用法示例。
在下文中一共展示了Context.AppendInstruction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterOperand
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
{
// Retrieve register context
//context.SetInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX), new MemoryOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.ESP, new IntPtr(28)));
// Restore registers (Note: EAX and EDX are NOT restored!)
//context.AppendInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EDX), new MemoryOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX, new IntPtr(28)));
//context.AppendInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EBX), new MemoryOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX, new IntPtr(4)));
//context.AppendInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EDI), new MemoryOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX, new IntPtr(20)));
//context.AppendInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.ESI), new MemoryOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX, new IntPtr(16)));
//context.AppendInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.ESP), new MemoryOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX, new IntPtr(32)));
//context.AppendInstruction(CPUx86.Instruction.MovInstruction, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EBP), new MemoryOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EAX, new IntPtr(24)));
//uint ebp, uint esp, int eip
RegisterOperand edx = new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EDX);
RegisterOperand ebp = new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.EBP);
RegisterOperand esp = new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.ESP);
// Restore registers
context.AppendInstruction(X86.Mov, new RegisterOperand(BuiltInSigType.UInt32, GeneralPurposeRegister.ESP), context.Operand1);
// Jmp to EIP (stored in EDX)
context.AppendInstruction(X86.Jmp, null, edx);
//context.SetOperand(0, edx);
}
示例2: AddEpilogueInstructions
/// <summary>
/// Adds the epilogue instructions.
/// </summary>
/// <param name="context">The context.</param>
private void AddEpilogueInstructions(Context context)
{
Operand ebp = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EBP);
Operand esp = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.ESP);
Operand edx = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EDX);
Operand edi = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EDI);
Operand ecx = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.ECX);
Operand ebx = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EBX);
context.SetInstruction(X86.Nop);
if (SaveRegisters)
{
context.AppendInstruction(X86.Pop, ebx);
context.AppendInstruction(X86.Pop, ecx);
context.AppendInstruction(X86.Pop, edi);
// Save EDX for int32 return values (or do not save EDX for non-int64 return values)
if (!MethodCompiler.Method.Signature.ReturnType.IsUI8)
{
context.AppendInstruction(X86.Pop, edx);
}
}
if (MethodCompiler.StackLayout.StackSize != 0)
{
context.AppendInstruction(X86.Add, esp, esp, Operand.CreateConstantSignedInt(TypeSystem, -MethodCompiler.StackLayout.StackSize));
}
context.AppendInstruction(X86.Pop, ebp);
context.AppendInstruction(X86.Ret);
}
示例3: foreach
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
{
//var result = context.Result;
var op2 = context.Operand1;
var constant = Operand.CreateConstant(BuiltInSigType.IntPtr, parameters.Count * 4);
var eax = Operand.CreateCPURegister(BuiltInSigType.IntPtr, GeneralPurposeRegister.EAX); // FIXME - need access to virtual register allocator
var edx = Operand.CreateCPURegister(BuiltInSigType.IntPtr, GeneralPurposeRegister.EDX); // FIXME - need access to virtual register allocator
var esp = Operand.CreateCPURegister(BuiltInSigType.IntPtr, GeneralPurposeRegister.ESP); // FIXME - need access to virtual register allocator
var ebp = Operand.CreateCPURegister(BuiltInSigType.IntPtr, GeneralPurposeRegister.EBP); // FIXME - need access to virtual register allocator
context.SetInstruction(X86.Sub, esp, constant);
context.AppendInstruction(X86.Mov, edx, esp);
var size = parameters.Count * 4;
foreach (var parameter in parameters)
{
context.AppendInstruction(X86.Mov, Operand.CreateMemoryAddress(BuiltInSigType.IntPtr, edx, new IntPtr(size - 4)), Operand.CreateMemoryAddress(BuiltInSigType.IntPtr, ebp, new IntPtr(size + 8)));
size -= 4;
}
context.AppendInstruction(X86.Mov, eax, op2);
context.AppendInstruction(X86.Call, null, eax);
context.AppendInstruction(X86.Add, esp, constant);
//context.AppendInstruction(X86.Mov,result, Operand.CreateCPURegister(result.Type, GeneralPurposeRegister.EAX));
}
示例4: Div
/// <summary>
/// Visitation function for <see cref="IX86Visitor.Div"/> instructions.
/// </summary>
/// <param name="context">The context.</param>
public void Div(Context context)
{
if (context.Result.IsCPURegister && context.Result2.IsCPURegister && context.Operand1.IsCPURegister)
if (context.Result.Register == GeneralPurposeRegister.EDX &&
context.Result2.Register == GeneralPurposeRegister.EAX &&
context.Operand1.Register == GeneralPurposeRegister.EDX &&
context.Operand2.Register == GeneralPurposeRegister.EAX)
return;
Operand operand1 = context.Operand1;
Operand operand2 = context.Operand2;
Operand operand3 = context.Operand3;
Operand result = context.Result;
Operand result2 = context.Result2;
Operand EAX = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EAX);
Operand EDX = Operand.CreateCPURegister(TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EDX);
context.SetInstruction(X86.Mov, EDX, operand1);
context.AppendInstruction(X86.Mov, EAX, operand2);
if (operand3.IsCPURegister)
{
context.AppendInstruction2(X86.Div, EDX, EAX, EDX, EAX, operand3);
}
else
{
Operand v3 = AllocateVirtualRegister(TypeSystem.BuiltIn.I4);
context.AppendInstruction(X86.Mov, v3, operand3);
context.AppendInstruction2(X86.Div, EDX, EAX, EDX, EAX, v3);
}
context.AppendInstruction(X86.Mov, result2, EAX);
context.AppendInstruction(X86.Mov, result, EDX);
}
示例5:
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
{
Operand result = context.Result;
Operand eax = methodCompiler.CreateVirtualRegister(methodCompiler.TypeSystem.BuiltIn.U4);
context.AppendInstruction(X86.Add, eax, eax, Operand.CreateCPURegister(methodCompiler.TypeSystem.BuiltIn.U4, GeneralPurposeRegister.ESP));
context.AppendInstruction(X86.Mov, eax, Operand.CreateMemoryAddress(methodCompiler.TypeSystem.BuiltIn.U4, eax, 0));
context.AppendInstruction(X86.Mov, result, eax);
}
示例6:
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
{
Operand esp = Operand.CreateCPURegister(BuiltInSigType.Int32, GeneralPurposeRegister.ESP);
context.SetInstruction(X86.Mov, esp, context.Operand1);
context.AppendInstruction(X86.Popad);
context.AppendInstruction(X86.Add, esp, Operand.CreateConstant(BuiltInSigType.Int32, 0x08));
context.AppendInstruction(X86.Sti);
context.AppendInstruction(X86.IRetd);
}
示例7:
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
{
Operand esp = Operand.CreateCPURegister(methodCompiler.TypeSystem.BuiltIn.I4, GeneralPurposeRegister.ESP);
context.SetInstruction(X86.Mov, esp, context.Operand1);
context.AppendInstruction(X86.Popad);
context.AppendInstruction(X86.Add, esp, esp, Operand.CreateConstant(methodCompiler.TypeSystem, 0x08));
context.AppendInstruction(X86.Sti);
context.AppendInstruction(X86.IRetd);
}
示例8: CreateInterruptVectors
/// <summary>
/// Creates the interrupt service routine (ISR) methods.
/// </summary>
private void CreateInterruptVectors()
{
RuntimeType runtimeType = typeSystem.GetType(@"Mosa.Kernel.x86.IDT");
if (runtimeType == null)
return;
RuntimeMethod runtimeMethod = runtimeType.FindMethod(@"ProcessInterrupt");
if (runtimeMethod == null)
return;
Operand interruptMethod = Operand.CreateSymbolFromMethod(runtimeMethod);
Operand esp = Operand.CreateCPURegister(BuiltInSigType.Int32, GeneralPurposeRegister.ESP);
for (int i = 0; i <= 255; i++)
{
InstructionSet instructionSet = new InstructionSet(100);
Context ctx = new Context(instructionSet);
ctx.AppendInstruction(X86.Cli);
if (i <= 7 || i >= 16 | i == 9) // For IRQ 8, 10, 11, 12, 13, 14 the cpu will automatically pushed the error code
ctx.AppendInstruction(X86.Push, null, Operand.CreateConstant(BuiltInSigType.SByte, 0x0));
ctx.AppendInstruction(X86.Push, null, Operand.CreateConstant(BuiltInSigType.SByte, (byte)i));
ctx.AppendInstruction(X86.Pushad);
ctx.AppendInstruction(X86.Call, null, interruptMethod);
ctx.AppendInstruction(X86.Popad);
ctx.AppendInstruction(X86.Add, esp, Operand.CreateConstant(BuiltInSigType.Int32, 0x08));
ctx.AppendInstruction(X86.Sti);
ctx.AppendInstruction(X86.IRetd);
LinkTimeCodeGenerator.Compile(this.compiler, @"InterruptISR" + i.ToString(), instructionSet, typeSystem);
}
}
示例9: RegisterOperand
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
{
SigType I4 = BuiltInSigType.Int32;
RegisterOperand esp = new RegisterOperand(I4, GeneralPurposeRegister.ESP);
context.SetInstruction(X86.Mov, esp, context.Operand1);
context.AppendInstruction(X86.Popad);
context.AppendInstruction(X86.Add, esp, new ConstantOperand(I4, 0x08));
context.AppendInstruction(X86.Sti);
context.AppendInstruction(X86.IRetd);
}
示例10:
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
{
var dest = context.Operand1;
var v0 = Operand.CreateCPURegister(methodCompiler.TypeSystem.BuiltIn.Void, SSE2Register.XMM0);
var zero = Operand.CreateConstant(methodCompiler.TypeSystem, 0);
var offset16 = Operand.CreateConstant(methodCompiler.TypeSystem, 16);
context.SetInstruction(X86.PXor, InstructionSize.Size128, v0, v0, v0);
context.AppendInstruction(X86.MovupsStore, InstructionSize.Size128, dest, zero, v0);
context.AppendInstruction(X86.MovupsStore, InstructionSize.Size128, dest, offset16, v0);
}
示例11: RegisterOperand
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
{
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(X86.Mov, edx, operand1);
context.AppendInstruction(X86.In, eax, edx);
context.AppendInstruction(X86.Mov, result, eax);
}
示例12:
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
{
Operand operand1 = context.Operand1;
Operand operand2 = context.Operand2;
Operand edx = Operand.CreateCPURegister(operand1.Type, GeneralPurposeRegister.EDX);
Operand eax = Operand.CreateCPURegister(operand2.Type, GeneralPurposeRegister.EAX);
context.SetInstruction(X86.Mov, edx, operand1);
context.AppendInstruction(X86.Mov, eax, operand2);
context.AppendInstruction(X86.Out, null, edx, eax);
}
示例13:
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, BaseMethodCompiler methodCompiler)
{
Operand result = context.Result;
Operand operand = context.Operand1;
Operand eax = Operand.CreateCPURegister(methodCompiler.TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EAX);
Operand ecx = Operand.CreateCPURegister(methodCompiler.TypeSystem.BuiltIn.I4, GeneralPurposeRegister.ECX);
Operand reg = Operand.CreateCPURegister(methodCompiler.TypeSystem.BuiltIn.I4, GeneralPurposeRegister.EBX);
context.SetInstruction(X86.Mov, eax, operand);
context.AppendInstruction(X86.Mov, ecx, methodCompiler.ConstantZero);
context.AppendInstruction(X86.CpuId, eax, eax);
context.AppendInstruction(X86.Mov, result, reg);
}
示例14: RegisterOperand
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
{
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(Instruction.MovInstruction, edx, operand1);
context.AppendInstruction(Instruction.MovInstruction, eax, operand2);
context.AppendInstruction(Instruction.OutInstruction, null, edx, eax);
}
示例15:
/// <summary>
/// Replaces the intrinsic call site
/// </summary>
/// <param name="context">The context.</param>
/// <param name="typeSystem">The type system.</param>
void IIntrinsicPlatformMethod.ReplaceIntrinsicCall(Context context, ITypeSystem typeSystem, IList<RuntimeParameter> parameters)
{
Operand result = context.Result;
Operand operand = context.Operand1;
Operand eax = Operand.CreateCPURegister(BuiltInSigType.Int32, GeneralPurposeRegister.EAX);
Operand ecx = Operand.CreateCPURegister(BuiltInSigType.Int32, GeneralPurposeRegister.ECX);
Operand reg = Operand.CreateCPURegister(BuiltInSigType.Int32, GeneralPurposeRegister.EDX);
context.SetInstruction(X86.Mov, eax, operand);
context.AppendInstruction(X86.Xor, ecx, ecx);
context.AppendInstruction(X86.CpuId, eax, eax);
context.AppendInstruction(X86.Mov, result, reg);
}