Commit 0df01fd3d71481b5cc7aeea6a741b9fc3be15178
Committed by
Scott McNutt
1 parent
661ba14051
Exists in
master
and in
54 other branches
nios2: fix r15 issue for gcc4
The "-ffixed-r15" option doesn't work well for gcc4. Since we don't use gp for small data with option "-G0", we can use gp as global data pointer. This allows compiler to use r15. It is necessary for gcc4 to work properly. Signed-off-by: Thomas Chou <thomas@wytron.com.tw> Signed-off-by: Scott McNutt <smcnutt@psyent.com>
Showing 6 changed files with 20 additions and 18 deletions Side-by-side Diff
README
... | ... | @@ -4023,6 +4023,14 @@ |
4023 | 4023 | |
4024 | 4024 | ==> U-Boot will use R8 to hold a pointer to the global data |
4025 | 4025 | |
4026 | +On Nios II, the ABI is documented here: | |
4027 | + http://www.altera.com/literature/hb/nios2/n2cpu_nii51016.pdf | |
4028 | + | |
4029 | + ==> U-Boot will use gp to hold a pointer to the global data | |
4030 | + | |
4031 | + Note: on Nios II, we give "-G0" option to gcc and don't use gp | |
4032 | + to access small data sections, so gp is free. | |
4033 | + | |
4026 | 4034 | NOTE: DECLARE_GLOBAL_DATA_PTR must be used with file-global scope, |
4027 | 4035 | or current versions of GCC may "optimize" the code too much. |
4028 | 4036 |
arch/nios2/config.mk
arch/nios2/cpu/start.S
... | ... | @@ -113,13 +113,6 @@ |
113 | 113 | bne r5, r6, 4b |
114 | 114 | 5: |
115 | 115 | |
116 | - /* GLOBAL POINTER -- the global pointer is used to reference | |
117 | - * "small data" (see -G switch). The linker script must | |
118 | - * provide the gp address. | |
119 | - */ | |
120 | - movhi gp, %hi(_gp) | |
121 | - ori gp, gp, %lo(_gp) | |
122 | - | |
123 | 116 | /* JUMP TO RELOC ADDR */ |
124 | 117 | movhi r4, %hi(_reloc) |
125 | 118 | ori r4, r4, %lo(_reloc) |
arch/nios2/include/asm/global_data.h
... | ... | @@ -48,7 +48,7 @@ |
48 | 48 | #define GD_FLG_LOGINIT 0x00020 /* Log Buffer has been initialized */ |
49 | 49 | #define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */ |
50 | 50 | |
51 | -#define DECLARE_GLOBAL_DATA_PTR register gd_t *gd asm ("r15") | |
51 | +#define DECLARE_GLOBAL_DATA_PTR register gd_t *gd asm ("gp") | |
52 | 52 | |
53 | 53 | #endif /* __ASM_NIOS2_GLOBALDATA_H_ */ |
doc/README.standalone
... | ... | @@ -19,12 +19,12 @@ |
19 | 19 | thus the compiler cannot perform type checks on these assignments. |
20 | 20 | |
21 | 21 | 2. The pointer to the jump table is passed to the application in a |
22 | - machine-dependent way. PowerPC, ARM, MIPS and Blackfin architectures | |
23 | - use a dedicated register to hold the pointer to the 'global_data' | |
24 | - structure: r2 on PowerPC, r8 on ARM, k0 on MIPS, and P3 on Blackfin. | |
25 | - The x86 architecture does not use such a register; instead, the | |
26 | - pointer to the 'global_data' structure is passed as 'argv[-1]' | |
27 | - pointer. | |
22 | + machine-dependent way. PowerPC, ARM, MIPS, Blackfin and Nios II | |
23 | + architectures use a dedicated register to hold the pointer to the | |
24 | + 'global_data' structure: r2 on PowerPC, r8 on ARM, k0 on MIPS, | |
25 | + P3 on Blackfin and gp on Nios II. The x86 architecture does not | |
26 | + use such a register; instead, the pointer to the 'global_data' | |
27 | + structure is passed as 'argv[-1]' pointer. | |
28 | 28 | |
29 | 29 | The application can access the 'global_data' structure in the same |
30 | 30 | way as U-Boot does: |
... | ... | @@ -56,6 +56,7 @@ |
56 | 56 | ARM 0x0c100000 0x0c100000 |
57 | 57 | MIPS 0x80200000 0x80200000 |
58 | 58 | Blackfin 0x00001000 0x00001000 |
59 | + Nios II 0x02000000 0x02000000 | |
59 | 60 | |
60 | 61 | For example, the "hello world" application may be loaded and |
61 | 62 | executed on a PowerPC board with the following commands: |
examples/standalone/stubs.c
... | ... | @@ -84,7 +84,7 @@ |
84 | 84 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x) : "r0"); |
85 | 85 | #elif defined(CONFIG_NIOS2) |
86 | 86 | /* |
87 | - * r15 holds the pointer to the global_data, r8 is call-clobbered | |
87 | + * gp holds the pointer to the global_data, r8 is call-clobbered | |
88 | 88 | */ |
89 | 89 | #define EXPORT_FUNC(x) \ |
90 | 90 | asm volatile ( \ |
91 | 91 | |
... | ... | @@ -92,11 +92,11 @@ |
92 | 92 | #x ":\n" \ |
93 | 93 | " movhi r8, %%hi(%0)\n" \ |
94 | 94 | " ori r8, r0, %%lo(%0)\n" \ |
95 | -" add r8, r8, r15\n" \ | |
95 | +" add r8, r8, gp\n" \ | |
96 | 96 | " ldw r8, 0(r8)\n" \ |
97 | 97 | " ldw r8, %1(r8)\n" \ |
98 | 98 | " jmp r8\n" \ |
99 | - : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r15"); | |
99 | + : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "gp"); | |
100 | 100 | #elif defined(CONFIG_M68K) |
101 | 101 | /* |
102 | 102 | * d7 holds the pointer to the global_data, a0 is a call-clobbered |