mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-21 21:38:52 +00:00
Misc changes
This commit is contained in:
parent
9c7d80f11c
commit
f9a421df12
8 changed files with 161 additions and 22 deletions
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using Indy.IL2CPU.NativeX86.Utilities.BIOS;
|
||||
|
||||
|
||||
namespace Cosmos.Kernel {
|
||||
class ConsoleDrv {
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@
|
|||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Indy.IL2CPU.NativeX86.Utilities\Cosmos.Kernel.Boot.csproj">
|
||||
<ProjectReference Include="..\Cosmos.Kernel.Boot\Cosmos.Kernel.Boot.csproj">
|
||||
<Project>{BB58FFC3-A532-45BA-AAB2-28EB0451C2A1}</Project>
|
||||
<Name>Cosmos.Kernel.Boot</Name>
|
||||
</ProjectReference>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<TypeDefinition> xCheckedTypes = new List<TypeDefinition>();
|
||||
foreach (MethodDefinition xMethod in mMethods.Keys) {
|
||||
|
|
|
|||
|
|
@ -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!");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue