imagecraft compiler migration guide - cypress … · failure may reasonably be expected to result...

32
ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. ** Cypress Semiconductor 198 Champion Court San Jose, CA 95134-1709 Phone (USA): 800.858.1810 Phone (Intnl): 408.943.2600 http://www.cypress.com

Upload: buidien

Post on 01-Sep-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Cypress Semiconductor 198 Champion Court

San Jose, CA 95134-1709 Phone (USA): 800.858.1810 Phone (Intnl): 408.943.2600

http://www.cypress.com

Page 2: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Copyrights

Copyright © 2009 Cypress Semiconductor Corporation. All rights reserved.

Programmable System on a Chip, PSoC Designer, and PSoC Express are trademarks, and PSoC is a registered trademark of Cypress Semiconductor Corporation (Cypress), along with Cypress® and Cypress Semiconductor™. All other trademarks or registered trademarks referenced herein are the property of their respective owners.

The information in this document is subject to change without notice and should not be construed as a commitment by Cypress. While reasonable precautions have been taken, Cypress assumes no responsibility for any errors that may appear in this document. No part of this document may be copied or reproduced in any form or by any means without the prior written consent of Cypress. Made in the U.S.A.

This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source Code except as specified above is prohibited without the express written permission of Cypress.

Disclaimer

CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress’ product in a life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges.

Flash Code Protection

Cypress products meet the specifications contained in their particular Cypress PSoC Data Sheets. Cypress believes that its family of PSoC products is one of the most secure families of its kind on the market today, regardless of how they are used. There may be methods, unknown to Cypress, that can breach the code protection features. Any of these methods, to our knowledge, would be dishonest and possibly illegal. Neither Cypress nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as "unbreakable."

Cypress is willing to work with the customer who is concerned about the integrity of their code. Code protection is constantly evolving. We at Cypress are committed to continuously improving the code protection features of our products.

1 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 3: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Contents

2 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Introduction ...................................................................................................................................................4 Installation .....................................................................................................................................................5

What to Install .........................................................................................................................................5 Selecting the ImageCraft Compiler for Projects in PSoC Designer .......................................................5

PSoC Designer GUI & Content.....................................................................................................................6 Compiler & Linker Options......................................................................................................................6 Boot Templates ......................................................................................................................................7 User Modules .........................................................................................................................................8 System Level Drivers..............................................................................................................................8

Assembly Language Migration......................................................................................................................9 Arithmetic................................................................................................................................................9 Constants................................................................................................................................................9 Operators................................................................................................................................................9 Assembler Directives............................................................................................................................11 Labels ...................................................................................................................................................15 C Pre-Processor ...................................................................................................................................15 C Language Interface ...........................................................................................................................15

Data Types.....................................................................................................................................15 Function Parameter/Return Interface ............................................................................................15 RAM Paging Mode/Indexed RAM Addressing Mode.....................................................................16

C Migration..................................................................................................................................................17 Preprocessor Directives .......................................................................................................................17 Predefined Macros ...............................................................................................................................17 Compiler Directives ..............................................................................................................................18

#asm, #endasm..............................................................................................................................18 #pragma .........................................................................................................................................18

Data ......................................................................................................................................................18 Data Types.....................................................................................................................................18 Data Qualifiers ...............................................................................................................................19 Constant Data ................................................................................................................................19 Expression Evaluation ...................................................................................................................20

Functions ..............................................................................................................................................21 Fastcall16.......................................................................................................................................21 Absolute Location of Entry Points ..................................................................................................21 Interrupt Service Routines .............................................................................................................21 C Library Functions........................................................................................................................22

Assembly Language Interface..............................................................................................................22 Linker Migration...........................................................................................................................................23

Customization.......................................................................................................................................23 Default Location of Relocatable Code..................................................................................................23 Map & List Files ....................................................................................................................................23

Page 4: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Contents

3 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Miscellaneous .............................................................................................................................................24 Optimizations........................................................................................................................................24 Code Size Reporting ............................................................................................................................24

Appendix 1: Assembler Command Line .....................................................................................................25 Executables ..........................................................................................................................................25 Command Line Options........................................................................................................................25

Appendix 2: C Compiler Command Line ....................................................................................................27 Executables ..........................................................................................................................................27 Command Line Options........................................................................................................................27

Appendix 3: Linker Command Line.............................................................................................................30 Executables ..........................................................................................................................................30 Command Line Options........................................................................................................................30

