Determining size of kernel
-
Avery Fay
Determining size of kernel
I'm working on a kernel that is currently being loaded into memory by GRUB. I would like to know how large the kernel is so that my page allocator won't allocate the page(s) taken by it. Can GRUB provide this information? If not, how would I get this information?
-
Tim
Re:Determining size of kernel
Whatever5k's reply is a bit of a red herring
-- the size of the kernel on disk will usually be less than the size in memory, because the bss isn't present on disk, and because the alignment on disk can be less than that in memory.
You'll need to write a linker script for your kernel, if you haven't already done so.
Then you can declare the scode and end variables in your source file:
The total size of the kernel in memory is (end - scode) bytes. The size of the .text section is (ecode - scode); data is (edata - ecode); bss is (ebss - edata).
You'll need to write a linker script for your kernel, if you haven't already done so.
Code: Select all
OUTPUT_FORMAT("pei-i386") /* or whatever */
ENTRY(_start32)
SECTIONS
{
/* kernel code */
.text 0xC0000000 :
{
_scode = .;
*(.text)
. = ALIGN(4096);
_ecode = .;
}
/* kernel data */
.data :
{
libc_first_ctor = . ;
*(.ctor)
libc_last_ctor = . ;
libc_first_dtor = . ;
*(.dtor)
libc_last_dtor = . ;
*(.data)
*(.eh_frame)
*(.gcc_except_table)
. = ALIGN(4096);
_edata = .;
}
/* kernel BSS */
.bss :
{
*(.bss)
*(COMMON)
_ebss = .;
}
_end = .;
}Code: Select all
extern char scode[], end[];-
Avery Fay
Re:Determining size of kernel
Thanks a lot. I think I understand the script for the most part. What linker are you using? And will the align directives cause each section to be page aligned or only the whole image? Also, do you know of any documentation on linking and ld (other than the man page)?
-
Tim
Re:Determining size of kernel
Cygwin ld, although this should work for any ld version.Avery Fay wrote:Thanks a lot. I think I understand the script for the most part. What linker are you using?
They cause the start of each section to be page-aligned in memory. The on-disk alignment might be different if the format you are using supports that. BTW: note that the base address here is 0xC0000000; you might want to change that if you're not using paging.And will the align directives cause each section to be page aligned or only the whole image?
info ldAlso, do you know of any documentation on linking and ld (other than the man page)?
I don't know of any apart from that :/
-
Avery Fay
Re:Determining size of kernel
I got most of the it working... however I still have one question that maybe someone could answer. In the above example, does _end have the first memory location after the image? Or is the address pointed to by _end actually used. For example, suppose _end was 0x00100000. Would the whole page from 0x00100000 - 0x00100FFF be available or only 0x00100001 - 0x00100FFF?