public int Generate(string aInputFilePath, string aInputFileContents, string aDefaultNamespace, IntPtr[] aOutputFileContents, out uint oPcbOutput, IVsGeneratorProgress aGenerateProgress)
        {
            string xResult;

            using (var xInput = new StringReader(aInputFileContents)) {
                using (var xOut = new StringWriter()) {
                    try
                    {
                        new Assembler();
                        try
                        {
                            var xGen = new XSharp.Compiler.AsmGenerator();
                            xGen.Generate(xInput, xOut);
                            xResult =
                                "; Generated at " + DateTime.Now.ToString() + "\r\n"
                                + "\r\n"
                                + xOut.ToString() + "\r\n";
                        }
                        finally
                        {
                            Assembler.ClearCurrentInstance();
                        }
                    } catch (Exception ex) {
                        var xSB = new StringBuilder();
                        xSB.Append(xOut);
                        xSB.AppendLine();

                        for (Exception e = ex; e != null; e = e.InnerException)
                        {
                            xSB.AppendLine(e.Message);
                        }
                        xResult = xSB.ToString();
                    }
                }
            }

            aOutputFileContents[0] = IntPtr.Zero;
            oPcbOutput             = 0;
            var xBytes = Encoding.UTF8.GetBytes(xResult);

            if (xBytes.Length > 0)
            {
                aOutputFileContents[0] = Marshal.AllocCoTaskMem(xBytes.Length);
                Marshal.Copy(xBytes, 0, aOutputFileContents[0], xBytes.Length);
                oPcbOutput = (uint)xBytes.Length;
            }

            return(VSConstants.S_OK);
        }
    public int Generate(string aInputFilePath, string aInputFileContents, string aDefaultNamespace, IntPtr[] aOutputFileContents, out uint oPcbOutput, IVsGeneratorProgress aGenerateProgress) {
      string xResult;
      using (var xInput = new StringReader(aInputFileContents)) {
        using (var xOut = new StringWriter()) {
            try
            {
              new Assembler();
              try
              {
                var xGen = new XSharp.Compiler.AsmGenerator();
                xGen.Generate(xInput, xOut);
                xResult =
                  "; Generated at " + DateTime.Now.ToString() + "\r\n"
                  + "\r\n"
                  + xOut.ToString() + "\r\n";
              }
              finally
              {
                Assembler.ClearCurrentInstance();
              }
            } catch (Exception ex) {
              var xSB = new StringBuilder();
              xSB.Append(xOut);
              xSB.AppendLine();

              for (Exception e = ex; e != null; e = e.InnerException) {
                xSB.AppendLine(e.Message);
              }
              xResult = xSB.ToString();
            }
          }
      }

      aOutputFileContents[0] = IntPtr.Zero;
      oPcbOutput = 0;
      var xBytes = Encoding.UTF8.GetBytes(xResult);
      if (xBytes.Length > 0) {
        aOutputFileContents[0] = Marshal.AllocCoTaskMem(xBytes.Length);
        Marshal.Copy(xBytes, 0, aOutputFileContents[0], xBytes.Length);
        oPcbOutput = (uint)xBytes.Length;
      }

      return VSConstants.S_OK;
    }