Page 5: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Introduction The HI-TECH Lite for PSoC C compiler is no longer provided as a free C compiler in PSoC Designer 5.0 SP4.5. In its place a free ImageCraft C compiler is provided. PSoC Designer continues to provide support for the HI-TECH PRO for PSoC C compiler.

If you formerly used the HI-TECH Lite for PSoC C compiler or HI-TECH PRO for PSoC C compiler, and you wish to migrate your project to ImageCraft, there are some changes that you will need to make to successfully transition your code base to the new compiler. This manual details those changes and discusses the basic differences between the two compilers.

When feasible, guidance is provided to make source code compatible with both compilers.

4 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 6: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Installation What to Install

A PSoC Designer 5.0 SP4.5 installation provides all the support necessary to use the free ImageCraft C compiler. The PSoC Designer 5.0 SP4.5 installer is available via web download at http://www.cypress.com/psocdesigner. Prerequisites for installation are listed in the PSoC Designer 5.0 SP4.5 release notes also available on the same web page.

Selecting the ImageCraft Compiler for Projects in PSoC Designer

There are two ways in which you can specify a compiler selection in PSoC Designer.

1. You can select the ImageCraft compiler as the default compiler for new projects a. From the Tools menu, select Options. b. Select the Compiler tab. c. Select ImageCraft from the list of available compilers.

2. Or you can select the ImageCraft compiler as the compiler for a specific project. This step is required for selecting the ImageCraft compiler for existing projects. a. From the Project menu, select Settings. b. Select the Compiler tab. c. Select ImageCraft from the list of available compilers. d. Save the project.

5 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 7: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

PSoC Designer GUI & Content Compiler & Linker Options

When you select the ImageCraft compiler from the Project > Settings menu the options presented are different from the HI-TECH options.

Figure 1. The Project ImageCraft Compiler Settings in PSoC Designer 5.0 SP4.5

Macro defines and Macro undefines work the same for HI-TECH and ImageCraft. Warning level and Optimization settings are present in the HI-TECH options, but not ImageCraft. The ImageCraft compiler settings dialog presents checkboxes for configuring the following

o Optimization of math functions for speed. o Compiler data flow optimization o Usage of the Multiply Accumulator (MAC) o Enabling (RAM) paging (also known as large memory model) and specification of a stack page offset for a

paged application. Modification of the stack page offset may be necessary to enable applications that use most of the available RAM to build successfully. See the Stack and RAM Allocation Differences under C Migration.

o Condensation and Sublimation code compression algorithms The ImageCraft compiler settings dialog does not provide an Options text box.

6 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 8: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

The ImageCraft linker settings dialog enables you to specify a starting address for relocatable code to specify a list of additional object or library modules, and to specify an additional library path.

Figure 2. The Project ImageCraft Linker Settings in PSoC Designer 5.0 SP4.5

Boot Templates

The boot.tpl (which produces boot.asm when the Generate Application command is invoked) contains the boot up sequence for a given part. To provide the best ease of use using either compiler, the boot.tpl contains conditional boot-up sequence code that assembles differently depending on which compiler is selected. This is accomplished through the memory.inc file which is generated at build time. memory.inc contains the following assembly constants to control conditional assembly if you select ImageCraft as the compiler for the project. IMAGECRAFT: equ 1

HITECH: equ 2

TOOLCHAIN: equ IMAGECRAFT

This allows conditional compilation of the generated boot.asm file by using the IF assembler directive, for example: IF (TOOLCHAIN & HITECH)

Nop ; would be executed if HI-TECH were selected

ELSE

Nop ; would be executed if ImageCraft were selected …

ENDIF ; TOOLCHAIN

7 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 9: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

You may include memory.inc in your own assembly files and write conditional assembly code to facilitate porting between compilers.

User Modules

All user modules support the ImageCraft C compiler.

System Level Drivers

All system level drivers support the ImageCraft C compiler.

8 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 10: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Assembly Language Migration Arithmetic

The ImageCraft assembler performs integer calculations using 16-bit math whereas the HI-TECH assembler uses 32-bit math. ImageCraft assembler calculations depending on values that cannot fit within 16 bits will produce unexpected results. When porting a HI-TECH assembler file to ImageCraft, look for these types of operations and make changes to support 16-bit math as needed on a case-by-case basis.

Constants

The ImageCraft assembler numeric constant format support differs from HI-TECH assembler constant format support. The following table recommends replacement formats that are supported by both assemblers.

Radix HI-TECH Format Regular Expression

Example Recommended Replacement Format Regular Expression

Example

0b111 Binary [01]+B 111B 0[Bb][01]+ 0B111

765o

765O

765q

Octal [0-7]+[oOqQ]

