Quick Steps to hosted libc

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
purevoid

Quick Steps to hosted libc

Post by purevoid »

Hi,

I just want to make sure I'm going about things the right way, so please forgive me if I sound a bit naive.

Anyways, I'm building an OS that uses the O'Caml language, and associated runtime. I've finally come to a wall where glibc code getting linked into my kernel is hurting DST (hardware exceptions and the like).

So, my thought is to get a libc compiled for DST, and then rebuild the O'Caml runtime using this libc instead of system one.

I'm not sure what the best libc implementation is to use for this task, so I've chosen newlib for now. Just want something that's easy to port. I had a look at dietlibc, but I think that might have some linux dependencies in it...

Anyways, I'm looking at osfaq2 to see how to do this. Are the steps as follows:

1. Build a custom binutils and gcc with newlib headers.
2. Compile newlib into a static library (do I use my new gcc?)
3. [Re]Build O'Caml runtime using this new gcc toolchain.
4. Build DST using this gcc toolchain, the new libc, and new ocaml runtime.
5. Run, and hope life will be very merry.

I assume then, I can just define the OS interfaces in some libc-interface.c file that's part of my kernel? And the linker will fix everything up so it's all good?

Kindest Regards,

Jonathan
purevoid

Re:Quick Steps to hosted libc

Post by purevoid »

Hmm, I've been giving newlib a go. Everything was fine for a bit, but now trying to compile cairo library, I start having include hell.

It seems newlib doesn't have a bunch of seemingly standard headers (stdint.h, and stddef.h for example).

Am I missing something completely obvious? Or am I better to try some other libc implementation that'll work better for building a hosted environment for my OS?

Jonathan
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Quick Steps to hosted libc

Post by Solar »

purevoid wrote: It seems newlib doesn't have a bunch of seemingly standard headers (stdint.h, and stddef.h for example).
stdint.h is new with C99 IIRC, and I couldn't find info about newlib stddef.h either.

You could look into PDCLib (see signature) for these two; PDCLib doesn't have much at this point, but it has those two. I also seem to recall that GCC itself builds them in some internal directory...
Am I missing something completely obvious? Or am I better to try some other libc implementation that'll work better for building a hosted environment for my OS?
I'm a bit confused. "Hosted" means, basically, user-space (as opposed to "freestanding" which is, basically, kernel-space). But from your initial post I understand that you want a libc to use in kernel space, to support your chosen language's runtime in kernel space?

I know next to nothing about OCAML... can someone enlighten me with one, two sentences about the language and whether its runtime can be used in kernel space?
Every good solution is obvious once you've found it.
purevoid

Re:Quick Steps to hosted libc

Post by purevoid »

Ohh, I found some interesting tips. I used -ffreestanding with the system compiler, and used -isystem for newlib includes. That seemed to work.

And yes, ocaml can run in kernel space. Stuff like printing/opening files just returns error condition/does nothing.

DST has been using ocaml as the kernel for about 9 months already ;-)
I know next to nothing about OCAML... can someone enlighten me with one, two sentences about the language
O'Caml is a multi-paradigm programming language: boasts static type checking, GC, and other functional language nicities. It also has it's own form of OO, as well as a number of imperative features (for/while loops, mutable data structures).

Jonathan
Post Reply