6 Replies Latest reply: Jul 13, 2011 9:20 AM by 874627 RSS

    Sparc assembly programming resources?

      Hi. I would like to find some up to date Sparc assembly programming resources. So far, I have the Sparc v9 Architecture manual, System V ABI Sparc supplement, SCD 2.4.1 from www.sparc.org. I also found the Solaris 10 Assembly Language Reference for Sparc.The problem is these are all references. I would like to find some educational material with more background information and an organized presentation of all the aspects, how things should be done and how everything connects. Are there official coding standards and best practices documented anywhere? Not just "hello world" because it's not useful. I looked and could not find much help on this topic. There are books like this for other platforms and OS but I haven't found anything useful for Solaris Sparc. There is an older book available that was written for Sparc v8 but it uses gnu M4 heavily and obscures things that probably should have been explained directly.

      How do the Solaris and OpenSolaris developers learn to write assembly code for Sparc? What learning resources do they have available? Thanks.
        • 1. Re: Sparc assembly programming resources?
          Darryl Gove-Oracle
          The other resources are the unified sparc architecuture docs from http://opensparc.net/ .

          The book that uses m4 is probably the only resource that attempts to teach sparc assembly language from scratch. However, I'd advocate more of a hybrid approach and use inline templates (or asm statements) to embed assembly into a C program. That way you can let the compiler handle the mundane stuff allowing you to focus on the bit of code that you're working on.

          See http://www.oracle.com/technetwork/articles/servers-storage-dev/inlining-344163.html

          The quick guide to SPARC assembly is:

          - The final register is the destination, so add %o1,1,%o2 is equivalent to %o2 = %o1 + 1
          - Control Transfer Instructions (branches, calls, etc) have a delay slot - meaning an instruction after the CTI that gets executed with the CTI.
          - Loads and stores need to be correctly aligned (see -xmemalign=)
          - Some of the registers are are reserved for OS use (discussed in Solaris Application Programming)
          - The architecture uses register windows (see save and restore instructions)
          - The lower set of double precision floating point registers maps onto all the single precision registers (two single precision registers per double precision)


          • 2. Re: Sparc assembly programming resources?
            Hi and thanks for your reply. I'm not a C coder so as good as a suggestion as that would be for many people, it won't help me because I'm interested in writing pure assembly for Sparc.

            Thanks for your notes, I've gathered that from the info I've been able to find to this point. I'll check the links you posted.

            Are there any pieces of code you can point me to that you would consider canonical examples of how to write Sparc assembly the "right way"? Again, all the reference materials are obviously essential, but there is a lot that isn't being said.
            • 3. Re: Sparc assembly programming resources?
              Darryl Gove-Oracle
              Well, the compiler generates pretty good assembly - use -S to generate the output. I would suggest starting with reading assembly, then go to writing it. I do a fair amount of assembly coding, but I find I can be most productive by writing in C, then refining the code until it produces the assembly that I want. Writing directly in assembly is very hard going - good luck! :)


              • 4. Re: Sparc assembly programming resources?
                Hi. I took a quick look at your blog and the site you linked earlier, very impressive! My background is systems software design and development for z/OS using pure assembler and I never learned C so I'm just more comfortable in assembler. A major difference is we have one stop shopping, since IBM designed the hardware and software to work together and the documentation reflects this. I find things disjointed in trying to work on Sparc with Solaris or other OS simply because a lot seems to have dropped through the cracks and none of the parties has much of an incentive to tie things together for outsiders. I've spent all my career on one machine and OS and I'm trying to learn other architectures and systems just to broaden my own horizons.

                I don't dispute your compiler produces excellent code, I've heard elsewhere the optimizations of Solaris Studio for Sparc produce much better code than the competitor! Still, compiler output is not often very readable nor is the code what a human would code to solve the same problem! I'll take a look at it, but as good as I am sure it is, I don't imagine I'll be able to learn things like good style and best practices except in very specific areas like linkage and I would guess some important things that the code will do will not be obvious or documented and so I'm not going to get the benefit of it. Since there aren't any books by experts on the topic it would help to see actual known good human-written code and have a mentor, but I don't know where to find those. I understand Solaris is not open any more, so I'll ask on OpenSolaris to see what they have.

                I suppose you must have information on the topic or guys with deep knowledge (including yourself) that know how things should be done and how to avoid problems, but perhaps it is proprietary. Anyway if you can help further, feel free to email me. Thanks for your suggestions.
                • 5. Re: Sparc assembly programming resources?
                  Darryl Gove-Oracle
                  You should be able to pick up SPARC assembly very easily given your background. There's not too much that's complex. Feel free to contact me if you have questions (firstdotlastatoracledotcom)


                  • 6. Re: Sparc assembly programming resources?
                    Thanks very much. I'm marking this answered.

                    If any other sources come to mind, please update the thread.