multiboot 0.8.0

Library to access multiboot structures.
Documentation
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
extern crate core;
extern crate multiboot;

use core::mem;
use multiboot::information::{
    ColorInfoRgb, ColorInfoType, ElfSymbols, FramebufferTable, MemoryEntry, MemoryManagement,
    MemoryType, Module, Multiboot, MultibootInfo, PAddr, SymbolType,
};

struct Mem {
    string_buffer: [u8; 5],
    module_buffer: [u8; 16],
}

impl Mem {
    fn new() -> Self {
        Self {
            string_buffer: [0; 5],
            module_buffer: [0; 16],
        }
    }
}

impl MemoryManagement for Mem {
    unsafe fn paddr_to_slice(&self, _addr: PAddr, _size: usize) -> Option<&'static [u8]> {
        None
    }

    unsafe fn allocate(&mut self, length: usize) -> Option<(PAddr, &mut [u8])> {
        match length {
            5 => Some((0x12345678, &mut self.string_buffer)), // for our test string
            16 => Some((0xaaaaaaaa, &mut self.module_buffer)), // four our test module
            _ => None,
        }
    }

    unsafe fn deallocate(&mut self, addr: PAddr) {
        if addr != 0 {
            unimplemented!()
        }
    }
}

#[test]
/// Just create an empty struct.
fn empty() {
    let mut mem = Mem::new();
    let mut info = MultibootInfo::default();
    let mut multiboot = Multiboot::from_ref(&mut info, &mut mem);
    // this has no effect here, but it should still work
    multiboot.set_memory_bounds(None);
    multiboot.set_command_line(None);
    multiboot.set_modules(None);
    multiboot.set_symbols(None);
    multiboot.set_memory_regions(None);
    multiboot.set_boot_loader_name(None);
    multiboot.set_framebuffer_table(None);
    let expected: [u8; 120] = [
        0x00, 0x00, 0x00, 0x00, // flags
        0x00, 0x00, 0x00, 0x00, // mem_lower
        0x00, 0x00, 0x00, 0x00, // mem_upper
        0xff, 0xff, 0xff, 0xff, // boot_device
        0x00, 0x00, 0x00, 0x00, // cmdline
        0x00, 0x00, 0x00, 0x00, // mods_count
        0x00, 0x00, 0x00, 0x00, // mods_addr
        0x00, 0x00, 0x00, 0x00, // syms1
        0x00, 0x00, 0x00, 0x00, // syms2
        0x00, 0x00, 0x00, 0x00, // syms3
        0x00, 0x00, 0x00, 0x00, // syms4
        0x00, 0x00, 0x00, 0x00, // mmap_length
        0x00, 0x00, 0x00, 0x00, // mmap_addr
        0x00, 0x00, 0x00, 0x00, // drives_length
        0x00, 0x00, 0x00, 0x00, // drives_addr
        0x00, 0x00, 0x00, 0x00, // config_table
        0x00, 0x00, 0x00, 0x00, // boot_loader_name
        0x00, 0x00, 0x00, 0x00, // apm_table
        0x00, 0x00, 0x00, 0x00, // vbe_control_info
        0x00, 0x00, 0x00, 0x00, // vbe_mode_info
        0x00, 0x00, // vbe_mode
        0x00, 0x00, // vbe_interface_seg
        0x00, 0x00, // vbe_interface_off
        0x00, 0x00, // vbe_interface_len
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // framebuffer_addr
        0x00, 0x00, 0x00, 0x00, // framebuffer_pitch
        0x00, 0x00, 0x00, 0x00, // framebuffer_width
        0x00, 0x00, 0x00, 0x00, // framebuffer_height
        0x00, // framebuffer_bpp
        0x00, // framebuffer_type
        0x00, 0x00, // alignment
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // color_info
        0x00, 0x00, // alignment
    ];
    assert_eq!(multiboot_info_to_bytes(info), expected);
}

