Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
mterwoord committed Jun 16, 2016
1 parent dd1710d commit 00c205b
Show file tree
Hide file tree
Showing 33 changed files with 65 additions and 112 deletions.
45 changes: 9 additions & 36 deletions Users/Orvid/OrvidTestOS/AsmMouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,68 +25,41 @@ public override void AssembleNew(object aAssembler, object aMethodInfo)
{
XS.Mov(XSRegisters.BL, 0xa8);

new Call
{
DestinationLabel = "send_mouse_cmd"
};
XS.Call("send_mouse_cmd");

new Call
{
DestinationLabel = "mouse_read"
};
XS.Call("mouse_read");

new Noop();

XS.Mov(XSRegisters.BL, 0x20);

new Call
{
DestinationLabel = "send_mouse_cmd"
};
XS.Call("send_mouse_cmd");

new Call
{
DestinationLabel = "mouse_read"
};
XS.Call("mouse_read");

XS.Or(XSRegisters.AL, 3);

XS.Mov(XSRegisters.BL, 0x60);

XS.Push(XSRegisters.EAX);

new Call
{
DestinationLabel = "send_mouse_cmd"
};
XS.Call("send_mouse_cmd");

XS.Pop(XSRegisters.EAX);

new Call
{
DestinationLabel = "mouse_write"
};
XS.Call("mouse_write");

new Noop();

XS.Mov(XSRegisters.BL, 0xd4);

new Call
{
DestinationLabel = "send_mouse_cmd"
};
XS.Call("send_mouse_cmd");

XS.Mov(XSRegisters.AL, 0xf4);

new Call
{
DestinationLabel = "mouse_write"
};
XS.Call("mouse_write");

new Call
{
DestinationLabel = "mouse_read"
};
XS.Call("mouse_read");

#region mouse_read
XS.Label("mouse_read");
Expand Down
6 changes: 3 additions & 3 deletions source/Cosmos.Core.Plugs/Assemblers/UpdateIDT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
};
}

new CPUx86.Jump { DestinationLabel = "__AFTER__ALL__ISR__HANDLER__STUBS__" };
XS.Jump("__AFTER__ALL__ISR__HANDLER__STUBS__");
var xInterruptsWithParam = new int[] { 8, 10, 11, 12, 13, 14 };
for (int j = 0; j < 256; j++)
{
new CPUAll.Label("__ISR_Handler_" + j.ToString("X2"));
new CPUx86.Call { DestinationLabel = "__INTERRUPT_OCCURRED__" };
XS.Call("__INTERRUPT_OCCURRED__");

if (Array.IndexOf(xInterruptsWithParam, j) == -1)
{
Expand Down Expand Up @@ -139,7 +139,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
{
xHandler = GetMethodDef(typeof(INTs).Assembly, typeof(INTs).FullName, "HandleInterrupt_Default", true);
}
new CPUx86.Call { DestinationLabel = CPUAll.LabelName.Get(xHandler) };
XS.Call(CPUAll.LabelName.Get(xHandler));
XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
new FXStore { DestinationReg = CPUx86.RegistersEnum.ESP, DestinationIsIndirect = true };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
var xGetInvocationListMethod = typeof(MulticastDelegate).GetMethod("GetInvocationList");
XS.Comment("push address of delgate to stack");
XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));//addrof this
new CPUx86.Call { DestinationLabel = LabelName.Get(xGetInvocationListMethod) };
XS.Call(LabelName.Get(xGetInvocationListMethod));
XS.Comment("get address from return value -> eax");
XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
;//list
Expand Down Expand Up @@ -115,7 +115,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
new CPUx86.Popad();
XS.Increment(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX));
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), 4);
new CPUx86.Jump { DestinationLabel = ".BEGIN_OF_LOOP" };
XS.Jump(".BEGIN_OF_LOOP");
}
XS.Label(".END_OF_INVOKE_");
XS.Comment("get the return value");
Expand Down Expand Up @@ -172,7 +172,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
// new CPU.Comment("push address of delgate to stack");
// Ldarg.DoExecute(xAssembler, xMethodInfo, 0);
// var xGetInvocationListMethod = typeof(MulticastDelegate).GetMethod("GetInvocationList");
// new CPUx86.Call { DestinationLabel = CPU.MethodInfoLabelGenerator.GenerateLabelName(xGetInvocationListMethod) };
// XS.Call(CPU.MethodInfoLabelGenerator.GenerateLabelName(xGetInvocationListMethod));
// new CPU.Comment("get address from return value -> eax");
// XS.Pop(XSRegisters.EAX);
// ;//list
Expand Down Expand Up @@ -269,7 +269,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
// new CPUx86.Popad();
// XS.INC(XSRegisters.EDX);
// XS.Add(XSRegisters.EAX, 4);
// new CPUx86.Jump { DestinationLabel = ".BEGIN_OF_LOOP" };
// XS.Jump(".BEGIN_OF_LOOP");
// new CPU.Label(".END_OF_INVOKE_");
// new CPU.Comment("get the return value");
// // TEMP!!!
Expand Down
17 changes: 7 additions & 10 deletions source/Cosmos.IL2CPU/AppAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected void MethodBegin(MethodInfo aMethod)
XS.Label(mCurrentMethodLabel + ".StackOverflowCheck_GetAddress");
XS.Pop(OldToNewRegister(RegistersEnum.EAX));
new Mov { DestinationRef = ElementReference.New("DebugStub_CallerEIP"), DestinationIsIndirect = true, SourceReg = RegistersEnum.EAX };
new Call { DestinationLabel = "DebugStub_SendStackOverflowOccurred" };
XS.Call("DebugStub_SendStackOverflowOccurred");
new Halt();
XS.Label(mCurrentMethodLabel + ".StackOverflowCheck_End");

