Sparc Architecture Overview - PowerPoint PPT Presentation

About This Presentation
Title:

Sparc Architecture Overview

Description:

Information for the assembler. .global - tell the assembler the name of this function. ... Dump of assembler code for function main: 0x105a0 main : save %sp, -64, %sp ... – PowerPoint PPT presentation

Number of Views:171
Avg rating:3.0/5.0
Slides: 36
Provided by: cpEngC
Category:

less

Transcript and Presenter's Notes

Title: Sparc Architecture Overview


1
Sparc Architecture Overview
2
Von Neumann Architecture
  • Designed by John von Neumann in 1949.
  • Machine CPU Memory
  • Program is stored in memory along with data.
  • CPU has Program Counter (PC) and Instruction
    Register (IR)
  • Use PC to keep the current location of
    instruction being executed.

3
Von Neumann Architecture
  • Control unit fetches an instruction from memory
    (located by PC) and stores in IR.
  • Memory Memory Address Register (MAR) Memory
    Data Register (MDR)
  • CPU puts an address in MAR and load/store from/to
    MDR.

4
Machine Organization Diagram
5
Instruction Execution
  • Fetch-Decode-Execute cycles
  • Fetch the next instruction from memory.
  • Change PC to point to next instruction.
  • Determine the type of the instruction fetched.
  • Find where the data being used by the instruction
    is kept.
  • Fetch the data, if required.
  • Execute the instruction.
  • Store the results in the appropriate place.
  • Go to step 1 and start all over again.

6
Instruction Cycles
  • pc 0
  • do
  • ir memorypc Fetch the instruction.
  • pc pc INSTR_SIZE Move PC to next
    instruction.
  • decode(ir) Decode the instruction.
  • fetch(operands) Fetch the operands.
  • execute Execute the instruction.
  • store(results) store the results.
  • while(ir ! HALT)

7
Sparc Architecture Overview
  • Load/Store architecture
  • ALU cannot access data from memory directly.
  • Data must be loaded into registers before
    computing.
  • RISC (Reduced Instruction Set Computer)
    architecture
  • All instructions are one word (32 bits).
  • 5-stage Pipelining CPU.

8
Sparc Registers
  • There are 32 registers (r0 - r31).
  • Each register is 64-bit for UltraSparc (128-bit
    for UltraSparc III).
  • Registers are logically divided into 4
    setsglobal (gx), in (ix), local (lx), and
    out (ox).
  • All registers are equal, can perform any
    operations.
  • Special register
  • g0 (r0) - always discards writes and return
    zero.

9
Sparc Registers
  • Global
  • g0 r0 readonly / return zero
  • g1 r1
  • g2 r2
  • g3 r3
  • g4 r4
  • g5 r5
  • g6 r6
  • g7 r7
  • Output
  • o0 r8
  • o1 r9
  • o2 r10
  • o3 r11
  • o4 r12
  • o5 r13
  • o6 r14 sp stack pointer
  • o7 r15 called sub ret addr

10
Sparc Registers
  • Local
  • l0 r16
  • l1 r17
  • l2 r18
  • l3 r19
  • l4 r20
  • l5 r21
  • l6 r22
  • l7 r23
  • Input
  • i0 r24
  • i1 r25
  • i2 r26
  • i3 r27
  • i4 r28
  • i5 r29
  • i6 r30 fp frame pointer
  • i7 r31 sub return addr

11
Format of Instructions
  • Any instruction is made up of two parts
  • Opcode (the name of the instruction)
  • Operands (the values or data manipulated by the
    instruction) -- can be omitted.
  • L1 add i2, 0x80, o1 ! Add two numbers

label
opcode
operands
comment
12
Label
  • Define the location of data or instruction.
  • Start with letter (A-Z and a-z), _, , or .
  • Followed by letter (A-Z and a-z), number (0-9),
    _, , or .
  • Must end with color ().

