This commit is accompanied by a new release of the Ultibo core installer, some changes required to support C libraries are not usable without the installer update so if you are wanting to take advantage of them please ensure you also download and install the latest Ultibo core installer.
List of changes:
- Add Syscalls unit to support inclusion of standard C library
- Add Ultibo specific versions of libc.a, libm.a and libgcc.a for ARMv6, ARMv7 and ARMv8
- Enable the SQLite package and add platform support routines for Ultibo core
- Enable SQLite in the fcl-db package
- Enable FreeType2 in the fcl-image package
- Add new ClockDeviceSetRate, ClockDeviceProperties and ClockDeviceWrite64 functions for Clock devices
- Add Clock device driver for ARM Timer on BCM2835, BCM2836 and BCM2837
- Fix FramebufferDeviceCopyRect incorrect stride value in overlapped (Left to Right) copy
- Fix BCM2708/9/10SPI0WriteRead to prevent cleaning or invalidation if DMA source or destination buffers are nil
- Fix for DMARequestComplete to prevent referencing a request buffer after it has been released
- Fixes for DMARequestSubmit and DMARequestCancel to match DMARequestComplete changes
- Fix missing MEMORY_PAGE_SIZE in PlatformQEMUVPB
- Fix FileSysLoggingStart to not fail if target is empty
- Adjust KeyboardGet to be consistent with KeyboardPeek
- Fix decoding of ShareMode parameter in FSCreateFile and TFileSysDriver.CreateFile
- Change ARMv7 page table attributes to remove use of Write-Through caching
- Move GENERIC_* file access constants to GlobalConst
- Move FILE_SHARE_* file sharing constants to GlobalConst
- Add FSFileGetAttrEx and TFileSysDriver.FileGetAttrEx function to return attributes from a handle
- Change to using EABIHF application binary interface (ABI) in all cases for compatibility with GCC
- Fix Read and ReadLn functions not returning on Enter key
- Change LineEnding constant in System unit to be CRLF instead of LF
- Fix USBRequestComplete to prevent referencing a request buffer after it has been released
- Fixes for USBRequestSubmit and USBRequestCancel to match USBRequestComplete changes
- Add __buildrtl.bat file to Core to allow building with automated tools
- Fix GetDiskFreeSpaceEx to not fail if lpTotalNumberOfFreeBytes is nil
- Change GetNumaHighestNodeNumber (Dummy) to comply with MSDN example
C library support
Ultibo core now supports including static libraries compiled with the GCC compiler in your project in order to use their functionality. As part of this support we now provide a specific build of the standard C libraries libc.a and libm.a which contain much of the support code needed by libraries compiled in C.
This release also includes a new Syscalls unit which provides the interface between the standard C library and Ultibo core and handles operations like memory, console i/o, date and time and file handling.
It is important to note that you cannot simply take libraries from another platform such as Linux and include them in your Ultibo project, at the very least they need to be recompiled with the appropriate parameters, depending on the requirements of the library some may also need you to supply support functions that interface the library to Ultibo core. We have provided two libraries with the release to show how the process works, the FreeType2 library requires no additional support code and uses only standard C library functions to manage memory, files and other operations, the SQLite3 library on the other hand needs a complete platform support layer in order to implement the required functions for memory, locking and file access.
The standard C library implementation that is included is based on Newlib which is an open source implementation of the C library supplied by RedHat. The Syscalls unit provides the functions needed to support the standard C library, one of the most critical of these is memory allocation. Most C code uses malloc() or similar functions to allocate memory and the Newlib library provides optimized versions of these functions which are compatible with a wide range of code, these functions are ultimately connected to the Ultibo core GetMem/FreeMem functions via the sbrk() call which requests memory in the form of a linear heap starting at a given point and incrementing until the end of available memory. In order to support this model the Syscalls unit maps all memory allocated to the C library into a virtual memory space which is expanded on demand in fixed size blocks, the behavior, mapping and allocation sizes of this memory management can be adjusted by a number of parameters in the GlobalConfig unit, see the SYSCALLS_HEAP_* variables for more information.
Additional information will be added to the forum and the wiki over time to explain in more detail how to compile a C library for use in your projects, including the parameters needed for correct interaction between the library and Ultibo core.
Change to EABIHF application binary interface (ABI)
In order to obtain compatibility between code compiled with FreePascal and code compiled with GCC it has been necessary to change the application binary interface (ABI) used by Ultibo core to be the ARM Embedded ABI (EABI) standard with hardware floating point support (HF). It might seem obvious that code running on an ARM processor should use the ABI defined by ARM but unless told otherwise FPC uses what it terms the "Default" ABI which while very similar to EABI has subtle differences that make it incompatible for certain data types and function parameters.
The change to EABIHF has been enabled in the FPC compiler as well as all other elements of Ultibo core so you should not need to take any action unless you build your projects or the RTL from the command line, the wiki will be updated shortly to reflect the changes needed when compiling FPC or the RTL and you should update your process to take account of these changes.
This change will not have any impact on your code unless you interface with assembler functions in which case you should review the parameters passed to and from those functions in order to ensure they are compliant with the ARM EABI.
Changes to DMARequestComplete and USBRequestComplete functions
For some months the wiki Current Status page has contained an issue for Very occasional deadlocks during console scroll which we have finally managed to track down. While the description of the bug doesn't make it appear serious the actual cause turns out to be very important because it would affect more and more operations over time in ways that would be difficult to diagnose. The issue turns out to be a situation where the DMARequestComplete() function could reference a DMA request after it had already been released which would result in an exception or a crash, once found it was evident that the USBRequestComplete() function also had the same issue and although not seen in any current issues the problem could occur at any time.
Removal of Write-Through caching in page table configuration
This release contains a small change to the page table configuration for ARMv7 processors to remove the use of Write-Through caching in all circumstances. In response to a forum post and following extensive investigation it was found that the ARMv7 and later processors, including the Cortex A7 in the Raspberry Pi 2B and the Cortex A53 in the Raspberry Pi 3B no longer implement Write-Through cache in order to reduce the complexity of the chip design. Unfortunately instead of removing the option and making it mandatory to use a different cache mode the designers decided to take the very unusual step of making all memory pages marked as Write-Through actually act as uncached instead which can significantly change the performance of certain code sequences.
In order to address this change in the behavior of the chip Ultibo core now uses Write-Back caching in place of Write-Through which removes the performance penalty caused by the design change above without impacting any other aspect of the design and behavior of Ultibo itself.
We will write a brief outline with more details of this issue and the way it impacts performance shortly however you should not assume that this change provides any sort of linear performance gain, as noted above the change has a significant affect on certain code and yet has little or no impact on other code.
For details of how to apply the latest source to your Ultibo core installation and rebuild your run time library see the wiki page Building from Source or watch the Building the RTL video on YouTube.