news:d66564b7-b531-48ed...@he10g2000vbb.googlegroups.com...
> On Jan 30, 3:26 pm, James Harris <
james.harri...@gmail.com>
wrote:
...
> > > What you need to look at is newlib. It's designed for
> > > use on embedded targets.
> > > See
http://sourceware.org/newlib/
> > >
> > > libc support for bare metal 8-bit AVRs is also available in
> > > the form of avr-libc at
http://www.nongnu.org/avr-libc/
>
> > They look useful. In particular newlib looks great.
>
> I tried using C libraries. As far as I could see, though, they
> are largely an all-or-nothing solution. In other words they
> expect to be compiled as a unit and form a single object file.
That's too bad. I would've thought they were independent.
> I wanted only a few routines. I know in theory that I could have
> copied the sources for just the functions I needed but some of
> them have dependencies. Too, the sources I saw had loads of
> #ifdef conditional compilation which I didn't want.
I'll take it that it's far more than just a C++ wrapper or just an
check to see if the file was included already.
I might've recommended a smaller, simpler C library or a kernel
library, maybe Paul Edward's PDPCLIB or Luca Abeni's OSLib.
> So I ended up writing the routines I needed so far. There were
> only a few of them. They are generally assembler interfaces with
> the BIOS to allow C code to call BIOS routines. So far only one
> routine is purely in C. It is the printf formatting routine -
> essentially sprintf. It parses all the format specifications
> but I have only added the actual formatting routines - integers,
> hex, chars, strings, padding and alignment - as I needed them.
> Notwithstanding the current routine[']s limitations writing
> it was easier than I anticipated. And because it does not depend
> on any other C library routines it is self contained.
Good job!
> As a bit of an aside I am not sure that sprintf is a good idea
> in the long run.
Yeah ... probably not, but it's the "C-way". I think I only use
two maybe three formats with sprintf() in my kernel. If
attempting to eliminate it, I'd probably break it into separate
custom routines. I generally prefer to use hexadecimal. It's
easy to convert integers to hex in C.
It's easy to change sprintf() to something more safe or set it up
to use a kernel function instead, if your C compiler has a
pre-processor. E.g., I sometimes need a modified printf(), e.g.,
for indentation, or a printf() function local to my application.
What I do in that case is use a similar name, so people have an
idea of what it is, and then have #defines to selectively set it
to a standard C libary function or to my custom function.
#if 1
#define LOCAL
#endif
#ifndef LOCAL
#include <stdio.h>
#define l_printf printf
#endif
...
l_printf("...blah...\n");
...
> For example, to format a 4-byte unsigned integer on a 16-bit
> machine seems to require a format specification change from
> %u to %lu. The problem with that is that %lu will be wrong
> for the same value if compiled on a 32-bit machine. I believe
> C99 provides workarounds but they are cumbersome/ugly
> and I am not sure well supported on 16-bit compilers.
The printf() sizes are going to be relative to the host machine's
sizes. Some of the larger printf() sizes are not standardized,
but frequently used. Unix and POSIX environments frequently have
and use a bunch that are not ANSI/ISO C/C++. I wouldn't expect a
16-bit compiler to support any integer size above 16-bits. I.e.,
I'd only expect machine native integer size. Although, many
16-bit compilers do seem to support using two 16-bit words as a
32-bit integer. I definately wouldn't expect 64-bits in a 16-bit
compiler.
> All-in-all the code development is progressing. The program
> can be run under MS-DOS but does not use MS-DOS. I haven't
> written the exe loader for it yet but it should run just on the
> BIOS as it only makes BIOS calls.
Great job!
Rod Pemberton