Expand Down Expand Up @@ -424,7 +424,7 @@ protected void MethodEnd(MethodInfo aMethod)
XS.Label(xLabelExc + ".MethodFooterStackCorruptionCheck_Break_on_location");
XS.Pop(OldToNewRegister(RegistersEnum.EAX));
new Mov { DestinationRef = ElementReference.New("DebugStub_CallerEIP"), DestinationIsIndirect = true, SourceReg = RegistersEnum.EAX };
new Call { DestinationLabel = "DebugStub_SendStackCorruptionOccurred" };
XS.Call("DebugStub_SendStackCorruptionOccurred");
new Halt();
}
XS.Label(xLabelExc + "__2");
Expand Down Expand Up @@ -821,10 +821,7 @@ protected void Push(string aLabelName, bool isIndirect = false)

protected void Call(MethodBase aMethod)
{
new Call
{
DestinationLabel = LabelName.Get(aMethod)
};
XS.Call(LabelName.Get(aMethod));
}

protected void Jump(string aLabelName)
Expand All @@ -849,7 +846,7 @@ protected void Call(MethodInfo aMethod, MethodInfo aTargetMethod, string aNextLa
{
XS.Sub(OldToNewRegister(RegistersEnum.ESP), xSize);
}
new Call { DestinationLabel = ILOp.GetMethodLabel(aTargetMethod) };
XS.Call(ILOp.GetMethodLabel(aTargetMethod));
var xMethodInfo = aMethod.MethodBase as SysReflection.MethodInfo;

uint xReturnsize = 0;
Expand Down Expand Up @@ -1393,9 +1390,9 @@ public void EmitEntrypoint(MethodBase aEntrypoint)
XS.Label(CosmosAssembler.EntryPointName);
XS.Push(OldToNewRegister(RegistersEnum.EBP));
XS.Set(OldToNewRegister(RegistersEnum.EBP), OldToNewRegister(RegistersEnum.ESP));
new Call { DestinationLabel = InitVMTCodeLabel };
XS.Call(InitVMTCodeLabel);
Assembler.WriteDebugVideo("Initializing string IDs.");
new Call { DestinationLabel = InitStringIDsLabel };
XS.Call(InitStringIDsLabel);
Assembler.WriteDebugVideo("Done initializing string IDs");
// we now need to do "newobj" on the entry point, and after that, call .Start on it
var xCurLabel = CosmosAssembler.EntryPointName + ".CreateEntrypoint";
Expand Down Expand Up @@ -1513,7 +1510,7 @@ protected void BeforeOp(MethodInfo aMethod, ILOpCode aOpCode, bool emitInt3NotNo
XS.Label(xLabel + ".StackCorruptionCheck_GetAddress");
XS.Pop(OldToNewRegister(RegistersEnum.EAX));
new Mov { DestinationRef = ElementReference.New("DebugStub_CallerEIP"), DestinationIsIndirect = true, SourceReg = RegistersEnum.EAX };
new Call { DestinationLabel = "DebugStub_SendStackCorruptionOccurred" };
XS.Call("DebugStub_SendStackCorruptionOccurred");
new Halt();
new Assembler.Label(xLabel + ".StackCorruptionCheck_End");

Expand Down
10 changes: 2 additions & 8 deletions source/Cosmos.IL2CPU/CosmosAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,12 @@ public void Initialize()
if (mComPort > 0)
{
WriteDebugVideo("Initializing DebugStub.");
new Call
{
DestinationLabel = "DebugStub_Init"
};
XS.Call("DebugStub_Init");
}

// Jump to Kernel entry point
WriteDebugVideo("Jumping to kernel.");
new Call
{
DestinationLabel = EntryPointName
};
XS.Call(EntryPointName);

new Comment(this, "Kernel done - loop till next IRQ");
XS.Label(".loop");
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/IL/Box.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
uint xSize = Align(SizeOfType(xType.Value), 4);
string xTypeID = GetTypeIDLabel(xType.Value);
new CPUx86.Push { DestinationValue = (ObjectImpl.FieldDataOffset + xSize) };
new CPUx86.Call { DestinationLabel = LabelName.Get(GCImplementationRefs.AllocNewObjectRef) };
XS.Call(LabelName.Get(GCImplementationRefs.AllocNewObjectRef));
XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
XS.Set(XSRegisters.ESI, XSRegisters.EAX, sourceIsIndirect: true);
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EBX, SourceRef = ElementReference.New(xTypeID), SourceIsIndirect = true };
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/IL/Brfalse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
// XS.Jump(ConditionalTestEnum.NotZero, LabelFalse);
// XS.Xor(XSRegisters.EBX, XSRegisters.CPUx86.Registers.EBX);
// XS.Jump(ConditionalTestEnum.NotZero, LabelFalse);
// new CPUx86.Jump { DestinationLabel = TargetLabel };
// XS.Jump(TargetLabel);
// XS.Label(LabelFalse);
// } else
// {
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/IL/Call.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static void DoExecute(Cosmos.Assembler.Assembler Assembler, MethodInfo aC
{
XS.Sub(XSRegisters.OldToNewRegister(CPU.RegistersEnum.ESP), (uint)xExtraStackSize);
}
new CPUx86.Call { DestinationLabel = xNormalAddress };
XS.Call(xNormalAddress);

uint xReturnSize = 0;
if (xMethodInfo != null)
Expand Down
4 changes: 2 additions & 2 deletions source/Cosmos.IL2CPU/IL/Callvirt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static void DoExecute(Cosmos.Assembler.Assembler Assembler, MethodInfo aM
{
XS.Sub(XSRegisters.OldToNewRegister(CPU.RegistersEnum.ESP), (uint)xExtraStackSize);
}
new CPU.Call { DestinationLabel = xNormalAddress };
XS.Call(xNormalAddress);
}
else
{
Expand All @@ -108,7 +108,7 @@ public static void DoExecute(Cosmos.Assembler.Assembler Assembler, MethodInfo aM
new CPU.Push { DestinationReg = CPU.RegistersEnum.EAX, DestinationIsIndirect = true };
}
new CPU.Push { DestinationValue = aTargetMethodUID };
new CPU.Call { DestinationLabel = LabelName.Get(VTablesImplRefs.GetMethodAddressForTypeRef) };
XS.Call(LabelName.Get(VTablesImplRefs.GetMethodAddressForTypeRef));
if (xExtraStackSize > 0)
{
xThisOffset -= xExtraStackSize;
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/IL/Ceq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
XS.Add(XSRegisters.OldToNewRegister(RegistersEnum.ESP), 8);
XS.Xor(XSRegisters.OldToNewRegister(RegistersEnum.EAX), XSRegisters.OldToNewRegister(RegistersEnum.EAX));
XS.Push(XSRegisters.OldToNewRegister(RegistersEnum.EAX));
new CPUx86.Jump { DestinationLabel = xNextLabel };
XS.Jump(xNextLabel);
}

}
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/IL/Cgt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
XS.Jump(ConditionalTestEnum.GreaterThan, LabelTrue);
XS.Label(LabelFalse);
new CPUx86.Push { DestinationValue = 0 };
new CPUx86.Jump { DestinationLabel = xNextLabel };
XS.Jump(xNextLabel);
XS.Label(LabelTrue );
new CPUx86.Push { DestinationValue = 1 };*/
}
Expand Down
8 changes: 4 additions & 4 deletions source/Cosmos.IL2CPU/IL/Cgt_Un.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
//
// XS.Jump(ConditionalTestEnum.Above, LabelTrue);
// new CPUx86.Push { DestinationValue = 0 };
// new CPUx86.Jump { DestinationLabel = NextInstructionLabel };
// XS.Jump(NextInstructionLabel);
//
// XS.Label(LabelTrue);
// new CPUx86.Push{DestinationValue=1};
Expand All @@ -179,15 +179,15 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
// XS.Pop(XSRegisters.EAX);
// XS.Compare(XSRegisters.EAX, XSRegisters.ESP, sourceIsIndirect: true);
// XS.Jump(ConditionalTestEnum.Below, LabelTrue);
// new CPUx86.Jump { DestinationLabel = LabelFalse };
// XS.Jump(LabelFalse);
// XS.Label(LabelTrue);
// XS.Add(XSRegisters.ESP, 4);
// new CPUx86.Push { DestinationValue = 1 };
// new CPUx86.Jump { DestinationLabel = NextInstructionLabel };
// XS.Jump(NextInstructionLabel);
// XS.Label(LabelFalse);
// XS.Add(XSRegisters.ESP, 4);
// new CPUx86.Push { DestinationValue = 0 };
// new CPUx86.Jump { DestinationLabel = NextInstructionLabel };
// XS.Jump(NextInstructionLabel);
// }
// }
// }
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/IL/Div.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )

