OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:05 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: GRUB Booting with Error: No suitable video mode
PostPosted: Sun Jul 17, 2022 12:31 pm 
Offline

Joined: Sun Jul 17, 2022 12:18 pm
Posts: 1
[Sorry for my poor english I'm french :)]

Hello guys, i have some problems with booting my os on my laptop.
I tried this basic tutorial to boot with grub: https://wiki.osdev.org/Bare_Bones#Booti ... ing_System
When I launched with qemu, all is good and no error appears but when I put my OS on a key and booting, it's perfectly starting GRUB
but when I'm selecting my OS it failed with error:
"error: no suitable video mode found"

So, if someone can help me with this I will be glad.
Here is all code that I used (code gave on the tutorial)

kernel.c
Code:
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

/* Check if the compiler thinks you are targeting the wrong operating system. */
#if defined(__linux__)
   #error "You are not using a cross-compiler, you will most certainly run into trouble"
#endif

/* This tutorial will only work for the 32-bit ix86 targets. */
#if !defined(__i386__)
   #error "This tutorial needs to be compiled with a ix86-elf compiler"
#endif

/* Hardware text mode color constants. */
enum vga_color {
   VGA_COLOR_BLACK = 0,
   VGA_COLOR_BLUE = 1,
   VGA_COLOR_GREEN = 2,
   VGA_COLOR_CYAN = 3,
   VGA_COLOR_RED = 4,
   VGA_COLOR_MAGENTA = 5,
   VGA_COLOR_BROWN = 6,
   VGA_COLOR_LIGHT_GREY = 7,
   VGA_COLOR_DARK_GREY = 8,
   VGA_COLOR_LIGHT_BLUE = 9,
   VGA_COLOR_LIGHT_GREEN = 10,
   VGA_COLOR_LIGHT_CYAN = 11,
   VGA_COLOR_LIGHT_RED = 12,
   VGA_COLOR_LIGHT_MAGENTA = 13,
   VGA_COLOR_LIGHT_BROWN = 14,
   VGA_COLOR_WHITE = 15,
};

static inline uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg)
{
   return fg | bg << 4;
}

static inline uint16_t vga_entry(unsigned char uc, uint8_t color)
{
   return (uint16_t) uc | (uint16_t) color << 8;
}

size_t strlen(const char* str)
{
   size_t len = 0;
   while (str[len])
      len++;
   return len;
}

static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;

size_t terminal_row;
size_t terminal_column;
uint8_t terminal_color;
uint16_t* terminal_buffer;

void terminal_initialize(void)
{
   terminal_row = 0;
   terminal_column = 0;
   terminal_color = vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK);
   terminal_buffer = (uint16_t*) 0xB8000;
   for (size_t y = 0; y < VGA_HEIGHT; y++) {
      for (size_t x = 0; x < VGA_WIDTH; x++) {
         const size_t index = y * VGA_WIDTH + x;
         terminal_buffer[index] = vga_entry(' ', terminal_color);
      }
   }
}

void terminal_setcolor(uint8_t color)
{
   terminal_color = color;
}

void terminal_putentryat(char c, uint8_t color, size_t x, size_t y)
{
   const size_t index = y * VGA_WIDTH + x;
   terminal_buffer[index] = vga_entry(c, color);
}

void terminal_putchar(char c)
{
   terminal_putentryat(c, terminal_color, terminal_column, terminal_row);
   if (++terminal_column == VGA_WIDTH) {
      terminal_column = 0;
      if (++terminal_row == VGA_HEIGHT)
         terminal_row = 0;
   }
}

void terminal_write(const char* data, size_t size)
{
   for (size_t i = 0; i < size; i++)
      terminal_putchar(data[i]);
}

void terminal_writestring(const char* data)
{
   terminal_write(data, strlen(data));
}

void kernel_main(void)
{
   /* Initialize terminal interface */
   terminal_initialize();

   /* Newline support is left as an exercise. */
   terminal_writestring("Hello, kernel World!");
}


boot.asm
Code:
; constants for multiboot header
; See more tutorials for better comprehension
MALIGN      equ  1<<0               ; Align all modules on page boudaries, (need) (more details) Also 1 << 0 == 1 (fucking tutorial)
MEMINFO     equ  1<<1               ; provide memory map
FLAGS       equ  MALIGN | MEMINFO   ; I think FLAGS = 11 ? It's multiboot flag field
MAGIC       equ  0x1BADB002         ; magic number
CHECKSUM    equ -(MAGIC + FLAGS)    ; checksum of above, to prove we are multiboot

; set multiboot section
section .multiboot
    align 4
    dd MAGIC
    dd FLAGS
    dd CHECKSUM

section .data
    align 4096

; initial stack
section .initial_stack, nobits
    align 4

stack_bottom:
    ; 1 MB of uninitialized data for stack
    resb 104856
stack_top:

; kernel entry, main text section
section .text
    global _start


; define _start, aligned by linker.ld script
_start:
    mov esp, stack_top
    extern kernel_main
    push ebx
    call kernel_main
loop:
    jmp loop


Makefile
Code:
ASM_SRC      = boot.asm
NASM      = nasm
ASM_FLAGS   = -f elf32

CC         = i386-elf-gcc
C_SRC      = kernel.c
C_FLAGS      = -W -std=gnu99 -ffreestanding -O2 -Wall -Wextra

OBJ         = $(ASM_SRC:.asm=.o) $(C_SRC:.c=.o)
QEMU      = qemu-system-i386
QEMU_FLAGS   = -cdrom
LD         = ld/linker.ld
GRUB      = grub/grub.cfg

OS_NAME      = myos
OS_BIN      = $(OS_NAME).bin
OS_ISO      = $(OS_NAME).iso

all: build
   mkdir -p isodir/boot/grub
   cp $(OS_BIN) isodir/boot/$(OS_BIN)
   cp $(GRUB) isodir/boot/$(GRUB)
   grub-mkrescue -o $(OS_ISO) isodir

build: $(OBJ)
   $(CC) -T $(LD) -o $(OS_BIN) -ffreestanding -O2 -nostdlib $(OBJ) -lgcc

run:
   $(QEMU) $(QEMU_FLAGS) $(OS_ISO)

clean:
   $(RM) $(OBJ)
   $(RM) *.bin

fclean: clean
   $(RM) *.iso

re: fclean all

key:
   sudo dd if=$(OS_ISO) of=/dev/sda && sync

%.o: %.c
   $(CC) -c $(C_FLAGS) -o $@ $<

%.o: %.asm
   $(NASM) $(ASM_FLAGS) -o $@ $<


Thanks for all !


Top
 Profile  
 
 Post subject: Re: GRUB Booting with Error: No suitable video mode
PostPosted: Wed Jul 20, 2022 6:40 pm 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
If you are using grub-efi, it may be having trouble because your Multiboot header does not advertise support for graphics modes and Grub is unable to switch to text mode in EFI.

Quote:
Code:
Also 1 << 0 == 1 (fucking tutorial)

You will find any code in which a series of bits is defined tends to use "1 << 0" for 1 when it then uses "1 << 1" for 2 and "1 << 2" for 4. That's generally considered good practice for defining bitfield values.

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 56 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group