blob: d143f27eedd87739cc70358ed771b8873e7c16de [file] [log] [blame]
Heinrich Schuchardt467d90a2020-10-05 08:30:10 +02001.. SPDX-License-Identifier: GPL-2.0+
2
3Global data
4===========
5
6Globally required fields are held in the global data structure. A pointer to the
7structure is available as symbol gd. The symbol is made available by the macro
8%DECLARE_GLOBAL_DATA_PTR.
9
10Register pointing to global data
11--------------------------------
12
13On most architectures the global data pointer is stored in a register.
14
15+------------+----------+
16| ARC | r25 |
17+------------+----------+
18| ARM 32bit | r9 |
19+------------+----------+
20| ARM 64bit | x18 |
21+------------+----------+
22| M68000 | d7 |
23+------------+----------+
24| MicroBlaze | r31 |
25+------------+----------+
Heinrich Schuchardt467d90a2020-10-05 08:30:10 +020026| Nios II | gp |
27+------------+----------+
28| PowerPC | r2 |
29+------------+----------+
30| RISC-V | gp (x3) |
31+------------+----------+
32| SuperH | r13 |
33+------------+----------+
Heinrich Schuchardtb2107a42020-10-15 07:40:57 +020034| x86 32bit | fs |
35+------------+----------+
Heinrich Schuchardt467d90a2020-10-05 08:30:10 +020036
Heinrich Schuchardtb2107a42020-10-15 07:40:57 +020037The sandbox, x86_64, and Xtensa are notable exceptions.
Heinrich Schuchardt467d90a2020-10-05 08:30:10 +020038
Ovidiu Panait181cbd42022-09-13 21:31:26 +030039Current implementation uses a register for the GD pointer because this results
40in smaller code. However, using plain global data for the GD pointer would be
41possible too (and simpler, as it does not require the reservation of a specific
42register for it), but the resulting code is bigger.
43
Heinrich Schuchardt467d90a2020-10-05 08:30:10 +020044Clang for ARM does not support assigning a global register. When using Clang
45gd is defined as an inline function using assembly code. This adds a few bytes
46to the code size.
47
48Binaries called by U-Boot are not aware of the register usage and will not
49conserve gd. UEFI binaries call the API provided by U-Boot and may return to
50U-Boot. The value of gd has to be saved every time U-Boot is left and restored
51whenever U-Boot is reentered. This is also relevant for the implementation of
52function tracing. For setting the value of gd function set_gd() can be used.
53
54Global data structure
55---------------------
56
57.. kernel-doc:: include/asm-generic/global_data.h
58 :internal: