Cosmos/source/Cosmos.HAL2/Global.cs
Og-Rok 2d5f637a91 Softwaare Multitasking
Working context switching but far from stable. Changes needed to be made
to the internals of cosmos to include mutex's in vital components (Heap,
Thread Manager, ect). Context switching currently only switches the
general registers and does not switch the MMX context, however this will
be added in the future. Also when a thread currently dies it takes the
whole system down, patches to the IDT handlers needed to be made to
prevent system lockup in the future
2018-04-04 01:22:52 +01:00

74 lines
2.3 KiB
C#

using System;
using System.Threading;
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;
static public void Init(TextScreenBase textScreen)
{
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();
Core.Processing.ProcessorScheduler.Initialize();
//PIT.RegisterTimer(new PIT.PITTimer(Core.Processing.ProcessorScheduler.SwitchTask, 20, true));
mDebugger.Send("Done initializing Cosmos.HAL.Global");
}
public static void EnableInterrupts()
{
CPU.EnableInterrupts();
}
public static bool InterruptsEnabled => CPU.mInterruptsEnabled;
public static uint SpawnThread(ThreadStart aStart)
{
return Core.Processing.ProcessContext.StartContext("", aStart, Core.Processing.ProcessContext.Context_Type.THREAD);
}
public static uint SpawnThread(ParameterizedThreadStart aStart, object param)
{
return Core.Processing.ProcessContext.StartContext("", aStart, Core.Processing.ProcessContext.Context_Type.THREAD, param);
}
}
}