13
Operands
  • Most instructions have three operands
  • three registersop reg, reg, regadd g1, i2,
    g2 ! G2 is the destination.
  • two registers and a literal constantop reg, imm,
    regadd o1, 30, o2 ! O2 is the destination.
  • two registersop reg, regmov o4, l3 ! L3 is
    the destination.

14
Operands
  • a constant and a registerop imm, regmov 453,
    g1 ! G1 is the destination.
  • a registerop regclr l2
  • a constantop immcall myfunc
  • Notice
  • Last one is usually the destination.

15
Constant in Operand
  • Constant (imm) must be 13-bit signed number
  • -4096 lt imm lt 4096
  • Format of constant ???

16
Comment
  • Inline comment (!)
  • ignore to the end of line.
  • ! Inline comment here. Ignore to end of line.
  • C-style comment (/ /)
  • ignore anything between the comment markers.
  • / comment here
  • and it can be multiple line. /

17
Our First Program
  • Let try some simple C program (but nothello
    world !).
  • / first.c -- not hello world ! as usual /
  • main()
  • int x, y
  • x 9
  • y (x - 2)(x 14)/(x 1)
  • printf(x d, y d\n, x, y)

18
printf Function
var1
  • printf(x d, y d\n, x, y)
  • Display information formatted by the first
    string.
  • Format
  • d integer
  • s string
  • f floating point
  • \n newline

format
var2
19
Our First Program
  • gcc -S first.c
  • generate first.s
  • .file "first.c"
  • gcc2_compiled.
  • .global .umul
  • .global .div
  • .section ".rodata"
  • .align 8
  • .LLC0
  • .asciz "x d and y d\n"
  • .section ".text"
  • .align 4
  • .global main
  • .type main,function
  • .proc 04
  • main
  • !PROLOGUE 0
  • save sp, -120, sp
  • !PROLOGUE 1
  • mov 9, o0
  • st o0, fp-20
  • ld fp-20, o1
  • add o1, -2, o0
  • ld fp-20, o2
  • add o2, 14, o1
  • call .umul, 0
  • nop
  • ld fp-20, o2
  • add o2, 1, o1
  • call .div, 0
  • ...

20
Sparc Basic Assembly Instructions
  • Load/Store Operations
  • mov 75, o2 ! o2 75
  • mov o2, i3 ! i3 o2
  • clr l4 ! l4 0
  • Arithmetics
  • add o1, l2, l3 ! l3 o1 l2
  • add o3, 19, g4 ! g4 o3 19
  • sub i0, g2, o5 ! o5 i0 g2

21
Sparc Basic Assembly Instructions
  • Multiply / Divide
  • To multiply 24 i2
  • mov 24, o0 ! First operand
  • mov i2, o1 ! Second operand
  • call .mul ! Result stored in o0
  • nop ! Delay slot, discussed later
  • ! o0 o0 o1
  • To divide o2 / g3
  • mov o2, o0 ! First operand
  • mov g3, o1 ! Second operand
  • call .div ! Result stored in o0
  • nop ! Delay slot, discussed later
  • ! o0 o0 / o1

22
Our First Program (Revisited)
  • / first.m /
  • /
  • This programs compute
  • y (x - 2) (x 14) / (x 8)
  • for x 9
  • /
  • / use l0 and l1 to store x and y /
  • define(x_r, l0)
  • define(y_r, l1)
  • / define constants /
  • define(c1, 2)

23
Our First Program (Revisited)
  • fmt .asciz "x d and y d\n"
  • .align 4
  • .global main
  • main save sp, -64, sp
  • mov 9, x_r ! x 9
  • sub x_r, c1, o0 ! o0 x - 2
  • add x_r, 14, o1 ! o1 x 14
  • call .mul ! o0 o0 o1
  • nop
  • add x_r, 1, o1 ! o1 x 1
  • call .div ! o0 o0 / o1
  • nop
  • mov o0, y_r ! store result in y

