Preface


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


   Compiler Options.
   Compiler Directives.
   Assembly Options.
   Assembler Directives.
   Calling Conventions.
   C/Math Library Functions.
   Startup Routine.
   Vector Table.
   I/O files at various stages.
   Inline Assembly Language.


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.



Revision History:

Version Number Date Overview of changes
1.0 21-December-2007 Created.
2.0 07-March-2008 'Using inline assembly in GNU' is added.
3.0 30-September-2008 Modified 'Using inline assembly in GNU' section to add ‘-h-tick-hex’ option.
4.0 20-October-2016 Added new responsive template

Compiler Options


Renesas Compiler Options

Equivalent GCC compiler options
 

-D<identifier>
Defines the "identifier". Functionality similar to #define.

-D<name>
Predefines the "name" as a macro, with definition 1.
 

-c
Creates a relocatable file (extension .r30) and ends processing.

-c
Compile or assemble the source files (extension .o), but do not link. The linking stage simply is not done. The ultimate output is in the form of an object file for each source file.
 

-Idirectory = <path name> [,…]
Include paths (upto 8 directories can be specified).

-I<path>  
 

-E
Invokes only preprocess commands and outputs result to standard output.

-P
invokes only preprocess commands and creates a file (extension *.i).

 

-E  
Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocessed source code, which is sent to the standard output.


-E -o output-filename  
Place output in specified output file filename.
 

-S
Creates an assembly language source file (extension .a30) and ends processing.

-S
Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file (extension .s) for each non-assembler input file specified.

-Upredefined macro
Undefines the specified predefined macro

-U name
Cancel any previous definition of name, either built in or provided with a `-D' option.

-o filename
Set object filename.

-o filename
Place output in file filename. This applies regardless to whatever sort of output is being produced.
 

-g
Outputs debug information to an assembly language source file (extension .a30).Therefore you can perform C language- level debugging.

-g
Produce debugging information, GDB can work with this debugging information.
 

-O[1-5]
Speed optimization
O5 is the strongest optimization.

-OS
Optimization of speed followed by ROM size. 

-O[1-3]
 

-OS_MAX (-OSM)
Maximum optimization of speed followed by ROM size.
-O3
 

-OR
Optimize for size.

-OR_MAX (-ORM)
Maximum optimization of ROM size followed by speed.

-Os
 

-Oforward_function_to_inline (-OFFTI)
Expands all inline functions in-line.

Although inline functions require that an inline function be declared before its entity definition can be made, use of this option allows the entity definition of an inline function to be made before declaring it.
Not Supported.

You need to specify the function attribute as "always_inline" which will force the compiler to make the function inline. And you also need to pass the command line option '-funit-at-a-time' to the compiler.

The option "funit-at-a-time" will allow the compiler to consider information gained from later functions in the file when compiling a function. So even if the body of the inline function is defined after the calling routine, the compiler will not give an error because it has already gained information about the function.
-Oloop_unroll[= loop count] (-OLU)
Unrolls code as many times as the loop count without revolving the loop statement. The "loop count" can be omitted. When omitted, this option is applied to a loop count of up to 5.
-funroll-loops
Unroll loops whose number of iterations can be determined at compile time or upon entry to the loop.

--param max-unroll-times=number
The maximum "number" of unrollings of a single loop.
-Ono_stdlib (-ONS)
Inhibits inline padding of standard library functions and modification of library functions.
Not Supported
No workaround
Not Supported
No workaround
-nostdlib
Do not use the standard system startup files or libraries when linking. No startup files and only the libraries you specify will be passed to the linker.
-Ostatic_to_inline (-OSTI)
A static function is treated as an inline function and the assembling code which carried out inline deployment is generated.
Not Supported.

However if you enable any kind of optimization it inlines all the static functions at their calling locations.

-l filename
Specifies a library file that is used by ln30 when linking files.

-l filename
Search the library named library when linking.

-Wnon_prototype (-WNP)
Outputs warning messages for function without prototype declarations

-Werror-implicit-function-declaration
Give a warning (or error) whenever a function is used before being declared.

OR

-Wmissing-prototypes (C only)
Warn if a global function is defined without a previous prototype declaration. This warning is issued even if the definition itself provides a prototype.

-Wunknown_pragma (-WUP)
Outputs warning messages for non-supported #pragma.

-Wunknown-pragmas
Warn when a #pragma directive is encountered which is not understood by GCC. `-Wall' command line option should be enabled.

-Wall
Displays messages for all detectable warnings.

-Wall
This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros.
 

