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 456772f commit f5e3ea6
Show file tree
Hide file tree
Showing 28 changed files with 129 additions and 143 deletions.
1 change: 0 additions & 1 deletion Users/Matthijs/DebugCompiler/MyEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public void Test(Type kernelToRun)
xEngine.OutputHandler = new TestOutputHandler();

Assert.IsTrue(xEngine.Execute());

}

private class TestOutputHandler : OutputHandlerFullTextBase
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.Core.Plugs/Assemblers/UpdateIDT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
new CPUx86.Return();
new CPUAll.Label("__AFTER__ALL__ISR__HANDLER__STUBS__");
new CPUx86.Noop();
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 8 };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 8);
XS.Compare(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), 0);
new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.Zero, DestinationLabel = ".__AFTER_ENABLE_INTERRUPTS" };

Expand Down
4 changes: 2 additions & 2 deletions source/Cosmos.Core.Plugs/CPUImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public static uint GetEndOfKernel() {
public class ZeroFillAsm : AssemblerMethod {
public override void AssembleNew(CPUAll.Assembler aAssembler, object aMethodInfo) {
new CPUx86.ClrDirFlag();
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EDI, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 0xC }; //address
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.ECX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 0x8 }; //length
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDI), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 0xC); //address
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ECX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 0x8); //length
// set EAX to value of fill (zero)
XS.Xor(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
XS.ShiftRight(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ECX), 1);
Expand Down
14 changes: 7 additions & 7 deletions source/Cosmos.Core.Plugs/IOPortImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ private class Write16Assembler : AssemblerMethod
{
public override void AssembleNew(Assembler.Assembler aAssembler, object aMethodInfo)
{
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EDX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 0x0C };
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 0x08 };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 0x0C);
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 0x08);
XS.WriteToPortDX(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.AX));
}
}
Expand All @@ -49,8 +49,8 @@ private class Write32Assembler : AssemblerMethod
{
public override void AssembleNew(Assembler.Assembler aAssembler, object aMethodInfo)
{
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EDX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 0x0C };
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 0x08 };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 0x0C);
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 0x08);
XS.WriteToPortDX(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
}
}
Expand All @@ -63,7 +63,7 @@ private class Read8Assembler : AssemblerMethod
{
public override void AssembleNew(Assembler.Assembler aAssembler, object aMethodInfo)
{
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EDX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 0x08 };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 0x08);
//TODO: Do we need to clear rest of EAX first?
// MTW: technically not, as in other places, it _should_ be working with AL too..
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), 0);
Expand All @@ -80,7 +80,7 @@ private class Read16Assembler : AssemblerMethod
{
public override void AssembleNew(Assembler.Assembler aAssembler, object aMethodInfo)
{
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EDX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 0x08 };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 0x08);
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), 0);
XS.ReadFromPortDX(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.AX));
XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
Expand All @@ -95,7 +95,7 @@ private class Read32Assembler : AssemblerMethod
{
public override void AssembleNew(Assembler.Assembler aAssembler, object aMethodInfo)
{
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EDX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 0x08 };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 0x08);
XS.ReadFromPortDX(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
}
Expand Down
16 changes: 8 additions & 8 deletions source/Cosmos.Core.Plugs/System/Assemblers/Array_InternalCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,37 @@ public class Array_InternalCopy : AssemblerMethod
*/
public override void AssembleNew(Assembler.Assembler aAssembler, object aMethodInfo)
{
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = SourceArrayDisplacement };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: SourceArrayDisplacement);
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, SourceReg = CPUx86.RegistersEnum.EAX, SourceIsIndirect = true }; // dereference memory handle to pointer
XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
new CPUx86.Add { DestinationReg = CPUx86.RegistersEnum.ESP, DestinationIsIndirect = true, SourceValue = 12, Size = 32 }; // pointer is at the element size
XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, SourceReg = CPUx86.RegistersEnum.EAX, SourceIsIndirect = true }; // element size
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EBX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = SourceIndexDisplacement };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: SourceIndexDisplacement);
XS.Multiply(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBX));
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), 16);
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.ESI, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = SourceArrayDisplacement };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESI), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: SourceArrayDisplacement);
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.ESI, SourceReg = CPUx86.RegistersEnum.ESI, SourceIsIndirect = true }; // dereference memory handle to pointer
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESI), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX)); // source ptr
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EDX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = DestinationArrayDisplacement };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: DestinationArrayDisplacement);
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EDX, SourceReg = CPUx86.RegistersEnum.EDX, SourceIsIndirect = true }; // dereference memory handle to pointer
XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX));
new CPUx86.Add { DestinationReg = CPUx86.RegistersEnum.ESP, DestinationIsIndirect = true, SourceValue = 12, Size = 32 }; // pointer is at element size
XS.Pop(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, SourceReg = CPUx86.RegistersEnum.EAX, SourceIsIndirect = true }; // dereference handle to pointer
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.ECX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = DestinationIndexDisplacement };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ECX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: DestinationIndexDisplacement);
XS.Multiply(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ECX));
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), 16);
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EDI, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = DestinationArrayDisplacement };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDI), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: DestinationArrayDisplacement);
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EDI, SourceReg = CPUx86.RegistersEnum.EDI, SourceIsIndirect = true }; // dereference handle to pointer
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDI), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));

