Kernel End
Kernel End
Hi
By using GRUB as my bootloader, is there any way for my kernel, during run time, to determine the physical address of where it 'ends' (the address which, if incremented by 1, would point to the beginning of free space which extends untill the end of physical memory).
Thanks
By using GRUB as my bootloader, is there any way for my kernel, during run time, to determine the physical address of where it 'ends' (the address which, if incremented by 1, would point to the beginning of free space which extends untill the end of physical memory).
Thanks
Here's an attempt to explain.
In the UNIX system, the linker (ld) placed a symbol end (_end in Assembly) whose value is defined as the first address above the end of the program:
The GNU linker lets you do something like this with the linker script:
Now you can do the same thing with your kernel.
Hope that helps!
In the UNIX system, the linker (ld) placed a symbol end (_end in Assembly) whose value is defined as the first address above the end of the program:
Code: Select all
extern int end;
main()
{
printf("highest address in progrram memory: %d\n", end - 1);
}
Code: Select all
SECTIONS
{
.text : { /* ... */ }
.data : { /* ... */ }
.bss : { /* ... */ }
end = .; _end = .; __end = .;
}
Hope that helps!
PGOS. It's my hand-written OS. Deal with it.
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Hi,
It's not
That gives you the value at the end of the kernel, not the address (which is what you want).
This is correct (and also hex is better for addresses):
Just thought I'd mention that small detail.
EDIT: This is basically what this line means:
It's not
Code: Select all
printf("highest address in progrram memory: %d\n", end - 1);
This is correct (and also hex is better for addresses):
Code: Select all
printf("highest address in progrram memory: %d\n", *((uint32_t*) &end) );
EDIT: This is basically what this line means:
If you use a linker script, just remember that you need to get the ADDRESS of the symbol, not the contents
Stupid V7 manuals!pcmattman wrote:Hi,
It's not
That gives you the value at the end of the kernel, not the address (which is what you want).Code: Select all
printf("highest address in progrram memory: %d\n", end - 1);
This is correct (and also hex is better for addresses):
Just thought I'd mention that small detail.Code: Select all
printf("highest address in progrram memory: %d\n", *((uint32_t*) &end) );
EDIT: This is basically what this line means:If you use a linker script, just remember that you need to get the ADDRESS of the symbol, not the contents
PGOS. It's my hand-written OS. Deal with it.
Guess what: you're wrong. Givenpcmattman wrote:It might be that you can access end and that the symbol holds the correct address in V7, but if you do it in your own linker script way don't expect the same.Stupid V7 manuals!
Code: Select all
end = .; _end = .; __end = .;
Code: Select all
extern int end;
p = &end
Code: Select all
p = end;
The V7 manuals win again!
(and maybe I should go to my normal, bloated man pages)
PGOS. It's my hand-written OS. Deal with it.
That's very strange, because it shouldn't. Methinks theres something else going on here.pietro10 wrote:Guess what: you're wrong. Givenpcmattman wrote:It might be that you can access end and that the symbol holds the correct address in V7, but if you do it in your own linker script way don't expect the same.Stupid V7 manuals!
in the linker script,Code: Select all
end = .; _end = .; __end = .;
doesn't work, butCode: Select all
extern int end; p = &end
does.Code: Select all
p = end;
The V7 manuals win again!
(and maybe I should go to my normal, bloated man pages)
- thepowersgang
- Member
- Posts: 734
- Joined: Tue Dec 25, 2007 6:03 am
- Libera.chat IRC: thePowersGang
- Location: Perth, Western Australia
- Contact:
Wrong, assuming you're using binutils. Symbols created by the linker are exactly like labels in asm.thepowersgang wrote:the _end symbol is not an address like a label in an assembler file, it is a value that is set to the end of kernel address by the linker and so therefore taking the address of it is pointless. What you want is the value.
From the ld manual http://sourceware.org/binutils/docs-2.1 ... rence.html
Linker scripts symbol declarations, by contrast, create an entry in the symbol table but do not assign any memory to them. Thus they are an address without a value. ... Hence when you are using a linker script defined symbol in source code you should always take the address of the symbol, and never attempt to use its value.