singrdk/base/Kernel/Singularity/MpBootInfo.cs

100 lines
3.0 KiB
C#
Raw Permalink Normal View History

2008-03-05 09:52:00 -05:00
///////////////////////////////////////////////////////////////////////////////
//
// Microsoft Research Singularity
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: MpBootInfo.cs
//
// Note:
// This structure holds values needed to bring the application processors
// into protected mode.
//
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
2008-11-17 18:29:00 -05:00
using Microsoft.Singularity.Hal;
2008-03-05 09:52:00 -05:00
using Microsoft.Singularity.Memory;
namespace Microsoft.Singularity
{
[StructLayout(LayoutKind.Sequential, Pack=4)]
[CLSCompliant(false)]
2008-11-17 18:29:00 -05:00
[AccessedByRuntime("referenced in c++")]
2008-03-05 09:52:00 -05:00
public struct MpBootInfo
{
#if SINGULARITY_MP
[AccessedByRuntime("referenced in c++")]
public const uint MAX_CPU =
# if MAX_CPU4
4;
# elif MAX_CPU3
3;
# elif MAX_CPU2
2;
# else
2008-11-17 18:29:00 -05:00
15;
2008-03-05 09:52:00 -05:00
# endif // MAX_CPUX
#else
[AccessedByRuntime("referenced in c++")]
public const uint MAX_CPU = 1;
#endif // SINGULARITY_MP
[AccessedByRuntime("referenced in c++")]
public const uint Signature = 0x4d504249; // "MPBI"
// Settings for next processor to enter protected mode
[AccessedByRuntime("referenced in c++")]
public uint signature;
[AccessedByRuntime("referenced in c++")]
public UIntPtr KernelStackBegin;
[AccessedByRuntime("referenced in c++")]
public UIntPtr KernelStack;
[AccessedByRuntime("referenced in c++")]
public UIntPtr KernelStackLimit;
[AccessedByRuntime("referenced in c++")]
public volatile int TargetCpu;
2008-11-17 18:29:00 -05:00
[AccessedByRuntime("defined in MpBootInfo.cpp")]
2008-03-05 09:52:00 -05:00
[MethodImpl(MethodImplOptions.InternalCall)]
2008-11-17 18:29:00 -05:00
[StackBound(256)]
2008-03-05 09:52:00 -05:00
internal static unsafe extern MpBootInfo * HalGetMpBootInfo();
2008-11-17 18:29:00 -05:00
[AccessedByRuntime("defined in MpBootInfo.cpp")]
2008-03-05 09:52:00 -05:00
[MethodImpl(MethodImplOptions.InternalCall)]
2008-11-17 18:29:00 -05:00
[StackBound(256)]
2008-03-05 09:52:00 -05:00
internal static unsafe extern void HalReleaseMpStartupLock();
2008-11-17 18:29:00 -05:00
public unsafe void ReleaseMpStartupLock()
2008-03-05 09:52:00 -05:00
{
2008-11-17 18:29:00 -05:00
HalReleaseMpStartupLock();
}
public unsafe bool PrepareForCpuStart(int targetCpu)
{
2008-03-05 09:52:00 -05:00
UIntPtr size = MemoryManager.PagePad(
2008-11-17 18:29:00 -05:00
Platform.BootCpu.KernelStackBegin
- Platform.BootCpu.KernelStackLimit);
2008-03-05 09:52:00 -05:00
2008-11-17 18:29:00 -05:00
UIntPtr stack = MemoryManager.KernelAllocate(
2008-03-05 09:52:00 -05:00
MemoryManager.PagesFromBytes(size), null, 0, System.GCs.PageType.Stack);
2008-11-17 18:29:00 -05:00
if (stack == UIntPtr.Zero) {
2008-03-05 09:52:00 -05:00
return false;
}
2008-11-17 18:29:00 -05:00
KernelStackLimit = stack;
KernelStackBegin = stack + size;
signature = Signature;
TargetCpu = targetCpu;
2008-03-05 09:52:00 -05:00
HalReleaseMpStartupLock();
return true;
}
}
}