当前位置:网站首页>程序的存储态与运行态
程序的存储态与运行态
2022-07-28 11:15:00 【Mindtechnist】

欢迎加入【Linux C/C++/Python社区】一起探讨和分享Linux C/C++/Python/Shell编程、机器人技术、机器学习、机器视觉、嵌入式AI相关领域的知识和技术。
程序的存储态与运行态
*认识程序的运行与存储:结合硬件存储器来分析程序在运行和静止时的存储状态。相关文章链接
应用程序有静止状态(存储态)和运行状态(运行态)。静止状态就是程序在运行之前存储在非易失性存储器中的状态,比如stm32的内部Flash中,因此,系统掉电后程序也能正常保存。当我们把程序下载(烧写)到STM32F429的Flash中,如果不运行程序,那么程序就处于静止状态,关机重启后程序依然存在,不会丢失。在程序开始运行的时候,也就是程序处于运行态的时候,程序经常会修改一些暂存数据,为了提高速度,这些数据一般会加载到内存(RAM)中,而内存中的数据在掉电后会丢失。因此,程序在静止和运行两种状态下,它们在存储器中的位置是不一样的。
程序在存储态时,RO节(RO section)和RW节(RW section)都保存在ROM区,比如STM32的Flash中。当程序开始运行时,内核直接从ROM中读取代码,并在执行主体代码前先执行一段加载代码,把RW section中的数据从ROM拷贝到RAM内存中,并在RAM中加入ZI section,ZI节的数据都被初始化为0,加载完RAM区之后,正式开始执行主体程序。
在《MDK编译过程及ARM编译工具链》一文中说到,编译后的信息划分了几个域(可参考本人文章)。编译信息中的RW-data和ZI-data分别对应这里的RW section和ZI section,二者的区别在于是否需要掉电保存。因为在RAM中创建数据时,默认初值都是0,比如ZI节,但是有的数据要求初值非0,也就是被初始化为非0值的数据,这些数据需要通过ROM来记录初值(因为初值是程序运行前就确定好的,也就是说这个非0初值应该具有掉电保存的性质,所以这就需要把具有非0初值的数据保存在ROM/Flash中,而初值为0的数据掉电后重新在RAM内存中加载并不会影响初值,所以不需要掉电保存,也就不需要保存到ROM/Flash中记录初值,而是在运行态时直接在RAM中创建即可,即ZI section),而存放在ROM中的数据会在程序运行时复制到RAM。STM32的RO区不会加载到RAM中,内核直接从Flash读取指令。这里需要区分开的是,计算机会把RO区加载到内存,因为计算机有MMU单元,支持虚拟内存,可以运行大于物理内存的程序。
当程序下载到STM32的Flash(RAM)中的时候,它占用的空间为 code + RO-data + RW-data ,若这个总和大于STM32的Flash存储空间,将会出现错误。程序执行时占用的SRAM空间为 RW-data + ZI-data。
| 程序状态 | 编译后的数据域 |
|---|---|
| 运行态RO区 | code + RO-data |
| 运行态RW区 | RW-data + ZI-data |
| 存储态ROM区 | code + RO-data + RW-data |


边栏推荐
- 【补题日记】[2022牛客暑期多校2]D-Link with Game Glitch
- 强缓存、协商缓存具体过程
- Globalthis is not defined solution
- Solutions to slow start of MATLAB
- 【补题日记】[2022牛客暑期多校2]H-Take the Elevator
- Can dynamic partitions be configured when MySQL is offline synchronized to ODPs
- P5472 [noi2019] douzhudi (expectation, Mathematics)
- Direct insert sort and Hill sort
- Unity鼠标带动物体运动的三种方法
- OSCache cache monitoring Refresh Tool
猜你喜欢

Dialogue with Zhuang biaowei: the first lesson of open source

Techniques for visualizing large time series.

Zotero document manager and its use posture (updated from time to time)

A new mode of one-stop fixed asset management

Understand how to prevent tampering and hijacking of device fingerprints

Are interviews all about memorizing answers?

consul安装与配置

Blackboard cleaning effect shows H5 source code + very romantic / BGM attached

Leecode8 string conversion integer (ATOI)

Shell (II)
随机推荐
Six papers that must be seen in the field of target detection
【补题日记】[2022牛客暑期多校2]I-let fat tension
一文看懂设备指纹如何防篡改、防劫持
R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize the grouped dot plot, set the palette parameter, and set the color of data points in different grouped dot p
Flash point list of cross platform efficiency software
哪位大神帮看下 oracle number类型解析 怎么搞 Struct{scale=15,val
Shell (II)
Static proxy instance
R language uses dplyr package group_ By function and summarize function calculate the mean value of all covariates involved in the analysis based on grouped variables (difference in means of covariate
对话庄表伟:开源第一课
Upgrading of computing power under the coordination of software and hardware, redefining productivity
大佬们,问下,这个不能checkpoint,因为有个jdbc的task任务状态是FINISHED,
R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize dot plot, set the add parameter, add violin graph to the dot plot, and add the vertical line of mean standar
MySQL (version 8.0.16) command and description
14、用户web层服务(二)
AlexNet—论文分析及复现
Database advanced learning notes - storage structure
Today's sleep quality record 74 points
15. User web layer services (III)
How is the JS code compiled and executed by the browser engine?