1

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?

7
  • You might want to give more background on this. Because, well, maybe has written a C library that makes it easy to write bootloaders for a specific architecture, but that doesn't, in the end, mean that there was no one who ever wrote a line of assembler. Commented Jun 22, 2015 at 11:29
  • Can we write boot loader in C (purely, without even a single assembly code)? Commented Jun 22, 2015 at 11:31
  • I just answered that question in my comment. I think you need to think harder about what you're actually asking., Commented Jun 22, 2015 at 11:32
  • I have written boot-loaders that have no assembler code, so yes. You need to change the title of this. Writing an OS without assembly language is a different question than writing a boot-loader with out assembly language, and the answer is different too. Commented Jun 22, 2015 at 11:38
  • 1
    Yes. Write it directly in machine language instead and bypass the assembler. Commented Jun 22, 2015 at 15:38

6 Answers 6

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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

1 Comment

well, I guess in C, however at some point you need to use assembly for 'talking' to hardware etc...
0

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.

Comments

0

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.

Comments

-1

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.

9 Comments

I am just learning. So I'm sorry. Sir, If so, then OS cannot be written without assembly?
at some point you will need to write assembly is you write a new OS. how will you 'talk' to the hardware?
@nandhakumar : At its very simplest a kernel context switch requires the stack-pointer to be switched; there is no high-level language construct in any systems-level language that I know of that can do that - so at least assembler is required for that, and perhaps other processor specific core (non-memory mapped) register access.
@FatGiant : "Talking to the hardware" is not an issue if the I/O is memory mapped. The issue is modifying core registers that are not memory mapped.
@FatGiant : I have the advantage perhaps of being an embedded systems developer where "talking to the hardware" directly is everyday. For example if a hardware device has a register mapped to say address 0x8000, then uint16_t input = *0x8000, will read it (without assembler). Many operating systems on targets with memory-management units will stop user level code from doing that, but not the OS or device driver code, and many embedded systems lack an MMU in any case, or even the concept of "user level".
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.