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?
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 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,
.data and so on. Similarly the flash memory for the actual program may be divided in several parts.