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:
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.
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.
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.
July 5, 2010
July 6, 2010
../newlib-1.18.0/configure –prefix=$PREFIX –target=i386 CC_FOR_TARGET=llvm-gcc CFLAGS=-emit-llvm AR_FOR_TARGET=llvm-ar AS_FOR_TARGET=llvm-as LD_FOR_TARGET=llvm-ld NM_FOR_TARGET=llvm-nm RANLIB_FOR_TARGET=llvm-ranlib –enable-newlib-io-long-long –disable-newlib-io-float –disable-newlib-supplied-syscalls