blob: 98d642157ecc1356e2e6afb9ab34130319699bc0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/* -------------------------------------------
Copyright Mahrouss Logic
------------------------------------------- */
#include <Builtins/ACPI/ACPIFactoryInterface.hxx>
#include <HALKit/AMD64/Processor.hpp>
///////////////////////////////////////////////////////////////////////////////////////
//! NOTE: fGSI stands 'Field Global System Interrupt'
///////////////////////////////////////////////////////////////////////////////////////
namespace NewOS::HAL {
constexpr Int32 kThreadAPIC = 0;
constexpr Int32 kThreadLAPIC = 1;
constexpr Int32 kThreadIOAPIC = 2;
constexpr Int32 kThreadAPIC64 = 3;
constexpr Int32 kThreadBoot = 4;
/*
*
* this is used to store info about the current running thread
* we use this struct to determine if we can use it, or mark it as used or on
* sleep.
*
*/
struct ProcessorInfoAMD64 final {
Int32 ThreadType;
UIntPtr JumpAddress;
struct {
UInt32 Code;
UInt32 Data;
UInt32 BSS;
} Selector;
};
STATIC voidPtr kApicMadt = nullptr;
STATIC const char* kApicSignature = "APIC";
/// @brief Multiple APIC descriptor table.
struct MadtType final : public SDT {
struct MadtAddress final {
UInt32 fPhysicalAddress;
UInt32 fFlags; // 1 = Dual Legacy PICs installed
Char fType;
Char fRecLen; // record length
};
};
struct MadtProcessorLocalApic final {
Char fProcessorId;
Char fApicId;
UInt32 fFlags;
};
struct MadtIOApic final {
Char fApicId;
Char fReserved;
UInt32 fAddress;
UInt32 fSystemInterruptBase;
};
struct MadtInterruptSource final {
Char fBusSource;
Char fIrqSource;
UInt32 fGSI;
UInt16 fFlags;
};
struct MadtInterruptNmi final {
Char fNmiSource;
Char fReserved;
UInt16 fFlags;
UInt32 fGSI;
};
struct MadtLocalApicAddressOverride final {
UInt16 fResvered;
UIntPtr fAddress;
};
///////////////////////////////////////////////////////////////////////////////////////
STATIC MadtType* kApicInfoBlock = nullptr;
///////////////////////////////////////////////////////////////////////////////////////
void hal_system_get_cores(voidPtr rsdPtr) {
kcout << "NewOS: Constructing ACPIFactoryInterface...\r\n";
auto acpi = ACPIFactoryInterface(rsdPtr);
kApicMadt = acpi.Find(kApicSignature).Leak().Leak();
MUST_PASS(kApicMadt); // MADT must exist.
kcout << "NewOS: Successfuly fetched the MADT!\r\n";
kApicInfoBlock = (MadtType*)kApicMadt;
}
} // namespace NewOS::HAL
///////////////////////////////////////////////////////////////////////////////////////
|