Preface

This document contains useful information for embedded software developers who wish to migrate their code from IAR tools to CyberTHOR Studios GNU tools (and vice versa) for M16C Architecture targets. At present, this guide contains the following:


   Compiler Options
   Compiler Directives
   Extended Keywords
   Intrinsic Functions
   Assembler Options
   Assembler Directives
   Calling Convention
   C/Math Library Functions
   Startup Routine
   Vector Table
  I/O files examples

Revision History:

Version Number Date Overview of changes
1.0 21-December-2007 Created.
2.0 01-October-2008 Reference links provided in tables are removed. Reference link to gcc and as manuals are provided below the tables.
3.0 20-October-2016 Added new responsive template

Please note that this is an intermediate guide, which will be improved and enhanced periodically.

Please do not hesitate to send any of your suggestions or ideas. You may log in your suggestions on our web site https://gcc-renesas.com/.

You will need to register first, after which you can either add a new support query at the following link: https://gcc-renesas.com/my-support-requests/tickettrackingsystem/addticket, or ask a question here: https://gcc-renesas.com/forum/ask/.

Please note that in order to be able to add a new support query or ask a question you must be logged in.

Compiler Options


IAR

GNU

--cpu CPU

M16C/R8C Compiler supported targets are Renesas
M16C/1X, 2X, 3X, 6X, and R8C Series of CPU
Use --cpu and specify M16C or R8C.

-mcpu=m16c
Generates the object code for the M16C (up to /60) series.

-mcpu=r8c
Generates the code for R8C/Tiny Series.

To compile code for the M16C/80 core and M32C, you need the M32C IAR C/C++ Compiler.

-mcpu=m32c
Generates the object code for the M32C/80 series.

-mcpu=m32cm
Generates the object code for the M16C/80 series

In-line assembler

asm("MOV.W R1,R0");
Note: The asm keyword reduces the compiler’s ability to optimize the code. Use  modules written in assembler language instead of inline assembler.

asm(<assembly-language instruction string>);

 

e.g.

asm("MOV.W R1,R0");

With the IAR compiler function and variable names are the same on C and assembler level.

The GNU compiler adds a “_” to C function or variables names if they are referred from assembler level.

--align_func={1|2}

By default, the compiler uses byte alignment for function entries. Use --align_func=2 to specify word alignment and force the compiler to align all function entries to an even address

-falign-functions
-falign-functions=n


 

--char_is_signed

By default the compiler interprets the char type as unsigned.

-fsigned-char

-fno-unsigned-char
Let the type char be signed, like signed char.

--enable_multibytes

Enables support for multibyte characters

Unicode characters are default supported.

To add the character set "wchar.h" files need to be included passing "-std=c99" command line option.

-y

--low_consts
Copies constants to near RAM

For M16C GNUC always copies constants from ROM to RAM.

For M32C this is not supported.

--strict_ansi
Enables strict ISO/ANSI

-pedantic

Let the type char be signed, like signed char.

-Dsymbol[=value]
The option -D has the same effect as a #define statement at the top of the source file

-D symbol=value
Functionality similar to #define.

--dependencies=[i][m] {filename|directory}
When you use this option, each source file opened by the compiler is listed in a file.
The following modifiers are available:
i -> Include only the names of files (default)
m -> Makefile style
If --dependencies=m is used, the output uses makefile style.

-M
The preprocessor outputs one make rule containing the object file name For that source file.
-MF file
When used with `-M' or `-MM', specifies a file to write the dependencies to.

--diag_error=tag,tag,...
Use this option to classify diagnostic messages as errors. An error indicates a violation of the C or C++ language rules.

-Werror=
Make all warnings into errors.

-f filename
Reads command line options from the named file, with the default extension xcl.

@file
Read command-line options from file. The options read are inserted in place of the original @file option. If file does not exist, or cannot be read, then the option will be treated literally, and not removed.

--header_context
It is necessary to know which header file that was included from what
source line, to find the cause of a problem. Use this option to list, for each diagnostic message, not only the source position of the problem, but also the entire include stack at that point

-Wsystem-headers
Print warning messages for constructs found in system header files.

-Ipath
Includes file path.

-I dir
Add the directory dir to the list of directories to be searched For header files.

-la

Assembler file

-S

The input C source file is compiled only, assembling and linking is not done. The output is in the form of an assembly file.

-lA  (N is implied)

Assembler file with C or C++ source as comments

-Wa,-ah={filename|directory}
include high-level source

-laN

Assembler file without diagnostics in file.

-Wa,-ad={filename|directory}
omit debugging directives

--no_cse
Use --no_cse to disable common sub-expression elimination.

-fno-gcse
Disable the global common sub-expression elimination.

--no_inline
Use –no_inline to disable function inlining.

-fno-inline
Don't pay attention to the inline keyword.

--no_tbaa

Use --no_tbaa to disable type-based alias analysis.

When this option is not used, the

compiler is free to assume that objects are only accessed through the declared type or

through unsigned char.

may_alias

Accesses to objects with types are not subjected to type-based alias analysis, but are instead assumed to be able to alias any other type of objects, just like the char type.

