Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

int32_t TCB_STACK[NUM_OF_THREADS][STACK_SIZE];

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading