I wrote a custom (VERY basic “Hello world!”) bootloader in Assembler and I would like to execute a C program in that. Would the C program work, or fail due to a lost stdio.h file? And how could I bundle the C program along with the bootloader into a single .bin file to dd to a flash drive/CD?
I wrote a custom (VERY basic Hello world!) bootloader in Assembler and I would
Share
I’m not sure what you mean by “lost
stdio.h“, but many C runtime functions, including those prototyped instdio.h, are implemented using system calls. Without an OS running, those system calls won’t work.It is possible to write C code that runs without an OS, for example most common bootloaders have just a tiny amount of assembler and mostly C code. The trick is to avoid using runtime libraries. Alternatives to syscalls, for e.g. display, are BIOS calls and hardware-specific I/O.
To take just one example, in addition to dynamic allocation,
fopenin read mode needs the following low-level operations:freadandfgetcto find the data on diskYou don’t have an OS to help with any of that, your C code will need to implement a driver (possibly calling the BIOS) for block read, and implement the behavior of the other steps.