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 c4af87a commit 7877199
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 70 deletions.
4 changes: 2 additions & 2 deletions Users/Orvid/OrvidTestOS/AsmMouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override void AssembleNew(object aAssembler, object aMethodInfo)

XS.Call("mouse_read");

new Noop();
XS.Noop();

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

Expand All @@ -49,7 +49,7 @@ public override void AssembleNew(object aAssembler, object aMethodInfo)

XS.Call("mouse_write");

new Noop();
XS.Noop();

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using Cosmos.Assembler.x86;
using Cosmos.Assembler.x86;
using Cosmos.IL2CPU.Plugs;
using XSharp.Compiler;

namespace Cosmos.Core.Plugs.Assemblers
{
public class DisableInterruptsAssembler: AssemblerMethod
{
public override void AssembleNew(Assembler.Assembler aAssembler, object aMethodInfo)
{
new ClearInterruptFlag();
XS.ClearInterruptFlag();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using Cosmos.Assembler;
using Cosmos.Assembler;
using Cosmos.IL2CPU.Plugs;
using XSharp.Compiler;

namespace Cosmos.Core.Plugs.Assemblers
{
public class EnableInterruptsAssembler: AssemblerMethod
{
public override void AssembleNew(Assembler.Assembler aAssembler, object aMethodInfo)
{
new Assembler.x86.Sti();
XS.EnableInterrupts();
}
}
}
12 changes: 6 additions & 6 deletions source/Cosmos.Core.Plugs/Assemblers/UpdateIDT.cs
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
// the other INTs

// We are updating the IDT, disable interrupts
new CPUx86.ClearInterruptFlag();
XS.ClearInterruptFlag();

for (int i = 0; i < 256; i++)
{
Expand Down Expand Up @@ -116,7 +116,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
new CPUx86.Push { DestinationValue = 0 };
}
new CPUx86.Push { DestinationValue = (uint)j };
new CPUx86.Pushad();
XS.PushAllRegisters();

XS.Sub(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESP), 4);
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESP)); // preserve old stack address for passing to interrupt handler
Expand Down Expand Up @@ -146,16 +146,16 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESP), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX)); // this restores the stack for the FX stuff, except the pointer to the FX data
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESP), 4); // "pop" the pointer

new CPUx86.Popad();
XS.PopAllRegisters();

XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESP), 8);
new CPUAll.Label("__ISR_Handler_" + j.ToString("X2") + "_END");
new CPUx86.IRET();
XS.InterruptReturn();
}
new CPUAll.Label("__INTERRUPT_OCCURRED__");
new CPUx86.Return();
new CPUAll.Label("__AFTER__ALL__ISR__HANDLER__STUBS__");
new CPUx86.Noop();
XS.Noop();
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 All @@ -165,7 +165,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
new CPUx86.Mov { DestinationRef = CPUAll.ElementReference.New("static_field__Cosmos_Core_CPU_mInterruptsEnabled"), DestinationIsIndirect = true, SourceValue = 1 };
new CPUx86.Lidt { DestinationReg = CPUx86.RegistersEnum.EAX, DestinationIsIndirect = true };
// Reenable interrupts
new CPUx86.Sti();
XS.EnableInterrupts();

new CPUAll.Label(".__AFTER_ENABLE_INTERRUPTS");
}
Expand Down
14 changes: 7 additions & 7 deletions source/Cosmos.Core.Plugs/CPUImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ public static uint GetEndOfKernel() {

public class ZeroFillAsm : AssemblerMethod {
public override void AssembleNew(CPUAll.Assembler aAssembler, object aMethodInfo) {
new CPUx86.ClrDirFlag();
XS.ClearDirectionFlag();
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);
new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.NotBelow, DestinationLabel = ".step2" };
new CPUx86.StoreByteInString();
XS.StoreByteInString();
new CPUAll.Label(".step2");
XS.ShiftRight(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ECX), 1);
new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.NotBelow, DestinationLabel = ".step3" };
new CPUx86.StoreWordInString();
XS.StoreWordInString();
new CPUAll.Label(".step3");
new CPUx86.Stos { Size = 32, Prefixes = CPUx86.InstructionPrefixes.Repeat };
}
Expand All @@ -63,7 +63,7 @@ public static void ZeroFill(uint aStartAddress, uint aLength) { }

public class InitFloatAsm : AssemblerMethod {
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo) {
new CPUx86.x87.FloatInit();
XS.FPU.FloatInit();
}
}

Expand All @@ -72,7 +72,7 @@ public static void InitFloat(CPU aThis) { }

public class HaltAsm : AssemblerMethod {
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo) {
new CPUx86.Halt();
XS.Halt();
}
}

Expand Down Expand Up @@ -124,15 +124,15 @@ public class DisableINTsAsm : AssemblerMethod
{
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo)
{
new CPUx86.ClearInterruptFlag();
XS.ClearInterruptFlag();
}
}

public class EnableINTsAsm : AssemblerMethod
{
public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo)
{
new CPUx86.Sti();
XS.EnableInterrupts();
}
}

Expand Down
24 changes: 12 additions & 12 deletions source/Cosmos.Core.Plugs/System/Assemblers/InvokeImplAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
* EBX contains the number of items in the array
* ECX contains the argument size
*/
new CPUx86.ClearInterruptFlag();
XS.ClearInterruptFlag();
XS.Label(".DEBUG");
//new CPU.Label("____DEBUG_FOR_MULTICAST___");
XS.Comment("move address of delegate to eax");
Expand Down Expand Up @@ -66,7 +66,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
{
XS.Compare(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EBX));//are we at the end of this list
new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.GreaterThanOrEqualTo, DestinationLabel = ".END_OF_INVOKE_" };//then we better stop
new CPUx86.Pushad();
XS.PushAllRegisters();
XS.Comment("esi points to where we will copy the methods argumetns from");
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESI), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.ESP));
XS.Comment("edi = ptr to delegate object");
Expand Down Expand Up @@ -112,7 +112,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
XS.Set(XSRegisters.EDI, XSRegisters.EDI, sourceIsIndirect: true); // dereference handle
XS.Set(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDI), XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDI), sourceDisplacement: Ldfld.GetFieldOffset(xMethodInfo.MethodBase.DeclaringType, "System.Object System.Delegate._target"));//i really dont get the +12, MtW: that's for the object header
XS.Label(".noTHIStoPop");
new CPUx86.Popad();
XS.PopAllRegisters();
XS.Increment(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX));
XS.Add(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX), 4);
XS.Jump(".BEGIN_OF_LOOP");
Expand All @@ -131,21 +131,21 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EDX));//ebp
new CPUx86.Mov { DestinationReg = CPUx86.RegistersEnum.ESP, DestinationIsIndirect = true, DestinationDisplacement = 12, SourceReg = CPUx86.RegistersEnum.EDI };
new Assembler.Label(".noReturn");
new CPUx86.Sti();
XS.EnableInterrupts();
}

