Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
mterwoord committed Jun 15, 2016
1 parent 1dc41f1 commit ff5662e
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 75 deletions.
48 changes: 8 additions & 40 deletions Users/Orvid/OrvidTestOS/AsmMouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,7 @@ public override void AssembleNew(object aAssembler, object aMethodInfo)
SourceValue = 1
};

new ConditionalJump
{
Condition = ConditionalTestEnum.NotZero,
DestinationLabel = "mouse_read_ready"
};
XS.Jump(ConditionalTestEnum.NotZero, "mouse_read_ready");

new Loop
{
Expand Down Expand Up @@ -269,11 +265,7 @@ public override void AssembleNew(object aAssembler, object aMethodInfo)
SourceValue = 32
};

new ConditionalJump
{
Condition = ConditionalTestEnum.Zero,
DestinationLabel = "mouse_write_ok1"
};
XS.Jump(ConditionalTestEnum.Zero, "mouse_write_ok1");

new Loop
{
Expand Down Expand Up @@ -320,11 +312,7 @@ public override void AssembleNew(object aAssembler, object aMethodInfo)
SourceValue = 2
};

new ConditionalJump
{
Condition = ConditionalTestEnum.Zero,
DestinationLabel = "mouse_write_ok"
};
XS.Jump(ConditionalTestEnum.Zero, "mouse_write_ok");

new Loop
{
Expand Down Expand Up @@ -377,11 +365,7 @@ public override void AssembleNew(object aAssembler, object aMethodInfo)
SourceValue = 2
};

new ConditionalJump
{
Condition = ConditionalTestEnum.Zero,
DestinationLabel = "mouse_write_ok3"
};
XS.Jump(ConditionalTestEnum.Zero, "mouse_write_ok3");

new Loop
{
Expand Down Expand Up @@ -430,11 +414,7 @@ public override void AssembleNew(object aAssembler, object aMethodInfo)
SourceValue = 1
};

new ConditionalJump
{
Condition = ConditionalTestEnum.NotZero,
DestinationLabel = "mouse_write_ok4"
};
XS.Jump(ConditionalTestEnum.NotZero, "mouse_write_ok4");

new Loop
{
Expand All @@ -446,11 +426,7 @@ public override void AssembleNew(object aAssembler, object aMethodInfo)
DestinationReg = RegistersEnum.AH
};

new ConditionalJump
{
Condition = ConditionalTestEnum.NotZero,
DestinationLabel = "mouse_write_loop4"
};
XS.Jump(ConditionalTestEnum.NotZero, "mouse_write_loop4");
}

