Obicere
Obicere

Reputation: 3019

Configuring GCC for the SPARC architecture

I've been trying to compile a SPARC program. Just a simple one taken straight out of the book: SPARC Architecture, Assembly Language Programming, and C: Second Edition. However, I get an error leading me to believe SPARC wasn't correctly configured on my computer yet. This is on a Windows machine.

.global main
main:
    save    %sp,    96,    %sp
    mov     9,      %l0
    sub     %l0,    1,     %o0
    sub     %l0,    7,     %o1
    call    .mul        
    nop
    sub     %l0,    11,    %o1
    call    .div    
    mov     %o0,    %l1        

    mov     1,      %g1
    ta      0

I have GCC 4.9.2 installed through Cygwin 1.7.5.

I get the follow error upon trying to compile through GCC

C:\Users\Matt\Desktop>gcc expr.s -o expr
expr.s: Assembler messages:
expr.s: Warning: end of file not at end of a line; newline inserted
expr.s:3: Error: no such instruction: `save %sp,96,%sp'
expr.s:4: Error: bad register name `%l0'
expr.s:5: Error: bad register name `%l0'
expr.s:6: Error: bad register name `%l0'
expr.s:9: Error: bad register name `%l0'
expr.s:11: Error: bad register name `%o0'
expr.s:13: Error: bad register name `%g1'
expr.s:14: Error: no such instruction: `ta 0'

Which highlights almost everything unique with SPARC compared to a different architecture as being an 'error'.

So, I tried setting the architecture specifically for the program:

gcc -march=sparc expr.s -o expr

This still throws an error, which leads me to believe that my current configuration isn't set up for SPARC.

The procedure I used to setup GCC is: here

The only difference is instead of specifying c,c++ for the languages, I used all.

Thanks

Upvotes: 2

Views: 1984

Answers (2)

Neha Karanjkar
Neha Karanjkar

Reputation: 3500

Here's a small tutorial on compiling simple programs for a Sparc V8 target and running them on Qemu. The tutorial includes steps on obtaining a cross compiler(assuming you're working with Linux)

Upvotes: 2

user2548418
user2548418

Reputation: 1571

You are right, your gcc is not set up for SPARC. If you are running Windows, the computer you are running on has an ISA other than SPARC (most likely x86). Your ISA is the hardware interface and can not be changed by a software upgrade.

To compile SPARC programs, you will need to rebuild gcc as a SPARC cross-compiler (host and target ISAs are different). When building from source, this is done with the -target= flag. Building a cross-compiler for linux will be similar to cygwin link.

Once you build the cross-compiler, to execute it you will need a way to simulate a SPARC processor. Using a system such as qemu will work.

Upvotes: 2

Related Questions