Moved PIC to new kernel.

This commit is contained in:
kudzu_cp 2010-08-20 02:26:22 +00:00
parent a7c0112e36
commit 5b05ecbdc8
9 changed files with 99 additions and 62 deletions

View file

@ -120,7 +120,6 @@
<Compile Include="Network\TCPIPModel\IPv4Packet.cs" />
<Compile Include="Network\TCPIPModel\Ethernet2Frame.cs" />
<Compile Include="Storage\ATA\ATA.cs" />
<Compile Include="PIC.cs" />
<Compile Include="PCIBus.cs" />
<Compile Include="Old\TempDictionary.cs" />
<Compile Include="Global.cs" />

View file

@ -1,46 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cosmos.Hardware2 {
//TODO: Change this to be an instance like other drivers
public abstract class PIC : Cosmos.Hardware2.Device {
/// <summary>
/// Remaps the IRQ's to INT20-INT2F
/// </summary>
const ushort CmdPort1 = 0x20;
const ushort DataPort1 = 0x21;
const ushort CmdPort2 = 0xA0;
const ushort DataPort2 = 0xA1;
public static void SignalPrimary() {
Kernel.CPUBus.Write8(CmdPort1, 0x20);
}
public static void SignalSecondary() {
Kernel.CPUBus.Write8(CmdPort2, 0x20);
Kernel.CPUBus.Write8(CmdPort1, 0x20);
}
public static void Init() {
// Init
Kernel.CPUBus.Write8(CmdPort1, 0x11);
Kernel.CPUBus.Write8(CmdPort2, 0x11);
// Offsets
Kernel.CPUBus.Write8(DataPort1, 0x20);
Kernel.CPUBus.Write8(DataPort2, 0x28);
// More Init
Kernel.CPUBus.Write8(DataPort1, 0x04);
Kernel.CPUBus.Write8(DataPort2, 0x02);
// 8086 mode
Kernel.CPUBus.Write8(DataPort1, 0x01);
Kernel.CPUBus.Write8(DataPort2, 0x01);
// Masks - 0 = receive all IRQ's
// MTW, to disable PIT, send 0x1 to DataPort1
Kernel.CPUBus.Write8(DataPort1, 0x01);
Kernel.CPUBus.Write8(DataPort2, 0x00);
}
}
}

View file

@ -10,6 +10,7 @@ namespace Cosmos.Core {
// Further more some kind of security needs to be applied to these, but even now
// at least we have isolation between the consumers that use these.
public readonly IOGroup.Keyboard Keyboard = new IOGroup.Keyboard();
public readonly IOGroup.PIC PIC = new IOGroup.PIC();
public readonly IOGroup.PIT PIT = new IOGroup.PIT();
public readonly IOGroup.TextScreen TextScreen = new IOGroup.TextScreen();
}

View file

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cosmos.Core {
// Non hardware class, only used by core and hardware drivers for ports etc.
public class CPU {
}
}

View file

@ -40,7 +40,6 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="Cosmos.Hardware2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983, processorArchitecture=x86" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@ -50,14 +49,17 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BaseIOGroups.cs" />
<Compile Include="CPU.cs" />
<Compile Include="Global.cs" />
<Compile Include="IOGroup\Keyboard.cs" />
<Compile Include="IOGroup\PIC.cs" />
<Compile Include="IRQs.cs" />
<Compile Include="IOGroup\IOGroup.cs" />
<Compile Include="IOGroup\PIT.cs" />
<Compile Include="IOGroup\TextScreen.cs" />
<Compile Include="IOPort.cs" />
<Compile Include="MemoryBlock.cs" />
<Compile Include="PIC.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

View file

