x86: Place global data below stack before entering C
By reserving space for the Global Data immediately below the stack during assembly level initialisation, the C declaration of the static global data can be removed, along with the 'RAM Bootstrap' function. This results in cleaner code, and the ability to pass boot-up flags from assembler into C
This commit is contained in:
parent
5a3876d2ac
commit
161b3589ea
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <version.h>
|
#include <version.h>
|
||||||
|
#include <asm/global_data.h>
|
||||||
|
|
||||||
|
|
||||||
.section .text
|
.section .text
|
||||||
@ -127,6 +128,13 @@ mem_ok:
|
|||||||
/* Set the upper memory limit parameter */
|
/* Set the upper memory limit parameter */
|
||||||
subl $CONFIG_SYS_STACK_SIZE, %eax
|
subl $CONFIG_SYS_STACK_SIZE, %eax
|
||||||
|
|
||||||
|
/* Reserve space for global data */
|
||||||
|
subl $(GD_SIZE * 4), %eax
|
||||||
|
|
||||||
|
/* %eax points to the global data structure */
|
||||||
|
movl %esp, (GD_RAM_SIZE * 4)(%eax)
|
||||||
|
movl %ebx, (GD_FLAGS * 4)(%eax)
|
||||||
|
|
||||||
call board_init_f /* Enter, U-boot! */
|
call board_init_f /* Enter, U-boot! */
|
||||||
|
|
||||||
/* indicate (lack of) progress */
|
/* indicate (lack of) progress */
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
* Keep it *SMALL* and remember to set CONFIG_SYS_GBL_DATA_SIZE > sizeof(gd_t)
|
* Keep it *SMALL* and remember to set CONFIG_SYS_GBL_DATA_SIZE > sizeof(gd_t)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bd_t *bd;
|
bd_t *bd;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
@ -49,6 +51,26 @@ typedef struct {
|
|||||||
char env_buf[32]; /* buffer for getenv() before reloc. */
|
char env_buf[32]; /* buffer for getenv() before reloc. */
|
||||||
} gd_t;
|
} gd_t;
|
||||||
|
|
||||||
|
extern gd_t *gd;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Word Offsets into Global Data - MUST match struct gd_t */
|
||||||
|
#define GD_BD 0
|
||||||
|
#define GD_FLAGS 1
|
||||||
|
#define GD_BAUDRATE 2
|
||||||
|
#define GD_HAVE_CONSOLE 3
|
||||||
|
#define GD_RELOC_OFF 4
|
||||||
|
#define GD_ENV_ADDR 5
|
||||||
|
#define GD_ENV_VALID 6
|
||||||
|
#define GD_CPU_CLK 7
|
||||||
|
#define GD_BUS_CLK 8
|
||||||
|
#define GD_RAM_SIZE 9
|
||||||
|
#define GD_RESET_STATUS 10
|
||||||
|
#define GD_JT 11
|
||||||
|
|
||||||
|
#define GD_SIZE 12
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Global Data Flags
|
* Global Data Flags
|
||||||
*/
|
*/
|
||||||
@ -61,8 +83,6 @@ typedef struct {
|
|||||||
#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */
|
#define GD_FLG_DISABLE_CONSOLE 0x00040 /* Disable console (in & out) */
|
||||||
#define GD_FLG_ENV_READY 0x00080 /* Environment imported into hash table */
|
#define GD_FLG_ENV_READY 0x00080 /* Environment imported into hash table */
|
||||||
|
|
||||||
extern gd_t *gd;
|
|
||||||
|
|
||||||
#define DECLARE_GLOBAL_DATA_PTR
|
#define DECLARE_GLOBAL_DATA_PTR
|
||||||
|
|
||||||
#endif /* __ASM_GBL_DATA_H */
|
#endif /* __ASM_GBL_DATA_H */
|
||||||
|
@ -54,8 +54,6 @@ extern ulong _i386boot_rel_dyn_end;
|
|||||||
extern ulong _i386boot_bss_start;
|
extern ulong _i386boot_bss_start;
|
||||||
extern ulong _i386boot_bss_size;
|
extern ulong _i386boot_bss_size;
|
||||||
|
|
||||||
void ram_bootstrap (void *, ulong);
|
|
||||||
|
|
||||||
const char version_string[] =
|
const char version_string[] =
|
||||||
U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")";
|
U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")";
|
||||||
|
|
||||||
@ -164,13 +162,12 @@ init_fnc_t *init_sequence[] = {
|
|||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static gd_t gd_data;
|
|
||||||
gd_t *gd;
|
gd_t *gd;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load U-Boot into RAM, initialize BSS, perform relocation adjustments
|
* Load U-Boot into RAM, initialize BSS, perform relocation adjustments
|
||||||
*/
|
*/
|
||||||
void board_init_f (ulong stack_limit)
|
void board_init_f (ulong gdp)
|
||||||
{
|
{
|
||||||
void *text_start = &_i386boot_text_start;
|
void *text_start = &_i386boot_text_start;
|
||||||
void *u_boot_cmd_end = &__u_boot_cmd_end;
|
void *u_boot_cmd_end = &__u_boot_cmd_end;
|
||||||
@ -184,12 +181,9 @@ void board_init_f (ulong stack_limit)
|
|||||||
ulong rel_offset;
|
ulong rel_offset;
|
||||||
Elf32_Rel *re;
|
Elf32_Rel *re;
|
||||||
|
|
||||||
void (*start_func)(void *, ulong);
|
|
||||||
|
|
||||||
uboot_size = (ulong)u_boot_cmd_end - (ulong)text_start;
|
uboot_size = (ulong)u_boot_cmd_end - (ulong)text_start;
|
||||||
dest_addr = (void *)stack_limit - (uboot_size + (ulong)bss_size);
|
dest_addr = (void *)gdp - (uboot_size + (ulong)bss_size);
|
||||||
rel_offset = text_start - dest_addr;
|
rel_offset = text_start - dest_addr;
|
||||||
start_func = ram_bootstrap - rel_offset;
|
|
||||||
|
|
||||||
/* First stage CPU initialization */
|
/* First stage CPU initialization */
|
||||||
if (cpu_init_f() != 0)
|
if (cpu_init_f() != 0)
|
||||||
@ -213,38 +207,16 @@ void board_init_f (ulong stack_limit)
|
|||||||
*(ulong *)(re->r_offset - rel_offset) -= (Elf32_Addr)rel_offset;
|
*(ulong *)(re->r_offset - rel_offset) -= (Elf32_Addr)rel_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
((gd_t *)gdp)->reloc_off = rel_offset;
|
||||||
|
((gd_t *)gdp)->flags |= GD_FLG_RELOC;
|
||||||
|
|
||||||
/* Enter the relocated U-Boot! */
|
/* Enter the relocated U-Boot! */
|
||||||
start_func(dest_addr, rel_offset);
|
(board_init_r - rel_offset)((gd_t *)gdp, (ulong)dest_addr);
|
||||||
|
|
||||||
/* NOTREACHED - board_init_f() does not return */
|
/* NOTREACHED - board_init_f() does not return */
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* We cannot initialize gd_data in board_init_f() because we would be
|
|
||||||
* attempting to write to flash (I have even tried using manual relocation
|
|
||||||
* adjustments on pointers but it just won't work) and board_init_r() does
|
|
||||||
* not have enough arguments to allow us to pass the relocation offset
|
|
||||||
* straight up. This bootstrap function (which runs in RAM) is used to
|
|
||||||
* setup gd_data in order to pass the relocation offset to the rest of
|
|
||||||
* U-Boot.
|
|
||||||
*
|
|
||||||
* TODO: The compiler optimization barrier is intended to stop GCC from
|
|
||||||
* optimizing this function into board_init_f(). It seems to work without
|
|
||||||
* it, but I've left it in to be sure. I think also that the barrier in
|
|
||||||
* board_init_r() is no longer needed, but left it in 'just in case'
|
|
||||||
*/
|
|
||||||
void ram_bootstrap (void *dest_addr, ulong rel_offset)
|
|
||||||
{
|
|
||||||
/* compiler optimization barrier needed for GCC >= 3.4 */
|
|
||||||
__asm__ __volatile__("": : :"memory");
|
|
||||||
|
|
||||||
/* tell others: relocation done */
|
|
||||||
gd_data.reloc_off = rel_offset;
|
|
||||||
gd_data.flags |= GD_FLG_RELOC;
|
|
||||||
|
|
||||||
board_init_r(&gd_data, (ulong)dest_addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void board_init_r(gd_t *id, ulong dest_addr)
|
void board_init_r(gd_t *id, ulong dest_addr)
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
|
Loading…
Reference in New Issue
Block a user