1 /*
2  * Copyright (c) 2024 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #pragma once
9 
10 #include <stdint.h>
11 
12 // parse bootinfo
13 struct bootinfo_item {
14     uint16_t tag;
15     uint16_t size;
16     uint32_t data[0];
17 };
18 
19 // bootinfo tags (from QEMU)
20 enum BOOTINFO_TAGS {
21     BOOTINFO_TAG_END = 0,
22     BOOTINFO_TAG_MACHTYPE = 1,
23     BOOTINFO_TAG_CPUTYPE = 2,
24     BOOTINFO_TAG_FPUTYPE = 3,
25     BOOTINFO_TAG_MMUTYPE = 4,
26     BOOTINFO_TAG_MEMCHUNK = 5,
27     BOOTINFO_TAG_RAMDISK = 6,
28     BOOTINFO_TAG_COMMAND_LINE = 7,
29     BOOTINFO_TAG_RNG_SEED = 8,
30     BOOTINFO_TAG_VIRT_QEMU_VERSION = 0x8000,
31     BOOTINFO_TAG_VIRT_GF_PIC_BASE = 0x8001,
32     BOOTINFO_TAG_VIRT_GF_RTC_BASE = 0x8002,
33     BOOTINFO_TAG_VIRT_GF_TTY_BASE = 0x8003,
34     BOOTINFO_TAG_VIRT_VIRTIO_BASE = 0x8004,
35     BOOTINFO_TAG_VIRT_CTRL_BASE = 0x8005,
36 };
37 
38 void dump_all_bootinfo_records(void);
39 const void *bootinfo_find_record(uint16_t id, uint16_t *size_out);
40 
41 // for BOOTINFO_TAG_*TYPE tags
42 struct bootinfo_item_type {
43     uint32_t type;
44 };
45 
46 // for BOOTINFO_TAG_VIRT_QEMU_VERSION
47 struct bootinfo_item_qemu_version {
48     uint8_t major;
49     uint8_t minor;
50     uint8_t micro;
51     uint8_t unused__;
52 };
53 
54 // for BOOTINFO_TAG_MEMCHUNK
55 struct bootinfo_item_memchunk {
56     uint32_t base;
57     uint32_t size;
58 };
59 
60 // for VIRT_*_BASE tags
61 struct bootinfo_item_device {
62     uint32_t base;
63     uint32_t irq_base;
64 };