Page 1 of 1

How do i load files using grub?

Posted: Fri Nov 30, 2007 10:40 pm
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?

Posted: Sat Dec 01, 2007 1:00 am
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.

Posted: Sun Dec 02, 2007 6:25 am
by JamesM
Also, check the bottom of this page.

Posted: Sun Dec 02, 2007 3:46 pm
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 '?'

Posted: Mon Dec 03, 2007 2:24 am
by JamesM
No. Firstly bootdata should be of type "unsigned int *".

Then...

Code: Select all

code = (char*)*bootdata;
Should do it.

Posted: Mon Dec 03, 2007 4:13 pm
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.

Posted: Tue Dec 04, 2007 2:37 am
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: ).