Unlike some other instruction sets, the SPARC Version 8 instruction set never embeds memory addresses into the instructions. Thus, no instructions can directly modify the contents of memory. Instead, all data manipulation is performed in the SPARC general purpose registers. Two basic memory access operations can be performed on SPARC systems. These are "load" and "store" or, in other words, "read from memory" and "write to memory." There are several variations of these two operations which handle different data sizes. Using load instructions, data is read in from memory and stored into a register. Once in a register, the data can be manipulated as needed. Using store instructions, the modified data is written back to memory. Load instructionsThe load instruction is used to read a value stored in memory, placing the data into a register when it can then be manipulated. Here are six commonly used load instructions: Table B-1. SPARC load instructions
Now let's look at a couple of examples. The instruction below reads the word of data stored at the memory address indicated by input register %i0 and loads it into output register %o1 . ld [%i0], %o1 The next example reads an unsigned byte of data from memory, loading it into output register %o3 . The memory address where the byte is read is the contents of input register %i4 plus hexadecimal 8. In a case like this, the value in %i4 may often be the pointer to a structure. The offset of 8 points to the most significant byte of the third word in the structure, the 9th byte. ldub [%i4 + 0x8], %o3 The example below reads a double word (two words) from memory and loads the data into two registers starting with register %l4 . So, if %i3 contains address 0xfea603b0, this load instruction will read memory location 0xfea603b0 and 0xfea603b4, loading the data into registers %l4 and %l5 , respectively. ldd [%i3], %l4 Loading from alternate address spaceEach of the six load instructions shown above also has a variation that says to load the information from an alternate address space, such as the control registers for the Memory Management Unit. Each SPARC implementation may offer different alternate addressable registers that can be accessed via the load alternate address space instructions. During system crash dump analysis, odds are very good you will not run into these instructions, since they are not generated by the compiler, but we'll show them just in case you do encounter them. Here they are. Table B-2. Load instructions from alternate address space
Loading from the floating-point unit & coprocessorThe next six load instructions are specifically for the optional floating-point unit and the optional coprocessor. While in assembly language they appear to be instructions we've seen earlier, the actual opcodes differ . Table B-3. Load instructions for optional FPU
Store instructionsIf you feel comfortable with the various load instructions, the store instructions will be a piece of cake. After data in a register has been manipulated, we use the store instruction to write the data to a specified memory location. There are four basic store operations and four alternate address space variations of them. They are as follows : Table B-4. SPARC store instructions
Let's take a look at a couple of examples of store instructions. The one below stores the contents of input register %i3 into the memory location whose address is in local register %l6 . st %i3, [%l6] The next example stores the least significant byte in register %i0 into the 2nd byte of the word whose address is contained in register %l5 . stb %i0, [%l5 + 1] Storing from the floating-point unit & coprocessorOf course, we also have additional store instructions that are used in conjunction with the optional floating-point processor and optional coprocessor. As with the load instructions, these instructions differ a bit between assembly language and the actual SPARC opcode. Table B-5. SPARC additional store instructions
Atomic memory access instructionsTwo instructions in the SPARC instruction set and two alternate address space variations of them can perform a read from memory and a write to memory atomically. What do we mean by atomically? The instruction cannot be interrupted during its execution; the read and the write happen in the same breath . In a multiprocessor system, two or more processors executing the instructions addressing the same byte simultaneously are guaranteed to execute them in an undefined, but serial order. Here are the instructions: Table B-6. SPARC atomic energy access instructions
The ldstub instructions read an unsigned byte from memory into a register, then write all ones (hexadecimal 0xff) to that byte of memory. The swap instructions interchange the contents of a memory location with the contents of a register. In general terms, both of these instructions, since they involve a lot of work, usually take longer to execute than others. However, when integrity of the data being manipulated is critical and timing is everything, these atomic instructions are invaluable. For example, it is the ldstub instruction that provides SPARC systems the ability to have safe, predictable locking mechanisms. Note Instruction execution times differ with each SPARC implementation. Refer to the specific processor's technical manual for timing data. Possible traps during memory access instructionsThe memory access instructions generate the most traps. With the exception of the floating-point and coprocessor trap conditions, the traps shown below will cause a user program to terminate, dumping core . When these conditions are detected during execution of kernel code, it is considered catastrophic, and the system will immediately panic with a "bad trap.". Table B-7. SPARC trap conditions and causes
When analyzing a system crash dump caused by a "bad trap," you'll usually find that a load or store instruction caused the crash. |