Implement routines for accessing and manipulating CPU control registers
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Rafal Kupiec 2022-12-02 23:03:42 +01:00
parent b275caf161
commit b89121fded
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
6 changed files with 531 additions and 9 deletions

70
sdk/xtdk/amd64/hlfuncs.h Normal file
View File

@ -0,0 +1,70 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: sdk/xtdk/amd64/hlfuncs.h
* DESCRIPTION: XT hardware abstraction layer routines specific to AMD64 architecture
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#ifndef __XTDK_AMD64_HLFUNCS_H
#define __XTDK_AMD64_HLFUNCS_H
#include "xtdefs.h"
#include "xtstruct.h"
#include "xttypes.h"
/* I/O port addresses for COM ports */
extern ULONG ComPortAddress[];
/* HAL library routines forward references */
XTAPI
UCHAR
HlIoPortInByte(IN USHORT Port);
XTAPI
VOID
HlIoPortOutByte(IN USHORT Port,
IN UCHAR Data);
XTAPI
ULONG_PTR
HlReadCR0();
XTAPI
ULONG_PTR
HlReadCR2();
XTAPI
ULONG_PTR
HlReadCR3();
XTAPI
ULONG_PTR
HlReadCR4();
XTAPI
ULONG_PTR
HlReadCR8();
XTAPI
VOID
HlWriteCR0(UINT_PTR Data);
XTAPI
VOID
HlWriteCR2(UINT_PTR Data);
XTAPI
VOID
HlWriteCR3(UINT_PTR Data);
XTAPI
VOID
HlWriteCR4(UINT_PTR Data);
XTAPI
VOID
HlWriteCR8(UINT_PTR Data);
#endif /* __XTDK_AMD64_HLFUNCS_H */

View File

@ -37,13 +37,4 @@ HlInitializeComPort(IN OUT PCPPORT Port,
IN ULONG PortNumber,
IN ULONG BaudRate);
XTAPI
UCHAR
HlIoPortInByte(IN USHORT Port);
XTAPI
VOID
HlIoPortOutByte(IN USHORT Port,
IN UCHAR Data);
#endif /* __XTDK_HLFUNCS_H */

62
sdk/xtdk/i686/hlfuncs.h Normal file
View File

@ -0,0 +1,62 @@
/**
* PROJECT: ExectOS
* COPYRIGHT: See COPYING.md in the top level directory
* FILE: sdk/xtdk/i686/hlfuncs.h
* DESCRIPTION: XT hardware abstraction layer routines specific to i686 architecture
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
*/
#ifndef __XTDK_I686_HLFUNCS_H
#define __XTDK_I686_HLFUNCS_H
#include "xtdefs.h"
#include "xtstruct.h"
#include "xttypes.h"
/* I/O port addresses for COM ports */
extern ULONG ComPortAddress[];
/* HAL library routines forward references */
XTAPI
UCHAR
HlIoPortInByte(IN USHORT Port);
XTAPI
VOID
HlIoPortOutByte(IN USHORT Port,
IN UCHAR Data);
XTAPI
ULONG_PTR
HlReadCR0();
XTAPI
ULONG_PTR
HlReadCR2();
XTAPI
ULONG_PTR
HlReadCR3();
XTAPI
ULONG_PTR
HlReadCR4();
XTAPI
VOID
HlWriteCR0(UINT_PTR Data);
XTAPI
VOID
HlWriteCR2(UINT_PTR Data);
XTAPI
VOID
HlWriteCR3(UINT_PTR Data);
XTAPI
VOID
HlWriteCR4(UINT_PTR Data);
#endif /* __XTDK_I686_HLFUNCS_H */

View File

@ -32,3 +32,6 @@
/* XT routines */
#include "hlfuncs.h"
#include "rtlfuncs.h"
/* Architecture specific XT routines*/
#include ARCH_HEADER(hlfuncs.h)

View File

@ -54,3 +54,223 @@ HlIoPortOutByte(IN USHORT Port,
"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;
}
/**
* Reads the CR8 register and returns its value.
*
* @return The value stored in the CR8 register.
*
* @since XT 1.0
*/
XTAPI
ULONG_PTR
HlReadCR8()
{
ULONG_PTR Value;
asm volatile("mov %%cr8, %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");
}
/**
* Writes the value to the CR8 register.
*
* @param Data
* The value to write to the CR8 register.
*
* @return This routine does not return any value.
*
* @since XT 1.0
*/
XTAPI
VOID
HlWriteCR8(UINT_PTR Data)
{
asm volatile("mov %0, %%cr8"
:
:
"r"(Data)
:
"memory");
}

View File

@ -54,3 +54,179 @@ HlIoPortOutByte(IN USHORT Port,
"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");
}