Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Interrupt Queue #1188

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:
contents: write

env:
BUILD_VERSION: 2.5.1.${{ github.run_number }}
BUILD_VERSION: 2.6.0.${{ github.run_number }}

jobs:

Expand Down
3 changes: 2 additions & 1 deletion Source/Docs/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ The target platforms are:

- 32-bit x86 (stable)
- 64-bit x86 (x64) (in development)
- A32 ARMv8 (in early development)
- 32-bit ARMv8+ (in early development)
- 64-bit ARMv8+ (in early development)

The MOSA compiler supports most object and non-object oriented code, including:

Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/CompilerVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static Version GetVersion()
if (version.Build == 0)
{
// Revision and build number are reversed by design
version = new Version(2, 5, 1, 1);
version = new Version(2, 6, 0, 0);
}

return version;
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.x64/Intrinsic/IRQs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Mosa.Compiler.x64.Intrinsic;
/// </summary>
internal static partial class IntrinsicMethods
{
private static readonly string DefaultInterruptMethodName = "Mosa.Kernel.X64.IDT::ProcessInterrupt";
private static readonly string DefaultInterruptMethodName = "Mosa.Kernel.BareMetal.X64.IDT::ProcessInterrupt";

private static void InsertIRQ(int irq, Context context, Transform transform)
{
Expand Down
5 changes: 2 additions & 3 deletions Source/Mosa.Compiler.x86/Intrinsic/IRQs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace Mosa.Compiler.x86.Intrinsic;
/// </summary>
internal static partial class IntrinsicMethods
{
//private static readonly string DefaultInterruptMethodName = "Mosa.Kernel.x86.IDT::ProcessInterrupt";
private static readonly string DefaultInterruptMethodName = "Mosa.Runtime.Interrupt::Process";
private static readonly string DefaultInterruptMethodName = "Mosa.Kernel.BareMetal.x86.IDT::ProcessInterrupt";

private static readonly string[] seperator = new string[] { "::" };

Expand All @@ -23,7 +22,7 @@ private static void InsertIRQ(int irq, Context context, Transform transform)
interruptMethodName = DefaultInterruptMethodName;
}

var ar = interruptMethodName.Split(seperator, System.StringSplitOptions.None);
var ar = interruptMethodName.Split(seperator, StringSplitOptions.None);

if (ar.Length != 2)
return;
Expand Down
2 changes: 1 addition & 1 deletion Source/Mosa.DeviceSystem/HAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static void Assert(bool condition, string message)
}

/// <summary>
/// Pause
/// Yield
/// </summary>
public static void Yield() => hardwareAbstraction.Yield();

Expand Down
3 changes: 1 addition & 2 deletions Source/Mosa.Kernel.BareMetal.x86/IDT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Mosa.Kernel.BareMetal.BootMemory;
using Mosa.Kernel.BareMetal.Intel;
using Mosa.Runtime;
using Mosa.Runtime.Plug;
using Mosa.Runtime.x86;

namespace Mosa.Kernel.BareMetal.x86;
Expand Down Expand Up @@ -2170,7 +2169,6 @@ private static void IRQ255()
/// Interrupts the handler.
/// </summary>
/// <param name="stackStatePointer">The stack state pointer.</param>
[Plug("Mosa.Runtime.Interrupt::Process")]
private static unsafe void ProcessInterrupt(Pointer stackStatePointer)
{
var stack = new IDTStackEntry(stackStatePointer);
Expand Down Expand Up @@ -2270,6 +2268,7 @@ private static unsafe void ProcessInterrupt(Pointer stackStatePointer)

default:
Interrupt?.Invoke(stack.Interrupt, stack.ErrorCode);
BareMetal.InterruptManager.ProcessInterrupt(stack.Interrupt, stack.ErrorCode);
break;
}

Expand Down
6 changes: 6 additions & 0 deletions Source/Mosa.Kernel.BareMetal/InterruptManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static void Setup()
{
Debug.WriteLine("InterreuptManager:Setup()");

InterruptQueue.Setup();
Platform.Interrupt.Setup();

Debug.WriteLine("InterreuptManager:Setup() [Exit]");
Expand All @@ -19,4 +20,9 @@ public static void SetHandler(InterruptHandler handler)
{
Platform.Interrupt.SetHandler(handler);
}

public static void ProcessInterrupt(uint interrupt, uint errorCode)
{
InterruptQueue.Enqueue(interrupt);
}
}
79 changes: 79 additions & 0 deletions Source/Mosa.Kernel.BareMetal/InterruptQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

namespace Mosa.Kernel.BareMetal;

public static class InterruptQueue
{
private const int MaxIRQs = 8196;

private static int[] slots;
private static int first;
private static int last;
private static int length;

public static void Setup()
{
Debug.WriteLine("InterruptQueue:Setup()");

slots = new int[8196];
first = -1;
last = -1;
length = 0;

for (var i = 0; i < MaxIRQs; i++)
{
slots[i] = -1;
}

Debug.WriteLine("InterruptQueue:Setup() [Exit]");
}

public static int GetLength() => length;

public static void Enqueue(uint irq)
{
if (last == -1)
{
first = (int)irq;
last = (int)irq;
length = 1;
}
else
{
if (last == irq)
return;

if (slots[irq] != -1)
return;

slots[last] = (int)irq;

last = (int)irq;

length++;
}
}

public static int Dequeue()
{
if (first == -1)
{
return -1;
}
else
{
var ret = first;

first = slots[first];

if (first == -1)
{
last = -1;
}

length--;

return ret;
}
}
}
4 changes: 3 additions & 1 deletion Source/Mosa.Kernel.BareMetal/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ private static Pointer AllocateMemory(uint size)

private static void ProcessInterrupt(uint interrupt, uint errorCode)
{
if (interrupt is >= 0x20 and < 0x30)
if (interrupt is >= 0x20 and < 0x30) // FIXME: X86 specific
{
HAL.ProcessInterrupt((byte)(interrupt - 0x20));
}
}
}
11 changes: 0 additions & 11 deletions Source/Mosa.Runtime/Interrupt.cs

This file was deleted.

Loading