765Q

0[0-7]+ 0765

789d Decimal [0-9]+[dD] 789D

[1-9][0-9] 789

Hexadecimal n/a

Operators

ImageCraft operator support differs from HI-TECH operator support. The following table indicates recommended ImageCraft replacements for HI-TECH operator usages to be compatible with both assemblers.

9 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 11: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Operator HI-TECH Usage ImageCraft Replacement

>, gt (greater than) IF (constex1 > constex2)

…code1

ELSE

…code2

ENDIF

IF (constex1 / (constex2 + 1))

…code1

ELSE

…code2

ENDIF

>=, ge (greater than or equal)

IF (constex1 >= constex2)

…code1

ELSE

…code2

ENDIF

IF (constex1 / constex2)

…code1

ELSE

…code2

ENDIF

<, lt (less than) IF (constex1 < constex2)

…code1

ELSE

…code2

ENDIF

IF (constex2 / (constex1 + 1))

…code1

ELSE

…code2

ENDIF

<, le (less than or equal)

IF (constex1 <= constex2)

…code1

ELSE

…code2

ENDIF

IF (constex2 / constex1)

…code1

ELSE

…code2

ENDIF

=, eq (equal) IF (constex1 = constex2)

…code1

ELSE

…code2

ENDIF

IF (constex1 ^ constex2)

…code2

ELSE

…code1

ENDIF

<>, ne (not equal) IF (constex1 <> constex2)

…code1

ELSE

…code2

ENDIF

IF (constex1 ^ constex2)

…code1

ELSE

…code2

ENDIF

float24 DW float24(7.67) ImageCraft’s assembler does not support the float24 data format and the float24 operator. Make changes to the source file to facilitate migration as necessary on a case-by-case basis.

10 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 12: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Operator HI-TECH Usage ImageCraft Replacement

highword IF (highword const1)

…code1

ELSE

…code2

ENDIF

ImageCraft’s assembler uses 16-bit math only and does not support the highword operator. Make changes to the source file to support 16-bit math as necessary on a case-by-case basis.

mod mov A, constex1 mod constex2 mov A, constex1 % constex2

not mov A, not constex1 mov A, ~constex1

nul IF nul arg1 ImageCraft’s assembler does not support the nul operator. Also, ImageCraft’s assembler requires that all inputs to conditionals have assigned values. Make changes to the source file to facilitate migration as necessary on a case-by-case basis.

shl (shift left) mov A, constex1 shl 1 mov A, constex1 << 1

shr (shift right) mov A, constex1 shr 2 mov A, constex1 >> 2

Assembler Directives

The ImageCraft assembler directive support differs from HI-TECH assembler directive support. The following table indicates recommended Image replacements of HI-TECH directives.

HI-TECH

Directive

HI-TECH Directive Usage ImageCraft Replacement Notes

ALIGN ALIGN constex For code or data in an absolute memory area, the ORG directive could be used to place the next data/code at an appropriate spot.

For code or data in a relative memory area, there is no replacement.

AREA name(RAM, REL, CON)

AREA name(RAM, ABS, OVR)

AREA name(ROM, REL, CON)

AREA AREA name(class, flags)

AREA name(ROM, ABS, OVR)

ImageCraft’s AREA directive does not support the bit, delta, global, limit, local, ovrld, pure, reloc, size, space, and with flags that HI-TECH’s AREA directive provides.

11 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 13: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

HI-TECH

Directive

HI-TECH Directive Usage ImageCraft Replacement Notes

DDW DDW constex1, constex2, etc.

Break the double words into words and use a DW directive: DW constex1MSW, constex1LSW, constex2MSW, constex2LSW, etc.

ELSIF IF (conditionX)

…code1

ELSIF (conditionY)

…code2

ELSE

…code3

ENDIF

IF (conditionX)

…code1

ELSE

IF (conditionY)

…code2

ELSE

…code3

ENDIF

ENDIF

END END start_label Remove the END directive END is optional in HI-TECH.

GLOBAL GLOBAL label1, label2, etc.

EXPORT label1, label2, etc.

This directive is identical to the EXPORT directive.

IRP IRP paramname, const1, const2, etc.

…code referencing ‘paramname’

ENDM

Replace with an equivalent of the expanded code.

IRPC IRPC paramname, stringconst

…code referencing ‘char’

ENDM

Replace with an equivalent of the code expansion.

LOCAL MACRO …

…code

LOCAL label

label:

…code

ENDM

MACRO …

…code

.label:

…code

ENDM