#[test]
/// Set memory bounds.
fn memory_bounds() {
    let mut mem = Mem::new();
    let mut info = MultibootInfo::default();
    let mut multiboot = Multiboot::from_ref(&mut info, &mut mem);
    multiboot.set_memory_bounds(Some((640, 8 * 1024)));
    let expected: [u8; 120] = [
        0x01, 0x00, 0x00, 0x00, // flags
        0x80, 0x02, 0x00, 0x00, // mem_lower
        0x00, 0x20, 0x00, 0x00, // mem_upper
        0xff, 0xff, 0xff, 0xff, // boot_device
        0x00, 0x00, 0x00, 0x00, // cmdline
        0x00, 0x00, 0x00, 0x00, // mods_count
        0x00, 0x00, 0x00, 0x00, // mods_addr
        0x00, 0x00, 0x00, 0x00, // syms1
        0x00, 0x00, 0x00, 0x00, // syms2
        0x00, 0x00, 0x00, 0x00, // syms3
        0x00, 0x00, 0x00, 0x00, // syms4
        0x00, 0x00, 0x00, 0x00, // mmap_length
        0x00, 0x00, 0x00, 0x00, // mmap_addr
        0x00, 0x00, 0x00, 0x00, // drives_length
        0x00, 0x00, 0x00, 0x00, // drives_addr
        0x00, 0x00, 0x00, 0x00, // config_table
        0x00, 0x00, 0x00, 0x00, // boot_loader_name
        0x00, 0x00, 0x00, 0x00, // apm_table
        0x00, 0x00, 0x00, 0x00, // vbe_control_info
        0x00, 0x00, 0x00, 0x00, // vbe_mode_info
        0x00, 0x00, // vbe_mode
        0x00, 0x00, // vbe_interface_seg
        0x00, 0x00, // vbe_interface_off
        0x00, 0x00, // vbe_interface_len
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // framebuffer_addr
        0x00, 0x00, 0x00, 0x00, // framebuffer_pitch
        0x00, 0x00, 0x00, 0x00, // framebuffer_width
        0x00, 0x00, 0x00, 0x00, // framebuffer_height
        0x00, // framebuffer_bpp
        0x00, // framebuffer_type
        0x00, 0x00, // alignment
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // color_info
        0x00, 0x00, // alignment
    ];
    assert_eq!(multiboot_info_to_bytes(info), expected);
}

#[test]
/// Also set the command line.
fn command_line() {
    let mut mem = Mem::new();
    let mut info = MultibootInfo::default();
    let mut multiboot = Multiboot::from_ref(&mut info, &mut mem);
    multiboot.set_command_line(Some("test"));
    let expected: [u8; 120] = [
        0x04, 0x00, 0x00, 0x00, // flags
        0x00, 0x00, 0x00, 0x00, // mem_lower
        0x00, 0x00, 0x00, 0x00, // mem_upper
        0xff, 0xff, 0xff, 0xff, // boot_device
        0x78, 0x56, 0x34, 0x12, // cmdline
        0x00, 0x00, 0x00, 0x00, // mods_count
        0x00, 0x00, 0x00, 0x00, // mods_addr
        0x00, 0x00, 0x00, 0x00, // syms1
        0x00, 0x00, 0x00, 0x00, // syms2
        0x00, 0x00, 0x00, 0x00, // syms3
        0x00, 0x00, 0x00, 0x00, // syms4
        0x00, 0x00, 0x00, 0x00, // mmap_length
        0x00, 0x00, 0x00, 0x00, // mmap_addr
        0x00, 0x00, 0x00, 0x00, // drives_length
        0x00, 0x00, 0x00, 0x00, // drives_addr
        0x00, 0x00, 0x00, 0x00, // config_table
        0x00, 0x00, 0x00, 0x00, // boot_loader_name
        0x00, 0x00, 0x00, 0x00, // apm_table
        0x00, 0x00, 0x00, 0x00, // vbe_control_info
        0x00, 0x00, 0x00, 0x00, // vbe_mode_info
        0x00, 0x00, // vbe_mode
        0x00, 0x00, // vbe_interface_seg
        0x00, 0x00, // vbe_interface_off
        0x00, 0x00, // vbe_interface_len
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // framebuffer_addr
        0x00, 0x00, 0x00, 0x00, // framebuffer_pitch
        0x00, 0x00, 0x00, 0x00, // framebuffer_width
        0x00, 0x00, 0x00, 0x00, // framebuffer_height
        0x00, // framebuffer_bpp
        0x00, // framebuffer_type
        0x00, 0x00, // alignment
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // color_info
        0x00, 0x00, // alignment
    ];
    assert_eq!(multiboot_info_to_bytes(info), expected);
    assert_eq!(mem.string_buffer, [0x74, 0x65, 0x73, 0x74, 0x00]); // 'test'
}

#[test]
/// Set modules.
fn modules() {
    let mut mem = Mem::new();
    let mut info = MultibootInfo::default();
    let mut multiboot = Multiboot::from_ref(&mut info, &mut mem);
    multiboot.set_modules(Some(&[Module::new(0x12345678, 0x87654321, Some("test"))]));
    let expected: [u8; 120] = [
        0x08, 0x00, 0x00, 0x00, // flags
        0x00, 0x00, 0x00, 0x00, // mem_lower
        0x00, 0x00, 0x00, 0x00, // mem_upper
        0xff, 0xff, 0xff, 0xff, // boot_device
        0x00, 0x00, 0x00, 0x00, // cmdline
        0x01, 0x00, 0x00, 0x00, // mods_count
        0xaa, 0xaa, 0xaa, 0xaa, // mods_addr
        0x00, 0x00, 0x00, 0x00, // syms1
        0x00, 0x00, 0x00, 0x00, // syms2
        0x00, 0x00, 0x00, 0x00, // syms3
        0x00, 0x00, 0x00, 0x00, // syms4
        0x00, 0x00, 0x00, 0x00, // mmap_length
        0x00, 0x00, 0x00, 0x00, // mmap_addr
        0x00, 0x00, 0x00, 0x00, // drives_length
        0x00, 0x00, 0x00, 0x00, // drives_addr
        0x00, 0x00, 0x00, 0x00, // config_table
        0x00, 0x00, 0x00, 0x00, // boot_loader_name
        0x00, 0x00, 0x00, 0x00, // apm_table
        0x00, 0x00, 0x00, 0x00, // vbe_control_info
        0x00, 0x00, 0x00, 0x00, // vbe_mode_info
        0x00, 0x00, // vbe_mode
        0x00, 0x00, // vbe_interface_seg
        0x00, 0x00, // vbe_interface_off
        0x00, 0x00, // vbe_interface_len
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // framebuffer_addr
        0x00, 0x00, 0x00, 0x00, // framebuffer_pitch
        0x00, 0x00, 0x00, 0x00, // framebuffer_width
        0x00, 0x00, 0x00, 0x00, // framebuffer_height
        0x00, // framebuffer_bpp
        0x00, // framebuffer_type
        0x00, 0x00, // alignment
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // color_info
        0x00, 0x00, // alignment
    ];
    assert_eq!(multiboot_info_to_bytes(info), expected);
    assert_eq!(mem.string_buffer, [0x74, 0x65, 0x73, 0x74, 0x00]); // 'test'
    assert_eq!(
        mem.module_buffer,
        [
            0x78, 0x56, 0x34, 0x12, // start
            0x21, 0x43, 0x65, 0x87, // end
            0x78, 0x56, 0x34, 0x12, // TEST_STR
            0x00, 0x00, 0x00, 0x00 // reserved
        ]
    );
}

#[test]
/// Set symbols.
fn symbols() {
    let mut mem = Mem::new();
    let mut info = MultibootInfo::default();
    let mut multiboot = Multiboot::from_ref(&mut info, &mut mem);
    multiboot.set_symbols(Some(SymbolType::Elf(ElfSymbols::from_addr(
        1, 8, 0x12345678, 0,
    ))));
    let expected: [u8; 120] = [
        0x20, 0x00, 0x00, 0x00, // flags
        0x00, 0x00, 0x00, 0x00, // mem_lower
        0x00, 0x00, 0x00, 0x00, // mem_upper
        0xff, 0xff, 0xff, 0xff, // boot_device
        0x00, 0x00, 0x00, 0x00, // cmdline
        0x00, 0x00, 0x00, 0x00, // mods_count
        0x00, 0x00, 0x00, 0x00, // mods_addr
        0x01, 0x00, 0x00, 0x00, // syms1
        0x08, 0x00, 0x00, 0x00, // syms2
        0x78, 0x56, 0x34, 0x12, // syms3
        0x00, 0x00, 0x00, 0x00, // syms4
        0x00, 0x00, 0x00, 0x00, // mmap_length
        0x00, 0x00, 0x00, 0x00, // mmap_addr
        0x00, 0x00, 0x00, 0x00, // drives_length
        0x00, 0x00, 0x00, 0x00, // drives_addr
        0x00, 0x00, 0x00, 0x00, // config_table
        0x00, 0x00, 0x00, 0x00, // boot_loader_name
        0x00, 0x00, 0x00, 0x00, // apm_table
        0x00, 0x00, 0x00, 0x00, // vbe_control_info
        0x00, 0x00, 0x00, 0x00, // vbe_mode_info
        0x00, 0x00, // vbe_mode
        0x00, 0x00, // vbe_interface_seg
        0x00, 0x00, // vbe_interface_off
        0x00, 0x00, // vbe_interface_len
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // framebuffer_addr
        0x00, 0x00, 0x00, 0x00, // framebuffer_pitch
        0x00, 0x00, 0x00, 0x00, // framebuffer_width
        0x00, 0x00, 0x00, 0x00, // framebuffer_height
        0x00, // framebuffer_bpp
        0x00, // framebuffer_type
        0x00, 0x00, // alignment
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // color_info
        0x00, 0x00, // alignment
    ];
    assert_eq!(multiboot_info_to_bytes(info), expected);
}

