Skip to content

Commit

Permalink
Merge pull request #566 from tgiphil/master
Browse files Browse the repository at this point in the history
WIP - x64 support
  • Loading branch information
tgiphil committed Jan 15, 2019
2 parents 9dbf5b0 + 3e9145b commit ca0f47f
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 35 deletions.
8 changes: 4 additions & 4 deletions Source/Data/X64Instructions.json
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
"OpcodeEncoding": [
{
"Condition": "[register]",
"Encoding": "[x64-rex32],opcode=0xFF,mod=11,reg=010,rm=reg3:o1,rex.r=0,rex.x=0,rex.b=reg4x:r"
"Encoding": "[x64-rex32],opcode=0xFF,mod=11,reg=010,rm=reg3:o1,rex.r=0,rex.x=0,rex.b=reg4x:o1"
},
{
"Condition": "[constant]",
Expand Down Expand Up @@ -3876,7 +3876,7 @@
"OpcodeEncoding": [
{
"Condition": "[register]",
"Encoding": "[x64-rex32],opcode=01010|reg3:r,rex.r=reg4x:r,rex.x=0,rex.b=0"
"Encoding": "[x64-rex32],opcode=01010|reg3:o1,rex.r=reg4x:o1,rex.x=0,rex.b=0"
},
{
"Condition": "[constant]",
Expand Down Expand Up @@ -4545,7 +4545,7 @@
"OpcodeEncoding": [
{
"Condition": "",
"Encoding": "[x64-rex32],operand-prefix=0x66,opcode=0x0F,opcode2=0x2E,mod=11,reg=reg3:o1,rm=reg3:o2,rex.r=reg4x:r,rex.x=0,rex.b=reg4x:o2"
"Encoding": "[x64-rex32],operand-prefix=0x66,opcode=0x0F,opcode2=0x2E,mod=11,reg=reg3:o1,rm=reg3:o2,rex.r=reg4x:o1,rex.x=0,rex.b=reg4x:o2"
}
]
},
Expand All @@ -4564,7 +4564,7 @@
"OpcodeEncoding": [
{
"Condition": "",
"Encoding": "[x64-rex32],opcode=0x0F,opcode2=0x2E,mod=11,reg=reg3:o1,rm=reg3:o2,rex.r=reg4x:r,rex.x=0,rex.b=reg4x:o2"
"Encoding": "[x64-rex32],opcode=0x0F,opcode2=0x2E,mod=11,reg=reg3:o1,rm=reg3:o2,rex.r=reg4x:o1,rex.x=0,rex.b=reg4x:o2"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected BaseRegisterAllocator(BasicBlocks basicBlocks, VirtualRegisters virtua
StackFrame = stackFrame;

VirtualRegisterCount = virtualRegisters.Count;
PhysicalRegisterCount = 16; // max for all architectures
PhysicalRegisterCount = 32; // max for all architectures
RegisterCount = VirtualRegisterCount + PhysicalRegisterCount;

LiveIntervalTracks = new List<LiveIntervalTrack>(PhysicalRegisterCount);
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/Stages/CallStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void SetReturn64(Context context)
}
else
{
context.SetInstruction(IRInstruction.MoveInt64, Operand.CreateCPURegister(TypeSystem.BuiltIn.U4, Architecture.ReturnHighRegister), context.Operand1);
context.SetInstruction(IRInstruction.MoveInt64, Operand.CreateCPURegister(TypeSystem.BuiltIn.U8, Architecture.ReturnRegister), context.Operand1);
}
}

Expand Down
18 changes: 11 additions & 7 deletions Source/Mosa.Platform.x64/Architecture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,23 +207,27 @@ public override void ExtendMethodCompilerPipeline(Pipeline<BaseMethodCompilerSta
new SimpleDeadCodeRemovalStage(),
new AddressModeConversionStage(),
new FloatingPointStage(),
new StopStage(), // Temp
});

compilerPipeline.InsertAfterLast<StackLayoutStage>(
new BuildStackStage()
);

//compilerPipeline.InsertBefore<CodeGenerationStage>(
// new BaseMethodCompilerStage[]
// {
// new FinalTweakStage(),
// compilerOptions.EnablePlatformOptimizations ? new PostOptimizationStage() : null,
// });
compilerPipeline.InsertBefore<CodeGenerationStage>(
new BaseMethodCompilerStage[]
{
new FinalTweakStage(),

//compilerOptions.EnablePlatformOptimizations ? new PostOptimizationStage() : null,
});

compilerPipeline.InsertBefore<CodeGenerationStage>(
new JumpOptimizationStage()
);

//compilerPipeline.InsertBefore<GreedyRegisterAllocatorStage>(
// new StopStage()
//);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Platform.x64/Instructions/Call.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override void Emit(InstructionNode node, BaseCodeEmitter emitter)
emitter.OpcodeEncoder.AppendBit(0b0);
emitter.OpcodeEncoder.AppendBit(0b0);
emitter.OpcodeEncoder.AppendBit(0b0);
emitter.OpcodeEncoder.AppendBit((node.Result.Register.RegisterCode >> 3) & 0x1);
emitter.OpcodeEncoder.AppendBit((node.Operand1.Register.RegisterCode >> 3) & 0x1);
emitter.OpcodeEncoder.AppendByte(0xFF);
emitter.OpcodeEncoder.Append2Bits(0b11);
emitter.OpcodeEncoder.Append3Bits(0b010);
Expand Down
4 changes: 2 additions & 2 deletions Source/Mosa.Platform.x64/Instructions/Push64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public override void Emit(InstructionNode node, BaseCodeEmitter emitter)
emitter.OpcodeEncoder.SuppressByte(0x40);
emitter.OpcodeEncoder.AppendNibble(0b0100);
emitter.OpcodeEncoder.AppendBit(0b0);
emitter.OpcodeEncoder.AppendBit((node.Result.Register.RegisterCode >> 3) & 0x1);
emitter.OpcodeEncoder.AppendBit((node.Operand1.Register.RegisterCode >> 3) & 0x1);
emitter.OpcodeEncoder.AppendBit(0b0);
emitter.OpcodeEncoder.AppendBit(0b0);
emitter.OpcodeEncoder.AppendNibble(0b0101);
emitter.OpcodeEncoder.AppendBit(0b0);
emitter.OpcodeEncoder.Append3Bits(node.Result.Register.RegisterCode);
emitter.OpcodeEncoder.Append3Bits(node.Operand1.Register.RegisterCode);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Platform.x64/Instructions/Ucomisd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override void Emit(InstructionNode node, BaseCodeEmitter emitter)
emitter.OpcodeEncoder.SuppressByte(0x40);
emitter.OpcodeEncoder.AppendNibble(0b0100);
emitter.OpcodeEncoder.AppendBit(0b0);
emitter.OpcodeEncoder.AppendBit((node.Result.Register.RegisterCode >> 3) & 0x1);
emitter.OpcodeEncoder.AppendBit((node.Operand1.Register.RegisterCode >> 3) & 0x1);
emitter.OpcodeEncoder.AppendBit(0b0);
emitter.OpcodeEncoder.AppendBit((node.Operand2.Register.RegisterCode >> 3) & 0x1);
emitter.OpcodeEncoder.AppendByte(0x0F);
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Platform.x64/Instructions/Ucomiss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override void Emit(InstructionNode node, BaseCodeEmitter emitter)
emitter.OpcodeEncoder.SuppressByte(0x40);
emitter.OpcodeEncoder.AppendNibble(0b0100);
emitter.OpcodeEncoder.AppendBit(0b0);
emitter.OpcodeEncoder.AppendBit((node.Result.Register.RegisterCode >> 3) & 0x1);
emitter.OpcodeEncoder.AppendBit((node.Operand1.Register.RegisterCode >> 3) & 0x1);
emitter.OpcodeEncoder.AppendBit(0b0);
emitter.OpcodeEncoder.AppendBit((node.Operand2.Register.RegisterCode >> 3) & 0x1);
emitter.OpcodeEncoder.AppendByte(0x0F);
Expand Down
8 changes: 8 additions & 0 deletions Source/Mosa.Platform.x64/Stages/LongOperandStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected override void PopulateVisitationDictionary()
AddVisitation(IRInstruction.ConvertInt64ToFloatR8, ConvertInt64ToFloatR8);
AddVisitation(IRInstruction.IfThenElse64, IfThenElse64);
AddVisitation(IRInstruction.LoadInt64, LoadInt64);
AddVisitation(IRInstruction.LoadSignExtend32x64, LoadSignExtend32x64);
AddVisitation(IRInstruction.LoadParamInt64, LoadParamInt64);
AddVisitation(IRInstruction.LoadParamSignExtend16x64, LoadParamSignExtend16x64);
AddVisitation(IRInstruction.LoadParamSignExtend32x64, LoadParamSignExtend32x64);
Expand Down Expand Up @@ -160,6 +161,13 @@ private void LoadInt64(InstructionNode node)
node.SetInstruction(X64.MovLoad64, node.Result, node.Operand1, node.Operand2);
}

private void LoadSignExtend32x64(InstructionNode node)
{
LoadStore.OrderLoadOperands(node, MethodCompiler);

node.SetInstruction(X64.MovzxLoad32, node.Result, node.Operand1, node.Operand2);
}

private void LoadParamInt64(InstructionNode node)
{
node.SetInstruction(X64.MovLoad64, node.Result, StackFrame, node.Operand1);
Expand Down
2 changes: 1 addition & 1 deletion Tools/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ gdb
rufus
- GNU License v3
- https://github.com/pbatard/rufus
- Version: 2.17
- Version: 3.4
Binary file removed Tools/rufus/rufus-2.17.exe
Binary file not shown.
Binary file added Tools/rufus/rufus-3.4.exe
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
########################################
How to Create a Bootable USB Flash Drive
########################################
########################
Flash Drive Installation
########################

.. warning:: These instructions maybe out of date.
While most of the development and testing of MOSA is done using virtualization software, MOSA does indeed boot on real hardware too.

While most of the development and testing of MOSA is done using virtualization software, MOSA does indeed boot on real hardware too.
Below are the steps for deploying a MOSA disk image to a USB flash drive:

Here are detailed instructions for deploying MOSA operating system to a USB flash drive:
.. warning:: These instructions may vary slightly depending on your installation.

1. Download the `dd <http://www.chrysocome.net/dd>`__ utility for Windows.
1. Create a MOSA disk image using the MOSA Launcher Tool.

2. Copy the ``dd.exe`` executable to the build directory (usually a sub-folder under temp):
2. Download the `dd <http://www.chrysocome.net/dd>`__ utility for Windows.

3. Copy the ``dd.exe`` executable to the build directory (usually a sub-folder under temp):

.. code-block:: text
%TEMP%\MOSA
3. Open a command prompt window and change directory to the build directory.
4. Open a command prompt window and change directory to the build directory.

.. code-block:: text
cd %TEMP%\MOSA
4. Connect the USB key you wish to ERASE and install the MOSA image onto.
5. Connect the USB key you wish to ERASE and install the MOSA image onto.

.. danger:: Data on the USB flash drive will be lost!

5. Determine the device path for the USB flash drive.
6. Determine the device path for the USB flash drive.

Get a list all the block devices on your system by typing the command below. Find the one for the USB flash drive you just connected. Be careful, if you select or mistype the wrong device, you can corrupt your hard drive or other storage devices. Unless you understand these steps completely, do not proceed.

.. code-block:: text
dd -list
6. Type the following and substitute the of= parameter with the device path found in the previous step.
7. Type the following and substitute the of= parameter with the device path found in the previous step.

.. code-block:: text
dd of=\\?\Device\HarddiskX\PartitionX if=bootimage.img bs=512 –progress
7. Wait until all the blocks are written to the USB key before disconnecting it.
8. Wait until all the blocks are written to the USB key before disconnecting it.

8. Now boot a PC or laptop with the USB flash drive connected!
9. Now boot a PC or laptop with the USB flash drive connected!

4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Contents

intro
faq
compiler-tool
tools
compiler-tool
boot-image-tool
bootable-usb-flash-drive
flash-drive-installation
compiler-design
tests
get-involved
Expand Down

0 comments on commit ca0f47f

Please sign in to comment.