Keil™, An ARM® Company

RealView Libraries and Floating Point Support Guide

On-Line Manuals

RealView Libraries and Floating Point Support Guide

Preface
Introduction
The C and C++ Libraries
About the C and C++ libraries
Features of the C and C++ libraries
Namespaces
Writing reentrant and thread‑safe code
Introduction to reentrancy and thread‑safety
Use of static data in the C libraries
The __user_libspace static data area
Managing locks in multithreaded applications
Using the ARM C libraries with a multithreaded app
Thread‑safety in the ARM C libraries
Thread‑safety in the ARM C++ libraries
Building an application with the C library
Using the libraries with an application
Building an application for a semihosted environme
Building an application for a non semihosting envi
Building an application without the C library
Integer and FP helper functions
Bare machine integer C
Bare machine C with floating‑point
Exploiting the C library
The standalone C library functions
Tailoring the C library to a new execution environ
How C and C++ programs use the library functions
__rt_entry
Exiting from the program
__rt_exit()
__rt_lib_init()
__rt_lib_shutdown()
Tailoring static data access
Tailoring locale and CTYPE using assembler macros
Selecting locale at link time
Selecting locale at runtime
Defining a locale block
LC_CTYPE data block
LC_COLLATE data block
LC_MONETARY data block
LC_NUMERIC data block
LC_TIME data block
_get_lconv()
localeconv()
setlocale()
_findlocale()
The lconv structure
Tailoring locale and CTYPE using C macros
Selecting locale at link time
Selecting locale at runtime
Macros and utility functions
_get_lc_ctype()
_get_lc_collate()
_get_lc_monetary()
_get_lc_numeric()
_get_lc_time()
_get_lconv()
localeconv()
setlocale()
_findlocale()
__LC_CTYPE_DEF
__LC_COLLATE_DEF
__LC_TIME_DEF
__LC_NUMERIC_DEF
__LC_MONETARY_DEF
__LC_INDEX_END
The lconv structure
Tailoring error signaling, error handling, and pro
_sys_exit()
errno
__rt_errno_addr()
__raise()
__rt_raise()
__default_signal_handler()
_ttywrch()
__rt_fp_status_addr()
Tailoring storage management
Avoiding the ARM‑supplied heap and heap‑using
Support for malloc
Tailoring the runtime memory model
The memory models
Controlling the runtime memory model
Writing your own memory model
__user_initial_stackheap()
__user_setup_stackheap()
__user_heap_extend()
__user_heap_extent()
__user_stack_cleanup_space()
__rt_heap_extend()
__rt_stack_postlongjmp()
Tailoring the input/output functions
Dependencies on low‑level functions
Target‑dependent input/output support functions
_sys_open()
_sys_close()
_sys_read()
_sys_write()
_sys_ensure()
_sys_flen()
_sys_seek()
_sys_istty()
_sys_tmpnam()
_sys_command_string()
#pragma import(_main_redirection)
Tailoring other C library functions
clock()
_clock_init()
time()
remove()
rename()
system()
getenv()
_getenv_init()
Selecting real‑time division
ISO implementation definition
ISO C library implementation definition
Standard C++ library implementation definition
C library extensions
atoll()
strtoll()
strtoull()
printf()
snprintf()
vsnprintf()
lldiv()
llabs()
wcstombs()
alloca()
strlcpy()
strlcat()
_fisatty()
__heapstats()
__heapvalid()
Library naming conventions
Placing ARM libraries
Helper libraries
Identifying library variants
The C Micro-library
Floating‑point Support

Building an application for a non semihosting environment

2.3.3. Building an application for a non semihosting environment

If you do not want to use any semihosting functionality, you must remove all calls to semihosting functions or re-implement them with non semihosting functions.

To build an application that does not use semihosting functionality:

  1. Create the source files to implement the target‑dependent features. for example, functions that use the semihosting calls or that depend on the target memory map.

  2. Add the __use_no_semihosting symbol to the source. See Avoiding semihosting.

  3. Link the new objects with your application.

  4. Use the new configuration when creating the target‑dependent application.

You must re‑implement functions that the C library uses to insulate itself from target dependencies. For example, if you use printf() you must re‑implement fputc(). If you do not use the higher‑level input/output functions like printf(), you do not have to re‑implement the lower‑level functions like fputc().

