This commit is contained in:
Matthijs ter Woord 2016-06-12 09:46:11 -04:00
parent 91d891244c
commit 8a2d8a1403
17 changed files with 98 additions and 59 deletions

View file

@ -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_AsmBreakEIP dd 0
DebugStub_AsmOrigByte dd 0 DebugStub_AsmOrigByte dd 0
@ -45,8 +45,8 @@ Ret
DebugStub_SetINT1_TrapFLAG: DebugStub_SetINT1_TrapFLAG:
Push EBP push dword EBP
Push EAX push dword EAX
Mov EBP, [DebugStub_CallerESP] Mov EBP, [DebugStub_CallerESP]
Sub EBP, 4 Sub EBP, 4
Mov EAX, [EBP] Mov EAX, [EBP]
@ -61,8 +61,8 @@ Ret
DebugStub_ResetINT1_TrapFLAG: DebugStub_ResetINT1_TrapFLAG:
Push EBP push dword EBP
Push EAX push dword EAX
Mov EBP, [DebugStub_CallerESP] Mov EBP, [DebugStub_CallerESP]
Sub EBP, 4 Sub EBP, 4
Mov EAX, [EBP] Mov EAX, [EBP]

View file

@ -1,4 +1,4 @@
; Generated at 6/12/2016 9:24:33 AM ; Generated at 6/12/2016 9:42:10 AM

View file

@ -1,10 +1,10 @@
; Generated at 6/12/2016 9:24:33 AM ; Generated at 6/12/2016 9:42:10 AM
DebugStub_ProcessCommand: DebugStub_ProcessCommand:
Call DebugStub_ComReadAL Call DebugStub_ComReadAL
Push EAX push dword EAX
Cmp AL, DebugStub_Const_Vs2Ds_Noop Cmp AL, DebugStub_Const_Vs2Ds_Noop
JE near DebugStub_ProcessCommand_Exit JE near DebugStub_ProcessCommand_Exit
mov dword EAX, 0x0 mov dword EAX, 0x0

View file

@ -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: DebugStub_SendText:
Push EBP push dword EBP
Mov EBP, ESP Mov EBP, ESP
Pushad Pushad
Mov AL, DebugStub_Const_Ds2Vs_Message Mov AL, DebugStub_Const_Ds2Vs_Message
@ -177,7 +177,7 @@ Ret
DebugStub_SendSimpleNumber: DebugStub_SendSimpleNumber:
Push EBP push dword EBP
Mov EBP, ESP Mov EBP, ESP
Pushad Pushad
Mov AL, DebugStub_Const_Ds2Vs_SimpleNumber Mov AL, DebugStub_Const_Ds2Vs_SimpleNumber
@ -193,7 +193,7 @@ Ret
DebugStub_SendSimpleLongNumber: DebugStub_SendSimpleLongNumber:
Push EBP push dword EBP
Mov EBP, ESP Mov EBP, ESP
Pushad Pushad
Mov AL, DebugStub_Const_Ds2Vs_SimpleLongNumber Mov AL, DebugStub_Const_Ds2Vs_SimpleLongNumber
@ -211,7 +211,7 @@ Ret
DebugStub_SendComplexNumber: DebugStub_SendComplexNumber:
Push EBP push dword EBP
Mov EBP, ESP Mov EBP, ESP
Pushad Pushad
Mov AL, DebugStub_Const_Ds2Vs_ComplexNumber Mov AL, DebugStub_Const_Ds2Vs_ComplexNumber
@ -227,7 +227,7 @@ Ret
DebugStub_SendComplexLongNumber: DebugStub_SendComplexLongNumber:
Push EBP push dword EBP
Mov EBP, ESP Mov EBP, ESP
Pushad Pushad
Mov AL, DebugStub_Const_Ds2Vs_ComplexLongNumber Mov AL, DebugStub_Const_Ds2Vs_ComplexLongNumber
@ -278,7 +278,7 @@ Ret
DebugStub_SendInterruptOccurred: DebugStub_SendInterruptOccurred:
Push EAX push dword EAX
Mov AL, DebugStub_Const_Ds2Vs_InterruptOccurred Mov AL, DebugStub_Const_Ds2Vs_InterruptOccurred
Call DebugStub_ComWriteAL Call DebugStub_ComWriteAL
Pop EAX Pop EAX

View file

