The Pedigree Project 0.1
BootstrapInfo.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef KERNEL_BOOTSTRAPINFO_H
21#define KERNEL_BOOTSTRAPINFO_H
22#include "pedigree/kernel/compiler.h"
23#include "pedigree/kernel/processor/types.h"
24
25#include <config.h>
26
31
32extern BootstrapStruct_t* g_pBootstrapInfo EXPORTED_PUBLIC;
33
34#define BOOTSTRAP_FLAG_CMDLINE 0x001
35#define BOOTSTRAP_FLAG_MODULES 0x002
36#define BOOTSTRAP_FLAG_ELF 0x004
37#define BOOTSTRAP_FLAG_MEMORY_MAP 0x008
38#define BOOTSTRAP_FLAG_ACPI 0x010
39#define BOOTSTRAP_FLAG_SMBIOS 0x020
40#define BOOTSTRAP_FLAG_FRAMEBUFFER 0x040
41#define BOOTSTRAP_FLAG_UEFI 0x080
42
43#if HOSTED
44// Required to specify C linkage for the hosted bootstrap friend declaration.
45#if defined(__clang__)
46#pragma clang diagnostic push
47#pragma clang diagnostic ignored "-Wmain"
48#endif
49extern "C" int main(int argc, char* argv[]);
50#if defined(__clang__)
51#pragma clang diagnostic pop
52#endif
53#endif
54
55class EXPORTED_PUBLIC BootstrapStruct_t {
56#if HOSTED
57 friend int ::main(int argc, char* argv[]);
58#endif
59
60 public:
62
63 bool isInitrdLoaded() const;
64 uint8_t* getInitrdAddress() const;
65 size_t getInitrdSize() const;
66
67 char* getCommandLine() const;
68
69 size_t getSectionHeaderCount() const;
70 size_t getSectionHeaderEntrySize() const;
71 size_t getSectionHeaderStringTableIndex() const;
72 uintptr_t getSectionHeaders() const;
73
74 void* getMemoryMap() const;
75 uint64_t getMemoryMapEntryAddress(void* opaque) const;
76 uint64_t getMemoryMapEntryLength(void* opaque) const;
77 uint32_t getMemoryMapEntryType(void* opaque) const;
78 void* nextMemoryMapEntry(void* opaque) const;
79
80 size_t getModuleCount() const;
81 void* getModuleBase() const;
82
83 typedef uint64_t bootstrap_uintptr_t;
84
85 typedef struct {
86 bootstrap_uintptr_t base;
87 bootstrap_uintptr_t end;
88 bootstrap_uintptr_t name_ptr;
89 bootstrap_uintptr_t pad;
90 } PACKED Module;
91
92 typedef struct {
93 uint32_t size;
94 uint64_t address;
95 uint64_t length;
96 uint32_t type;
98
99 void setMemoryMap(const MemoryMapEntry* entries, size_t count);
100 void setModules(const Module* modules, size_t count);
101 void setCommandLine(const char* text);
102 void setUefi();
103 void setAcpiRsdp(uintptr_t address);
104
105 const Module* getModuleArray() const {
106 return reinterpret_cast<const Module*>(getModuleBase());
107 }
108
109 uintptr_t getAcpiRsdp() const;
110 uintptr_t getSmbios() const;
111 bool isUefi() const;
112
114 uint64_t address;
115 // Format 0 has red in the low byte; format 1 has blue in the low byte.
116 uint32_t width, height, pitch, bpp, format;
117 };
118 bool getFramebuffer(FramebufferInfo& info) const;
119
120 private:
121 uint32_t flags;
122 uint32_t reserved;
123 uint32_t mods_count;
124 bootstrap_uintptr_t mods_addr;
125 uint32_t num;
126 uint32_t size;
127 uint32_t shndx;
128 bootstrap_uintptr_t addr;
129 bootstrap_uintptr_t mmap_addr;
130 uint32_t mmap_length;
131 uint32_t mmap_entry_size;
132 bootstrap_uintptr_t cmdline;
133 bootstrap_uintptr_t acpi_rsdp;
134 bootstrap_uintptr_t smbios;
135 bootstrap_uintptr_t framebuffer;
136 uint32_t framebuffer_width;
137 uint32_t framebuffer_height;
138 uint32_t framebuffer_pitch;
139 uint32_t framebuffer_bpp;
140 uint32_t framebuffer_format;
141} PACKED;
142
145#endif