-Wnesting_comment (-WNC)
Outputs warning messages for comments including /*.

-Wcomment
Warn whenever a comment-start sequence `/*' appears in a `/*' comment, or whenever a Backslash-Newline appears in a `//' comment. This warning is enabled by `-Wall'.  
 

-Wuninitialize_variable (-WUV)
Outputs warning messages for uninitialized auto variables.

-Wuninitialized
Warn if an automatic variable is used without first being initialized or if a variable may be clobbered by a setjmp call.

-Wno_used_argument (-WNUA)
Outputs a warning to a function having an unused argument.

-Wunused-parameter
Warn whenever a function parameter is unused aside from its declaration.

-Wundefined_macro (-WUM)
Output the warning for undefined macro in #if.

-Wundef
Warn if an undefined identifier is evaluated in an `#if' directive.

-Wno_used_static_function (-WNUSF)
Static function is not referenced from anywhere in the file.

-Wunused-function
Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by `-Wall'.

-Wstop_at_warning (-WSAW)
Stops compiling the source files if a warning occurs during compiling and returns the compiler end code "10".
-Werror
Make all warnings into errors.

-as30 "option"

Specifies options for the as30 assemble command. If you specify two or more options, enclose them in double quotes.

-Wa,option  OR -Xassembler option

Pass option as an option to the assembler. If option contains commas, it is split into multiple options at the commas.

-ln30 "option"

Specifies options for the as30 link command. If you specify two or more options, enclose them in double quotes.

-Wl, option  OR  -Xlinker option
Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas.

-ln30 -W
On the occurrence of a warning, no absolute module file is generated.
-Wl,--fatal-warnings
Treat warnings as errors.

-fshow_stack_usage (-fSSU)

Outputs the usage condition of the stack pointer to a file (extension .stk).

Not supported; a workaround is -

-fstack-check  
Generate code to verify that you do not go beyond the boundary of the stack.

-fansi
When this option is specified, the compiler generates code in conformity with ANSI standards.
-ansi   OR
-std=c89

Specify the The ISO C standard from 1990 to which the code should conform
-fno_align (-fNA)
Does not align the start address of the function.
-fno-align-functions  OR
-falign-functions=1
The functions will not be aligned.
-fnot_reserve_asm (-fNRA)
Exclude asm from reserved words. (Only _asm is valid.)

-fnot_reserve_inline (-fNRI)
Exclude inline from reserved words. (Only _inline is valid.)
-fno-asm
Do not recognize asm, inline or typeof as a keyword.
-fenable_register (-fER)
Make register storage class available.
Not Supported

Register class allocation is enabled by default.
It can't be disabled.
-R8C
Generates object code for R8C/Tiny Series.
-mcpu=r8c
Generates the code for R8C/Tiny Series.
 
-M82
Generates object code for M32C/80 Series.
-mcpu=m32c
Generates the object code for the M32C/80 series.
  -mcpu=m16c
Generates the object code for the M16C (up to /60) series
  -mcpu=m32cm
Generates the object code for the M16C/80 series
Default Target
If you do not pass any target specifying switch to the compiler, by default it generates code for M16C target.
Default Target
By default compiler generates code for R8C target.

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

Compiler Directives


Renesas Directives Equivalent GNU directive or method
#pragma INTERRUPT interrupt-vector-number 
                      interrupt-handling-function-name
Or
#pragma INTERRUPT 
           interrupt-handling-function-name
                        (vect= interrupt-vector-number)

e.g.
#pragma INTERRUPT 8 ext_0
OR
#pragma INTERRUPT ext_0 (vect=8)
void ext_0(void) 
{
P0=6;
}
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 volatile int P0; 
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() 
{
P0 = 6;
}
asm(assembler template);

Assembly language can be directly included in C programs inside functions. If there are no variable names it can also be included outside functions.

e.g.asm(" mov.w $@, $@", var1,var2);
 asm ( assembler template
: output operands                     /* optional */
: input operands                        /* optional */
: list of clobbered registers     /* optional */
);

In an assembler instruction using asm, you can specify the operands of the instruction using C expressions.

e.g. asm ("add.w %1,%0" : "=f" (num2) : "f" (num1));
#pragma ASM
assembly instructions
#pragma ENDASM

Specifies an area in which statements are written 
in assembly language.

e.g.
#pragma ASM
mov.w R0,R1
add.w R1,02H
#pragma ENDASM
Not Supported

You can put multiple assembler instructions together in a single asm template, separated by the characters normally used in assembly code for the system. A combination that works in most places is a newline to break the line, plus a tab character to move to the instruction field (written as `\n\t'). Sometimes semicolons can be used, if the assembler allows semicolons as a line-breaking character.

e.g
asm ("movl %0,r9\n\tmovl %1,r10\n\tcall _foo"
: /* no outputs */
: "g" (from), "g" (to)
: "r9", "r10");
#pragma ADDRESS. variable-name.
                                         absolute-address

Specifies the absolute address of a variable.
Not Supported

#define variable-name (*(volatile char *)
                                                        
(absolute-address))
#pragma BITADDRESS

A variable is assigned to the bit position which the specified absolute address specified.
Not Supported

Defining an address like shown below, can allow you to access it as a BYTE location as well as allows you to access each BIT field individually.

/* UART0 transmit/receive mode register */
union st_u0mr
{
   struct
          
{
         /* Bit Access */
         unsigned char SMD0_U0MR :1;
         unsigned char SMD1_U0MR :1;
         unsigned char SMD2_U0MR :1;
         unsigned char CKDIR_U0MR:1;
         unsigned char STPS_U0MR :1;
         unsigned char PRY_U0MR :1;
         unsigned char PRYE_U0MR :1; /* Parity enable bit */
         unsigned char IOPOL_U0MR :1;
         } BIT;

unsigned char BYTE;                           /* Byte Access */
};

/* Assigning the absolute address */
#define U0MR (*(volatile union st_u0mr *)(0x03a0))

/* Accessing the Parity Enable bit */
U0MR.BIT.PRYE_U0MR ^= 0x1;
#pragma STRUCT structure_tag unpack
Inhibits the packing of structures with the specified tag
Not Supported

However following option could help to have all structures of even byte size and aligned properly.

-fpack-struct[=num]
Pack the structure member according to this value (which must be a small power of two), representing the maximum alignment.
#pragma ROM variable_name
Maps the specified variable to rom
Not Supported

const variable_name
Declaring the type of a variable as "const", places that variable into the ROM.

You can assing the variables to an user defined section and can also map it at a required memory location using your own linker script.
inline returntype funcname(arg)
inline returntype funcname(arg);
__inline__ returntype funcname(arg);
Register Variables -
register int var1=1;

register variables used within functions are  managed dynamically. At anyone position, the register used for a register variable is not necessarily always the same one.

register int var1=1;
asm(" mov.w $$,A1",var1);
Register Variables -
register int var1 =1;
OR
register int var1 asm ("Register-Name")=1;

Local register variables in specific registers do not reserve the registers, except at the point where they are used as input or output operands in an asm statement and the asm statement itself is not deleted. Global register variables reserve registers throughout the program.

register int var1 asm ("r3") = 1;
asm("mov.w %0,r0":"=r" (var1));

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

Assembler Options


Renesas Assembler Options Equivalent GNU assembler options
 
-M60
Generates code that conforms to the M16C/60 group.

-M61
Generates code that conforms to the M16C/61 group.
-m16c
Assemble M16C instructions (the default).

 
 -M82
Generates a code that conforms to the M32C/80 series

-M90
Generates a code that conforms to the M32C/90 series
-m32c
Assemble M32C instructions.

 
-S
Specifies that local symbol information be output.
-L
--keep-locals
Keep (in the symbol table) local symbols. On traditional a.out systems these start with `L', but different systems have different local label prefixes.
-D (symbol name) = (numeric value)
Sets Symbol Constant
--defsym sym=value
Define the symbol sym to be value before assembling the input file.
–L
Generates Assembler List File

–a

Generates list file.
 

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

Assembler Directives


Renesas Assembler Directives GNU Assembler Directives
.SECTION (section name),
                                 (section type),ALIGN

This command defines the beginning of a section. Section type can be selected from 'CODE', 'ROMDATA', and 'DATA'. The section type can be omitted. In this case, as30 assumes section type CODE as it processes assembling.

If 'ALIGN' is specified, ln30 allocates the beginning of a section to an even address.
.section name [, "flags"[, @type
                        [,flag_specific_arguments]]]

It creates the section "name". The optional flags argument is a quoted string describing section attributes like section being allocatable (a), executable (x) etc.

The optional type argument describes the contents of the section like it contains data (@progbits) or array of pointers to init function (@init_array) etc.
 
.ORG <absolute address>
Addresses in the section become absolute values when assembled.
.org new-lc , fill
If the comma and fill are omitted, fill defaults to
zero.
 

.FILE

.file
 

.ALIGN <boundary alignment value>

.align <boundary alignment value>
(for details on more options of aligning like filling

specific values, etc, please see link below)
 

.BYTE
.byte   
 
.WORD
.word
 
.LWORD
Stores data in ROM in 4-byte length.
.long
 
.IF .if
 
.ELIF
.elseif
.ELSE
.else
 
.END
.end

.ENDIF .endif

.GLB symbol
If the symbol specified with the directive
command then the assembler process them
assuming that they are defined in external
file.
.global symbol
 
symbol .EQU value .equ symbol, value
 
.PAGE
Breaks page at specified position of list file.
.eject
Force a page break at this point, when generating assembly listings
.FORM
Specifies number of columns and lines in 1 page of list file.
.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.

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

Calling Convetions


Rules of Return Value

Values Renesas Compiler Options GNU Compiler Options
_Boll
Char (QImode)
R0L Register R0L Register
int
near pointer (HImode)
R0 Register R0 Register
float
long
far pointer (SImode)
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

Values are stored in 16 bits
beginning with the high-order
bits sequentially in order of
registers R3, R2, R1, and R0 as
they are returned.

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

Values are stored in 16 bits
beginning with the high-order
bits sequentially in order of
registers R3, R1, R2, and R0 as
they are returned.

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 Renesas Compiler Options GNU Compiler Options
Registers Used Registers Used
First argument char type,
_Bool type(QImode)

int type,
near pointer type (HImode)

R1L register
 

R1 register

 

R1L
 

R1

Second argument int type
near pointer type
R2 register R2
All other arguments Any On Stack On Stack


C/Math Library Functions


 

GNU C library namely Newlib is distributed under a free software license. 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 library functions.
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 Atoff 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


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


Vector Table Implementation :

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

/* End of Vector Table */


I/O files at various stages


Input Files to Renesas Program Output Files Input Files to GNU Program Output Files
Compiler nc30/nc308 Compiler GCC
C source file (.c)
C Header file (.h)
Assembly Source file (.a30) C source file (.c)
C Header file (.h)
Assembly Source file (.s)
Assembler as30/as308 Assembler GAS
Assembly Source file (.a30)
Include File (.inc)
Relocatable module file (.r30)
Assembler list file (.lst)
Assembler error tag file (.atg)
Branch Information file (.jin)
Assembly Source file (.s)
Assembly header file (.inc)
Relocatable Object file (.o)
Assembler List file (.lst)
Linker ln30/ln308 Linker LD
Relocatable module file (.r30)
Library file (.lib)
Branch information file (.jin)
Absolute model file (.x30)
Map file (.map)
Linker error tag file (.ltg)
Relocatable Object file (.o)
Library File (.a)
Output File (.out, .x, .abs)
Map File (.map)
Load Module Converter lmc30/lmc308 Objcopy
Absolute model file (.x30) Motorola S-Record format file (.mot)
Intel HEx format file (.hex)
ID file (.id)
Output File (.out, .x, .abs)
 
Motorola S-Record format file (.mot)

Inline Assembly Language


Using Inline Assembly Language :

We can instruct the compiler to insert the code of a function into the code of its callers, to the point where actually the call is to be made. Such functions are inline functions.  This method of inlining reduces the function-call overhead. And if any of the actual argument values are constant, their known values may permit simplifications at compile time so that not all of the inline function’s code needs to be included. The effect on code size is less predictable, it depends on the particular case. To declare an inline function, we’ve to use the keyword inline in its declaration. Inline assembly is important primarily because of its ability to operate and make its output visible on C variables. Because of this capability, "asm" works as an interface between the assembly instructions and the "C" program that contains it.

Syntax

GCC, the GNU C Compiler for Linux, uses AT&T&sol;UNIX assembly syntax.

a) Source-Destination Ordering

The first operand is the source and the second operand is the destination. ie, "Op-code src dst". This is similar to the syntax followed in Renesas.

b) Register Naming

Register names are prefixed by % ie, if r0 is to be used, write %r0.

c) Immediate Operand

Immediate operands are preceded by ’#’. For hexadecimal constants a ’0x’ is suffixed to the constant. However, in order to support hexadecimal constants suffixed with a 'H',

please pass '-h-tick-hex' option to the assembler.

e.g., Use the following command to build the "asm("mov.w #H'03,R0");" code statement for m16c targets,

$ m32c-elf-gcc test.c -Wa,-h-tick-hex

d) Operand Size

Size of memory operands is determined from the last character of the op-code name. Op-code suffixes of ’b’, ’w’, and ’l’ specify byte(8-bit), word(16-bit), and long (32-bit) memory references.

e) Memory Operands

Base register is enclosed in ‘(’ and ’)’ and indirect memory reference is like “section&colon;disp(base, index, scale)”. When a constant is used for disp and sol; scale, ’#’ shouldn’t be prefixed.

Useful Links:

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