Difference between revisions of "Unit Syscalls"

From Ultibo.org
Jump to: navigation, search
Line 5: Line 5:
 
----
 
----
  
''To be documented''
+
'''Ultibo Newlib C Library Syscalls interface unit'''
 +
 
 +
This unit provides the system calls (syscalls) interface for the Newlib C library implementation to allow code compiled with GCC to be linked with Ultibo applications.
 +
 +
The Newlib C library is a portable C library designed to be used in embedded environments as well as many other situations. It is made available by RedHat from the sourceware.org website, new releases are made at least yearly and this unit has been developed using 2.4.0 but should work mostly unchanged with future releases.
 +
 +
The build process below creates the libc.a, libm.a and libg.a static libraries, in addition to those GCC also requires the libgcc.a support library which is built at the same time as the compiler and provided in the distribution.
 +
 +
The build process is documented for Debian but should be translatable to other platforms. As documented this will produce a version of Newlib that has support for recursive library calls, has dynamic support for multiple threads and is compiled for the specific architectures that are supported by Ultibo.
 +
 +
Note that Newlib supports code compiled with other C compilers so it should be completely possible to link code generated by other C compilers with Ultibo applications. At this stage it has only been tested with GCC.
 +
 
 +
=== Building Newlib ===
 +
----
 +
 
 +
''Flags:''
 +
 
 +
<code>REENTRANT_SYSCALLS_PROVIDED</code>
 +
 
 +
<code>__DYNAMIC_REENT__</code>
 +
 
 +
<code> __LARGE64_FILES (Note: Not currently supported by Newlib, need to modify \newlib\configure.host to enable stdio64 support for arm-none-eabi or aarch64-none-elf)</code>
 +
 
 +
   
 +
''Options:''
 +
 
 +
'''Raspberry Pi'''
 +
 
 +
-mabi=aapcs
 +
-marm
 +
-march=armv6
 +
-mcpu=arm1176jzf-s
 +
-mfpu=vfp
 +
-mfloat-abi=hard
 +
 
 +
'''Raspberry Pi2/3 (32-bit)'''
 +
 
 +
-mabi=aapcs
 +
-marm
 +
-march=armv7-a
 +
-mfpu=vfpv3-d16
 +
-mfloat-abi=hard
 +
 
 +
'''Raspberry Pi3 (64-bit)'''
 +
 
 +
-mabi=lp64 (Note: Supported only by later versionsof GCC)
 +
-march=armv8-a
 +
   
 +
''Build:''
 +
 
 +
Download Newlib (currently 2.4.0) from ftp://sourceware.org/pub/newlib/index.html
 +
 
 +
Unpack to folder <code>$HOME/newlib-2.4.0</code>
 +
 +
 +
'''Build ARMv6:'''
 +
 
 +
cd
 +
 
 +
mkdir build-newlib-armv6
 +
 
 +
cd build-newlib-armv6
 +
 
 +
export PATH=$HOME/gcc-arm-none-eabi-5_4-2016q2/bin:$PATH
 +
 
 +
../newlib-2.4.0/configure --disable-multilib --target=arm-none-eabi CFLAGS_FOR_TARGET="-O2 -mabi=aapcs -marm -march=armv6 -mfpu=vfp -mfloat-abi=hard -DREENTRANT_SYSCALLS_PROVIDED -D__DYNAMIC_REENT__"
 +
 
 +
make all
 +
 
 +
''Dump:''
 +
   
 +
cd arm-none-eabi/newlib
 +
arm-none-eabi-objdump -d libc.a > libc.list
 +
arm-none-eabi-objdump -d libg.a > libg.list
 +
arm-none-eabi-objdump -d libm.a > libm.list
 +
 
 +
 
 +
'''Build ARMv7: '''
 +
 
 +
cd
 +
 +
mkdir build-newlib-armv7
 +
 +
cd build-newlib-armv7
 +
 +
export PATH=$HOME/gcc-arm-none-eabi-5_4-2016q2/bin:$PATH
 +
 +
