How do i load files using grub?

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
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

How do i load files using grub?

Post by Pyrofan1 »

i've read that you can use grub to load files for you into memory. how do i do this? and where in memory will they be?
User avatar
JackScott
Member
Member
Posts: 1036
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Mastodon: https://aus.social/@jackscottau
Matrix: @JackScottAU:matrix.org
GitHub: https://github.com/JackScottAU
Contact:

Post by JackScott »

http://www.gnu.org/software/grub/manual ... tml#module
http://www.gnu.org/software/grub/manual ... ion-format

Between those two documents, the ideas should become apparent. You specify that you want GRUB to load a module, and then parse the multiboot information structure to find the module in memory once you get into the kernel.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Also, check the bottom of this page.
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

okay after reading those links i came up with this:

Code: Select all

void _main(void* mbd,unsigned int magic)
{
        char *code;
        char *bootdata=mbd;	

        unsigned int flags;
        unsigned int loaded_modules;

        flags=(unsigned int)*bootdata;
	if((flags&0x08)==0x08)
	{
		Printf("Modules were loaded succesfully\n");
		bootdata+=20;
		loaded_modules=*bootdata;
		Printf("Number of modules loaded: %d\n",loaded_modules);
		bootdata+=4;
		code=&bootdata;
	}
	else
	{
		Printf("Modules were not succesfully loaded\n");
	}
now the file i want loaded looks like this

Code: Select all

=@aa#a!a
i when i run my OS it tells me that the modules have been loaded, but it seems the code pointer is pointing to the '@' and not the '=' like it's suppose to. and decrementing the pointer doesn't work because then it's pointing to a '?'
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

No. Firstly bootdata should be of type "unsigned int *".

Then...

Code: Select all

code = (char*)*bootdata;
Should do it.
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

that didn't work, now it tells me that the modules have been loaded, then it say that 0 modules have been loaded and now it seems that the code pointer is pointing to a random place in memory.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

yes, that is because "bootdata" is now 4 bytes long, so when you do "bootdata += 20" and "bootdata += 4" you are incrementing bootdata by 20*4 bytes and 4*4 bytes respectively. Divide each of those numbers by 4 (or alternatively, the better way, define a multiboot structure... :roll: ).
Post Reply