mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-11 10:41:33 +00:00
random changes, interrupts work now
This commit is contained in:
parent
0fcc0b4e95
commit
ffcd2a6bbd
12 changed files with 65 additions and 41 deletions
|
|
@ -6,8 +6,8 @@ namespace Cosmos.Kernel {
|
|||
public static void Main() {
|
||||
Console.WriteLine("This is Indy OS...");
|
||||
//int xDivider = 0;
|
||||
Console.WriteLine("Try Interrupts now");
|
||||
System.Diagnostics.Debugger.Break();
|
||||
Console.WriteLine("Done");
|
||||
Console.WriteLine("Testing IDT");
|
||||
TestIDT();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ class ConsoleDrv
|
|||
public static int Main()
|
||||
{
|
||||
mTypes = new VTable[1];
|
||||
mTypes[0] = new VTable();
|
||||
mTypes[0].MethodIndexes = new int[2];
|
||||
mTypes[0].MethodAddresses = new int[2];
|
||||
mTypes[0].MethodIndexes[0] = 14;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace Indy.IL2CPU.Assembler.NativeX86 {
|
|||
mOutputWriter.WriteLine("mb_info multiboot_info ; just a dummy ");
|
||||
mOutputWriter.WriteLine("");
|
||||
mOutputWriter.WriteLine("");
|
||||
mOutputWriter.WriteLine("rb 32768 ; our own stack ");
|
||||
mOutputWriter.WriteLine("rb 50000 ; our own stack ");
|
||||
mOutputWriter.WriteLine("Kernel_Stack: ");
|
||||
mOutputWriter.WriteLine("");
|
||||
mOutputWriter.WriteLine("");
|
||||
|
|
|
|||
19
source/Indy.IL2CPU.IL.NativeX86/DebugHelper.cs
Normal file
19
source/Indy.IL2CPU.IL.NativeX86/DebugHelper.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Indy.IL2CPU.IL.NativeX86 {
|
||||
public static class DebugHelper {
|
||||
private static bool mWritingPossible = false;
|
||||
public static void DoWriteIfPossible(string aMessage) {
|
||||
if (mWritingPossible) {
|
||||
System.Diagnostics.Debug.WriteLine(aMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public static void MakeWritingPossible() {
|
||||
//mWritingPossible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -40,6 +40,7 @@
|
|||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Mono.Cecil.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PostSharp.Core, Version=1.0.7.261, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7, processorArchitecture=MSIL" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
|
|
@ -55,6 +56,7 @@
|
|||
<Compile Include="CustomImplementations\System\ConsoleImpl.cs" />
|
||||
<Compile Include="CustomImplementations\System\ConsoleImplRefs.cs" />
|
||||
<Compile Include="CustomImplementations\System\Diagnostics\DebugImpl.cs" />
|
||||
<Compile Include="DebugHelper.cs" />
|
||||
<Compile Include="NativeX86CustomMethodImplementationOp.cs" />
|
||||
<Compile Include="NativeX86OpCodeMap.cs" />
|
||||
<Compile Include="NativeX86PutCharOp.cs" />
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
|
@ -9,32 +9,14 @@ using CPU = Indy.IL2CPU.Assembler.X86;
|
|||
|
||||
namespace Indy.IL2CPU.IL.NativeX86 {
|
||||
public class NativeX86MethodFooterOp: X86MethodFooterOp {
|
||||
private bool mIsInterruptHandler = false;
|
||||
private string mLabelName;
|
||||
public NativeX86MethodFooterOp(Instruction aInstruction, MethodInformation aMethodInfo)
|
||||
: base(aInstruction, aMethodInfo) {
|
||||
foreach (CustomAttribute xAttrib in aMethodInfo.MethodDefinition.CustomAttributes) {
|
||||
if(xAttrib.Constructor.DeclaringType.FullName == typeof(InterruptServiceRoutineAttribute).FullName) {
|
||||
mIsInterruptHandler = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mLabelName = aMethodInfo.LabelName;
|
||||
}
|
||||
|
||||
public override void DoAssemble() {
|
||||
// MtW: after trial and a huge amount of errors, this line doesn't seem to be needed
|
||||
//Assembler.Add(new CPU.Add("esp", TotalLocalsSize.ToString()));
|
||||
AssembleFooter(HasReturnValue, Assembler, LocalsCount, TotalArgsSize);
|
||||
}
|
||||
|
||||
public static void AssembleFooter(bool aHasReturnValue, Assembler.Assembler aAssembler, int aLocalsCount, int aTotalArgsSize) {
|
||||
if (aHasReturnValue) {
|
||||
aAssembler.Add(new Assembler.X86.Pop("eax"));
|
||||
}
|
||||
for (int i = 0; i < aLocalsCount; i++) {
|
||||
aAssembler.Add(new CPU.Add("esp", "4"));
|
||||
}
|
||||
aAssembler.Add(new CPU.Pop("ebp"));
|
||||
aAssembler.Add(new CPU.Ret(aTotalArgsSize == 0 ? "" : aTotalArgsSize.ToString()));
|
||||
base.DoAssemble();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
@ -15,6 +15,10 @@ namespace Indy.IL2CPU.IL.NativeX86 {
|
|||
return typeof(NativeX86CustomMethodImplementationOp);
|
||||
}
|
||||
|
||||
protected override Type GetMethodFooterOp() {
|
||||
return typeof(NativeX86MethodFooterOp);
|
||||
}
|
||||
|
||||
protected override Type GetMethodHeaderOp() {
|
||||
return typeof(NativeX86MethodHeaderOp);
|
||||
}
|
||||
|
|
@ -99,7 +103,8 @@ namespace Indy.IL2CPU.IL.NativeX86 {
|
|||
return;
|
||||
}
|
||||
case "System_Void___Cosmos_Kernel_ConsoleDrv_TestIDT____": {
|
||||
//aAssembler.Add(new Literal("int 0x80"));
|
||||
aAssembler.Add(new Literal("xchg bx, bx"));
|
||||
aAssembler.Add(new Literal("int 3"));
|
||||
break;
|
||||
}
|
||||
case "System_Void___Indy_IL2CPU_IL_NativeX86_RuntimeEngineImpl_IO_WriteToPort___System_UInt16__System_Byte__": {
|
||||
|
|
@ -173,8 +178,8 @@ namespace Indy.IL2CPU.IL.NativeX86 {
|
|||
int[] xInterruptsWithParam = new int[] { 8, 10, 11, 12, 13, 14 };
|
||||
for (int i = 0; i < 256; i++) {
|
||||
aAssembler.Add(new CPU.Push("0x" + i.ToString("X")));
|
||||
if (i == 0) {
|
||||
//aAssembler.Add(new Literal("xchg bx, bx"));
|
||||
if (i == 3) {
|
||||
aAssembler.Add(new Literal("xchg bx, bx"));
|
||||
}
|
||||
aAssembler.Add(new CPU.Push("____INTERRUPT_HANDLER___" + i));
|
||||
aAssembler.Add(new CPU.Push("0x08"));
|
||||
|
|
|
|||
|
|
@ -7,18 +7,19 @@ using System.Text;
|
|||
namespace Indy.IL2CPU.IL.NativeX86 {
|
||||
public static partial class RuntimeEngineImpl {
|
||||
public static void InitializeEngine() {
|
||||
DebugHelper.MakeWritingPossible();
|
||||
Console.Clear();
|
||||
Debug.WriteLine("Slowing down PIT");
|
||||
PIT_SetSlowest();
|
||||
Debug.WriteLine("Loading IDT");
|
||||
SetupInterruptDescriptorTable();
|
||||
Debug.WriteLine("Loading PICs");
|
||||
//SetupProgrammableInterruptControllers();
|
||||
//Debug.WriteLine("Kernel Booted!");
|
||||
SetupProgrammableInterruptControllers();
|
||||
Debug.WriteLine("Kernel Booted");
|
||||
}
|
||||
|
||||
public static void FinalizeEngine() {
|
||||
|
||||
Debug.WriteLine("Engine Shut down done.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,19 +39,20 @@ namespace Indy.IL2CPU.IL.NativeX86 {
|
|||
private static void IDT_SetHandler(byte aInterruptNumber, uint aBase, ushort aSel, IDTEntryStruct.FlagsEnum aFlags) {
|
||||
mIDTEntries[aInterruptNumber].AlwaysZero = 0;
|
||||
mIDTEntries[aInterruptNumber].Sel = 8;
|
||||
mIDTEntries[aInterruptNumber].BaseLow = (ushort)(aBase & 0xFFFF);
|
||||
mIDTEntries[aInterruptNumber].BaseHi = (ushort)((aBase >> 16) & 0xFFFF);
|
||||
mIDTEntries[aInterruptNumber].BaseLow = (ushort)(aBase);
|
||||
mIDTEntries[aInterruptNumber].BaseHi = (ushort)(aBase >> 16);
|
||||
mIDTEntries[aInterruptNumber].Flags = 128 /*Present*/| 0 /*Ring0*/| 8 /*32-bit*/| 0xF /*interrupt gate*/;
|
||||
} // was E
|
||||
|
||||
private static void InterruptHandler(byte aInterrupt, uint aParam) {
|
||||
if(aInterrupt >= 40 && aInterrupt <= 47) {
|
||||
Debug.WriteLine("Interrupt received");
|
||||
System.Diagnostics.Debugger.Break();
|
||||
if (aInterrupt >= 40 && aInterrupt <= 47) {
|
||||
WriteToPort(0xA0, 0x20);
|
||||
}
|
||||
if (aInterrupt >= 32 && aInterrupt <= 47) {
|
||||
WriteToPort(0x20, 0x20);
|
||||
}
|
||||
//Debug.WriteLine("Interrupt received");
|
||||
}
|
||||
|
||||
private static void SetupInterruptDescriptorTable() {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,10 @@ namespace Indy.IL2CPU.IL.X86 {
|
|||
: base(aInstruction, aMethodInfo) {
|
||||
}
|
||||
public override void DoAssemble() {
|
||||
// todo: implement correct truncating
|
||||
Pop("ecx");
|
||||
Move(Assembler, "eax", "0");
|
||||
Move(Assembler, "ax", "cx");
|
||||
Pushd("eax");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,14 +14,23 @@ namespace Indy.IL2CPU.IL.X86 {
|
|||
LiteralStr = (string)aInstruction.Operand;
|
||||
}
|
||||
|
||||
public LdStr(string aLiteralStr):base(null, null) {
|
||||
LiteralStr = aLiteralStr;
|
||||
}
|
||||
|
||||
public override void DoAssemble() {
|
||||
if (Assembler.InMetalMode) {
|
||||
string xDataName = Assembler.GetIdentifier("StringLiteral");
|
||||
var xDataByteArray = new StringBuilder();
|
||||
xDataByteArray.Append(BitConverter.GetBytes(LiteralStr.Length).Aggregate("", (r, b) => r + b + ","));
|
||||
xDataByteArray.Append(Encoding.ASCII.GetBytes(LiteralStr).Aggregate("", (r, b) => r + b + ","));
|
||||
//xDataByteArray.Append("0,");
|
||||
Assembler.DataMembers.Add(new DataMember(xDataName, "db", xDataByteArray.ToString().TrimEnd(',')));
|
||||
string xDataVal = xDataByteArray.ToString().TrimEnd(',');
|
||||
string xDataName = (from item in Assembler.DataMembers
|
||||
where item.DefaultValue == xDataVal
|
||||
select item.Name).FirstOrDefault();
|
||||
if (String.IsNullOrEmpty(xDataName)) {
|
||||
xDataName = Assembler.GetIdentifier("StringLiteral");
|
||||
Assembler.DataMembers.Add(new DataMember(xDataName, "db", xDataVal));
|
||||
}
|
||||
Move(Assembler, "eax", xDataName);
|
||||
Pushd("eax");
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -633,6 +633,9 @@ namespace Indy.IL2CPU {
|
|||
} else {
|
||||
xTheSize = 4;
|
||||
}
|
||||
if(xTheSize<4) {
|
||||
xTheSize = 4;
|
||||
}
|
||||
if (xTheSize == 4) {
|
||||
theType = "dd";
|
||||
xTheSize = 1;
|
||||
|
|
|
|||
Loading…
Reference in a new issue