bootboot.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * bootboot.h
  3. * https://gitlab.com/bztsrc/bootboot
  4. *
  5. * Copyright (C) 2017 - 2021 bzt (bztsrc@gitlab)
  6. *
  7. * Permission is hereby granted, free of charge, to any person
  8. * obtaining a copy of this software and associated documentation
  9. * files (the "Software"), to deal in the Software without
  10. * restriction, including without limitation the rights to use, copy,
  11. * modify, merge, publish, distribute, sublicense, and/or sell copies
  12. * of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  22. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  25. * DEALINGS IN THE SOFTWARE.
  26. *
  27. * This file is part of the BOOTBOOT Protocol package.
  28. * @brief The BOOTBOOT structure
  29. *
  30. */
  31. #ifndef _BOOTBOOT_H_
  32. #define _BOOTBOOT_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. #ifndef _MSC_VER
  37. #define _pack __attribute__((packed))
  38. #else
  39. #define _pack
  40. #pragma pack(push)
  41. #pragma pack(1)
  42. #endif
  43. #define BOOTBOOT_MAGIC "BOOT"
  44. /* default virtual addresses for level 0 and 1 static loaders */
  45. #define BOOTBOOT_MMIO 0xfffffffff8000000 /* memory mapped IO virtual address */
  46. #define BOOTBOOT_FB 0xfffffffffc000000 /* frame buffer virtual address */
  47. #define BOOTBOOT_INFO 0xffffffffffe00000 /* bootboot struct virtual address */
  48. #define BOOTBOOT_ENV 0xffffffffffe01000 /* environment string virtual address */
  49. #define BOOTBOOT_CORE 0xffffffffffe02000 /* core loadable segment start */
  50. /* minimum protocol level:
  51. * hardcoded kernel name, static kernel memory addresses */
  52. #define PROTOCOL_MINIMAL 0
  53. /* static protocol level:
  54. * kernel name parsed from environment, static kernel memory addresses */
  55. #define PROTOCOL_STATIC 1
  56. /* dynamic protocol level:
  57. * kernel name parsed, kernel memory addresses from ELF or PE symbols */
  58. #define PROTOCOL_DYNAMIC 2
  59. /* big-endian flag */
  60. #define PROTOCOL_BIGENDIAN 0x80
  61. /* loader types, just informational */
  62. #define LOADER_BIOS (0<<2)
  63. #define LOADER_UEFI (1<<2)
  64. #define LOADER_RPI (2<<2)
  65. #define LOADER_COREBOOT (3<<2)
  66. /* framebuffer pixel format, only 32 bits supported */
  67. #define FB_ARGB 0
  68. #define FB_RGBA 1
  69. #define FB_ABGR 2
  70. #define FB_BGRA 3
  71. /* mmap entry, type is stored in least significant tetrad (half byte) of size
  72. * this means size described in 16 byte units (not a problem, most modern
  73. * firmware report memory in pages, 4096 byte units anyway). */
  74. typedef struct {
  75. uint64_t ptr;
  76. uint64_t size;
  77. } _pack MMapEnt;
  78. #define MMapEnt_Ptr(a) ((a)->ptr)
  79. #define MMapEnt_Size(a) ((a)->size & 0xFFFFFFFFFFFFFFF0)
  80. #define MMapEnt_Type(a) ((a)->size & 0xF)
  81. #define MMapEnt_IsFree(a) (((a)->size&0xF)==1)
  82. #define MMAP_USED 0 /* don't use. Reserved or unknown regions */
  83. #define MMAP_FREE 1 /* usable memory */
  84. #define MMAP_ACPI 2 /* acpi memory, volatile and non-volatile as well */
  85. #define MMAP_MMIO 3 /* memory mapped IO region */
  86. #define INITRD_MAXSIZE 16 /* Mb */
  87. typedef struct {
  88. /* first 64 bytes is platform independent */
  89. uint8_t magic[4]; /* 'BOOT' magic */
  90. uint32_t size; /* length of bootboot structure, minimum 128 */
  91. uint8_t protocol; /* 1, static addresses, see PROTOCOL_* and LOADER_* above */
  92. uint8_t fb_type; /* framebuffer type, see FB_* above */
  93. uint16_t numcores; /* number of processor cores */
  94. uint16_t bspid; /* Bootsrap processor ID (Local APIC Id on x86_64) */
  95. int16_t timezone; /* in minutes -1440..1440 */
  96. uint8_t datetime[8]; /* in BCD yyyymmddhhiiss UTC (independent to timezone) */
  97. uint64_t initrd_ptr; /* ramdisk image position and size */
  98. uint64_t initrd_size;
  99. uint64_t fb_ptr; /* framebuffer pointer and dimensions */
  100. uint32_t fb_size;
  101. uint32_t fb_width;
  102. uint32_t fb_height;
  103. uint32_t fb_scanline;
  104. /* the rest (64 bytes) is platform specific */
  105. union {
  106. struct {
  107. uint64_t acpi_ptr;
  108. uint64_t smbi_ptr;
  109. uint64_t efi_ptr;
  110. uint64_t mp_ptr;
  111. uint64_t unused0;
  112. uint64_t unused1;
  113. uint64_t unused2;
  114. uint64_t unused3;
  115. } x86_64;
  116. struct {
  117. uint64_t acpi_ptr;
  118. uint64_t mmio_ptr;
  119. uint64_t efi_ptr;
  120. uint64_t unused0;
  121. uint64_t unused1;
  122. uint64_t unused2;
  123. uint64_t unused3;
  124. uint64_t unused4;
  125. } aarch64;
  126. } arch;
  127. /* from 128th byte, MMapEnt[], more records may follow */
  128. MMapEnt mmap;
  129. /* use like this:
  130. * MMapEnt *mmap_ent = &bootboot.mmap; mmap_ent++;
  131. * until you reach bootboot->size, while(mmap_ent < bootboot + bootboot->size) */
  132. } _pack BOOTBOOT;
  133. #ifdef _MSC_VER
  134. #pragma pack(pop)
  135. #endif
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif