Multiboot 1 information data structure help needed

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
shouldntbenearapc
Posts: 2
Joined: Thu Sep 19, 2024 11:14 am

Multiboot 1 information data structure help needed

Post by shouldntbenearapc »

Hello,
I'm new to OSDev. I have followed the Bare Bones tutorial and now I want to parse the Multiboot 1 information data structure which I succeeded at to some point. However, when trying to access the boot_loader_name field I'm getting output which isn't a boot loader name. It's just one letter, either 'S' when launching qemu with the kernel parameter or 'W' when launching qemu with an iso grub built. Accessing the cmdline field works and I can even append additional parameters there. I'm getting the correct magic value from EAX after converting it to hexadecimal which is 0x2BADB002 and the flags field gives back 591 (1001001111) which should mean flags[9] is set which is the boot_loader_name flag.
I would like to understand why this is the boot loader name I'm getting. I know I haven't finished representing the entire data structure in my C struct. Could that be causing it?
This is my multiboot struct and kernel main function:

Code: Select all

typedef struct  {
    uint32_t flags;
    uint32_t mem_low;
    uint32_t mem_high;
    uint32_t boot_dev;
    uint32_t cmdline;
    uint32_t mods_count;
    uint32_t mods_addr;
    union {
        uint32_t syms1;
        uint32_t syms2;
    } u;
    uint32_t mmap_length;
    uint32_t mmap_addr;
    uint32_t drive_length;
    uint32_t drive_addr;
    uint32_t config_table;
    uint32_t boot_loader_name;
} __attribute__((packed)) mboot;

void kernel_main(mboot *arg1, uint32_t *magic) {
    terminal_initialize();
    if (init_serial() == 1) {
        terminal_writestring("Serial init fail\n");
    };
    
    char magicstr[100] = {0};
    intstr(magic, magicstr);
    terminal_writestring(magicstr);
    write_serialstr(magicstr);
    
    char test[100] = {0};  
    intstr(arg1->flags, test);
    write_serialstr(test);
    terminal_writestring((char *) arg1->cmdline);
    terminal_writestring("\n");
    terminal_writestring((char *) arg1->boot_loader_name);
    terminal_writestring("\n");

}
and this is my fasm assembly

Code: Select all

format ELF
org 0x100000
use32

MEMINFO = 2
FLAGS = 3
MAGIC = 0x1BADB002
CHECKSUM = -(MAGIC + FLAGS)

section '.multiboot' align 4
    dd MAGIC
    dd FLAGS
    dd CHECKSUM 
    dd _start
section '.bss' align 16
section '.text' executable
public _start
extrn kernel_main
_start:
    mov esp, stack_top
    push $0
    popf
    push eax
    push ebx
    call kernel_main
    cli
_loop:  
    hlt
    jmp _loop


rb 16384
stack_top:
User avatar
iansjack
Member
Member
Posts: 4700
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Multiboot 1 information data structure help needed

Post by iansjack »

The syms union in the multiboot info structure should be 16 bytes; you only have it as 4 bytes, so everything after that is misaligned.
shouldntbenearapc
Posts: 2
Joined: Thu Sep 19, 2024 11:14 am

Re: Multiboot 1 information data structure help needed

Post by shouldntbenearapc »

iansjack wrote: Thu Sep 19, 2024 1:52 pm The syms union in the multiboot info structure should be 16 bytes; you only have it as 4 bytes, so everything after that is misaligned.
Thank you, that fixed it.
Post Reply