[coreboot] [PATCH] cld before call

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Wed Jul 29 13:08:55 CEST 2009

On 29.07.2009 12:51, Carl-Daniel Hailfinger wrote:
> On 29.07.2009 05:24, ron minnich wrote:
>> my understanding of all this is:
>> 1. if you want it set a certain way, you have to set it
>> 2. don't ever assume it has any particular value.
> There is an excellent LWN.net article about this:
> http://lwn.net/Articles/272048/
> "GCC relies on the ABI mandate that the direction flag is cleared before
> entry to a function"
> That means if you call the payload via a pointer, gcc will make sure the
> direction flag is cleared (either by clearing it directly before the
> call or by never changing it after the start of the program).
> AFAIK calling a function via inline asm is not something gcc can see, so
> this special case might be an exception. Then again, it's pretty
> unlikely that gcc sets the direction flag for some operations and defers
> clearing to the last possible moment.

Turns out gcc developers disagreed with each other about direction flag
guarantees for inline asm. The following is an attempt at summarizing
the discussion on the gcc mailing list linked from the lwn article.

Michael Matz said there are no guarantees for inline asm, but he also
said that std is not emitted lazily, so having cld inside inline asm
will not break any code afterwards, i.e. code after an inline asm does
never depend on the DF being set.
Chris Lattner said it's reasonable for inline asm to expect the DF to be
Richard Guenther said inline asm shouldn't make assumptions about DF.
Jan Hubicka said gcc does not emit std at the moment.

Anyone up for reposting that question to the gcc list?



More information about the coreboot mailing list