mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-27 14:02:19 +00:00
Optimized asm in DebubStub a bit
This commit is contained in:
parent
ecb1f42bd3
commit
7265b30987
5 changed files with 65 additions and 21 deletions
|
|
@ -336,6 +336,7 @@
|
||||||
<Compile Include="X\RegisterEBP.cs" />
|
<Compile Include="X\RegisterEBP.cs" />
|
||||||
<Compile Include="X\RegisterECX.cs" />
|
<Compile Include="X\RegisterECX.cs" />
|
||||||
<Compile Include="X\RegisterEDX.cs" />
|
<Compile Include="X\RegisterEDX.cs" />
|
||||||
|
<Compile Include="X\RegisterESI.cs" />
|
||||||
<Compile Include="X\RegisterESP.cs" />
|
<Compile Include="X\RegisterESP.cs" />
|
||||||
<Compile Include="X\Y86.cs" />
|
<Compile Include="X\Y86.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -91,19 +91,15 @@ namespace Indy.IL2CPU.Assembler.X86 {
|
||||||
//TODO: Add extension methods so we can do int.Push, byte.Push, etc
|
//TODO: Add extension methods so we can do int.Push, byte.Push, etc
|
||||||
AL = (int)MsgType.TracePoint;
|
AL = (int)MsgType.TracePoint;
|
||||||
EAX.Push();
|
EAX.Push();
|
||||||
|
ESI = ESP;
|
||||||
Call("WriteByteToComPort");
|
Call("WriteByteToComPort");
|
||||||
|
EAX.Pop();
|
||||||
|
|
||||||
// Send EIP
|
// Send EIP
|
||||||
AL = Memory[EBP];
|
ESI = EBP;
|
||||||
EAX.Push();
|
|
||||||
Call("WriteByteToComPort");
|
Call("WriteByteToComPort");
|
||||||
AL = Memory[EBP + 1];
|
|
||||||
EAX.Push();
|
|
||||||
Call("WriteByteToComPort");
|
Call("WriteByteToComPort");
|
||||||
AL = Memory[EBP + 2];
|
|
||||||
EAX.Push();
|
|
||||||
Call("WriteByteToComPort");
|
Call("WriteByteToComPort");
|
||||||
AL = Memory[EBP + 3];
|
|
||||||
EAX.Push();
|
|
||||||
Call("WriteByteToComPort");
|
Call("WriteByteToComPort");
|
||||||
Label = "DebugStub_SendTrace_Exit";
|
Label = "DebugStub_SendTrace_Exit";
|
||||||
Return();
|
Return();
|
||||||
|
|
@ -116,26 +112,26 @@ namespace Indy.IL2CPU.Assembler.X86 {
|
||||||
// Write the type
|
// Write the type
|
||||||
AL = (int)MsgType.Text;
|
AL = (int)MsgType.Text;
|
||||||
EAX.Push();
|
EAX.Push();
|
||||||
|
ESI = ESP;
|
||||||
Call("WriteByteToComPort");
|
Call("WriteByteToComPort");
|
||||||
|
EAX.Pop();
|
||||||
|
|
||||||
|
//TODO: Limited to 255 bytes, need to send 2 bytes
|
||||||
// Write Length
|
// Write Length
|
||||||
EAX = Memory[EBP + 12];
|
ESI = EBP;
|
||||||
ECX = EAX; // Store in counter for later
|
new Add("ESI", 12);
|
||||||
EAX.Push();
|
ECX = Memory[ESI];
|
||||||
Call("WriteByteToComPort");
|
Call("WriteByteToComPort");
|
||||||
|
|
||||||
// Address of string
|
// Address of string
|
||||||
new X86.Move("ESI", "[EBP + 8]");
|
ESI = Memory[EBP + 8];
|
||||||
Label = "DebugStub_SendTextWriteChar";
|
Label = "DebugStub_SendTextWriteChar";
|
||||||
ECX.Compare(0);
|
ECX.Compare(0);
|
||||||
JumpIf(Flags.Equal, "DebugStub_SendTextExit");
|
JumpIf(Flags.Equal, "DebugStub_SendTextExit");
|
||||||
new X86.Move("AL", "[ESI]");
|
|
||||||
EAX.Push();
|
|
||||||
Call("WriteByteToComPort");
|
Call("WriteByteToComPort");
|
||||||
new X86.Dec("ECX");
|
new X86.Dec("ECX");
|
||||||
// We are storing as 16 bits, but for now I will transmit 8 bits
|
// We are storing as 16 bits, but for now I will transmit 8 bits
|
||||||
// So we inc twice to skip the 0
|
// So we inc again to skip the 0
|
||||||
new X86.Inc("ESI");
|
|
||||||
new X86.Inc("ESI");
|
new X86.Inc("ESI");
|
||||||
Jump("DebugStub_SendTextWriteChar");
|
Jump("DebugStub_SendTextWriteChar");
|
||||||
|
|
||||||
|
|
@ -146,7 +142,7 @@ namespace Indy.IL2CPU.Assembler.X86 {
|
||||||
// Input: ESI
|
// Input: ESI
|
||||||
// Output: None
|
// Output: None
|
||||||
// Modifies: EAX, EDX
|
// Modifies: EAX, EDX
|
||||||
|
//
|
||||||
// Sends byte at [ESI] to com port and does esi + 1
|
// Sends byte at [ESI] to com port and does esi + 1
|
||||||
protected void WriteByteToComPort() {
|
protected void WriteByteToComPort() {
|
||||||
// This sucks to use the stack, but x86 can only read and write ports from AL and
|
// This sucks to use the stack, but x86 can only read and write ports from AL and
|
||||||
|
|
@ -161,14 +157,22 @@ namespace Indy.IL2CPU.Assembler.X86 {
|
||||||
// Sucks again to use DX just for this, but x86 only supports
|
// Sucks again to use DX just for this, but x86 only supports
|
||||||
// 8 bit address for literals on ports
|
// 8 bit address for literals on ports
|
||||||
DX = mComStatusAddr;
|
DX = mComStatusAddr;
|
||||||
|
|
||||||
|
// Wait for serial port to be ready
|
||||||
Label = "WriteByteToComPort_Wait";
|
Label = "WriteByteToComPort_Wait";
|
||||||
AL = Port[DX];
|
AL = Port[DX];
|
||||||
AL.Test(0x20);
|
AL.Test(0x20);
|
||||||
JumpIf(Flags.Zero, "WriteByteToComPort_Wait");
|
JumpIf(Flags.Zero, "WriteByteToComPort_Wait");
|
||||||
|
|
||||||
|
// Set address of port
|
||||||
DX = mComAddr;
|
DX = mComAddr;
|
||||||
AL = Memory[ESP + 4];
|
// Get byte to send
|
||||||
|
AL = Memory[ESI];
|
||||||
|
// Send the byte
|
||||||
Port[DX] = AL;
|
Port[DX] = AL;
|
||||||
Return(4);
|
|
||||||
|
new Inc("ESI");
|
||||||
|
Return();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void DebugSuspend() {
|
protected void DebugSuspend() {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ namespace Indy.IL2CPU.Assembler.X86.X {
|
||||||
new Push(ToString());
|
new Push(ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Pop() {
|
||||||
|
new Pop(ToString());
|
||||||
|
}
|
||||||
|
|
||||||
protected void Move(string aValue) {
|
protected void Move(string aValue) {
|
||||||
new X86.Move(ToString(), aValue);
|
new X86.Move(ToString(), aValue);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
35
source/Indy.IL2CPU.Assembler.X86/X/RegisterESI.cs
Normal file
35
source/Indy.IL2CPU.Assembler.X86/X/RegisterESI.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Indy.IL2CPU.Assembler.X86.X {
|
||||||
|
public class RegisterESI : Register32 {
|
||||||
|
public const string Name = "ESI";
|
||||||
|
public static readonly RegisterESI Instance = new RegisterESI();
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator RegisterESI(MemoryAction aAction) {
|
||||||
|
Instance.Move(aAction.ToString());
|
||||||
|
return Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator RegisterESI(UInt32 aValue) {
|
||||||
|
Instance.Move(aValue.ToString());
|
||||||
|
return Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator RegisterESI(RegisterESP aValue) {
|
||||||
|
Instance.Move(aValue.ToString());
|
||||||
|
return Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator RegisterESI(RegisterEBP aValue) {
|
||||||
|
Instance.Move(aValue.ToString());
|
||||||
|
return Instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -19,9 +19,9 @@ namespace Indy.IL2CPU.Assembler.X86.X {
|
||||||
public RegisterEDX EDX = RegisterEDX.Instance;
|
public RegisterEDX EDX = RegisterEDX.Instance;
|
||||||
public RegisterDX DX = RegisterDX.Instance;
|
public RegisterDX DX = RegisterDX.Instance;
|
||||||
|
|
||||||
public RegisterESP ESP = RegisterESP.Instance;
|
|
||||||
|
|
||||||
public RegisterEBP EBP = RegisterEBP.Instance;
|
public RegisterEBP EBP = RegisterEBP.Instance;
|
||||||
|
public RegisterESP ESP = RegisterESP.Instance;
|
||||||
|
public RegisterESI ESI = RegisterESI.Instance;
|
||||||
|
|
||||||
public readonly Ports Port = new Ports();
|
public readonly Ports Port = new Ports();
|
||||||
public readonly Memory Memory = new Memory();
|
public readonly Memory Memory = new Memory();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue