FreeNOS
IntelCore.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __LIBARCH_INTEL_CPU_H
19#define __LIBARCH_INTEL_CPU_H
20
21#include <Types.h>
22#include <Macros.h>
23#include "IntelIO.h"
24
41inline u64 timestamp()
42{
43 unsigned long long val;
44 asm volatile ("rdtsc\n" : "=A"(val));
45 return val;
46}
47
51#define cpu_reboot() \
52({ \
53 IntelIO io; \
54 io.outb(0x64, 0xfe); \
55})
56
64#define cpu_shutdown() \
65({ \
66 IntelIO io; \
67 io.outw(0xB004, 0x0 | 0x2000); \
68})
69
73#define idle() \
74 asm volatile ("hlt");
75
81#define ltr(sel) \
82({ \
83 u16 tr = sel; \
84 asm volatile ("ltr %0\n" :: "r"(tr)); \
85})
86
92#define tlb_flush(addr) \
93 asm volatile("invlpg (%0)" ::"r" (addr) : "memory")
94
98#define tlb_flush_all() \
99 asm volatile("mov %cr3, %eax\n" \
100 "mov %eax, %cr3\n")
101
107#define INTEL_DIVZERO 0
108#define INTEL_DEBUGEX 1
109#define INTEL_NMI 2
110#define INTEL_BREAKP 3
111#define INTEL_OVERFLOW 4
112#define INTEL_BOUNDS 5
113#define INTEL_OPCODE 6
114#define INTEL_DEVERR 7
115#define INTEL_DOUBLEF 8
116#define INTEL_COSEG 9
117#define INTEL_TSSERR 10
118#define INTEL_SEGERR 11
119#define INTEL_STACKERR 12
120#define INTEL_GENERR 13
121#define INTEL_PAGEFAULT 14
122#define INTEL_FLOATERR 16
123#define INTEL_ALIGNERR 17
124#define INTEL_MACHCHK 18
125#define INTEL_SIMD 19
126#define INTEL_VIRTERR 20
127
137#define INTEL_EFLAGS_DEFAULT (1 << 1)
138#define INTEL_EFLAGS_IRQ (1 << 9)
139
169
186
190typedef struct SegRegs
191{
192 /* Segments. */
194}
196
200typedef struct CPURegs
201{
203}
205
212typedef struct IRQRegs0
213{
215}
217
229typedef struct IRQRegs3
230{
232}
234
238typedef struct CPUState
239{
240 /* Segments. */
242
243 /* By pusha */
245
246 /* Vector/error arguments. */
248
249 /* Pushed by processor. */
251}
253
258{
259 public:
260
266 void logException(CPUState *state) const;
267
273 void logState(CPUState *state) const;
274
281 void logRegister(const char *name, u32 reg) const;
282
286 volatile u32 readCR2() const;
287
291 volatile u32 readCR3() const;
292
296 void writeCR3(u32 cr3) const;
297};
298
299#ifdef __KERNEL__
300
302extern Segment gdt[];
303
305extern TSS kernelTss;
306
308extern Address kernelPageDir[];
309
310#endif /* __KERNEL__ */
311
318#endif /* __LIBARCH_INTEL_CPU_H */
Intel CPU Core.
Definition IntelCore.h:258
volatile u32 readCR3() const
Read the CR3 register.
void writeCR3(u32 cr3) const
Write the CR3 register.
void logState(CPUState *state) const
Log the CPU state.
void logRegister(const char *name, u32 reg) const
Log a register.
void logException(CPUState *state) const
Log a CPU exception.
Definition IntelCore.cpp:26
volatile u32 readCR2() const
Read the CR2 register.
u64 timestamp()
Reads the CPU's timestamp counter.
Definition IntelCore.h:41
Address kernelPageDir[]
Kernel page directory.
TSS kernelTss
Task State Segment.
Segment gdt[]
Global Descriptor Table.
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned long Address
A memory address.
Definition Types.h:131
unsigned long long u64
Unsigned 64-bit number.
Definition Types.h:50
Structure represents the pusha/popa format.
Definition IntelCore.h:201
u32 ebp
Definition IntelCore.h:202
u32 eax
Definition IntelCore.h:202
u32 esi
Definition IntelCore.h:202
u32 esp0
Definition IntelCore.h:202
u32 edi
Definition IntelCore.h:202
u32 edx
Definition IntelCore.h:202
u32 ebx
Definition IntelCore.h:202
u32 ecx
Definition IntelCore.h:202
Contains all the CPU registers.
Definition ARMCore.h:244
u32 vector
Definition IntelCore.h:247
IRQRegs3 irq
Definition IntelCore.h:250
u32 error
Definition IntelCore.h:247
SegRegs seg
Definition IntelCore.h:241
CPURegs regs
Definition IntelCore.h:244
Privileged Interrupt Registers (ring 0)
Definition IntelCore.h:213
u32 eflags
Definition IntelCore.h:214
Unprivileged Interrupt Registers (ring 3)
Definition IntelCore.h:230
u32 eflags
Definition IntelCore.h:231
Segmentation registers.
Definition IntelCore.h:191
u32 ss0
Definition IntelCore.h:193
Segment descriptor used in the GDT.
Definition IntelCore.h:174
u32 privilege
Definition IntelCore.h:179
u32 baseMid
Definition IntelCore.h:177
u32 limitHigh
Definition IntelCore.h:181
u32 limitLow
Definition IntelCore.h:175
u32 baseLow
Definition IntelCore.h:176
u32 present
Definition IntelCore.h:180
u32 baseHigh
Definition IntelCore.h:183
u32 type
Definition IntelCore.h:178
u32 granularity
Definition IntelCore.h:182
Intel's Task State Segment.
Definition IntelCore.h:153
u32 es
Definition IntelCore.h:164
u32 edi
Definition IntelCore.h:163
u32 ecx
Definition IntelCore.h:161
u32 gs
Definition IntelCore.h:164
u32 esi
Definition IntelCore.h:163
u32 esp0
Definition IntelCore.h:155
u32 ss1
Definition IntelCore.h:156
u32 esp
Definition IntelCore.h:162
u32 ss2
Definition IntelCore.h:157
u32 edx
Definition IntelCore.h:161
u32 eax
Definition IntelCore.h:161
u32 fs
Definition IntelCore.h:164
u32 ss0
Definition IntelCore.h:155
u32 esp2
Definition IntelCore.h:157
u32 esp1
Definition IntelCore.h:156
u32 ebp
Definition IntelCore.h:162
u32 cs
Definition IntelCore.h:164
u32 bitmap
Definition IntelCore.h:166
u32 eip
Definition IntelCore.h:159
u32 cr3
Definition IntelCore.h:158
u32 backlink
Definition IntelCore.h:154
u32 ldt
Definition IntelCore.h:165
u32 ds
Definition IntelCore.h:164
u32 ebx
Definition IntelCore.h:161
u32 ss
Definition IntelCore.h:164
u32 eflags
Definition IntelCore.h:160