../newlib-2.4.0/configure --disable-multilib --target=arm-none-eabi CFLAGS_FOR_TARGET="-O2 -mabi=aapcs -marm -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard -DREENTRANT_SYSCALLS_PROVIDED -D__DYNAMIC_REENT__"
 +
 
 +
make all
 +
 
 +
''Dump:''
 +
 
 +
cd arm-none-eabi/newlib
 +
arm-none-eabi-objdump -d libc.a > libc.list
 +
arm-none-eabi-objdump -d libg.a > libg.list
 +
arm-none-eabi-objdump -d libm.a > libm.list
 +
 
 +
 
 +
'''Build ARMv8:'''
 +
     
 +
cd
 +
 +
mkdir build-newlib-armv8
 +
 +
cd build-newlib-armv8
 +
 
 +
export PATH=$HOME/gcc-linaro-aarch64-none-elf-4.8-2014.04_linux/bin:$PATH
 +
 
 +
../newlib-2.4.0/configure --disable-multilib --target=aarch64-none-elf CFLAGS_FOR_TARGET="-O2 -march=armv8-a -DREENTRANT_SYSCALLS_PROVIDED -D__DYNAMIC_REENT__"
 +
 
 +
make all
 +
 
 +
''Dump:''
 +
 
 +
cd aarch64-none-elf/newlib
 +
aarch64-none-elf-objdump -d libc.a > libc.list
 +
aarch64-none-elf-objdump -d libg.a > libg.list
 +
aarch64-none-elf-objdump -d libm.a > libm.list
 +
 
 +
 +
'''Notes:'''
 +
 +
File handles (fd) passed to and returned from this unit are int values which are 32-bit however internally Newlib stores these into the _file member of a _FILE structure (see below) and this is defined as short which is only 16-bit. Because of this we have to map each Ultibo handle to a TSyscallsEntry and use the functions SyscallsAddEntry, SyscallsRemoveEntry and SyscallsGetEntry which start at zero and increment to 65535.
 +
 
 +
The global errno variable (not used for reentrant version ) is defined in:
 +
 
 +
\newlib\libc\reent\reent.c
 +
 
 +
int errno;
 +
 
 +
The global environ variable is defined in: 
 +
 
 +
\newlib\libc\stdlib\environ.c
 +
 
 +
char **environ = &initial_env[0];
 +
 
 +
The TZ environment variable is used by a number of functions in Newlib including tzset and strftime. This variable can be set on the command line or using the SetEnvironmentVariable() function in the Ultibo unit. See the GNU C library reference for details of the format and value of the TZ environment variable:
 +
 
 +
https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
  
 
=== Constants ===
 
=== Constants ===

Revision as of 02:16, 30 December 2016

Return to Unit Reference


Description


Ultibo Newlib C Library Syscalls interface unit

This unit provides the system calls (syscalls) interface for the Newlib C library implementation to allow code compiled with GCC to be linked with Ultibo applications.

The Newlib C library is a portable C library designed to be used in embedded environments as well as many other situations. It is made available by RedHat from the sourceware.org website, new releases are made at least yearly and this unit has been developed using 2.4.0 but should work mostly unchanged with future releases.

The build process below creates the libc.a, libm.a and libg.a static libraries, in addition to those GCC also requires the libgcc.a support library which is built at the same time as the compiler and provided in the distribution.

The build process is documented for Debian but should be translatable to other platforms. As documented this will produce a version of Newlib that has support for recursive library calls, has dynamic support for multiple threads and is compiled for the specific architectures that are supported by Ultibo.

Note that Newlib supports code compiled with other C compilers so it should be completely possible to link code generated by other C compilers with Ultibo applications. At this stage it has only been tested with GCC.

Building Newlib


Flags:

REENTRANT_SYSCALLS_PROVIDED

__DYNAMIC_REENT__

__LARGE64_FILES (Note: Not currently supported by Newlib, need to modify \newlib\configure.host to enable stdio64 support for arm-none-eabi or aarch64-none-elf)