示例#3
0
        protected void Test(string aFilename)
        {
            tabsMain.TabPages.Add(Path.GetFileNameWithoutExtension(aFilename));
            var xTab = tabsMain.TabPages[tabsMain.TabPages.Count - 1];

            var xTbox = new TextBox();

            xTab.Controls.Add(xTbox);
            xTbox.Dock       = DockStyle.Fill;
            xTbox.Multiline  = true;
            xTbox.Font       = new Font("Consolas", 12);
            xTbox.ScrollBars = ScrollBars.Both;

            using (var xInput = new StreamReader(aFilename)) {
                using (var xOutput = new StringWriter()) {
                    try {
                        var xGenerator = new XSharp.Compiler.AsmGenerator();

                        xOutput.WriteLine("ORIGIN:");
                        xGenerator.Generate(xInput, xOutput);
                        if (Compile)
                        {
                            if (null == _nasmPath)
                            {
                                xOutput.WriteLine("Can't compile. NASM not found.");
                            }
                            else
                            {
                                FileInfo inputFile        = new FileInfo(Path.GetTempFileName());
                                bool     compilationError = false;

                                try
                                {
                                    // UTF8 stream without a BOM.
                                    using (StreamWriter writer = new StreamWriter(inputFile.FullName, true))
                                    {
                                        writer.WriteLine(xOutput.ToString());
                                    }
                                    xOutput.WriteLine("============================");
                                    xOutput.WriteLine("Compiling");
                                    compilationError = !LaunchNasm(inputFile.FullName, xOutput);
                                    if (compilationError)
                                    {
                                        xOutput.WriteLine("Some compilation error.");
                                    }
                                    else
                                    {
                                        xOutput.WriteLine("Successfully compiled.");
                                    }
                                }
                                finally
                                {
                                    inputFile.Refresh();
                                    if (!compilationError && inputFile.Exists)
                                    {
                                        inputFile.Delete();
                                    }
                                }
                            }
                        }
                        xTbox.Text = xOutput.ToString() + "\r\n" + xOutput.ToString();
                    } catch (Exception ex) {
                        xTab.Text = "* " + xTab.Text;
                        StringBuilder builder = new StringBuilder();

                        builder.AppendLine(xOutput.ToString());
                        Exception innerMostException = null;
                        for (Exception e = ex; null != e; e = e.InnerException)
                        {
                            builder.AppendLine(e.Message);
                            innerMostException = e;
                        }
                        if (null != innerMostException)
                        {
                            builder.AppendLine(innerMostException.StackTrace);
                        }
                        xTbox.Text = builder.ToString();
                    }
                }
            }
        }