@ -2,12 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmos.Hardware2;
namespace Cosmos.Core {
static public class Global {
static readonly public BaseIOGroups BaseIOGroups = new BaseIOGroups();
static readonly public Cosmos.Debug.Kernel.Debugger Dbg = new Cosmos.Debug.Kernel.Debugger("Core", "");
static public PIC PIC;
static public void Init() {
// Temp
@ -16,7 +16,7 @@ namespace Cosmos.Core {
Kernel.Heap.Init();
Kernel.CPU.CreateGDT();
PIC.Init();
PIC = new PIC();
Kernel.CPU.CreateIDT(true);
Kernel.CPU.InitFloat();
// End Temp

View file

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cosmos.Core.IOGroup {
public class PIC {
public readonly IOPort PortCmd1 = new IOPort(0x20);
public readonly IOPort PortData1 = new IOPort(0x21);
public readonly IOPort PortCmd2 = new IOPort(0xA0);
public readonly IOPort PortData2 = new IOPort(0xA1);
}
}

View file

@ -4,12 +4,29 @@ using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Cosmos.Kernel;
using Cosmos.Hardware2;
namespace Cosmos.Core {
public class IRQs {
// TODO: Protect IRQs like memory and ports are
// TODO: Make IRQs so they are not hookable, and instead release high priority threads like FreeBSD (When we get threading)
public enum EFlagsEnum : uint {
Carry = 1,
Parity = 1 << 2,
AuxilliaryCarry = 1 << 4,
Zero = 1 << 6,
Sign = 1 << 7,
Trap = 1 << 8,
InterruptEnable = 1 << 9,
Direction = 1 << 10,
Overflow = 1 << 11,
NestedTag = 1 << 14,
Resume = 1 << 16,
Virtual8086Mode = 1 << 17,
AlignmentCheck = 1 << 18,
VirtualInterrupt = 1 << 19,
VirtualInterruptPending = 1 << 20,
ID = 1 << 21
}
[StructLayout(LayoutKind.Explicit, Size = 0x68)]
public struct TSS {
@ -139,9 +156,9 @@ namespace Cosmos.Core {
public static void HandleInterrupt_Default(ref IRQContext aContext) {
if (aContext.Interrupt >= 0x20 && aContext.Interrupt <= 0x2F) {
if (aContext.Interrupt >= 0x28) {
PIC.SignalSecondary();
Global.PIC.SignalSecondary();
} else {
PIC.SignalPrimary();
Global.PIC.SignalPrimary();
}
}
}
@ -153,7 +170,7 @@ namespace Cosmos.Core {
public static void HandleInterrupt_20(ref IRQContext aContext) {
//TODO New Kernel
//PIT.HandleInterrupt();
PIC.SignalPrimary();
Global.PIC.SignalPrimary();
}
//public static InterruptDelegate IRQ01;
@ -174,7 +191,7 @@ namespace Cosmos.Core {
////
//// - End change area
//Console.WriteLine("Signal PIC primary");
PIC.SignalPrimary();
Global.PIC.SignalPrimary();
}
//IRQ 5 - (Added for ES1370 AudioPCI)
@ -183,7 +200,7 @@ namespace Cosmos.Core {
public static void HandleInterrupt_25(ref IRQContext aContext) {
IRQ(0x25, ref aContext);
PIC.SignalSecondary();
Global.PIC.SignalSecondary();
}
//IRQ 09 - (Added for AMD PCNet network card)
@ -191,7 +208,7 @@ namespace Cosmos.Core {
public static void HandleInterrupt_29(ref IRQContext aContext) {
IRQ(0x29, ref aContext);
PIC.SignalSecondary();
Global.PIC.SignalSecondary();
}
//IRQ 10 - (Added for VIA Rhine network card)
@ -205,7 +222,7 @@ namespace Cosmos.Core {
IRQ(0x2A, ref aContext);
PIC.SignalSecondary();
Global.PIC.SignalSecondary();
}
//IRQ 11 - (Added for RTL8139 network card)
@ -219,7 +236,7 @@ namespace Cosmos.Core {
IRQ(0x2B, ref aContext);
PIC.SignalSecondary();
Global.PIC.SignalSecondary();
}
public static void HandleInterrupt_2C(ref IRQContext aContext) {
@ -232,7 +249,7 @@ namespace Cosmos.Core {
IRQ(0x2C, ref aContext);
PIC.SignalSecondary();
Global.PIC.SignalSecondary();
}
//IRQ 14 - Primary IDE. If no Primary IDE this can be changed
@ -240,7 +257,7 @@ namespace Cosmos.Core {
Global.Dbg.SendMessage("IRQ", "Primary IDE");
//Storage.ATAOld.HandleInterruptPrimary();
//Storage.ATA.ATA.HandleInterruptPrimary();
PIC.SignalSecondary();
Global.PIC.SignalSecondary();
}
public static event InterruptDelegate Interrupt30;
@ -264,7 +281,7 @@ namespace Cosmos.Core {
public static void HandleInterrupt_2F(ref IRQContext aContext) {
//Storage.ATA.ATA.HandleInterruptSecondary();
Global.Dbg.SendMessage("IRQ", "Secondary IDE");
PIC.SignalSecondary();
Global.PIC.SignalSecondary();
}
public static void HandleInterrupt_00(ref IRQContext aContext) {

View file

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cosmos.Core {
// PIC is not in hardware becuase its a special core piece like CPU that is not interacted with by anything except Core.
//
// Remaps the IRQ's to INT20-INT2F
public class PIC {
protected IOGroup.PIC IO = Global.BaseIOGroups.PIC;
public void SignalPrimary() {
IO.PortCmd1.Byte = 0x20;
}
public void SignalSecondary() {
IO.PortCmd2.Byte = 0x20;
IO.PortCmd1.Byte = 0x20;
}
public PIC() {
// Init
IO.PortCmd1.Byte = 0x11;
IO.PortCmd2.Byte = 0x11;
// Offsets
IO.PortData1.Byte = 0x20;
IO.PortData2.Byte = 0x28;
// More Init
IO.PortData1.Byte = 0x04;
IO.PortData2.Byte = 0x02;
// 8086 mode
IO.PortData1.Byte = 0x01;
IO.PortData2.Byte = 0x01;
// Masks - 0 = receive all IRQ's
// MTW, to disable PIT, send 0x1 to DataPort1
IO.PortData1.Byte = 0x01;
IO.PortData2.Byte = 0x00;
}
}
}