[U-Boot] lib_arm global data pointer
Drasko DRASKOVIC
drasko.draskovic at gmail.com
Fri Jul 10 14:52:32 CEST 2009
Hi all,
in libarm/board.c, in function start_armboot(void) I found lines like these:
/* Pointer is writable since we allocated a register for it */
gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
/* compiler optimization barrier needed for GCC >= 3.4 */
__asm__ __volatile__("": : :"memory");
gd is defined as: register volatile gd_t *gd asm ("r8")
I have 3 questions:
1) Why is it necessary to allocate register? Don't we have stack at this
point (we already allocated stack in start.S).
2) One C question - are we sure that compiler will listen to our which and
really allocate register?
3) Why do we need this membar? To prevent compiler from touching our reg r8
or for some other reason?
Suppose that I allocated one register in start.S and put in it some data I
want to have later on C side. From start.S we enter to start_armboot(void)
function.
Would this work :
void start_armboot (void)
{
init_fnc_t **init_fnc_ptr;
char *s;
#ifndef CFG_NO_FLASH
ulong size;
#endif
#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
unsigned long addr;
#endif
*#ifdef DATA_FROM_ASM_IN_R10
register volatile unsigned long tmp asm ("r10");
#endif*
/* Pointer is writable since we allocated a register for it */
gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
/* compiler optimization barrier needed for GCC >= 3.4 */
__asm__ __volatile__("": : :"memory");
memset ((void*)gd, 0, sizeof (gd_t));
gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
memset (gd->bd, 0, sizeof (bd_t));
*#ifdef DATA_FROM_ASM_IN_R10
/* data will be passed to C from assembly start-up in reg r10 */
gd->bd->bi_my_data = tmp;
#endif*
monitor_flash_len = _bss_start - _armboot_start;
for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
if ((*init_fnc_ptr)() != 0) {
hang ();
}
}
...
}
Would I from this point on really have on C stack what I had in r10 in
start.S?
If not, does anybody have idea how I can do it?
Thanks and best regards,
Drasko DRASKOVIC
More information about the U-Boot
mailing list