Global variable and 64 bits higher half kernel with GRUB2

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
tr16
Posts: 1
Joined: Fri Mar 14, 2014 4:18 am

Global variable and 64 bits higher half kernel with GRUB2

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply