Table of Contents

newlib

newlib is a library meant for embedded systems. It contains implementations for all of libc and libm, the standard C library and the standard Math library. newlib can be compiled for a variety of embedded systems, I have compiled it for target=mipsel-elf. newlib isn't entirely complete though, it requires a few operating-system like calls, such as read, write and _exit. Stubs for these functions are given in libgloss/libnosys with some machine-independent implementations in libgloss. The most important of these to us are:

write (similar to putc)

_exit (similar to exit)

sbrk (required for dynamic memory allocation)

read (similar to getc)

libgloss has implementations of sbrk, read, and write, but for I/O, it requires you to write implementations for inbyte and outbyte (similar to getchar and putchar). This is easy to do in the Verilog backend (use $write) as well as the MIPS backends (already implemented as print_c_uart). If inbyte and outbyte are implemented, supposedly you get all of stdio working for free. With the simple sbrk implementation, dynamic memory allocation should also work for free (for Verilog backend, detect sbrk call as impossible to put to hardware for now).

There is a problem with printf, putchar, and other stdio functions. The current newlib implementation is very general and implements these using file open/close with stdout as the file. With either backend, there is no notion of files, so this is a problem. Also, this file implementation uses sbrk, implying dynamic memory allocation. I don't think we'll really need that for just printing to stdout. I'll try to look into modifying newlib to make all output go to stdout, skipping the need for file operations and sbrk for I/O.

Other libraries

Another important library is libgcc. libgcc includes arithmetic operations that the host processor cannot perform directly, including soft float libraries. If we want to support floating point, one possible way would be to include libgcc and compile with a -msoft-float switch and let LegUp synthesize the soft float libraries into hardware. libgcc is automatically compiled when compiling gcc from source.

Building newlib and gcc, cross-compiled for mipsel

This site is very good: http://www.ifp.illinois.edu/~nakazato/tips/xgcc.html. I used TARGET=mipsel-elf. To compile gcc by source, you will also need gmp and mpfr libraries. Download the source and extract the gmp source into the gcc source directory into folder gmp. Similarly, extract the mpfr source into folder mpfr. While compiling, there was a header problem when configuring. Just copy the required headers from the gmp source directory to build-gcc/gmp and continue `make all-gcc`. I compiled binutils, gcc and newlib for a mipsel target. binutils is about 2 minutes, gcc and newlib take more than an hour together.

Log

July 5, 2010

Compiled gcc, newlib for mipsel-elf

Compiled libnosys and two temporary libraries that define _exit, inbyte and outbyte for gxemul/tiger mips

Simplified commands work such as outbyte and write. strlen works, so puts(str) can be replaced by write(0, str, strlen(str))