[U-Boot] [PATCH] Save/restore global data pointer on API boundary

Wolfgang Denk wd at denx.de
Tue Aug 7 20:30:21 CEST 2012


Dear Leif Lindholm,

In message <50214A38.3000305 at arm.com> you wrote:
> Most architectures keep the global data pointer (gd) in a register.

This may, or may not be.  You should not make any assumptions on how
gd is implemented.

> When using the external app API, because they are calling us rather
> than we calling them, this register can be corrupted.

How can this be?  The caller should always use the same register
convention as we do - otherwise we are in a much deeper trouble.
It is up to the caller to make sure it uses the published API (resp.
ABI).

> The attached (trivial) patch saves the gd pointer at api_init(),
> and restores it on every entry to syscall(). This may want to be
> put behind an ifdef for those architectures that don't use a
> dedicated register.

This is wrong.  You make assumptions here why may be correct, but may
be wrong as well.  If we were to implement this, you would have to
make sure it always works, no matter how gd is implemented on a
specific board / platform.   But I doubt this is the right approach.
This should be done by the caller.


BTW:  Please also note that there are a few coding style errors.
Checkpatch says:

WARNING: Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt
WARNING: please, no spaces at the start of a line (2 x)


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
If the odds are a million to one against something occuring,  chances
are 50-50 it will.


More information about the U-Boot mailing list