Page 1 of 1

[SOLVED] GRUB Multiboot and Graphic Mode

Posted: Tue Jan 26, 2021 1:31 pm
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

Re: GRUB Multiboot and Graphic Mode

Posted: Tue Jan 26, 2021 2:24 pm
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).

Re: GRUB Multiboot and Graphic Mode

Posted: Tue Jan 26, 2021 3:54 pm
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