24
Our First Program (Revisited)
  • set fmt, o0 ! first argument for printf
  • mov x_r, o1 ! second argument for printf
  • mov y_r, o2 ! third argument for printf
  • call printf ! print them out
  • nop
  • mov 1, g1 ! prepare to exit
  • ta 0 ! normal exit

25
Directives
  • Information for the assembler.
  • .global - tell the assembler the name of this
    function.
  • .asciz - define a string.
  • .align - align a location counter on a boundary.

26
Creating Executable File
  • Use M4 macro-processor
  • m4 lt first.m gt first.s
  • (M4 produces first.s. Notice macro expansion.)
  • Compile first.s
  • gcc -S first.s -o first
  • (this produces an executable file first.)

27
Running our First Program
  • Run first
  • first
  • x 9 and y 16
  • Using printf to trace a program is not
    convenient.

28
The gdb Debugger
  • To check the result, we will use a debugger.
  • Run gdb ltfilenamegt
  • gdb first
  • (gdb)
  • Run your program
  • (gdb)r
  • Starting program /usr3/faculty/natawut/Class/Asse
    mbly/first
  • ...
  • Program exited with code 011.
  • (gdb)

29
Breakpoint
  • Set a breakpoint
  • (gdb) b main
  • Breakpoint 1 at 0x105a4
  • (gdb) r
  • Starting program /usr3/faculty/natawut/Class/Asse
    mbly/first
  • ...
  • Breakpoint 1, 0x105a4 in main ()
  • (gdb)

30
Print an Instruction
  • (gdb) x/i pc
  • 0x105a4 ltmain4gt mov 9, l0
  • (gdb)
  • 0x105a8 ltmain8gt sub l0, 2, o0
  • (gdb)
  • We can examine memory by typing x.
  • Tell gdb to interpret the current memory as an
    instruction.
  • Use current location pointed by pc.
  • Repeat last command by hitting enter key.

31
Print the Entire Program
  • (gdb) disassemble
  • Dump of assembler code for function main
  • 0x105a0 ltmaingt save sp, -64, sp
  • 0x105a4 ltmain4gt mov 9, l0
  • 0x105a8 ltmain8gt sub l0, 2, o0
  • 0x105ac ltmain12gt add l0, 0xe, o1
  • 0x105b0 ltmain16gt call 0x2069c lt.mulgt
  • 0x105b4 ltmain20gt nop
  • ...
  • 0x105d4 ltmain52gt add o7, l7, l7
  • End of assembler dump.
  • (gdb)

32
More Debugging Commands
  • Advance breakpoint
  • (gdb) b main16
  • Breakpoint 3 at 0x105cc
  • (gdb) c
  • Continuing.
  • Breakpoint 3, 0x105cc in main ()
  • (gdb)
  • We use c to continue execution after stopping
    at a breakpoint.

33
More Debugging Commands
  • Print out the contents of a register
  • (gdb) p l0
  • 1 9
  • (gdb)
  • Automatically print out contents
  • (gdb) display/i pc
  • 1 x/i pc 0x105a4 ltmain4gt mov 9, l0
  • (gdb) r
  • The program being debugged has been started
    already.
  • Start it from the beginning? (y or n) y
  • Starting program /usr3/faculty/natawut/Class/Asse
    mbly/first

34
More Debugging Commands
  • Breakpoint 2, 0x105a4 in main ()
  • 1 x/i pc 0x105a4 ltmain4gt mov 9, l0
  • (gdb) ni
  • 0x105a8 in main ()
  • 1 x/i pc 0x105a8 ltmain8gt sub l0, 2, o0
  • (gdb)
  • We use r to restart execution from the
    beginning and ni to execute the next
    instruction.

35
More Debugging Commands
  • For other commands, try help
  • To exit from gdb q
Write a Comment
User Comments (0)
About PowerShow.com