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

  1. vbcc - C compiler (c) in 1995-2000 by Volker Barthelmann
  2.  
  3.  
  4. INTRODUCTION
  5.  
  6.     vbcc is a free 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.     Motorola m68k/Coldfire 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.     -cpu=n      Generate code for cpu n (e.g. -cpu=68020), default: 68000
  25.  
  26.     -fpu=n      Generate code for fpu n (e.g. -fpu=68881), default: 0
  27.  
  28.     -sd         Use small data model (see below).
  29.  
  30.     -sc         Use small code model (see below).
  31.  
  32.     -prof       Insert code for profiling (not really usable yet).
  33.  
  34.     -const-in-data
  35.  
  36.                 By default constant data will be placed in the code
  37.                 section (and therefore is accessable with faster pc-relative
  38.                 addressing modes). Using this option it will be placed in the
  39.                 data section.
  40.                 This could e.g. be useful if you want to use small data and
  41.                 small code, but your code gets too big with all the constant
  42.                 data.
  43.                 Note that on operating systems with memory protection this
  44.                 option will disable write-protection of constant data.
  45.  
  46.     -use-framepointer
  47.  
  48.                 By default automatic variables are addressed through a7
  49.                 instead of a5. This generates slightly better code, because
  50.                 the function entry and exit overhead is reduced and a5 can be
  51.                 used as register variable etc.
  52.                 However this may be a bit confusing when debugging and you
  53.                 can force vbcc to use a5 as a fixed framepointer.
  54.  
  55.     -no-peephole
  56.  
  57.                 The intermediate code does not contain any of the 68k
  58.                 addressing modes, so if they are to be used an extra pass
  59.                 over the intermediate code is necessary to recognize certain
  60.                 patterns that can be expressed using a 68k addressing mode.
  61.                 By default vbcc tries to use some 68k addressing modes.
  62.                 Currently (ax)+ and subsets of (displ,ax,dy*skal) are used.
  63.                 However not all cases where those addressing modes could be
  64.                 used are recognized.
  65.                 With this option you can prevent vbcc from searching for
  66.                 possible addressing modes. This may simplify debugging.
  67.  
  68.     -no-delayed-popping
  69.  
  70.                 By default arguments of function calls are not always popped
  71.                 from the stack immediately after the call, so that the
  72.                 arguments of several calls may be popped at once.
  73.                 With this option vbcc can be forced to pop them after every
  74.                 function call.
  75.                 This may simplify debugging and very slightly reduce the
  76.                 stack size needed by the compiled program.
  77.  
  78.     -gas        Create output suitable for the GNU assembler. This is
  79.                 mainly useful to create code for other operating systems.
  80.  
  81.     -no-fp-return
  82.  
  83.                 Do not return floats and doubles in floating-point registers
  84.                 even if code for an fpu is generated. This is mainly useful
  85.                 to create code for other operating systems.
  86.  
  87.     -no-mreg-return
  88.  
  89.                 Do not use multiple registers to return types that do not
  90.                 fit into a single register. This is mainly for backwards
  91.                 compatibility.
  92.  
  93.     -hunkdebug  When creating debug-output (-g option) create Amiga debug
  94.                 hunks rather than DWARF2. This does not work with -gas.
  95.  
  96.     -no-intz    When generating code for FPU do quick&dirty conversions
  97.                 from floating-point to integer. The code may be somewhat
  98.                 faster but will not correctly round to zero.
  99.                 Only use it if you know what you are doing.
  100.  
  101.     -d2scratch  obsolete
  102.  
  103.     -noa4       obsolete
  104.  
  105.  
  106. SOME INTERNALS
  107.  
  108.     The current version generates assembler output for use with the PhxAss
  109.     assembler (c) by Frank Wille. Most peephole optimizations are done by the
  110.     assembler so vbcc only does some that the assembler cannot make.
  111.     The generated executables will probably only work with OS2.0 or higher.
  112.  
  113.     With -gas assembler output suitable for the GNU assembler is generated
  114.     (the version must understand the Motorola syntax - some old ones do not).
  115.     The output is only slightly modified from the PhxAss-output and will
  116.     therefore result in worse code on gas. However this code generator should
  117.     be usable on most operating systems on 68k machines that way.
  118.  
  119.     The register names are:
  120.  
  121.          a0,  a1,  a2,  a3,  a4,  a5,  a6,  a7
  122.          d0,  d1,  d2,  d3,  d4,  d5,  d6,  d7
  123.         fp0, fp1, fp2, fp3, fp4, fp5, fp6, fp7
  124.  
  125.     The registers d0, d1, a0, a1, fp0 and fp1  are used as scratch registers
  126.     (i.e. they can be destroyed in function calls), all other registers are
  127.     preserved.
  128.  
  129.     All scalar types up to 4 bytes are returned in register d0 like
  130.     common on the Amiga (although I think pointers should better be returned
  131.     in a0). If compiled for an fpu, floating point values are returned in
  132.     fp0 unless -no-fpreturn is specified.
  133.     Types which are 8, 12 or 16 bytes large will be returned in several
  134.     registers (d0/d1/a0/a1) unless -no-mreg-return is specified.
  135.     All other types are returned by passing the function the address
  136.     of the result as a hidden argument - so when you call such a function
  137.     without a proper declaration in scope you can expect a crash.
  138.  
  139.     You must not link objects together that have been compiled with
  140.     different settings!
  141.  
  142.     vbcc uses d0-d7 and a0-a6 for temporary results and register variables
  143.     (a4 is used as small data pointer if -sd is used). a5 can be
  144.     used as frame pointer for automatic variables (but this is not necessary -
  145.     they can be accessed through a7, too). At the moment all local
  146.     variables are addressed via (dist,ax), so a function may have only ~32k
  147.     of local variables if code for <=68000 is generated.
  148.  
  149.     The elementary data types are represented like:
  150.  
  151.     type        size in bits        alignment in bytes
  152.  
  153.     char                8                       1
  154.     short              16                       2
  155.     int                32                       2
  156.     long               32                       2
  157.     all pointers       32                       2
  158.     float(fpu)         32                       2       see below
  159.     double(fpu)        64                       2       see below
  160.  
  161.     Although it would be better to have all 32bit+ types aligned to 4 bytes
  162.     I chose 2 bytes to be compatible with the Amiga system structures which
  163.     unfortunately have longwords aligned to 4n+2-addresses.
  164.  
  165.     The amiga68k code generator at the moment only works on systems
  166.     that store floats and doubles in a similar way (IEEE) like the Amiga.
  167.  
  168.  
  169. SMALL DATA
  170.  
  171.     vbcc can access static data in two ways. By default all such data will
  172.     be accessed with full 32bit addresses (large data model).
  173.     However there is a second way. You can set up an address register (a4)
  174.     to point into your data segment and then address data with a 16bit
  175.     offset through this register.
  176.     The advantages of the small data model are that your program will
  177.     usually be smaller (because the 16bit offsets use less space and no
  178.     relocation information is needed) and faster.
  179.     The disadvantages are that one address register cannot be used by the
  180.     compiler and that you can use it only if all your static data occupies
  181.     less than 64kb. Also you may not mix object modules and libraries that
  182.     have been compiled with different data models (you can call functions
  183.     compiled with large data model from object files compiled with small
  184.     data model, but not vice versa and only functions can be called that
  185.     way - other data cannot be accessed) and you probably have to use
  186.     PhxLnk then.
  187.  
  188.     If you use small data together with functions which are called from
  189.     functions which have not been compiled with vbcc or with the small data
  190.     model then you _must_ define those functions with the __saveds attribute
  191.     or call geta4() as the first statement in your function (do not use
  192.     automatic initializations prior to the call to geta4).
  193.     Note that you must not call geta4() through a function pointer!
  194.  
  195.  
  196. SMALL CODE
  197.  
  198.     If you use the small code model calls to external functions (i.e. from
  199.     libraries or other object files) are done with 16bit offsets over
  200.     the program counter rather than with absolute 32bit addresses.
  201.     The advantage is slightly smaller and faster code.
  202.     The disadvantages are that all the code (including library functions)
  203.     must be small enough and that you may have to use PhxLnk. However
  204.     you can link objects/libraries together if they have been compiled
  205.     with different code models.
  206.  
  207.  
  208. CPUs
  209.  
  210.     At the moment the values of -cpu=n have those effects:
  211.  
  212.     n<68000     - code for the Coldfire family is generated
  213.  
  214.     n>=68000    - code for the 68k family is generated
  215.  
  216.     n>=68020:   - 32bit multiplication/division/modulo is done with the
  217.                   mul?.l, div?.l and div?l.l instructions
  218.                 - tst.l ax is used
  219.                 - extb.l dx is used
  220.                 - 16/32bit offsets are used in certain addressing modes
  221.                 - link.l is used
  222.                 - addressing modes with scaling are used
  223.                 - (dx) is used if no address register is available (not yet)
  224.  
  225.     n==68040    - 8bit constants are not copied in data registers
  226.  
  227.  
  228. FPUs
  229.  
  230.     At the moment the values of -fpu=n have those effects:
  231.  
  232.     n>68000:    - floating point calculations are done using the fpu
  233.     n=68040:
  234.     n=68060:    - instructions that have to be emulated on these fpus
  235.                   will not be used; at the moment this only includes
  236.                   the fintrz instruction in case of the 040
  237.  
  238.  
  239. MATH
  240.  
  241.     Integer math hopefully works without problems on all cpus. Long multiply
  242.     on cpus <68020 uses inline routines. This may increase code size a bit,
  243.     but it should be significantly faster, because function call overhead
  244.     is not necessary and the compiler can use the registers which already
  245.     contain the sources and/or need the result. However if anyone really
  246.     wants an option for using library routines for multiply, this can easily
  247.     be implemented. Long division and modulo is handled by calls to library
  248.     functions. At the moment standard library calls with parameter passing
  249.     via stack are used. This is rather slow, but division takes quite some
  250.     time anyway.
  251.     (mult/div/mod with constant powers of two are replaced by corresponding
  252.      bitwise operations (div/mod only if the other operand is unsigned), but
  253.      sums of powers of two not yet).
  254.  
  255.     If no FPU is specified floating point math is done using the C=
  256.     math libraries. 32 bit IEEE format is used for float and 64 bit IEEE
  257.     for double.
  258.  
  259.     Floating point math is done with the FPU if one is specified (see above).
  260.     Floating point values are kept in registers then and therefore may
  261.     have extended precision sometimes, which is not ANSI compliant (but
  262.     will usually cause no harm). When floating point values are stored in
  263.     memory they use the same IEEE formats as without FPU.
  264.     Float or double return values are passed in fp0.
  265.  
  266.     Note that you must not link object files together if they were not
  267.     compiled with the same -fpu settings and that you have to link with
  268.     the proper math library (see vclib.doc).
  269.  
  270.  
  271. TARGET-SPECIFIC VARIABLE ATTRIBUTES
  272.  
  273.     The m68k-backend offers the following variable attributes:
  274.  
  275.     __saveds:    Load the pointer to the small data segment at
  276.                  function-entry. Applicable only to functions.
  277.  
  278.     __chip:      Place variable in chip-memory. Only applicable on
  279.                  AmigaOS to variables with static storage-duration.
  280.  
  281.     __far:       Do not place this variable in the small-data segment
  282.                  in small-data-mode. No effect in large-data-mode.
  283.                  Only applicable to variables with static storage-
  284.                  duration.
  285.  
  286.     __near:      Currently ignored.
  287.  
  288.     __interrupt: This is used to declare interrupt-handlers. The
  289.                  function using this attribute will save all registers
  290.                  it destroys (including scratch-registers) and return
  291.                  with rfe rather than rts.
  292.  
  293.     __section(<string-literal>):
  294.                  Places the variable/function in a section named
  295.                  according to the argument.
  296.  
  297.  
  298. STACK
  299.  
  300.     If the -stack-check option is used, every function-prologue will
  301.     call the function __stack_check with the stacksize needed by this
  302.     function on the stack. This function has to consider its own
  303.     stacksize and must restore all registers.
  304.  
  305.     If the compiler is able to calculate the maximum stack-size of a
  306.     function including all callees, it will add a comment in the
  307.     generated assembly-output (subject to change to labels).
  308.  
  309.  
  310. STDARG
  311.  
  312.     A possible <stdarg,h> could look like this:
  313.  
  314.     typedef unsigned char *va_list;
  315.  
  316.     #define va_start(ap, lastarg) ((ap) = (va_list)(&lastarg + 1))
  317.     #define va_arg(ap, type) ((ap) += \
  318.       (sizeof(type)<sizeof(int)?sizeof(int):sizeof(type)), ((type *)(ap))[-1])
  319.     #define va_end(ap) ((ap) = 0L)
  320.  
  321.  
  322. KNOWN PROBLEMS
  323.  
  324.     - Converting floating point values to unsigned integers is not correct
  325.       if the value is >LONG_MAX and code for an FPU is generated.
  326.  
  327.     - The extended precision of the FPU registers can cause problems if
  328.       a program depends on the exact precision. Most programs will not
  329.       have trouble with that, but programs which do exact comparisons
  330.       with floating point types (e.g. to try to calculate the number
  331.       of significant bits) may not work as expected (especially if the
  332.       optimizer was turned on).
  333.  
  334.  
  335. Volker Barthelmann                                      vb@compilers.de
  336.  
  337.