@ -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 DebugStub_Const_Signature equ 427034631

View file

@ -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_CallerEBP dd 0
DebugStub_CallerEIP dd 0 DebugStub_CallerEIP dd 0
@ -17,7 +17,7 @@ Call DebugStub_ComReadEAX
Mov ECX, EAX Mov ECX, EAX
mov dword EAX, 0x0 mov dword EAX, 0x0
Call DebugStub_ComReadAL Call DebugStub_ComReadAL
Push EAX push dword EAX
Mov EBX, DebugStub_DebugBPs Mov EBX, DebugStub_DebugBPs
shl dword EAX, 0x2 shl dword EAX, 0x2
Add EBX, EAX Add EBX, EAX

View file

@ -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 DebugStub_MaxBPId dd 0
@ -41,7 +41,6 @@ mov byte AL, 0x0
Call DebugStub_ComWriteAL Call DebugStub_ComWriteAL
mov byte AL, 0x0 mov byte AL, 0x0
Call DebugStub_ComWriteAL Call DebugStub_ComWriteAL
Push dword DebugStub_Const_Signature
Mov ESI, ESP Mov ESI, ESP
Call DebugStub_ComWrite32 Call DebugStub_ComWrite32
Pop EAX Pop EAX

View file

@ -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 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

View file

@ -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 %ifndef Exclude_IOPort_Based_SerialInit

View file

@ -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: DebugStub_ComWriteAL:
Push ESI push dword ESI
Push EAX push dword EAX
Mov ESI, ESP Mov ESI, ESP
Call DebugStub_ComWrite8 Call DebugStub_ComWrite8
Pop EAX Pop EAX
@ -61,7 +61,7 @@ Ret
DebugStub_ComWriteAX: DebugStub_ComWriteAX:
Push EAX push dword EAX
Mov ESI, ESP Mov ESI, ESP
Call DebugStub_ComWrite16 Call DebugStub_ComWrite16
Pop EAX Pop EAX
@ -72,7 +72,7 @@ Ret
DebugStub_ComWriteEAX: DebugStub_ComWriteEAX:
Push EAX push dword EAX
Mov ESI, ESP Mov ESI, ESP
Call DebugStub_ComWrite32 Call DebugStub_ComWrite32
Pop EAX Pop EAX

View file

@ -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 DebugStub_ComAddr dd 1016
%ifndef Exclude_IOPort_Based_Serial %ifndef Exclude_IOPort_Based_Serial
DebugStub_WriteRegister: DebugStub_WriteRegister:
Push EDX push dword EDX
Add DX, 0x03F8 Add DX, 0x03F8
out DX, AL out DX, AL
Pop EDX Pop EDX
@ -16,7 +16,7 @@ Ret
DebugStub_ReadRegister: DebugStub_ReadRegister:
Push EDX push dword EDX
Add DX, 0x03F8 Add DX, 0x03F8
in byte AL, DX in byte AL, DX
Pop EDX Pop EDX

View file

@ -1,4 +1,4 @@
; Generated at 6/12/2016 9:24:33 AM ; Generated at 6/12/2016 9:42:10 AM

View file

@ -1,4 +1,4 @@
; Generated at 6/12/2016 9:24:33 AM ; Generated at 6/12/2016 9:42:10 AM

View file

