mips的内存管理-kseg0,kseg1虚拟和物理地址映射理解

2023-05-16

《mips-24kf-manual.gliethttp.pdf》p89页
所以mips复位和中断发生,都会自动进入kernel模式
. The core enters Kernel mode both at reset and when an exception is recognized.
. In User mode, virtual addresses 0x8000_0000 to 0xFFFF_FFFF are invalid and cause an exception if accessed.
. An unmapped segment does not use the TLB or the FM to translate from virtual-to-physical addresses. Especially
after reset, it is important to have unmapped memory segments, because the TLB is not yet programmed to perform
the translation.
. Unmapped segments have a fixed simple translation from virtual to physical address. This is much like the transla-
tions the FM provides for the core, but we will still make the distinction.
. Except for kseg0, unmapped segments are always uncached. The cacheability of kseg0 is set in the K0 field of the
CP0 registe
. A mapped segment does use the TLB or the FM to translate from virtual-to-physical addresses.
. For the core with the FM MMU, the mapped segments have a fixed translation from virtual to physical address.
. kseg0, the physical address selected is defined by subtracting 0x8000_0000 from the virtual address.
. Optionally, the MMU can be based on a simple algorithm to translate virtual addresses into physical addresses via a
Fixed Mapping (FM) mechanism. These translations are different for various regions of the virtual address space
(useg/kuseg, kseg0, kseg1, kseg2/3).
========================================
对于MIPS的MMU和Memory Management, the first and yet important one we need always keep in mind is: No real-mode
没有实模式。这一点是MIPS CPU 的一个很重要的特点(或缺点)。
我们会问了:BNN,Give me a break. Without CPU running in the real-mode,
how could you boot up a kernel? Well, here is the thing: Bydefault, MIPS architecture , when power on, has enabled/mapped two memory areas. In other words, those two memory areas are the places where your boot codes HAVE TO resident and run on top of. If you read the makefiles of MIPS linux source tree, you would easily find the infor. For example, 0x8000xxxx or some things like that.
MIPS 存储体系结构
我们在这里不谈64位CPU,只谈32位的。
MIPS将存储空间划分为4大块--kuseg, kseg0,kseg1 and kseg2.
------------------------------------------------------------------
0xFFFF FFFF
mapped kseg2
0xC000 0000
unmapped uncached kseg1
0xA000 0000
unmapped cached kseg0
0x8000 0000
2G kuseg
0x0000 0000
------------------------------------------------------------------
对于上述图表,弟兄们要记住以下几点:
* 当开电(Power On)的时候,只有kseg0 and kseg1 是可以存取的。
*kseg0 512M(From 0x8000 0000 to 0xA000 0000) are DIRECTLY mapped to physical memory ranging from 0x0000 0000 to 0x2000 0000, with cache-able(either write back or write through, which is decided by SR(Status Register of MIPS CPU)
*kseg1 512M(From 0xA000 0000 to 0xC000 0000) are (also) DIRECTLy mapped to physical memory ranging from 0x0000 0000 t0 0x2000 0000, with non-cachable.
以上两点对于理解MIPS OS的启动是至关重要的。细心的读者会发现:kseg1有点象其他CPU的real-mode方式。
*(虚拟)地址from 0x0000 0000 to 0x8000 0000 是不可以存取的,在加电时(POWERON)!必须等到MMU TLB初始化之后才可以。
*同理对地址from 0xC000 0000 to 0xFFFF 0000
*MIPS的CPU运行有3个态--User Mode; Supervisor Mode and Kernel Mode.For simplicity, let's just talk about User Mode and Kernel Mode. Please always keep this in mind:
CPU can ONLY access kuseg memory area when running in User Mode
CPU MUST be in kernel mode or supervisor mode when visiting kseg0, kseg1 and kseg2 memory area.
* MMU TLB
MIPS CPU通过TLB 来translates all virtual addresses generated by the CPU.对于这一点,这里不多废话。
下面谈谈ASID(Address Space Identifier). Basically, ASID, plus the VA(Virtual Address) are composed of the primary key of an TLB entry. 换句话说,虚拟地址本身是不能唯一,确定一个TLB entry的。一般而言,ASID的值就是相应的process ID.
Note that ASID can minimized TLB re-loads, since several TLB entries can have the same virtual page number, but different ASID's. 对于一个多任务操作系统来讲,每个任务都有自己的4G虚拟空间,但是有自己的ASID。
MMU 控制寄存器
对于一个Kernel Engineer来说,对MMU的处理主要是通过MMU的一些控制寄存器来完成的。MIPS体系结构中集成了一个叫做System Control Coprocessor (CP0)的部件。CP0就是我们常说的MMU控制器。在CP0中,除了TLB entry(例如,对RM5200,有48pair,96个TLB entry),一些控制寄存器提供给OS KERNEL来控制MMU的行为。
每个CP0控制寄存器都对应一个唯一的寄存器号。MIPS提供特殊的指令来对CP0进行操作。
mfc0 reg. CP0_REG
mtc0 reg. CP0_REG
我们通过上述的两条指令来把一个GPR寄存器的值assign给一个CP0寄存器,从而达到控制MMU的目的。
下面简单介绍几个与TLB相关的CP0控制寄存器。
Index Register
这个寄存器是用来指定TLB entry的,当你进行TLB读写的时候。我们已经知道,例如,MIPS R5提供了48个TLB pair,所以index寄存器的值是从0到47。换句话说,每次TLB写的行为是对一个pair发生的。这一点是与其他的CPU MMU TLB 读写不同的。

EntryLo0, EntryLo1
这两个寄存器是用来specify 一个TLB pair的偶(even)和奇(odd)物理(Physical)页面地址。
一定要注意的是:EntryLo0 is used for even pages; EntryLo1 is used for odd pages.Otherwise, the MMU will get exception fault.

Entry Hi
Entry Hi寄存器存放VPN2,或一个TLB的虚拟地址部分。注意的是:ASID value也是在这里被体现。

Page Mask
MIPS TLB提供可变大小的TLB地址映射。一个PAGE可以是4K,16K,64K,256K,1M,4M或16M。这种可变PAGE SIZE提供了很好的灵活性,特别是对Embedded System Software. 对于Embedded System Softare,一个很大的区别就是:不允许大量的Page Fault.这一点是传统OS或General OS在Embedded OS上的致命缺陷。也是为什么POSIX 1。B的目的所在。传统OS存储管理的一个原则就是:Page On Demand.这对大多Embedded System是不允许的。 For embedded system,往往是需要在系统初始化的时刻就对所有的存储进行configuration, 以确保在系统运行时不会有Page Fault.

上述几个寄存器除了MAP一个虚拟页面之外,还包括设置一个页面的属性。其中包括:
writable or not; invalide or not; cache write back or write through
下面简单谈谈MIPS的JTLB。
在MIPS中, 如R5000, JTLB is provided. JTLB stands for Joint TLB. 什么意思呢?就是
TLB buffer中包含的mixed Instruction and Data TLB 映射。有的CPU的Instruction TLB 和Data TLB buffer 是分开的。
当然MIPS(R5000)确实还有两个小的,分开的Instruction TLB和Data TLB。但其大小很小。主要是为了Performance,而且是对系统软件透明的。
在这里再谈谈MMU TLB和CPU Level 1 Cache的关系。
我们知道,MIPS,或大多数CPU,的Level 1 Cache都是采用Virtually Indexed and Physicall tagged. 通过这个机制,OS就不需要在每次进程切换的时候去flush CACHE。为什么呢?
举一个例子吧:
进程A的一个虚拟地址Addr1,其对应的物理地址是addre1;
进程B的一个虚拟地址Addr1,其对应的物理地址是addre2;
在某个时刻,进程A在运行中,并且Addr1在Level 1 CACHE中。
这时候,OS does a context swith and bring process B up, having process A sleep. Now, let's assume that the first instruction/data fetch process B does is to access its own virtual address Addr1.
这时候CPU会错误的把进程A在Level 1中的Addr1的addr1返回给CPU吗?
我们的回答应该是:不会的。
原因是:
当进程切换时,OS会将进程B的ASID或PID填入ASID寄存器中。请记住:对TLB的访问,(ASID + VPN)才是Primary Key.
由于MIPS的CACHE属性是Virtually Indexed, Physically tagged.所以,任何地址的访问,CPU都会issue the request to MMU for TLB translation to get the correct physical address, which then will be used for level cache matching.
与此同时,CPU会把虚拟地址信号传给Level 1 Cache 控制器。然后,我们必须等待MMU的Physical Address数据。只有physical tag也 匹配上了,我们才能说一个:Cache Hit.
所以,我们不需要担心不同的进程有相同的虚拟地址的事情。
弟兄们可以重温一下我们讲过的Direct Mapped; Full Associative, and Set Associative.
从而理解为什么Cache中可以存在多个具有相同虚拟地址的entry. For example,the above Addr1 for proccess A and Addr1 for process B.
 
 
原文见: http://blog.chinaunix.net/uid-20564848-id-74683.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

mips的内存管理-kseg0,kseg1虚拟和物理地址映射理解 的相关文章

随机推荐

  • Python JSON dumps与loads傻傻分不清

    一 JSON基本概念 JSON代表JavaScript对象符号 它是一种轻量级的数据交换格式 xff0c 用于存储和交换数据 它是一种独立于语言的格式 xff0c 非常容易理解 xff0c 因为它本质上是自描述的 python中有一个内置包
  • tomcat 端口冲突问题的解决办法

    方法1 tomcat开机启动了 xff0c 你可以查看任务管理器 xff0c 把tomcat xff08 或者Apache tomcat xff09 的任务关了 方法 2 更改tomcat的8080端口 打开配置文件 xff08 如下 xf
  • 总结之知识图谱前沿技术课程

    前言正文参考文献 前言 写在前面 xff0c 本文的内容主要基于2017年12月2日在苏州大学举办的知识图谱前沿技术课程 xff08 感谢各位老师的talk xff0c 受益良多 xff09 以及本人在之前阅读的有关paper xff0c
  • Qt 5.15的源码编译(Windows)

    前言 xff1a 在技术革新如此之快的时代 xff0c Qt也在为适应这些变化发生着重大的改变 又一长期 3年 支持版Qt 5 15 LTS在2020年3月发布 xff0c 重大更新的大版本Qt 6 0也在2020年12月发布 但是 xff
  • 【vim编辑器的使用】

    目录 1 vim的编辑器的使用 1 1 vim 文件名 xff1a 表示将文件用vim编辑器打开 2 vim的三种编辑模式 2 1 命令模式 2 2 插入模式 2 3 底行模式 Vim 是从 vi 发展出来的一个文本编辑器 代码补完 编译及
  • gcc编译器

    GCC xff08 GNU Compiler Collection xff0c GNU编译器套件 xff09 是由GNU开发的编程语言译器 GNU编译器套件包括C C 43 43 Objective C Fortran Java Ada和G
  • send()函数recv()函数详解

    目录 1 send xff08 xff09 函数 2 recv xff08 xff09 函数 1 send xff08 xff09 函数 函数原型 xff1a ssize t send int sockfd const void buf s
  • 数据元素、数据项、数据对象的概念详解

    数据元素 xff1a 数据的基本单位 数据项 xff1a 独立包含的数据最小单位 若干数据项组成一个数据元素 数据对象 xff1a 相同数据元素的集合 若干数据元素组成数据对象
  • Linux解压压缩命令tar

    目录 一 tar tar命令打包 tar命令解压 选项解释 一 tar Linux系统中常用的压缩格式有 xff1a tar gz tar bz2 tar xz tar Z 可以用tar进行解压缩 tar命令打包 xff1a tar 选项
  • ubuntu服务器编译源码

    1 xff0c Vmware软件安装后 2 xff0c VMware workstation full 16 0 0 16894299 exe 3 xff0c 新建虚拟磁盘 xff0c 加载镜像文件 ubuntu 16 04 7 deskt
  • 3.1 Linux启动Shell

    系列文章目录 第1章 Linux Shell简介 第2章 Shell基础 第3章 Bash Shell基础命令 lt 本章所在位置 gt 第4章 Bash Shell命令进阶 第5章 Linux Shell深度理解 第6章 Linux环境变
  • IP地址打印格式

    在C语言中 xff0c 可以使用printf 函数打印IP地址 常见的方法是将IP地址转换为点分十进制格式 xff0c 并使用 s或 u u u u等格式说明符进行打印 以下是一些示例代码 xff1a 将IP地址转化为字符串并以 34 s
  • 子网掩码打印方式

    在C语言中 xff0c 可以使用printf 函数打印子网掩码 和打印IP地址类似 xff0c 常见的方法是将掩码转换为点分十进制格式 xff0c 并使用 s或 u u u u等格式说明符进行打印 以下是一些示例代码 xff1a 将子网掩码
  • realloc 用法 .

    最近在写source code时需要在数组的buffer小时重新申请一块buffer 故找了一些资料 xff0c 乖乖 xff0c 竟然原指针还可以 漂移 realloc 原型 xff1a extern void realloc void
  • 多个方面比较电路交换、报文交换和分组交换的主要优缺点

    xff08 1 xff09 电路交换 xff1a 由于电路交换在通信之前要在通信双方之间建立一条被双方独占的物理通路 xff08 由通信双方之间的交换设备和链路逐段连接而成 xff09 xff0c 因而有以下优缺点 优点 xff1a 由于通
  • LVDS,CML,LVPECL,VML接口详细介绍

    在平时的工作中 xff0c 经常会接触到各种差分电平的转换 xff0c 网上也有很多这样的资料 xff0c 但发现有些混乱 xff0c 所以找了TI的这份文档进行翻译 xff0c 一是系统的归类一下 xff0c 二是自己也能通过这个来加深理
  • Linux-网桥原理分析 .

    Linux 网桥原理分析 http biancheng dnbcw info linux 244269 html 目 录 1 前言 6 2 网桥的原理 7 2 1 桥接的概念 7 2 2 linux的桥接实现 8 2 3 网桥的功能 9 3
  • IP头、TCP头、UDP头详解以及定义

    一 MAC帧头定义 数据帧定义 xff0c 头14个字节 xff0c 尾4个字节 typedef struct MAC FRAME HEADER char m cDstMacAddress 6 目的mac地址 char m cSrcMacA
  • SGMII 和 Serdes 的详细说明

    Serdes xff1a SERDES是英文SERializer 串行器 DESerializer 解串器 的简称 它是一种时分多路复用 TDM 点对点的通信技术 xff0c 即在发送端多路低速并行信号被转换成高速串行信号 xff0c 经过
  • mips的内存管理-kseg0,kseg1虚拟和物理地址映射理解

    mips 24kf manual gliethttp pdf p89页 所以mips复位和中断发生 都会自动进入kernel模式 The core enters Kernel mode both at reset and when an e