// calculate byte count to copy
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = DestinationArrayDisplacement };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: DestinationArrayDisplacement);
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, SourceReg = CPUx86.RegistersEnum.EAX, SourceIsIndirect = true }; // dereference memory handle to pointer
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), 12);
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, SourceReg = CPUx86.RegistersEnum.EAX, SourceIsIndirect = true };
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EDX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = LengthDisplacement };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: LengthDisplacement);
XS.Multiply(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX));
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ECX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
new CPUx86.Movs { Size = 8, Prefixes = CPUx86.InstructionPrefixes.Repeat };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Cosmos.Assembler.x86;
using Cosmos.IL2CPU.Plugs;
using XSharp.Compiler;

namespace Cosmos.Core.Plugs.System.Assemblers
{
Expand All @@ -8,9 +9,9 @@ public class Array_get_Length : AssemblerMethod
public override void AssembleNew(Assembler.Assembler aAssembler, object aMethodInfo)
{
// $this ebp+8
new Mov { DestinationReg = RegistersEnum.EAX, SourceReg = RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 8 };
XS.Set(XSRegisters.OldToNewRegister(RegistersEnum.EAX), XSRegisters.OldToNewRegister(RegistersEnum.EBP), sourceDisplacement: 8);
new Mov { DestinationReg = RegistersEnum.EAX, SourceReg = RegistersEnum.EAX, SourceIsIndirect = true };
new Push { DestinationIsIndirect = true, DestinationReg = RegistersEnum.EAX, DestinationDisplacement = 8 };
}
}
}
}
10 changes: 5 additions & 5 deletions source/Cosmos.Core.Plugs/System/Assemblers/Buffer_BlockCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ public class Buffer_BlockCopy : AssemblerMethod
*/
public override void AssembleNew(Assembler.Assembler aAssembler, object aMethodInfo)
{
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.ESI, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 24 };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESI), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 24);
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESI), 16);
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 20 };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 20);
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESI), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));

new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EDI, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 16 };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDI), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 16);
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDI), 16);
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.EAX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 12 };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 12);
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDI), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));

new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.ECX, SourceReg = CPUx86.RegistersEnum.EBP, SourceIsIndirect = true, SourceDisplacement = 8 };
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ECX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBP), sourceDisplacement: 8);
new CPUx86.Movs { Size = 8, Prefixes = CPUx86.InstructionPrefixes.Repeat };
}
}
Expand Down
Loading

0 comments on commit f5e3ea6

Please sign in to comment.