#[test]
/// Set memory regions.
fn mmap() {
    let mut mem = Mem::new();
    let mut info = MultibootInfo::default();
    let mut multiboot = Multiboot::from_ref(&mut info, &mut mem);
    multiboot.set_memory_regions(Some((0x12345678, 1)));
    let expected: [u8; 120] = [
        0x40, 0x00, 0x00, 0x00, // flags
        0x00, 0x00, 0x00, 0x00, // mem_lower
        0x00, 0x00, 0x00, 0x00, // mem_upper
        0xff, 0xff, 0xff, 0xff, // boot_device
        0x00, 0x00, 0x00, 0x00, // cmdline
        0x00, 0x00, 0x00, 0x00, // mods_count
        0x00, 0x00, 0x00, 0x00, // mods_addr
        0x00, 0x00, 0x00, 0x00, // syms1
        0x00, 0x00, 0x00, 0x00, // syms2
        0x00, 0x00, 0x00, 0x00, // syms3
        0x00, 0x00, 0x00, 0x00, // syms4
        0x18, 0x00, 0x00, 0x00, // mmap_length
        0x78, 0x56, 0x34, 0x12, // mmap_addr
        0x00, 0x00, 0x00, 0x00, // drives_length
        0x00, 0x00, 0x00, 0x00, // drives_addr
        0x00, 0x00, 0x00, 0x00, // config_table
        0x00, 0x00, 0x00, 0x00, // boot_loader_name
        0x00, 0x00, 0x00, 0x00, // apm_table
        0x00, 0x00, 0x00, 0x00, // vbe_control_info
        0x00, 0x00, 0x00, 0x00, // vbe_mode_info
        0x00, 0x00, // vbe_mode
        0x00, 0x00, // vbe_interface_seg
        0x00, 0x00, // vbe_interface_off
        0x00, 0x00, // vbe_interface_len
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // framebuffer_addr
        0x00, 0x00, 0x00, 0x00, // framebuffer_pitch
        0x00, 0x00, 0x00, 0x00, // framebuffer_width
        0x00, 0x00, 0x00, 0x00, // framebuffer_height
        0x00, // framebuffer_bpp
        0x00, // framebuffer_type
        0x00, 0x00, // alignment
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // color_info
        0x00, 0x00, // alignment
    ];
    assert_eq!(multiboot_info_to_bytes(info), expected);
    let memory_entry = MemoryEntry::new(0x12345678, 4096, MemoryType::Defect);
    let expected_entry: [u8; 24] = [
        0x14, 0x00, 0x00, 0x00, // size
        0x78, 0x56, 0x34, 0x12, 0x00, 0x00, 0x00, 0x00, // base_addr
        0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // length
        0x05, 0x00, 0x00, 0x00, // type
    ];
    assert_eq!(
        unsafe { mem::transmute::<_, [u8; 24]>(memory_entry) },
        expected_entry
    );
}

#[test]
/// Also set the boot loader name.
fn boot_loader_name() {
    let mut mem = Mem::new();
    let mut info = MultibootInfo::default();
    let mut multiboot = Multiboot::from_ref(&mut info, &mut mem);
    multiboot.set_boot_loader_name(Some("test"));
    let expected: [u8; 120] = [
        0x00, 0x02, 0x00, 0x00, // flags
        0x00, 0x00, 0x00, 0x00, // mem_lower
        0x00, 0x00, 0x00, 0x00, // mem_upper
        0xff, 0xff, 0xff, 0xff, // boot_device
        0x00, 0x00, 0x00, 0x00, // cmdline
        0x00, 0x00, 0x00, 0x00, // mods_count
        0x00, 0x00, 0x00, 0x00, // mods_addr
        0x00, 0x00, 0x00, 0x00, // syms1
        0x00, 0x00, 0x00, 0x00, // syms2
        0x00, 0x00, 0x00, 0x00, // syms3
        0x00, 0x00, 0x00, 0x00, // syms4
        0x00, 0x00, 0x00, 0x00, // mmap_length
        0x00, 0x00, 0x00, 0x00, // mmap_addr
        0x00, 0x00, 0x00, 0x00, // drives_length
        0x00, 0x00, 0x00, 0x00, // drives_addr
        0x00, 0x00, 0x00, 0x00, // config_table
        0x78, 0x56, 0x34, 0x12, // boot_loader_name
        0x00, 0x00, 0x00, 0x00, // apm_table
        0x00, 0x00, 0x00, 0x00, // vbe_control_info
        0x00, 0x00, 0x00, 0x00, // vbe_mode_info
        0x00, 0x00, // vbe_mode
        0x00, 0x00, // vbe_interface_seg
        0x00, 0x00, // vbe_interface_off
        0x00, 0x00, // vbe_interface_len
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // framebuffer_addr
        0x00, 0x00, 0x00, 0x00, // framebuffer_pitch
        0x00, 0x00, 0x00, 0x00, // framebuffer_width
        0x00, 0x00, 0x00, 0x00, // framebuffer_height
        0x00, // framebuffer_bpp
        0x00, // framebuffer_type
        0x00, 0x00, // alignment
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // color_info
        0x00, 0x00, // alignment
    ];
    assert_eq!(multiboot_info_to_bytes(info), expected);
    assert_eq!(mem.string_buffer, [0x74, 0x65, 0x73, 0x74, 0x00]); // 'test'
}

