Newlib Toolchain (or32-elf)
Introduction
This page contains information about the OpenRISC software toolchain based on the newlib C library.
The OpenRISC 1000 port of the newlib library aims to provide a library against which applications to be run on the bare-metal hardware, without an opearting system, can be compiled. It is also used as the library against which programs are compiled in the when running the GCC testsuite.
Installation
Newlib Toolchain 1.0rc1 Precompiled Binaries
The following are precompiled OpenRISC 1000 toolchains for a variety of platforms.
They contain version 1.0rc1 of the newlib (or32-elf) toolchain. The included components are GCC-4.5.1, binutils-2.20.1, newlib-0.18.0, GDB-7.2 and or1ksim-0.5.1.
Download
OpenRISC
newlib toolchain 1.0rc1 compiled under Ubuntu x86/i686 (32-bit)
OpenRISC
newlib toolchain 1.0rc1 compiled under CentOS-5.5 x86_64 (64-bit)
OpenRISC
newlib toolchain 1.0rc1 compiled under OS X 10.6 (Snow Leopard) (Note: no libstdc++-v3)
Extract and install
The following commands indicate how to install the toolchain from the download archive. The tools are installed to the /opt path and symbolic links are created to more general path names (which helps with switching to more updated versions of the toolchain later.) The shell's PATH environment variable must be updated.
cd /opt
tar xjf 〈path to downloaded archive〉/〈archive name〉
sudo ln -s or32-elf-1.0rc1 or32-elf
sudo ln -s or1ksim-0.5.1rc1 or1ksim
Finally, open your .bashrc file (typically just ~/.bashrc) and add the following at the end. Note: If the toolchain was installed elsewhere, please use the appropriate path.
export PATH=$PATH:/opt/or32-elf/bin:/opt/or1ksim/bin
Toolchain Use
The newlib-based toolchain contains the standard GCC libraries of libgcc and libstdc++-v3 and those included in newlib; libc, libm and libgloss.
The OpenRISC port provides a set of support functions for controling basic CPU functions. The libgloss port provides basic board support that should allow easily addition of new boards.
Compile-time options
At present the newlib libraries are not linked by default. The following options must be passed at compile time. (Note that we plan to make this the default in coming releases.)
or32-elf-gcc -mnewlib -mboard=boardname
Board support
Libgloss now provides an easy way of adding additional boards by way of linking in a small library containing just a few values used at run-time to configure the system. Each board has its own path and libboard.a in the /install_path/or32-elf/lib/boards directory. The boardname above should correspond to a directory under this path.
Libgloss also implements system calls, and at present only basic I/O via UART is implemented for the read and write system calls.
In toolchain version 1.0rc1 a handful of boards and the or1ksim architectural simulator are supported.
| Board | Description |
|---|---|
| or1ksim | or1ksim simulator, no peripherals |
| or1ksim-uart | or1ksim simulator with a UART |
| ordb1a3pe1500 | ORSoC dedvelopment board 1, A3PE1500 part, as in ORPSoC |
| ml501 | Xilinx ML501 board, as in ORPSoC |
| orpsocrefdesign | ORPSoC reference design |
For example, to compile with support for the ordb1a3pe1500 board, one would pass the following options at compile-time.
or32-elf-gcc -mnewlib -mboard=ordb1a3pe1500
Each libboard.a defines the following symbols:
| Symbol | Description |
|---|---|
| _board_mem_base | Base of main memory |
| _board_mem_size | Size of main memory |
| _board_clk_freq | Frequency in hertz of CPU clock, also presumed as UART clock |
| _board_uart_base | Base address of a UART 16550 peripheral |
| _board_uart_baud | Desired buad rate for UART |
| _board_uart_IRQ | IRQ number of UART |
Adding additional boards is as simple as creating a path under the /install_path/or32-elf/lib/boards directory with the board's name and creating a libboard.a with the appropriate symbols set to the right values.
For examples, see the existing boardname.S files in the libgloss/or32 path in the newlib port source.
Support library
A set of support functions providing simple access to control various features of the CPU have been added.
They are accessible via the inclusion of the following header.
#include <or1k-newlib-support.h>
The following functions are provided
| Function Name | Arguments | Description | Return value |
|---|---|---|---|
| or1k_interrupt_handler_add | int irq, void(*function_name)(void*) | Install function_name as handler for interrupt at IRQ irq | none |
| or1k_interrupt_enable | int irq | Enable generation interrupt at IRQ irq in PICMR | none |
| or1k_interrupt_disable | int irq | Disable generation of interrupt at IRQ irq in PICMR | none |
| or1k_exception_handler_add | int vector, void(*function_name)(void*) | Install function_name as handler for vector at address (vector*0x100) | none |
| or1k_mtspr | unsigned long int spr, unsigned long int value | Write SPR[spr] = value | none |
| or1k_mfspr | unsigned long int spr | Read SPR[spr] | SPR[spr] |
| or1k_report | unsigned long int value | Simulator report function with l.nop 0x2 | none |
| or1k_icache_enable | void | Enable instruction cache in SR | none |
| or1k_icache_disable | void | Disable instruction cache in SR | none |
| or1k_icache_flush | unsigned long addr | Flush addr from instruction cache | none |
| or1k_dcache_enable | void | Enable data cache in SR | none |
| or1k_dcache_disable | void | Disable data cache in SR | none |
| or1k_dcache_flush | unsigned long addr | Flush addr from data cache | none |
| or1k_immu_enable | void | Enable instruction MMU in SR | none |
| or1k_immu_disable | void | Disable instruction MMU in SR | none |
| or1k_dmmu_enable | void | Enable data MMU in SR | none |
| or1k_dmmu_disable | void | Disable data MMU in SR | none |
| or1k_timer_init | unsigned int hz | Initialise timer to count at hz hertz, reset tick counter, install handler | none |
| or1k_timer_enable | void | Start timer, enable timer interrupt in SR | none |
| or1k_timer_disable | void | Stop timer interrupts | none |
| or1k_timer_get_ticks | void | Read tick counter value | tick counter |
| or1k_timer_reset_ticks | void | Reset tick counter value | none |
Functions still missing: interrupt acknowledge/clear function to clear bit in PICSR, cache region flush, MMU map function.
These functions are implemented in the or1k-support.c and or1k-support-asm.S files in the newlib/libc/machine/or32 path in the newlib port directory. The header, or1k-newlib-support.h is found in the newlib/libc/machine/or32/include path. Note that this header and the OR1K spr-defs.h header are installed also in the /install_path/or32-elf/include path.
Contributions are welcome to help fix and improve this support library.
Feel free to post any suggestions or offers to assist the project to the OpenRISC forum or openrisc_team@opencores.org
Upcoming Changes
Please note that the versions currently in the OpenRISC project repository differ from the 1.0rc1 in the following ways:
-mnewlib flag no longer required
This flag will no longer be mandatory to imply the use of the newlib C library in upcoming releases.
Support header
The support header will be renamed or1k-support.h
Build From Source
This section will contain information about compiling the toolchain from the source contained in the repositories. Note that this is only recommended for those developing the toolchain itself, or wishing to obtain a version more recent than the previous release.
Download source
First obtain a checkout of the OpenRISC GNU tool source directory. Note that this may take a while as it contains many files, and is large in size, which may cause the checkout to stop part-way through. Run the following command until no more files are downloaded to be sure all of the files were successfully checked out.
svn co http://opencores.org/ocsvn/openrisc/openrisc/trunk/gnu-src
Prerequisites
Libraries
Various libraries are required to compile the GNU tools. The following is a command for Debian-based GNU/Linux systems to ensure the required libraries are installed.
sudo apt-get -y install build-essential make gcc g++ flex bison patch texinfo libncurses-dev libmpfr-dev libgmp3-dev libmpc-dev libzip-dev
Please post on the OpenRISC forum if any tools are missing, or to provide a one-liner to install the required prerequisites on another distribution.
or1ksim
Ensure or1ksim is built and installed somewhere on the system. See the guide on the or1ksim page for information on downloading, building and installing it.
It is assumed in the rest of this that install prefix used when building or1ksim was /opt/or1ksim - if this is different to the path used then please substitute the correct one appropriately in the following commands.
Install path
The install path of the compiled toolchain used in the following examples is /opt/openrisc - it is recommended this is used, but if an alternative is desired, then substitute /opt/openrisc appropriately.
Create the install path and ensure it has sufficient permissions to allow the user to write to it when performing the installation of the toolchain.
Building
The script used to build the toolchains is bld-all.sh and it is found in the gnu-src/ path. It will create a unified build environment when compiling the GNU tools (binutils, GCC, GDB.)
There are two toolchains that can be compiled with bld-all.sh, one with the newlib C library, and one with the uClibc C library. The following details how to compile the newlib-based toolchain.
For a full list of options provided by the build script, run it with the --help option:
./bld-all.sh --help
Newlib toolchain only
To build and install only the newlib (or32-elf-) toolchain:
./bld-all.sh --force --prefix /opt/openrisc --or1ksim-dir /opt/or1ksim --no-uclibc --no-or32-linux
PATH Variable
Be sure to add the install prefix's binaries directory to the PATH environment variable so the tools can be found.
Add the following line to the end of the .bashrc file:
export PATH=$PATH:/opt/openrisc/bin
Page Maintainer
This web page is maintained by
