Is a boot loader without assembly language possible?

2.1k views Asked by At

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?

6

There are 6 answers

0
Brendan On BEST ANSWER

It's possible to:

  • design a compiler with built in support for whatever a boot loader may need, so that you can do everything in that compiler's language without assembly
  • use a lower level language (machine code)
  • design a computer where the firmware has direct support for higher level languages (e.g. modern UEFI can be used directly from C/C++)

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.

1
AudioBubble On

Technically speaking doesn't have to be assembly. Certainly possible to create a bootloader by other means

9
Clifford On

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.

0
user3344003 On

Technically, it is possible. You need an compiler that can generate specific instructions. You might be able to do it with a C compiler with in-line assembly. The old BLISS programming language might be able to do it in some implementations.

0
Muskovets On

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.

0
Jacen On

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.