OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:43 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: How do you access arguments from GRUB in kernel?
PostPosted: Sat May 14, 2022 6:49 pm 
Offline
Member
Member

Joined: Sun May 08, 2022 2:10 am
Posts: 70
How would you go about accessing arguments that GRUB passed to the kernel, for example like this:
Code:
menuentry "Example" {
    mutliboot /boot/os.elf argument=value
}

How would you be able to access the "argument"?


Top
 Profile  
 
 Post subject: Re: How do you access arguments from GRUB in kernel?
PostPosted: Sat May 14, 2022 7:40 pm 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
In Multiboot 1, the "cmdline" struct member is a 32-bit pointer to a null-terminated string that is passed along with the rest of the multiboot data.

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


Top
 Profile  
 
 Post subject: Re: How do you access arguments from GRUB in kernel?
PostPosted: Sun May 15, 2022 5:26 am 
Offline
Member
Member
User avatar

Joined: Fri Jun 11, 2021 6:02 am
Posts: 96
Location: Belgium
https://ftp.gnu.org/old-gnu/Manuals/gru ... iboot.html

I would also consider using Multiboot2 instead.

_________________
My OS is Norost B (website, Github, sourcehut)
My filesystem is NRFS (Github, sourcehut)


Top
 Profile  
 
 Post subject: Re: How do you access arguments from GRUB in kernel?
PostPosted: Sun May 15, 2022 1:22 pm 
Offline
Member
Member

Joined: Sun May 08, 2022 2:10 am
Posts: 70
Hmmm, I checked using grub-file, my kernel is multiboot 1, but not multiboot 2 compliant. But I don't believe that I know how I could access the args. Unless the
Code:
.long FLAGS
line in the muliboot header that's back in boot.S is the arguments? Even then, how would I be able to access that all the way over in the Kernel? Since I really would rather not be trying to do it with asm. If that's the ONLY possible way to do it then I will, but if I could pass it to the kernel and check it from there, I would much rather do that.


Top
 Profile  
 
 Post subject: Re: How do you access arguments from GRUB in kernel?
PostPosted: Sun May 15, 2022 2:16 pm 
Offline
Member
Member
User avatar

Joined: Fri Jun 11, 2021 6:02 am
Posts: 96
Location: Belgium
Techflash wrote:
Since I really would rather not be trying to do it with asm. If that's the ONLY possible way to do it then I will, but if I could pass it to the kernel and check it from there, I would much rather do that.


You will have to use assembly. It's the only way to get the values out of the registers before they get clobbered. Besides, you should have some assembly already anyways to set up the stack.

_________________
My OS is Norost B (website, Github, sourcehut)
My filesystem is NRFS (Github, sourcehut)


Top
 Profile  
 
 Post subject: Re: How do you access arguments from GRUB in kernel?
PostPosted: Sun May 15, 2022 4:06 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
Techflash wrote:
Even then, how would I be able to access that all the way over in the Kernel?

When the bootloader jumps to your kernel entry point, EBX contains a pointer to the Multiboot information structure. You can pass that pointer to your main C function and then access all of the Multiboot information from C, including the kernel command line.

If you copied your code from a tutorial, it may already pass the pointer in EBX to your main C function.

Demindiro wrote:
https://ftp.gnu.org/old-gnu/Manuals/grub-0.92/html_mono/multiboot.html

Huh, why not link the latest version of the spec?


Top
 Profile  
 
 Post subject: Re: How do you access arguments from GRUB in kernel?
PostPosted: Sun May 15, 2022 4:14 pm 
Offline
Member
Member
User avatar

Joined: Fri Jun 11, 2021 6:02 am
Posts: 96
Location: Belgium
Octocontrabass wrote:


I picked whatever from GNU showed up first when searching for it. I admittedly didn't check the version.

_________________
My OS is Norost B (website, Github, sourcehut)
My filesystem is NRFS (Github, sourcehut)


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 59 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