--no_unroll
Use this option to disable loop unrolling.

-fno-unroll-loops 

-fno-unroll-all-loops  

--no_warnings
By default the compiler issues standard warning messages. use this option to disable all warning messages.

By default all the warnings are disabled.

 

-Wall enables the warning for normal code.

-o {filename|directory}
Use the -o option to specify an output file.

-o file
Place output in file file.

--preprocess=c

Preserve comments

-C
Do not discard comments. All comments are passed through to the output file, except for comments in processed directives, which are deleted along with the directive.

--preprocess=n

Preprocess only

-E
Option, nothing is done except preprocessing.

--preprocess=l

Generate #line directives

-P
Inhibit generation of linemarkers in the output from the preprocessor. This might be useful when running the preprocessor on something that is not C code, and will be sent to a program which might be confused by the linemarkers.

--code_segment=name
-Rname

Place executable code in name.

void foobar (void) __attribute__ ((section ("bar")));
puts the function foobar in the bar section.

-r

--debug
Use the --debug or the -r option to make the compiler include information for supported debuggers.

-g
Produce debugging information for supported debuggers.

--require_prototypes
This option forces the compiler to verify that all functions have proper prototypes.
The following will generate an error:

 

§         A function definition of a public function with no previous prototype declaration

  • A function call with no declaration or a K&R C declaration.
  • An indirect function call through a function pointer with a type that does not include a prototype.

Not supported

 

But some of the related optioned are:

-Wstrict-prototypes (C only)

Warn if a function is declared or defined without specifying the argument types.

-Wmissing-prototypes (C only)

Warn if a global function is defined without a previous prototype declaration.

-Wdeclaration-after-statement (C only)
Warn when a declaration is found after a statement in a block.

-s[2|3|6|9|debug|low|medium|high]
Use this option to make the compiler optimize the code for maximum execution speed.
2, debug Debug*

3, low Low*

6, medium Medium

 

-z[2|3|6|9|debug|low|medium|high]
Use this option to make the compiler optimize the code for minimum size.

-O[1-3]
Optimise for execution speed.

1 – Optimise  for size and speed.

2 – Better optimisation, nearly all optimisations not involving space-speed trade off are used.

3 – Maximum optimisation for speed.

 

-z9
Highly opimized on minimum code size.

-Os
Code size optimization.

--strict_ansi
Use --strict_ansi to ensure that the program conforms to the
ISO/ANSI C standard.

-ansi

--align_data={1|2}

-u(1|2)
By default, the compiler uses word alignment for data objects. Use -u1 to specify byte alignment (or -u2 to restore word alignment).

aligned (alignment)
This attribute specifies a minimum alignment (in bytes) for variables of the specified type. For example, the declarations:
  struct S { short f[3]; } __attribute__ ((aligned (8)));
typedef int more_aligned_int __attribute__ ((aligned (8)));

force the compiler to insure (as far as it can) that each variable whose type is struct S or more_aligned_int will be allocated and aligned at least on a 8-byte boundary.

--warnings_are_errors
Use this option to make the compiler treat all warnings as errors.

-Werror
Make all warnings into errors.

-2

--64bit_doubles
Use this option to force the compiler to use 64-bit doubles instead of 32-bit doubles which is the default.

By default 64-bit double. No possibility to use 32-bit double.

--calling_convention={simple| normal}
Specifies the calling convention for functions.

Not supported

--constant_data={near|far|huge}
Specifies an explicit location for constants.

Not supported

But using the "attribute" constant variable can be placed in the named segment, as shown below.

char foo __attribute__ ((section (sectionname)));

--data_model={near|far|huge}
Specifies the data model.

Not supported

 


For more information on the above compiler command line options, please refer to the gcc manual.

Compiler Directives


IAR

GNU

#pragma bitfield
Controls the order of bitfield members

Not supported

#pragma constseg
Places constant variables in a named segment

Not supported
By using the "attribute" constant variable can be placed in the named segment, as shown below.
char foo __attribute__ ((section (sectionname)));

#pragma data_alignment
Gives a variable a higher (more strict) alignment. By default, the compiler uses word alignment for data objects.

Not supported
The "attribute" specifies a minimum alignment (in bytes) for variables of the specified type. For example, the declarations:
  struct S { short f[3]; } __attribute__ ((aligned (8)));
typedef int more_aligned_int __attribute__ ((aligned (8)));

force the compiler to insure (as far as it can) that each variable whose type is struct S or more_aligned_int will be allocated and aligned at least on a 8-byte boundary.

#pragma dataseg
Places variables in a named segment

Not supported
By using the "attribute" variable can be placed in the named segment, as shown below.
char foo __attribute__ ((section (sectionname)));

#pragma inline
Inlines a function

inline void foo (const char) __attribute__((always_inline));

#pragma location
Specifies the absolute address of a variable

Not supported

 

#define <var_name> (*(volatile char foo*) <abs add>)

#pragma optimize
Specifies type and level of optimization

Not supported
But by passing the -O,-O1,-O2,-O & -Os option in the command line optimisation can be achieved.

#pragma pack
Specifies the alignment of structures and union members

struct S { int x[2];} __attribute__ ((packed));

The packed attribute specifies that a variable or structure field should have the smallest possible alignment--one byte for a variable, and one bit for a field, unless you specify a larger value with the aligned attribute.

#pragma segment
Declares a segment name to be used by intrinsic functions

Not supported


Alternative solution can be similar to the statement mentioned below.
char foo __attribute__ ((section (sectionname)));

#pragma type_attribute
Changes the declaration and definitions of a variable or function

Default memory segmentation not supported. Pragma also not supported.

#pragma vector
Specifies the vector of an interrupt or trap function
To define an interrupt function, the __interrupt keyword and the #pragma
vector directive can be used, for example:
#pragma vector=0x09
__interrupt void my_interrupt_routine()
{
/* Do something */
}

interrupt-handling-function-prototype __attribute__((section (".vects")))

To assign a particular vector number to an Interrupt Service Routine (ISR), put a call to that ISR at that particular vector number  location in vector table.

e.g.
#define VECT_SECT __attribute__((section (".vects")))
#define ISR __attribute__ ((interrupt))
typedef void (*function_ptr) (void);
extern void start (void);
void ext_0() ISR;
function_ptr HardwareVectors[] VECT_SECT =
{
start,0,0,0,0,0,0,0,ext_0,0,0,0,0,0,0,0
};

void ext_0()
{
/* Do something */

}


For more information on the above compiler directives, please refer to the gcc manual.

Extended Keywords


IAR

GNU

__bitvar
Control the storage of variables.

Not supported.

__data13

Control the storage of variables. This is a special addressing mode used only for bit variables. Valid for M16C and R8C only.

Not supported.

__data16

Control the storage of variables. Valid for M16C and R8C only.

Not supported

But using the "attribute" constant variable can be placed in the named segment, as shown below.

char foo __attribute__ ((section (sectionname)));

__data20

Control the storage of variables. Valid for M16C only.

Not supported

But using the "attribute" constant variable can be placed in the named segment, as shown below.

char foo __attribute__ ((section (sectionname)));

__far

Control the storage of variables. Stores data in the far area (20 or 24 bitr addressing), but uses only 16-bit for pointer arithmetics.

Not supported

But using the "attribute" constant variable can be placed in the named segment, as shown below.

char foo __attribute__ ((section (sectionname)));

__huge

For M16C alias for __data20

Stores data in the far area (20 or 24 bitr addressing) with full size pointer arithmetics.

Not supported

But using the "attribute" constant variable can be placed in the named segment, as shown below.

char foo __attribute__ ((section (sectionname)));

__near

Alias for __data16

Not supported

But using the "attribute" constant variable can be placed in the named segment, as shown below.

char foo __attribute__ ((section (sectionname)));

__interrupt

Defines interrupt function.

Interrupt

Defines interrupt function.

__intrinsic

Reserved for compiler internal use.

Not supported.

__monitor

Supports atomic execution of a function.

Not supported.

__no_init

Supports non-volatile memory.

Not supported.

__fast_interrupt

Supports interrupt functions using special registers for fast interrupt entry. For M32C only

Not supported.

__regbank_interrupt

Supports interrupt functions using secondary register bank.

Not supported.

__root

Ensures a function or variable is included in the object code even if it is not used.

Not supported.

__simple

Ensures that a simple calling convention is used for a function.

Not supported.

__task

allows functions to exit without restoring registers.

Not supported.

__tiny_func

Specifies the JSRS instruction for function calls.

Not supported.

Intrinsic Functions


Intrinsic functions are a special feature of the IAR compiler and not supported in GNUC.
However, most intrinsic functions can be easily implemented as shown below:

IAR

GNU

__break()
Inserts a BRK instruction

#define __break() asm(“BRK”);

__BTSTS(unsigned char b, unsigned char * a)

Inserts a BTSTS instruction

Not supported.

Needs special variables to be implemented.

__disable_interrupt()
Clears interrupt enable flag.

#define __ disable_interrupt () asm(“FCLR I”);

__enable_interrupt()
Sets interrupt enable flag.

#define __enable_interrupt() asm(“FSET I”);

unsigned short __get_FLG_register()
Reads the value of FLG register

Not supported.

Needs special variables to be implemented.

unsigned char __get_interrupt_level()
Reads the current interrupt level

Not supported.

Needs special variables to be implemented.

__istate_t __read_interrupt_state()
Reads the current interrupt state

Not supported.

Needs special variables to be implemented.

__illegal_opcode()
Inserts an UND instruction

#define __illegal_opcode() asm(“UND”);

__no_operation()
Inserts a NOP instruction

#define __no_operation() asm(“NOP”);

unsigned char __overflow()
Reads the value of overflow flag

Not supported.

Needs special variables to be implemented.

__require(void *)
Ensures the module containing the specified symbol is linked

Not supported.

short __RMPA_B(const signed char *, const signed char *, short, unsigned short)

Inserts an RMPA.B instruction

Not supported.

Needs special variables to be implemented.

__RMPA_B_INTO(const signed char *, const signed char *, short, unsigned short)
Inserts an RMPA.B instruction followed by an INTO instruction

Not supported.

Needs special variables to be implemented.

__RMPA_B_overflow(const signed char *, const signed char *, short, unsigned short)
Inserts an RMPA.B instruction and stores the value of the overflow flag

Not supported.

Needs special variables to be implemented.

__RMPA_W(const signed char *, const signed char *, long, unsigned short)
Inserts an RMPA.W instruction

Not supported.

Needs special variables to be implemented.

__RMPA_W_INTO(const signed char *, const signed char *, long, unsigned short)
Inserts an RMPA.W instruction followed by an INTO instruction

Not supported. Needs special variables to be implemented.

__RMPA_W_overflow(const signed char *, const signed char *, long, unsigned short)
Inserts an RMPA.W instruction and stores the value of the overflow flag

Not supported.

Needs special variables to be implemented.

__segment_begin()
Returns the start address of a segment

Not supported.

__segment_end()
Returns the end address of a segment

Not supported.

__set_FLG_register(unsigned short)
Sets the value of FLG register

Not supported.

Needs special variables to be implemented.

__set_INTB_register(unsigned long)
Sets the value of INTB register

Not supported.

Needs special variables to be implemented.

__set_interrupt_level(unsigned char)
Sets the interrupt level

Not supported.

Needs special variables to be implemented.

__set_interrupt_state(__istate_t)
Restores a previous interrupt state

Not supported.

Needs special variables to be implemented.

__SMOVB_B(char*, const char*, unsigned short)
Inserts a SMOVB.B instruction

Not supported.

Needs special variables to be implemented.

__SMOVB_W(short*, const short*, unsigned short)
Inserts a SMOVB.W instruction

Not supported.

Needs special variables to be implemented.

__SMOVF_B(char*, const char*, unsigned short)
Inserts a SMOVF.B instruction

Not supported.

Needs special variables to be implemented.

__SMOVF_W(short*, const short*, unsigned short)
Inserts a SMOVF.W instruction

Not supported.

Needs special variables to be implemented.

__software_interrupt(unsigned char)
Inserts a INT instruction

Not supported.

Needs special variables to be implemented.

__SSTR_B(char*, const char*, unsigned short)
Inserts a SSTR.B instruction

Not supported.

Needs special variables to be implemented.

__SSTR_W(short*, const short*, unsigned short)
Inserts a SSTR.W instruction

Not supported.

Needs special variables to be implemented.

__wait_for_interrupt()
Inserts a WAIT instruction

#define __wait_for_interrupt() asm(“WAIT”);

Assembler Options


IAR

GNU

-B
Macro execution information

-a[cdhlmns]
Turn on listings, in any of a variety of ways:
 -am
include macro expansions.

-b
Makes a library module

"m32c-elf-ar.exe" utility makes the library module.

-Dsymbol[=value]
Defines a symbol

--defsym sym=value

Define the symbol sym to be value before assembling the input file.

-Enumber
Maximum number of errors

Not supported
But -Z option may be used to generate the output after generating the errors. And final warning message of the form `n errors, m warnings, generating bad object file.' is displayed.

-f filename
Extends the command line

@file
Read command-line options from file

-Iprefix
Includes paths

-I path
Use this option to add a path to the list of directories as searches for files specified in .include directives.

-L[prefix]
Lists to prefixed source name

–a
Generates list file.

-l filename
Lists to named file

–a=file
Generates list file.
=file, set the name of the listing file

-Oprefix
Sets object filename prefix.

Not supported
But using -o option you can specify the directory path and file name.
e.g. m32c-elf-gcc proj.c -o obj\proj.o
it is important to specify the file name in this case. Default file name is not assigned.

-o filename
Sets object filename

-o filename

Sets object filename

-plines
 Lines/page

Not supported.

Can be replaced by assembler directive ”.psize lines , columns” which defines the number of lines and columns (optional) to be printed per page.

Not supported

--listing-cont-lines=number
set the maximum number of lines printed in a listing for a single line of input to number + 1

-r
Generates debug information

-g

Generates debugging information.

For generating dwarf-2 debug information use

-gdwarf-2

 

-S
Set silent operation

Not supported
If you use the `-W' and `--no-warn' options, no warnings are issued, but errors are still reported.

-Usymbol

Undefines a symbol

Not supported.

Can be replaced by assembler directive “.purgem name”, which undefines the macro name.

-w[string][s]
Disables warnings

-W –no_warn

Switch all warnings off.

-x
Generate a cross-reference list

Not supported

 


For more information on the above assembler command line options, please refer to the as manual.

Assembler Directives


IAR

GNU

$

#include

Includes a file.

.include "file"
This directive provides a way to include supporting files at specified points in your source program.

#elif
Introduces a new condition in a #if…#endif block

.elseif

#else
Assembles instructions if a condition is false.

.else

#endif
Ends a #if, #ifdef, or #ifndef block.

.endif

#error
Generates an error.

.err , .error "string"

#if
Assembles instructions if a condition is true.

.if

#ifdef
Assembles instructions if a symbol is defined.

.ifdef

#ifndef
Assembles instructions if a symbol is undefined.

.ifndef symbol

