3
votes

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

3
ATMEL studio compiler ATMEGA 32 platformMohamed Moustafa
does it make any difference if i am using diff compiler or platform ?Mohamed Moustafa
@MohamedMoustafa Yes, it makes a huge difference. Some platforms don't map any ROM at all into process memory space.David Schwartz
Atmel Studio compiler - it does not exists. Atmel studio IDE & gcc compiler yes. I think it is too complicated topic at the moment for you.It is explained in the hundreds of articles - it you do not understand them - means it is too early. To have any use of if you need to have a deep knowledge of the C language, linker scripts, startup codes & target hardware. For now just remember - uninitialised static variables are zeroed, automatic are not.0___________
There's various hiccups here, specific to Harvard architecture junk, however.Lundin

3 Answers

6
votes

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.

4
votes

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.

0
votes

ROM cannot be written to, but RAM can be written to. ROM holds the (BIOS) Basic Input / Output System, but RAM holds the programs running and the data used. ROM is much smaller than RAM. ROM is non-volatile (permanent), but RAM is volatile.