This document contains useful information for embedded software developers who wish to migrate their code from TASKING tools to Cyberthor Studios GNU tools (and vice versa) for M16C Architecture targets. At present, this guide contains the following:
Compiler Options.
Compiler Directives.
Compiler Extended Keywords.
Intrinsic Functions.
Assembly Options.
Assembler Directives.
Calling Conventions.
C/Math Library Functions.
Startup Routine.
Vector Table.
I/O files at various stages.
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 | 27-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 |
For more information on the above compiler command line options, please refer to the gcc manual.
TASKING |
GNU |
#pragma align Pragma align aligns all objects to even addresses
#pragma align-data Pragma align-data aligns all data to even addresses
#pragma align-func Pragma align-func aligns all functions to even addresses.
|
aligned (alignment) It is not supported for functions |
#pragma extension isuffix
Enables a language extension to specify imaginary floating-point constants.
|
Not supported |
#pragma extern symbol
|
Not Supported |
#pragma clear #pragma noclear
By default, uninitialized global or static variables are cleared to zero on startup. with pragma noclear, this step is skipped.
|
Not Supported |
#pragma inline #pragma noinline
Pragma inline and pragma noinline to inline a function body.
|
Function attributes can be used to inline functions void foo (const char) __attribute__((always_inline));
void foo (const char) __attribute__((noinline)); |
#pragma smartinline
With this pragma small functions that are not too often called, are inlined. |
Not supported. |
#pragma macro #pragma nomacro Turns macro expansion on or off.
|
Not supported. |
#pragma message "string"
Print the message string(s) on standard output. |
Not Supported.
|
#pragma optimize flags #pragma endoptimize
Compiler option -O for the code between the pragmas optimize and endoptimize
|
Not supported
But by passing the -O,-O1,-O2,-O3& -Os option in the command line optimization can be achieved. |
#pragma renamesect spec Rename sections of the specified type. #pragma endrenamesect Restore default section naming. |
Not Supported |
#pragma runtime [flag,...]
Check for runtime errors |
Not Supported |
#pragma weak symbol
Mark a symbol as "weak”.
|
#pragma weak symbol
This pragma declares symbol to be weak
|
#pragma alias symbol=defined_symbol
Define symbol as an alias for defined_symbol
|
Not supported
By using attribute alias for function can be written as alias ("target") For Example void f () __attribute__ ((weak, alias ("__f"))); defines `f' to be a weak alias for `__f' |
For more information on the above compiler directives, please refer to the gcc manual.
TASKING |
GNU |
__bita |
Not supported. |
__at() Place the object at an absolute address. |
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 (Anywhere in 20 bits addressing), but uses only 16-bit for pointer arithmetic.
|
Not supported |
__paged The data can be stored a 64 kB page, anywhere in memory. |
Not supported |
__near Stores the data in the first 64kB of memory. |
Not supported |
__interrupt Defines interrupt function.
|
__attribute__
((interrupt ("IRQ"))) Indicate that the specified function is an interrupt
handler. For
ex: void f () __attribute__ ((interrupt ("IRQ"))); |
__rom This specifies that a variable must be placed in
|
Not Supported. |
__sfr Define a symbol as a Special Function Register (SFR). |
Not Supported. |
TASKING |
GNU |
void __brk (void) Breaks the interrupt
|
#define __ disable_interrupt ( ) asm(“FCLR I”); |
void __int (int) Initialize the interrupt
|
#define __enable_interrupt( ) asm(“FSET I”); |
__illegal_opcode( )
|
#define __illegal_opcode( ) asm(“UND”); |
void __nop(void)
Inserts a NOP instruction |
#define __no_operation( ) asm(“NOP”); |
void __wait (void) WAIT instruction
|
#define __wait_for_interrupt( ) asm(“WAIT”); |
TASKING |
GNU |
-I
(--include-directory) -Ipath,... --include-directory=path,... Specify the path where include files are located. A relative path will be relative to the current directory. |
-I pathUse this option to add a path to the list of directories as searches for files specified in .include directives |
-Oa/-OA (= on/off) Optimize speed by means of instruction alignment.
-Og/-OG Allow
generic instructions -Os/-OS Optimize instruction size |
Not Supported |
-gAHLS No debug information -gs Automatic HLL or assembly level debug information -gflag Custom debug information |
-g
Generates debugging information.
Generate dwarf-2 debug information |
By default all warnings are reported -w --no-warnings Suppress all warnings -w[num]... --no-warnings[=nr,...] Suppress specific warnings
--warnings-as-errors Treat warnings as errors
|
--warn Don't suppress warning messages or treat them as errors. -W --no-warn Suppress warning messages. --fatal-warnings Treat warnings as errors. |
-? --help[=options] Displays an overview of all command line options. |
--help Displays a summary of the command line options |
--error-file[=file] Redirect diagnostic messages to a file
|
Not Supported |
-k Keep output file after errors
|
Not supported |
-m{t|n} Select TASKING preprocessor or no preprocessor
|
Not Supported |
-o file Specify name of output file |
-o filename Sets
object filename |
-v Verbose information
|
Not Supported. |
-V Display version header only
|
-v Displays Version information
|
-f filename OR
--option-file= filename |
@file |
--emit-locals Emit local symbols |
Not Supported. |
-C cpu Define the target processor
|
Not Supported |
--check Check for syntax errors |
Not Supported |
--r8c This option lets the assembler to assemble for R8C/tiny core. |
Not Supported |
-t flags [c/C (+/-console Or l/L (+/-list) Option tells the assembler to display section information.
|
Not Supported.
|
-l This option generates assembler list file
|
-a Requests high-level, assembly, and symbols listing
-ah Requests a high-level language listing,
-al Requests an output-program assembly listing.
-as Requests a symbol table listing |
For more information on the above
assembler options, please refer to the
as manual.
TASKING |
GNU |
WARN [{string | expr}[,{string | expr}]...] Programmer generated warning
|
|
#IF #ELSE #ENDIF |
.if .else .endif |
#DEFINE Define substitution string
|
.define |
#COMMENT Start comment lines. You cannot use this directive in MACRO/DUP definitions.
|
/*comment */ |
DEFSECT Define section name, type and attributes
|
|
#END End of source program
|
.end |
#fail Programmer generated error message
|
.fail Expr Generates an error or a warning |
#include Include a file
|
.include "file" |
MSG Programmer generated message
|
print string on the standard output during assembly |
RADIX Change input radix for constants
|
Not Supported |
SECT Activate a declared section
|
|
UNDEF Undefine DEFINE symbol
|
.undef |
EXTERN External symbol declaration |
.extern |
EQU Assigns permanent value to a symbol
|
|
GLOBAL Global Symbol declaration |
|
LOCAL Local symbol declaration |
Not Supported |
SET Set temporary value to a symbol
|
Set the value of symbol to expression
|
SIZE Set size of symbol in the ELF symbol table |
.size This directive is used to set the size associated with a symbol |
TYPE Set symbol type in the ELF symbol table
|
.type |
WEAK Mark symbol as 'weak' |
This directive sets the weak attribute on the comma
separated list of symbol |
ALIGN Define alignment
|
|
ASCII / ASCIZ Define ASCII string without / with ending NULL byte |
|
BS Define block storage (initialized)
|
Not Supported |
BSB Define byte block storage (initialized)
|
Not Supported |
BSBIT Define bit block storage in bit-addressable data
|
Not Supported |
BSW / BSL Define word / long block storage (initialized)
|
Not Supported |
DB Define constant byte
|
Not Supported |
DBIT Define constant bit |
Not Supported |
DS Define storage
|
Not Supported |
DW / DL Define a word / long constant |
Not Supported |
FLOAT / DOUBLE Define a float / double constant |
Not Supported |
DUP Duplicate sequence of source lines
|
Not Supported |
DUPA Duplicate sequence with arguments
|
Not Supported |
DUPC Duplicate sequence with characters
|
Not Supported |
DUPF Duplicate sequence in loop
|
Not Supported |
ENDM End of macro or duplicate sequence
|
.endm |
EXITM Exit macro
|
|
IF/ELIF/ELSE/ENDIF Conditional assembly |
Already Defined |
MACRO Define macro
|
.macro |
PMACRO Undefine (purge) macro
|
|
CALLS Passes call information to object file. Used by the linker to build a call graph and calculate stack size
|
Not Supported |
For more information on the above
assembler directives, please refer to the
as manual.
Rules of Return Value
Values |
TASKING |
GNU |
_Boll |
R0L Register |
R0L Register |
int |
R0 Register A0 Register |
R0 Register |
float |
R2R0 R2R0 |
Anything bigger than 16 bits is |
double |
R3R1R2R0 Registers |
Anything bigger than 16 bits is |
long long |
R3R1R2R0 Registers |
Anything bigger than 16 bits is |
Rules of Argument Transfer
Argument |
Argument Type |
TASKING |
GNU |
Registers
Used |
Registers Used | ||
First argument |
char type, _Bool type(QImode) |
R0L register if R0L not empty R0H. |
R1L |
int type, near pointer type (HImode) |
R0 Register
|
R1 | |
4-byte argument
Long long |
R2R0
R3R1R2R0 |
On Stack
On Stack | |
Second argument |
int type
near pointer type |
Assign to register R1 if available ,otherwise on stack.
A1 Register if available otherwise on the stock |
R2 |
Third argument |
Int type |
R1 Register |
On stack
|
Fourth Argument |
Int Type |
R3 Register |
On stack |
All other arguments |
Any |
Assign to registers according to above rules as long as registers are available. Otherwise on stack. |
On Stack |
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) | ||
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) | ||
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) | ||
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) | ||
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) | ||
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
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*/
#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
/* 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 */
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
Input Files to TASKING 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) |
Intermediate C source file (.ic) C / Assembler list file (.lst) Assembly Source file (.src) Compiler
error message eile (.err) |
C source file (.c) |
Assembly Source file (.s) |
Assembler am16c |
|
Assembler GAS |
|
Assembly Source file (.src)
(.asm) |
Relocatable object file (.obj) Assembler list file (.lst) Assembler error Message file (.err) |
Assembly Source file (.s) |
Relocatable Object file (.o) |
Linker |
|
Linker LD |
|
Object file (.obj)
|
Object library file (.a) Relocatable linker output file(.eln) Motorola S-record file (.s) Intel Hex format file (.hex) Absolute IEEE-695 output file (.abs) Absolute ELF/DWARF output file (.elf)
|
Relocatable Object file (.o) |
Output File (.out, .x, .abs) |
Useful Links:
http://sources.redhat.com/newlib/libc.html
http://sources.redhat.com/newlib/libm.html