XS.Label("mouse_write_ok4");
Expand Down Expand Up @@ -502,11 +478,7 @@ public override void AssembleNew(object aAssembler, object aMethodInfo)
DestinationReg = RegistersEnum.AL,
SourceValue = 2
};
new ConditionalJump
{
Condition = ConditionalTestEnum.Zero,
DestinationLabel = "mouse_cmd_send"
};
XS.Jump(ConditionalTestEnum.Zero, "mouse_cmd_send");
new Loop
{
DestinationLabel = "mouse_cmd_wait"
Expand Down Expand Up @@ -552,11 +524,7 @@ public override void AssembleNew(object aAssembler, object aMethodInfo)
DestinationReg = RegistersEnum.AL,
SourceValue = 0x02
};
new ConditionalJump
{
Condition = ConditionalTestEnum.Zero,
DestinationLabel = "mouse_cmd_ok"
};
XS.Jump(ConditionalTestEnum.Zero, "mouse_cmd_ok");
new Loop
{
DestinationLabel = "mouse_cmd_accept"
Expand Down
8 changes: 4 additions & 4 deletions source/Cosmos.IL2CPU/AppAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected void MethodBegin(MethodInfo aMethod)
// if StackCorruption detection is active, we're also going to emit a stack overflow detection
XS.Set(OldToNewRegister(RegistersEnum.EAX), "Before_Kernel_Stack");
XS.Compare(OldToNewRegister(RegistersEnum.EAX), OldToNewRegister(RegistersEnum.ESP));
new ConditionalJump { Condition = ConditionalTestEnum.LessThan, DestinationLabel = mCurrentMethodLabel + ".StackOverflowCheck_End" };
XS.Jump(ConditionalTestEnum.LessThan, mCurrentMethodLabel + ".StackOverflowCheck_End");
new ClearInterruptFlag();
// don't remove the call. It seems pointless, but we need it to retrieve the EIP value
new Call { DestinationLabel = mCurrentMethodLabel + ".StackOverflowCheck_GetAddress" };
Expand All @@ -185,7 +185,7 @@ protected void MethodBegin(MethodInfo aMethod)
var xAsmMember = new DataMember(xName, (byte)0);
Assembler.DataMembers.Add(xAsmMember);
XS.Compare(xName, 1, destinationIsIndirect: true, size: RegisterSize.Byte8);
new ConditionalJump { Condition = ConditionalTestEnum.Equal, DestinationLabel = ".BeforeQuickReturn" };
XS.Jump(ConditionalTestEnum.Equal, ".BeforeQuickReturn");
XS.Set(xName, 1, destinationIsIndirect: true, size: RegisterSize.Byte8);
XS.Jump(".AfterCCTorAlreadyCalledCheck");
XS.Label(".BeforeQuickReturn");
Expand Down Expand Up @@ -423,7 +423,7 @@ protected void MethodEnd(MethodInfo aMethod)
XS.Set(OldToNewRegister(RegistersEnum.EAX), OldToNewRegister(RegistersEnum.ESP));
XS.Set(OldToNewRegister(RegistersEnum.EBX), OldToNewRegister(RegistersEnum.EBP));
XS.Compare(OldToNewRegister(RegistersEnum.EAX), OldToNewRegister(RegistersEnum.EBX));
new ConditionalJump { Condition = ConditionalTestEnum.Equal, DestinationLabel = xLabelExc + "__2" };
XS.Jump(ConditionalTestEnum.Equal, xLabelExc + "__2");
new ClearInterruptFlag();
// don't remove the call. It seems pointless, but we need it to retrieve the EIP value
new Call { DestinationLabel = xLabelExc + ".MethodFooterStackCorruptionCheck_Break_on_location" };
Expand Down Expand Up @@ -1515,7 +1515,7 @@ protected void BeforeOp(MethodInfo aMethod, ILOpCode aOpCode, bool emitInt3NotNo
XS.Add(OldToNewRegister(RegistersEnum.EAX), xStackDifference.Value);
}
XS.Compare(OldToNewRegister(RegistersEnum.EAX), OldToNewRegister(RegistersEnum.EBX));
new ConditionalJump { Condition = ConditionalTestEnum.Equal, DestinationLabel = xLabel + ".StackCorruptionCheck_End" };
XS.Jump(ConditionalTestEnum.Equal, xLabel + ".StackCorruptionCheck_End");
new ClearInterruptFlag();
// don't remove the call. It seems pointless, but we need it to retrieve the EIP value
new Call { DestinationLabel = xLabel + ".StackCorruptionCheck_GetAddress" };
Expand Down
20 changes: 10 additions & 10 deletions source/Cosmos.IL2CPU/IL/Branch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,29 +140,29 @@ public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
break;
case ConditionalTestEnum.GreaterThanOrEqualTo:
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.EDX), XSRegisters.OldToNewRegister(RegistersEnum.EBX));
new ConditionalJump {Condition = ConditionalTestEnum.LessThan, DestinationLabel = xNoJump};
XS.Jump(ConditionalTestEnum.LessThan, xNoJump);
new ConditionalJump {Condition = ConditionalTestEnum.GreaterThan, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode)};
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.ECX), XSRegisters.OldToNewRegister(RegistersEnum.EAX));
new ConditionalJump {Condition = ConditionalTestEnum.Below, DestinationLabel = xNoJump};
XS.Jump(ConditionalTestEnum.Below, xNoJump);
break;
case ConditionalTestEnum.GreaterThan:
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.EDX), XSRegisters.OldToNewRegister(RegistersEnum.EBX));
new ConditionalJump {Condition = ConditionalTestEnum.LessThan, DestinationLabel = xNoJump};
XS.Jump(ConditionalTestEnum.LessThan, xNoJump);
new ConditionalJump {Condition = ConditionalTestEnum.GreaterThan, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode)};
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.ECX), XSRegisters.OldToNewRegister(RegistersEnum.EAX));
new ConditionalJump {Condition = ConditionalTestEnum.BelowOrEqual, DestinationLabel = xNoJump};
XS.Jump(ConditionalTestEnum.BelowOrEqual, xNoJump);
break;
case ConditionalTestEnum.LessThanOrEqualTo:
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.EDX), XSRegisters.OldToNewRegister(RegistersEnum.EBX));
new ConditionalJump {Condition = ConditionalTestEnum.LessThan, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode)};
new ConditionalJump {Condition = ConditionalTestEnum.GreaterThan, DestinationLabel = xNoJump};
XS.Jump(ConditionalTestEnum.GreaterThan, xNoJump);
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.ECX), XSRegisters.OldToNewRegister(RegistersEnum.EAX));
new ConditionalJump {Condition = ConditionalTestEnum.BelowOrEqual, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode)};
break;
case ConditionalTestEnum.LessThan:
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.EDX), XSRegisters.OldToNewRegister(RegistersEnum.EBX));
new ConditionalJump {Condition = ConditionalTestEnum.LessThan, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode)};
new ConditionalJump {Condition = ConditionalTestEnum.GreaterThan, DestinationLabel = xNoJump};
XS.Jump(ConditionalTestEnum.GreaterThan, xNoJump);
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.ECX), XSRegisters.OldToNewRegister(RegistersEnum.EAX));
new ConditionalJump {Condition = ConditionalTestEnum.Below, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode)};
break;
Expand All @@ -171,25 +171,25 @@ public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.EDX), XSRegisters.OldToNewRegister(RegistersEnum.EBX));
new ConditionalJump {Condition = ConditionalTestEnum.Above, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode)};
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.ECX), XSRegisters.OldToNewRegister(RegistersEnum.EAX));
new ConditionalJump {Condition = ConditionalTestEnum.Below, DestinationLabel = xNoJump};
XS.Jump(ConditionalTestEnum.Below, xNoJump);
break;
case ConditionalTestEnum.Above:
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.EDX), XSRegisters.OldToNewRegister(RegistersEnum.EBX));
new ConditionalJump {Condition = ConditionalTestEnum.Above, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode)};
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.ECX), XSRegisters.OldToNewRegister(RegistersEnum.EAX));
new ConditionalJump {Condition = ConditionalTestEnum.BelowOrEqual, DestinationLabel = xNoJump};
XS.Jump(ConditionalTestEnum.BelowOrEqual, xNoJump);
break;
case ConditionalTestEnum.BelowOrEqual:
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.EDX), XSRegisters.OldToNewRegister(RegistersEnum.EBX));
new ConditionalJump {Condition = ConditionalTestEnum.Above, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode)};
new ConditionalJump {Condition = ConditionalTestEnum.Below, DestinationLabel = xNoJump};
XS.Jump(ConditionalTestEnum.Below, xNoJump);
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.ECX), XSRegisters.OldToNewRegister(RegistersEnum.EAX));
new ConditionalJump {Condition = ConditionalTestEnum.Above, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode)};
break;
case ConditionalTestEnum.Below:
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.EDX), XSRegisters.OldToNewRegister(RegistersEnum.EBX));
new ConditionalJump {Condition = ConditionalTestEnum.Above, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode)};
new ConditionalJump {Condition = ConditionalTestEnum.Below, DestinationLabel = xNoJump};
XS.Jump(ConditionalTestEnum.Below, xNoJump);
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.ECX), XSRegisters.OldToNewRegister(RegistersEnum.EAX));
new ConditionalJump {Condition = ConditionalTestEnum.AboveOrEqual, DestinationLabel = AppAssembler.TmpBranchLabel(aMethod, aOpCode)};
break;
Expand Down
6 changes: 3 additions & 3 deletions source/Cosmos.IL2CPU/IL/Ceq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
{
XS.Pop(XSRegisters.OldToNewRegister(RegistersEnum.EAX));
new Compare { DestinationReg = RegistersEnum.EAX, SourceReg = RegistersEnum.ESP, SourceIsIndirect = true };
new ConditionalJump { Condition = ConditionalTestEnum.Equal, DestinationLabel = Label.LastFullLabel + ".True" };
XS.Jump(ConditionalTestEnum.Equal, Label.LastFullLabel + ".True");
XS.Jump(Label.LastFullLabel + ".False");
XS.Label(".True");
XS.Add(XSRegisters.OldToNewRegister(RegistersEnum.ESP), 4);
Expand Down Expand Up @@ -85,9 +85,9 @@ public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
XS.Pop(XSRegisters.OldToNewRegister(RegistersEnum.EAX));
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.EAX), XSRegisters.OldToNewRegister(RegistersEnum.ESP), sourceDisplacement: 4);
XS.Pop(XSRegisters.OldToNewRegister(RegistersEnum.EAX));
new ConditionalJump { Condition = ConditionalTestEnum.NotEqual, DestinationLabel = Label.LastFullLabel + ".False" };
XS.Jump(ConditionalTestEnum.NotEqual, Label.LastFullLabel + ".False");
XS.Xor(XSRegisters.OldToNewRegister(RegistersEnum.EAX), XSRegisters.OldToNewRegister(RegistersEnum.ESP), sourceDisplacement: 4);
new ConditionalJump { Condition = ConditionalTestEnum.NotZero, DestinationLabel = Label.LastFullLabel + ".False" };
XS.Jump(ConditionalTestEnum.NotZero, Label.LastFullLabel + ".False");

