Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin work on amd64 #71

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions source/XSharp/XSharp/Assembler/Gen1/Assembler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,29 +199,6 @@ protected void BeforeFlush()
//MergeAllElements();
}

public virtual void FlushBinary(Stream aOutput, ulong aBaseAddress)
{
BeforeFlush();
var xMax = AllAssemblerElementCount;
var xCurrentAddresss = aBaseAddress;
for (int i = 0; i < xMax; i++)
{
GetAssemblerElement(i).UpdateAddress(this, ref xCurrentAddresss);
}
aOutput.SetLength(aOutput.Length + (long) (xCurrentAddresss - aBaseAddress));
for (int i = 0; i < xMax; i++)
{
var xItem = GetAssemblerElement(i);
if (!xItem.IsComplete(this))
{
throw new Exception("Incomplete element encountered.");
}
//var xBuff = xItem.GetData(this);
//aOutput.Write(xBuff, 0, xBuff.Length);
xItem.WriteData(this, aOutput);
}
}

public virtual void FlushText(TextWriter aOutput)
{
BeforeFlush();
Expand All @@ -245,6 +222,7 @@ public virtual void FlushText(TextWriter aOutput)
aOutput.WriteLine();
}
aOutput.WriteLine();
aOutput.WriteLine("section .text");

// Write out code
for (int i = 0; i < mInstructions.Count; i++)
Expand Down
136 changes: 70 additions & 66 deletions source/XSharp/XSharp/Assembler/Gen1/x86/JumpToSegment.cs
Original file line number Diff line number Diff line change
@@ -1,66 +1,70 @@
using System;

namespace XSharp.Assembler.x86
{
[XSharp.Assembler.OpCode("jmp")]
public class JumpToSegment : Instruction {
public XSharp.Assembler.ElementReference DestinationRef {
get;
set;
}

public ushort Segment {
get;
set;
}

public override void WriteText( XSharp.Assembler.Assembler aAssembler, System.IO.TextWriter aOutput )
{
if (DestinationRef != null) {
aOutput.Write("jmp ");
aOutput.Write(Segment);
aOutput.Write(":");
aOutput.Write(DestinationRef.ToString());
} else {
aOutput.Write("jmp ");
aOutput.Write(Segment);
aOutput.Write(":0x0");
}
}

public string DestinationLabel {
get {
if (DestinationRef != null) {
return DestinationRef.Name;
}
return String.Empty;
}
set {
DestinationRef = XSharp.Assembler.ElementReference.New(value);
}
}

public override bool IsComplete( XSharp.Assembler.Assembler aAssembler )
{
ulong xAddress;
return DestinationRef == null || DestinationRef.Resolve(aAssembler, out xAddress);
}

public override void UpdateAddress(XSharp.Assembler.Assembler aAssembler, ref ulong aAddress) {
base.UpdateAddress(aAssembler, ref aAddress);
aAddress += 7;
}

//public override byte[] GetData(Assembler aAssembler) {
public override void WriteData( XSharp.Assembler.Assembler aAssembler, System.IO.Stream aOutput )
{
aOutput.WriteByte(0xEA);
ulong xAddress = 0;
if (DestinationRef != null && DestinationRef.Resolve(aAssembler, out xAddress)) {
xAddress = (ulong)(((long)xAddress) + DestinationRef.Offset);
}
aOutput.Write(BitConverter.GetBytes((uint)(xAddress)), 0, 4);
aOutput.Write(BitConverter.GetBytes(Segment), 0, 2);
}
}
}
using System;

namespace XSharp.Assembler.x86
{
[XSharp.Assembler.OpCode("jmp")]
public class JumpToSegment : Instruction {
public XSharp.Assembler.ElementReference DestinationRef {
get;
set;
}

public ushort Segment {
get;
set;
}

public JumpToSegment()
{
;
}
public override void WriteText( XSharp.Assembler.Assembler aAssembler, System.IO.TextWriter aOutput )
{
if (DestinationRef != null) {
aOutput.Write("jmp ");
aOutput.Write(Segment);
aOutput.Write(":");
aOutput.Write(DestinationRef.ToString());
} else {
aOutput.Write("jmp ");
aOutput.Write(Segment);
aOutput.Write(":0x0");
}
}

public string DestinationLabel {
get {
if (DestinationRef != null) {
return DestinationRef.Name;
}
return String.Empty;
}
set {
DestinationRef = XSharp.Assembler.ElementReference.New(value);
}
}

public override bool IsComplete( XSharp.Assembler.Assembler aAssembler )
{
ulong xAddress;
return DestinationRef == null || DestinationRef.Resolve(aAssembler, out xAddress);
}

public override void UpdateAddress(XSharp.Assembler.Assembler aAssembler, ref ulong aAddress) {
base.UpdateAddress(aAssembler, ref aAddress);
aAddress += 7;
}

//public override byte[] GetData(Assembler aAssembler) {
public override void WriteData( XSharp.Assembler.Assembler aAssembler, System.IO.Stream aOutput )
{
aOutput.WriteByte(0xEA);
ulong xAddress = 0;
if (DestinationRef != null && DestinationRef.Resolve(aAssembler, out xAddress)) {
xAddress = (ulong)(((long)xAddress) + DestinationRef.Offset);
}
aOutput.Write(BitConverter.GetBytes((uint)(xAddress)), 0, 4);
aOutput.Write(BitConverter.GetBytes(Segment), 0, 2);
}
}
}
20 changes: 10 additions & 10 deletions source/XSharp/XSharp/Assembler/Gen1/x86/Push.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace XSharp.Assembler.x86
{
[XSharp.Assembler.OpCode("push")]
public class Push : InstructionWithDestinationAndSize {

public Push():base("push") {
Size = 32;
}
}
}
namespace XSharp.Assembler.x86
{
[XSharp.Assembler.OpCode("push")]
public class Push : InstructionWithDestinationAndSize {
public Push():base("push") {
Size = 64;
}
}
}
Loading
Loading