#region OLD attempt
// public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object aMethodInfo) {
// new CPUx86.Xchg { DestinationReg = CPUx86.Registers.BX, SourceReg = CPUx86.Registers.BX, Size = 16 };
// new CPUx86.Noop();
// XS.Noop();
// var xAssembler = (CosmosAssembler)aAssembler;
// var xMethodInfo = (Cosmos.IL2CPU.MethodInfo)aMethodInfo;
// var xMethodBaseAsInfo = xMethodInfo.MethodBase as global::System.Reflection.MethodInfo;
// if (xMethodBaseAsInfo.ReturnType != typeof(void)) {
// throw new Exception("Events with return type not yet supported!");
// }
// new Comment("XXXXXXX");
// //new CPUx86.Halt();
// //XS.Halt();
// // param 0 is instance of eventhandler
// // param 1 is sender
// // param 2 is eventargs
Expand Down Expand Up @@ -204,15 +204,15 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
// //new CPU.Label(".noreturnYet");
// //new CPU.Comment("space for the return value");
// //new CPUx86.Pushd("0");
// new CPUx86.Pushad();
// XS.Pushad();
// new CPU.Comment("esi points to where we will copy the methods arguments from");
// XS.Mov(XSRegisters.ESI, XSRegisters.CPUx86.Registers.ESP);
// new CPU.Comment("edi = ptr to delegate object");
// new CPUx86.Pushad();
// XS.Pushad();
// Ldarg.DoExecute(xAssembler, xMethodInfo, 0);
// Ldfld.DoExecute(xAssembler, xMethodInfo.MethodBase.DeclaringType, "System.Object System.Delegate._target");
// XS.Pop(XSRegisters.EDI);
// new CPUx86.Popad();
// XS.Popad();
// XS.Compare(XSRegisters.EDI, 0);
// new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.Zero, DestinationLabel = ".NO_THIS" };
// XS.Push(XSRegisters.EDI);
Expand All @@ -224,7 +224,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
// new CPU.Comment("move the current delegate to edi");
// XS.Mov(XSRegisters.EDI, XSRegisters.EAX, sourceIsIndirect: true);
// new CPU.Comment("move the methodptr from that delegate to the stack ");
// new CPUx86.Pushad();
// XS.Pushad();
// Ldarg.DoExecute(xAssembler, xMethodInfo, 0);
// Ldfld.DoExecute(xAssembler, xMethodInfo.MethodBase.DeclaringType, "System.IntPtr System.Delegate._methodPtr");
// XS.Mov(XSRegisters.EDI, XSRegisters.CPUx86.Registers.ESP);
Expand Down Expand Up @@ -266,7 +266,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
// //new CPUx86.Pop("edi");
// //new CPUx86.Move("[esp]", "edi");
// new CPU.Label(".noTHIStoPop");
// new CPUx86.Popad();
// XS.Popad();
// XS.INC(XSRegisters.EDX);
// XS.Add(XSRegisters.EAX, 4);
// XS.Jump(".BEGIN_OF_LOOP");
Expand All @@ -289,7 +289,7 @@ public override void AssembleNew(Cosmos.Assembler.Assembler aAssembler, object a
// //XS.Push(XSRegisters.EDX);//ebp
// //new CPUx86.Move { DestinationReg = CPUx86.Registers.ESP, DestinationIsIndirect = true, DestinationDisplacement = 12, SourceReg = CPUx86.Registers.EDI };
// new CPU.Label(".noReturn");
// // new CPUx86.Sti();
// // XS.Sti();
// //#warning remove this ^ sti call when issue is fixed!!!
// //MethodInfo.Arguments[0].
// // new CPUx86.Move("ebx", "[eax + " + (MethodInfo.Arguments[0].TypeInfo.Fields["$$ArgSize$$"].Offset + 12) + "]");
Expand Down
16 changes: 8 additions & 8 deletions source/Cosmos.IL2CPU/AppAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ protected void MethodBegin(MethodInfo aMethod)
XS.Set(OldToNewRegister(RegistersEnum.EAX), "Before_Kernel_Stack");
XS.Compare(OldToNewRegister(RegistersEnum.EAX), OldToNewRegister(RegistersEnum.ESP));
XS.Jump(ConditionalTestEnum.LessThan, mCurrentMethodLabel + ".StackOverflowCheck_End");
new ClearInterruptFlag();
XS.ClearInterruptFlag();
// don't remove the call. It seems pointless, but we need it to retrieve the EIP value
new Call { DestinationLabel = mCurrentMethodLabel + ".StackOverflowCheck_GetAddress" };
XS.Label(mCurrentMethodLabel + ".StackOverflowCheck_GetAddress");
XS.Pop(OldToNewRegister(RegistersEnum.EAX));
new Mov { DestinationRef = ElementReference.New("DebugStub_CallerEIP"), DestinationIsIndirect = true, SourceReg = RegistersEnum.EAX };
XS.Call("DebugStub_SendStackOverflowOccurred");
new Halt();
XS.Halt();
XS.Label(mCurrentMethodLabel + ".StackOverflowCheck_End");

}
Expand Down Expand Up @@ -418,14 +418,14 @@ protected void MethodEnd(MethodInfo aMethod)
XS.Set(OldToNewRegister(RegistersEnum.EBX), OldToNewRegister(RegistersEnum.EBP));
XS.Compare(OldToNewRegister(RegistersEnum.EAX), OldToNewRegister(RegistersEnum.EBX));
XS.Jump(ConditionalTestEnum.Equal, xLabelExc + "__2");
new ClearInterruptFlag();
XS.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" };
XS.Label(xLabelExc + ".MethodFooterStackCorruptionCheck_Break_on_location");
XS.Pop(OldToNewRegister(RegistersEnum.EAX));
new Mov { DestinationRef = ElementReference.New("DebugStub_CallerEIP"), DestinationIsIndirect = true, SourceReg = RegistersEnum.EAX };
XS.Call("DebugStub_SendStackCorruptionOccurred");
new Halt();
XS.Halt();
}
XS.Label(xLabelExc + "__2");
XS.Pop(OldToNewRegister(RegistersEnum.EBP));
Expand Down Expand Up @@ -1504,14 +1504,14 @@ protected void BeforeOp(MethodInfo aMethod, ILOpCode aOpCode, bool emitInt3NotNo
}
XS.Compare(OldToNewRegister(RegistersEnum.EAX), OldToNewRegister(RegistersEnum.EBX));
XS.Jump(ConditionalTestEnum.Equal, xLabel + ".StackCorruptionCheck_End");
new ClearInterruptFlag();
XS.ClearInterruptFlag();
// don't remove the call. It seems pointless, but we need it to retrieve the EIP value
new Call { DestinationLabel = xLabel + ".StackCorruptionCheck_GetAddress" };
XS.Label(xLabel + ".StackCorruptionCheck_GetAddress");
XS.Pop(OldToNewRegister(RegistersEnum.EAX));
new Mov { DestinationRef = ElementReference.New("DebugStub_CallerEIP"), DestinationIsIndirect = true, SourceReg = RegistersEnum.EAX };
XS.Call("DebugStub_SendStackCorruptionOccurred");
new Halt();
XS.Halt();
new Assembler.Label(xLabel + ".StackCorruptionCheck_End");

}
Expand Down Expand Up @@ -1604,12 +1604,12 @@ protected void EmitTracer(MethodInfo aMethod, ILOpCode aOp, string aNamespace, b
if (emitInt3NotNop)
{
INT3Emitted = true;
new INT3();
XS.Int3();
}
else
{
INT3PlaceholderEmitted = true;
new DebugNoop();
XS.DebugNoop();
}
}

