TheLoneJoker
TheLoneJoker

Reputation: 1629

uboot: What is DECLARE_GLOBAL_DATA_PTR?

In some of the uboot files I have seen this declaration:

DECLARE_GLOBAL_DATA_PTR

right below the includes.... does anyone know what/why is this done ?

Thanks, vj

Upvotes: 2

Views: 3403

Answers (1)

Joe Kul
Joe Kul

Reputation: 2534

That is a macro declaration that a resource (for example, a CPU register) will be reserved for pointing to a struct global_data. For ARM, the macro is defined in arch/arm/include/asm/global_data.h, and it reserves CPU register r8.

See README l. 4602+ which describe resource constraints in early boot. The global data pointer gives easy access to the data elements which are most useful in this boot phase.

Global means that this data is generally available. C source files use this declaration before any compiled code, to tell the compiler to not use that register (e.g. ARM CPU r8) for anything else.

By the end of booting, for example in common/main.c main_loop(), I see that DECLARE_GLOBAL_DATA_PTR is used only in a few particular configurations. So, perhaps other code for actions driven by console commands (for example) would not need to reserve that resource. Of the C source files, looks like 25% use it, 75% do not use it.

~/u-boot-2012.10$ find . -name "*.c" | wc -l
2824
~/u-boot-2012.10$ find . -name "*.c" | xargs grep DECLARE_GLOBAL_DATA_PTR | wc -l
745

Upvotes: 5

Related Questions