How can C allocate memory without an OS? (Cases where OS is written in C)


I am following a course where we are writing an OS on a microcontroller.

The OS is written in C and the instructor initializes stack spaces for each thread in the following way.


How can the memory be allocated if there isn’t any OS already running to service this in the first place? Am I missing something?

>Solution :

You don’t have to "allocate" anything as such on a bare metal system, you have full access to all of the physical memory and there’s no one else to share it with.

On such a system those arrays end up in statically allocated RAM memory known as .bss. Where .bss is located and how large it is, is determined by the linker script. The linker script decides which parts of the memory to reserve for what. Stack, .bss, .data and so on. Similarly the flash memory for the actual program may be divided in several parts.

Leave a Reply Cancel reply