Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
    
Could you explain this a bit more deeper: The easiest way would be to copy the code you need to the boot loader. –  Sen Feb 1 '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 1 '11 at 15:04
add comment

Just use static linking. Dynamic linking will not work at that point.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.