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

Exploiting the C library

2.4.4. Exploiting the C library

If you create an application that includes a main() function, the linker automatically includes the initialization code necessary for the execution environment. See Building an application with the C library for instructions. There are situations though where this is not desirable or possible.

You can create an application that consists of customized startup code and still use many of the library functions. You must either:

  • avoid functions that require initialization

  • provide the initialization and low‑level support functions.

Program design

The functions you must re‑implement depend on how much of the library functionality you require:

  • If you want only the compiler support functions for division, structure copy, and FP arithmetic, you must provide __rt_raise(). This also enables very simple library functions such as those in errno.h, setjmp.h, and most of string.h to work.

  • If you call setlocale() explicitly, locale‑dependent functions are activated. This enables you to use the atoi family, sprintf(), sscanf(), and the functions in ctype.h.

  • Programs that use floating‑point must call _fp_init(). If you select software floating‑point, the program must also provide __rt_fp_status_addr(). If this function is not re‑implemented, the default action is to create a __user_libspace area. See The __user_libspace static data area for a description of the __user_libspace area.

  • Implementing high‑level input/output support is necessary for functions that use fprintf() or fputs(). The high‑level output functions depend on fputc() and ferror(). The high‑level input functions depend on fgetc() and __backspace().

Implementing these functions and the heap enables you to use almost the entire library.

Using low‑level functions

If you are using the libraries in an application that does not have a main() function, you must re‑implement some functions in the library. See The standalone C library functions for more information.

__rt_raise() is essential. It is required by all FP functions, by integer division (so that divide‑by‑zero can be reported), and by some other library routines. You probably cannot write a non trivial program without doing something that requires __rt_raise().

Note

If rand() is called, srand() must be called first. This is done automatically during library initialization but not when you avoid the library initialization.

Using high‑level functions

High‑level I/O functions, fprintf() for example, can be used if the low‑level functions, fputc() for example, are re‑implemented. Most of the formatted output functions also require a call to setlocale(). See Tailoring the input/output functions for instructions.

Anything that uses locale must not be called before first calling setlocale() to initialize it, for example, call setlocale(LC_ALL, "C"). Locale‑using functions are described in The standalone C library functions. These include the functions in ctype.h and locale.h, the printf() family, the scanf() family, ato*, strto*, strcoll/strxfrm, and much of time.h.

Using malloc()

If heap support is required for bare machine C, _init_alloc() must be called first to supply initial heap bounds, and __rt_heap_extend() must be provided even if it only returns failure. Prototypes for both functions are in rt_heap.h.

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