OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Sep 20, 2020 2:56 pm

All times are UTC - 6 hours




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Get the value "text-and-data" from grub
PostPosted: Fri Jan 08, 2010 4:23 am 
Offline
Member
Member

Joined: Thu Apr 10, 2008 1:47 am
Posts: 104
Hi,
as you can see in the picture grub display an information "text-and-data" which is the size of the loaded kernel in memory.
How to get this information that is not present in multiboot information structure ?

Thanks

Attachment:
grub.png

_________________
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !


Top
 Profile  
 
 Post subject: Re: Get the value "text-and-data" from grub
PostPosted: Fri Jan 08, 2010 5:28 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9287
Location: On the balcony, watching the Swedish Chef
Grub prints information of the ELF header, that's where you should get your data from: put a reference to the end of the image in your code, and your linker script. If you used the barebones' script, you can use this:

Code:
extern char sbss; // first byte in the BSS section
(...)
intptr_t image_end = (intptr_t)&sbss; // address where BSS starts, and thus where .text and .data ends

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Get the value "text-and-data" from grub
PostPosted: Fri Jan 08, 2010 8:03 am 
Offline
Member
Member

Joined: Thu Apr 10, 2008 1:47 am
Posts: 104
As it can be seen on the picture (but not be readed in the text :oops: ), i have no ELF header because my kernel is a PE file.
And because i use VS2008 i have not LD script of course so i don't use barebones'script but the excellent :mrgreen: Booting non-ELF kernel with GRUB tutorial

To impliment my physical memory manager i must know the kernel size, so grub know and display it but don't provide info if not ELF or a.out format

_________________
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !


Top
 Profile  
 
 Post subject: Re: Get the value "text-and-data" from grub
PostPosted: Fri Jan 08, 2010 8:31 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2637
Location: Devon, UK
Hi,

1. Parse the PE headers,
2. Find a way of sticking markers at the start and end of your kernel (same idea as the linker script), or...
3. Use an Elf GCC Cross-Compiler.

Cheers,
Adam


Top
 Profile  
 
 Post subject: Re: Get the value "text-and-data" from grub
PostPosted: Fri Jan 08, 2010 9:28 am 
Offline
Member
Member

Joined: Thu Apr 10, 2008 1:47 am
Posts: 104
1 & 2 are the way i was thinking
3 : no way for different reasons

Thanks

In fact the easiest way was to ask it to Grub because he had the information.
I'll see in grub source maybe ...

_________________
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !


Top
 Profile  
 
 Post subject: Re: Get the value "text-and-data" from grub
PostPosted: Fri Jan 08, 2010 9:42 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9287
Location: On the balcony, watching the Swedish Chef
Grub knows the filesize, that's it...

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: Get the value "text-and-data" from grub
PostPosted: Fri Jan 08, 2010 5:40 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1444
IMAGE_OPTIONAL_HEADER->SizeOfImage is what you want. Its easy to write a generic PE getFileSize routine that the kernel can use.

_________________
OS Development Series | Project Neptune
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject: Re: Get the value "text-and-data" from grub
PostPosted: Mon Jan 11, 2010 4:42 am 
Offline
Member
Member

Joined: Thu Apr 10, 2008 1:47 am
Posts: 104
neon wrote:
IMAGE_OPTIONAL_HEADER->SizeOfImage is what you want. Its easy to write a generic PE getFileSize routine that the kernel can use.


Yes like that :
Code:
PartialMSDOS_HEADER *dh = (PartialMSDOS_HEADER *)LOADBASE;
NT_Header *nth = (NT_Header *)(dh->PEHeaderOffset + LOADBASE);
int iKernelSize = nth->OptionalHeader.SizeOfImage;


The information seems to be missing in the Grub multiboot info for non elf or a.out kernel.

_________________
[ Grub 2 | Visual Studio 2013 | PE File ]
The OsDev E.T.
Don't send OsDev MIB !


Top
 Profile  
 
 Post subject: Re: Get the value "text-and-data" from grub
PostPosted: Mon Jan 11, 2010 11:35 am 
Offline
Member
Member

Joined: Wed Oct 18, 2006 10:43 pm
Posts: 490
Location: Kansas City, KS, USA
gedd wrote:
The information seems to be missing in the Grub multiboot info for non elf or a.out kernel.

Of course it is. As has been pointed out already, and is painfully obvious if you bother to read the multiboot spec at all, GRUB only knows the ELF format. The a.out kludge is provided so that GRUB can load and properly zero the BSS section of any other kind of binary file, such as COFF or even PE (which you are constantly complaining about). If you'd properly fill in the values in the a.out kludge structure then perhaps you'd have much better luck here. As it is, GRUB doesn't even know about your BSS section so isn't bothering to zero it for you. I hope you're able to do that yourself, although it's much easier to just tell GRUB where it is and how big it is.

gedd wrote:
As it can be seen on the picture (but not be readed in the text :oops: ), i have no ELF header because my kernel is a PE file.
And because i use VS2008 i have not LD script of course so i don't use barebones script but the excellent :mrgreen: Booting non-ELF kernel with GRUB tutorial

I'd hardly call that an "excellent tutorial" if it doesn't cover half the things you need to know, like how to get the size of the kernel loaded in memory.

From your own tutorial:
Code:
multiboot_header:
    dd(MULTIBOOT_HEADER_MAGIC)      ; magic number
    dd(MULTIBOOT_HEADER_FLAGS)      ; flags
    dd(CHECKSUM)               ; checksum
    dd(HEADER_ADRESS)            ; header address
    dd(LOADBASE)               ; load address
    dd(00)                     ; load end address : not used
    dd(00)                     ; bss end addr : not used
    dd(HEADER_ADRESS + 0x20)      ; entry_addr : equ kernel entry     
                                    ; 0x20 is the size of multiboot heeader

Are you stupid, or just lazy? Actually, nevermind; I don't want to know. Either one isn't a proper excuse.

You've been given proper answers to this "question" of yours already. I've just given you another. Pick something and implement it. If you can't be bothered to learn how to properly use your compiler toolchain (which seems to be the case), you've broken forum rule #3. As far as I'm concerned, you also broke rule #4.

Since GRUB doesn't work for you, perhaps you should just extend it so that it does, or write a bootloader yourself to make sure you get absolutely everything you want in a bootloader. GRUB isn't for everyone, but at least most people here follow the advice they are given and move on, rather than complaining about the same old crap day in and day out.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Ethin, mrjbom and 11 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