Options:

Raspberry Pi

-mabi=aapcs
-marm
-march=armv6
-mcpu=arm1176jzf-s
-mfpu=vfp
-mfloat-abi=hard
  

Raspberry Pi2/3 (32-bit)

-mabi=aapcs
-marm
-march=armv7-a
-mfpu=vfpv3-d16
-mfloat-abi=hard
  

Raspberry Pi3 (64-bit)

-mabi=lp64 (Note: Supported only by later versionsof GCC)
-march=armv8-a
   

Build:

Download Newlib (currently 2.4.0) from ftp://sourceware.org/pub/newlib/index.html

Unpack to folder $HOME/newlib-2.4.0


Build ARMv6:

cd
  
mkdir build-newlib-armv6
  
cd build-newlib-armv6
  
export PATH=$HOME/gcc-arm-none-eabi-5_4-2016q2/bin:$PATH
  
../newlib-2.4.0/configure --disable-multilib --target=arm-none-eabi CFLAGS_FOR_TARGET="-O2 -mabi=aapcs -marm -march=armv6 -mfpu=vfp -mfloat-abi=hard -DREENTRANT_SYSCALLS_PROVIDED -D__DYNAMIC_REENT__"
  
make all
  

Dump:

cd arm-none-eabi/newlib
arm-none-eabi-objdump -d libc.a > libc.list
arm-none-eabi-objdump -d libg.a > libg.list
arm-none-eabi-objdump -d libm.a > libm.list


Build ARMv7:

cd

mkdir build-newlib-armv7

cd build-newlib-armv7

export PATH=$HOME/gcc-arm-none-eabi-5_4-2016q2/bin:$PATH

../newlib-2.4.0/configure --disable-multilib --target=arm-none-eabi CFLAGS_FOR_TARGET="-O2 -mabi=aapcs -marm -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard -DREENTRANT_SYSCALLS_PROVIDED -D__DYNAMIC_REENT__"
  
make all
  

Dump:

cd arm-none-eabi/newlib
arm-none-eabi-objdump -d libc.a > libc.list
arm-none-eabi-objdump -d libg.a > libg.list
arm-none-eabi-objdump -d libm.a > libm.list


Build ARMv8:

cd

mkdir build-newlib-armv8

cd build-newlib-armv8
 
export PATH=$HOME/gcc-linaro-aarch64-none-elf-4.8-2014.04_linux/bin:$PATH
 
../newlib-2.4.0/configure --disable-multilib --target=aarch64-none-elf CFLAGS_FOR_TARGET="-O2 -march=armv8-a -DREENTRANT_SYSCALLS_PROVIDED -D__DYNAMIC_REENT__"
 
make all
 

Dump:

cd aarch64-none-elf/newlib
aarch64-none-elf-objdump -d libc.a > libc.list
aarch64-none-elf-objdump -d libg.a > libg.list
aarch64-none-elf-objdump -d libm.a > libm.list


Notes:

File handles (fd) passed to and returned from this unit are int values which are 32-bit however internally Newlib stores these into the _file member of a _FILE structure (see below) and this is defined as short which is only 16-bit. Because of this we have to map each Ultibo handle to a TSyscallsEntry and use the functions SyscallsAddEntry, SyscallsRemoveEntry and SyscallsGetEntry which start at zero and increment to 65535.

The global errno variable (not used for reentrant version ) is defined in:

\newlib\libc\reent\reent.c 
  
int errno;
  

The global environ variable is defined in:

\newlib\libc\stdlib\environ.c 
 
char **environ = &initial_env[0];
  

The TZ environment variable is used by a number of functions in Newlib including tzset and strftime. This variable can be set on the command line or using the SetEnvironmentVariable() function in the Ultibo unit. See the GNU C library reference for details of the format and value of the TZ environment variable:

https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html

Constants


None available

Type definitions


None available

Public variables


None available

Function declarations


None available


Return to Unit Reference