Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 933
Mohamed Moustafa Avatar asked Sep 12 '25 00:09

Mohamed Moustafa


2 Answers

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.

like image 108
old_timer Avatar answered Sep 13 '25 13:09

old_timer


They are located wherever your project's linker script defines them to be located.

Some targets locate and execute code in ROM, while others may copy code from ROM to RAM on start-up and execute from RAM - usually for performance reasons on faster processors. As such .text and .rodata may be located in R/W or R/O memory. However .bss and .data cannot by definition be located in R/O memory.

like image 28
Clifford Avatar answered Sep 13 '25 15:09

Clifford