Expand Down
6 changes: 3 additions & 3 deletions source/Cosmos.IL2CPU/CosmosAssembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void Initialize()

// CLI ASAP
WriteDebugVideo("Clearing interrupts.");
new ClearInterruptFlag();
XS.ClearInterruptFlag();


WriteDebugVideo("Begin multiboot info.");
Expand Down Expand Up @@ -345,8 +345,8 @@ public void Initialize()

new Comment(this, "Kernel done - loop till next IRQ");
XS.Label(".loop");
new ClearInterruptFlag();
new Halt();
XS.ClearInterruptFlag();
XS.Halt();
XS.Jump(".loop");

if (mComPort > 0)
Expand Down
4 changes: 2 additions & 2 deletions source/Cosmos.IL2CPU/IL/Conv_Ovf_I.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
// case 2:
// case 4:
// {
// new CPUx86.Noop();
// XS.Noop();
// break;
// }
// case 8:
Expand Down Expand Up @@ -93,7 +93,7 @@ public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
// case 2:
// case 4:
// {
// new CPUx86.Noop();
// XS.Noop();
// break;
// }
// case 8:
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/IL/Conv_Ovf_I8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
XS.Push(XSRegisters.OldToNewRegister(CPUx86.RegistersEnum.EAX));
break;
case 8:
new CPUx86.Noop();
XS.Noop();
break;
default:
//EmitNotImplementedException( Assembler, GetServiceProvider(), "Conv_Ovf_I8: SourceSize " + xSource + " not supported!", mCurLabel, mMethodInformation, mCurOffset, mNextLabel );
Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/IL/Conv_U8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override void Execute(MethodInfo aMethod, ILOpCode aOpCode)
if (TypeIsFloat(xSource))
{
new CPUx86.x87.FloatLoad { DestinationReg = RegistersEnum.ESP, Size = 64, DestinationIsIndirect = true };
new CPUx86.x87.FloatABS();
XS.FPU.FloatAbs();
new CPUx86.x87.IntStoreWithTrunc { DestinationReg = RegistersEnum.ESP, Size = 64, DestinationIsIndirect = true };
}
//Else it's already an Int64, or UInt64
Expand Down
3 changes: 2 additions & 1 deletion source/Cosmos.IL2CPU/IL/Nop.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using XSharp.Compiler;
using CPU = Cosmos.Assembler.x86;

namespace Cosmos.IL2CPU.X86.IL
Expand All @@ -13,7 +14,7 @@ public Nop( Cosmos.Assembler.Assembler aAsmblr )

public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
{
new CPU.Noop();
XS.Noop();
}

}
Expand Down
Loading

0 comments on commit 7877199

Please sign in to comment.