If you are building an application for a different execution environment, you can re‑implement the target‑dependent functions. There are no target‑dependent functions in the C++ library, although some C++ functions use underlying C library functions that are target‑dependent.

C++ exceptions in a non semihosted environment

The default C++ std::terminate() handler is required by the C++ Standard to call abort(). The default C library implementation of abort() uses functions that require semihosting support. Therefore, if you use exceptions in a non semihosted environment, you must provide an alternative implementation of abort().

Overview of semihosting dependencies

Table 2.3 shows the functions that depend directly on semihosting.

Table 2.3. Direct semihosting dependencies

FunctionDescription
__user_initial_stackheap()See Tailoring the runtime memory model. You might have to re‑implement this function if you are using scatter‑loading.
_sys_exit() _ttywrch()See Tailoring error signaling, error handling, and program exit.
_sys_command_string(),
_sys_close(), _sys_ensure(),
_sys_iserror(), _sys_istty(),
_sys_flen(), _sys_open(),
_sys_read(), _sys_seek(),
_sys_write(), _sys_tmpnam()
See Tailoring the input/output functions.
clock(),
_clock_init()remove(),
rename()system(), time()
See Tailoring other C library functions.

Table 2.4 shows those functions that depend indirectly on one or more of the functions listed in Table 2.3.

Table 2.4. Indirect semihosting dependencies

FunctionUsage
__raise()Catch, handle, or diagnose C library exceptions, without C signal support. See Tailoring error signaling, error handling, and program exit.
__default_signal_handler()Catch, handle, or diagnose C library exceptions, with C signal support. See Tailoring error signaling, error handling, and program exit.
__Heap_Initialize()Choosing or redefining memory allocation. See Tailoring storage management.
ferror(), fputc(), __stdoutRe‑implementing the printf family. See Tailoring the input/output functions.
__backspace(), fgetc(),
__stdin
Re‑implementing the scanf family. See Tailoring the input/output functions.
fwrite(), fputs(), puts(),
fread(), fgets(), gets(),
ferror()
Re‑implementing the stream output family. See Tailoring the input/output functions.

Avoiding semihosting

If you write an application in C, you must link it with the C library even if it makes no direct use of C library functions. The C library contains compiler helper functions and initialization code. Some C library functions use semihosting.

To avoid using semihosting, do either of the following:

  • re‑implement the functions in your own application

  • write the application so that it does not call any semihosted function.

To guarantee that no functions using semihosting are included in your application, use either:

  • IMPORT __use_no_semihosting from assembly language

  • #pragma import(__use_no_semihosting) from C.

If you include a semihosting‑using library function and also reference __use_no_semihosting, the library detects the conflicting symbols and the linker reports an error. To find out which objects are using semihosting, link with ‑‑verbose ‑‑list=out.txt, search the output for the symbol, and find out what object referenced it. See Controlling linker diagnostics in the Linker Guide for more information.

API definitions

In addition to the semihosted functions listed in Table 2.3 and Table 2.4, Table 2.5 shows functions and files that might be useful when building for a different environment.

Table 2.5. Published API definitions

File or functionDescription
__main()
__rt_entry()
Initializes the runtime environment and executes the user application.
__rt_lib_init()
__rt_exit()
__rt_lib_shutdown()
Initializes or finalizes the runtime library.
LC_CTYPE localeDefines the character properties for the local alphabet. See Tailoring locale and CTYPE using assembler macros.
rt_sys.hA C header file describing all the functions whose default (semihosted) implementations use semihosting calls.
rt_heap.hA C header file describing the storage management abstract data type.
rt_locale.hA C header file describing the five locale category filing systems, and defining some macros that are useful for describing the contents of locale categories.
rt_misc.hA C header file describing miscellaneous unrelated public interfaces to the C library.
rt_memory.sAn empty, but commented, prototype implementation of the memory model. See Writing your own memory model for a description of this file.

If you are re‑implementing a function that exists in the standard ARM library, the linker uses an object or library from your project rather than the standard ARM library. Any library you add to a project does not have to follow the ARM library naming convention.

Caution

Do not replace or delete libraries supplied by ARM Limited. You must not overwrite the supplied library files. Place your re‑implemented functions in a separate library.

Copyright © 2007 ARM Limited. All rights reserved.ARM DUI 0378A