ref: update formatting
This commit is contained in:
parent
7d0155d8ce
commit
024407225c
16 changed files with 433 additions and 377 deletions
|
|
@ -1,15 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "util/number.h"
|
||||
#include "memory/pointer.h"
|
||||
#include "util/number.h"
|
||||
|
||||
namespace acpi {
|
||||
|
||||
constexpr uint32_t fold_signature(const char (&text)[5]) {
|
||||
return static_cast<uint32_t>(static_cast<uint8_t>(text[0]))
|
||||
| static_cast<uint32_t>(static_cast<uint8_t>(text[1])) << 8
|
||||
| static_cast<uint32_t>(static_cast<uint8_t>(text[2])) << 16
|
||||
| static_cast<uint32_t>(static_cast<uint8_t>(text[3])) << 24;
|
||||
return static_cast<uint32_t>(static_cast<uint8_t>(text[0])) |
|
||||
static_cast<uint32_t>(static_cast<uint8_t>(text[1])) << 8 |
|
||||
static_cast<uint32_t>(static_cast<uint8_t>(text[2])) << 16 |
|
||||
static_cast<uint32_t>(static_cast<uint8_t>(text[3])) << 24;
|
||||
}
|
||||
|
||||
enum class signature : uint32_t {
|
||||
|
|
@ -35,10 +35,10 @@ inline signature_text_t unfold_signature(uint32_t folded) {
|
|||
struct sdt_header_t {
|
||||
uint32_t signature;
|
||||
uint32_t length;
|
||||
uint8_t revision;
|
||||
uint8_t checksum;
|
||||
char oem_id[6];
|
||||
char oem_table_id[8];
|
||||
uint8_t revision;
|
||||
uint8_t checksum;
|
||||
char oem_id[6];
|
||||
char oem_table_id[8];
|
||||
uint32_t oem_revision;
|
||||
uint32_t creator_id;
|
||||
uint32_t creator_revision;
|
||||
|
|
@ -46,16 +46,16 @@ struct sdt_header_t {
|
|||
static_assert(sizeof(sdt_header_t) == 36);
|
||||
|
||||
struct rsdp_t {
|
||||
char signature[8];
|
||||
uint8_t checksum;
|
||||
char oem_id[6];
|
||||
uint8_t revision;
|
||||
char signature[8];
|
||||
uint8_t checksum;
|
||||
char oem_id[6];
|
||||
uint8_t revision;
|
||||
uint32_t rsdt_address;
|
||||
|
||||
uint32_t length;
|
||||
uint64_t xsdt_address;
|
||||
uint8_t extended_checksum;
|
||||
uint8_t reserved[3];
|
||||
uint8_t extended_checksum;
|
||||
uint8_t reserved[3];
|
||||
} __attribute__((packed));
|
||||
static_assert(sizeof(rsdp_t) == 36);
|
||||
|
||||
|
|
@ -80,17 +80,18 @@ struct Rsdp {
|
|||
private:
|
||||
template<typename Fn>
|
||||
static void dispatch(const sdt_header_t* header, Fn&& fn) {
|
||||
#define ACPI_DISPATCH(signature_enum, TableType) \
|
||||
case signature::signature_enum: \
|
||||
if constexpr (requires { fn(static_cast<const TableType*>(nullptr)); }) { \
|
||||
fn(reinterpret_cast<const TableType*>(header)); \
|
||||
return; \
|
||||
} \
|
||||
#define ACPI_DISPATCH(signature_enum, TableType) \
|
||||
case signature::signature_enum: \
|
||||
if constexpr (requires { fn(static_cast<const TableType*>(nullptr)); }) { \
|
||||
fn(reinterpret_cast<const TableType*>(header)); \
|
||||
return; \
|
||||
} \
|
||||
break;
|
||||
|
||||
switch (static_cast<signature>(header->signature)) {
|
||||
ACPI_DISPATCH(madt, madt_t)
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#undef ACPI_DISPATCH
|
||||
|
|
|
|||
|
|
@ -7,187 +7,186 @@
|
|||
namespace acpi {
|
||||
|
||||
enum class madt_entry_type : uint8_t {
|
||||
local_apic = 0,
|
||||
io_apic = 1,
|
||||
interrupt_source_override = 2,
|
||||
nmi_source = 3,
|
||||
local_apic_nmi = 4,
|
||||
local_apic_address_override = 5,
|
||||
local_apic = 0,
|
||||
io_apic = 1,
|
||||
interrupt_source_override = 2,
|
||||
nmi_source = 3,
|
||||
local_apic_nmi = 4,
|
||||
local_apic_address_override = 5,
|
||||
};
|
||||
|
||||
inline constexpr const char *get_madt_entry_type_name(madt_entry_type type) {
|
||||
switch (type) {
|
||||
case madt_entry_type::local_apic:
|
||||
return "local_apic";
|
||||
case madt_entry_type::io_apic:
|
||||
return "io_apic";
|
||||
case madt_entry_type::interrupt_source_override:
|
||||
return "interrupt_source_override";
|
||||
case madt_entry_type::nmi_source:
|
||||
return "nmi_source";
|
||||
case madt_entry_type::local_apic_nmi:
|
||||
return "local_apic_nmi";
|
||||
case madt_entry_type::local_apic_address_override:
|
||||
return "local_apic_address_override";
|
||||
}
|
||||
return "unknown";
|
||||
inline constexpr const char* get_madt_entry_type_name(madt_entry_type type) {
|
||||
switch (type) {
|
||||
case madt_entry_type::local_apic:
|
||||
return "local_apic";
|
||||
case madt_entry_type::io_apic:
|
||||
return "io_apic";
|
||||
case madt_entry_type::interrupt_source_override:
|
||||
return "interrupt_source_override";
|
||||
case madt_entry_type::nmi_source:
|
||||
return "nmi_source";
|
||||
case madt_entry_type::local_apic_nmi:
|
||||
return "local_apic_nmi";
|
||||
case madt_entry_type::local_apic_address_override:
|
||||
return "local_apic_address_override";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
struct madt_flags_t {
|
||||
uint32_t dual_8259_present : 1;
|
||||
uint32_t reserved : 31;
|
||||
uint32_t dual_8259_present : 1;
|
||||
uint32_t reserved : 31;
|
||||
};
|
||||
static_assert(sizeof(madt_flags_t) == 4);
|
||||
|
||||
struct local_apic_flags_t {
|
||||
uint32_t enabled : 1;
|
||||
uint32_t online_capable : 1;
|
||||
uint32_t reserved : 30;
|
||||
uint32_t enabled : 1;
|
||||
uint32_t online_capable : 1;
|
||||
uint32_t reserved : 30;
|
||||
};
|
||||
static_assert(sizeof(local_apic_flags_t) == 4);
|
||||
|
||||
enum class inti_polarity : uint16_t {
|
||||
bus_default = 0,
|
||||
active_high = 1,
|
||||
active_low = 3,
|
||||
bus_default = 0,
|
||||
active_high = 1,
|
||||
active_low = 3,
|
||||
};
|
||||
|
||||
enum class inti_trigger_mode : uint16_t {
|
||||
bus_default = 0,
|
||||
edge = 1,
|
||||
level = 3,
|
||||
bus_default = 0,
|
||||
edge = 1,
|
||||
level = 3,
|
||||
};
|
||||
|
||||
struct inti_flags_t {
|
||||
inti_polarity polarity : 2;
|
||||
inti_trigger_mode trigger_mode : 2;
|
||||
uint16_t reserved : 12;
|
||||
inti_polarity polarity : 2;
|
||||
inti_trigger_mode trigger_mode : 2;
|
||||
uint16_t reserved : 12;
|
||||
};
|
||||
static_assert(sizeof(inti_flags_t) == 2);
|
||||
|
||||
struct madt_t {
|
||||
sdt_header_t header;
|
||||
uint32_t local_apic_address;
|
||||
madt_flags_t flags;
|
||||
uint8_t entries[0];
|
||||
sdt_header_t header;
|
||||
uint32_t local_apic_address;
|
||||
madt_flags_t flags;
|
||||
uint8_t entries[0];
|
||||
} __attribute__((packed));
|
||||
static_assert(sizeof(madt_t) == 44);
|
||||
|
||||
struct madt_entry_t {
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
} __attribute__((packed));
|
||||
static_assert(sizeof(madt_entry_t) == 2);
|
||||
|
||||
struct madt_local_apic_t {
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
uint8_t acpi_processor_uid;
|
||||
uint8_t apic_id;
|
||||
local_apic_flags_t flags;
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
uint8_t acpi_processor_uid;
|
||||
uint8_t apic_id;
|
||||
local_apic_flags_t flags;
|
||||
} __attribute__((packed));
|
||||
static_assert(sizeof(madt_local_apic_t) == 8);
|
||||
|
||||
struct madt_io_apic_t {
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
uint8_t io_apic_id;
|
||||
uint8_t reserved;
|
||||
uint32_t io_apic_address;
|
||||
uint32_t global_system_interrupt_base;
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
uint8_t io_apic_id;
|
||||
uint8_t reserved;
|
||||
uint32_t io_apic_address;
|
||||
uint32_t global_system_interrupt_base;
|
||||
} __attribute__((packed));
|
||||
static_assert(sizeof(madt_io_apic_t) == 12);
|
||||
|
||||
struct madt_interrupt_source_override_t {
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
uint8_t bus; // always 0 (ISA)
|
||||
uint8_t source; // ISA IRQ number
|
||||
uint32_t global_system_interrupt;
|
||||
inti_flags_t flags;
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
uint8_t bus; // always 0 (ISA)
|
||||
uint8_t source; // ISA IRQ number
|
||||
uint32_t global_system_interrupt;
|
||||
inti_flags_t flags;
|
||||
} __attribute__((packed));
|
||||
static_assert(sizeof(madt_interrupt_source_override_t) == 10);
|
||||
|
||||
struct madt_nmi_source_t {
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
inti_flags_t flags;
|
||||
uint32_t global_system_interrupt;
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
inti_flags_t flags;
|
||||
uint32_t global_system_interrupt;
|
||||
} __attribute__((packed));
|
||||
static_assert(sizeof(madt_nmi_source_t) == 8);
|
||||
|
||||
struct madt_local_apic_nmi_t {
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
uint8_t acpi_processor_uid; // 0xFF: applies to all processors
|
||||
inti_flags_t flags;
|
||||
uint8_t lint; // local APIC LINT# the NMI is wired to
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
uint8_t acpi_processor_uid; // 0xFF: applies to all processors
|
||||
inti_flags_t flags;
|
||||
uint8_t lint; // local APIC LINT# the NMI is wired to
|
||||
} __attribute__((packed));
|
||||
static_assert(sizeof(madt_local_apic_nmi_t) == 6);
|
||||
|
||||
struct madt_local_apic_address_override_t {
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
uint16_t reserved;
|
||||
uint64_t local_apic_address;
|
||||
madt_entry_type type;
|
||||
uint8_t length;
|
||||
uint16_t reserved;
|
||||
uint64_t local_apic_address;
|
||||
} __attribute__((packed));
|
||||
static_assert(sizeof(madt_local_apic_address_override_t) == 12);
|
||||
|
||||
struct Madt {
|
||||
explicit Madt(paddr_t madt_physical)
|
||||
: table(madt_physical.access<madt_t>()) {}
|
||||
explicit Madt(const madt_t *madt_table) : table(madt_table) {}
|
||||
explicit Madt(paddr_t madt_physical) : table(madt_physical.access<madt_t>()) {}
|
||||
explicit Madt(const madt_t* madt_table) : table(madt_table) {}
|
||||
|
||||
paddr_t local_apic_address() {
|
||||
uint64_t address = table->local_apic_address;
|
||||
for_each_entry(
|
||||
[&](const madt_local_apic_address_override_t *override_entry) {
|
||||
address = override_entry->local_apic_address;
|
||||
paddr_t local_apic_address() {
|
||||
uint64_t address = table->local_apic_address;
|
||||
for_each_entry([&](const madt_local_apic_address_override_t* override_entry) {
|
||||
address = override_entry->local_apic_address;
|
||||
});
|
||||
return paddr_t{address};
|
||||
}
|
||||
|
||||
bool has_legacy_pic() { return table->flags.dual_8259_present != 0; }
|
||||
|
||||
template <typename Fn> void for_each_entry(Fn &&callback) {
|
||||
auto ptr = table->entries;
|
||||
const auto end =
|
||||
reinterpret_cast<const uint8_t *>(table) + table->header.length;
|
||||
while (ptr < end) {
|
||||
auto entry = reinterpret_cast<const madt_entry_t *>(ptr);
|
||||
if (entry->length < sizeof(madt_entry_t)) {
|
||||
break;
|
||||
}
|
||||
dispatch(entry, callback);
|
||||
ptr += entry->length;
|
||||
return paddr_t{address};
|
||||
}
|
||||
|
||||
bool has_legacy_pic() {
|
||||
return table->flags.dual_8259_present != 0;
|
||||
}
|
||||
|
||||
template<typename Fn>
|
||||
void for_each_entry(Fn&& callback) {
|
||||
auto ptr = table->entries;
|
||||
const auto end = reinterpret_cast<const uint8_t*>(table) + table->header.length;
|
||||
while (ptr < end) {
|
||||
auto entry = reinterpret_cast<const madt_entry_t*>(ptr);
|
||||
if (entry->length < sizeof(madt_entry_t)) {
|
||||
break;
|
||||
}
|
||||
dispatch(entry, callback);
|
||||
ptr += entry->length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename Fn>
|
||||
static void dispatch(const madt_entry_t *entry, Fn &&fn) {
|
||||
#define MADT_DISPATCH(entry_enum, EntryType) \
|
||||
case madt_entry_type::entry_enum: \
|
||||
if constexpr (requires { fn(static_cast<const EntryType *>(nullptr)); }) \
|
||||
fn(reinterpret_cast<const EntryType *>(entry)); \
|
||||
break;
|
||||
template<typename Fn>
|
||||
static void dispatch(const madt_entry_t* entry, Fn&& fn) {
|
||||
#define MADT_DISPATCH(entry_enum, EntryType) \
|
||||
case madt_entry_type::entry_enum: \
|
||||
if constexpr (requires { fn(static_cast<const EntryType*>(nullptr)); }) \
|
||||
fn(reinterpret_cast<const EntryType*>(entry)); \
|
||||
break;
|
||||
|
||||
switch (entry->type) {
|
||||
MADT_DISPATCH(local_apic, madt_local_apic_t)
|
||||
MADT_DISPATCH(io_apic, madt_io_apic_t)
|
||||
MADT_DISPATCH(interrupt_source_override, madt_interrupt_source_override_t)
|
||||
MADT_DISPATCH(nmi_source, madt_nmi_source_t)
|
||||
MADT_DISPATCH(local_apic_nmi, madt_local_apic_nmi_t)
|
||||
MADT_DISPATCH(local_apic_address_override,
|
||||
madt_local_apic_address_override_t)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (entry->type) {
|
||||
MADT_DISPATCH(local_apic, madt_local_apic_t)
|
||||
MADT_DISPATCH(io_apic, madt_io_apic_t)
|
||||
MADT_DISPATCH(interrupt_source_override, madt_interrupt_source_override_t)
|
||||
MADT_DISPATCH(nmi_source, madt_nmi_source_t)
|
||||
MADT_DISPATCH(local_apic_nmi, madt_local_apic_nmi_t)
|
||||
MADT_DISPATCH(local_apic_address_override, madt_local_apic_address_override_t)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#undef MADT_DISPATCH
|
||||
}
|
||||
}
|
||||
|
||||
const madt_t *table;
|
||||
const madt_t* table;
|
||||
};
|
||||
|
||||
} // namespace acpi
|
||||
|
|
|
|||
|
|
@ -1,89 +1,117 @@
|
|||
#pragma once
|
||||
|
||||
#include "util/number.h"
|
||||
#include "util/function.h"
|
||||
#include "memory/pointer.h"
|
||||
#include "util/function.h"
|
||||
#include "util/number.h"
|
||||
|
||||
namespace multiboot {
|
||||
|
||||
inline constexpr uint32_t magic = 0x36d76289;
|
||||
inline constexpr uint32_t magic = 0x36d76289;
|
||||
inline constexpr uint32_t alignment = 8;
|
||||
|
||||
enum class tag_type : uint32_t {
|
||||
end = 0,
|
||||
cmdline = 1,
|
||||
end = 0,
|
||||
cmdline = 1,
|
||||
boot_loader_name = 2,
|
||||
module = 3,
|
||||
basic_meminfo = 4,
|
||||
bootdev = 5,
|
||||
mmap = 6,
|
||||
vbe = 7,
|
||||
framebuffer = 8,
|
||||
elf_sections = 9,
|
||||
apm = 10,
|
||||
efi32 = 11,
|
||||
efi64 = 12,
|
||||
smbios = 13,
|
||||
acpi_old = 14,
|
||||
acpi_new = 15,
|
||||
network = 16,
|
||||
efi_mmap = 17,
|
||||
efi_bs = 18,
|
||||
efi32_ih = 19,
|
||||
efi64_ih = 20,
|
||||
load_base_addr = 21,
|
||||
module = 3,
|
||||
basic_meminfo = 4,
|
||||
bootdev = 5,
|
||||
mmap = 6,
|
||||
vbe = 7,
|
||||
framebuffer = 8,
|
||||
elf_sections = 9,
|
||||
apm = 10,
|
||||
efi32 = 11,
|
||||
efi64 = 12,
|
||||
smbios = 13,
|
||||
acpi_old = 14,
|
||||
acpi_new = 15,
|
||||
network = 16,
|
||||
efi_mmap = 17,
|
||||
efi_bs = 18,
|
||||
efi32_ih = 19,
|
||||
efi64_ih = 20,
|
||||
load_base_addr = 21,
|
||||
};
|
||||
|
||||
inline constexpr const char* get_tag_name(tag_type type) {
|
||||
switch (type) {
|
||||
case tag_type::end: return "end";
|
||||
case tag_type::cmdline: return "cmdline";
|
||||
case tag_type::boot_loader_name: return "boot_loader_name";
|
||||
case tag_type::module: return "module";
|
||||
case tag_type::basic_meminfo: return "basic_meminfo";
|
||||
case tag_type::bootdev: return "bootdev";
|
||||
case tag_type::mmap: return "mmap";
|
||||
case tag_type::vbe: return "vbe";
|
||||
case tag_type::framebuffer: return "framebuffer";
|
||||
case tag_type::elf_sections: return "elf_sections";
|
||||
case tag_type::apm: return "apm";
|
||||
case tag_type::efi32: return "efi32";
|
||||
case tag_type::efi64: return "efi64";
|
||||
case tag_type::smbios: return "smbios";
|
||||
case tag_type::acpi_old: return "acpi_old";
|
||||
case tag_type::acpi_new: return "acpi_new";
|
||||
case tag_type::network: return "network";
|
||||
case tag_type::efi_mmap: return "efi_mmap";
|
||||
case tag_type::efi_bs: return "efi_bs";
|
||||
case tag_type::efi32_ih: return "efi32_ih";
|
||||
case tag_type::efi64_ih: return "efi64_ih";
|
||||
case tag_type::load_base_addr: return "load_base_addr";
|
||||
case tag_type::end:
|
||||
return "end";
|
||||
case tag_type::cmdline:
|
||||
return "cmdline";
|
||||
case tag_type::boot_loader_name:
|
||||
return "boot_loader_name";
|
||||
case tag_type::module:
|
||||
return "module";
|
||||
case tag_type::basic_meminfo:
|
||||
return "basic_meminfo";
|
||||
case tag_type::bootdev:
|
||||
return "bootdev";
|
||||
case tag_type::mmap:
|
||||
return "mmap";
|
||||
case tag_type::vbe:
|
||||
return "vbe";
|
||||
case tag_type::framebuffer:
|
||||
return "framebuffer";
|
||||
case tag_type::elf_sections:
|
||||
return "elf_sections";
|
||||
case tag_type::apm:
|
||||
return "apm";
|
||||
case tag_type::efi32:
|
||||
return "efi32";
|
||||
case tag_type::efi64:
|
||||
return "efi64";
|
||||
case tag_type::smbios:
|
||||
return "smbios";
|
||||
case tag_type::acpi_old:
|
||||
return "acpi_old";
|
||||
case tag_type::acpi_new:
|
||||
return "acpi_new";
|
||||
case tag_type::network:
|
||||
return "network";
|
||||
case tag_type::efi_mmap:
|
||||
return "efi_mmap";
|
||||
case tag_type::efi_bs:
|
||||
return "efi_bs";
|
||||
case tag_type::efi32_ih:
|
||||
return "efi32_ih";
|
||||
case tag_type::efi64_ih:
|
||||
return "efi64_ih";
|
||||
case tag_type::load_base_addr:
|
||||
return "load_base_addr";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
enum class framebuffer_type : uint8_t {
|
||||
indexed = 0,
|
||||
rgb = 1,
|
||||
indexed = 0,
|
||||
rgb = 1,
|
||||
ega_text = 2,
|
||||
};
|
||||
|
||||
enum class mem_type : uint32_t {
|
||||
available = 1,
|
||||
reserved = 2,
|
||||
available = 1,
|
||||
reserved = 2,
|
||||
acpi_reclaimable = 3,
|
||||
nvs = 4,
|
||||
badram = 5,
|
||||
nvs = 4,
|
||||
badram = 5,
|
||||
};
|
||||
|
||||
inline constexpr const char* get_mem_type_name(mem_type type) {
|
||||
switch (type) {
|
||||
case mem_type::available: return "available";
|
||||
case mem_type::reserved: return "reserved";
|
||||
case mem_type::acpi_reclaimable: return "acpi_reclaimable";
|
||||
case mem_type::nvs: return "nvs";
|
||||
case mem_type::badram: return "badram";
|
||||
default: return "unknown";
|
||||
case mem_type::available:
|
||||
return "available";
|
||||
case mem_type::reserved:
|
||||
return "reserved";
|
||||
case mem_type::acpi_reclaimable:
|
||||
return "acpi_reclaimable";
|
||||
case mem_type::nvs:
|
||||
return "nvs";
|
||||
case mem_type::badram:
|
||||
return "badram";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +136,7 @@ struct tag {
|
|||
struct tag_string {
|
||||
tag_type type;
|
||||
uint32_t size;
|
||||
char string[0];
|
||||
char string[0];
|
||||
};
|
||||
|
||||
struct tag_module {
|
||||
|
|
@ -116,7 +144,7 @@ struct tag_module {
|
|||
uint32_t size;
|
||||
uint32_t mod_start;
|
||||
uint32_t mod_end;
|
||||
char cmdline[0];
|
||||
char cmdline[0];
|
||||
};
|
||||
|
||||
struct tag_basic_meminfo {
|
||||
|
|
@ -135,11 +163,11 @@ struct tag_bootdev {
|
|||
};
|
||||
|
||||
struct tag_mmap {
|
||||
tag_type type;
|
||||
uint32_t size;
|
||||
uint32_t entry_size;
|
||||
uint32_t entry_version;
|
||||
mem_entry entries[0];
|
||||
tag_type type;
|
||||
uint32_t size;
|
||||
uint32_t entry_size;
|
||||
uint32_t entry_version;
|
||||
mem_entry entries[0];
|
||||
};
|
||||
|
||||
struct vbe_info_block {
|
||||
|
|
@ -151,32 +179,31 @@ struct vbe_mode_info_block {
|
|||
};
|
||||
|
||||
struct tag_vbe {
|
||||
tag_type type;
|
||||
uint32_t size;
|
||||
uint16_t vbe_mode;
|
||||
uint16_t vbe_interface_seg;
|
||||
uint16_t vbe_interface_off;
|
||||
uint16_t vbe_interface_len;
|
||||
vbe_info_block vbe_control_info;
|
||||
tag_type type;
|
||||
uint32_t size;
|
||||
uint16_t vbe_mode;
|
||||
uint16_t vbe_interface_seg;
|
||||
uint16_t vbe_interface_off;
|
||||
uint16_t vbe_interface_len;
|
||||
vbe_info_block vbe_control_info;
|
||||
vbe_mode_info_block vbe_mode_info;
|
||||
};
|
||||
|
||||
|
||||
struct tag_framebuffer {
|
||||
tag_type type;
|
||||
uint32_t size;
|
||||
uint64_t framebuffer_addr;
|
||||
uint32_t framebuffer_pitch;
|
||||
uint32_t framebuffer_width;
|
||||
uint32_t framebuffer_height;
|
||||
uint8_t framebuffer_bpp;
|
||||
tag_type type;
|
||||
uint32_t size;
|
||||
uint64_t framebuffer_addr;
|
||||
uint32_t framebuffer_pitch;
|
||||
uint32_t framebuffer_width;
|
||||
uint32_t framebuffer_height;
|
||||
uint8_t framebuffer_bpp;
|
||||
framebuffer_type framebuffer_type;
|
||||
uint16_t reserved;
|
||||
uint16_t reserved;
|
||||
|
||||
union {
|
||||
struct {
|
||||
uint16_t framebuffer_palette_num_colors;
|
||||
color framebuffer_palette[0];
|
||||
color framebuffer_palette[0];
|
||||
};
|
||||
struct {
|
||||
uint8_t framebuffer_red_field_position;
|
||||
|
|
@ -195,7 +222,7 @@ struct tag_elf_sections {
|
|||
uint32_t num;
|
||||
uint32_t entsize;
|
||||
uint32_t shndx;
|
||||
char sections[0];
|
||||
char sections[0];
|
||||
};
|
||||
|
||||
struct tag_apm {
|
||||
|
|
@ -227,28 +254,28 @@ struct tag_efi64 {
|
|||
struct tag_smbios {
|
||||
tag_type type;
|
||||
uint32_t size;
|
||||
uint8_t major;
|
||||
uint8_t minor;
|
||||
uint8_t reserved[6];
|
||||
uint8_t tables[0];
|
||||
uint8_t major;
|
||||
uint8_t minor;
|
||||
uint8_t reserved[6];
|
||||
uint8_t tables[0];
|
||||
};
|
||||
|
||||
struct tag_old_acpi {
|
||||
tag_type type;
|
||||
uint32_t size;
|
||||
uint8_t rsdp[0];
|
||||
uint8_t rsdp[0];
|
||||
};
|
||||
|
||||
struct tag_new_acpi {
|
||||
tag_type type;
|
||||
uint32_t size;
|
||||
uint8_t rsdp[0];
|
||||
uint8_t rsdp[0];
|
||||
};
|
||||
|
||||
struct tag_network {
|
||||
tag_type type;
|
||||
uint32_t size;
|
||||
uint8_t dhcpack[0];
|
||||
uint8_t dhcpack[0];
|
||||
};
|
||||
|
||||
struct tag_efi_mmap {
|
||||
|
|
@ -256,7 +283,7 @@ struct tag_efi_mmap {
|
|||
uint32_t size;
|
||||
uint32_t descr_size;
|
||||
uint32_t descr_vers;
|
||||
uint8_t efi_mmap[0];
|
||||
uint8_t efi_mmap[0];
|
||||
};
|
||||
|
||||
struct tag_efi32_ih {
|
||||
|
|
@ -290,34 +317,35 @@ inline info* get_multiboot_info() {
|
|||
|
||||
template<typename Fn>
|
||||
void visit(const tag* t, Fn&& fn) {
|
||||
#define MB_DISPATCH(tag_enum, TagType) \
|
||||
case tag_type::tag_enum: \
|
||||
if constexpr (requires { fn(static_cast<const TagType*>(nullptr)); }) \
|
||||
fn(reinterpret_cast<const TagType*>(t)); \
|
||||
#define MB_DISPATCH(tag_enum, TagType) \
|
||||
case tag_type::tag_enum: \
|
||||
if constexpr (requires { fn(static_cast<const TagType*>(nullptr)); }) \
|
||||
fn(reinterpret_cast<const TagType*>(t)); \
|
||||
break;
|
||||
|
||||
switch (t->type) {
|
||||
MB_DISPATCH(cmdline, tag_string)
|
||||
MB_DISPATCH(cmdline, tag_string)
|
||||
MB_DISPATCH(boot_loader_name, tag_string)
|
||||
MB_DISPATCH(module, tag_module)
|
||||
MB_DISPATCH(basic_meminfo, tag_basic_meminfo)
|
||||
MB_DISPATCH(bootdev, tag_bootdev)
|
||||
MB_DISPATCH(mmap, tag_mmap)
|
||||
MB_DISPATCH(vbe, tag_vbe)
|
||||
MB_DISPATCH(framebuffer, tag_framebuffer)
|
||||
MB_DISPATCH(elf_sections, tag_elf_sections)
|
||||
MB_DISPATCH(apm, tag_apm)
|
||||
MB_DISPATCH(efi32, tag_efi32)
|
||||
MB_DISPATCH(efi64, tag_efi64)
|
||||
MB_DISPATCH(smbios, tag_smbios)
|
||||
MB_DISPATCH(acpi_old, tag_old_acpi)
|
||||
MB_DISPATCH(acpi_new, tag_new_acpi)
|
||||
MB_DISPATCH(network, tag_network)
|
||||
MB_DISPATCH(efi_mmap, tag_efi_mmap)
|
||||
MB_DISPATCH(efi32_ih, tag_efi32_ih)
|
||||
MB_DISPATCH(efi64_ih, tag_efi64_ih)
|
||||
MB_DISPATCH(load_base_addr, tag_load_base_addr)
|
||||
default: break;
|
||||
MB_DISPATCH(module, tag_module)
|
||||
MB_DISPATCH(basic_meminfo, tag_basic_meminfo)
|
||||
MB_DISPATCH(bootdev, tag_bootdev)
|
||||
MB_DISPATCH(mmap, tag_mmap)
|
||||
MB_DISPATCH(vbe, tag_vbe)
|
||||
MB_DISPATCH(framebuffer, tag_framebuffer)
|
||||
MB_DISPATCH(elf_sections, tag_elf_sections)
|
||||
MB_DISPATCH(apm, tag_apm)
|
||||
MB_DISPATCH(efi32, tag_efi32)
|
||||
MB_DISPATCH(efi64, tag_efi64)
|
||||
MB_DISPATCH(smbios, tag_smbios)
|
||||
MB_DISPATCH(acpi_old, tag_old_acpi)
|
||||
MB_DISPATCH(acpi_new, tag_new_acpi)
|
||||
MB_DISPATCH(network, tag_network)
|
||||
MB_DISPATCH(efi_mmap, tag_efi_mmap)
|
||||
MB_DISPATCH(efi32_ih, tag_efi32_ih)
|
||||
MB_DISPATCH(efi64_ih, tag_efi64_ih)
|
||||
MB_DISPATCH(load_base_addr, tag_load_base_addr)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#undef MB_DISPATCH
|
||||
|
|
@ -329,7 +357,8 @@ void visit_all(const info* mb, Fn&& fn) {
|
|||
const auto end = reinterpret_cast<const uint8_t*>(mb) + mb->total_size;
|
||||
while (ptr < end) {
|
||||
auto t = reinterpret_cast<const tag*>(ptr);
|
||||
if (t->type == tag_type::end) break;
|
||||
if (t->type == tag_type::end)
|
||||
break;
|
||||
visit(t, fn);
|
||||
ptr += (t->size + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,22 +2,22 @@
|
|||
#include <stdint.h>
|
||||
|
||||
enum class Color : uint8_t {
|
||||
Black = 0,
|
||||
Blue = 1,
|
||||
Green = 2,
|
||||
Cyan = 3,
|
||||
Red = 4,
|
||||
Magenta = 5,
|
||||
Brown = 6,
|
||||
LightGray = 7,
|
||||
DarkGray = 8,
|
||||
LightBlue = 9,
|
||||
LightGreen = 10,
|
||||
LightCyan = 11,
|
||||
LightRed = 12,
|
||||
Black = 0,
|
||||
Blue = 1,
|
||||
Green = 2,
|
||||
Cyan = 3,
|
||||
Red = 4,
|
||||
Magenta = 5,
|
||||
Brown = 6,
|
||||
LightGray = 7,
|
||||
DarkGray = 8,
|
||||
LightBlue = 9,
|
||||
LightGreen = 10,
|
||||
LightCyan = 11,
|
||||
LightRed = 12,
|
||||
LightMagenta = 13,
|
||||
Yellow = 14,
|
||||
White = 15,
|
||||
Yellow = 14,
|
||||
White = 15,
|
||||
};
|
||||
|
||||
struct TextAttr {
|
||||
|
|
@ -26,7 +26,6 @@ struct TextAttr {
|
|||
|
||||
constexpr TextAttr(Color fg = Color::White, Color bg = Color::Black) : fg(fg), bg(bg) {}
|
||||
|
||||
// Returns the attribute in the high byte, ready to OR with a character value.
|
||||
constexpr uint16_t word() const {
|
||||
return (uint16_t)(((uint8_t)bg << 4) | (uint8_t)fg) << 8;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue