In computer science, bare machine refers to a computer executing instructions directly on logic hardware without an intervening operating system. Modern operating systems evolved through various stages, from elementary to the present day complex, highly sensitive systems incorporating many services. After the development of programmable computers but prior to the development of operating systems, sequential instructions were executed on the computer hardware directly using machine language without any system software layer. This approach is termed the "bare machine" precursor to modern operating systems. Today it is mostly applicable to embedded systems and firmware generally with time-critical latency requirements, while conventional programs are run by a runtime system overlaid on an operating system.
Advantages
For a given application, in most of the cases, a bare-metal implementation will run faster, using less memory and so being more power efficient. This is because operating systems, as any program, needs some execution time and memory space to run and these are no longer needed on bare-metal. For instance, any hardware feature including inputs and outputs are directly accessible on bare-metal while using an OS imply generally the call to a subroutine, consuming running time and memory.
Disadvantages
For a given application, bare-metal programming requires more effort to work properly and is more complex because the services provided by the operating system and used by the application have to be re-implemented regarding the needs. These services can be:
Memory management: Storing location of the code and the data regarding the hardware resources and peripherals.
Interruptions handling.
Task scheduling, if the application can perform more than one task.
Peripherals management.
Errors / faults management, if wanted and / or needed.
Debugging a bare-metal program is difficult since:
There are no software error notifications nor faults management, unless they have been implemented and validated.
There is no standard output, unless it has been implemented and validated.
The machine where the program is written cannot be the same where the program is executed, so the target hardware is either an emulator / simulator or an external device. This forces to setup a way to load the bare-metal program onto the target, start the program execution and access the target resources.
Bare-metal programming is generally done using a close-to-hardware language, such as C++, C or assembly language, which are generally thought to be harder to master. All the previous issues inevitably mean that bare-metal programs are very rarely portable.
Examples
Early Computers
Early computers, such as the PDP-11 allowed programmers to load a program, supplied in machine code, to RAM. The resulting operation of the program could be monitored by lights, and output derived from magnetic tape, print devices, or storage.
Embedded systems
Bare machine programming remains common practice in embedded systems, where microcontrollers or microprocessors often boot directly into monolithic, single-purpose software, without loading a separate operating system. Such embedded software can vary in structure, but the simplest form may consist of an infinite main loop, calling subroutines responsible for checking for inputs, performing actions, and writing outputs.
Development
The approach of using bare machines paved the way for new ideas which accelerated the evolution of operating system development. This approach highlighted a need for the following:
Input/output devices to enter both code and data conveniently:
* Input devices, such as keyboards, were created. These were necessary, as earlier computers often had unique, obtuse, and convoluted input devices.