The Pedigree Project  0.1
BootstrapInfo.cc
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 #include "pedigree/kernel/BootstrapInfo.h"
21 #include "pedigree/kernel/compiler.h"
22 #include "pedigree/kernel/processor/types.h"
23 
24 #ifndef PPC_COMMON
25 
27 {
28  uint32_t size;
29  uint64_t address;
30  uint64_t length;
31  uint32_t type;
32 } PACKED;
33 
34 BootstrapStruct_t::BootstrapStruct_t()
35 {
36  flags = 0;
37 }
38 
39 bool BootstrapStruct_t::isInitrdLoaded() const
40 {
41  if (flags & MULTIBOOT_FLAG_MODS)
42  return (mods_count != 0);
43  else
44  return false;
45 }
46 
47 uint8_t *BootstrapStruct_t::getInitrdAddress() const
48 {
49  if (flags & MULTIBOOT_FLAG_MODS)
50  return reinterpret_cast<uint8_t *>(getModuleArray()[0].base);
51  else
52  return 0;
53 }
54 
55 size_t BootstrapStruct_t::getInitrdSize() const
56 {
57  if (flags & MULTIBOOT_FLAG_MODS)
58  return getModuleArray()[0].end - getModuleArray()[0].base;
59  else
60  return 0;
61 }
62 
63 bool BootstrapStruct_t::isDatabaseLoaded() const
64 {
65  if (flags & MULTIBOOT_FLAG_MODS)
66  return (mods_count > 1);
67  else
68  return 0;
69 }
70 
71 uint8_t *BootstrapStruct_t::getDatabaseAddress() const
72 {
73  if (flags & MULTIBOOT_FLAG_MODS)
74  return reinterpret_cast<uint8_t *>(getModuleArray()[1].base);
75  else
76  return 0;
77 }
78 
79 size_t BootstrapStruct_t::getDatabaseSize() const
80 {
81  if (flags & MULTIBOOT_FLAG_MODS)
82  return getModuleArray()[1].end - getModuleArray()[1].base;
83  else
84  return 0;
85 }
86 
87 char *BootstrapStruct_t::getCommandLine() const
88 {
89  if (flags & MULTIBOOT_FLAG_CMDLINE)
90  return reinterpret_cast<char *>(cmdline);
91  else
92  return 0;
93 }
94 
95 size_t BootstrapStruct_t::getSectionHeaderCount() const
96 {
97  if (flags & MULTIBOOT_FLAG_ELF)
98  return num;
99  else
100  return 0;
101 }
102 
103 size_t BootstrapStruct_t::getSectionHeaderEntrySize() const
104 {
105  if (flags & MULTIBOOT_FLAG_ELF)
106  return size;
107  else
108  return 0;
109 }
110 
111 size_t BootstrapStruct_t::getSectionHeaderStringTableIndex() const
112 {
113  if (flags & MULTIBOOT_FLAG_ELF)
114  return shndx;
115  else
116  return 0;
117 }
118 
119 uintptr_t BootstrapStruct_t::getSectionHeaders() const
120 {
121  if (flags & MULTIBOOT_FLAG_ELF)
122  return addr;
123  else
124  return 0;
125 }
126 
127 void *BootstrapStruct_t::getMemoryMap() const
128 {
129  if (flags & MULTIBOOT_FLAG_MMAP)
130  return reinterpret_cast<void *>(mmap_addr);
131  else
132  return 0;
133 }
134 
135 uint64_t BootstrapStruct_t::getMemoryMapEntryAddress(void *opaque) const
136 {
137  if (!opaque)
138  return 0;
139 
140  MemoryMapEntry_t *entry = reinterpret_cast<MemoryMapEntry_t *>(opaque);
141  return entry->address;
142 }
143 
144 uint64_t BootstrapStruct_t::getMemoryMapEntryLength(void *opaque) const
145 {
146  if (!opaque)
147  return 0;
148 
149  MemoryMapEntry_t *entry = reinterpret_cast<MemoryMapEntry_t *>(opaque);
150  return entry->length;
151 }
152 
153 uint32_t BootstrapStruct_t::getMemoryMapEntryType(void *opaque) const
154 {
155  if (!opaque)
156  return 0;
157 
158  MemoryMapEntry_t *entry = reinterpret_cast<MemoryMapEntry_t *>(opaque);
159  return entry->type;
160 }
161 
162 void *BootstrapStruct_t::nextMemoryMapEntry(void *opaque) const
163 {
164  if (!opaque)
165  return 0;
166 
167  MemoryMapEntry_t *entry = reinterpret_cast<MemoryMapEntry_t *>(opaque);
168  uintptr_t entry_addr = reinterpret_cast<uintptr_t>(opaque);
169  void *new_opaque = reinterpret_cast<void *>(entry_addr + entry->size + 4);
170 
171  if (reinterpret_cast<uintptr_t>(new_opaque) >= (mmap_addr + mmap_length))
172  return 0;
173  else
174  return new_opaque;
175 }
176 
177 size_t BootstrapStruct_t::getModuleCount() const
178 {
179  if (flags & MULTIBOOT_FLAG_MODS)
180  return mods_count;
181  else
182  return 0;
183 }
184 
185 void *BootstrapStruct_t::getModuleBase() const
186 {
187  if (flags & MULTIBOOT_FLAG_MODS)
188  return reinterpret_cast<void *>(mods_addr);
189  else
190  return 0;
191 }
192 
193 #endif