...
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
#define MAX_REGIONS 64
|
#define MAX_REGIONS 64
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u64 base_address;
|
u64 base_addr;
|
||||||
u64 length;
|
u64 length;
|
||||||
} memory_region;
|
} memory_region;
|
||||||
|
|
||||||
@@ -20,8 +20,8 @@ extern uptr kernel_end;
|
|||||||
static memory_region memory_regions[MAX_REGIONS] = {0};
|
static memory_region memory_regions[MAX_REGIONS] = {0};
|
||||||
static size_t memory_region_count = 0;
|
static size_t memory_region_count = 0;
|
||||||
|
|
||||||
static void find_memory_regions(uptr multiboot_info) {
|
static void find_memory_regions() {
|
||||||
multiboot_tag_mmap *tag = multiboot_get_mmap(multiboot_info);
|
multiboot_tag_mmap *tag = multiboot_get_mmap();
|
||||||
if (tag == NULL) {
|
if (tag == NULL) {
|
||||||
boot_panic("Multiboot did not provide mmap tag");
|
boot_panic("Multiboot did not provide mmap tag");
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ static void find_memory_regions(uptr multiboot_info) {
|
|||||||
boot_panic("Too many memory regions");
|
boot_panic("Too many memory regions");
|
||||||
}
|
}
|
||||||
|
|
||||||
memory_regions[memory_region_count++] = (memory_region){ entry->base_address, entry->length };
|
memory_regions[memory_region_count++] = (memory_region){ entry->base_addr, entry->length };
|
||||||
}
|
}
|
||||||
|
|
||||||
entry_ptr += tag->entry_size;
|
entry_ptr += tag->entry_size;
|
||||||
@@ -45,11 +45,11 @@ static void find_memory_regions(uptr multiboot_info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We are now in long mode with kernel pages and vga buffer identity mapped
|
// We are now in long mode with kernel pages and vga buffer identity mapped
|
||||||
void x86_64_main(uptr multiboot_info) {
|
void x86_64_main() {
|
||||||
console_clear();
|
console_clear();
|
||||||
find_memory_regions(multiboot_info);
|
find_memory_regions();
|
||||||
|
|
||||||
for (u32 i = 0; i < memory_region_count; ++i) {
|
for (u32 i = 0; i < memory_region_count; ++i) {
|
||||||
kprintf("region: base_address=0x%X, length=0x%X\n", memory_regions[i].base_address, memory_regions[i].length);
|
kprintf("region: base_addr=0x%X, length=0x%X\n", memory_regions[i].base_addr, memory_regions[i].length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
#include "multiboot2.h"
|
#include "multiboot2.h"
|
||||||
|
|
||||||
|
// [size:4][reserved:4][data:N]
|
||||||
#define INFO_DATA_OFFSET 8
|
#define INFO_DATA_OFFSET 8
|
||||||
#define TAG_ALIGNMENT 8
|
|
||||||
#define TAG_TYPE_OFFSET 0
|
#define TAG_TYPE_OFFSET 0
|
||||||
#define TAG_SIZE_OFFSET 4
|
#define TAG_SIZE_OFFSET 4
|
||||||
|
|
||||||
void *multiboot_get_tag(uptr multiboot_info, u32 type) {
|
extern u8 multiboot_info[];
|
||||||
uptr current = multiboot_info + INFO_DATA_OFFSET;
|
|
||||||
|
void *multiboot_get_tag(u32 type) {
|
||||||
|
uptr current = (uptr)&multiboot_info + INFO_DATA_OFFSET;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
u32 tag_type = *(u32*)(current + TAG_TYPE_OFFSET);
|
u32 tag_type = *(u32*)(current + TAG_TYPE_OFFSET);
|
||||||
@@ -20,7 +23,8 @@ void *multiboot_get_tag(uptr multiboot_info, u32 type) {
|
|||||||
return (void*)current;
|
return (void*)current;
|
||||||
}
|
}
|
||||||
|
|
||||||
current = align_up(current + tag_size, TAG_ALIGNMENT);
|
// note(nub31): Each tag is aligned to 8 bytes
|
||||||
|
current = align_up(current + tag_size, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
#define MULTIBOOT_TAG_TYPE_EFI_BS 18
|
#define MULTIBOOT_TAG_TYPE_EFI_BS 18
|
||||||
#define MULTIBOOT_TAG_TYPE_EFI32_IH 19
|
#define MULTIBOOT_TAG_TYPE_EFI32_IH 19
|
||||||
#define MULTIBOOT_TAG_TYPE_EFI64_IH 20
|
#define MULTIBOOT_TAG_TYPE_EFI64_IH 20
|
||||||
#define MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDRESS 21
|
#define MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR 21
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u32 type;
|
u32 type;
|
||||||
@@ -87,7 +87,7 @@ typedef struct {
|
|||||||
#define MULTIBOOT_MEMORY_BADRAM 5
|
#define MULTIBOOT_MEMORY_BADRAM 5
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u64 base_address;
|
u64 base_addr;
|
||||||
u64 length;
|
u64 length;
|
||||||
u32 type;
|
u32 type;
|
||||||
u32 reserved;
|
u32 reserved;
|
||||||
@@ -127,7 +127,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
u32 type;
|
u32 type;
|
||||||
u32 size;
|
u32 size;
|
||||||
u64 framebuffer_address;
|
u64 framebuffer_addr;
|
||||||
u32 framebuffer_pitch;
|
u32 framebuffer_pitch;
|
||||||
u32 framebuffer_width;
|
u32 framebuffer_width;
|
||||||
u32 framebuffer_height;
|
u32 framebuffer_height;
|
||||||
@@ -236,91 +236,91 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
u32 type;
|
u32 type;
|
||||||
u32 size;
|
u32 size;
|
||||||
u32 load_base_address;
|
u32 load_base_addr;
|
||||||
} multiboot_tag_load_base_address;
|
} multiboot_tag_load_base_addr;
|
||||||
|
|
||||||
void *multiboot_get_tag(uptr multiboot_info, u32 type);
|
void *multiboot_get_tag(u32 type);
|
||||||
|
|
||||||
static inline multiboot_tag_cmdline *multiboot_get_cmdline(uptr multiboot_info) {
|
static inline multiboot_tag_cmdline *multiboot_get_cmdline() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_CMDLINE);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_CMDLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_bootloader_name *multiboot_get_bootloader_name(uptr multiboot_info) {
|
static inline multiboot_tag_bootloader_name *multiboot_get_bootloader_name() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_module *multiboot_get_module(uptr multiboot_info) {
|
static inline multiboot_tag_module *multiboot_get_module() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_MODULE);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_MODULE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_basic_meminfo *multiboot_get_basic_meminfo(uptr multiboot_info) {
|
static inline multiboot_tag_basic_meminfo *multiboot_get_basic_meminfo() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_BASIC_MEMINFO);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_BASIC_MEMINFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_bootdev *multiboot_get_bootdev(uptr multiboot_info) {
|
static inline multiboot_tag_bootdev *multiboot_get_bootdev() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_BOOTDEV);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_BOOTDEV);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_mmap *multiboot_get_mmap(uptr multiboot_info) {
|
static inline multiboot_tag_mmap *multiboot_get_mmap() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_MMAP);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_MMAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_vbe *multiboot_get_vbe(uptr multiboot_info) {
|
static inline multiboot_tag_vbe *multiboot_get_vbe() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_VBE);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_VBE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_framebuffer *multiboot_get_framebuffer(uptr multiboot_info) {
|
static inline multiboot_tag_framebuffer *multiboot_get_framebuffer() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_FRAMEBUFFER);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_FRAMEBUFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_elf_sections *multiboot_get_elf_sections(uptr multiboot_info) {
|
static inline multiboot_tag_elf_sections *multiboot_get_elf_sections() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_ELF_SECTIONS);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_ELF_SECTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_apm *multiboot_get_apm(uptr multiboot_info) {
|
static inline multiboot_tag_apm *multiboot_get_apm() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_APM);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_APM);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_efi32 *multiboot_get_efi32(uptr multiboot_info) {
|
static inline multiboot_tag_efi32 *multiboot_get_efi32() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_EFI32);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_EFI32);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_efi64 *multiboot_get_efi64(uptr multiboot_info) {
|
static inline multiboot_tag_efi64 *multiboot_get_efi64() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_EFI64);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_EFI64);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_smbios *multiboot_get_smbios(uptr multiboot_info) {
|
static inline multiboot_tag_smbios *multiboot_get_smbios() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_SMBIOS);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_SMBIOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_acpi_old *multiboot_get_acpi_old(uptr multiboot_info) {
|
static inline multiboot_tag_acpi_old *multiboot_get_acpi_old() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_ACPI_OLD);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_ACPI_OLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_acpi_new *multiboot_get_acpi_new(uptr multiboot_info) {
|
static inline multiboot_tag_acpi_new *multiboot_get_acpi_new() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_ACPI_NEW);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_ACPI_NEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_network *multiboot_get_network(uptr multiboot_info) {
|
static inline multiboot_tag_network *multiboot_get_network() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_NETWORK);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_NETWORK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_efi_mmap *multiboot_get_efi_mmap(uptr multiboot_info) {
|
static inline multiboot_tag_efi_mmap *multiboot_get_efi_mmap() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_EFI_MMAP);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_EFI_MMAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool multiboot_get_efi_bs(uptr multiboot_info) {
|
static inline bool multiboot_get_efi_bs() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_EFI_BS) != NULL;
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_EFI_BS) != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_efi32_ih *multiboot_get_efi32_ih(uptr multiboot_info) {
|
static inline multiboot_tag_efi32_ih *multiboot_get_efi32_ih() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_EFI32_IH);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_EFI32_IH);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_efi64_ih *multiboot_get_efi64_ih(uptr multiboot_info) {
|
static inline multiboot_tag_efi64_ih *multiboot_get_efi64_ih() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_EFI64_IH);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_EFI64_IH);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline multiboot_tag_load_base_address *multiboot_get_load_base_address(uptr multiboot_info) {
|
static inline multiboot_tag_load_base_addr *multiboot_get_load_base_addr() {
|
||||||
return multiboot_get_tag(multiboot_info, MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDRESS);
|
return multiboot_get_tag(MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
global _start
|
global _start
|
||||||
|
global multiboot_info
|
||||||
extern kernel_start
|
extern kernel_start
|
||||||
extern kernel_end
|
extern kernel_end
|
||||||
extern x86_64_main
|
extern x86_64_main
|
||||||
|
|||||||
Reference in New Issue
Block a user