When my kernel is loaded by grub, it begins reading the multiboot info. First, the memory limits, and then the memory map. My problem is that the reported address of the memory map is 0x100a4, which happens to be in the middle of my kernel code.
What I assume is happening is that grub is creating the table, then loading my kernel source right over it, but why is it doing this? Surely it knows how big my kernel is, and should know not to do this. What possible fixes are there? Can I tell grub to load the kernel elsewhere?
My kernel code is overwriting grub's memory map table.
-
- Member
- Posts: 64
- Joined: Fri Jan 26, 2018 11:43 am
Re: My kernel code is overwriting grub's memory map table.
Grub Legacy or Grub2?
Greetings
Peter
Greetings
Peter
-
- Member
- Posts: 5575
- Joined: Mon Mar 25, 2013 7:01 pm
Re: My kernel code is overwriting grub's memory map table.
GRUB is designed to load the operating system above 1MB. I wouldn't be surprised if it assumes you will never request a load address below 1MB and doesn't validate the request.j4cobgarby wrote:What I assume is happening is that grub is creating the table, then loading my kernel source right over it, but why is it doing this?
Tell GRUB to load your OS at 1MB or higher.j4cobgarby wrote:What possible fixes are there?
Yes.j4cobgarby wrote:Can I tell grub to load the kernel elsewhere?
Without seeing your code, I can't point you at exactly what you need to change, but it'll probably be one of the addresses in your linker script.
-
- Member
- Posts: 64
- Joined: Fri Jan 26, 2018 11:43 am
Re: My kernel code is overwriting grub's memory map table.
It seems that my kernel is being loaded at 1MB. Here's my linker script:Octocontrabass wrote:GRUB is designed to load the operating system above 1MB. I wouldn't be surprised if it assumes you will never request a load address below 1MB and doesn't validate the request.j4cobgarby wrote:What I assume is happening is that grub is creating the table, then loading my kernel source right over it, but why is it doing this?
Tell GRUB to load your OS at 1MB or higher.j4cobgarby wrote:What possible fixes are there?
Yes.j4cobgarby wrote:Can I tell grub to load the kernel elsewhere?
Without seeing your code, I can't point you at exactly what you need to change, but it'll probably be one of the addresses in your linker script.
Code: Select all
ENTRY(_start)
SECTIONS
{
/* start putting code at 1MB, apparently this is a
* normal place for kernel code to be loaded from*/
. = 0x100000;
/* multiboot header has to be early on in the image so
* that grub finds it */
.text BLOCK(4K) : ALIGN(4K)
{
*(.multiboot) /* first the multiboot header */
*(.text) /* now the actual entry code */
}
/* now the uninitialised data */
.bss BLOCK(4K) : ALIGN(4K)
{
*(.bss) /* just the stacks */
}
}
-
- Member
- Posts: 5575
- Joined: Mon Mar 25, 2013 7:01 pm
Re: My kernel code is overwriting grub's memory map table.
The linker script determines what values the linker will put in the ELF headers, and GRUB can read the ELF headers to determine where to load your kernel. The multiboot header can also contain a load address, though, and I can't recall off the top of my head which one takes priority when both are present.
According to your linker script, your kernel will be loaded at 0x100000. Is 0x100a4 really in the middle of your kernel code?
According to your linker script, your kernel will be loaded at 0x100000. Is 0x100a4 really in the middle of your kernel code?
-
- Member
- Posts: 64
- Joined: Fri Jan 26, 2018 11:43 am
Re: My kernel code is overwriting grub's memory map table.
You know, it's possible that I misread some address. In hindsight I'm not sure if it was in the middle of my code...Octocontrabass wrote:The linker script determines what values the linker will put in the ELF headers, and GRUB can read the ELF headers to determine where to load your kernel. The multiboot header can also contain a load address, though, and I can't recall off the top of my head which one takes priority when both are present.
According to your linker script, your kernel will be loaded at 0x100000. Is 0x100a4 really in the middle of your kernel code?
At least I've learnt that I can move my kernel around by using the linker script, I was never really that solid on how the linker script worked, so thanks!
Re: My kernel code is overwriting grub's memory map table.
You sure are the expert, but maybe the content of "multiboot" is the reason?Octocontrabass wrote:The linker script determines what values the linker will put in the ELF headers, and GRUB can read the ELF headers to determine where to load your kernel. The multiboot header can also contain a load address, though, and I can't recall off the top of my head which one takes priority when both are present.
According to your linker script, your kernel will be loaded at 0x100000. Is 0x100a4 really in the middle of your kernel code?
Greetings
Peter
-
- Member
- Posts: 64
- Joined: Fri Jan 26, 2018 11:43 am
Re: My kernel code is overwriting grub's memory map table.
I haven't specified a load address in the header, so that's probably not it here.PeterX wrote:You sure are the expert, but maybe the content of "multiboot" is the reason?Octocontrabass wrote:The linker script determines what values the linker will put in the ELF headers, and GRUB can read the ELF headers to determine where to load your kernel. The multiboot header can also contain a load address, though, and I can't recall off the top of my head which one takes priority when both are present.
According to your linker script, your kernel will be loaded at 0x100000. Is 0x100a4 really in the middle of your kernel code?
Greetings
Peter