This chapter documents the backend for the Motorola M68k/CPU32/ColdFire microprocessor family. @section Legal This module is written in 2002-2019 by Frank Wille and is covered by the vasm copyright without modifications. @section Additional options for this module Note, that the order on the command line may be important when specifiying options. For example, if you specify -devpac compatibility mode behind enabling some optimization options, the Devpac-mode might disable these optimizations again. This module provides the following additional options: @subsection CPU selections @table @option @item -m68000 Generate code for the MC68000 CPU. @item -m68008 Generate code for the MC68008 CPU. @item -m68010 Generate code for the MC68010 CPU. @item -m68020 Generate code for the MC68020 CPU. @item -m68030 Generate code for the MC68030 CPU. @item -m68040 Generate code for the MC68040 CPU. @item -m68060 Generate code for the MC68060 CPU. @item -m68020up Generate code for the MC68020-68060 CPU. Be careful with instructions like PFLUSHA, which exist on 68030 and 68040/060 with a different opcode (vasm will use the 040/060 version). @item -m68080 Generate code for the Apollo Core AC68080 FPGA CPU. @item -mcpu32 Generate code for the CPU32 family (MC6833x, MC6834x, etc.). @item -mcf5... @itemx -m5... Generate code for a ColdFire family CPU. The following types are recognized: 5202, 5204, 5206, 520x, 5206e, 5207, 5208, 5210a, 5211a, 5212, 5213, 5214, 5216, 5224, 5225, 5232, 5233, 5234, 5235, 523x, 5249, 5250, 5253, 5270, 5271, 5272, 5274, 5275, 5280, 5281, 528x, 52221, 52553, 52230, 52231, 52232, 52233, 52234, 52235, 52252, 52254, 52255, 52256, 52258, 52259, 52274, 52277, 5307, 5327, 5328, 5329, 532x, 5372, 5373, 537x, 53011, 53012, 53013, 53014, 53015, 53016, 53017, 5301x, 5407, 5470, 5471, 5472, 5473, 5474, 5475, 547x, 5480, 5481, 5482, 5483, 5484, 5485, 548x, 54450, 54451, 54452, 54453, 5445x. @item -mcfv2 Generate code for the V2 ColdFire core. This option selects ISA_A (no hardware division or MAC), which is the most limited ISA supported by 5202, 5204 and 5206. All other ColdFire chips are backwards compatible to V2. @item -mcfv3 Generate code for the V3 ColdFire core. This option selects ISA_A+, hardware division MAC and EMAC instructions, which are supported by nearly all V3 CPUs, except the 5307. @item -mcfv4 Generate code for the V4 ColdFire core. This option selects ISA_B and MAC as supported by the 5407. @item -mcfv4e Generate code for the V4e ColdFire core. This option selects ISA_B, USP-, FPU-, MAC- and EMAC-instructions (no hardware division) as supported by all 547x and 548x CPUs. @item -m68851 Generate code for the MC68851 MMU. May be used in combination with another @option{-m} option. @item -m68881 Generate code for the MC68881 FPU. May be used in combination with another @option{-m} option. @item -m68882 Generate code for the MC68882 FPU. May be used in combination with another @option{-m} option. @item -no-fpu Ignore any FPU options or directives, which has the effect that no 68881/2 FPU instructions will be accepted. This option can override the default of @option{-gas} to enable the FPU. @end table @subsection Optimization options @table @option @item -no-opt Disable all optimizations. Can be seen as a main switch to ignore all other optimization options on the command line and in the source. @item -opt-allbra When specified the assembler will also try to optimize branch instructions which already have a valid size extension. This option is automatically enabled in @option{-phxass} mode. @item -opt-brajmp Translate relative branch instructions, whose destination is in a different section, into absolute jump instructions. @item -opt-clr Enables optimization from @code{MOVE #0,} into @code{CLR } for the MC68000. Note that @code{CLR} will execute a read-modify-write cycle on the 68000, so it is disabled by default. With 68010 and higher this is a generic standard optimization. @item -opt-fconst Floating point constants are loaded with the lowest precision possible. This means that @code{FMOVE.D #1.0,FP0} would be optimized to @code{FMOVE.S #1.0,FP0}, because it is faster and shorter at the same precision. The optimization will be performed on all FPU instructions with immediate addressing mode. When an FDIV-family instruction (@code{FSDIV}, @code{FDDIV}, @code{FSGLDIV}) is detected it will additionally be checked if the immediate constant is a power of 2 and then converted into @code{FMUL #1/c,FPn}. @item -opt-jbra @code{JMP} and @code{JSR} instructions to external labels will be converted into @code{BRA.L} and @code{BSR.L}, when the selected CPU is 68020 or higher (or CPU32). @item -opt-lsl Allows optimization of @code{LSL #1} into @code{ADD}. It is also needed to optimize @code{ASL #2} and @code{LSL #2} into two @code{ADD} instructions (together with @option{-opt-speed}). These optimizations may modify the V-flag, which might not be intended. @item -opt-movem Enables optimization from @code{MOVEM ,Rn} into @code{MOVE ,Rn} (or the other way around). This optimization will modify the flags, when the destination is no address register. @item -opt-mul Immediate multplication factors, which are a power of two (from 2 to 256), are optimized to shifts. Multiplications with zero are replaced by a @code{MOVEQ #0,Dn}, with -1 are replaced by a @code{NEG.L Dn} and with 1 by @code{EXT.L Dn} or @code{TST.L Dn} (long-form). Not all optimizations are available for all cpu types (e.g. @code{MULU.W} can only be optimized on ColdFire by using the @code{MVZ.W} instruction. This optimization will leave the flags in a different state as can normally be expected after a multiplication instruction, and the size of the optimized code may be bigger than before in a few situations (e.g. @code{MULS.W #4,Dn}). The latter will additionally require the @option{-opt-speed} flag. @item -opt-div Unsigned immediate divisors, which are a power of two (from 2 to 256), are optimized to shifts. Divisions by 1 are replaced by @code{TST.L Dn} (32-bit) or @code{MVZ.W Dn,Dn} (16-bit, ColdFire only). Divisions by -1 are replaced by @code{NEG.L Dn} (32-bit) or by a combination of @code{NEG.W Dn} and @code{MVZ.W Dn,Dn} (16-bit, ColdFire only). This optimization will leave the flags in a different state as can normally be expected after a division instruction. @item -opt-pea Enables optimization from @code{MOVE #x,-(SP)} into @code{PEA x}. This optimization will leave the flags unmodified, which might not be intended. @item -opt-speed Optimize for speed, even if this would increase code size. For example it enables optimization of @code{ASL.W #2,Dn} into two @code{ADD.W Dn,Dn} instructions. Or @code{MULS.W #-4,Dn} into @code{EXT.L Dn + ASL.L #2,Dn + NEG.L Dn}. Generally the assembler will never optimize a single into multiple instructions without this option. @item -opt-st Enables optimization from @code{MOVE.B #-1,} into @code{ST }. This optimization will leave the flags unmodified, which might not be intended. @item -sc All @code{JMP} and @code{JSR} instructions to external labels will be converted into 16-bit PC-relative jumps. @item -sd References to absolute symbols in a small data section (named "__MERGED") are optimized into a base-relative addressing mode using the current base register set by an active @code{NEAR} directive. This option is automatically enabled in @option{-phxass} mode. @item -showcrit Print all critical optimizations which have side effects. Among those are @option{-opt-lsl}, @option{-opt-mul}, @option{-opt-st}, @option{-opt-pea}, @option{-opt-movem} and @option{-opt-clr}. @item -showopt Print all optimizations and translations vasm is doing (same as @code{opt ow+}). @end table In its default setting (no @option{-devpac} or @option{-phxass} option) vasm performs the following optimizations: @itemize @minus @item Absolute to PC-relative. @item Branches without explicit size. @item Displacements (32 to 16 bit, @code{(0,An)} to @code{(An)}, etc). @item Optimize floating point constants to the lowest possible precision. @item Many instruction optimizations which are safe. @end itemize @subsection Other options @table @option @item -conv-brackets Brackets (@code{'['} and @code{']'}) in an operand are automatically converted into parentheses (@code{'('} and @code{')'}) as long as the CPU is 68000 or 68010. This is a compatibility option for some old assemblers. @item -devpac All options are initially set to be Devpac compatible. Which means that all optimizations are disabled, no debugging symbols will be written and vasm will warn about any optimization being done. When symbol output is enabled by @code{opt d+}, then the TOS symbol table defaults to standard DRI format (limited to 8 characters). Shift-right operations are performed using an unsigned 32-bit value. Other options are the same as vasm's defaults. The symbol @code{__G2} is defined, which contains information about the selected cpu type. The symbol @code{__LK} reflects the type of output file generated. Which is 0 for TOS executables, 4 for Amiga executables and 3 for Amiga object files. All other formats are represented by 99, as they are unknown to Devpac. It will also automatically enable @option{-guess-ext}. @item -elfregs Register names are preceded by a '%' to prevent confusion with symbol names. @item -gas Enable additional GNU-as compatibility mnemonics, like @code{mov}, @code{movm} and @code{jra}. Also accepts @code{|} instead of @code{;} for comments. GNU-as compatibility mode selects the 68020 CPU and 68881/2 FPU by default and enables @option{-opt-jbra}. @item -guess-ext Accept illegal size extensions for an instruction, as long as the instruction is unsized or there is just a single size possible. This is the default setting in PhxAss and Devpac compatibility mode. @item -kick1hunks Prevents optimization of JMP/JSR to 32-bit PC-relative (BRA/BSR). @item -phxass PhxAss-compatibilty mode. The "current PC symbol" (e.g. @code{*} in mot-syntax module) is set to the instruction's address + 2 whenever an instruction is parsed. According to the current cpu setting the symbols @code{__CPU}, @code{__FPU} and @code{__MMU} are defined. @code{JMP/JSR (label,PC)} will never be optimized (into a branch, for example). It will also automatically enable @option{-opt-allbra}, @option{-sd} and @option{-guess-ext}. @item -rangewarnings Values which are out of range usually produce an error. With this option the errors 2026, 2030, 2033 and 2037 will be displayed as a warning, allowing the user to create an object file. @item -sdreg= Set the small data base register to @code{An}. is valid between 2 and 6. @item -sgs Additionally allow immediate operands to be prefixed by @code{&} instead of just by @code{#}. This syntax was used by the SGS assembler. @item -regsymredef Allow redefining register symbols with @code{EQUR}. This should only be used for compatibility with old sources. Not many assemblers support that. @end table @section General This backend accepts M68k and CPU32 instructions as described in Mototola's M68000 family Programmer's Reference Manual. Additionally it supports ColdFire instructions as described in Motorola's ColdFire Microprocessor Family Programmer's Reference Manual. The syntax for the scale factor in ColdFire @code{MAC} instructions is @code{<<} for left- and @code{>>} for right-shift. The scale factor may be appended as an optional operand, when needed. Example: @code{mac d0.l,d1.u,<<}. The mask flag in @code{MAC} instructions is written as @code{&} and is appended directly to the effective address operand. Example: @code{mac d0,d1,(a0)&,d2}. The target address type is 32bit. Default alignment for instructions is 2 bytes. The default alignment for data is 2 bytes, when the data size is larger than 8 bits. Depending on the selected cpu type the @code{__VASM} symbol will have a value defined by the following bits: @table @code @item bit 0 MC68000 instruction set. Also used by MC6830x, MC68322, MC68356. @item bit 1 MC68010 instruction set. @item bit 2 MC68020 instruction set. @item bit 3 MC68030 instruction set. @item bit 4 MC68040 instruction set. @item bit 5 MC68060 instruction set. @item bit 6 MC68881 or MC68882 FPU. @item bit 7 MC68851 PMMU. @item bit 8 CPU32. Any MC6833x or MC6834x CPU. @item bit 9 ColdFire ISA_A. @item bit 10 ColdFire ISA_A+. @item bit 11 ColdFire ISA_B. @item bit 12 ColdFire ISA_C. @item bit 13 ColdFire hardware division support. @item bit 14 ColdFire MAC instructions. @item bit 15 ColdFire enhanced MAC instructions. @item bit 16 ColdFire USP register. @item bit 17 ColdFire FPU instructions. @item bit 18 ColdFire MMU instructions. @item bit 20 Apollo Core AC68080 instruction set. @end table @section Extensions This backend extends the selected syntax module by the following directives: @table @code @item .sdreg Equivalents to @code{near }. @item basereg , Starts a block of base-relative addressing through register @code{An} (remember that @code{A7} is not allowed as a base register). The programmer has to make sure that is placed into @code{An} first, while the assembler automatically subtracts , which is usually a program label with an optional offset, from each displacement in a @code{(d,An)} addressing mode. @code{basereg} has priority over the @code{near} directive. Its effect can be suspended with the @code{endb} directive. It is allowed to use several base registers in parallel. @item cpu32 Generate code for the CPU32 family. @item endb Ends a @code{basereg} block and suspends its effect onto the specified base register @code{An}. It may be reused with a different base expression thereafter (refer to @code{basereg}). @item far Disables small data (base-relative) mode. All data references will be absolute. @item fpu Enables 68881/68882 FPU code generation. The is inserted into the FPU instructions to select the correct coprocessor. Note that is always 1 for the on-chip FPUs in the 68040 and 68060. A of zero will disable FPU code generation. @item initnear Initializes the selected small data register. In contrast to PhxAss, where this directive comes from, just a reference to @code{_LinkerDB} is generated, which has to be resolved by a linker. @item machine Makes the assembler generate code for , which can be the following: @code{68000}, @code{68010}, @code{68020}, @code{68030}, @code{68040}, @code{68060}, @code{68080}, @code{68851}, @code{68881}, @code{68882}, @code{cpu32}. And various ColdFire CPUs, starting with @code{5...}. @item mc68000 Generate code for the MC68000 CPU. @item mc68010 Generate code for the MC68010 CPU. @item mc68020 Generate code for the MC68020 CPU. @item mc68030 Generate code for the MC68030 CPU. @item mc68040 Generate code for the MC68040 CPU. @item mc68060 Generate code for the MC68060 CPU. @item ac68080 Generate code for the Apollo Core AC68080 FPGA CPU. @item mcf5... Generate code for a ColdFire CPU. The recognized models are listed in the assembler-options section. @item near [] Enables small data (base-relative) mode and sets the base register to @code{An}. @code{near} without an argument will reactivate a previously defined small data mode, which might have been switched off by a @code{far} directive. @item near code All @code{JMP} and @code{JSR} instructions to external labels will be converted into 16-bit PC-relative jumps. The small code mode can be switched off by a @code{far} directive. @item opt