ImageCraft automatically treats labels specified as local with the period (.) within a macro as local to each applicable macro expansion.

MACRO name MACRO paramlist MACRO name (paramlist)

Both compilers support syntax specifying the MACRO directive first.

12 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 14: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

HI-TECH

Directive

HI-TECH Directive Usage ImageCraft Replacement Notes

OPT COND OPT COND

OPT EXPAND OPT EXPAND

OPT LIST OPT LIST options

OPT NOCOND OPT NOCOND

OPT NOEXPAND

OPT NOEXPAND

OPT NOLIST OPT NOLIST

OPT NOXREF OPT NOXREF

OPT PAGE OPT PAGE

OPT SPACE OPT SPACE numlines

OPT SUBTITLE

OPT SUBTITLE “subtitle”

OPT TITLE OPT TITLE “title”

OPT XREF OPT XREF

At the top of the file: INCLUDE “memory.inc”

At the location of the OPT xxx directive: IF (TOOLCHAIN & HITECH)

OPT xxx

ENDIF

Alternatively, remove the OPT xxx directive.

OPT INCLUDE OPT INCLUDE “filename”

INCLUDE “filename” ImageCraft uses the INCLUDE directive instead of the OPT INCLUDE directive

ORG ORG absconstex1 ORG absconstex2 ImageCraft’s ORG directive sets the location counter relative to address zero whereas HI-TECH’s ORG directive sets the location counter relative to the active PSECT/AREA start address. To facilitate porting, the ORG directive’s constant expression may need to be adjusted depending on the start address of the HI-TECH PSECT/ AREA.

13 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 15: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

HI-TECH

Directive

HI-TECH Directive Usage ImageCraft Replacement Notes

PROCESSOR PROCESSOR chipspec At the top of the file: INCLUDE “memory.inc”

At the location of the PROCESSOR directive: IF (TOOLCHAIN & HITECH)

PROCESSOR chipspec

ENDIF

Alternatively, remove the PROCESSOR directive. Command line options can be used if a return to HI-TECH is needed.

AREA name(RAM, REL, CON)

AREA name(RAM, ABS, OVR)

AREA name(ROM, REL, CON)

PSECT PSECT name, flags

AREA name(ROM, ABS, OVR)

REPT REPT const

…code

ENDM

…code

repeated const times.

Alternatively, define a named macro, and execute the named macro const times.

SET label: SET constex label: EQU constex ImageCraft uses EQU to redefine constant values whereas HI-TECH uses SET to redefine constant values.

14 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 16: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

HI-TECH

Directive

HI-TECH Directive Usage ImageCraft Replacement Notes

SIGNAT SIGNAT label, constex At the top of the file: INCLUDE “memory.inc”

At the location of the SIGNAT directive: IF (TOOLCHAIN & HITECH)

SIGNAT label, constex

ENDIF

Alternatively, remove the SIGNAT directive.

Labels

The ImageCraft assembler does not support the usage of the question mark (?) in labels. Removing question marks or replacing them with alpha-numeric characters or underscores (_) is recommended.

C Pre-Processor

