Page 1 of 1

Global variable and 64 bits higher half kernel with GRUB2

Posted: Fri Mar 14, 2014 4:29 am
by tr16
(I apologize for my english since it is not my mother-tongue)

Hi everyone,

Following this tutorial (http://wiki.osdev.org/64-bit_Higher_Hal ... ith_GRUB_2) in order to write my own OS, I encounter a weird bug.
As soon as I add global (static or not) variables in my C code, the assembly bootstrap can't reach the C main() function. The system restarts.

I tried with only the code given by the tutorial, simply changing the c code from:

Code: Select all

int main()
{
	while (1);
}
to:

Code: Select all

int a;
int b[20];
int main()
{
	while (1);
}
NB: the a and b symbols appears to be in the .bss section. If the "static" keyword is added it is no more the case, but the kernel keeps crashing.

I think it is a kind of global symbols mismatch when GRUB2 loads the ELF64 file, but I still can't figure out what is wrong since I am not an expert in the ELF64 format.

Re: Global variable and 64 bits higher half kernel with GRUB

Posted: Fri Mar 14, 2014 5:16 am
by Combuster
I think you missed the most important part of the page:
the factual accuracy of this article is disputed
IOW, if you want to get something done, it's best if you tried something else first.