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 
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/processor/types.h"
25 
29 // Again, if we're passed via grub these multiboot #defines will be valid,
30 // otherwise they won't.
31 #if defined(MULTIBOOT)
32 #define MULTIBOOT_FLAG_MEM 0x001
33 #define MULTIBOOT_FLAG_DEVICE 0x002
34 #define MULTIBOOT_FLAG_CMDLINE 0x004
35 #define MULTIBOOT_FLAG_MODS 0x008
36 #define MULTIBOOT_FLAG_AOUT 0x010
37 #define MULTIBOOT_FLAG_ELF 0x020
38 #define MULTIBOOT_FLAG_MMAP 0x040
39 #define MULTIBOOT_FLAG_CONFIG 0x080
40 #define MULTIBOOT_FLAG_LOADER 0x100
41 #define MULTIBOOT_FLAG_APM 0x200
42 #define MULTIBOOT_FLAG_VBE 0x400
43 #endif
44 
45 extern class BootstrapStruct_t *g_pBootstrapInfo EXPORTED_PUBLIC;
46 
47 #ifdef MULTIBOOT
48 
49 // Required to specify linkage of the 'main' symbol for the friend declaration.
50 extern "C" int main(int argc, char *argv[]);
51 
53 {
54 #ifdef HOSTED
55  friend int ::main(int argc, char *argv[]);
56 #endif
57  public:
59 
60  bool isInitrdLoaded() const;
61  uint8_t *getInitrdAddress() const;
62  size_t getInitrdSize() const;
63 
64  bool isDatabaseLoaded() const;
65  uint8_t *getDatabaseAddress() const;
66  size_t getDatabaseSize() const;
67 
68  char *getCommandLine() const;
69 
70  size_t getSectionHeaderCount() const;
71  size_t getSectionHeaderEntrySize() const;
72  size_t getSectionHeaderStringTableIndex() const;
73  uintptr_t getSectionHeaders() const;
74 
75  void *getMemoryMap() const;
76  uint64_t getMemoryMapEntryAddress(void *opaque) const;
77  uint64_t getMemoryMapEntryLength(void *opaque) const;
78  uint32_t getMemoryMapEntryType(void *opaque) const;
79  void *nextMemoryMapEntry(void *opaque) const;
80 
81  size_t getModuleCount() const;
82  void *getModuleBase() const;
83 
84 #ifdef HOSTED
85  typedef uintptr_t bootstrap_uintptr_t;
86 #else
87  typedef uint32_t bootstrap_uintptr_t;
88 #endif
89 
90  typedef struct
91  {
92  bootstrap_uintptr_t base;
93  bootstrap_uintptr_t end;
94  bootstrap_uintptr_t name_ptr;
95  bootstrap_uintptr_t pad;
96  } PACKED Module;
97 
98  const Module *getModuleArray() const
99  {
100  return reinterpret_cast<const Module *>(getModuleBase());
101  }
102 
103  private:
104  // If we are passed via grub, this information will be completely different
105  // to via the bootstrapper.
106  uint32_t flags;
107 
108  uint32_t mem_lower;
109  uint32_t mem_upper;
110 
111  uint32_t boot_device;
112 
113  uint32_t cmdline;
114 
115  uint32_t mods_count;
116  bootstrap_uintptr_t mods_addr;
117 
118  /* ELF information */
119  uint32_t num;
120  uint32_t size;
121  bootstrap_uintptr_t addr;
122  uint32_t shndx;
123 
124  uint32_t mmap_length;
125  uint32_t mmap_addr;
126 
127  uint32_t drives_length;
128  uint32_t drives_addr;
129 
130  uint32_t config_table;
131 
132  uint32_t boot_loader_name;
133 
134  uint32_t apm_table;
135 
136  uint32_t vbe_control_info;
137  uint32_t vbe_mode_info;
138  uint32_t vbe_mode;
139  uint32_t vbe_interface_seg;
140  uint32_t vbe_interface_off;
141  uint32_t vbe_interface_len;
142 } PACKED;
143 
144 #else
145 
147 {
148  int (*prom)(struct anon *);
149  uint32_t initrd_start;
150  uint32_t initrd_end;
151 
152  /* ELF information */
153  uint32_t num;
154  uint32_t size;
155  uint32_t addr;
156  uint32_t shndx;
157 
158  inline bool isInitrdLoaded() const
159  {
160  return true;
161  }
162  inline uint8_t *getInitrdAddress() const
163  {
164  return reinterpret_cast<uint8_t *>(initrd_start);
165  }
166  inline size_t getInitrdSize() const
167  {
168  return initrd_end - initrd_start;
169  }
170 
171  char *getCommandLine() const
172  {
173  static char buf[1] = {0};
174  return buf;
175  }
176 };
177 
178 #endif
179 
182 #endif
Bootstrap structure passed to the kernel entry point.