<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Hello Renato,<br>
      <br>
      On 08/11/2013 10:58 PM, Renato Golin wrote:<br>
    </div>
    <blockquote
cite="mid:CAMSE1ke9LVpC+aUhC74WQY6YshZKWSS4dHg-J0fM1r4Gyi3-JQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">On 10 August 2013 12:37, Jeroen Hofstee <span
          dir="ltr"><<a moz-do-not-send="true"
            href="mailto:llvm@myspectrum.nl" target="_blank">llvm@myspectrum.nl</a>></span>
        wrote:<br>
        <div class="gmail_extra">
          <div class="gmail_quote">
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">+
              The first issue is U-boot's use of global registers. As
              this is not supported by<br>
              clang / llvm, it looks like a show stopper.</blockquote>
            <div><br>
            </div>
            <div>Not sure what you mean by that. Is it just the use of
              the "register" modifier on variables, I'm not sure how the
              R9 reservation will help here... Otherwise, if U-boot uses
              R9 the same way the AAPCS states (static base or thread
              register), than turning it on ARM-wide seems the right
              fix.</div>
            <div><br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    U-boot uses 'register volatile gd_t *gd asm ("r8")' to access data
    which needs<br>
    to be available before and after relocation. This is a global
    definition and gcc<br>
    is compiled with -ffixed-r8 in order to prevent using r8.<br>
    <br>
    From the looks of [2] "clang does not support global register
    variables; this is<br>
    unlikely to be implemented soon because it requires additional LLVM
    backend<br>
    support.", you might be led to believe U-boot cannot be compiled
    with llvm/clang,<br>
    <br>
    However changing it to:<br>
    <br>
    static __inline __maybe_unused volatile gd_t *get_gd(void)<br>
    {<br>
        gd_t *gd_ptr;<br>
    <br>
        __asm__ volatile("mov %0, r9\n" : "=r" (gd_ptr));<br>
    <br>
        return gd_ptr;<br>
    } <br>
    <br>
    #define gd  get_gd() <br>
    <br>
    works fine (albeit slightly less efficient), when clang / llvm does
    not change r9.<br>
    That is the reason I need the ReserveR9 also outside of IOS.<br>
    <br>
    <blockquote
cite="mid:CAMSE1ke9LVpC+aUhC74WQY6YshZKWSS4dHg-J0fM1r4Gyi3-JQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div>If I got it right, you want to disable movt/movh for
              your specific case, so leaving it ARM-wide makes sense.</div>
            <div><br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    yes, It hardcodes addresses in code, which is not intended behaviour
    for U-boot.<br>
    <blockquote
cite="mid:CAMSE1ke9LVpC+aUhC74WQY6YshZKWSS4dHg-J0fM1r4Gyi3-JQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div> </div>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">IOS
              does this conditionally IsR9Reserved = ReserveR9 |
              !HasV6Ops; but I<br>
              don't understand why, therefore I just left it untouched.<br>
            </blockquote>
            <div><br>
            </div>
            <div>I could be wrong but the AAPCS document hints that R9
              usage is v6+, so I'm guessing HasV6Ops is important for
              all platforms, not just Darwin. But I don't have the old
              APCS document to show me that R9 can be used as GPR in
              pre-v6.<br>
            </div>
            <div><br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    I am not sure what you are referring to. In general v6 in 5.1.1
    refers to the use of r9 as a<br>
    general-purpose register. As in variable 6, not version 6. Changing
    r9 in llvm will definitely<br>
    crash u-boot and likely every other application with explicitly
    asked llvm _not_ to touch r9<br>
    by setting ReserveR9.<br>
    <br>
    <blockquote
cite="mid:CAMSE1ke9LVpC+aUhC74WQY6YshZKWSS4dHg-J0fM1r4Gyi3-JQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div>I think both flags can be set together, and leave the
              isTargetIOS() just for the SupportsTailCall, like:<br>
            </div>
            <div><br>
            </div>
            <div>  UseMovt = hasV6T2Ops() && ArmUseMOVT;<br>
            </div>
            <div>
                IsR9Reserved = ReserveR9 | !HasV6Ops;</div>
            <div>  if (isTargetIOS())</div>
            <div>    SupportsTailCall =
              !getTargetTriple().isOSVersionLT(5, 0);</div>
            <div><br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    See above, and the initial commit. I want r9 to always be left
    alone. IOS doesn't<br>
    for some reasons I do not know, but it is not for AAPCS. (and if I
    have to guess,<br>
    it is related to their r9 usage depending on the target). <br>
    <br>
    <blockquote
cite="mid:CAMSE1ke9LVpC+aUhC74WQY6YshZKWSS4dHg-J0fM1r4Gyi3-JQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div><br>
            </div>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">patch
              attached (hopefully unified, it at least applies with
              patch -u -p0).<br>
            </blockquote>
            <div><br>
            </div>
            <div>Have you ran all tests? Test-suite? I suppose you'd
              have to test on both Linux and Darwin systems, but if you
              don't have access to them, I'll be happy to test on Linux,
              and other folks could test on Darwin.</div>
            <div><br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    No, not manually at least, just build it on Linux and verified
    u-boot works.<br>
    I grepped for the usage of these flags inside llvm / clang, but
    there is<br>
    nothing interesting there. I do not have a darwin / ios build env.<br>
    <br>
    Regards,<br>
    Jeroen<br>
    <br>
    [1]
<a class="moz-txt-link-freetext" href="http://git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/include/asm/global_data.h;h=79a959741945968eca7a21018187b97eb65d70f3;hb=refs/heads/master">http://git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/include/asm/global_data.h;h=79a959741945968eca7a21018187b97eb65d70f3;hb=refs/heads/master</a><br>
    [2]
<a class="moz-txt-link-freetext" href="http://clang.llvm.org/docs/UsersManual.html#gcc-extensions-not-implemented-yet">http://clang.llvm.org/docs/UsersManual.html#gcc-extensions-not-implemented-yet</a><br>
    <br>
  </body>
</html>