-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
irq: Start refactoring IRQ allocation and interrupt handling
- Loading branch information
Showing
27 changed files
with
258 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,50 @@ | ||
// Function prototypes for interrupts | ||
// Interrupt handling | ||
|
||
#pragma once | ||
|
||
#include <menix/common.h> | ||
#include <menix/util/list.h> | ||
|
||
typedef usize Irq; | ||
typedef struct Context Context; | ||
typedef Context* (*InterruptFn)(usize isr, Context* regs, void* priv); | ||
|
||
// Handler called by the processor. | ||
Context* int_handler(usize isr, Context* regs); | ||
typedef enum | ||
{ | ||
IrqIgnored = 0, // Interrupt was not handled. | ||
IrqHandled = (1 << 0), // Handler completed the IRQ work. | ||
IrqWake = (1 << 1), // Handler wants to wake up the handler thread. | ||
} IrqStatus; | ||
|
||
// Registers a new IRQ handler. Automatically selects optimal IRQ placement. | ||
// You can also pass an additional parameter for context passed to the handler. | ||
// Returns `true` upon success. | ||
bool irq_allocate_handler(InterruptFn handler, void* data); | ||
typedef enum | ||
{ | ||
IrqFlags_None = 0, | ||
} IrqFlags; | ||
|
||
// Internal function to register an interrupt handler at a specific ISR index on the current CPU. | ||
bool isr_register_handler(usize cpu, usize idx, InterruptFn handler, void* data); | ||
// An IRQ handler callback. | ||
typedef IrqStatus (*IrqHandlerFn)(Irq irq, void* context); | ||
|
||
typedef struct IrqAction | ||
{ | ||
struct IrqAction* next; // Next action in the list. | ||
Irq irq; // The IRQ number. | ||
IrqFlags flags; // Flags for this action. | ||
IrqHandlerFn handler; // Called directly to handle the IRQ. | ||
IrqHandlerFn worker; // Function to call in a worker thread, if woken up by the handler. | ||
struct Thread* thread; // The thread to execute the worker function on. | ||
const char* name; // Name of the IRQ. | ||
void* context; // A generic context to pass to the handler. | ||
} IrqAction; | ||
|
||
extern IrqAction* irq_actions; | ||
|
||
// Platform independent handler that runs the given IRQ. To be called by architecture specific interrupt handlers. | ||
void irq_generic_handler(Irq irq); | ||
|
||
// Registers a new IRQ handler. Automatically selects optimal CPU placement. | ||
// Returns true upon success. | ||
// `handler`: The main interrupt handler. Must not be NULL. | ||
// `thread_handler`: The threaded handler. Optional. | ||
// `flags`: Flags to control how this IRQ handler behaves. | ||
// `name`: Name of this IRQ. | ||
// `data`: Context to pass to the IRQ on invocation. | ||
bool irq_allocate(IrqHandlerFn handler, IrqHandlerFn thread_handler, IrqFlags flags, const char* name, void* data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#include <menix/common.h> | ||
|
||
#include <gdt.h> | ||
#include <idt.h> | ||
#include <tss.h> | ||
|
||
// CPUID Leaf 1 ECX | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#pragma once | ||
|
||
#define ARCH_BITS 64 | ||
#define ARCH_MAX_PAGE_SIZE 0x1000 | ||
#define ARCH_BITS 64 | ||
#define ARCH_DEFAULT_PAGE_SIZE 0x1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.