ptos/amd64+hal: intr: Add IRQL managmenet

Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
2026-07-13 03:54:22 +00:00
parent b1f30e1f72
commit 2081b15219
4 changed files with 88 additions and 2 deletions
+57
View File
@@ -7,6 +7,7 @@
*/ */
#include <hal/intr.h> #include <hal/intr.h>
#include <ke/bugcheck.h>
#include <machine/intr.h> #include <machine/intr.h>
#include <machine/idt.h> #include <machine/idt.h>
#include <ptdef.h> #include <ptdef.h>
@@ -14,6 +15,20 @@
/* Globals */ /* Globals */
static INTR_HANDLER HandlerTable[256]; static INTR_HANDLER HandlerTable[256];
/*
* Set a new IRQL
*/
static inline VOID
SetIrql(IRQL Irql)
{
ASMV(
"mov %0, %%cr8"
:
: "r" ((UQUAD)Irql)
: "memory"
);
}
UCHAR UCHAR
HalIntrRegister(INTR_HANDLER *Handler, BOOLEAN IsUser) HalIntrRegister(INTR_HANDLER *Handler, BOOLEAN IsUser)
{ {
@@ -56,3 +71,45 @@ HalIntrRegister(INTR_HANDLER *Handler, BOOLEAN IsUser)
/* No more vectors */ /* No more vectors */
return 0; return 0;
} }
IRQL
HalGetIrql(VOID)
{
UQUAD CurrentIrql;
ASMV(
"mov %%cr8, %0"
: "=r" (CurrentIrql)
:
: "memory"
);
return (IRQL)CurrentIrql;
}
IRQL
HalRaiseIrql(IRQL Irql)
{
IRQL CurrentIrql;
CurrentIrql = HalGetIrql();
if (Irql < CurrentIrql) {
KeBugCheck(BUGCHECK_IRQL_NOT_GTE, "got bad irql\n");
}
SetIrql(Irql);
return CurrentIrql;
}
IRQL
HalLowerIrql(IRQL Irql)
{
IRQL CurrentIrql;
CurrentIrql = HalGetIrql();
if (Irql > CurrentIrql) {
KeBugCheck(BUGCHECK_IRQL_NOT_LTE, "got bad irql\n");
}
return CurrentIrql;
}
+23
View File
@@ -52,4 +52,27 @@ typedef struct _INTR_HANDLER {
*/ */
UCHAR HalIntrRegister(INTR_HANDLER *Handler, BOOLEAN IsUser); UCHAR HalIntrRegister(INTR_HANDLER *Handler, BOOLEAN IsUser);
/*
* Returns the current IRQL
*/
IRQL HalGetIrql(VOID);
/*
* Raise the IRQL level to a higher level
*
* @Irql: IRQL to raise to
*
* Returns the previous IRQL
*/
IRQL HalRaiseIrql(IRQL Irql);
/*
* Lower the IRQL level to a lower level
*
* @Irql: IRQL to lower to
*
* Returns the previous IRQL
*/
IRQL HalLowerIrql(IRQL Irql);
#endif /* !_HAL_INTR_H_ */ #endif /* !_HAL_INTR_H_ */
+5 -1
View File
@@ -19,13 +19,17 @@
* @BUGCHECK_IO_ERROR: Fatal I/O error * @BUGCHECK_IO_ERROR: Fatal I/O error
* @BUGCHECK_UNBOUND_RESRC: Fatal unbound resource * @BUGCHECK_UNBOUND_RESRC: Fatal unbound resource
* @BUGCHECK_EXCEPTION: Fatal exception * @BUGCHECK_EXCEPTION: Fatal exception
* @BUGCHECK_IRQL_NOT_GTE: IRQL not greater than or equal
* @BUGCHECK_IRQL_NOT_LTE: IRQL not less than or equal
*/ */
typedef enum { typedef enum {
BUGCHECK_MISC, BUGCHECK_MISC,
BUGCHECK_OOM, BUGCHECK_OOM,
BUGCHECK_IO_ERROR, BUGCHECK_IO_ERROR,
BUGCHECK_UNBOUND_RESRC, BUGCHECK_UNBOUND_RESRC,
BUGCHECK_EXCEPTION BUGCHECK_EXCEPTION,
BUGCHECK_IRQL_NOT_GTE,
BUGCHECK_IRQL_NOT_LTE
} BUGCHECK_REASON; } BUGCHECK_REASON;
/* /*
+3 -1
View File
@@ -36,7 +36,9 @@ static CHAR *ReasonTable[] = {
[BUGCHECK_OOM] = "out of memory", [BUGCHECK_OOM] = "out of memory",
[BUGCHECK_IO_ERROR] = "i/o error", [BUGCHECK_IO_ERROR] = "i/o error",
[BUGCHECK_UNBOUND_RESRC] = "unbounded resource", [BUGCHECK_UNBOUND_RESRC] = "unbounded resource",
[BUGCHECK_EXCEPTION] = "fatal exception" [BUGCHECK_EXCEPTION] = "fatal exception",
[BUGCHECK_IRQL_NOT_GTE] = "irql not greater than or equal",
[BUGCHECK_IRQL_NOT_LTE] = "irql not less than or equal"
}; };
VOID VOID