Search code examples
cmemoryembeddedramrom

RAM & ROM memory segments


There are different memory segments such as .bss, .text, .data,.rodata,....

I've failed to know which of them locates in RAM and which of them locates in FLASH memory, many sources have mentioned them in both sections of (RAM & ROM) memories.

Please provide a fair explanation of the memory segments of RAM and flash.

ATMEL studio compiler
ATMEGA 32 platform


Solution

  • Hopefully you understand the typical uses of those section names. .text being code, .rodata read only data, .data being non-zero read/write data (global variables for example that have been initialized at compile time), .bss read/write data assumed to be zero, uninitialized. (global variables that were not initialized).

    so .text and .rodata are read only so they can be in flash or ram and be used there. .data and .bss are read/write so they need to be USED in ram, but in order to put that information in ram it has to be in a non-volatile place when the power is off, then copied over to ram. So in a microcontroller the .data information will live in flash and the bootstrap code needs to copy that data to its home in ram where the code expects to find it. For .bss you dont need all those zeros you just need the starting address and number of bytes and the bootstrap can zero that memory.

    so all of them can/do live in both. but the typical use case is the read only ones are USED in flash, and the read/write USED in ram.