From f9a421df122aedc7e30e10e4bdeecb8ce2e9138d Mon Sep 17 00:00:00 2001
From: mterwoord_cp <7cd3fd84a0151ea055c2f79e4d2eef9576fe9afesxUZAwxD>
Date: Mon, 29 Oct 2007 10:04:17 +0000
Subject: [PATCH] Misc changes
---
source/Cosmos.Kernel/ConsoleDrv.cs | 2 +-
source/Cosmos.Kernel/Cosmos.Kernel.csproj | 2 +-
.../NativeOpCodeMap.cs | 62 ++++++++++++++++-
.../RuntimeEngineImpl.cs | 18 ++---
.../RuntimeEngineImpl/GDT.cs | 69 ++++++++++++++++++-
.../Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs | 2 +-
source/Indy.IL2CPU/Engine.cs | 19 +++--
source/Indy.IL2CPU/VTablesImplRefs.cs | 9 +--
8 files changed, 161 insertions(+), 22 deletions(-)
diff --git a/source/Cosmos.Kernel/ConsoleDrv.cs b/source/Cosmos.Kernel/ConsoleDrv.cs
index 44eb66531..98315575a 100644
--- a/source/Cosmos.Kernel/ConsoleDrv.cs
+++ b/source/Cosmos.Kernel/ConsoleDrv.cs
@@ -1,5 +1,5 @@
using System;
-using Indy.IL2CPU.NativeX86.Utilities.BIOS;
+
namespace Cosmos.Kernel {
class ConsoleDrv {
diff --git a/source/Cosmos.Kernel/Cosmos.Kernel.csproj b/source/Cosmos.Kernel/Cosmos.Kernel.csproj
index 253086662..363137eaf 100644
--- a/source/Cosmos.Kernel/Cosmos.Kernel.csproj
+++ b/source/Cosmos.Kernel/Cosmos.Kernel.csproj
@@ -55,7 +55,7 @@
-
+
{BB58FFC3-A532-45BA-AAB2-28EB0451C2A1}
Cosmos.Kernel.Boot
diff --git a/source/Indy.IL2CPU.IL.X86.Native/NativeOpCodeMap.cs b/source/Indy.IL2CPU.IL.X86.Native/NativeOpCodeMap.cs
index 7c511538a..7b338dd9b 100644
--- a/source/Indy.IL2CPU.IL.X86.Native/NativeOpCodeMap.cs
+++ b/source/Indy.IL2CPU.IL.X86.Native/NativeOpCodeMap.cs
@@ -65,6 +65,13 @@ namespace Indy.IL2CPU.IL.X86.Native {
case "System_Void___Indy_IL2CPU_IL_X86_Native_RuntimeEngineImpl_IDT_RegisterIDT____": {
return true;
}
+ case "System_Void___Indy_IL2CPU_IL_X86_Native_RuntimeEngineImpl_GDT_LoadArray____": {
+ return true;
+ }
+ case "System_Void___Indy_IL2CPU_IL_X86_Native_RuntimeEngineImpl_GDT_RegisterGDT____": {
+ return true;
+ }
+
case "System_Void___System_Diagnostics_Debugger_Break____": {
return true;
}
@@ -98,6 +105,14 @@ namespace Indy.IL2CPU.IL.X86.Native {
DoAssemble_IDT_RegisterIDT(aAssembler, aMethodInfo);
return;
}
+ case "System_Void___Indy_IL2CPU_IL_X86_Native_RuntimeEngineImpl_GDT_LoadArray____": {
+ DoAssemble_GDT_LoadArray(aAssembler, aMethodInfo);
+ return;
+ }
+ case "System_Void___Indy_IL2CPU_IL_X86_Native_RuntimeEngineImpl_GDT_RegisterGDT____": {
+ DoAssemble_GDT_RegisterGDT(aAssembler, aMethodInfo);
+ return;
+ }
case "System_Void___System_Diagnostics_Debugger_Break____": {
//aAssembler.Add(new Literal("xchg bx, bx"));
return;
@@ -142,8 +157,52 @@ namespace Indy.IL2CPU.IL.X86.Native {
aAssembler.Add(new CPUNative.Sti());
}
+ private void DoAssemble_GDT_RegisterGDT(Assembler.Assembler aAssembler, MethodInformation aInfo) {
+ TypeDefinition xRuntimeEngineTypeDef = Engine.GetTypeDefinition(typeof(RuntimeEngineImpl).Assembly.GetName().Name, typeof(RuntimeEngineImpl).FullName);
+ FieldDefinition xFieldDef = xRuntimeEngineTypeDef.Fields.GetField("mGDTPointer");
+ string xPointerFieldName;
+ Engine.QueueStaticField(xFieldDef, out xPointerFieldName);
+ aAssembler.Add(new CPU.Move("eax", xPointerFieldName));
+ //aAssembler.Add(new Literal("XCHG BX, BX "));
+ aAssembler.Add(new CPUNative.Cli());
+ aAssembler.Add(new CPUNative.Lgdt("eax"));
+ aAssembler.Add(new CPU.Move("eax", "0x8"));
+ //aAssembler.Add(new CPU.Move("ds", "ax"));
+ //aAssembler.Add(new CPU.Move("es", "ax"));
+ //aAssembler.Add(new CPU.Move("fs", "ax"));
+ //aAssembler.Add(new CPU.Move("gs", "ax"));
+ //aAssembler.Add(new CPU.Move("ss", "ax"));
+ aAssembler.Add(new CPU.JumpAlways("0x0008:flush____gdt______table"));
+ aAssembler.Add(new Label("flush____gdt______table"));
+ //aAssembler.Add(new CPUNative.Sti());
+ }
+
+
private string mIDTSetHandlerMethodName;
+ private void DoAssemble_GDT_LoadArray(Assembler.Assembler aAssembler, MethodInformation aMethodInfo) {
+ TypeDefinition xRuntimeEngineTypeDef = Engine.GetTypeDefinition(typeof(RuntimeEngineImpl).Assembly.GetName().Name, typeof(RuntimeEngineImpl).FullName);
+ FieldDefinition xFieldDef = xRuntimeEngineTypeDef.Fields.GetField("mGDTEntries");
+ string xFieldName = Assembler.DataMember.GetStaticFieldName(xFieldDef);
+ string xFieldData = "0,0,0,0,2,0,0,0,1,0,0,0";
+ for (int i = 0; i < 3; i++) {
+ xFieldData += ",0,0,0,0,0,0,0,0";
+ }
+ aAssembler.DataMembers.RemoveAll(delegate(DataMember aItem) {
+ return aItem.Name == xFieldName;
+ });
+ aAssembler.DataMembers.Add(new DataMember(xFieldName, "dd", xFieldName));
+ aAssembler.DataMembers.Add(new DataMember(xFieldName + "___Contents", "db", xFieldData));
+ xFieldDef = xRuntimeEngineTypeDef.Fields.GetField("mGDTPointer");
+ string xPointerFieldName;
+ Engine.QueueStaticField(xFieldDef, out xPointerFieldName);
+ aAssembler.Add(new CPU.Move("eax", xPointerFieldName));
+ aAssembler.Add(new CPU.Move("word [eax]", "0x" + ((8 * 3) - 1).ToString("X")));
+ aAssembler.Add(new CPU.Move("ecx", xFieldName));
+ aAssembler.Add(new CPU.Add("ecx", "0xC"));
+ aAssembler.Add(new CPU.Move("dword [eax + 2]", "ecx"));
+ }
+
private void DoAssemble_IDT_LoadArray(Indy.IL2CPU.Assembler.Assembler aAssembler, MethodInformation aMethodInfo) {
//aAssembler.Add(new Literal("XCHG BX, BX "));
TypeDefinition xRuntimeEngineTypeDef = Engine.GetTypeDefinition(typeof(RuntimeEngineImpl).Assembly.GetName().Name, typeof(RuntimeEngineImpl).FullName);
@@ -159,7 +218,7 @@ namespace Indy.IL2CPU.IL.X86.Native {
aAssembler.DataMembers.RemoveAll(delegate(DataMember aItem) {
return aItem.Name == xFieldName;
});
- aAssembler.DataMembers.Add(new DataMember(xFieldName, "dd", xFieldName));
+ aAssembler.DataMembers.Add(new DataMember(xFieldName, "dd", xFieldName + "___Contents"));
aAssembler.DataMembers.Add(new DataMember(xFieldName + "___Contents", "db", xFieldData));
xFieldDef = xRuntimeEngineTypeDef.Fields.GetField("mIDTPointer");
string xPointerFieldName;
@@ -177,6 +236,7 @@ namespace Indy.IL2CPU.IL.X86.Native {
public override void PostProcess(Indy.IL2CPU.Assembler.Assembler aAssembler) {
base.PostProcess(aAssembler);
+ return;
TypeDefinition xRuntimeEngineTypeDef = Engine.GetTypeDefinition(typeof(RuntimeEngineImpl).Assembly.GetName().Name, typeof(RuntimeEngineImpl).FullName);
MethodDefinition xTheMethod = Engine.GetMethodDefinition(xRuntimeEngineTypeDef, "IDT_SetHandler", "System.Byte", "System.UInt32", "System.UInt16", xRuntimeEngineTypeDef.FullName + "/IDTEntryStruct/FlagsEnum");
Engine.QueueMethod(xTheMethod);
diff --git a/source/Indy.IL2CPU.IL.X86.Native/RuntimeEngineImpl.cs b/source/Indy.IL2CPU.IL.X86.Native/RuntimeEngineImpl.cs
index 63a409ad0..1cf87a350 100644
--- a/source/Indy.IL2CPU.IL.X86.Native/RuntimeEngineImpl.cs
+++ b/source/Indy.IL2CPU.IL.X86.Native/RuntimeEngineImpl.cs
@@ -9,17 +9,19 @@ namespace Indy.IL2CPU.IL.X86.Native {
public static MultiBootInfoStruct mMultibootInfo;
public static void InitializeEngine() {
Console.Clear();
- Debug.WriteLine("Slowing down PIT");
- PIT_SetSlowest();
- Debug.WriteLine("Loading IDT");
- SetupInterruptDescriptorTable();
- Debug.WriteLine("Loading PICs");
- SetupProgrammableInterruptControllers();
- Debug.WriteLine("Kernel Booted");
+// Debug.WriteLine("Loading GDT");
+// SetupGDT();
+// Debug.WriteLine("Slowing down PIT");
+// PIT_SetSlowest();
+// Debug.WriteLine("Loading IDT");
+// SetupInterruptDescriptorTable();
+// Debug.WriteLine("Loading PICs");
+// SetupProgrammableInterruptControllers();
+// Debug.WriteLine("Kernel Booted");
}
public static void FinalizeEngine() {
- Debug.WriteLine("Engine Shut down done.");
+ //Debug.WriteLine("Engine Shut down done.");
}
}
}
\ No newline at end of file
diff --git a/source/Indy.IL2CPU.IL.X86.Native/RuntimeEngineImpl/GDT.cs b/source/Indy.IL2CPU.IL.X86.Native/RuntimeEngineImpl/GDT.cs
index 6948d92be..3832da97c 100644
--- a/source/Indy.IL2CPU.IL.X86.Native/RuntimeEngineImpl/GDT.cs
+++ b/source/Indy.IL2CPU.IL.X86.Native/RuntimeEngineImpl/GDT.cs
@@ -1,9 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.InteropServices;
using System.Text;
-namespace Indy.IL2CPU.IL.X86.Native.RuntimeEngineImpl {
+namespace Indy.IL2CPU.IL.X86.Native {
public partial class RuntimeEngineImpl {
+ [StructLayout(LayoutKind.Sequential)]
+ public struct GDTEntry {
+ public ushort LimitLow;
+ public ushort BaseLow;
+ public byte BaseMiddle;
+ public byte Access;
+ public byte Granularity;
+ public byte BaseHigh;
+ }
+
+ private static void GDT_InitEntry(ref GDTEntry aEntry, uint aBase, uint aLimit, ushort aFlags) {
+ aEntry.BaseLow = (ushort)(aBase & 0xFFFF);
+ aEntry.BaseMiddle = (byte)((aBase >> 16) & 0xFF);
+ aEntry.BaseHigh = (byte)((aBase >> 24) & 0xFF);
+ aEntry.LimitLow = (ushort)(aLimit & 0xFFFF);
+ aEntry.Granularity = (byte)((aLimit >> 16) & 0x0F);
+ aEntry.Granularity |= (byte)((aFlags >> 4) & 0xF0);
+ aEntry.Access = (byte)(aFlags & 0xFF);
+ }
+
+ private static GDTEntry[] mGDTEntries = new GDTEntry[3];
+
+ public const ushort CodeSelector = 8;
+ public const ushort DataSelector = 16;
+
+
+ private static DTPointerStruct mGDTPointer;
+
+
+ private static void GDT_RegisterGDT() {
+ }
+
+ private static void GDT_LoadArray() {
+ }
+
+ public static void SetupGDT() {
+ GDT_LoadArray();
+ GDT_InitEntry(ref mGDTEntries[0], 0, 0, 0);
+ GDT_InitEntry(ref mGDTEntries[CodeSelector >> 3], 0, 0xFFFFFFFF, 0x89A);
+
+// Accessed = 1,
+// Writable = 2,
+// Expansion = 4,
+// Executable = 8,
+// Descriptor = 16,
+// Privilege_Ring_0 = 0,
+// Privilege_Ring_1 = 32,
+// Privilege_Ring_2 = 64,
+// Privilege_Ring_3 = 96,
+// Present = 128,
+// OperandSize_16Bit = 0,
+// OperandSize_32Bit = 1024,
+// Granularity_Byte = 0,
+// Granularity_4K = 2048
+//Entry.Type.Granularity_4K |
+// Entry.Type.OperandSize_32Bit |
+// Entry.Type.Present |
+// Entry.Type.Descriptor |
+// Entry.Type.Writable));
+//
+//
+ GDT_InitEntry(ref mGDTEntries[DataSelector >> 3], 0, 0xFFFFFFFF, 0x92);
+ Console.WriteLine("Register now:");
+ System.Diagnostics.Debugger.Break();
+ GDT_RegisterGDT();
+ }
}
}
diff --git a/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs b/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs
index d16a85f9f..d326a26b4 100644
--- a/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs
+++ b/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs
@@ -56,7 +56,7 @@ namespace Indy.IL2CPU.IL.X86 {
int xLocalSize = aLocalsSizes[j];
aAssembler.Add(new CPU.Add("esp", "0x" + xLocalSize.ToString("X")));
}
- aAssembler.Add(new CPU.Pop("ebp"));
+ aAssembler.Add(new CPU.Popd("ebp"));
aAssembler.Add(new CPU.Ret(aTotalArgsSize == 0 ? "" : aTotalArgsSize.ToString()));
}
}
diff --git a/source/Indy.IL2CPU/Engine.cs b/source/Indy.IL2CPU/Engine.cs
index 085f97dd1..fc6d9bcec 100644
--- a/source/Indy.IL2CPU/Engine.cs
+++ b/source/Indy.IL2CPU/Engine.cs
@@ -1,6 +1,4 @@
-// this file supports the VERBOSE_DEBUG define. this makes it emit a bunch of comments in the assembler output.
-// note that the tests are supposed to NOT include these comments
-#define VERBOSE_DEBUG
+#define VERBOSE_DEBUG
using System;
using System.Collections.Generic;
using System.IO;
@@ -198,6 +196,19 @@ namespace Indy.IL2CPU {
GenerateVMT();
}
mMap.PostProcess(mAssembler);
+// if(!aInMetalMode) {
+// FieldDefinition xFieldDef = VTablesImplRefs.VTablesImplDef.Fields.GetField("mIDTEntries");
+// string xFieldName = Assembler.DataMember.GetStaticFieldName(xFieldDef);
+// string xFieldData = "0,0,0,0,2,0,0,0,1,0,0,0";
+// for (int i = 0; i < 256; i++) {
+// xFieldData += ",0,0,0,0,0,0,0,0";
+// }
+// mAssembler.DataMembers.RemoveAll(delegate(DataMember aItem) {
+// return aItem.Name == xFieldName;
+// });
+// mAssembler.DataMembers.Add(new DataMember(xFieldName, "dd", xFieldName + "___Contents"));
+// mAssembler.DataMembers.Add(new DataMember(xFieldName + "___Contents", "db", xFieldData));
+// }
ProcessAllStaticFields();
} finally {
mAssembler.Flush();
@@ -236,8 +247,6 @@ namespace Indy.IL2CPU {
xOp.Assemble();
}
-
-
private void ScanForMethodToIncludeForVMT() {
List xCheckedTypes = new List();
foreach (MethodDefinition xMethod in mMethods.Keys) {
diff --git a/source/Indy.IL2CPU/VTablesImplRefs.cs b/source/Indy.IL2CPU/VTablesImplRefs.cs
index 2fb152abc..23405c0a3 100644
--- a/source/Indy.IL2CPU/VTablesImplRefs.cs
+++ b/source/Indy.IL2CPU/VTablesImplRefs.cs
@@ -8,6 +8,7 @@ using Mono.Cecil;
namespace Indy.IL2CPU {
public static class VTablesImplRefs {
public static readonly AssemblyDefinition RuntimeAssemblyDef;
+ public static readonly TypeDefinition VTablesImplDef;
public static readonly MethodDefinition LoadTypeTableRef;
public static readonly MethodDefinition SetTypeInfoRef;
public static readonly MethodDefinition SetMethodInfoRef;
@@ -15,19 +16,19 @@ namespace Indy.IL2CPU {
static VTablesImplRefs() {
RuntimeAssemblyDef = AssemblyFactory.GetAssembly(typeof(VTablesImpl).Assembly.Location);
- TypeDefinition xType = null;
+ VTablesImplDef = null;
foreach (ModuleDefinition xMod in RuntimeAssemblyDef.Modules) {
if (xMod.Types.Contains(typeof(VTablesImpl).FullName)) {
- xType = xMod.Types[typeof(VTablesImpl).FullName];
+ VTablesImplDef = xMod.Types[typeof(VTablesImpl).FullName];
break;
}
}
- if (xType == null) {
+ if (VTablesImplDef == null) {
throw new Exception("RuntimeEngine type not found!");
}
foreach (FieldInfo xField in typeof(VTablesImplRefs).GetFields()) {
if (xField.Name.EndsWith("Ref")) {
- MethodDefinition xTempMethod = xType.Methods.GetMethod(xField.Name.Substring(0, xField.Name.Length - "Ref".Length)).FirstOrDefault();
+ MethodDefinition xTempMethod = VTablesImplDef.Methods.GetMethod(xField.Name.Substring(0, xField.Name.Length - "Ref".Length)).FirstOrDefault();
if (xTempMethod == null) {
throw new Exception("Method '" + xField.Name.Substring(0, xField.Name.Length - "Ref".Length) + "' not found on RuntimeEngine!");
}