Xyris
0.5
regs.hpp
Go to the documentation of this file.
1
/**
2
* @file regs.hpp
3
* @author Keeton Feavel (
[email protected]
)
4
* @brief i686 control register definitions. C & C++ compatible header.
5
* @version 0.3
6
* @date 2019-12-10
7
*
8
* @copyright Copyright the Xyris Contributors (c) 2019
9
*
10
*/
11
#pragma once
12
#include <stdint.h>
13
#include <stddef.h>
14
15
/**
16
* @brief A structure definining values for all x86 registers.
17
* Cannot be namespaced due to C linkage and ASM interoperability
18
*/
19
struct
registers
{
20
uint32_t
ds
;
/* Data segment selector */
21
uint32_t
edi
,
esi
,
ebp
,
ignored
,
ebx
,
edx
,
ecx
,
eax
;
/* Pushed by pusha. */
22
uint32_t
int_num
,
err_code
;
/* Interrupt number and error code (if applicable) */
23
uint32_t
eip
,
cs
,
eflags
,
esp
,
ss
;
/* Pushed by the processor automatically */
24
}
__attribute__
((packed));
25
26
#ifdef __cplusplus
27
namespace
Registers {
28
#endif
29
30
struct
CR0
31
{
32
uint32_t
protectedMode
: 1;
// Protected mode?
33
uint32_t
monitorCoProcessor
: 1;
// Control the interaction of wait instruction?
34
uint32_t
emulation
: 1;
// Force all FPU operations to be emulated?
35
uint32_t
taskSwitched
: 1;
// Save the FPU task context?
36
uint32_t
extensionType
: 1;
// Is the external math coprocessor an 80287 or 80387?
37
uint32_t
numericError
: 1;
// FPU floating point error reporting?
38
uint32_t
reservedA
: 10;
// Reserved
39
uint32_t
writeProtection
: 1;
// Prevent the CPU from writing to read only pages?
40
uint32_t
reservedB
: 1;
// Reserved
41
uint32_t
alignmentMask
: 1;
// Automatic alignment checking?
42
uint32_t
reservedC
: 10;
// Reserved
43
uint32_t
nonWriteThrough
: 1;
// Disable write through caching?
44
uint32_t
cacheDisable
: 1;
// Cache disabled?
45
uint32_t
pagingEnable
: 1;
// Enable paging
46
}
__attribute__
((packed));
47
48
struct
CR2
49
{
50
uint32_t
pageFaultAddr
: 32;
// Address where page fault occured
51
}
__attribute__
((packed));
52
53
struct
CR3
54
{
55
uint32_t
ignoredA
: 3;
// Ignored
56
uint32_t
writeThrough
: 1;
// Page level write through
57
uint32_t
cacheDisable
: 1;
// Cache disable
58
uint32_t
ignoredB
: 7;
// Ignored
59
uint32_t
pageDir
: 20;
// Page directory physical address
60
}
__attribute__
((packed));
61
62
// A pointer to the array of interrupt handlers. Assembly instruction 'lidt' will read it
63
struct
IDTR
{
64
uint16_t
size
: 16;
65
uint32_t
base
: 32;
66
}
__attribute__
((packed));
67
68
// A pointer to the global descriptor table. Assembly 'lgdt' will read it.
69
struct
GDTR
{
70
uint16_t
size
: 16;
71
uint32_t
base
: 32;
72
}
__attribute__
((packed));
73
74
// Structure compile-time size checks
75
#ifdef __cplusplus
76
static_assert(
sizeof
(
struct
CR0
) == 4);
77
static_assert(
sizeof
(
struct
CR2
) == 4);
78
static_assert(
sizeof
(
struct
CR3
) == 4);
79
static_assert(
sizeof
(
struct
IDTR
) == 6);
80
static_assert(
sizeof
(
struct
GDTR
) == 6);
81
#endif
82
83
__attribute__
((always_inline))
84
static
inline
struct
CR0
readCR0(void)
85
{
86
struct
CR0
x;
87
asm
volatile
(
"mov %%cr0, %0"
:
"=r"
(x));
88
return
x;
89
}
90
91
__attribute__
((always_inline))
92
static
inline
void
writeCR0(
struct
CR0
x)
93
{
94
asm
volatile
(
"mov %0, %%cr0"
::
"r"
(x));
95
}
96
97
static
inline
struct
CR2
readCR2(void)
98
{
99
struct
CR2
x;
100
asm
volatile
(
"mov %%cr2, %0"
:
"=r"
(x));
101
return
x;
102
}
103
104
static
inline
struct
CR3
readCR3(void)
105
{
106
struct
CR3
x;
107
asm
volatile
(
"mov %%cr3, %0"
:
"=r"
(x));
108
return
x;
109
}
110
111
static
inline
void
writeCR3(
struct
CR3
x)
112
{
113
asm
volatile
(
"mov %0, %%cr3"
::
"r"
(x));
114
}
115
116
#ifdef __cplusplus
117
}
// !namespace Registers
118
#endif
registers::ecx
uint32_t ecx
Definition:
regs.hpp:21
registers::eflags
uint32_t eflags
Definition:
regs.hpp:23
CR3::ignoredB
uint32_t ignoredB
Definition:
regs.hpp:58
CR0::cacheDisable
uint32_t cacheDisable
Definition:
regs.hpp:44
IDTR::size
uint16_t size
Definition:
regs.hpp:64
CR0::nonWriteThrough
uint32_t nonWriteThrough
Definition:
regs.hpp:43
registers::esp
uint32_t esp
Definition:
regs.hpp:23
__attribute__
struct registers __attribute__((packed))
CR3::writeThrough
uint32_t writeThrough
Definition:
regs.hpp:56
CR0::reservedC
uint32_t reservedC
Definition:
regs.hpp:42
registers::ds
uint32_t ds
Definition:
regs.hpp:20
registers::ignored
uint32_t ignored
Definition:
regs.hpp:21
CR0::pagingEnable
uint32_t pagingEnable
Definition:
regs.hpp:45
registers::eax
uint32_t eax
Definition:
regs.hpp:21
CR2
Definition:
regs.hpp:48
registers::ebp
uint32_t ebp
Definition:
regs.hpp:21
registers::ss
uint32_t ss
Definition:
regs.hpp:23
CR0::numericError
uint32_t numericError
Definition:
regs.hpp:37
GDTR
Definition:
regs.hpp:69
registers::edi
uint32_t edi
Definition:
regs.hpp:21
IDTR
Definition:
regs.hpp:63
registers
A structure definining values for all x86 registers. Cannot be namespaced due to C linkage and ASM in...
Definition:
regs.hpp:19
CR2::pageFaultAddr
uint32_t pageFaultAddr
Definition:
regs.hpp:50
registers::eip
uint32_t eip
Definition:
regs.hpp:23
CR0::protectedMode
uint32_t protectedMode
Definition:
regs.hpp:32
CR0::emulation
uint32_t emulation
Definition:
regs.hpp:34
registers::err_code
uint32_t err_code
Definition:
regs.hpp:22
CR3::pageDir
uint32_t pageDir
Definition:
regs.hpp:59
GDTR::base
uint32_t base
Definition:
regs.hpp:71
registers::edx
uint32_t edx
Definition:
regs.hpp:21
CR0::writeProtection
uint32_t writeProtection
Definition:
regs.hpp:39
registers::esi
uint32_t esi
Definition:
regs.hpp:21
registers::ebx
uint32_t ebx
Definition:
regs.hpp:21
GDTR::size
uint16_t size
Definition:
regs.hpp:70
CR0
Definition:
regs.hpp:30
CR0::reservedB
uint32_t reservedB
Definition:
regs.hpp:40
registers::cs
uint32_t cs
Definition:
regs.hpp:23
CR0::monitorCoProcessor
uint32_t monitorCoProcessor
Definition:
regs.hpp:33
IDTR::base
uint32_t base
Definition:
regs.hpp:65
registers::int_num
uint32_t int_num
Definition:
regs.hpp:22
CR3
Definition:
regs.hpp:53
CR3::cacheDisable
uint32_t cacheDisable
Definition:
regs.hpp:57
CR0::alignmentMask
uint32_t alignmentMask
Definition:
regs.hpp:41
CR0::taskSwitched
uint32_t taskSwitched
Definition:
regs.hpp:35
CR0::reservedA
uint32_t reservedA
Definition:
regs.hpp:38
CR0::extensionType
uint32_t extensionType
Definition:
regs.hpp:36
CR3::ignoredA
uint32_t ignoredA
Definition:
regs.hpp:55
Kernel
Arch
i686
regs.hpp
Generated by
1.8.17