In the early days of computing, there were no operating systems. The programmer wrote a program that executed directly on a computer. This type of programming is done also today, typically in embedded systems. The reason for not using an operating system in an embedded computer could be safety regulations, but it could also be size, in the sense that the computer used is too small to make it cost-effective to use an operating system.
Computers running without operating systems can be said to run programs on the bare metal. Such programs can be developed, and executed, also on modern computers. The task of making a bare-metal program for a 32-bit Intel-x86-compatible processor is described in the book chapter The Bare Metal.
It is shown, in chapter The Bare Metal, how a bare-metal program can be constructed, and how it can be made to execute. The exercise of creating a bare-metal program for a computer where an operating system is normally used can be both rewarding and challenging. It will also give you insight in how hardware and software operate together, with a focus on the early phases of program execution, directly after the computer is started.
The interactions between software and hardware are further elaborated in chapter Hello world. The chapter Hello world presents an analysis of the program from chapter The Bare Metal, and the assembly instructions corresponding to the C statements used in the program are described.
The relations betwen statements in the C programming language and the corresponding assembly instructions are described more systematically in chapter C and Assembly. A selection of the available assembly instructions in a 32-bit Intel-x86-compatible processor is presented. It is also described how assembly instructions are used when performing function calls and returns from function calls, and how parameters to functions are handled.
Embedded systems often react to events from the outside world by receiving interrupts. The interrupts are generated when events occur. Example events could be that a new measurement value is ready, or that a new data item is available on a communication channel. The interrupts are generated as electrical signals, which while passing through a dedicated electronic compoment, often referred to as an interrupt controller, are converted to a format suitable for the computer used. The resulting effect is that an event is generated, such that the flow of execution is interrupted. The program then continues, for a short while, by executing a dedicated routine, referred to as an interrupt handler.
The task of an interrupt handler is to perform immediate actions that are necessary, such as storing an incoming measurement value or an incoming data communication value in a storage buffer. When the interrupt handler has finished its task, the ordinary execution of the program continues, at the point where it left off when the interrupt occurred.
Interrupts, and interrupt handlers, are described in chapter Interrupts.
Programs executing on a computer peform their work mostly on behalf of the computer's processor. The processor, which in this book is a a 32-bit Intel-x86-compatible processor, reads instructions, in binary form but possible to describe using assembly language as shown in chapter C and Assembly. For each instruction read, the processor takes actions. The actions depend on the specific instruction read, but also on data available to the processor.
Memory comes in different forms. There is memory referred to as RAM, meaning random access memory. RAM can store programs and data, and it is often referred to as main memory, and sometimes also as primary memory. In addition, there are smaller-sized memories, possible to access more quickly than what can be done for RAM. These smaller-sized memories are referred to as cache memories, or simply caches.
A third type of memory is referred to as secondary memory or secondary storage. This type of memory is slower to access than RAM, but it often has the advantage that its information is kept also when the power to the computer is switched off.
Memory, in different forms, combined with software examples illustrating how to write to and read from memory, is the topic of chapter Memory.
Besides the processor and the different types of memory, there are components, often referred to as devices, attached to a computer. In a modern computer, the devices may be part of the same physical silicon chip on which the processor is placed. Devices can be thought of as components aiding the processor managing specifc tasks not directly expressable using instructions, but also as components aiding the processor in its communication with the outside world. Examples of devices used for communication are components used for serial communication using an UART, or for network communication using a network interface.
Examples of devices used for internal tasks, not explicitly involving communication with the outside world, include an an interrupt controller, for handling interrupts, or a cache controller for managing cache memory. Another example is a DMA controller, for handling rapid transfer of data to and from memory without the processor being directly involved.
Communication with the external world is covered in chapter Communication. Communication protocols are described, and interactions between hardware and software when performing communication is addressed.
The final two chapters, called Development and describe how embedded software can be developed, using tools for creating an executable program, and how it can be deployed, by installing the program and making it execute, in an embedded system. The development process involves selecting tools, such as compiler, linker, and debugger. An overview of such tools is given, and examples of their usage are presented.
The deployment of software in an embedded system involves taking into account the hardware architecture and the choice of operating system. It must be decided how the software shall be distributed, if more than one processor is present in the system, and it must also be decided if an operating system, and if so what kind, shall be used. These questions are discussed and illustrated with software examples in chapter Deployment.