Why is this string not being printed? Causes Grub Error 13

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
username291
Posts: 7
Joined: Tue Aug 12, 2025 1:48 pm

Why is this string not being printed? Causes Grub Error 13

Post by username291 »

isr.c file

Code: Select all

#include <stdint.h>
#define VGA_MEM 0x000B8000

__attribute__((noreturn))
void exception_handler(void) 
{
    char* msg = "Exception occurred";
    uint16_t* fb = (uint16_t*)VGA_MEM;
    for (int i = 0; msg[i]; i++)
    {
        fb[i] = msg[i] | (0x07 << 8);
    }
    __asm__ volatile ("cli; hlt");
    while(1);
}
this ISR is called when any CPU exception occurs

when i launch bochs with kernel.elf containing this char* msg, it says Grub Error 13 invalid executable format
but if i put char[] msg then it works. Please can you help me

link.ld file

Code: Select all

ENTRY(loader)                /* the name of the entry label */

SECTIONS {
    . = 0x00100000;          /* the code should be loaded at 1 MB */

    .text ALIGN (0x1000) :   /* align at 4 KB */
    {
        *(.text)             /* all text sections from all files */
    }

    .rodata ALIGN (0x1000) : /* align at 4 KB */
    {
        *(.rodata*)          /* all read-only data sections from all files */
    }

    .data ALIGN (0x1000) :   /* align at 4 KB */
    {
        *(.data)             /* all data sections from all files */
    }

    .bss ALIGN (0x1000) :    /* align at 4 KB */
    {
        *(COMMON)            /* all COMMON sections from all files */
        *(.bss)              /* all bss sections from all files */
    }
}
username291
Posts: 7
Joined: Tue Aug 12, 2025 1:48 pm

Re: Why is this string not being printed? Causes Grub Error 13

Post by username291 »

I think I have fixed this

The problem was in my loader.asm file:

Code: Select all

. . .

section .text:                  ; start of the text (code) section
align 4                         ; the code must be 4 byte aligned
    dd MAGIC_NUMBER             ; write the magic number to the machine code,
    dd FLAGS                    ; the flags,
    dd CHECKSUM                 ; and the checksum

. . .
which I got from the little os book

after i changed "section .text:" to "section .text" without the ":" symbol, grub error 13 disappeared and the string got printed
Post Reply