Iam studying the concepts of operating system. The basic starting point of an OS is its Boot loader. Boot loader is most often written in assembly language. Is it possible to create a boot loader without even a single line of assembly language?
Is a boot loader without assembly language possible?
2.1k views Asked by nandha kumar AtThere are 6 answers
It is certainly possible to create a boot-loader without assembly language, and I doubt your assertion that a boot-loader is:
"most often written in assembly language."
However the question in the title differs from the question in the body; a boot-loader is not part of the OS, and an OS that includes pre-emptive scheduling almost certainly needs some assembly language code to at least perform context switches.
If you have Intel BITS, you can write loader in Python.
Otherwise, you can use UEFI libraries to write loader in C or C++.
Instead this ways, you can write a compiler that converts your C++ code into X86 machine code and creates special assembly to boot your kernel. Then you may not write a bootloader.
And, if you do not have BITS or UEFI and you don't want to do this, you can't do this.
Well, the starting point of an OS is not the bootloader. On some systems (I've done this on an ARM7) you can run your OS without any bootloader. If you don't need any bootloader, you don't need any assembly instruction in your bootloader.
What about the OS itself ? The primary role of an OS is scheduling several tasks, each task having its own context. Most processor architecture rely on a stack to allocate memory for local variables. Languages usually abstract the concept on stack, and only keep the "local variable" concept, and thus are unable to switch the tasks contexts. So, basically, it is not possible to write an OS only in C language. Nevertheless, some languages give access to every processor resources (mostly internal registers). For instance, the PL/M51 allows to write an OS without any assembly for an intel 8051 processor.
To sum up, the answer is: assembly isn't mandatory, you just need a language with enough expressive power to describe the tasks you OS shall perform.
It's possible to:
However, none of this has anything to do with practicality. For a lot of cases (e.g. 80x86 BIOS) its far easier to use some assembly than to avoid it. Note that "some assembly" may just mean wrappers around firmware's functions and a little initialisation code; where the majority of the boot loader is in some other language.