Nothing to see here, move along
1use crate::header::{KernelObjectHeader, NONE_SENTINEL};
2use crate::object_tag::ObjectTag;
3use crate::untyped::{self, UntypedState};
4
5pub trait KernelObject: Sized {
6 const TAG: ObjectTag;
7 const METADATA_SIZE: usize;
8 const METADATA_ALIGN: usize;
9
10 fn init_default(header: KernelObjectHeader) -> Self;
11}
12
13#[derive(Debug, Clone, Copy)]
14#[repr(C)]
15pub struct EndpointObject {
16 pub header: KernelObjectHeader,
17 pub sender_head: u16,
18 pub sender_tail: u16,
19 pub sender_len: u16,
20 pub receiver_head: u16,
21 pub receiver_tail: u16,
22 pub receiver_len: u16,
23 pub holder: u16,
24 pub _pad: [u8; 18],
25}
26
27const _: () = assert!(core::mem::size_of::<EndpointObject>() == 64);
28
29impl KernelObject for EndpointObject {
30 const TAG: ObjectTag = ObjectTag::Endpoint;
31 const METADATA_SIZE: usize = core::mem::size_of::<Self>();
32 const METADATA_ALIGN: usize = 64;
33
34 fn init_default(header: KernelObjectHeader) -> Self {
35 Self {
36 header,
37 sender_head: NONE_SENTINEL,
38 sender_tail: NONE_SENTINEL,
39 sender_len: 0,
40 receiver_head: NONE_SENTINEL,
41 receiver_tail: NONE_SENTINEL,
42 receiver_len: 0,
43 holder: NONE_SENTINEL,
44 _pad: [0; 18],
45 }
46 }
47}
48
49#[derive(Debug, Clone, Copy)]
50#[repr(C)]
51pub struct NotificationObject {
52 pub header: KernelObjectHeader,
53 pub word: u64,
54 pub waiters: [u16; 4],
55 pub waiter_count: u8,
56 pub _pad: [u8; 15],
57}
58
59const _: () = assert!(core::mem::size_of::<NotificationObject>() == 64);
60
61impl KernelObject for NotificationObject {
62 const TAG: ObjectTag = ObjectTag::Notification;
63 const METADATA_SIZE: usize = core::mem::size_of::<Self>();
64 const METADATA_ALIGN: usize = 64;
65
66 fn init_default(header: KernelObjectHeader) -> Self {
67 Self {
68 header,
69 word: 0,
70 waiters: [0xFFFF; 4],
71 waiter_count: 0,
72 _pad: [0; 15],
73 }
74 }
75}
76
77#[derive(Debug, Clone, Copy)]
78#[repr(C)]
79pub struct SchedContextObject {
80 pub header: KernelObjectHeader,
81 pub budget_us: u64,
82 pub period_us: u64,
83 pub remaining_us: u64,
84 pub replenish_remaining_us: u32,
85 pub attached_pid: u16,
86 pub priority: u8,
87 pub flags: u8,
88}
89
90const _: () = assert!(core::mem::size_of::<SchedContextObject>() == 64);
91
92impl KernelObject for SchedContextObject {
93 const TAG: ObjectTag = ObjectTag::SchedContext;
94 const METADATA_SIZE: usize = core::mem::size_of::<Self>();
95 const METADATA_ALIGN: usize = 64;
96
97 fn init_default(header: KernelObjectHeader) -> Self {
98 Self {
99 header,
100 budget_us: 0,
101 period_us: 0,
102 remaining_us: 0,
103 replenish_remaining_us: 0,
104 attached_pid: 0xFFFF,
105 priority: 0,
106 flags: 0,
107 }
108 }
109}
110
111#[derive(Debug, Clone, Copy)]
112#[repr(C)]
113pub struct UntypedObject {
114 pub header: KernelObjectHeader,
115 pub phys_base: u64,
116 pub watermark: u32,
117 pub child_count: u32,
118 pub first_child: u16,
119 pub size_bits: u8,
120 pub is_device: u8,
121 pub _pad: [u8; 12],
122}
123
124const _: () = assert!(core::mem::size_of::<UntypedObject>() == 64);
125
126impl KernelObject for UntypedObject {
127 const TAG: ObjectTag = ObjectTag::Untyped;
128 const METADATA_SIZE: usize = core::mem::size_of::<Self>();
129 const METADATA_ALIGN: usize = 64;
130
131 fn init_default(header: KernelObjectHeader) -> Self {
132 Self {
133 header,
134 phys_base: 0,
135 watermark: 0,
136 child_count: 0,
137 first_child: 0xFFFF,
138 size_bits: 0,
139 is_device: 0,
140 _pad: [0; 12],
141 }
142 }
143}
144
145impl UntypedObject {
146 pub const fn to_state(&self) -> UntypedState {
147 UntypedState::from_parts(
148 self.watermark,
149 self.size_bits,
150 self.is_device != 0,
151 self.child_count,
152 )
153 }
154
155 pub fn apply_state(&mut self, state: &UntypedState) {
156 self.watermark = state.watermark();
157 self.size_bits = state.size_bits();
158 self.is_device = match state.is_device() {
159 true => 1,
160 false => 0,
161 };
162 self.child_count = state.child_count();
163 }
164}
165
166#[derive(Debug, Clone, Copy)]
167#[repr(C)]
168pub struct IrqHandlerObject {
169 pub header: KernelObjectHeader,
170 pub vector: u8,
171 pub source_kind: u8,
172 pub port_base: u16,
173 pub port_count: u16,
174 pub _pad1: [u8; 2],
175 pub source_data: u32,
176 pub _pad2: [u8; 20],
177}
178
179const _: () = assert!(core::mem::size_of::<IrqHandlerObject>() == 64);
180
181impl KernelObject for IrqHandlerObject {
182 const TAG: ObjectTag = ObjectTag::IrqHandler;
183 const METADATA_SIZE: usize = core::mem::size_of::<Self>();
184 const METADATA_ALIGN: usize = 64;
185
186 fn init_default(header: KernelObjectHeader) -> Self {
187 Self {
188 header,
189 vector: 0,
190 source_kind: 0,
191 port_base: 0,
192 port_count: 0,
193 _pad1: [0; 2],
194 source_data: 0,
195 _pad2: [0; 20],
196 }
197 }
198}
199
200#[derive(Debug, Clone, Copy)]
201#[repr(C)]
202pub struct FramebufferObject {
203 pub header: KernelObjectHeader,
204 pub phys_addr: u64,
205 pub byte_size: u64,
206 pub width: u32,
207 pub height: u32,
208 pub pitch: u32,
209 pub bpp: u16,
210 pub _pad: [u8; 2],
211}
212
213const _: () = assert!(core::mem::size_of::<FramebufferObject>() == 64);
214
215impl KernelObject for FramebufferObject {
216 const TAG: ObjectTag = ObjectTag::Framebuffer;
217 const METADATA_SIZE: usize = core::mem::size_of::<Self>();
218 const METADATA_ALIGN: usize = 64;
219
220 fn init_default(header: KernelObjectHeader) -> Self {
221 Self {
222 header,
223 phys_addr: 0,
224 byte_size: 0,
225 width: 0,
226 height: 0,
227 pitch: 0,
228 bpp: 0,
229 _pad: [0; 2],
230 }
231 }
232}
233
234#[derive(Debug, Clone, Copy)]
235#[repr(C)]
236pub struct PciDeviceObject {
237 pub header: KernelObjectHeader,
238 pub device_table_idx: u8,
239 pub _pad: [u8; 31],
240}
241
242const _: () = assert!(core::mem::size_of::<PciDeviceObject>() == 64);
243
244impl KernelObject for PciDeviceObject {
245 const TAG: ObjectTag = ObjectTag::PciDevice;
246 const METADATA_SIZE: usize = core::mem::size_of::<Self>();
247 const METADATA_ALIGN: usize = 64;
248
249 fn init_default(header: KernelObjectHeader) -> Self {
250 Self {
251 header,
252 device_table_idx: 0,
253 _pad: [0; 31],
254 }
255 }
256}
257
258#[derive(Debug, Clone, Copy)]
259#[repr(C)]
260pub struct ProcessObject {
261 pub header: KernelObjectHeader,
262 pub pid: u16,
263 pub _pad: [u8; 30],
264}
265
266const _: () = assert!(core::mem::size_of::<ProcessObject>() == 64);
267
268impl KernelObject for ProcessObject {
269 const TAG: ObjectTag = ObjectTag::Process;
270 const METADATA_SIZE: usize = core::mem::size_of::<Self>();
271 const METADATA_ALIGN: usize = 64;
272
273 fn init_default(header: KernelObjectHeader) -> Self {
274 Self {
275 header,
276 pid: 0xFFFF,
277 _pad: [0; 30],
278 }
279 }
280}
281
282#[derive(Debug, Clone, Copy)]
283#[repr(C)]
284pub struct FrameObject {
285 pub header: KernelObjectHeader,
286 pub phys_addr: u64,
287 pub size_bits: u8,
288 pub _pad: [u8; 23],
289}
290
291const _: () = assert!(core::mem::size_of::<FrameObject>() == 64);
292
293impl KernelObject for FrameObject {
294 const TAG: ObjectTag = ObjectTag::Frame;
295 const METADATA_SIZE: usize = core::mem::size_of::<Self>();
296 const METADATA_ALIGN: usize = 64;
297
298 fn init_default(header: KernelObjectHeader) -> Self {
299 Self {
300 header,
301 phys_addr: 0,
302 size_bits: 12,
303 _pad: [0; 23],
304 }
305 }
306}
307
308#[derive(Debug, Clone, Copy)]
309#[repr(C)]
310pub struct CNodeObject {
311 pub header: KernelObjectHeader,
312 pub slots_phys: u64,
313 pub size_bits: u8,
314 pub frame_count: u8,
315 pub _pad: [u8; 22],
316}
317
318const _: () = assert!(core::mem::size_of::<CNodeObject>() == 64);
319
320impl KernelObject for CNodeObject {
321 const TAG: ObjectTag = ObjectTag::CNode;
322 const METADATA_SIZE: usize = core::mem::size_of::<Self>();
323 const METADATA_ALIGN: usize = 64;
324
325 fn init_default(header: KernelObjectHeader) -> Self {
326 Self {
327 header,
328 slots_phys: 0,
329 size_bits: 0,
330 frame_count: 0,
331 _pad: [0; 22],
332 }
333 }
334}
335
336macro_rules! assert_layout_matches {
337 ($obj:ty, $size:expr, $align:expr) => {
338 const _: () = assert!(<$obj>::METADATA_SIZE as u32 == $size);
339 const _: () = assert!(<$obj>::METADATA_ALIGN as u32 == $align);
340 };
341}
342
343assert_layout_matches!(EndpointObject, untyped::FIXED_OBJECT_SIZE, untyped::FIXED_OBJECT_ALIGN);
344assert_layout_matches!(NotificationObject, untyped::FIXED_OBJECT_SIZE, untyped::FIXED_OBJECT_ALIGN);
345assert_layout_matches!(SchedContextObject, untyped::FIXED_OBJECT_SIZE, untyped::FIXED_OBJECT_ALIGN);
346assert_layout_matches!(UntypedObject, untyped::FIXED_OBJECT_SIZE, untyped::FIXED_OBJECT_ALIGN);
347assert_layout_matches!(IrqHandlerObject, untyped::FIXED_OBJECT_SIZE, untyped::FIXED_OBJECT_ALIGN);
348assert_layout_matches!(FramebufferObject, untyped::FIXED_OBJECT_SIZE, untyped::FIXED_OBJECT_ALIGN);
349assert_layout_matches!(PciDeviceObject, untyped::FIXED_OBJECT_SIZE, untyped::FIXED_OBJECT_ALIGN);
350assert_layout_matches!(ProcessObject, untyped::FIXED_OBJECT_SIZE, untyped::FIXED_OBJECT_ALIGN);
351assert_layout_matches!(FrameObject, untyped::FIXED_OBJECT_SIZE, untyped::FIXED_OBJECT_ALIGN);
352assert_layout_matches!(CNodeObject, untyped::FIXED_OBJECT_SIZE, untyped::FIXED_OBJECT_ALIGN);