.
common/init/board\_init.c
1 void board_init_f_init_reserve(ulong base)
2 {
3 struct global_data *gd_ptr;
4 #ifndef _USE_MEMCPY
5 int *ptr;
6 #endif
7
8 /*
9 * clear GD entirely and set it up.
10 * Use gd_ptr, as gd may not be properly set yet.
11 */
12
13 gd_ptr = (struct global_data *)base;
14 /* zero the area */
15 #ifdef _USE_MEMCPY
16 memset(gd_ptr, '\0', sizeof(*gd));
17 #else
18 for (ptr = (int *)gd_ptr; ptr < (int *)(gd_ptr + 1); )
19 *ptr++ = 0;
20 #endif
21 /* set GD unless architecture did it already */
22 #if !defined(CONFIG_ARM)
23 arch_setup_gd(gd_ptr);
24 #endif
25 /* next alloc will be higher by one GD plus 16-byte alignment */
26 base += roundup(sizeof(struct global_data), 16);
27
28 /*
29 * record early malloc arena start.
30 * Use gd as it is now properly set for all architectures.
31 */
32
33 #if defined(CONFIG_SYS_MALLOC_F)
34 /* go down one 'early malloc arena' */
35 gd->malloc_base = base;
36 /* next alloc will be higher by one 'early malloc arena' size */
37 base += CONFIG_SYS_MALLOC_F_LEN;
38 #endif
39 }
- 1번 줄의 인자 base는 0x07FFDE60입니다.
- 4번 줄의
_USE_MEMCPY
가 정의되어 있어 5번 줄이 수행되지 않습니다. - 15번 줄에 의해
gd_ptr
주소를gd
사이즈만큼 0으로 초기화 합니다. - 22번 줄에서 라즈베리 파이는 ARM코어를 사용하기 때문에 23번줄은 수행되지 않습니다.
- 26번 줄의 roundup은 macro함수로
base += ( { const typeof(16) __y = 16; (((sizeof(struct global_data)) + (__y - 1)) / __y) * __y; } );
로 치환되어 수행됩니다.sizeof(struct global_data)
은 0xC8의 크기를 가지고 있습니다. 결국 base의 값은 0x07FFDF30이 됩니다. - 33번 줄의
CONFIG_SYS_MALLOC_F
은 정의되어 있어 if문이 수행됩니다. - 37번 줄의
CONFIG_SYS_MALLOC_F_LEN
은 0x2000로 정의되어 있습니다. return을 하지도 않은 base값을 마지막에 증가키기 때문에 37번 줄은 컴파일시 최적화 과정에서 사라지게 됩니다. 이런 코드가 아직 남아 있는 이유를 git log를 보면 다음과 같이 나와 있습니다.Initialization for each "chunk" (GD, early malloc arena...) ends with an incrementation line of the form 'base +=
'. The last of these incrementations seems useless, as base will not be used any more after this incrementation; but if/when a new "chunk" is appended, this increment will be essential as it will give base right value for this new chunk (which will have to end with its own incrementation statement). Besides, the compiler's optimizer will silently detect and remove the last base incrementation, therefore leaving that last (seemingly useless) incrementation causes no code increase.