home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 5 / CD_Magazyn_EXEC_nr_5.iso / Programy / Programowanie / vbcc07e.lzx / vbcc / doc / vbccppc.doc < prev    next >
Encoding:
Text File  |  2001-02-12  |  8.7 KB  |  260 lines

  1. vbcc - C compiler (c) in 1995-2000 by Volker Barthelmann
  2.  
  3.  
  4. INTRODUCTION
  5.  
  6.     vbcc is a portable and retargetable ANSI C compiler.
  7.     It is clearly split into a target independant and a target dependant
  8.     part and supports emulating datatypes of the target machine on any
  9.     other machine so that it is possible to e.g. make a crosscompiler for
  10.     a 64bit machine on a 32bit machine.
  11.     This document only deals with the target dependant parts of the
  12.     PowerPC version.
  13.  
  14.  
  15. LEGAL
  16.  
  17.     vbcc is (c) in 1995-2000 by Volker Barthelmann. 
  18.     This is a development snapshot which must not be distributed.
  19.     Also, commercial usage is forbidden.
  20.  
  21.  
  22. ADDITIONAL OPTIONS FOR THIS VERSION
  23.  
  24.     -merge-constants
  25.  
  26.                 Place identical floating point constants at the same
  27.                 memory location. This can reduce program size and increase
  28.                 compilation time.
  29.  
  30.     -const-in-data
  31.  
  32.                 By default constant data will be placed in the .rodata
  33.                 section. Using this option it will be placed in the data
  34.                 section.
  35.                 Note that on operating systems with memory protection this
  36.                 option will disable write-protection of constant data.
  37.  
  38.     -fsub-zero
  39.  
  40.                 Use fsub to load a floating-point-register with zero.
  41.                 This is faster but requires all registers to always contain
  42.                 valid values (i.e. no NaNs etc.) which may not be the case
  43.                 depending on startup-code, libraries etc.
  44.  
  45.     -amiga-align
  46.  
  47.                 Do not require any alignments greater than 2 bytes.
  48.                 This is needed when accessing Amiga system-structures, but
  49.                 can cause a performance penalty.
  50.  
  51.     -elf
  52.  
  53.                 Do not prefix symbols with '_'. Prefix labels with '.'.
  54.  
  55.     -poweropen
  56.  
  57.                 Generate code for the PowerOpen ABI like used in AIX.
  58.                 This does not work correctly yet.
  59.  
  60.     -sc
  61.  
  62.                 Generate code for the modified PowerOpen ABI used in the
  63.                 StormC compiler.
  64.  
  65.     -no-regnames
  66.  
  67.                 Do not use register names but only numbers. This is necessary
  68.                 to avoid name-conflicts when using -elf.
  69.  
  70.     -setccs
  71.  
  72.                 The V.4 ABI requires that when varargs-functions are called
  73.                 with arguments passed in the floating-point registers this
  74.                 has to be signalled in a certain bit of the condition code
  75.                 register. vbcc usually doesn't make use of this and
  76.                 therefore does not care about that bit by default.
  77.                 This may lead to problems if you link objects compiled by
  78.                 vbcc to objects not compiled by vbcc (e.g. a different
  79.                 C-library) and call varargs-functions with floating-point
  80.                 arguments.
  81.                 In this case -setccs might help.
  82.  
  83.     -no-peephole
  84.  
  85.                 Do not perform several peephole optimizations.
  86.                 Currently includes:
  87.                  - better use of d16(r) addressing
  88.                  - use of indexed addressing modes
  89.                  - use of update-flag
  90.                  - use of record-flag
  91.                  - use of condition-code-registers to avoid certain branches
  92.  
  93.     -use-lmw
  94.  
  95.                 Use lmw/stmw-instructions. This can significantly reduce
  96.                 code-size. However these instructions may be slower on
  97.                 certain PPCs.
  98.  
  99.     -madd       Use the fmadd/fmsub instructions for combining
  100.                 multiplication with addition/subtraction in one instruction.
  101.                 As these instructions do not round between the operations,
  102.                 they have increased precision over separate addition and
  103.                 multiplication.
  104.                 While this usually does no harm, it is not ISO conforming
  105.                 and therefore not the default behaviour.
  106.  
  107.     -eabi       Use the PowerPC Embedded ABI (eabi).
  108.  
  109.     -sd         Place all objects in small data-sections.
  110.  
  111.     -gas        Create code suitable for the GNU assembler.
  112.  
  113.  
  114. SOME INTERNALS
  115.  
  116.     The current version generates assembly output for use with the "pasm"
  117.     assembler by Frank Wille or the GNU assembler. The generated code should
  118.     work on 32bit systems based on a PowerPC CPU using the V.4 ABI or the
  119.     PowerPC Embedded ABI (eabi).
  120.  
  121.     The register names are:
  122.  
  123.         r0 through r31 for the general purpose registers,
  124.         f0 through f31 for the floating point registers and
  125.         cr0 through cr7 for the condition-code registers.
  126.  
  127.     The registers r0, r3-r12, f0-f13 and cr0-cr1 are used as scratch registers
  128.     (i.e. they can be destroyed in function calls), all other registers are
  129.     preserved. r1 is the stack-pointer and r13 is the small-data-pointer if
  130.     small-data-mode is used.
  131.  
  132.     The first 8 function arguments which have integer or pointer types
  133.     are passed in registers r3 through r10 and the first 8 floating-point
  134.     arguments are passed in registers f1 through f8. All other arguments
  135.     are passed on the stack.
  136.  
  137.     Integers and pointers are returned in r3, floats and doubles in f1.
  138.     All other types are returned by passing the function the address
  139.     of the result as a hidden argument - so when you call such a function
  140.     without a proper declaration in scope you can expect a crash.
  141.  
  142.     The elementary data types are represented like:
  143.  
  144.     type        size in bits        alignment in bytes (-amiga-align)
  145.  
  146.     char                8                       1 (1)
  147.     short              16                       2 (2)
  148.     int                32                       4 (2)
  149.     long               32                       4 (2)
  150.     all pointers       32                       4 (2)
  151.     float              32                       4 (2)
  152.     double             64                       8 (2)
  153.  
  154.  
  155. TARGET-SPECIFIC VARIABLE ATTRIBUTES
  156.  
  157.     The PPC-backend offers the following variable attributes:
  158.  
  159.     __saveds:    Load the pointer to the small data segment at
  160.                  function-entry. Applicable only to functions.
  161.  
  162.     __chip:      Place variable in chip-memory. Only applicable on
  163.                  AmigaOS to variables with static storage-duration.
  164.  
  165.     __far:       Do not place this variable in the small-data segment
  166.                  in small-data-mode. No effect in large-data-mode.
  167.                  Only applicable to variables with static storage-
  168.                  duration.
  169.  
  170.     __near:      Currently ignored.
  171.  
  172.     __interrupt: Return with rfi rather than blr.
  173.  
  174.     __section("name","attr"):
  175.                  Place this function/object in section "name" with
  176.                  attributes "attr".
  177.  
  178.  
  179. TARGET-SPECIFIC PRAGMAS
  180.  
  181.     The PPC-backend offers the following #pragmas:
  182.  
  183.     #pragma amiga-align     Set alignment like -amiga-alignment option.
  184.  
  185.     #pragma natural-align   Align every type to its own size.
  186.  
  187.     #pragma default-align   Set alignment according to command-line options.
  188.  
  189.  
  190. STACK
  191.  
  192.     If the -stack-check option is used, every function-prologue will
  193.     call the function __stack_check with the stacksize needed by this
  194.     function in register r12. This function has to consider its own
  195.     stacksize and must restore all registers.
  196.  
  197.     If the compiler is able to calculate the maximum stack-size of a
  198.     function including all callees, it will add a comment in the
  199.     generated assembly-output (subject to change to labels).
  200.  
  201.  
  202. STDARG
  203.  
  204.     A possible <stdarg.h> for V.4 ABI could look like this:
  205.  
  206.     typedef struct {
  207.       int gpr;
  208.       int fpr;
  209.       char *regbase;
  210.       char *membase;
  211.     } va_list;
  212.  
  213.     char *__va_start(void);
  214.     char *__va_regbase(void);
  215.     int __va_fixedgpr(void);
  216.     int __va_fixedfpr(void);
  217.  
  218.     #define va_start(vl,dummy) \
  219.       ( \
  220.         vl.gpr=__va_fixedgpr(), \
  221.         vl.fpr=__va_fixedfpr(), \
  222.         vl.regbase=__va_regbase(), \
  223.         vl.membase=__va_start() \
  224.       )
  225.  
  226.     #define va_end(vl) (vl.regbase=vl.membase=0)
  227.  
  228.     #define __va_size(type) ((sizeof(type)+3)/4*4)
  229.     #define va_arg(vl,type) \
  230.       (__typeof(type)&15)>8? \
  231.         (vl.membase+=__va_size(type),((type*)vl.membase)[-1]) \
  232.       : \
  233.        ( \
  234.         (((__typeof(type)&15)==5||(__typeof(type)&15)==6)) ? \
  235.          ( \
  236.           ++vl.fpr<=8 ? \
  237.              ((double*)(vl.regbase+32))[vl.fpr] \
  238.           : \
  239.             (vl.membase+=__va_size(type),((type*)vl.membase)[-1]) \
  240.          ) \
  241.         : \
  242.          ( \
  243.           ++vl.gpr<=8 ? \
  244.             ((int*)(vl.regbase+0))[vl.gpr] \
  245.           : \
  246.             (vl.membase+=__va_size(type),((type*)vl.membase)[-1]) \
  247.          ) \
  248.        ) \
  249.  
  250.  
  251. KNOWN PROBLEMS
  252.  
  253.     - composite types are put on the stack rather than passed via pointer
  254.     - indication of fp-register-args with bit 6 of cr is not done well
  255.     - __interrupt does not save all modified registers
  256.  
  257.  
  258. Volker Barthelmann                                      vb@compilers.de
  259.  
  260.