From 8a2d8a14033d15290410b8581504d66cd142fdca Mon Sep 17 00:00:00 2001 From: Matthijs ter Woord Date: Sun, 12 Jun 2016 09:46:11 -0400 Subject: [PATCH] . --- source/Cosmos.Debug.DebugStub/AsmBreak.asm | 10 +++--- source/Cosmos.Debug.DebugStub/CmdMisc.asm | 2 +- source/Cosmos.Debug.DebugStub/CmdProcess.asm | 4 +-- source/Cosmos.Debug.DebugStub/CmdSend.asm | 14 ++++---- source/Cosmos.Debug.DebugStub/Consts.asm | 2 +- source/Cosmos.Debug.DebugStub/DebugStub.asm | 4 +-- source/Cosmos.Debug.DebugStub/Init.asm | 3 +- source/Cosmos.Debug.DebugStub/Screen.asm | 2 +- source/Cosmos.Debug.DebugStub/Serial.asm | 2 +- .../Cosmos.Debug.DebugStub/SerialHelpers.asm | 10 +++--- source/Cosmos.Debug.DebugStub/SerialIO.asm | 6 ++-- source/Cosmos.Debug.DebugStub/TracerEntry.asm | 2 +- source/Cosmos.Debug.DebugStub/Utilities.asm | 2 +- source/XSharp.Compiler/AsmGenerator.cs | 2 -- source/XSharp.Compiler/TokenPatterns.cs | 30 ++++++++++++---- source/XSharp.Compiler/XS.Literal.cs | 28 ++++++--------- source/XSharp.Compiler/XS.cs | 34 +++++++++++++++++++ 17 files changed, 98 insertions(+), 59 deletions(-) diff --git a/source/Cosmos.Debug.DebugStub/AsmBreak.asm b/source/Cosmos.Debug.DebugStub/AsmBreak.asm index 56b3b50e8..d61bbf195 100644 --- a/source/Cosmos.Debug.DebugStub/AsmBreak.asm +++ b/source/Cosmos.Debug.DebugStub/AsmBreak.asm @@ -1,4 +1,4 @@ -; Generated at 6/12/2016 9:24:33 AM +; Generated at 6/12/2016 9:42:10 AM DebugStub_AsmBreakEIP dd 0 DebugStub_AsmOrigByte dd 0 @@ -45,8 +45,8 @@ Ret DebugStub_SetINT1_TrapFLAG: -Push EBP -Push EAX +push dword EBP +push dword EAX Mov EBP, [DebugStub_CallerESP] Sub EBP, 4 Mov EAX, [EBP] @@ -61,8 +61,8 @@ Ret DebugStub_ResetINT1_TrapFLAG: -Push EBP -Push EAX +push dword EBP +push dword EAX Mov EBP, [DebugStub_CallerESP] Sub EBP, 4 Mov EAX, [EBP] diff --git a/source/Cosmos.Debug.DebugStub/CmdMisc.asm b/source/Cosmos.Debug.DebugStub/CmdMisc.asm index 62cfffd97..bab263015 100644 --- a/source/Cosmos.Debug.DebugStub/CmdMisc.asm +++ b/source/Cosmos.Debug.DebugStub/CmdMisc.asm @@ -1,4 +1,4 @@ -; Generated at 6/12/2016 9:24:33 AM +; Generated at 6/12/2016 9:42:10 AM diff --git a/source/Cosmos.Debug.DebugStub/CmdProcess.asm b/source/Cosmos.Debug.DebugStub/CmdProcess.asm index 30bc03f7c..04360f6da 100644 --- a/source/Cosmos.Debug.DebugStub/CmdProcess.asm +++ b/source/Cosmos.Debug.DebugStub/CmdProcess.asm @@ -1,10 +1,10 @@ -; Generated at 6/12/2016 9:24:33 AM +; Generated at 6/12/2016 9:42:10 AM DebugStub_ProcessCommand: Call DebugStub_ComReadAL -Push EAX +push dword EAX Cmp AL, DebugStub_Const_Vs2Ds_Noop JE near DebugStub_ProcessCommand_Exit mov dword EAX, 0x0 diff --git a/source/Cosmos.Debug.DebugStub/CmdSend.asm b/source/Cosmos.Debug.DebugStub/CmdSend.asm index 5b2e91b63..e5083132b 100644 --- a/source/Cosmos.Debug.DebugStub/CmdSend.asm +++ b/source/Cosmos.Debug.DebugStub/CmdSend.asm @@ -1,4 +1,4 @@ -; Generated at 6/12/2016 9:24:33 AM +; Generated at 6/12/2016 9:42:10 AM @@ -148,7 +148,7 @@ Ret DebugStub_SendText: -Push EBP +push dword EBP Mov EBP, ESP Pushad Mov AL, DebugStub_Const_Ds2Vs_Message @@ -177,7 +177,7 @@ Ret DebugStub_SendSimpleNumber: -Push EBP +push dword EBP Mov EBP, ESP Pushad Mov AL, DebugStub_Const_Ds2Vs_SimpleNumber @@ -193,7 +193,7 @@ Ret DebugStub_SendSimpleLongNumber: -Push EBP +push dword EBP Mov EBP, ESP Pushad Mov AL, DebugStub_Const_Ds2Vs_SimpleLongNumber @@ -211,7 +211,7 @@ Ret DebugStub_SendComplexNumber: -Push EBP +push dword EBP Mov EBP, ESP Pushad Mov AL, DebugStub_Const_Ds2Vs_ComplexNumber @@ -227,7 +227,7 @@ Ret DebugStub_SendComplexLongNumber: -Push EBP +push dword EBP Mov EBP, ESP Pushad Mov AL, DebugStub_Const_Ds2Vs_ComplexLongNumber @@ -278,7 +278,7 @@ Ret DebugStub_SendInterruptOccurred: -Push EAX +push dword EAX Mov AL, DebugStub_Const_Ds2Vs_InterruptOccurred Call DebugStub_ComWriteAL Pop EAX diff --git a/source/Cosmos.Debug.DebugStub/Consts.asm b/source/Cosmos.Debug.DebugStub/Consts.asm index 879e1aef6..d82871cd5 100644 --- a/source/Cosmos.Debug.DebugStub/Consts.asm +++ b/source/Cosmos.Debug.DebugStub/Consts.asm @@ -1,4 +1,4 @@ -; Generated at 6/12/2016 9:24:33 AM +; Generated at 6/12/2016 9:42:10 AM DebugStub_Const_Signature equ 427034631 diff --git a/source/Cosmos.Debug.DebugStub/DebugStub.asm b/source/Cosmos.Debug.DebugStub/DebugStub.asm index 63205c614..86f250e92 100644 --- a/source/Cosmos.Debug.DebugStub/DebugStub.asm +++ b/source/Cosmos.Debug.DebugStub/DebugStub.asm @@ -1,4 +1,4 @@ -; Generated at 6/12/2016 9:24:33 AM +; Generated at 6/12/2016 9:42:10 AM DebugStub_CallerEBP dd 0 DebugStub_CallerEIP dd 0 @@ -17,7 +17,7 @@ Call DebugStub_ComReadEAX Mov ECX, EAX mov dword EAX, 0x0 Call DebugStub_ComReadAL -Push EAX +push dword EAX Mov EBX, DebugStub_DebugBPs shl dword EAX, 0x2 Add EBX, EAX diff --git a/source/Cosmos.Debug.DebugStub/Init.asm b/source/Cosmos.Debug.DebugStub/Init.asm index 362c7d461..dc5ca96ad 100644 --- a/source/Cosmos.Debug.DebugStub/Init.asm +++ b/source/Cosmos.Debug.DebugStub/Init.asm @@ -1,4 +1,4 @@ -; Generated at 6/12/2016 9:24:33 AM +; Generated at 6/12/2016 9:42:10 AM DebugStub_MaxBPId dd 0 @@ -41,7 +41,6 @@ mov byte AL, 0x0 Call DebugStub_ComWriteAL mov byte AL, 0x0 Call DebugStub_ComWriteAL -Push dword DebugStub_Const_Signature Mov ESI, ESP Call DebugStub_ComWrite32 Pop EAX diff --git a/source/Cosmos.Debug.DebugStub/Screen.asm b/source/Cosmos.Debug.DebugStub/Screen.asm index 093016c34..950d004d9 100644 --- a/source/Cosmos.Debug.DebugStub/Screen.asm +++ b/source/Cosmos.Debug.DebugStub/Screen.asm @@ -1,4 +1,4 @@ -; Generated at 6/12/2016 9:24:33 AM +; Generated at 6/12/2016 9:42:10 AM DebugWaitMsg db 96, 87, 97, 105, 116, 105, 110, 103, 32, 102, 111, 114, 32, 100, 101, 98, 117, 103, 103, 101, 114, 32, 99, 111, 110, 110, 101, 99, 116, 105, 111, 110, 46, 46, 46, 96, 0 diff --git a/source/Cosmos.Debug.DebugStub/Serial.asm b/source/Cosmos.Debug.DebugStub/Serial.asm index b0641ee27..41d3482de 100644 --- a/source/Cosmos.Debug.DebugStub/Serial.asm +++ b/source/Cosmos.Debug.DebugStub/Serial.asm @@ -1,4 +1,4 @@ -; Generated at 6/12/2016 9:24:33 AM +; Generated at 6/12/2016 9:42:10 AM %ifndef Exclude_IOPort_Based_SerialInit diff --git a/source/Cosmos.Debug.DebugStub/SerialHelpers.asm b/source/Cosmos.Debug.DebugStub/SerialHelpers.asm index 08085aa20..a0fb1196b 100644 --- a/source/Cosmos.Debug.DebugStub/SerialHelpers.asm +++ b/source/Cosmos.Debug.DebugStub/SerialHelpers.asm @@ -1,4 +1,4 @@ -; Generated at 6/12/2016 9:24:33 AM +; Generated at 6/12/2016 9:42:10 AM @@ -48,8 +48,8 @@ Ret DebugStub_ComWriteAL: -Push ESI -Push EAX +push dword ESI +push dword EAX Mov ESI, ESP Call DebugStub_ComWrite8 Pop EAX @@ -61,7 +61,7 @@ Ret DebugStub_ComWriteAX: -Push EAX +push dword EAX Mov ESI, ESP Call DebugStub_ComWrite16 Pop EAX @@ -72,7 +72,7 @@ Ret DebugStub_ComWriteEAX: -Push EAX +push dword EAX Mov ESI, ESP Call DebugStub_ComWrite32 Pop EAX diff --git a/source/Cosmos.Debug.DebugStub/SerialIO.asm b/source/Cosmos.Debug.DebugStub/SerialIO.asm index 0f53f9d8d..f6f424e2e 100644 --- a/source/Cosmos.Debug.DebugStub/SerialIO.asm +++ b/source/Cosmos.Debug.DebugStub/SerialIO.asm @@ -1,11 +1,11 @@ -; Generated at 6/12/2016 9:24:33 AM +; Generated at 6/12/2016 9:42:10 AM DebugStub_ComAddr dd 1016 %ifndef Exclude_IOPort_Based_Serial DebugStub_WriteRegister: -Push EDX +push dword EDX Add DX, 0x03F8 out DX, AL Pop EDX @@ -16,7 +16,7 @@ Ret DebugStub_ReadRegister: -Push EDX +push dword EDX Add DX, 0x03F8 in byte AL, DX Pop EDX diff --git a/source/Cosmos.Debug.DebugStub/TracerEntry.asm b/source/Cosmos.Debug.DebugStub/TracerEntry.asm index 90b5bd360..f3e4e0c97 100644 --- a/source/Cosmos.Debug.DebugStub/TracerEntry.asm +++ b/source/Cosmos.Debug.DebugStub/TracerEntry.asm @@ -1,4 +1,4 @@ -; Generated at 6/12/2016 9:24:33 AM +; Generated at 6/12/2016 9:42:10 AM diff --git a/source/Cosmos.Debug.DebugStub/Utilities.asm b/source/Cosmos.Debug.DebugStub/Utilities.asm index 907bde05d..da6b62cde 100644 --- a/source/Cosmos.Debug.DebugStub/Utilities.asm +++ b/source/Cosmos.Debug.DebugStub/Utilities.asm @@ -1,4 +1,4 @@ -; Generated at 6/12/2016 9:24:33 AM +; Generated at 6/12/2016 9:42:10 AM diff --git a/source/XSharp.Compiler/AsmGenerator.cs b/source/XSharp.Compiler/AsmGenerator.cs index 404fc8a06..7a7b6696d 100644 --- a/source/XSharp.Compiler/AsmGenerator.cs +++ b/source/XSharp.Compiler/AsmGenerator.cs @@ -140,8 +140,6 @@ namespace XSharp.Compiler { /// The resulting target assembler content. The returned object contains /// a code and a data block. protected void ProcessLine(string aLine, int lineNumber) { - Assembler xAsm; - aLine = aLine.Trim(); if (String.IsNullOrEmpty(aLine) || aLine == "//") { return; diff --git a/source/XSharp.Compiler/TokenPatterns.cs b/source/XSharp.Compiler/TokenPatterns.cs index 8aa534dad..8f57dfa0b 100644 --- a/source/XSharp.Compiler/TokenPatterns.cs +++ b/source/XSharp.Compiler/TokenPatterns.cs @@ -233,6 +233,20 @@ namespace XSharp.Compiler { return GetRef(xList, ref xIdx, true); } + private RegisterSize GetSize(Token aToken) + { + switch (aToken.RawValue) + { + case "byte": + return RegisterSize.Int32; + case "word": + return RegisterSize.Short16; + case "dword": + return RegisterSize.Int32; + default: + throw new Exception($"Invalid size '{aToken.RawValue}'"); + } + } protected string GetRef(List aTokens, ref int rIdx, bool onlySingleTokenRefs = false) { var xToken1 = aTokens[rIdx]; Token xToken2 = null; @@ -486,7 +500,8 @@ namespace XSharp.Compiler { idx = 0; val = GetRef(xParser.Tokens, ref idx); if (val != "@ret_on_stack@") { - XS.PushLiteral(val); + //XS.PushLiteral(val); + throw new Exception(); } else { //aAsm += GetPatternCode(xParser.Tokens).GetCode(false); throw new NotImplementedException("Didn't get converted yet!"); @@ -704,17 +719,18 @@ namespace XSharp.Compiler { }); AddPattern("+123", delegate(TokenList aTokens) { - XS.PushLiteral(GetSimpleRef(aTokens[0])); + XS.Push(aTokens[0].IntValue, RegisterSize.Int32); }); AddPattern(new string[] { "+123 as byte", "+123 as word", "+123 as dword" }, delegate(TokenList aTokens) { - XS.PushLiteral(GetSimpleRef(aTokens[3]) + " " + GetSimpleRef(aTokens[1])); + var xSize = GetSize(aTokens[1]); + XS.Push(aTokens[1].IntValue, xSize); }); AddPattern("+_REG", delegate(TokenList aTokens) { - XS.PushLiteral(GetSimpleRef(aTokens[1])); + XS.Push(aTokens[1].Register); }); AddPattern(new string[] { //0 1 2 3 @@ -723,11 +739,11 @@ namespace XSharp.Compiler { "+#_ABC as word", "+#_ABC as dword" }, delegate(TokenList aTokens) { - string xSize = "dword "; + RegisterSize xSize = RegisterSize.Int32; if (aTokens.Count > 2) { - xSize = aTokens[3].RawValue + " "; + xSize = GetSize(aTokens[3]); } - XS.PushLiteral(xSize + ConstLabel(aTokens[1])); + XS.Push(ConstLabel(aTokens[1]), size: xSize); }); AddPattern("+All", delegate(TokenList aTokens) { XS.PushAllGeneralRegisters(); diff --git a/source/XSharp.Compiler/XS.Literal.cs b/source/XSharp.Compiler/XS.Literal.cs index 776876556..730e3ab06 100644 --- a/source/XSharp.Compiler/XS.Literal.cs +++ b/source/XSharp.Compiler/XS.Literal.cs @@ -1,4 +1,5 @@ -using Cosmos.Assembler; +using System; +using Cosmos.Assembler; using static XSharp.Compiler.XSRegisters; namespace XSharp.Compiler @@ -10,7 +11,6 @@ namespace XSharp.Compiler new LiteralAssemblerCode(code); } - public static void AddLiteral(string left, string right) { LiteralCode("Add " + left + ", " + right); @@ -46,40 +46,35 @@ namespace XSharp.Compiler LiteralCode("xor " + left + ", " + right); } - public static void PushLiteral(string value) - { - new LiteralAssemblerCode("Push " + value); - } - public static void PopLiteral(string value) { - new LiteralAssemblerCode("Pop " + value); + LiteralCode("Pop " + value); } public static void IntegerMultiplyLiteral(string left, string right) { - new LiteralAssemblerCode("imul " + left + ", " + right); + LiteralCode("imul " + left + ", " + right); } public static void SetLiteral(string destination, string source) { - new LiteralAssemblerCode("Mov " + destination + ", " + source); + LiteralCode("Mov " + destination + ", " + source); } public static void SetLiteral(string size, string destination, string source) { - new LiteralAssemblerCode("Mov " + size + " " + destination + ", " + source); + LiteralCode("Mov " + size + " " + destination + ", " + source); } public static void CompareLiteral(string size, string destination, string source) { if (string.IsNullOrWhiteSpace(size)) { - new LiteralAssemblerCode($"Cmp {destination}, {source}"); + LiteralCode($"Cmp {destination}, {source}"); } else { - new LiteralAssemblerCode($"Cmp {size} {destination}, {source}"); + LiteralCode($"Cmp {size} {destination}, {source}"); } } @@ -87,15 +82,12 @@ namespace XSharp.Compiler { if (string.IsNullOrWhiteSpace(size)) { - new LiteralAssemblerCode($"Test {destination}, {source}"); + LiteralCode($"Test {destination}, {source}"); } else { - new LiteralAssemblerCode($"Test {size} {destination}, {source}"); + LiteralCode($"Test {size} {destination}, {source}"); } } - - - } } diff --git a/source/XSharp.Compiler/XS.cs b/source/XSharp.Compiler/XS.cs index cef8a47ff..69bda5322 100644 --- a/source/XSharp.Compiler/XS.cs +++ b/source/XSharp.Compiler/XS.cs @@ -149,6 +149,40 @@ namespace XSharp.Compiler }; } + public static void Push(Register value) + { + new Push + { + DestinationReg = value.RegEnum + }; + } + + public static void Push(uint value, RegisterSize size) + { + new Push + { + DestinationValue = value, + Size = (byte)size + }; + } + + public static void Push(string label, bool isIndirect = false, RegisterSize size = RegisterSize.Int32) + { + new Push + { + DestinationRef = ElementReference.New(label), + DestinationIsIndirect = isIndirect, + Size = (byte)size + }; + } + + public static void Pop(Register value) + { + new Pop + { + DestinationReg = value.RegEnum + }; + } } }