How to enable the graphic mode by grub2?

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
theflysong
Member
Member
Posts: 27
Joined: Wed Jun 29, 2022 2:17 am
Libera.chat IRC: theflysong

How to enable the graphic mode by grub2?

Post 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
I'm a new man to develop operating system.
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: How to enable the graphic mode by grub2?

Post 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.
theflysong
Member
Member
Posts: 27
Joined: Wed Jun 29, 2022 2:17 am
Libera.chat IRC: theflysong

Re: How to enable the graphic mode by grub2?

Post 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"
I'm a new man to develop operating system.
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: How to enable the graphic mode by grub2?

Post 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
theflysong
Member
Member
Posts: 27
Joined: Wed Jun 29, 2022 2:17 am
Libera.chat IRC: theflysong

Re: How to enable the graphic mode by grub2?

Post 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
I'm a new man to develop operating system.
theflysong
Member
Member
Posts: 27
Joined: Wed Jun 29, 2022 2:17 am
Libera.chat IRC: theflysong

Re: How to enable the graphic mode by grub2?

Post 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
I'm a new man to develop operating system.
Post Reply