System calls

The latest evolution of the example operating system implemented in this chapter no longer allows our tasks to control system resources, such as input and output peripherals, and does not even allow the tasks to block voluntarily, as the sleep_ms function would not be allowed to set the pending flag to initiate a context switch.

The operating system exports an API that is accessible by the tasks through a system-call mechanism using the SVCall exception, handled by the isr_svc service routine, and triggered at any time from tasks through the instruction svc.

In this simple example, we use the svc 0 assembly instruction to switch to handler mode, by defining a shortcut macro, SVC():

#define SVC() asm volatile ("svc 0")

We wrap ...

Get Embedded Systems Architecture now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.