#message
Generates a message on standard output.

Not supported

.err (could be alternative solution)
If as assembles a .err directive, it will print an error message and, unless the `-Z' option was used, it will not generate an object file.

#undef
Undefines a label.

.purgem name
Undefines the macro name.

/*comment */
C-style comment delimiter.

/*comment */

//
C++ style comment delimiter.

line comment character '#' on the m32c

label ALIAS expr
Assigns a permanent value local to a module

To define a local symbol, write a label of the form `N:' (where N represents any positive integer).
Here is an example:
1:        branch 1f
2:        branch 1b
1:        branch 2f
2:        branch 1b

ALIGN align [,value2]
Aligns the location counter by inserting zero-filled bytes.

.align
Pad the location counter (in the current subsection) to a particular storage boundary.

ASEGN segment [:type], address

Begins a named absolute segment

Not supported.

label ASSIGN expr
Assigns a temporary value.

.equ symbol, expression
This directive sets the value of symbol to expression. It is synonymous with `.set'

BLKA
Allocates space for 24-bit data objects.

.comm symbol , length
If .comm does not see a definition for the symbol--just one or more common symbols--then it will allocate length bytes of uninitialized memory.

BLKB
Allocates space for 8-bit data objects.

BLKD
Allocates space for 64-bit data objects.

BLKF
Allocates space for 32-bit data objects.

BLKL
Allocates space for 32-bit data objects.

BLKW
Allocates space for 16-bit data objects.

BYTE
Generates 8-bit byte constants, including strings.

.byte expressions
.byte expects zero or more expressions, separated by commas. Each expression is assembled into the next byte.

COL
Sets the number of columns per page.

.psize lines , columns
Use this directive to declare the number of lines--and, optionally, the number of columns--to use for each page, when generating listings.

DS8
Allocates space for 8-bit data objects.

.comm symbol , length
If ld does not see a definition for the symbol--just one or more common symbols--then it will allocate length bytes of uninitialized memory.

DS16
Allocates space for 16-bit data objects.

DS24
Allocates space for 24-bit data objects.

DS32
Allocates space for 32-bit data objects.

ELSE
Assembles instructions if a condition is false.

.else
.else is part of the as support for conditional assembly

END
Terminates the assembly of the last module in a file.

.end
.end marks the end of the assembly file. as does not process anything in the file past the .end directive.

ENDIF
Ends an IF block.

.endif
.endif is part of the as support for conditional assembly; it marks the end of a block of code that is only assembled conditionally.

ENDM
Ends a macro definition.

.endm
The commands .macro and .endm allow you to define macros that generate assembly output.

label EQU expr
Assigns a permanent value local to a module.

.equ symbol, expression

.set symbol, expression

This directive sets the value of symbol to expression.

EXITM
Exits prematurely from a macro.

.exitm
Exit early from the current macro definition.

EXTERN
Imports an external symbol.

.extern
.extern is accepted in the source program for compatibility with other assemblers, but it is ignored. “as“ treats all undefined symbols as external.

FLOAT
Generates 32-bit floating point constants.

.float flonums

.single flonums
This directive assembles zero or more flonums, separated by commas. The exact kind of floating point numbers emitted depends on how as is configured.

IF
Assembles instructions if a condition is true.

.if absolute expression

LSTCND
Controls conditional assembler listing.

Not supported

Some of the list control directives supported are
.list, .nolist
Control (in conjunction with the .nolist directive) whether or not assembly listings are generated
.line line-number
Change the logical line number. line-number must be an absolute expression.

LSTCOD
Controls multi-line code listing.

LSTEXP
Controls the listing of macro generated lines.

LSTMAC
Controls the listing of macro definitions.

LSTOUT
Controls assembler-listing output.

LSTPAG
Controls the formatting of output into pages.

LSTREP
Controls the listing of lines generated by repeat directives.

LSTXRF
Generates a cross-reference table.

LWORD
Generates 32-bit constants.

.long expressions
.long expects zero or more expressions, separated by commas. For each expression emit a number that is the value of that expression.

MACRO
Defines a macro.

.macro

ORG
Sets the location counter to a new absolute address.

Not supported.

The instruction .org in GNUC sets the address relative to the start of the actual section.

PAGE
Generates a new page.

Not supported
.eject
.eject force a page break at this point, when generating assembly listings.

PAGSIZ
Sets the number of lines per page.

.psize lines , columns
Use this directive to declare the number of lines--and, optionally, the number of columns--to use for each page, when generating listings.

RSEG
Begins a relocatable section.

.section name
Use the .section directive to assemble the following code into a section named name

REPT
Assembles instructions a specified number of times.

.rept count
Repeat the sequence of lines between the .rept directive and the next .endr directive count times.

WORD
Generates 16-bit constants.

.word expressions
.word expects zero or more expressions, separated by commas. For each expression emit a number that is the value of that expression.


For more information on the above assembler directives, please refer to the as manual.

Calling Convention


Rules of Return Value

Values

IAR

GNU

_Boll
Char (QImode)

R0L Register

R0L Register

int
near pointer (HImode)

R0 Register

R0 Register

float
long
far pointer (SImode)

R2R0

LSB (16-bits) R0
MSB (16-bits) R2

Anything bigger than 16 bits is
returned in memory, at mem0
(mem0 through mem15 are
provided by libgcc.a)

double
long double

Pointer to return value in R0 (16-bit address) or R2R0 (32-bit address)

Anything bigger than 16 bits is
returned in memory, at mem0
(mem0 through mem15 are
provided by libgcc.a)

long long

Pointer to return value in R0 (16-bit address) or R2R0 (32-bit address)

Anything bigger than 16 bits is
returned in memory, at mem0
(mem0 through mem15 are
provided by libgcc.a)

Rules of Argument Transfer

Argument

Argument Type

IAR

GNU

Registers Used
(M16C using normal calling convention)

Registers Used

First argument

char type,
_Bool type(QImode)

R0L register
If R0L not empty R0H.

R1L

int type,
near pointer type (HImode)

2 byte pointer parameters in A0 register.
2-byte non-pointer parameters in R0 if no byte-size register candidates are found within the first 6 bytes of parameters; otherwise in R2 if it is vailable or else in A0

R1

4-byte argument

R2R0

On Stack

Second argument

int type
near pointer type

Assign to registers according to above rules as long as registers are available. Otherwise on stack.

R2

All other arguments

Any

Assign to registers according to above rules as long as registers are available. Otherwise on stack.

On Stack

 

Argument

Argument Type

IAR

GNU

Registers Used
(M16C using simple calling convention; M32C)

Registers Used

First argument

1-byte argument

R0L register

R1L

2-byte argument

R0 register

3-byte argument

A0 register

R1

4-byte argument

R2R0 registers

On Stack

Second arguments

int type

near pointer type

On Stack

R2

All other arguments

Any

On Stack

On Stack

C/Math Library Functions

GNU C library namely Newlib is under free software license. The Newlib supports various processors and architectures.

1.    Complete set of Standard input/output functions.
2.    Float parameters support for Math library.
3.    The library can be built with integer only support. This in turn reduces the load.
4.    Option is available to build the libraries with floating point support.
5.    A customizable math error handler matherr() is available.
6.    All the functions are reentrant.

Drawbacks Involved:

1.   malloc() is used in every stdio routine.
2.   There is no support for low-level routines to connect to the target.

C library Math Functions only in Renesas:

No.

Function

General Utilities (stddef.h)

1

Offsetof

C library Math Functions only in GNU:

No.

Function

Description

Character type handling routines (ctype.h)

Please refer the http://sources.redhat.com/newlib/libc.html#SEC35 for more information on these routines.

1

isascii

ASCII character predicate

2

toascii

Control character predicate

3

iswalnum

Alphanumeric wide character test

4

iswalpha

Alphabetic wide character test

5

iswcntrla

Wide character cntrl test

6

iswdigit

Decimal digit wide character test

7

iswgraph

Graphic wide character test

8

iswlower

Lowercase wide character test

9

iswprint

Printable wide character test

10

iswpunct

Punctuation wide character test

11

iswspace

Wide character space test

12

iswupper

Uppercase wide character test

13

iswxdigit

Hexadecimal digit wide character test

14

iswctype

Extensible wide character test

15

wctype

Get wide character classification type

16

*towlower

Translate wide characters to lower case

17

*towupper

Translate wide characters to upper case

18

towctrans

Extensible wide character case mapping

19

wctrans

Get wide character translation type

 

No.

Function

Description

Mathematics Functions (math.h)

Please refer the http://sources.redhat.com/newlib/libm.html#SEC1 for more information on these routines.

1

acosh, acoshf

Inverse hyperbolic cosine

2

asinh, asinhf

Inverse hyperbolic sine

3

atanh, atanhf

Inverse hyperbolic tangent

4

jN,jNf,yN,yNf

Bessel functions

5

erf, erff, erfc, erfcf

Error function

6

gamma, gammaf, lgamma, lgammaf, gamma_r, hypot, hypotf

Distance from origin

7

isnan, isnanf, isinf, isinff, finite, finitef

Test for exceptional numbers

8

remainder, remainderf

Round and remainder

9

cbrt, cbrtf

Cube root

10

copysign, copysignf

Sign of y, magnitude of x

11

expm, expmf

Exponential minus 1

12

ilogb, ilogbf

Get exponent of floating point number

13

infinity, infinityf

Representation of infinity

14

logp, logpf

Log of 1 + x

15

matherr

Modifiable math error handler

16

nan, nanf

Representation of infinity

17

nextafter, nextafterf

Get next number

18

scalbn, scalbnf

Scale by integer

 

No.

Function

Description

General Utilities (stdlib.h)

Please refer the http://sources.redhat.com/newlib/libc.html#SEC1 for more information on these routines.

1

atexit

Request execution of functions at program exit

2

atof

String to double or float

3

ecvt, ecvtf, fcvt, fcvtf

Double or float to string

4

gvcvt, gcvtf

Format double or float as string

5

ecvtbuf, fcvtbuf

Double or float to string

6

__env_lock, __env_unlock

Lock environ variable

7

getenv

Look up environment variable

8

mallinfo, malloc_stats, mallopt

Malloc support

9

__malloc_lock, __malloc_unlock

Lock malloc pool

10

mblen

Minimal multibyte length function

11

mbstowcs

Minimal multibyte string to wide char converter

12

mbtowc

Minimal multibyte to wide char converter

13

rand48, drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48, lcong48

Pseudo random number generators and initialization routines

14

strtof

String to double or float

15

system

Execute command string

16

wcstombs

Minimal wide char string to multibyte string converter

17

wctomb

Minimal wide char to multibyte converter

 

No.

Function

Description

String and Memory routines (string.h)

Please refer the http://sources.redhat.com/newlib/libc.html#SEC109 for more information on these routines.

1

bcmp

Compare two memory areas

2

bcopy

Copy memory regions

3

bzero

Initialize memory to zero

4

index

Search for character in string

5

memccpy

Copy memory regions with end token check

6

mempcpy

Copy memory regions and return end pointer

7

rindex

Reverse search for character in string

8

strcasecmp

Case insensitive character string compare

9

strlwr

Force string to lower case

10

strncasecmp

Case insensitive character string compare

11

strtok_r,strsep

Get next token from a string

12

strupr

Force string to uppercase

13

swab

Swap adjacent bytes

 

No.

Function

Description

Input/output routines (stdio.h)

Please refer the http://sources.redhat.com/newlib/libc.html#SEC67 for more information on these routines.

1

fgetpos

Record position in a stream or file

2

fiprintf

Format output to file (integer only)

3

fdopen

Turn open file into a stream

4

freopen

Open a file using an existing file descriptor

5

fseeko

Set file position

6

fsetpos

Restore position of a stream or file

7

ftello

Return position in a stream or file

8

getw

Read a word (int)

9

iprintf

Write formatted output (integer only)

10

mktemp, mkstemp

Generate unused file name

11

putw

Write a word (int)

12

remove

Delete a file's name

13

rename

Rename a file

14

setbuf

Specify full buffering for a file or stream

15

siprintf

Write formatted output (integer only)

16

asprintf, snprintf

Format output

17

tmpfile

Create a temporary file

18

tmpnam,

Name for a temporary file

Large file input / output:

19

fopen64

Open a large file

20

freopen64

Open a large file using an existing file descriptor

21

ftello64

Return position in a stream or file

22

fseeko64

Set file position for large file

23

fgetpos64

Record position in a large stream or file

24

fsetpos64

Restore position of a large stream or file

25

tmpfile64

Create a large temporary file


Along with all the above, following set of routines are provided in the newlib library:

1.    Wide character strings (wchar.h):
         Please refer http://sources.redhat.com/newlib/libc.html#SEC144

2.    Signal handling (signal.h):
         Please refer http://sources.redhat.com/newlib/libc.html#SEC169

3.    Time functions (time.h):
         Please refer http://sources.redhat.com/newlib/libc.html#SEC172

4.    Locale specific routines (locale.h):
         Please refer http://sources.redhat.com/newlib/libc.html#SEC183

Startup Routine


The startup routine in GNUM16CM32C toolchain for all targets is given below for user reference. 

/* Start-up code */
.text
      .global     _start
      .type _start, @function

_start:
      ldc   #_istack, isp                  /* set interrupt stack pointer */
      mov.b #0x02,0x0a                 /* write enable in protect register */
      mov.b #0x00,0x04                 /* set processer mode  :single chip mode */
                                               /* 0x04 is the address of processor mode register 0 */
      mov.b #0x00,0x0a                 /* write disable in protect register */
      ldc   #0x0080,flg                   /* select USER STACK POINTER (BIT7=1,USP) (BIT7=0,ISP) */
      ldc   #_ustack,sp                  /* set user stack pointer */
      fset  I                                 /* ADD THIS TO ENABLE INTERRUPTS */

/* INTERRUPT VECTOR ADDRESS  definition   */
#ifdef __m16c_cpu__                   /* For M16C target */
      ldc   #0xF, intbh                   /* load upper 4 bits of variable vector address in intbh */
      ldc   #0xA000, intbl               /* load lower 16 bits of variable vector address in intbl */

#elif __r8c_cpu__                        /* For R8C target */
      ldc   #0x0, intbh
      ldc   #0xFD00, intbl                /* load variable vector address in intbl */

#else                                         /* For M32C, M32CM targets */
      ldc   #0x0FFBE00, intb            /* load variable vector address in intb register */

#endif

/* call the hardware initialiser */
      jsr.a _hw_initialise   

/* load data section from ROM to RAM only if ROMSTART is defined */
#if ROMSTART
#ifndef __m16c_cpu__
#if defined(__m32c_cpu__) || defined(__m32cm_cpu__)
      mov.l #_mdata,a0                /* For M32C, M32CM targets, store the load address of data section in A0 */

#elif __r8c_cpu__                      /* For R8C target */
      mov.b #0x00,R1H                 /* load 00 in R1H */
      mov.w #_mdata,a0               /* store the load address of data section in A0 */

#endif                             
      mov.w #_data,a1                 /* store the start address of data section in, A1 */
      mov.w #_edata,r3                /* store the end address of data section in R3 */
      sub.w    a1,r3                      /* R3=R3-A1 Store size of data section in R3 */
      smovf.b

#endif

#ifdef __m16c_cpu__                  /* For M16C target */
      mov.b #%hi8(_mdata),r1h      /* move upper 4 bits of the 20 bit address (_mdata) to, r1h */
      mov.w #%lo16(_mdata),a0     /* move lower 16 bits of the 20 bit address (_mdata) to,a0 */
      mov.w #_data,a1                 /* store the start address of data section in,A1*/
      mov.w #_edata,r3                /* store the end address of data section in R3 */
      sub.w a1,r3                         /* R3=R3-A1. Store size of data section in R3 */
      mov.w r3,r2                         /* Store size of data section in R2 */
      smovf.b

/* load rodata section from ROM to RAM only for M16C target */
      mov.b #%hi8(_mdata),r1h      /* move upper 4 bits of the 20 bit address (_mdata) to r1h */
      mov.w #%lo16(_mdata),a0     /* move lower 16 bits of the 20 bit address (_mdata) to,a0 */
      add.w r2,a0                         /* add the size of data section to a0, to get load address of rodata section */
      jnc rodata_init            
      add.b #01, r1h                     /* if the carry flag is set,increment r1h */

rodata_init:                 
      mov.w #_rodata,a1               /* store the start address of rodata section in, A1 */
      mov.w #_erodata,r3              /* store the end address of rodata section in R3 */
      sub.w a1,r3                         /* R3=R3-A1. Store size of rodata section in R3 */
      smovf.b

#endif

#endif // ROMSTART

/* bss initialisation : zero out bss */
      mov.b #0x00,R0L                /* load R0L reg with 0x0 (value at which bss  section will be initialised) */
      mov.w #_bss, a1                /* store the start address of bss in A1 */
      mov.w #_ebss, a0               /* store the end address of bss in A0 */
      sub.w   a1,a0                     /* (A0 = A0-A1) */
      mov.w   a0,r3                     /* Store size of bss section in reg R3 */
      sstr.b

/* start user program */
      jsr.a _main      
.end

/* End of Start-up code */

Vector Table

The Vector Table in GNUM16CM32C toolchain for all targets is given below for user reference.
User need to call the Interrupt Service Routines (ISR) from the respective vector locations in the vector table. 

/*  Fixed Vector Table  */

             .section          .vects,"a",@progbits
             .type   _HardwareVectors, @object
             .size   _HardwareVectors, 36

_HardwareVectors:
    .long    0                  ;Hardware Vector 8
    .long    0                  ;Hardware Vector 7
    .long    0                  ;Hardware Vector 6
    .long    0                  ;Hardware Vector 5
    .long    0                  ;Hardware Vector 4
    .long    0                  ;Hardware Vector 3
    .long    0                  ;Hardware Vector 2
    .long    0                  ;Hardware Vector 1
    .long    _start           ;Reset ISR

/* Variable Vector Table */
             .section          .var_vects,"a",@progbits
             .type   _VariableVectors, @object
             .size   _VariableVectors, 256

 _VariableVectors:
    .long    _BRK_ISR    ;BRK instruction
    .long    0                  ;Variable Vector 1
    .long    0                  ;Variable Vector 2
    .long    0                  ;Variable Vector 3
        -          -
        -          -
        -          -
        -          -
    .long    0          ;Variable Vector 62
    .long    0          ;Variable Vector 63

 .end

I/O files examples


Input Files to IAR Program

Output Files

Input Files to GNU Program

Output Files

Preprocess

 

Preprocess

 

C source file (.c)

C Header file (.h)

Preprocessed source (.i)

C source file (.c)

C Header file (.h)

Preprocessed source (.i)

Compiler M16C/R8C

 

Compiler GCC

 

C source file (.c)
C Header file (.h)

Relocatable module file (.rxx)

C / Assembler list file (.lst)

Assembly Source file (.sxx)

C source file (.c)
C Header file (.h)

Assembly Source file (.s)

Assembler am16c

 

Assembler GAS

 

Assembly Source file (.sxx) (.asm) (.msa)
Assembly header file (.inc)

Relocatable module file (.rxx)

Assembler list file (.lst)

Assembly Source file (.s)
Assembly header file (.inc)

Relocatable Object file (.o)
Assembler List file (.lst)

Linker XLINK

 

Linker LD

 

Relocatable module file (.r34, .r48)
Library file (r34, .r48)

Absolute model file (.x, .elf)

Motorola S-record file (.mot)

Intel Hex format file (.hex)

Map file (.map)

Supports 30 industry-standard loader formats based on command options passed.

Relocatable Object file (.o)
Library File (.a)

Output File (.out, .x, .abs)
Map File (.map)

Load Module Converter

 

Objcopy

 

No separate loader module, it is inbuilt in XLINK

 

Output File (.out, .x, .abs)

Motorola S-Record format file (.mot)


Useful Links:

http://sources.redhat.com/newlib/libc.html
http://sources.redhat.com/newlib/libm.html