x86 systems run their romstage as execute-in-place from flash, which
prevents them from having writable data segments. In several code pieces
that get linked into both romstage and ramstage, this has been worked
around by using a local variable and having the 'static' storage class
guarded by #ifndef __PRE_RAM__.
However, x86 is the only architecture using execute-in-place (for now),
so it does not make sense to impose the restriction globally. Rather
than fixing the #ifdef at every occurrence, this should really be
wrapped in a way that makes it easier to modify in a single place. The
chromeos/cros_vpd.c file already had a nice approach for a wrapper
macro, but unfortunately restricted it to one file... this patch moves
it to stddef.h and employs it consistently throughout coreboot.
BRANCH=nyan
BUG=None
TEST=Measured boot time on Nyan_Big before and after, confirmed that it
gained 6ms from caching the FMAP in vboot_loader.c.
Original-Change-Id: Ia53b94ab9c6a303b979db7ff20b79e14bc51f9f8
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/203033
Original-Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Original-Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
(cherry picked from commit c8127e4ac9)
Signed-off-by: Marc Jones <marc.jones@se-eng.com>
Change-Id: I44dacc10214351992b775aca52d6b776a74ee922
Reviewed-on: http://review.coreboot.org/8055
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Tested-by: build bot (Jenkins)
59 lines
1.6 KiB
C
59 lines
1.6 KiB
C
#ifndef STDDEF_H
|
|
#define STDDEF_H
|
|
|
|
typedef long ptrdiff_t;
|
|
#ifndef __SIZE_TYPE__
|
|
#define __SIZE_TYPE__ unsigned long
|
|
#endif
|
|
typedef __SIZE_TYPE__ size_t;
|
|
/* There is a GCC macro for a size_t type, but not
|
|
* for a ssize_t type. Below construct tricks GCC
|
|
* into making __SIZE_TYPE__ signed.
|
|
*/
|
|
#define unsigned signed
|
|
typedef __SIZE_TYPE__ ssize_t;
|
|
#undef unsigned
|
|
|
|
typedef int wchar_t;
|
|
typedef unsigned int wint_t;
|
|
|
|
#define NULL ((void *)0)
|
|
|
|
/* Standard units. */
|
|
#define KiB (1<<10)
|
|
#define MiB (1<<20)
|
|
#define GiB (1<<30)
|
|
/* Could we ever run into this one? I hope we get this much memory! */
|
|
#define TiB (1<<40)
|
|
|
|
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
|
|
|
#define check_member(structure, member, offset) _Static_assert( \
|
|
offsetof(struct structure, member) == offset, \
|
|
"`struct " #structure "` offset for `" #member "` is not " #offset )
|
|
|
|
/**
|
|
* container_of - cast a member of a structure out to the containing structure
|
|
* @param ptr: the pointer to the member.
|
|
* @param type: the type of the container struct this is embedded in.
|
|
* @param member: the name of the member within the struct.
|
|
*
|
|
*/
|
|
#define container_of(ptr, type, member) ({ \
|
|
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
|
(type *)( (char *)__mptr - offsetof(type,member) );})
|
|
|
|
#ifdef __PRE_RAM__
|
|
#define ROMSTAGE_CONST const
|
|
#else
|
|
#define ROMSTAGE_CONST
|
|
#endif
|
|
|
|
/* Work around non-writable data segment in execute-in-place romstage on x86. */
|
|
#if defined(__PRE_RAM__) && CONFIG_ARCH_X86
|
|
#define MAYBE_STATIC
|
|
#else
|
|
#define MAYBE_STATIC static
|
|
#endif
|
|
|
|
#endif /* STDDEF_H */
|