This commit is contained in:
Niklas Gollenstede
2025-10-31 22:37:36 +01:00
commit 174fe17e89
197 changed files with 79558 additions and 0 deletions

31
kernel/arch/core_ring.h Normal file
View File

@@ -0,0 +1,31 @@
#pragma once
#include "../types.h"
namespace Core {
/*! \brief Protection Rings
*/
namespace Ring {
/*! \brief Switch to Ring 3
*
* \param stackpointer usermode stack pointer
* \param kickoff pointer to function in user mode
* \param kickoff_parameter put in register for 1. function parameter
*/
[[gnu::noreturn]]
void switchToUsermode(void *stackpointer, void *kickoff,
void *kickoff_parameter);
/*! \brief Get current protection level
*
* \return current ring
*/
inline unsigned get() {
unsigned cs;
asm volatile("mov %%cs, %0\n\t" : "=r"(cs)::"memory");
return cs & 0b11; // last bits define the ring
}
} // namespace Ring
} // namespace Core