mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-20 21:08:51 +00:00
Update Global.cs
This commit is contained in:
parent
d8df4aab2e
commit
ef3ce991f1
1 changed files with 44 additions and 122 deletions
|
|
@ -1,139 +1,61 @@
|
|||
using System;
|
||||
|
||||
using System;
|
||||
using Cosmos.Core;
|
||||
using Cosmos.Debug.Kernel;
|
||||
using Cosmos.HAL.BlockDevice;
|
||||
|
||||
namespace Cosmos.HAL
|
||||
{
|
||||
public static class Global
|
||||
{
|
||||
public static readonly Debugger mDebugger = new Debugger("HAL", "Global");
|
||||
|
||||
//static public PIT PIT = new PIT();
|
||||
// Must be static init, other static inits rely on it not being null
|
||||
|
||||
public static TextScreenBase TextScreen = new TextScreen();
|
||||
public static PCI Pci;
|
||||
public static int atamode;
|
||||
|
||||
static public void Init(TextScreenBase textScreen)
|
||||
public static class Global
|
||||
{
|
||||
if (textScreen != null)
|
||||
{
|
||||
TextScreen = textScreen;
|
||||
}
|
||||
public static readonly Debugger mDebugger = new Debugger("HAL", "Global");
|
||||
|
||||
mDebugger.Send("Before Core.Global.Init");
|
||||
Core.Global.Init();
|
||||
//static public PIT PIT = new PIT();
|
||||
// Must be static init, other static inits rely on it not being null
|
||||
|
||||
//TODO Redo this - Global init should be other.
|
||||
// Move PCI detection to hardware? Or leave it in core? Is Core PC specific, or deeper?
|
||||
// If we let hardware do it, we need to protect it from being used by System.
|
||||
// Probably belongs in hardware, and core is more specific stuff like CPU, memory, etc.
|
||||
//Core.PCI.OnPCIDeviceFound = PCIDeviceFound;
|
||||
public static TextScreenBase TextScreen = new TextScreen();
|
||||
public static PCI Pci;
|
||||
|
||||
//TODO: Since this is FCL, its "common". Otherwise it should be
|
||||
// system level and not accessible from Core. Need to think about this
|
||||
// for the future.
|
||||
|
||||
Console.WriteLine("Finding PCI Devices");
|
||||
mDebugger.Send("PCI Devices");
|
||||
PCI.Setup();
|
||||
|
||||
Console.WriteLine("Starting ACPI");
|
||||
mDebugger.Send("ACPI Init");
|
||||
ACPI.Start();
|
||||
|
||||
mDebugger.Send("Done initializing Cosmos.HAL.Global");
|
||||
|
||||
if (atamode == 1)
|
||||
{
|
||||
//TODO Implement an AHCI Driver
|
||||
}
|
||||
else if (atamode == 2)
|
||||
{
|
||||
//TODO Implement a RAID Driver
|
||||
}
|
||||
else if (atamode == 3)
|
||||
{
|
||||
mDebugger.Send("ATA Primary Master");
|
||||
InitAta(Ata.ControllerIdEnum.Primary, Ata.BusPositionEnum.Master);
|
||||
|
||||
//TODO Need to change code to detect if ATA controllers are present or not. How to do this? via PCI enum?
|
||||
// They do show up in PCI space as well as the fixed space.
|
||||
// Or is it always here, and was our compiler stack corruption issue?
|
||||
mDebugger.Send("ATA Secondary Master");
|
||||
InitAta(Ata.ControllerIdEnum.Secondary, Ata.BusPositionEnum.Master);
|
||||
//InitAta(BlockDevice.Ata.ControllerIdEnum.Secondary, BlockDevice.Ata.BusPositionEnum.Slave);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EnableInterrupts()
|
||||
{
|
||||
CPU.EnableInterrupts();
|
||||
}
|
||||
|
||||
private static void InitAta(Ata.ControllerIdEnum aControllerID,
|
||||
Ata.BusPositionEnum aBusPosition)
|
||||
{
|
||||
var xIO = aControllerID == Ata.ControllerIdEnum.Primary
|
||||
? Core.Global.BaseIOGroups.ATA1
|
||||
: Core.Global.BaseIOGroups.ATA2;
|
||||
var xATA = new AtaPio(xIO, aControllerID, aBusPosition);
|
||||
if (xATA.DriveType == AtaPio.SpecLevel.Null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (xATA.DriveType == AtaPio.SpecLevel.ATA)
|
||||
{
|
||||
BlockDevice.BlockDevice.Devices.Add(xATA);
|
||||
Ata.AtaDebugger.Send("ATA device with speclevel ATA found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Ata.AtaDebugger.Send("ATA device with spec level " + (int)xATA.DriveType +
|
||||
// " found, which is not supported!");
|
||||
return;
|
||||
}
|
||||
var xMbrData = new byte[512];
|
||||
xATA.ReadBlock(0UL, 1U, xMbrData);
|
||||
var xMBR = new MBR(xMbrData);
|
||||
|
||||
if (xMBR.EBRLocation != 0)
|
||||
{
|
||||
//EBR Detected
|
||||
var xEbrData = new byte[512];
|
||||
xATA.ReadBlock(xMBR.EBRLocation, 1U, xEbrData);
|
||||
var xEBR = new EBR(xEbrData);
|
||||
|
||||
for (int i = 0; i < xEBR.Partitions.Count; i++)
|
||||
static public void Init(TextScreenBase textScreen)
|
||||
{
|
||||
//var xPart = xEBR.Partitions[i];
|
||||
//var xPartDevice = new BlockDevice.Partition(xATA, xPart.StartSector, xPart.SectorCount);
|
||||
//BlockDevice.BlockDevice.Devices.Add(xPartDevice);
|
||||
}
|
||||
}
|
||||
if (textScreen != null)
|
||||
{
|
||||
TextScreen = textScreen;
|
||||
}
|
||||
|
||||
mDebugger.Send("Before Core.Global.Init");
|
||||
Core.Global.Init();
|
||||
|
||||
//TODO Redo this - Global init should be other.
|
||||
// Move PCI detection to hardware? Or leave it in core? Is Core PC specific, or deeper?
|
||||
// If we let hardware do it, we need to protect it from being used by System.
|
||||
// Probably belongs in hardware, and core is more specific stuff like CPU, memory, etc.
|
||||
//Core.PCI.OnPCIDeviceFound = PCIDeviceFound;
|
||||
|
||||
//TODO: Since this is FCL, its "common". Otherwise it should be
|
||||
// system level and not accessible from Core. Need to think about this
|
||||
// for the future.
|
||||
|
||||
Console.WriteLine("Finding PCI Devices");
|
||||
mDebugger.Send("PCI Devices");
|
||||
PCI.Setup();
|
||||
|
||||
Console.WriteLine("Starting ACPI");
|
||||
mDebugger.Send("ACPI Init");
|
||||
ACPI.Start();
|
||||
|
||||
IDE.InitDriver();
|
||||
AHCI.InitDriver();
|
||||
//EHCI.InitDriver();
|
||||
|
||||
mDebugger.Send("Done initializing Cosmos.HAL.Global");
|
||||
|
||||
// TODO Change this to foreach when foreach is supported
|
||||
Ata.AtaDebugger.Send("Number of MBR partitions found:");
|
||||
Ata.AtaDebugger.SendNumber(xMBR.Partitions.Count);
|
||||
for (int i = 0; i < xMBR.Partitions.Count; i++)
|
||||
{
|
||||
var xPart = xMBR.Partitions[i];
|
||||
if (xPart == null)
|
||||
{
|
||||
Console.WriteLine("Null partition found at idx: " + i);
|
||||
}
|
||||
else
|
||||
|
||||
public static void EnableInterrupts()
|
||||
{
|
||||
var xPartDevice = new Partition(xATA, xPart.StartSector, xPart.SectorCount);
|
||||
BlockDevice.BlockDevice.Devices.Add(xPartDevice);
|
||||
Console.WriteLine("Found partition at idx" + i);
|
||||
CPU.EnableInterrupts();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool InterruptsEnabled => CPU.mInterruptsEnabled;
|
||||
}
|
||||
|
||||
public static bool InterruptsEnabled => CPU.mInterruptsEnabled;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue