Shop OBEX P1 Docs P2 Docs Learn Events
P2 Compilers: PNUT, GAS, ??? Pros & Cons? — Parallax Forums

P2 Compilers: PNUT, GAS, ??? Pros & Cons?

Cluso99Cluso99 Posts: 18,069
edited 2013-04-14 04:41 in Propeller 2
I have been using PNUT for P2 PASM compiles (I know, its and assembler).

However, I would really like to use macros for the LMM code that I am using in my debugger for things such as call, ret, branch, jump, push and pop. David suggested GAS.
Where do I get it, how does it work, any restrictions?
Note I am a windoze only user.

Roy's OpenSpin compiler is currently only for P1.

What is the rationalle behind having two open compilers (GAS and OpenSpin) ? What are the differences?
BTW I understand pnut is a quick interim solution by Chip, so I have ignored this one.

Comments

  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2013-04-12 16:53
    GAS is part of the gcc project. It only does assembler. It's essentially the final step of compiling C code down to the prop (or something like that). The GAS syntax for assembler has some differences from the normal PASM syntax.

    OpenSpin is a Spin compiler that does the full spin language and PASM.

    PNUT can actually Spin also, it just hasn't been fixed to deal with the P2 fully. PNUT is Chips executable wrapper around the x86 ASM code that is the compiler/assembler. I ported the earlier version of this for P1. I will be bringing over the changes for P2 as well. However, I have to finish other things first.

    Roy
  • David BetzDavid Betz Posts: 14,516
    edited 2013-04-12 17:42
    Roy Eltham wrote: »
    GAS is part of the gcc project. It only does assembler. It's essentially the final step of compiling C code down to the prop (or something like that). The GAS syntax for assembler has some differences from the normal PASM syntax.

    OpenSpin is a Spin compiler that does the full spin language and PASM.

    PNUT can actually Spin also, it just hasn't been fixed to deal with the P2 fully. PNUT is Chips executable wrapper around the x86 ASM code that is the compiler/assembler. I ported the earlier version of this for P1. I will be bringing over the changes for P2 as well. However, I have to finish other things first.

    Roy
    Eric has recently made changes in GAS that brings it close to PASM. This new version is in the p2test branch and I can build a Windows version and upload it if there is interest.
  • SapiehaSapieha Posts: 2,964
    edited 2013-04-12 17:48
    Hi David.

    Thanks for that
    If possible some DOC on differences to PASM

    David Betz wrote: »
    Eric has recently made changes in GAS that brings it close to PASM. This new version is in the p2test branch and I can build a Windows version and upload it if there is interest.
  • RaymanRayman Posts: 14,755
    edited 2013-04-12 18:20
    It appears to me (might be wrong) that there are a few different GAS syntaxes...

    There's the original, the Intel, the old PASM and the new PASM...
    I think the old PASM threw some people because the program counter was in increments of "4" bytes instead of "1" long...

    But, I could be way, way off..
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-04-13 11:51
    David Betz wrote: »
    Eric has recently made changes in GAS that brings it close to PASM. This new version is in the p2test branch and I can build a Windows version and upload it if there is interest.
    David, I would love to give GAS a try in windoze. I think it would make my LMM calls etc much easier.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-04-13 11:55
    Cluso99 wrote: »
    David, I would love to give GAS a try in windoze. I think it would make my LMM calls etc much easier.
    Okay, I have an email out to Eric to ask him to describe the changes he's made. He sent an email to me about them a while ago but I'm not sure if he wants me to post it publically. As soon as I hear from him I'll post the new build and the documentation.

    Thanks,
    David
  • ersmithersmith Posts: 6,068
    edited 2013-04-13 17:28
    The new GAS is a lot more like PASM, but it's still not completely identical. Here are some of the major differences between PASM/PNut and gas -pasm:
    GAS Restrictions Compared to PASM
    ============================
    (1) Floating point in GAS can only occur in a .float directive, and
    only simple constants are accepted (no expressions).
    
    (2) Strings can only appear in .ascii (not byte).
    
    (3) Repeat counts missing (for now).
    
    (4) String literals not accepted in immediates.
    
    (5) No Spin operators like |<.
    
    (6) res produces zeros
    
    (7) org and fit are ignored (left to linker).
    
    (8) GAS only accepts ASCII (or UTF-8) input, not UTF-16.
    
    (9) conditionals like if_z cannot start the line, there must be at
    least one space before them
    
    (10) long and word directives are not automatically aligned (they must
    be explicitly aligned). This is actually a useful feature, since it
    allows you to easily define packed structures.
    
    Why use GAS?
    ============
    
    (1) It supports macros.
    
    (2) It has some built-in macros for LMM.
    
    (3) It has conditional compilation.
    
    (4) It allows you to specify sections to intersperse code and data, or
    code that should go in different parts of memory.
    
    (5) It produces linkable objects.
    
    (6) As a consequence of using ELF output, it supports some neat
    features like weak symbols (that can be overridden by other modules).
    
    (7) It can specify arbitrary alignment.
    
    (8) It can generate gdb debug info (if you like the gdb debugger).
    

    Some of the GAS restrictions can probably be lifted, but it probably won't ever be 100% compatible with PASM. On the other hand a lot of programs can compile with either one.

    Eric
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-04-13 19:10
    ersmith wrote: »
    The new GAS is a lot more like PASM, but it's still not completely identical. Here are some of the major differences between PASM/PNut and gas -pasm:
    GAS Restrictions Compared to PASM
    ============================
    (1) Floating point in GAS can only occur in a .float directive, and
    only simple constants are accepted (no expressions).

    (2) Strings can only appear in .ascii (not byte).

    (3) Repeat counts missing (for now).

    (4) String literals not accepted in immediates.

    (5) No Spin operators like |<.

    (6) res produces zeros

    (7) org and fit are ignored (left to linker).

    (8) GAS only accepts ASCII (or UTF-8) input, not UTF-16.

    (9) conditionals like if_z cannot start the line, there must be at
    least one space before them

    (10) long and word directives are not automatically aligned (they must
    be explicitly aligned). This is actually a useful feature, since it
    allows you to easily define packed structures.
    My comments...
    (1) Unsure
    (2) How do we embed a <cr> ?
    (3) ???
    (4) Can work around although I often use it
    (5) Are these only the special concatenated operators? i.e. is <, <=, *, etc fine?
    (6) Can work around
    (7) OK
    (8) No problems
    (9) No problems - in fact preferred
    (10) Agreed, no problems

    I understand we can run a pre-processor. Could this handle (2) and (4) temporarily?
    Why use GAS?
    ============

    (1) It supports macros.

    (2) It has some built-in macros for LMM.

    (3) It has conditional compilation.

    (4) It allows you to specify sections to intersperse code and data, or
    code that should go in different parts of memory.

    (5) It produces linkable objects.

    (6) As a consequence of using ELF output, it supports some neat
    features like weak symbols (that can be overridden by other modules).

    (7) It can specify arbitrary alignment.

    (8) It can generate gdb debug info (if you like the gdb debugger).

    Some of the GAS restrictions can probably be lifted, but it probably won't ever be 100% compatible with PASM. On the other hand a lot of programs can compile with either one.

    (1) and (3) are the huge features I think most of us require. Of course (2) is required for GCC.

    I understand GAS also has INCLUDE ???

    However, we have to use a linker. What is available and how easy is it to use? Presume both GAS and LINKERcould be placed in a .bat file in windows?

    Perhaps best to explain what I do now (P2 only and on Windows7)...
    Use PNUT to edit and create .OBJ file
    Switch to DOS Commandline and run P2.BAT which does...
    p2load -v -b 115200 -s XXX.obj -h -T

    So I can easily modify the P2.bat file to run GAS, Linker and P2Load.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-04-13 20:32
    ersmith wrote: »
    The new GAS is a lot more like PASM, but it's still not completely identical. Here are some of the major differences between PASM/PNut and gas -pasm:
    GAS Restrictions Compared to PASM
    ============================
    (1) Floating point in GAS can only occur in a .float directive, and
    only simple constants are accepted (no expressions).
    
    (2) Strings can only appear in .ascii (not byte).
    
    (3) Repeat counts missing (for now).
    
    (4) String literals not accepted in immediates.
    
    (5) No Spin operators like |<.
    
    (6) res produces zeros
    
    (7) org and fit are ignored (left to linker).
    
    (8) GAS only accepts ASCII (or UTF-8) input, not UTF-16.
    
    (9) conditionals like if_z cannot start the line, there must be at
    least one space before them
    
    (10) long and word directives are not automatically aligned (they must
    be explicitly aligned). This is actually a useful feature, since it
    allows you to easily define packed structures.
    
    Why use GAS?
    ============
    
    (1) It supports macros.
    
    (2) It has some built-in macros for LMM.
    
    (3) It has conditional compilation.
    
    (4) It allows you to specify sections to intersperse code and data, or
    code that should go in different parts of memory.
    
    (5) It produces linkable objects.
    
    (6) As a consequence of using ELF output, it supports some neat
    features like weak symbols (that can be overridden by other modules).
    
    (7) It can specify arbitrary alignment.
    
    (8) It can generate gdb debug info (if you like the gdb debugger).
    

    Some of the GAS restrictions can probably be lifted, but it probably won't ever be 100% compatible with PASM. On the other hand a lot of programs can compile with either one.

    Eric
    Thanks for the summary Eric! I'll upload the Windows version tomorrow.
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-04-14 00:24
    Thanks Eric & David. Looking forward to giving it a go.
  • ersmithersmith Posts: 6,068
    edited 2013-04-14 04:41
    Cluso99 wrote: »
    (2) How do we embed a <cr> ?
    You can use:
      .ascii "hello, world\r"
    
    or
      .ascii "hello, world"
      .byte 13
    

    I agree it's inconvenient, but unfortunately gas is pretty serious about distinguishing between numbers (byte directive) and characters (ascii directive). We're looking at ways to preprocess this away, but it requires special handling beyond what the normal preprocessor can do.
    (3) ???
    
    Sorry, that was a bit terse! What I meant is that repeat counts in byte/word/long are not understood by GAS, so:
      long 0[20]
    
    won't work. I think there is a way around this. GAS has its own notion of repeat counts, and we can probably in a future release provide translation.
    (5) Are these only the special concatenated operators? i.e. is <, <=, *, etc fine?
    Right... GAS pretty much only understands the same operators as C.
    I understand GAS also has INCLUDE ???
    It has a built in .include directive. It's also easy to run the assembly source through the C pre-processor (which can be invoked automatically by the gcc compiler driver). You can use either or both of GAS built in macros and C pre-processor macros; the GAS ones look more like assembler instructions and are more powerful than C macros (you can loop in a GAS macro, for example).
    However, we have to use a linker. What is available and how easy is it to use? Presume both GAS and LINKER could be placed in a .bat file in windows?
    The linker is a command line program, so it could pretty easily go in a batch file. For compiling a typical P2 assembly program you'd do:
       propeller-elf-as -pasm -p2 -o foo.o foo.s
       propeller-elf-ld -Tp2binary.ld -o foo.bin foo.o
    
    Here p2binary.ld is a simple linker script that you can use for all programs, something like:
    OUTPUT_FORMAT ( binary ) ;
    
    SECTIONS
    {
      . = 0;
      .text : { *(.text*) }
      .data : { *(.data*) }
      .bss  : { *(.bss*) }
    }
    
    This selects what kind of output to make, then says to link the code starting at 0 with the .text sections of all inputs first, then the .data sections, then .bss. Those are the typical sections in C code, although in a simple COG program you would probably only have the default .text section.

    The linker allows either ELF output (contains symbol and other debugging information and a load map allowing propeller-load to place sections in different parts of memory) or simple flat binary output; you can select this in the linker script or on the command line.

    Eric
Sign In or Register to comment.