Question

Let’s assume that I wrote a primitive bootloader using assembly language. The computer is still on real mode. Now I want to write a primitive kernel and shell using C language. Questions:

1.Do I need to write a C Language compiler in assembly for this new OS or can I use a C compiler running on a different OS? I guess it could be both!

2.If I use a C compiler from a different OS, functions like printf () can be compiled to target the BIOS’s functions instead of the OS’s API to avoid dependencies?

3.If my bootloader switch the computer into protected mode the kernel will need to implement the equivalent to the BIOS functions?

4.Assuming a YES to question 3: If I use a C compiler from a different OS what is required to make it target the new OS kernel functions? Rewriting the headers files?

(EDIT) PD: These are theoretical questions. I don’t need specific details about the actual implementation. I just want to validate the concepts. Don’t feel obligated to answer all of them!

Était-ce utile?

La solution

  1. You can do either. I would strongly recommend to just use a standard compiler though. Writing a good compiler is very complex and time consuming.
  2. As long as you do not have an implementation of the standard library just don't use it. You can tell C-compilers to assume that there is no standard library and write your own printf-like functions.
  3. You lose access to the BIOS functions in real mode. If you need them you do need to reimplement them.
  4. Not much change is required actually. Executables are incomplete and require to be linked against something that implements the used standard library functions and whatever other libraries used. All you need to do is link the executable against a (possible self-written) library that somehow implements the required functions.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top