//TODO: implement proper derivation correction and overflow detection

new CPUx86.Jump { DestinationLabel = LabelEnd };
XS.Jump(LabelEnd);

XS.Label(LabelNoLoop);
//save high dividend
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/IL/Div_Un.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )

//TODO: implement proper derivation correction and overflow detection

new CPUx86.Jump { DestinationLabel = LabelEnd };
XS.Jump(LabelEnd);

XS.Label(LabelNoLoop);

Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/IL/Ldsfld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
var xCctor = (xField.DeclaringType.GetConstructors(BindingFlags.Static | BindingFlags.NonPublic) ?? new ConstructorInfo[0]).SingleOrDefault();
if (xCctor != null)
{
new CPUx86.Call { DestinationLabel = LabelName.Get(xCctor) };
XS.Call(LabelName.Get(xCctor));
ILOp.EmitExceptionLogic(Assembler, aMethod, aOpCode, true, null, ".AfterCCTorExceptionCheck");
XS.Label(".AfterCCTorExceptionCheck");
}
Expand Down
5 changes: 1 addition & 4 deletions source/Cosmos.IL2CPU/IL/Ldsflda.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ public static void DoExecute(Cosmos.Assembler.Assembler assembler, MethodInfo aM
var xCctor = (declaringType.GetConstructors(BindingFlags.Static | BindingFlags.NonPublic) ?? new ConstructorInfo[0]).SingleOrDefault();
if (xCctor != null)
{
new CPUx86.Call
{
DestinationLabel = LabelName.Get(xCctor)
};
XS.Call(LabelName.Get(xCctor));
if (aCurrentOpCode != null)
{
ILOp.EmitExceptionLogic(assembler, aMethod, aCurrentOpCode, true, null, ".AfterCCTorExceptionCheck");
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/IL/Leave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
// TargetLabel = GetInstructionLabel(aReader.OperandValueBranchPosition);
// }
// public override void DoAssemble() {
// new CPU.Jump { DestinationLabel = TargetLabel };
// XS.Jump(TargetLabel);
// }
// }
// }
Expand Down
5 changes: 1 addition & 4 deletions source/Cosmos.IL2CPU/IL/Mul.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ public static void DoExecute(uint xStackContentSize, bool xStackContentIsFloat,
// add LEFT_LOW * RIGHT_HIGH + RIGHT_LOW + LEFT_HIGH to high dword of last result
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ECX));

new CPUx86.Jump
{
DestinationLabel = MoveReturnValue
};
XS.Jump(MoveReturnValue);

XS.Label(Simple32Multiply);
//mov RIGHT_LOW to eax
Expand Down
4 changes: 2 additions & 2 deletions source/Cosmos.IL2CPU/IL/Newarr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
new CPUx86.Push { DestinationValue = (ObjectImpl.FieldDataOffset + 4) };
new Add(Assembler).Execute(aMethod, aOpCode);
// the total array size is now on the stack.
new CPUx86.Call { DestinationLabel = LabelName.Get(GCImplementationRefs.AllocNewObjectRef) };
XS.Call(LabelName.Get(GCImplementationRefs.AllocNewObjectRef));
new CPUx86.Push { DestinationReg = CPUx86.RegistersEnum.ESP, DestinationIsIndirect = true };
new CPUx86.Push { DestinationReg = CPUx86.RegistersEnum.ESP, DestinationIsIndirect = true };
// it's on the stack 3 times now, once from the return value, twice from the pushes;
Expand All @@ -57,7 +57,7 @@ public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, DestinationIsIndirect = true, SourceReg = CPUx86.RegistersEnum.ESI, Size = 32 };
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), 4);
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, DestinationIsIndirect = true, SourceValue = (uint)xSize, Size = 32 };
new CPUx86.Call { DestinationLabel = xCtorName };
XS.Call(xCtorName);
}
}
}
Loading

0 comments on commit 00c205b

Please sign in to comment.