OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 5:36 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: GRUB not returning correct Module End Address???
PostPosted: Sun Aug 20, 2017 11:46 pm 
Offline

Joined: Mon Jan 20, 2014 7:58 pm
Posts: 13
I am trying load a initrd like file (currently just a string) via GRUB's 'module' tag.
I have located the header (the value of ebx directly after grub passes over to my kernel)
Checked the flags to make sure a modules section was included(true)
Located the module header with the number of modules and the physical location.
Located the first(and subsequent) module entries.

All this is well and good until I try to calculate the length of the module in memory.
The module start_points to the correct data(I can print a null terminated string from this), but . module_end always point module_start+4


Code:
Offset | MOD0 + 0x00
0x00  | 0x00110000 <- Yep Aligned on 4K...
0x04  | 0x00110004 <- eh???
0x08  | 0x00110008 <- and same again?
0x0B  | 0x00000000 //zero's


Am I right in thinking that if I have a 10 character string + a null terminator that (0x04 module_end)=>0x0011000A

and if i include a 2nd modules
Code:
Offset | MOD1 + 0x10
0x00  | 0x00111000 <- Yep Aligned on 4K...
0x04  | 0x00111004 <- eh???
0x08  | 0x00111008 <- and same again?
0x0B  | 0x00000000 //zero's


If i make the string(initrd) over 4K long the addresses progress along by 4K but the end address is still the same

From what i can tell this might be a problem with grub-mkrescue and the image that is included in my ISO though its probably something stupid i've done.

Code:
grub-mkrescue --version
grub-mkrescue (GRUB) 2.03


and this is my grub menu entry
Code:
multiboot /Kernel.bin
module /initrd

where 'initrd' is a plain text file

Im stumped as I have found no reference to incorrect module_end anywhere

Thanks in advance and I can provide whatever is required
Grant

_________________
https://github.com/teenHack42/MatrixOS
Working on: PCI[E]
--
teenHack42


Top
 Profile  
 
 Post subject: Re: GRUB not returning correct Module End Address???
PostPosted: Mon Aug 21, 2017 12:29 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
It looks to me as if you are examining the pointers to the module structures in the boot information structure, rather than the module structures themselves. Have a look at what those fields point to.


Top
 Profile  
 
 Post subject: Re: GRUB not returning correct Module End Address???
PostPosted: Mon Aug 21, 2017 2:10 am 
Offline

Joined: Mon Jan 20, 2014 7:58 pm
Posts: 13
iansjack wrote:
It looks to me as if you are examining the pointers to the module structures in the boot information structure, rather than the module structures themselves. Have a look at what those fields point to.

Image
1) The address that the first Mod Structure says is the start of the module(It does contain the right data so i believe this)
2) The offset in the Mod Struct to module_end address.
3) The module end address??? please correct me if my pointer referencing isnt right
4) The physical Address of the pointer?
5) The first 4 bytes at the location('I', ' ', 'w', 'a') => 9x7420746E
6) and the output from printf when pointed at a string at 0x00110000

and 'Mods List Address' is where the start of the mod structures are..

So i'm pretty sure i'm reading the address if the start and end pointers from the module struct correctly?
If I am, what should I try doing with grub?(uninstall, submit a bug)

Grant

_________________
https://github.com/teenHack42/MatrixOS
Working on: PCI[E]
--
teenHack42


Top
 Profile  
 
 Post subject: Re: GRUB not returning correct Module End Address???
PostPosted: Mon Aug 21, 2017 3:17 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
I'm not sure that I follow what you are doing there.

It's fairly simple:

Offset 0x20 in the boot information structure contains a (32-bit) pointer to an array of module structures. These are of the form

u32 mod_start
u32 mod_end
char *string
u32 0

So try examining the 16 bytes at the address pointed to by offset 0x20 (and the next 16 bytes, and so on for module_count) as a raw hex dump and see what they look like. The first 4 should contain the address of the start of the module, the next four the address of the end of the module (and you can ignore the other 8 bytes).

I wouldn't submit a bug report - if this were a bug in Grub it would have been discovered long before now.

(Don't forget when doing pointer arithmetic in C that adding 1 to a pointer actually adds the size of the variable pointed to - so if you have an array of 32-bit integers, p points to the first integer, p+1 to the second, etc.)


Top
 Profile  
 
 Post subject: Re: GRUB not returning correct Module End Address???
PostPosted: Mon Aug 21, 2017 3:32 am 
Offline
Member
Member

Joined: Thu Jul 05, 2007 8:58 am
Posts: 223
Could you show us the code you use to read this information from the multiboot header?


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], Majestic-12 [Bot] and 124 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