@ -140,8 +140,6 @@ namespace XSharp.Compiler {
/// <returns>The resulting target assembler content. The returned object contains /// <returns>The resulting target assembler content. The returned object contains
/// a code and a data block.</returns> /// a code and a data block.</returns>
protected void ProcessLine(string aLine, int lineNumber) { protected void ProcessLine(string aLine, int lineNumber) {
Assembler xAsm;
aLine = aLine.Trim(); aLine = aLine.Trim();
if (String.IsNullOrEmpty(aLine) || aLine == "//") { if (String.IsNullOrEmpty(aLine) || aLine == "//") {
return; return;

View file

@ -233,6 +233,20 @@ namespace XSharp.Compiler {
return GetRef(xList, ref xIdx, true); 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<Token> aTokens, ref int rIdx, bool onlySingleTokenRefs = false) { protected string GetRef(List<Token> aTokens, ref int rIdx, bool onlySingleTokenRefs = false) {
var xToken1 = aTokens[rIdx]; var xToken1 = aTokens[rIdx];
Token xToken2 = null; Token xToken2 = null;
@ -486,7 +500,8 @@ namespace XSharp.Compiler {
idx = 0; idx = 0;
val = GetRef(xParser.Tokens, ref idx); val = GetRef(xParser.Tokens, ref idx);
if (val != "@ret_on_stack@") { if (val != "@ret_on_stack@") {
XS.PushLiteral(val); //XS.PushLiteral(val);
throw new Exception();
} else { } else {
//aAsm += GetPatternCode(xParser.Tokens).GetCode(false); //aAsm += GetPatternCode(xParser.Tokens).GetCode(false);
throw new NotImplementedException("Didn't get converted yet!"); throw new NotImplementedException("Didn't get converted yet!");
@ -704,17 +719,18 @@ namespace XSharp.Compiler {
}); });
AddPattern("+123", delegate(TokenList aTokens) { AddPattern("+123", delegate(TokenList aTokens) {
XS.PushLiteral(GetSimpleRef(aTokens[0])); XS.Push(aTokens[0].IntValue, RegisterSize.Int32);
}); });
AddPattern(new string[] { AddPattern(new string[] {
"+123 as byte", "+123 as byte",
"+123 as word", "+123 as word",
"+123 as dword" "+123 as dword"
}, delegate(TokenList aTokens) { }, 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) { AddPattern("+_REG", delegate(TokenList aTokens) {
XS.PushLiteral(GetSimpleRef(aTokens[1])); XS.Push(aTokens[1].Register);
}); });
AddPattern(new string[] { AddPattern(new string[] {
//0 1 2 3 //0 1 2 3
@ -723,11 +739,11 @@ namespace XSharp.Compiler {
"+#_ABC as word", "+#_ABC as word",
"+#_ABC as dword" "+#_ABC as dword"
}, delegate(TokenList aTokens) { }, delegate(TokenList aTokens) {
string xSize = "dword "; RegisterSize xSize = RegisterSize.Int32;
if (aTokens.Count > 2) { 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) { AddPattern("+All", delegate(TokenList aTokens) {
XS.PushAllGeneralRegisters(); XS.PushAllGeneralRegisters();

View file

@ -1,4 +1,5 @@
using Cosmos.Assembler; using System;
using Cosmos.Assembler;
using static XSharp.Compiler.XSRegisters; using static XSharp.Compiler.XSRegisters;
namespace XSharp.Compiler namespace XSharp.Compiler
@ -10,7 +11,6 @@ namespace XSharp.Compiler
new LiteralAssemblerCode(code); new LiteralAssemblerCode(code);
} }
public static void AddLiteral(string left, string right) public static void AddLiteral(string left, string right)
{ {
LiteralCode("Add " + left + ", " + right); LiteralCode("Add " + left + ", " + right);
@ -46,40 +46,35 @@ namespace XSharp.Compiler
LiteralCode("xor " + left + ", " + right); LiteralCode("xor " + left + ", " + right);
} }
public static void PushLiteral(string value)
{
new LiteralAssemblerCode("Push " + value);
}
public static void PopLiteral(string value) public static void PopLiteral(string value)
{ {
new LiteralAssemblerCode("Pop " + value); LiteralCode("Pop " + value);
} }
public static void IntegerMultiplyLiteral(string left, string right) 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) 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) 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) public static void CompareLiteral(string size, string destination, string source)
{ {
if (string.IsNullOrWhiteSpace(size)) if (string.IsNullOrWhiteSpace(size))
{ {
new LiteralAssemblerCode($"Cmp {destination}, {source}"); LiteralCode($"Cmp {destination}, {source}");
} }
else else
{ {
new LiteralAssemblerCode($"Cmp {size} {destination}, {source}"); LiteralCode($"Cmp {size} {destination}, {source}");
} }
} }
@ -87,15 +82,12 @@ namespace XSharp.Compiler
{ {
if (string.IsNullOrWhiteSpace(size)) if (string.IsNullOrWhiteSpace(size))
{ {
new LiteralAssemblerCode($"Test {destination}, {source}"); LiteralCode($"Test {destination}, {source}");
} }
else else
{ {
new LiteralAssemblerCode($"Test {size} {destination}, {source}"); LiteralCode($"Test {size} {destination}, {source}");
} }
} }
} }
} }

View file

@ -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
};
}
} }
} }