dspfun wrote:
How do you create a standalone C program? With standalone C program I
mean it should run "freestandi ng" on a CPU without an OS or other
supporting software/libraries linked to the C program. After the bios/
setup has done its initializations and "stuff" I would like to be able
to continue execution with my own C program. The C program will be
really simple to start with, for example just write an integer value
to a memory address.
Thanks!
A freestanding *C program* is not really different from a hosted C
program, except that the standard guarantees the existence of only a
small subset of the library functions; your compiler may but doesn't
have to provide more. (There are details like main() but that's beside
the point.)
A true difference comes from how the program is built as an executable.
1. There is magic that starts your program
2. There is magic that creates the C runtime environment once the
program starts
3. There is an implementation of the (available) library functions,
notably I/O and malloc if available.
In many cases, those things come with a compiler capable of or dedicated
to making freestanding applications /of some sort/.
If e.g. you are writing code for a dishwasher, the #1 magic must start
from the CPU reset (which starts your program), which also means your
program must be linked at an absolute address.
If you are writing PC BIOS extension, you can rely on your program being
started by BIOS scan, by which time some basic BIOS services may become
available.
If you convince your OS loader that your program is the default command
shell, you probably have everything the OS provides, except system().
So scenarios vary depending on the level of abstraction from the hardware
-- Ark