OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: How to create 64bits multiboot2 graphics os with GRUB2 ?
PostPosted: Sat Jan 02, 2021 9:08 am 
Offline

Joined: Sat Jan 02, 2021 8:50 am
Posts: 2
Hi everybody!
I'd like to create a little operating system for fun who can works on my personal computer basically to understand computer mecanics.
Until now I just worked on a VGA Text mode "kernel" (not really, just some c functions for wrtiting on the screen).
It's really easy to work with in qemu or real hardware but graphics scared me.
It seem difficult to find some resources who can help.
I understand that I need to get the video framebuffer address to work with but I don't see anything who can help me on internet.
I used this multiboot2 header for now with nasm:
Code:
section .multiboot_header
header_start:
    dd 0xe85250d6
    dd 0
    dd header_end - header_start

    dd 0x100000000 - (0xe85250d6 + 0 + (header_end - header_start))

align 8
    dw 5
    dw 1
    dd 20
    dd 1024
    dd 768
    dd 32

align 8
    dw 0
    dw 0
    dd 8
header_end:

On the gnu multiboot2 specification webpage I can't understand how used the multiboot2 header file.
I thought I could find it but really nothing about seem existing on internet.
Anyway, thanks a lot for taking time reading. :)


Top
 Profile  
 
 Post subject: Re: How to create 64bits multiboot2 graphics os with GRUB2 ?
PostPosted: Sat Jan 02, 2021 6:58 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
I'm a bit confused. Where exactly are you getting stuck?


Top
 Profile  
 
 Post subject: Re: How to create 64bits multiboot2 graphics os with GRUB2 ?
PostPosted: Sun Jan 03, 2021 2:25 am 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
Here is how I parse the multiboot2 information:

https://github.com/kiznit/rainbow-os/bl ... #L219-L351

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: How to create 64bits multiboot2 graphics os with GRUB2 ?
PostPosted: Sun Jan 03, 2021 10:11 am 
Offline

Joined: Sat Jan 02, 2021 8:50 am
Posts: 2
Thank for your answers!
For be clear, I'm confused by how to use the multiboot2.h header file suggested on the gnu website.
I want to get the framebuffer address for working in graphics mode. I think I have to get some others information too.
If I understand I can do this by implement a multiboot header.
My confused is that I can't find how to properly implement the multiboot2 specification in my project.
At the moment I use the grub2 bootloader.
Here is my kernel.c code:
Code:
// multiboot2 file found on the gnu website
// https://www.gnu.org/software/grub/manual/multiboot2/multiboot.html#multiboot2_002eh
#include "multiboot2.h"
// .multiboot_header is defined in the linker.ld file below
struct multiboot_header test __attribute__((section(".multiboot_header"))) = {
    MULTIBOOT2_HEADER_MAGIC,
    MULTIBOOT_ARCHITECTURE_I386,
    // don't know how to get header size by c code
    0, 
    0x100000000 - (MULTIBOOT2_HEADER_MAGIC + MULTIBOOT_ARCHITECTURE_I386 + 0)
};

struct multiboot_header_tag test_2 __attribute__((section(".multiboot_header"))) = {
    .type = 0,
    .flags = 0,
    .size = 8
};

void kernel_start () {
    // 0xa0000 address is used for example
    // the above code is incorrect
    unsigned int *buffer = (unsigned int *) 0xa0000;
    for (int i = 0; i < 640 * 480; i++) {
        buffer[i] = 0x4398DE19;
    }   
    while (1) {}
}

Here is my linker.ld file if it can help to understand:
Code:
ENTRY(kernel_start)

SECTIONS {
    . = 1M;

    .boot : ALIGN(0x1000)
    {   
        *(.multiboot_header)
    }   
    .text : ALIGN(0x1000)
    {   
        *(.text)
    }   
}


Top
 Profile  
 
 Post subject: Re: How to create 64bits multiboot2 graphics os with GRUB2 ?
PostPosted: Sun Jan 03, 2021 7:04 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Filadelphila wrote:
For be clear, I'm confused by how to use the multiboot2.h header file suggested on the gnu website.

You don't have to use it. It's an example that shows one way you might define the things you need in order to make your OS compatible with multiboot2. You can

Filadelphila wrote:
My confused is that I can't find how to properly implement the multiboot2 specification in my project.

I suggest writing the multiboot2 header in assembly, like you already have, and linking it together with the rest of your kernel.

Since you want 64-bit code, you also need to write assembly code to switch the CPU from 32-bit mode to 64-bit mode, set up the stack, and pass the multiboot2 information pointer to your C function. Getting all of that to work together correctly can be a challenge, so you might want to stick to 32-bit mode for now. (But you still need to set up the stack and pass the multiboot2 information pointer.)

Once your C code has access to the multiboot2 information pointer, you can use it to find the address of the framebuffer.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], nullpointer and 67 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