-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.zig
More file actions
199 lines (168 loc) · 4.8 KB
/
Copy pathapplication.zig
File metadata and controls
199 lines (168 loc) · 4.8 KB
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
191
192
193
194
195
196
197
198
199
// A semver-compatible versioning scheme.
pub const ApiVersion = extern struct {
// The major release version, i.e. 1.0.0...
version_major: u16,
// The minor release version, i.e. 1.1.0...
version_minor: u16,
// The patch release version, i.e. 1.1.1...
version_patch: u16,
// Whether this is a pre-release version.
pre_release: bool,
pub fn default() ApiVersion {
return ApiVersion{
.version_major = version_info.major,
.version_minor = version_info.minor,
.version_patch = version_info.patch,
.pre_release = version_info.pre_release,
};
}
};
pub const BootloaderConfig = extern struct {
api_version: ApiVersion,
mappings: SystemMap,
};
pub const Framebuffer = extern struct {
buffer_start: u64,
buffer_info: FramebufferInfo,
pub fn new(buffer_start: u64, buffer_info: FramebufferInfo) Framebuffer {
return Framebuffer{
.buffer_start = buffer_start,
.buffer_info = buffer_info,
};
}
pub fn createBuffer(self: *@This()) [*]u8 {
return @as([*]u8, @ptrFromInt(&self.buffer_start));
}
};
pub const FramebufferInfo = extern struct {
// The length of the buffer in bytes.
byte_length: usize,
// The width of the buffer displayed in pixels.
width: usize,
// The height of the buffer displayed in pixels.
height: usize,
// The format of the pixel to be displayed.
pixel_format: PixelFormat,
// The number of bytes used per pixel displayed.
bbp: usize,
// Number of pixels between the start of a line and the start of the next.
//
// Some framebuffers use additional padding at the end of a line, so this
// value might be larger than `horizontal_resolution`. It is
// therefore recommended to use this field for calculating the start address of a line.
stride: usize,
};
pub const PixelFormat = enum(u16) {
rgb = 0,
bgr = 1,
un8 = 2,
unknown = 3,
};
pub const BootInfo = extern struct {
api_version: ApiVersion,
memory_regions: [*]MemoryRegion,
framebuffer: ?Framebuffer,
physical_memory_offset: ?u64,
recursive_index: ?u16,
rdsp_address: ?u64,
tls_address: ?TlsTemplate,
ramdisk_address: ?u64,
ramdisk_length: u64,
kernel_address: u64,
kernel_length: u64,
kernel_image_offset: u64,
pub fn new(memory_regions: [*]MemoryRegion) BootInfo {
return BootInfo{
.api_version = ApiVersion.default(),
.memory_regions = memory_regions,
.framebuffer = null,
.physical_memory_offset = null,
.recursive_index = null,
.rdsp_address = null,
.tls_template = null,
.ramdisk_address = null,
.ramdisk_length = 0,
.kernel_address = 0,
.kernel_length = 0,
.kernel_image_offset = 0,
};
}
};
pub const MemoryRegion = extern struct {
start: u64,
end: u64,
kind: MemoryRegionKind,
pub fn empty() MemoryRegion {
return MemoryRegion{
.start = 0,
.end = 0,
.kind = MemoryRegionKind.bootloader,
};
}
pub fn clone(self: *@This()) MemoryRegion {
var new = MemoryRegion.empty();
new.start = self.start;
new.end = self.end;
new.kind = self.kind;
return new;
}
};
pub const MemoryRegionKind = enum(u16) {
usable = 0,
bootloader = 1,
unknown_uefi = 2,
unknown_legacy = 3,
};
pub const Kernel = extern struct {
address: usize,
};
pub const TlsTemplate = extern struct {
start_address: u64,
file_size: u64,
mem_size: u64,
};
pub const SystemMap = extern struct {
kernel_stack: Mapping,
boot_info: Mapping,
framebuffer: Mapping,
physical_memory: ?Mapping,
page_table_recursive: ?Mapping,
aslr: bool,
dynamic_range_start: ?Mapping,
dynamic_range_end: ?Mapping,
ramdisk_memory: Mapping,
pub fn default() SystemMap {
return SystemMap{
.kernel_stack = Mapping.dynamic(),
.boot_info = Mapping.dynamic(),
};
}
};
pub const Mapping = union(enum) {
address: u64,
dynmap: DynamicMapping,
pub fn dynamic() Mapping {
return Mapping{
.dynmap = DynamicMapping{},
};
}
pub fn fixed(address: u64) Mapping {
return Mapping{
.address = address,
};
}
pub fn serialise(self: *@This()) [9]u8 {
if (self.address == 0) {
return [9]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0 };
} else |addr| {
_ = addr; // TODO: fill in with `concat_1_8` function when generator is complete.
}
}
};
pub const DynamicMapping = extern struct{};
// IMPORTS //
const builtin = @import("builtin");
const std = @import("std");
// This is a module we generate within our build script and we add to the root module as an anonymous
// import so that we may use it here to check version compliance.
const version_info = @import("index.zig").version_info;