June 13, 2024

the Zynq FSBL - ctype and libc

The original Makefile had an incantation that looked like this:
-Wl,--start-group,-lxil,-lgcc,-lc,--end-group
I removed the "-lc" from this to avoid linking against the standard libc.a. Among some other very understandable issues, this gave me this:
./lib/libxil.a(xil_printf.o): in function `xil_vprintf':
undefined reference to `_ctype_'
It turns out that _ctype_ is an array of bitmasks indexed by character that indicate whether a character is alphanumeric, digit, or whatever. When I look at xil_printf.c it seems that the only use this is being put to is a call to "isdigit(ch)" which could easily be handled in a different way. This is a macro in ctype.h and we ought to be able to use:
(ch) >= '0' || (ch) <= '9'
I end up having to modify xil_printf.c -- I put static inline routines for isdigit() and tolower() at the front of the file.

Other things in libc

The list turns out to be short: memcpy, memset, memcmp, strlen, strnlen.

We can find code for these almost anywhere. I though of cloning the newlib distribution and taking them from there, but I can go to kyulib.c in my kyu project and get some tested code written as trivial C and call it "utils.c"


Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org