Page 1 of 1

How to enable the graphic mode by grub2?

Posted: Wed Jun 29, 2022 2:27 am
by theflysong
I'm sorry my English is poor, but I will try my best to express the problem clearly.
This is my multiboot2 header, but it doesn't work

Code: Select all

struct os_header {
    struct multiboot_header header;
#ifdef VBE_ENABLE
    struct multiboot_header_tag_framebuffer framebuffer;
#endif
    struct multiboot_header_tag end;
} __attribute__((packed));

struct os_header OS_HEADER __attribute__((section(".multiboot"))) = {
    .header = {
        .magic    = MULTIBOOT2_HEADER_MAGIC,
        .architecture = MULTIBOOT_ARCHITECTURE_I386,
        .header_length = sizeof (struct tayhuang_header),
        .checksum = -(MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + sizeof(struct tayhuang_header)),
    },
#ifdef VBE_ENABLE
    #define FRAMEBUFFER_WIDTH 1024
    #define FRAMEBUFFER_HEIGHT 768
    #define FRAMEBUFFER_BPP 24
    //FIXME: Error here
    .framebuffer = {
        .type = MULTIBOOT_HEADER_TAG_FRAMEBUFFER,
        .flags = MULTIBOOT_HEADER_TAG_OPTIONAL,
        .size = sizeof (struct multiboot_header_tag_framebuffer),
        .width = FRAMEBUFFER_WIDTH,
        .height = FRAMEBUFFER_HEIGHT,
        .depth = FRAMEBUFFER_BPP
    },

#endif
    .end = {
        .type = MULTIBOOT_HEADER_TAG_END,
        .flags = 0,
        .size = sizeof (struct multiboot_header_tag)
    }
};
It works well.

When I insert the following line to enable the graphic mode

Code: Select all

#define VBE_ENABLE
I get "error: unsupported tag 0x8"

what's wrong with it

Re: How to enable the graphic mode by grub2?

Posted: Wed Jun 29, 2022 3:16 am
by klange
There are two framebuffer tags, one for your request to the bootloader, and one for the bootloader's response to your request.

8 is the ID for the latter. You want 5 for the former.

Re: How to enable the graphic mode by grub2?

Posted: Wed Jun 29, 2022 3:24 am
by theflysong
klange wrote:There are two framebuffer tags, one for your request to the bootloader, and one for the bootloader's response to your request.

8 is the ID for the latter. You want 5 for the former.
I know.
I‘ve changed
.type = MULTIBOOT_HEADER_TAG_FRAMEBUFFER
into
.type = 5

It still doesn't work
And I still get "error: unsupported tag 0x8"

Re: How to enable the graphic mode by grub2?

Posted: Wed Jun 29, 2022 4:24 am
by klange
Your tags probably aren't aligned correctly, then. Your struct doesn't look like it will do the right thing for that - building the multiboot structs in C is unorthodox, they're usually done in assembly.

Someone else had a similar issue several years ago: viewtopic.php?f=1&t=27602

Re: How to enable the graphic mode by grub2?

Posted: Wed Jun 29, 2022 5:19 am
by theflysong
klange wrote:Your tags probably aren't aligned correctly, then. Your struct doesn't look like it will do the right thing for that - building the multiboot structs in C is unorthodox, they're usually done in assembly.

Someone else had a similar issue several years ago: viewtopic.php?f=1&t=27602
I've add the __attribute__((packed)). So I think they're aligned correctly
But I will check it, thank you

Re: How to enable the graphic mode by grub2?

Posted: Wed Jun 29, 2022 5:29 am
by theflysong
klange wrote:Your tags probably aren't aligned correctly, then. Your struct doesn't look like it will do the right thing for that - building the multiboot structs in C is unorthodox, they're usually done in assembly.

Someone else had a similar issue several years ago: viewtopic.php?f=1&t=27602
Thank you
I insert the

Code: Select all

 multiboot_uint32_t reserved0;
under the

Code: Select all

 struct multiboot_header_tag_framebuffer framebuffer; 
And it works pretty good

Thank you very much