Search code examples
cassemblyoperating-systemosdevhobby-os

Port GNU C Library to minimal hobby OS


So I have a minimal OS that doesn't do much. There's a bootloader, that loads a basic C kernel in 32-bit protected mode. How do I port in a C library so I can use things like printf? I'm looking to use the GNU C Library. Are there any tutorials anywhere?


Solution

  • Ok, porting in a C library isn't that hard, i'm using Newlib in my kernel. Here is a tutorial to start: http://wiki.osdev.org/Porting_Newlib.

    You basically need to:

    • Compile the library (for example Newlib) using your cross compiler
    • Provide stub-implementations for a list of system functions (like fork, fstat, etc.) in your kernel
    • Link the library and your kernel together

    If you want to use functions like malloc or printf (which uses malloc internally), you need some kind of memory management and simplest working implementation of sbrk.