The HI-TECH compiler driver enables execution of the C pre-processor on assembly language files by using the CPSoC –P command line option. Therefore, HI-TECH project assembly files may contain C pre-processor directives and/or C style comments enclosed in /* and */. ImageCraft does not support C pre-processor directives in assembly files. Remove all C pre-processor directives and replace C style comments with assembly or C++ style equivalents (line comments starting with ; or with //).

C Language Interface

Data Types

The HI-TECH float data type consumes 24 bits. Also, the HI-TECH double data type can optionally be configured to consume 24 or 32 bits. The ImageCraft float and double data types always consume 32 bits. Assembly language code sharing float and double data with C must be adjusted to comprehend these differences.

HI-TECH allocates 1 or 2 bytes of space for pointer variables depending on each variable’s usage context. In some HI-TECH 2-byte pointer allocation cases, the setting of the most significant bit defines whether the pointer refers to RAM or Flash data space. The ImageCraft implementation always allocates 2 bytes of space for pointer variables. ImageCraft generated code strictly interprets the pointer data type declaration to determine which data space to access. Assembly language code sharing pointer data with C must be adjusted to comprehend these differences.

Function Parameter/Return Interface

HI-TECH fastcall16 function call/return convention matches ImageCraft fastcall16 function call/return convention. The #pragma fastcall16 funcname directive specifies to the compiler that the named function conforms to the fastcall16 calling convention.

15 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 17: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

If a function is not specified to conform to the fastcall16 convention, HI-TECH’s function call/return convention differs from ImageCraft’s convention. Whereas the HI-TECH compiler uses the A register and a compiled stack (fixed RAM locations for each parameter) to pass parameters, the ImageCraft compiler pass all parameters through the hardware stack (pointed to by SP). ImageCraft’s stack parameter passing convention pushes all function parameters onto the stack in reverse order of each function prototype specification (last parameter pushed on first; first parameter pushed onto the stack last).

The HI-TECH reentrant keyword enforces the convention of passing parameters through the hardware stack. ImageCraft does not support the reentrant keyword. However, the default ImageCraft function passing convention matches the HI-TECH reentrant convention. This keyword can be removed from function declarations.

RAM Paging Mode/Indexed RAM Addressing Mode

For large memory model programs, the HI-TECH compiler sets the M8C F register paging mode bits so that instructions using the indexed RAM addressing mode (ex. mov A, [X + offset]) access the index page (referenced by the IDX_PP register). The ImageCraft compiler sets the M8C F register paging mode bits so that instructions using the indexed RAM addressing mode access the stack page (referenced by the STK_PP register).

All assembly code should be evaluated for paging mode assumptions and modified as necessary. Furthermore, assembly functions using the RAM_PROLOGUE & RAM_EPILOGUE macros in memory.inc should be evaluated for the following scenario under ImageCraft usage:

When built with the ImageCraft compiler, a function containing the RAM_PROLOGUE RAM_CLASS_3 macro will change the paging mode so that instructions using the indexed RAM addressing mode access the index page. If that function calls a function containing the RAM_PROLOGUE RAM_CLASS_2 macro (instructions using the indexed RAM addressing mode access the stack page), the RAM_PROLOGUE RAM_CLASS_2 macro will assume that the paging mode is already set for indexed RAM addressing accesses to the stack page. The end result is that the RAM_CLASS_2 function will fail to operate correctly. The solution to this problem is to execute RAM_EPILOGUE RAM_CLASS_3 before the call to the RAM_CLASS_2 function, and execute RAM_PROLOGUE RAM_CLASS_3 upon return to change back to the desired paging mode of the RAM_CLASS_3 function.

16 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 18: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

C Migration Refer to the ImageCraft C Compiler User’s Guide for more detail on features listed below that affect project migration.

Preprocessor Directives

ImageCraft C preprocessor directive support differs from HI-TECH operator support. The following table indicates recommended ImageCraft replacements for HI-TECH C preprocessor directive usages to be compatible with both compilers.

HI-TECH Directive ImageCraft Replacement #assert condition #if condition

#error

#endif

#nn

Where nn is a number

#line nn

Predefined Macros

ImageCraft does not provide any of HI-TECH’s predefined macros. The following table recommends actions to take based on usage of each predefined macro.

HI-TECH Predefined Macro

Recommended Action for ImageCraft Compilation

HI_TECH_C

_HTC_VER_MAJOR

_HTC_VER_MINOR

_HTC_VER_PATCH

__HCPSOC__

_OMNI_CODE_

__FILE__

__LINE__

Retain usages of these macros that are enclosed within blocks conditionally included only when the HI-TECH compiler is doing the build.

For other usages, remove dependencies on these macros.

_PSOC_

_chipname

__DATE__

__TIME__

Alternative 1: Predefine these macros on the command line or in the PSoC Designer Project Settings dialog.

Alternative 2: Retain usages of these macros that are enclosed within blocks conditionally included only when the HI-TECH compiler is doing the build. For other usages, remove dependencies on these macros.

17 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 19: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Compiler Directives

#asm, #endasm

The ImageCraft compiler does not support the HI-TECH #asm and #endasm directives. Replace blocks enclosed within these directives with corresponding asm(“instruction”) statements.

#pragma

Change HI-TECH #pragma psect text=areaname directives to #pragma text:areaname directives for ImageCraft compilation.

The ImageCraft compiler does not support the following HI-TECH #pragma directives

#pragma inline

#pragma jis

#pragma nojis

#pragma pack

#pragma printf_check

#pragma regused

#pragma switch

Remove these and dependencies on them from your code or place these #pragma directives and their dependent code in conditional blocks. For example:

#ifdef HI_TECH_C

#pragma pack

#endif

Data

Stack and RAM Allocation Differences

By default, the HI-TECH compiler allocates function parameters and local variables on a compiled stack whereas the ImageCraft Compiler allocates these variables on the hardware stack. Under typical conditions, these differences are not critical to successfully building a HI-TECH project with ImageCraft. However, paged (also known as large memory model) applications that use most of the available RAM may fail to build in ImageCraft, and the following error message may be generated.

Cannot allocate space for paged area 'xxxxxxxxxxxxx'

In these cases, increasing the Stack page offset in the Project Settings dialog’s Compiler screen, which decreases the hardware stack size while making more RAM available for other data, can enable a successful build.

Data Types

The HI-TECH float data type consumes 24 bits. The ImageCraft float data type consumes 32 bits. The HI-TECH double data type can optionally be configured to consume 24 or 32 bits. The ImageCraft double data type always consumes 32 bits. These differences may have an impact on code performance.

18 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 20: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

ImageCraft does not support the HI-TECH bit data type. Change a bit variable declaration to unsigned char (or BYTE if including m8c.h) for ImageCraft compilation.

ImageCraft does not support the short long and unsigned short long data types. Change declarations containing these types to long and unsigned long respectively for ImageCraft compilation.

Data Qualifiers

The ImageCraft compiler does not support the HI-TECH persistent keyword. A work around is to create a pointer reference to an absolute RAM address that is NOT allocated by the compiler. For example, a BYTE variable equivalent could be created and used as follows.

#define persistentvarname (* (BYTE *) address)

othervar = persistentvarname;

Alternatively for the variable to be relocatable, the variable may be allocated in an assembly file and accessed in C as follows for a persistent BYTE variable equivalent.

Assembly File export _persistentvarname

AREA persistentvars(RAM, REL, CON)

_persistentvarname:

blk 1

C File extern BYTE varname;

othervar = persistentvarname;

The ImageCraft compiler does not support the HI-TECH __ioport keyword. Change declarations of the type

volatile unsigned int __ioport ioregname;

to #pragma ioport ioregname:ioaddress

BYTE ioregname; // Assumes m8c.h included

Typecasting of Pointers to Constants

Both the HI-TECH and ImageCraft compilers use the const keyword to specify the storage location of a value to be in Flash. This behavior is an extension to the const keyword, whose ANSI usage is to indicate that the value remains constant. Likewise, the const keyword is used in a pointer variable declaration to indicate that the pointer points to a value stored in Flash.

In a statement assigning a value to a pointer to a constant in Flash, the HI-TECH compiler allows the value to be typecast to the corresponding pointer type without using the const keyword whereas the ImageCraft compiler requires the typecast to include the const keyword. The HI-TECH compiler will successfully build the following code, but the ImageCraft compiler will fail to build it.

const char * ptr;

19 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 21: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

void func()

{

ptr = (char *) address;

}

To successfully build the code in ImageCraft, change the typecast as indicated below. …

const char * ptr;

void func()

{

ptr = (const char *) address;

}

Absolute Location of Constant Data

The HI-TECH compiler provides the following syntax option to specify a constant stored in Flash at an absolute address.

const type varname @ address = value;

ImageCraft constant data is specified as follows. #pragma abs_address:address

const type varname = value;

#pragma end_abs_address

Expression Evaluation

HI-TECH automatically promotes data to a larger data type whereas ImageCraft does not. This difference in integer promotion causes the following code to execute differently for an ImageCraft compilation vs. a HI-TECH compilation.

void main(void)

{

BYTE a;

BYTE b;

a = 40;

b = 0;

if (b – a > 10)

{

b = 10;

20 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 22: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

}

else

{

b = 5;

}

}

When compiled with HI-TECH, the values are promoted to signed 16-bit integers, so (b – a) evaluates to -40 and the end result is that b is set to 5. When compiled with ImageCraft, these values are treated as unsigned 8-bit values (as the BYTE type specifies), so (b – a) evaluates to 226, and the end result is that b is set to 10.

Functions

ImageCraft does not support the HI-TECH reentrant keyword, which forces function parameters to be passed via the hardware stack. However, ImageCraft inherently passes function parameters via the hardware stack. Remove the reentrant keyword from function declarations.

Fastcall16

HI-TECH provides the following syntax option for declaring a function using the fastcall16 calling convention.

type __fastcall16 funcname(parameterlist);

ImageCraft’s syntax for fastcall16 calling convention is #pragma fastcall16 funcname

type funcname(parameterlist);

Absolute Location of Entry Points

HI-TECH provides the following syntax option for placing a function entry point at an absolute address. type funcname(parameterlist) @ address {

…code }

ImageCraft’s syntax for placing a function entry point is #pragma abs_address:address

type funcname(parameterlist) {

…code }

#pragma end_abs_address

Interrupt Service Routines

To define an interrupt service routine, HI-TECH requires the interrupt (or __interrupt) keyword in the following declaration syntax.

void interrupt isr_name() @ interrupt_num

21 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 23: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

{

…code

}

To define an interrupt service routine, ImageCraft requires the following declaration syntax. #pragma interrupt_handler isr_name

void isr_name()

{

…code

}

If the interrupt service routine entry point will be accessed from multiple source files, it is recommended that the #pragma interrupt_handler statement be placed in a header file included by each source file.

C Library Functions

ImageCraft does not provide the C stdio.h library. Remove calls to stdio.h functions from your code or place the calls in conditional blocks. For example:

#ifdef HI_TECH_C

#include <stdio.h>

#endif

#ifdef HI_TECH_C

printf(“Hello world”);

#endif

Assembly Language Interface

See C Language Interface in the Assembly Language Migration section.

22 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 24: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Linker Migration Refer to the ImageCraft C Compiler User’s Guide for more detail on features listed below that affect project migration.

Customization

In addition to usage on the command line, HI-TECH linker command line options and file list can be placed inside a text file with a user specified name. The linker is then invoked with the command line

HLINK @filename

ImageCraft linker command line options and file list can also be placed inside a text file. However, this file must be named custom.lkp.

Default Location of Relocatable Code

The ImageCraft linker creates the executable image differently than HI-TECH. Whereas the HI-TECH linker generally places relocatable code toward the end of the image, the ImageCraft linker places relocatable code towards the front of the image. This can have impacts on custom assembly code where jmp is used if the code is now far enough away from the target that an ljmp must be used.

Map & List Files

The ImageCraft map and list file formats differ from the HI-TECH map and list file formats.

23 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 25: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Miscellaneous Optimizations

When optimizations are enabled, the HI-TECH toolchain can optimize assembly source code and generate executable output optimized for size automatically. The ImageCraft tool chains code compression algorithms require some assistance via source code directives. The AREA, .section, .endsection, .literal, .endliteral, directives and OR F, 0 and ADD SP,0 instructions in assembly source files and #pragma text directive in C source files affect operation of code compression in addition to the selection of which algorithms to use (condensation and sublimation are available). Refer to the ImageCraft assembler user’s guide and C compiler user’s guide for more information.

Code Size Reporting

The format of ImageCraft memory usage reports differs from the format of HI-TECH memory usage reports. Also, ImageCraft reports memory usage without including absolute areas.

24 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 26: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Appendix 1: Assembler Command Line Executables

The HI-TECH assembler filename is ASPSOC.exe. The general command-line syntax for the HI-TECH assembler is:

ASPSOC [options] files

The HI-TECH compiler driver CPSOC can also oversee assembly. See Command Line in the Compiler Migration section.

The ImageCraft compiler driver, iccm8c.exe invokes the assembler. The general command-line syntax for the compiler driver is:

iccm8c [options] files

Command Line Options

ImageCraft and HI-TECH assembler command line options differ significantly. The table below maps HI-TECH assembler command line options to corresponding ImageCraft compiler driver command line options.

HI-TECH Command Line Option

Corresponding ImageCraft Command Line Option

Notes

-A None ImageCraft produces only object files (-c option), library files, and/or an executable file.

-C None

-Cchipinfo None

-E[file|length] Redirect stderr to a file.

iccm8c [options] files 2> errorfilename

-Flength None

-H None

-L[listfile] None

-O None ImageCraft does not perform assembly source level optimizations.

-Ooutfile -o filename

-Pprocessor None

-Twidth None

-V None

-Wlevel None

-X None

25 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 27: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

26 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 28: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Appendix 2: C Compiler Command Line Executables

The HI-TECH compiler driver, CPSOC.exe, invokes the compiler and linker. The command-line syntax for the HI-TECH compiler driver is:

CPSOC [options] files [libraries]

The ImageCraft compiler driver, iccm8c.exe, invokes the compiler and linker. The command-line syntax for the ImageCraft compiler driver is:

iccm8c [options] files

Command Line Options

ImageCraft and HI-TECH compiler driver command line options differ significantly. The table below maps HI-TECH compiler driver command line options to corresponding ImageCraft compiler driver command line options.

HI-TECH Command Line Option

ImageCraft Replacement Notes

-C -c

-Dmacro -Wp-Dmacro

-E+file Redirect stderr to a file.

iccm8c [options] files 2> errorfilename

-Gfile -Wf-g

-Wl-g

These options are not equivalent. Refer to the user’s guides for more information.

-Ipath -Wp-Ipath

-Llibrary -Wl-Ldir

-Wl-llibrary

-L-option -Wl-option

-Mfile -Wl-m

-Nsize None ImageCraft identifier maximum length is fixed.

-Ofile -o file

-P None

-Q None

-S -Wf-l These options are not equivalent. Refer to the user’s guides for more information.

27 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 29: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

HI-TECH Command Line Option

ImageCraft Replacement Notes

-Usymbol -Wp-Usymbol

-V -v Output may differ between compilers.

-X None

--ASMLIST -Wf-l

--AUTOBANK None

--CHAR=type None

--CHECKSUM=start-end@destination <,specs>

None

--CHIP=processor None

--CHIPINFO None

--CR=file None

--DOUBLE=type None The ImageCraft double data type always consumes 32 bits.

--ERRFORMAT<=format> None

--ERRORS=numbers None

--FILL=opcode None

--GETOPTION=app, file None

--HELP<=option> None

--IDE=ide None

--LANG=language None

--MAC=number Use #pragma usemac and/or #pragma nomac in C source code files or specify usage of a MAC using the PSoC Designer Project Settings dialog.

These options are not equivalent. Refer to the user’s guides for more information.

--MEMMAP=mapfile None

--MSGFORMAT=format None

--MSGDISABLE None

--NODEL None

--NOEXEC None

--OBJDIR None

--OPT<=type> -Wf-Osize

-Wl-O

These options are not equivalent. Refer to the user’s guides for more information.

--OUTDIR=path None

28 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 30: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

HI-TECH Command Line Option

ImageCraft Replacement Notes

--OUTPUT=type -Wl-ftype Output formats available to the HI-TECH –OUTPUT option are not necessarily available to the ImageCraft –Wl-f option. Also, the same output format options have different type parameter values. Refer to the user’s guides for more information.

--PASS1 None

--PRE None

--PROTO None

--RAM=lo-hi<,lo-hi, …> None

--RENTRANT None

--ROM=lo-hi<, lo-hi, …> | tag

None

--RUNTIME=type Modify the project boot.tpl file to make changes to the ImageCraft runtime environment initialization.

The ImageCraft runtime environment is initialized by the PSoC Designer project boot.asm file, which is generated from the project boot.tpl file.

--SCANDEP None

--SERIAL=hexcode@address None

--SETOPTION=app, file None

--SETUP=argument None

--STRICT -Wf-A -A ImageCraft also allows –Wf-A which turns on some ANSI checking.

--SUMMARY=type None

--TIME None

--VER None

--WARN=level None

--WARNFORMAT=format None

--WDT=period None

29 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 31: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

Appendix 3: Linker Command Line Executables

The HI-TECH linker filename is hlink.exe. The general command-line syntax for the HI-TECH linker is:

HLINK [options] files

The HI-TECH compiler driver CPSOC can also oversee linking. See Command Line in the Compiler Migration section.

The ImageCraft compiler driver, iccm8c.exe invokes the linker. The general command-line syntax for the compiler driver is:

iccm8c [options] files

Command Line Options

ImageCraft and HI-TECH linker command line options differ significantly. The table below maps HI-TECH linker command line options to corresponding ImageCraft compiler driver command line options.

HI-TECH Command Line Option

Corresponding ImageCraft Command Line Option

Notes

-8 None

-Aclass=low-high None See also –Pspec.

-Cx None

-Cpsect=class None

-Dclass=delta None

-Dsymfile -Wl-g These options are not equivalent. Refer to the user guides for more information.

-Eerrfile Redirect stderr to a file.

iccm8c [options] files 2> errorfilename

-F None

-Gspec None

-Hsymfile -Wl-g These options are not equivalent. Refer to the user guides for more information.

-H+symfile -Wl-g These options are not equivalent. Refer to the user guides for more information.

-I None

30 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

Page 32: ImageCraft Compiler Migration Guide - Cypress … · failure may reasonably be expected to result in significant injury to ... Expression Evaluation ... 7 ImageCraft Compiler Migration

31 ImageCraft Compiler Migration Guide Document Number 001-53089 Rev. **

HI-TECH Command Line Option

Corresponding ImageCraft Command Line Option

Notes

-Jnum None

-K None

-L None

-LM None

-N None

-Nc None

-Ns None

-Mmapfile -Wl-m

-Ooutfile -o filename

-Pspec -bareaname:address range

-dram_end:address

-Bareaname:page

See user’s guides for more info.

-Qprocessor None

-S None

-Sclass=limit[,bound] None See also –Pspec.

-Usymbol None

-Vavmap None

-Wwarnlev None

-Wwidth None

-X None

-Z None