[SOLVED] GRUB Multiboot and Graphic Mode

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
User avatar
growlnx
Posts: 15
Joined: Sun Jan 05, 2020 5:51 pm
Libera.chat IRC: growlnx
Location: 0.0.0.0
Contact:

[SOLVED] GRUB Multiboot and Graphic Mode

Post by growlnx »

Hi all,

I'm using grub multiboot to boot my kernel (for 32-bit x86). Is there a way to use GOP (i'm not using the efi library)?
I also tried to enter in VESA graphic mode setting the flag in grub multiboot header, but i got an error (picture attached).

Code: Select all

MBALIGN  equ  1 << 0           
MEMINFO  equ  1 << 1          
MGRAPH_MODE equ 1 << 2
FLAGS    equ  MBALIGN | MEMINFO | MGRAPH_MODE
MAGIC    equ  0x1BADB002        
CHECKSUM equ -(MAGIC + FLAGS)

section .multiboot
	align 4
	dd MAGIC
	dd FLAGS
	dd CHECKSUM
Attachments
The kernel does not boot.
The kernel does not boot.
error_qemu_2021-01-26_16-29-12.png (5.89 KiB) Viewed 1616 times
Last edited by growlnx on Tue Jan 26, 2021 3:58 pm, edited 1 time in total.
Regards,
Growlnx.
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: GRUB Multiboot and Graphic Mode

Post by kzinti »

Sounds like you are missing a few fields in your header. Here is a working multiboot header to select a video mode:

Code: Select all

.equ MULTIBOOT_HEADER_MAGIC          , 0x1BADB002
.equ MULTIBOOT_HEADER_FLAGS          , 0x00000007   # VIDEO_MODE (4) + MEMORY_INFO (2) + PAGE_ALIGN (1)
.equ MULTIBOOT_HEADER_CHECKSUM       , -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) & 0xFFFFFFFF

.align 16, 0
multiboot_header:
    .long   MULTIBOOT_HEADER_MAGIC
    .long   MULTIBOOT_HEADER_FLAGS
    .long   MULTIBOOT_HEADER_CHECKSUM

    # aout kludge (unused)
    .long 0,0,0,0,0

    # Video mode
    .long   0       # Linear graphics please?
    .long   0       # Preferred width
    .long   0       # Preferred height
    .long   32      # Preferred pixel depth
I set the preferred "width" and "height" to zero because I don't have any preferences. But you could put what you want there (1024x768 for example).
User avatar
growlnx
Posts: 15
Joined: Sun Jan 05, 2020 5:51 pm
Libera.chat IRC: growlnx
Location: 0.0.0.0
Contact:

Re: GRUB Multiboot and Graphic Mode

Post by growlnx »

kzinti wrote:Sounds like you are missing a few fields in your header. Here is a working multiboot header to select a video mode:

Code: Select all

.equ MULTIBOOT_HEADER_MAGIC          , 0x1BADB002
.equ MULTIBOOT_HEADER_FLAGS          , 0x00000007   # VIDEO_MODE (4) + MEMORY_INFO (2) + PAGE_ALIGN (1)
.equ MULTIBOOT_HEADER_CHECKSUM       , -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) & 0xFFFFFFFF

.align 16, 0
multiboot_header:
    .long   MULTIBOOT_HEADER_MAGIC
    .long   MULTIBOOT_HEADER_FLAGS
    .long   MULTIBOOT_HEADER_CHECKSUM

    # aout kludge (unused)
    .long 0,0,0,0,0

    # Video mode
    .long   0       # Linear graphics please?
    .long   0       # Preferred width
    .long   0       # Preferred height
    .long   32      # Preferred pixel depth
I set the preferred "width" and "height" to zero because I don't have any preferences. But you could put what you want there (1024x768 for example).
It's working Thanks!! :D

Code: Select all

MAGIC equ 0x1BADB002
FLAG_VIDEO_MODE equ (1 << 2)
FLAGS equ FLAG_VIDEO_MODE
CHECKSUM equ -(MAGIC + FLAGS) & 0xFFFFFFFF
HEADER_ADDR equ 0 ; if flags[16] is set
LOAD_ADDR equ	0 ; if flags[16] is set
LOAD_END_ADDR equ	0 ; if flags[16] is set
BSS_END_ADDR equ 0 ; if flags[16] is set
ENTRY_ADDR equ 0 ; if flags[16] is set
MODE_TYPE equ 0 ; if flags[2] is set
WIDTH equ 0 ; if flags[2] is set
HEIGHT equ 0 ; if flags[2] is set
DEPTH equ 0x20 ; if flags[2] is set

section .multiboot
	align 4
	dd MAGIC
	dd FLAGS
	dd CHECKSUM
	dd HEADER_ADDR
	dd LOAD_ADDR
	dd LOAD_END_ADDR
	dd BSS_END_ADDR
	dd ENTRY_ADDR
	dd MODE_TYPE
	dd WIDTH
	dd HEIGHT
	dd DEPTH
References:
- https://www.gnu.org/software/grub/manua ... gic-fields
Regards,
Growlnx.
Post Reply