I would like to use some the functions given by libc at the boot loader stage itself. Is it possible to get them at that stage of loading?
3 Answers
You'll most likely have to write your own versions of the functions you want, though in some cases you may be able to use libc source code as a starting point. The functions in libc itself are written under all the assumptions of a UNIX userspace program, including:
- the presence of the kernel (or more specifically, the syscall interface to the kernel)
- a flat memory model
- a dynamic linking infrastructure (unless statically linked)
and at the bootloader stage, you have none of these. Instead, (by default, under Intel) you've got the BIOS, a segmented memory model, no memory protection, and full reign of the machine.
It's the same reason you see the custom printk()
function in kernel code instead of printf()
-- the assumptions that libc's printf()
makes just don't apply in kernel space.

- 16,682
Yes. The easiest way would be to copy the code you need to the boot loader.
Which functions are these? You should understand that you can't use them if they rely on system calls to fulfill their duty.

- 7,223
-
1Could you explain this a bit more deeper: The easiest way would be to copy the code you need to the boot loader. – Navaneeth Sen Feb 01 '11 at 14:15
-
@Sen: do you know how to copy and paste text between files? Just how much deeper do you need it? :D – alex Feb 01 '11 at 15:04
Just use static linking. Dynamic linking will not work at that point.