#[test]
/// Set framebuffer information.
fn framebuffer() {
    let mut mem = Mem::new();
    let mut info = MultibootInfo::default();
    let mut multiboot = Multiboot::from_ref(&mut info, &mut mem);
    multiboot.set_framebuffer_table(Some(FramebufferTable::new(
        0x12345678,
        800 * 4,
        800,
        600,
        32,
        ColorInfoType::Rgb(ColorInfoRgb {
            red_field_position: 0,
            red_mask_size: 8,
            green_field_position: 8,
            green_mask_size: 8,
            blue_field_position: 16,
            blue_mask_size: 8,
        }),
    )));
    let expected: [u8; 120] = [
        0x00, 0x10, 0x00, 0x00, // flags
        0x00, 0x00, 0x00, 0x00, // mem_lower
        0x00, 0x00, 0x00, 0x00, // mem_upper
        0xff, 0xff, 0xff, 0xff, // boot_device
        0x00, 0x00, 0x00, 0x00, // cmdline
        0x00, 0x00, 0x00, 0x00, // mods_count
        0x00, 0x00, 0x00, 0x00, // mods_addr
        0x00, 0x00, 0x00, 0x00, // syms1
        0x00, 0x00, 0x00, 0x00, // syms2
        0x00, 0x00, 0x00, 0x00, // syms3
        0x00, 0x00, 0x00, 0x00, // syms4
        0x00, 0x00, 0x00, 0x00, // mmap_length
        0x00, 0x00, 0x00, 0x00, // mmap_addr
        0x00, 0x00, 0x00, 0x00, // drives_length
        0x00, 0x00, 0x00, 0x00, // drives_addr
        0x00, 0x00, 0x00, 0x00, // config_table
        0x00, 0x00, 0x00, 0x00, // boot_loader_name
        0x00, 0x00, 0x00, 0x00, // apm_table
        0x00, 0x00, 0x00, 0x00, // vbe_control_info
        0x00, 0x00, 0x00, 0x00, // vbe_mode_info
        0x00, 0x00, // vbe_mode
        0x00, 0x00, // vbe_interface_seg
        0x00, 0x00, // vbe_interface_off
        0x00, 0x00, // vbe_interface_len
        0x78, 0x56, 0x34, 0x12, 0x00, 0x00, 0x00, 0x00, // framebuffer_addr
        0x80, 0x0c, 0x00, 0x00, // framebuffer_pitch
        0x20, 0x03, 0x00, 0x00, // framebuffer_width
        0x58, 0x02, 0x00, 0x00, // framebuffer_height
        0x20, // framebuffer_bpp
        0x01, // framebuffer_type
        0x00, 0x00, // alignment
        0x00, 0x08, 0x08, 0x08, 0x10, 0x08, // color_info
        0x00, 0x00, // alignment
    ];
    assert_eq!(multiboot_info_to_bytes(info), expected);
}

fn multiboot_info_to_bytes(info: MultibootInfo) -> [u8; 120] {
    assert_eq!(mem::size_of::<MultibootInfo>(), 120);

    let mut bytes = [0; 120];

    let info_bytes: [u8; 120] = unsafe { mem::transmute(info) };
    for (index, byte) in info_bytes.iter().enumerate() {
        // ignore padding bytes
        if ![0x6E, 0x6F, 0x76, 0x77].contains(&index) {
            bytes[index] = *byte;
        }
    }

    bytes
}