//they are equal, eax == 0
XS.Add(XSRegisters.OldToNewRegister(RegistersEnum.ESP), 8);
Expand Down
6 changes: 3 additions & 3 deletions source/Cosmos.IL2CPU/IL/Cgt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
XS.Pop(XSRegisters.OldToNewRegister(RegistersEnum.ECX));
//value1: ECX:EBX
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.ECX), XSRegisters.OldToNewRegister(RegistersEnum.EDX));
new ConditionalJump { Condition = ConditionalTestEnum.GreaterThan, DestinationLabel = LabelTrue };
new ConditionalJump { Condition = ConditionalTestEnum.LessThan, DestinationLabel = LabelFalse };
XS.Jump(ConditionalTestEnum.GreaterThan, LabelTrue);
XS.Jump(ConditionalTestEnum.LessThan, LabelFalse);
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.EBX), XSRegisters.OldToNewRegister(RegistersEnum.EAX));
XS.Label(LabelTrue);
new ConditionalMove { Condition = ConditionalTestEnum.GreaterThan, DestinationReg = RegistersEnum.EDI, SourceReg = RegistersEnum.ESI };
Expand Down Expand Up @@ -92,7 +92,7 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
else{
XS.Pop(XSRegisters.OldToNewRegister(RegistersEnum.EAX));
new Compare { DestinationReg = RegistersEnum.EAX, SourceReg = RegistersEnum.ESP, SourceIsIndirect = true };
new ConditionalJump { Condition = ConditionalTestEnum.LessThan, DestinationLabel = LabelTrue };
XS.Jump(ConditionalTestEnum.LessThan, LabelTrue);
XS.Jump(LabelFalse);
XS.Label(LabelTrue );
XS.Add(XSRegisters.OldToNewRegister(RegistersEnum.ESP), 4);
Expand Down
6 changes: 3 additions & 3 deletions source/Cosmos.IL2CPU/IL/Cgt_Un.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
//value1: ECX:EBX

XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.ECX), XSRegisters.OldToNewRegister(RegistersEnum.EDX));
new ConditionalJump { Condition = ConditionalTestEnum.Above, DestinationLabel = LabelTrue };
new ConditionalJump { Condition = ConditionalTestEnum.Below, DestinationLabel = LabelFalse };
XS.Jump(ConditionalTestEnum.Above, LabelTrue);
XS.Jump(ConditionalTestEnum.Below, LabelFalse);
XS.Compare(XSRegisters.OldToNewRegister(RegistersEnum.EBX), XSRegisters.OldToNewRegister(RegistersEnum.EAX));
XS.Label(LabelTrue);
new ConditionalMove { Condition = ConditionalTestEnum.Above, DestinationReg = RegistersEnum.EDI, SourceReg = RegistersEnum.ESI };
Expand Down Expand Up @@ -95,7 +95,7 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
XS.Pop(XSRegisters.OldToNewRegister(RegistersEnum.EAX));
new Compare { DestinationReg = RegistersEnum.EAX, SourceReg = RegistersEnum.ESP, SourceIsIndirect = true };

new ConditionalJump { Condition = ConditionalTestEnum.Below, DestinationLabel = LabelTrue };
XS.Jump(ConditionalTestEnum.Below, LabelTrue);
XS.Jump(LabelFalse);
XS.Label(LabelTrue );
XS.Add(XSRegisters.OldToNewRegister(RegistersEnum.ESP), 4);
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/IL/Clt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
XS.Pop(XSRegisters.OldToNewRegister(RegistersEnum.EAX));
XS.Push(XSRegisters.OldToNewRegister(RegistersEnum.ECX));
new Compare { DestinationReg = RegistersEnum.EAX, SourceReg = RegistersEnum.ESP, SourceIsIndirect = true };
new ConditionalJump { Condition = ConditionalTestEnum.LessThan, DestinationLabel = LabelTrue };
XS.Jump(ConditionalTestEnum.LessThan, LabelTrue);
XS.Jump(LabelFalse);
XS.Label(LabelTrue );
XS.Add(XSRegisters.OldToNewRegister(RegistersEnum.ESP), 4);
Expand Down
Loading

0 comments on commit ff5662e

Please sign in to comment.