示例#4
0
        public void Initialize()
        {
            uint xSig = 0x1BADB002;

            DataMembers.Add(new DataIfNotDefined("ELF_COMPILATION"));
            DataMembers.Add(new DataMember("MultibootSignature", new uint[] { xSig }));
            uint xFlags = 0x10003;

            DataMembers.Add(new DataMember("MultibootFlags", xFlags));
            DataMembers.Add(new DataMember("MultibootChecksum", (int)(0 - (xFlags + xSig))));
            DataMembers.Add(new DataMember("MultibootHeaderAddr", Cosmos.Assembler.ElementReference.New("MultibootSignature")));
            DataMembers.Add(new DataMember("MultibootLoadAddr", Cosmos.Assembler.ElementReference.New("MultibootSignature")));
            DataMembers.Add(new DataMember("MultibootLoadEndAddr", Cosmos.Assembler.ElementReference.New("_end_code")));
            DataMembers.Add(new DataMember("MultibootBSSEndAddr", Cosmos.Assembler.ElementReference.New("_end_code")));
            DataMembers.Add(new DataMember("MultibootEntryAddr", Cosmos.Assembler.ElementReference.New("Kernel_Start")));
            DataMembers.Add(new DataEndIfDefined());

            DataMembers.Add(new DataIfDefined("ELF_COMPILATION"));
            xFlags = 0x00003;
            DataMembers.Add(new DataMember("MultibootSignature", new uint[] { xSig }));
            DataMembers.Add(new DataMember("MultibootFlags", xFlags));
            DataMembers.Add(new DataMember("MultibootChecksum", (int)(0 - (xFlags + xSig))));
            DataMembers.Add(new DataEndIfDefined());

            // graphics info fields
            DataMembers.Add(new DataMember("MultibootGraphicsRuntime_VbeModeInfoAddr", Int32.MaxValue));
            DataMembers.Add(new DataMember("MultibootGraphicsRuntime_VbeControlInfoAddr", Int32.MaxValue));
            DataMembers.Add(new DataMember("MultibootGraphicsRuntime_VbeMode", Int32.MaxValue));
            // memory
            DataMembers.Add(new DataMember("MultiBootInfo_Memory_High", 0));
            DataMembers.Add(new DataMember("MultiBootInfo_Memory_Low", 0));
            DataMembers.Add(new DataMember("Before_Kernel_Stack", new byte[0x50000]));
            DataMembers.Add(new DataMember("Kernel_Stack", new byte[0]));
            DataMembers.Add(new DataMember("MultiBootInfo_Structure", new uint[1]));

            if (mComPort > 0)
            {
                new Define("DEBUGSTUB");
            }

            // This is our first entry point. Multiboot uses this as Cosmos entry point.
            new Label("Kernel_Start", isGlobal: true);
            new Mov
            {
                DestinationReg = Registers.ESP,
                SourceRef      = Cosmos.Assembler.ElementReference.New("Kernel_Stack")
            };

            // Displays "Cosmos" in top left. Used to make sure Cosmos is booted in case of hang.
            // ie bootloader debugging. This must be the FIRST code, even before setup so we know
            // we are being called properly by the bootloader and that if there are problems its
            // somwhere in our code, not the bootloader.
            WriteDebugVideo("Cosmos pre boot");

            // For when using Bochs, causes a break ASAP on entry after initial Cosmos display.
            new LiteralAssemblerCode("xchg bx, bx");

            // CLI ASAP
            WriteDebugVideo("Clearing interrupts.");
            new ClrInterruptFlag();


            WriteDebugVideo("Begin multiboot info.");
            new LiteralAssemblerCode("%ifndef EXCLUDE_MULTIBOOT_MAGIC");
            new Comment(this, "MultiBoot compliant loader provides info in registers: ");
            new Comment(this, "EBX=multiboot_info ");
            new Comment(this, "EAX=0x2BADB002 - check if it's really Multiboot-compliant loader ");
            new Comment(this, "                ;- copy mb info - some stuff for you  ");
            new Comment(this, "BEGIN - Multiboot Info");
            new Mov {
                DestinationRef = Cosmos.Assembler.ElementReference.New("MultiBootInfo_Structure"), DestinationIsIndirect = true, SourceReg = Registers.EBX
            };
            new Add {
                DestinationReg = Registers.EBX, SourceValue = 4
            };
            new Mov {
                DestinationReg = Registers.EAX, SourceReg = Registers.EBX, SourceIsIndirect = true
            };
            new Mov {
                DestinationRef = Cosmos.Assembler.ElementReference.New("MultiBootInfo_Memory_Low"), DestinationIsIndirect = true, SourceReg = Registers.EAX
            };
            new Add {
                DestinationReg = Registers.EBX, SourceValue = 4
            };
            new Mov {
                DestinationReg   = Registers.EAX,
                SourceReg        = Registers.EBX,
                SourceIsIndirect = true
            };
            new Mov {
                DestinationRef = Cosmos.Assembler.ElementReference.New("MultiBootInfo_Memory_High"), DestinationIsIndirect = true, SourceReg = Registers.EAX
            };
            new Comment(this, "END - Multiboot Info");
            new LiteralAssemblerCode("%endif");
            WriteDebugVideo("Creating GDT.");
            CreateGDT();

            WriteDebugVideo("Creating IDT.");
            CreateIDT();
#if LFB_1024_8
            new Comment("Set graphics fields");
            new Move {
                DestinationReg = Registers.EBX, SourceRef = Cosmos.Assembler.ElementReference.New("MultiBootInfo_Structure"), SourceIsIndirect = true
            };
            new Move {
                DestinationReg = Registers.EAX, SourceReg = Registers.EBX, SourceIsIndirect = true, SourceDisplacement = 72
            };
            new Move {
                DestinationRef = Cosmos.Assembler.ElementReference.New("MultibootGraphicsRuntime_VbeControlInfoAddr"), DestinationIsIndirect = true, SourceReg = Registers.EAX
            };
            new Move {
                DestinationReg = Registers.EAX, SourceReg = Registers.EBX, SourceIsIndirect = true, SourceDisplacement = 76
            };
            new Move {
                DestinationRef = Cosmos.Assembler.ElementReference.New("MultibootGraphicsRuntime_VbeModeInfoAddr"), DestinationIsIndirect = true, SourceReg = Registers.EAX
            };
            new Move {
                DestinationReg = Registers.EAX, SourceReg = Registers.EBX, SourceIsIndirect = true, SourceDisplacement = 80
            };
            new Move {
                DestinationRef = Cosmos.Assembler.ElementReference.New("MultibootGraphicsRuntime_VbeMode"), DestinationIsIndirect = true, SourceReg = Registers.EAX
            };
#endif

            //WriteDebugVideo("Initializing SSE.");
            //new Comment(this, "BEGIN - SSE Init");
            //// CR4[bit 9]=1, CR4[bit 10]=1, CR0[bit 2]=0, CR0[bit 1]=1
            //new Mov { DestinationReg = Registers.EAX, SourceReg = Registers.CR4 };
            //new Or { DestinationReg = Registers.EAX, SourceValue = 0x100 };
            //new Mov { DestinationReg = Registers.CR4, SourceReg = Registers.EAX };
            //new Mov { DestinationReg = Registers.EAX, SourceReg = Registers.CR4 };
            //new Or { DestinationReg = Registers.EAX, SourceValue = 0x200 };
            //new Mov { DestinationReg = Registers.CR4, SourceReg = Registers.EAX };
            //new Mov { DestinationReg = Registers.EAX, SourceReg = Registers.CR0 };

            //new And { DestinationReg = Registers.EAX, SourceValue = 0xfffffffd };
            //new Mov { DestinationReg = Registers.CR0, SourceReg = Registers.EAX };
            //new Mov { DestinationReg = Registers.EAX, SourceReg = Registers.CR0 };

            //new And { DestinationReg = Registers.EAX, SourceValue = 1 };
            //new Mov { DestinationReg = Registers.CR0, SourceReg = Registers.EAX };
            //new Comment(this, "END - SSE Init");

            if (mComPort > 0)
            {
                WriteDebugVideo("Initializing DebugStub.");
                new Call {
                    DestinationLabel = "DebugStub_Init"
                };
            }

            // Jump to Kernel entry point
            WriteDebugVideo("Jumping to kernel.");
            new Call {
                DestinationLabel = EntryPointName
            };

            new Comment(this, "Kernel done - loop till next IRQ");
            new Label(".loop");
            new ClrInterruptFlag();
            new Halt();
            new Jump {
                DestinationLabel = ".loop"
            };

            if (mComPort > 0)
            {
                var xGen = new XSharp.Compiler.AsmGenerator();

                var xGenerateAssembler =
                    new Action <object>(i =>
                {
                    XSharp.Nasm.Assembler xAsm;
                    if (i is StreamReader)
                    {
                        xAsm = xGen.Generate((StreamReader)i);
                    }
                    else if (i is string)
                    {
                        xAsm = xGen.Generate((string)i);
                    }
                    else
                    {
                        throw new Exception("Object type '" + i.ToString() + "' not supported!");
                    }
                    foreach (var xData in xAsm.Data)
                    {
                        Cosmos.Assembler.Assembler.CurrentInstance.DataMembers.Add(new DataMember()
                        {
                            RawAsm = xData
                        });
                    }
                    foreach (var xCode in xAsm.Code)
                    {
                        new LiteralAssemblerCode(xCode);
                    }
                });
                if (ReadDebugStubFromDisk)
                {
                    foreach (var xFile in Directory.GetFiles(Cosmos.Build.Common.CosmosPaths.DebugStubSrc, "*.xs"))
                    {
                        xGenerateAssembler(xFile);
                    }
                }
                else
                {
                    foreach (var xManifestName in typeof(ReferenceHelper).Assembly.GetManifestResourceNames())
                    {
                        if (!xManifestName.EndsWith(".xs", StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                        using (var xStream = typeof(ReferenceHelper).Assembly.GetManifestResourceStream(xManifestName))
                        {
                            using (var xReader = new StreamReader(xStream))
                            {
                                xGenerateAssembler(xReader);
                            }
                        }
                    }
                }
                OnAfterEmitDebugStub();
            }
            else
            {
                new Label("DebugStub_Step");
                new Return();
            }
            // Start emitting assembly labels
            Cosmos.Assembler.Assembler.CurrentInstance.EmitAsmLabels = true;
        }
示例#5
0
文件: MainForm.cs 项目: Orvid/Cosmos
    protected void Test(string aFilename) {
      tabsMain.TabPages.Add(Path.GetFileNameWithoutExtension(aFilename));
      var xTab = tabsMain.TabPages[tabsMain.TabPages.Count - 1];

      var xTbox = new TextBox();
      xTab.Controls.Add(xTbox);
      xTbox.Dock = DockStyle.Fill;
      xTbox.Multiline = true;
      xTbox.Font = new Font("Consolas", 12);
      xTbox.ScrollBars = ScrollBars.Both;

      using (var xInput = new StreamReader(aFilename)) {
        using (var xOutputCode = new StringWriter()) {
          using (var xOutputData = new StringWriter()) {
            try {
              var xGenerator = new XSharp.Compiler.AsmGenerator();

              xOutputData.WriteLine("ORIGIN:");
              xGenerator.Generate(xInput, xOutputData, xOutputCode);
              if (Compile)
              {
                  if (null == _nasmPath)
                  {
                      xOutputCode.WriteLine("Can't compile. NASM not found.");
                  }
                  else
                  {
                      FileInfo inputFile = new FileInfo(Path.GetTempFileName());
                      bool compilationError = false;

                      try
                      {
                          // UTF8 stream without a BOM.
                          using (StreamWriter writer = new StreamWriter(inputFile.FullName, true))
                          {
                              writer.WriteLine(xOutputData.ToString());
                              writer.WriteLine(xOutputCode.ToString());
                          }
                          xOutputCode.WriteLine("============================");
                          xOutputCode.WriteLine("Compiling");
                          compilationError = !LaunchNasm(inputFile.FullName, xOutputCode);
                          if (compilationError) { xOutputCode.WriteLine("Some compilation error."); }
                          else { xOutputCode.WriteLine("Successfully compiled."); }
                      }
                      finally
                      {
                          inputFile.Refresh();
                          if (!compilationError && inputFile.Exists) { inputFile.Delete(); }
                      }
                  }
              }
              xTbox.Text = xOutputData.ToString() + "\r\n" + xOutputCode.ToString();
            } catch (Exception ex) {
              xTab.Text = "* " + xTab.Text;
              StringBuilder builder = new StringBuilder();

              builder.AppendLine(xOutputData.ToString());
              builder.AppendLine(xOutputCode.ToString());
              Exception innerMostException = null;
              for (Exception e = ex; null != e; e = e.InnerException)
              {
                  builder.AppendLine(e.Message);
                  innerMostException = e;
              }
              if (null != innerMostException)
              {
                  builder.AppendLine(innerMostException.StackTrace);
              }
              xTbox.Text = builder.ToString();
            }
          }
        }
      }
    }
示例#6
0
    public void Initialize() {
      uint xSig = 0x1BADB002;

      DataMembers.Add(new DataIfNotDefined("ELF_COMPILATION"));
      DataMembers.Add(new DataMember("MultibootSignature", new uint[] { xSig }));
      uint xFlags = 0x10003;
      DataMembers.Add(new DataMember("MultibootFlags", xFlags));
      DataMembers.Add(new DataMember("MultibootChecksum", (int)(0 - (xFlags + xSig))));
      DataMembers.Add(new DataMember("MultibootHeaderAddr", Cosmos.Assembler.ElementReference.New("MultibootSignature")));
      DataMembers.Add(new DataMember("MultibootLoadAddr", Cosmos.Assembler.ElementReference.New("MultibootSignature")));
      DataMembers.Add(new DataMember("MultibootLoadEndAddr", Cosmos.Assembler.ElementReference.New("_end_code")));
      DataMembers.Add(new DataMember("MultibootBSSEndAddr", Cosmos.Assembler.ElementReference.New("_end_code")));
      DataMembers.Add(new DataMember("MultibootEntryAddr", Cosmos.Assembler.ElementReference.New("Kernel_Start")));
      DataMembers.Add(new DataEndIfDefined());

      DataMembers.Add(new DataIfDefined("ELF_COMPILATION"));
      xFlags = 0x00003;
      DataMembers.Add(new DataMember("MultibootSignature", new uint[] { xSig }));
      DataMembers.Add(new DataMember("MultibootFlags", xFlags));
      DataMembers.Add(new DataMember("MultibootChecksum", (int)(0 - (xFlags + xSig))));
      DataMembers.Add(new DataEndIfDefined());

      // graphics info fields
      DataMembers.Add(new DataMember("MultibootGraphicsRuntime_VbeModeInfoAddr", Int32.MaxValue));
      DataMembers.Add(new DataMember("MultibootGraphicsRuntime_VbeControlInfoAddr", Int32.MaxValue));
      DataMembers.Add(new DataMember("MultibootGraphicsRuntime_VbeMode", Int32.MaxValue));
      // memory
      DataMembers.Add(new DataMember("MultiBootInfo_Memory_High", 0));
      DataMembers.Add(new DataMember("MultiBootInfo_Memory_Low", 0));
      DataMembers.Add(new DataMember("Before_Kernel_Stack", new byte[0x50000]));
      DataMembers.Add(new DataMember("Kernel_Stack", new byte[0]));
      DataMembers.Add(new DataMember("MultiBootInfo_Structure", new uint[1]));

      if (mComPort > 0) {
        new Define("DEBUGSTUB");
      }

      // This is our first entry point. Multiboot uses this as Cosmos entry point.
      new Label("Kernel_Start", isGlobal: true);
      new Mov
      {
        DestinationReg = Registers.ESP,
        SourceRef = Cosmos.Assembler.ElementReference.New("Kernel_Stack")
      };

      // Displays "Cosmos" in top left. Used to make sure Cosmos is booted in case of hang.
      // ie bootloader debugging. This must be the FIRST code, even before setup so we know
      // we are being called properly by the bootloader and that if there are problems its
      // somwhere in our code, not the bootloader.
      WriteDebugVideo("Cosmos pre boot");

      // For when using Bochs, causes a break ASAP on entry after initial Cosmos display.
      new LiteralAssemblerCode("xchg bx, bx");

      // CLI ASAP
      WriteDebugVideo("Clearing interrupts.");
      new ClrInterruptFlag();


      WriteDebugVideo("Begin multiboot info.");
      new LiteralAssemblerCode("%ifndef EXCLUDE_MULTIBOOT_MAGIC");
      new Comment(this, "MultiBoot compliant loader provides info in registers: ");
      new Comment(this, "EBX=multiboot_info ");
      new Comment(this, "EAX=0x2BADB002 - check if it's really Multiboot-compliant loader ");
      new Comment(this, "                ;- copy mb info - some stuff for you  ");
      new Comment(this, "BEGIN - Multiboot Info");
      new Mov { DestinationRef = Cosmos.Assembler.ElementReference.New("MultiBootInfo_Structure"), DestinationIsIndirect = true, SourceReg = Registers.EBX };
      new Add { DestinationReg = Registers.EBX, SourceValue = 4 };
      new Mov { DestinationReg = Registers.EAX, SourceReg = Registers.EBX, SourceIsIndirect = true };
      new Mov { DestinationRef = Cosmos.Assembler.ElementReference.New("MultiBootInfo_Memory_Low"), DestinationIsIndirect = true, SourceReg = Registers.EAX };
      new Add { DestinationReg = Registers.EBX, SourceValue = 4 };
      new Mov {
        DestinationReg = Registers.EAX,
        SourceReg = Registers.EBX,
        SourceIsIndirect = true
      };
      new Mov { DestinationRef = Cosmos.Assembler.ElementReference.New("MultiBootInfo_Memory_High"), DestinationIsIndirect = true, SourceReg = Registers.EAX };
      new Comment(this, "END - Multiboot Info");
      new LiteralAssemblerCode("%endif");
      WriteDebugVideo("Creating GDT.");
      CreateGDT();

      WriteDebugVideo("Creating IDT.");
      CreateIDT();
#if LFB_1024_8
            new Comment("Set graphics fields");
            new Move { DestinationReg = Registers.EBX, SourceRef = Cosmos.Assembler.ElementReference.New("MultiBootInfo_Structure"), SourceIsIndirect = true };
            new Move { DestinationReg = Registers.EAX, SourceReg = Registers.EBX, SourceIsIndirect = true, SourceDisplacement = 72 };
            new Move { DestinationRef = Cosmos.Assembler.ElementReference.New("MultibootGraphicsRuntime_VbeControlInfoAddr"), DestinationIsIndirect = true, SourceReg = Registers.EAX };
            new Move { DestinationReg = Registers.EAX, SourceReg = Registers.EBX, SourceIsIndirect = true, SourceDisplacement = 76 };
            new Move { DestinationRef = Cosmos.Assembler.ElementReference.New("MultibootGraphicsRuntime_VbeModeInfoAddr"), DestinationIsIndirect = true, SourceReg = Registers.EAX };
            new Move { DestinationReg = Registers.EAX, SourceReg = Registers.EBX, SourceIsIndirect = true, SourceDisplacement = 80 };
            new Move { DestinationRef = Cosmos.Assembler.ElementReference.New("MultibootGraphicsRuntime_VbeMode"), DestinationIsIndirect = true, SourceReg = Registers.EAX };
#endif

      //WriteDebugVideo("Initializing SSE.");
      //new Comment(this, "BEGIN - SSE Init");
      //// CR4[bit 9]=1, CR4[bit 10]=1, CR0[bit 2]=0, CR0[bit 1]=1
      //new Mov { DestinationReg = Registers.EAX, SourceReg = Registers.CR4 };
      //new Or { DestinationReg = Registers.EAX, SourceValue = 0x100 };
      //new Mov { DestinationReg = Registers.CR4, SourceReg = Registers.EAX };
      //new Mov { DestinationReg = Registers.EAX, SourceReg = Registers.CR4 };
      //new Or { DestinationReg = Registers.EAX, SourceValue = 0x200 };
      //new Mov { DestinationReg = Registers.CR4, SourceReg = Registers.EAX };
      //new Mov { DestinationReg = Registers.EAX, SourceReg = Registers.CR0 };

      //new And { DestinationReg = Registers.EAX, SourceValue = 0xfffffffd };
      //new Mov { DestinationReg = Registers.CR0, SourceReg = Registers.EAX };
      //new Mov { DestinationReg = Registers.EAX, SourceReg = Registers.CR0 };

      //new And { DestinationReg = Registers.EAX, SourceValue = 1 };
      //new Mov { DestinationReg = Registers.CR0, SourceReg = Registers.EAX };
      //new Comment(this, "END - SSE Init");

      if (mComPort > 0) {
        WriteDebugVideo("Initializing DebugStub.");
        new Call { DestinationLabel = "DebugStub_Init" };
      }

      // Jump to Kernel entry point
      WriteDebugVideo("Jumping to kernel.");
      new Call { DestinationLabel = EntryPointName };

      new Comment(this, "Kernel done - loop till next IRQ");
      new Label(".loop");
      new ClrInterruptFlag();
      new Halt();
      new Jump { DestinationLabel = ".loop" };

      if (mComPort > 0) {
        var xGen = new XSharp.Compiler.AsmGenerator();

        var xGenerateAssembler =
          new Action<object>(i =>
                             {
                               XSharp.Nasm.Assembler xAsm;
                               if (i is StreamReader)
                               {
                                 xAsm = xGen.Generate((StreamReader)i);
                               }
                               else if (i is string)
                               {
                                 xAsm = xGen.Generate((string)i);
                               }
                               else
                               {
                                 throw new Exception("Object type '" + i.ToString() + "' not supported!");
                               }
                               foreach (var xData in xAsm.Data)
                               {
                                 Cosmos.Assembler.Assembler.CurrentInstance.DataMembers.Add(new DataMember() {RawAsm = xData});
                               }
                               foreach (var xCode in xAsm.Code)
                               {
                                 new LiteralAssemblerCode(xCode);
                               }
                             });
        if (ReadDebugStubFromDisk)
        {
          foreach (var xFile in Directory.GetFiles(Cosmos.Build.Common.CosmosPaths.DebugStubSrc, "*.xs"))
          {
            xGenerateAssembler(xFile);
          }
        }
        else
        {
          foreach (var xManifestName in typeof(ReferenceHelper).Assembly.GetManifestResourceNames())
          {
            if (!xManifestName.EndsWith(".xs", StringComparison.OrdinalIgnoreCase))
            {
              continue;
            }
            using (var xStream = typeof(ReferenceHelper).Assembly.GetManifestResourceStream(xManifestName))
            {
              using (var xReader = new StreamReader(xStream))
              {
                xGenerateAssembler(xReader);
              }
            }
          }
        }
        OnAfterEmitDebugStub();
      } else {
        new Label("DebugStub_Step");
        new Return();
      }
      // Start emitting assembly labels
      Cosmos.Assembler.Assembler.CurrentInstance.EmitAsmLabels = true;
    }