kernel symbols
kernel symbols
Hi, im new to this board.
I want to calculate the size of my kernel at runtime,
and i know that I can set symbols like _kernel_start and _kernel_end to do that. But what I want to know is how to do that. How to set them, and how to read them. I've tried to find out, but cant find anything. Im using gcc.
/norton
I want to calculate the size of my kernel at runtime,
and i know that I can set symbols like _kernel_start and _kernel_end to do that. But what I want to know is how to do that. How to set them, and how to read them. I've tried to find out, but cant find anything. Im using gcc.
/norton
Re:kernel symbols
i put them into my linker script and link that way.
and I link with
the -Tstage1.ld is the link script. this gives you etext, edata and eend
Code: Select all
ENTRY(start)
SECTIONS {
.text 0x100000 : {
code = .;
*(.text)
. = ALIGN(4096);
*(.rodata*)
. = ALIGN(4096);
_etext = .;
etext = _etext;
}
.data : {
*(.data)
. = ALIGN(4096);
_edata = .;
edata = _edata;
}
.bss : {
*(.bss)
*(COMMON)
. = ALIGN(4096);
_end = .;
eend = _end;
}
}
Code: Select all
ld -X -x -E -e start -Ttext 0x100000 -Tstage1.ld -Map map.txt $(OBJS) -o kernel.img
-- Stu --
Re:kernel symbols
if what you want to know is how to get the real end address of you kernel during runtime then all you have to do is declare the linker symbol as an
in the example given by df this would be the symbol "eend" thus you would use
and this gives you a pointer to the symbol so all you need is to dereference it and voila! you have the kernel size i.e you might use
hope that was what you wanted
Code: Select all
extern char
Code: Select all
extern char eend
Code: Select all
char *kend=&eend;
printf("kernel end = %x",kend);
Only Human
Re:kernel symbols
Assuming that eend is at the end of the bss section, AND assuming nothing follows it, AND assuming that eend shouldn't count.Neo wrote: if what you want to know is how to get the real end address of you kernel during runtime then all you have to do is declare the linker symbol as anin the example given by df this would be the symbol "eend" thus you would useCode: Select all
extern char
and this gives you a pointer to the symbol so all you need is to dereference it and voila! you have the kernel size i.e you might useCode: Select all
extern char eend
hope that was what you wantedCode: Select all
char *kend=&eend; printf("kernel end = %x",kend);
I would use a normal executable file format (such as ELF) which very plainly lists the size of each section, plus where it should be loaded. a+b=c, so that is the end address, nothing else.
[mod time="now"] Forgot, you also suppose that the kernel is linear, and has the bss section at the end (which I do not for example)[/mod]
Re:kernel symbols
well, considering its runtime, fileformat does not count since your ELF kernel is loaded into memory and built accoridng to its sections, its headers are not in memory, so unless your kernel plans to open its self ON DISK and parse its headers... what was your point again??Candy wrote:I would use a normal executable file format (such as ELF) which very plainly lists the size of each section, plus where it should be loaded. a+b=c, so that is the end address, nothing else.
-- Stu --
Re:kernel symbols
yeah that was assuming a lot but you could have the eend symbol after the last section as shown and assign the location counter to it.Assuming that eend is at the end of the bss section, AND assuming nothing follows it, AND assuming that eend shouldn't count.
Code: Select all
ENTRY(start)
SECTIONS {
.text 0x100000 : {
code = .;
*(.text)
. = ALIGN(4096);
*(.rodata*)
. = ALIGN(4096);
_etext = .;
etext = _etext;
}
.data : {
*(.data)
. = ALIGN(4096);
_edata = .;
edata = _edata;
}
.bss : {
*(.bss)
*(COMMON)
. = ALIGN(4096);
_end = .;
}
eend = .;
}
Only Human
Re:kernel symbols
who is doing that? If you are yourself, use that info for that purpose. Otherwise, load the headers from disk and use them.df wrote: fileformat does not count since your ELF kernel is loaded into memory and built accoridng to its sections, its headers are not in memory
Re:kernel symbols
read the OP. you know, the one at the very top. that says 'I want to calculate the size of the kernel at runtine'.Candy wrote:who is doing that? If you are yourself, use that info for that purpose. Otherwise, load the headers from disk and use them.
wouldnt it be easier to say
Code: Select all
intKernelSizze = _eend;
-- Stu --
Re:kernel symbols
yeah this seems such an easy way to get the size. btw df are there any problems that might arise with this method or is it reliable enough?
Only Human
Re:kernel symbols
Its reliable unless there's any "unusual" situation. Most of the assumptions Candy spoke of aren't really a big deal; you can ensure they are always true by the way you write your kernel linker script.Neo wrote: yeah this seems such an easy way to get the size. btw df are there any problems that might arise with this method or is it reliable enough?