-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHandOverState.hpp
190 lines (158 loc) · 3.88 KB
/
HandOverState.hpp
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#pragma once
#include <common/inttypes.hpp>
#include <interrupts/RegisterState.hpp>
#include <processes/UserApi.hpp>
namespace hos_v1 {
enum class MappingSource : uint32_t {
ANONYMOUS = 1, PHYSICAL = 2, DMA = 3,
};
enum class Permissions : uint32_t {
READ_WRITE = 1, READ_EXECUTE = 2, READ_WRITE_EXECUTE = 3, READ = 4, INVALID = 5
};
enum ThreadPriority : uint32_t {
IDLE, BACKGROUND, FOREGROUND, INTERACTIVE_FOREGROUND,
};
enum FramebufferFormat : uint32_t {
RGB = 1, BGR = 2
};
enum FramebufferType : uint32_t {
NO_FRAMEBUFFER = 1, SIMPLE_FRAMEBUFFER = 2,
};
enum SerialType : uint32_t {
NO_SERIAL = 1, PC = 2, PRIMECELL_PL011 = 3,
};
enum FirmwareType : uint32_t {
ACPI = 1, DTB = 2
};
enum class HandleType : uint32_t {
INVALID, FREE, PORT, REMOTE_PORT, THREAD, MEMORY_AREA, INTERRUPT, EVENT_QUEUE
};
/* TODO: other architectures */
enum DMAZone {
BITS32 = 0, BITS64, COUNT
};
static const size_t DMAZoneMax[DMAZone::COUNT] = {(1ul << 32) - 1, static_cast<size_t>(-1)};
static const size_t FRAME_ID_NONE = static_cast<size_t>(-1);
static const size_t FUTEX_FRAME_ID_NONE = 0;
struct Frame {
size_t address;
size_t copyOnWriteCount;
bool isForPhysicalAccess;
};
struct MemoryArea {
size_t *frameIDs;
uint64_t *futexIDs;
MappingSource source;
bool isShared;
Permissions permissions;
size_t length;
};
struct MappedArea {
size_t memoryAreaID;
size_t offset;
size_t start;
size_t length;
Permissions permissions;
};
struct Thread {
RegisterState registerState;
size_t tlsPointer;
ThreadPriority currentPriority;
ThreadPriority ownPriority;
};
struct Futex {
uint64_t id;
size_t numWaitingThreads;
size_t *waitingThreadIDs;
};
struct Handle {
HandleType type;
uint32_t handle;
size_t objectID;
};
struct EventQueue {
size_t numWaitingThreads;
size_t *waitingThreadIDs;
size_t numEvents;
userApi::ZoEventInfo *events;
};
struct Port {
size_t tag;
size_t eventQueueID;
};
struct Process {
size_t numMappedAreas;
MappedArea *mappedAreas;
size_t numLocalFutexes;
Futex *localFutexes;
size_t numHandles;
Handle *handles;
size_t numLogNameChars;
char *logName;
};
struct FramebufferInfo {
uint32_t type;
uint8_t *frontBuffer;
uint8_t *backBuffer;
uint32_t width;
uint32_t height;
uint32_t bytesPerPixel;
uint32_t bytesPerLine;
uint32_t format;
uint32_t scaleFactor;
};
struct SerialInfo {
uint32_t type;
size_t baseAddress;
size_t memoryLength;
};
struct FrameStack {
void *head;
size_t addIndex;
};
struct PagingContext {
#if defined(__x86_64__)
PhysicalAddress root;
#elif defined(__aarch64__)
PhysicalAddress lowRoot;
PhysicalAddress highRoot;
#endif
};
struct FirmwareInfo {
FirmwareType type;
PhysicalAddress rootAddress;
size_t regionLength;
};
struct System {
size_t version;
FramebufferInfo framebufferInfo;
SerialInfo serialInfo;
FrameStack freshFrameStack[DMAZone::COUNT];
FrameStack usedFrameStack[DMAZone::COUNT];
PagingContext handOverPagingContext;
FirmwareInfo firmwareInfo;
/* TODO: a way to pass time offset to APIC timer */
size_t numProcesses;
Process *processes;
/* This list should not include the idle Threads. These are re-created when the new scheduler
* objects are created. Their code is part of kernel code so their state would be invalid after
* kernel handover! */
size_t numThreads;
Thread *threads;
size_t numPorts;
Port *ports;
size_t numMemoryAreas;
MemoryArea *memoryAreas;
size_t numFrames;
Frame *frames;
size_t numEventQueues;
EventQueue *eventQueues;
uint64_t timerFrequency;
size_t numProcessors;
size_t numFutexes;
Futex *futexes;
/* not 0, multiple of PAGE_SIZE */
size_t nextFutexFrameID;
void decodeProcesses();
};
}