I did split my length and address parameters in my mmap entry struct. No compiler errors or warnings show up. If I could get some pointers on how to get and print the correct data, that would be great!
Also, the project can be found at https://github.com/ResistingGuide4/rOSes
earlyinit.c:
Code: Select all
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <kernel/multiboot2.h>
#include <kernel/testing.h>
struct multiboot_tag *multiboot_find_tag(void *mbd, uint32_t type) {
/* The multiboot info structure begins with a 32-bit integer
* indicating the total size of the structure. This is then
* followed by a 32-bit reserved region and then by the tags. */
struct multiboot_tag *tag = (void *)mbd + 8;
while ((void *)tag < (void *)mbd + *((uint32_t *)mbd)) {
if (tag->type == type) {
return tag;
}
tag = (void *)tag + tag->size;
/* Tags are always aligned on 8-byte boundaries. */
if ((uintptr_t)tag % 8 > 0) {
tag = (void *)tag + 8 - ((uintptr_t)tag % 8);
}
}
return 0;
}
struct multiboot_tag_mmap *memory_map;
uint32_t multiboot_magic;
//Called after higher half far jump
void heap_init(void *mbd, uint32_t magic) {
asm volatile("testing:");
if (magic != MULTIBOOT2_BOOTLOADER_MAGIC) {
abort();
}
struct multiboot_tag_mmap *tag_mmap =
(struct multiboot_tag_mmap *)multiboot_find_tag(
mbd, MULTIBOOT_TAG_TYPE_MMAP);
if (!tag_mmap) {
abort();
}
memory_map = tag_mmap;
multiboot_magic = magic;
}
//Called during main function
void readMMap() {
printf("Magic: %d\n", multiboot_magic);
struct multiboot_mmap_entry *entry =
(struct multiboot_mmap_entry *)(uintptr_t)memory_map->entries;
while ((void *)entry < (void *)memory_map + memory_map->size) {
printf("Start Addr Low: %d | Start Addr High: %d | Length Low: %d | Length High: %d | Type: %d.\n",
(unsigned int)entry->addr_low, (unsigned int)entry->addr_high,
(unsigned int)entry->len_low, (unsigned int)entry->len_high, (unsigned int)entry->type);
entry = (void *)entry + memory_map->entry_size;
}
}
Code: Select all
# Declare constants for the multiboot 2 header.
.set FLAGS, 0 # this is the Multiboot 'flag' field
.set MAGIC, 0xE85250D6 # 'magic number' lets bootloader find the header
.set SIZE, header_end - header_start
.set CHECKSUM, -(MAGIC + FLAGS + SIZE) # checksum of above, to prove we are multiboot
# Declare a header as in the Multiboot Standard.
.section .multiboot,"a",@progbits
.align 8
header_start:
.long MAGIC
.long FLAGS
.long SIZE
.long CHECKSUM
# Tags go here
.align 8
.short 1
.short 0
.long 12
.long 6
# Ending tag
.align 8
.short 0
.short 0
.long 8
header_end:
Code: Select all
struct multiboot_mmap_entry
{
multiboot_uint32_t size;
multiboot_uint32_t addr_low;
multiboot_uint32_t addr_high;
multiboot_uint32_t len_low;
multiboot_uint32_t len_high;
#define MULTIBOOT_MEMORY_AVAILABLE 1
#define MULTIBOOT_MEMORY_RESERVED 2
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
#define MULTIBOOT_MEMORY_NVS 4
#define MULTIBOOT_MEMORY_BADRAM 5
multiboot_uint32_t type;
} __attribute__((packed));
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
