How do I find the starting address of free memory in GRUB?
How do I find the starting address of free memory in GRUB?
Hi, I am trying to find out how to find the address where free memory starts while booting with GRUB. And how would I find it using the information from the memory mapping buffer in the mbi specifications?
-
- Member
- Posts: 5563
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How do I find the starting address of free memory in GRU
The Multiboot specification includes example code showing how to find the base address and type of each memory region. (The example code attempts to print the addresses, but it has a bug: it will not print values above 4GB correctly.)
There will be more than one free memory region.
Your kernel is located inside one of the free memory regions. You will need to use the address of the start and end of your kernel to avoid the memory containing your kernel.
There will be more than one free memory region.
Your kernel is located inside one of the free memory regions. You will need to use the address of the start and end of your kernel to avoid the memory containing your kernel.
Re: How do I find the starting address of free memory in GRU
Thanks, I must have missed it.Octocontrabass wrote:The Multiboot specification includes example code showing how to find the base address and type of each memory region. (The example code attempts to print the addresses, but it has a bug: it will not print values above 4GB correctly.)
There will be more than one free memory region.
Your kernel is located inside one of the free memory regions. You will need to use the address of the start and end of your kernel to avoid the memory containing your kernel.
Re: How do I find the starting address of free memory in GRU
I'm having trouble finding where the Kernel is in memory and how I would avoid it. Which one of the address fields would I use?
-
- Member
- Posts: 426
- Joined: Tue Apr 03, 2018 2:44 am
Re: How do I find the starting address of free memory in GRU
You can put symbols in your linker script to find the limits of your kernel. The multiboot loader will load your kernel into memory according to the ELF header. SO when your kernel gets control, you know where your kernel is, and you can define symbols at the start and end of your loaded kernel, then just ignore the kernel memory ranges when making the usable memory referenced by the multiboot header available to your physical memory manager.Caffeine wrote:I'm having trouble finding where the Kernel is in memory and how I would avoid it. Which one of the address fields would I use?
Linker_Scripts
Re: How do I find the starting address of free memory in GRU
Where should I put the symbols and what blocks? .text, .rodata, .data, or .bss?thewrongchristian wrote:You can put symbols in your linker script to find the limits of your kernel. The multiboot loader will load your kernel into memory according to the ELF header. SO when your kernel gets control, you know where your kernel is, and you can define symbols at the start and end of your loaded kernel, then just ignore the kernel memory ranges when making the usable memory referenced by the multiboot header available to your physical memory manager.Caffeine wrote:I'm having trouble finding where the Kernel is in memory and how I would avoid it. Which one of the address fields would I use?
Linker_Scripts
-
- Member
- Posts: 426
- Joined: Tue Apr 03, 2018 2:44 am
Re: How do I find the starting address of free memory in GRU
By way of example, here is my linker script:Caffeine wrote:Where should I put the symbols and what blocks? .text, .rodata, .data, or .bss?thewrongchristian wrote:You can put symbols in your linker script to find the limits of your kernel. The multiboot loader will load your kernel into memory according to the ELF header. SO when your kernel gets control, you know where your kernel is, and you can define symbols at the start and end of your loaded kernel, then just ignore the kernel memory ranges when making the usable memory referenced by the multiboot header available to your physical memory manager.Caffeine wrote:I'm having trouble finding where the Kernel is in memory and how I would avoid it. Which one of the address fields would I use?
Linker_Scripts
linked.ld
Code: Select all
SECTIONS
{
/* Begin putting sections at 1 MiB, a conventional place for kernels to be
loaded at by the bootloader. */
. = 1M;
_bootstrap_start = .;
...
/* Bootstrap code in low memory */
...
/* Rest of the kernel lives in high memory */
_kernel_offset_bootstrap = .;
. += kernel_offset;
_kernel_offset = .;
/* Next we'll put the .text section. */
.text ALIGN(4K) : AT(ADDR(.text) - kernel_offset)
...
/* Kernel code in high memory */
...
_bootstrap_nextalloc = .;
. -= kernel_offset;
_bootstrap_end = .;
- _bootstrap_start - start of bootstrap code in low memory.
- _kernel_offset_bootstrap - end of bootstrap code in low memory.
- _kernel_offset - Start of kernel code in high memory.
- _bootstrap_nextalloc - End of .bss section, start of kernel heap data.
- _bootstrap_end - end of kernel in low memory
Code: Select all
extern char _bootstrap_start[];
extern char _bootstrap_end[];
Re: How do I find the starting address of free memory in GRU
Awesome! Thanks!