exectos/xtoskrnl/hl/i686/cpufunc.c
belliash b89121fded
All checks were successful
ci/woodpecker/push/build Pipeline was successful
Implement routines for accessing and manipulating CPU control registers
2022-12-02 23:03:42 +01:00

233 lines
4.0 KiB
C

/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: xtoskrnl/hl/i686/cpufunc.c
* DESCRIPTION: Routines to provide access to special i686 CPU instructions
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#include "xtkmapi.h"
/**
* Reads the data from the specified I/O port.
*
* @param Port
* Specifies the port number in the range of 0-0xFFFF.
*
* @return The value read from the port.
*
* @since XT 1.0
*/
XTAPI
UCHAR
HlIoPortInByte(IN USHORT Port)
{
UCHAR Value;
asm volatile("inb %1, %0"
: "=a"(Value)
: "Nd"(Port));
return Value;
}
/**
* Writes the data to the specified I/O port.
*
* @param Port
* Specifies the port number in the range of 0-0xFFFF.
*
* @param Value
* Supplies the value to write.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HlIoPortOutByte(IN USHORT Port,
IN UCHAR Value)
{
asm volatile("outb %0, %1"
:
:
"a"(Value),
"Nd"(Port));
}
/**
* Reads the CR0 register and returns its value.
*
* @return The value stored in the CR0 register.
*
* @since XT 1.0
*/
XTAPI
ULONG_PTR
HlReadCR0()
{
ULONG_PTR Value;
asm volatile("mov %%cr0, %0"
:
"=r"
(Value)
:
:
"memory");
return Value;
}
/**
* Reads the CR2 register and returns its value.
*
* @return The value stored in the CR2 register.
*
* @since XT 1.0
*/
XTAPI
ULONG_PTR
HlReadCR2()
{
ULONG_PTR Value;
asm volatile("mov %%cr2, %0"
:
"=r"
(Value)
:
:
"memory");
return Value;
}
/**
* Reads the CR3 register and returns its value.
*
* @return The value stored in the CR3 register.
*
* @since XT 1.0
*/
XTAPI
ULONG_PTR
HlReadCR3()
{
ULONG_PTR Value;
asm volatile("mov %%cr3, %0"
:
"=r"
(Value)
:
:
"memory");
return Value;
}
/**
* Reads the CR4 register and returns its value.
*
* @return The value stored in the CR4 register.
*
* @since XT 1.0
*/
XTAPI
ULONG_PTR
HlReadCR4()
{
ULONG_PTR Value;
asm volatile("mov %%cr4, %0"
:
"=r"
(Value)
:
:
"memory");
return Value;
}
/**
* Writes the value to the CR0 register.
*
* @param Data
* The value to write to the CR0 register.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HlWriteCR0(UINT_PTR Data)
{
asm volatile("mov %0, %%cr0"
:
:
"r"(Data)
:
"memory");
}
/**
* Writes the value to the CR2 register.
*
* @param Data
* The value to write to the CR2 register.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HlWriteCR2(UINT_PTR Data)
{
asm volatile("mov %0, %%cr2"
:
:
"r"(Data)
:
"memory");
}
/**
* Writes the value to the CR3 register.
*
* @param Data
* The value to write to the CR3 register.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HlWriteCR3(UINT_PTR Data)
{
asm volatile("mov %0, %%cr3"
:
:
"r"(Data)
:
"memory");
}
/**
* Writes the value to the CR4 register.
*
* @param Data
* The value to write to the CR4 register.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HlWriteCR4(UINT_PTR Data)
{
asm volatile("mov %0, %%cr4"
:
:
"r"(Data)
:
"memory");
}