简体   繁体   English

何时由操作系统修改段寄存器?

[英]When are segment registers modified by operating systems?

In x86 architecture, there are some segment registers such as SS, CS, DS, FS, GS. 在x86架构中,有一些段寄存器,如SS,CS,DS,FS,GS。

I know that these 16bit registers indicates the LDT, GDT entries(as segment selector) and MMU references this(GDT, LDT) to calculate segment base + offset value. 我知道这些16位寄存器表示LDT,GDT条目(作为段选择器),MMU引用它(GDT,LDT)来计算段基+偏移值。 and check permissions and etc. 并检查权限等。

What I am curious is: who fills in the segment register contents based on what? 我很好奇的是:谁根据什么填写段寄存器内容? The kernel scheduler? 内核调度程序?

And what happens when application changes the segment register value itself? 当应用程序更改段寄存器值本身时会发生什么? I know that only CS can not be changed because it has CPL of current CPU. 我知道只有CS才能更改,因为它具有当前CPU的CPL。 but other registers(SS, DS...) can be changed. 但是其他寄存器(SS,DS ......)可以改变。

who fills in the segment register contents based on what??(kernel scheduler??) 谁根据什么??(内核调度程序??)填写段寄存器内容

The bootloader does. 引导加载程序。 ISRs and exception handlers do. ISR和异常处理程序。 System call handlers do. 系统调用处理程序。 The scheduler does. 调度程序。 Some other parts may need to. 其他一些部分可能需要。 The registers are assumed to be private and have to be saved and restored during various context switches. 假定寄存器是私有的,并且必须在各种上下文切换期间保存和恢复。 And, of course, they need to be initialized at some prior point too. 当然,它们也需要在之前的某个时刻进行初始化。

Based on what needs to be in those registers. 基于这些寄存器中需要的内容。 Their values are not universally shared between different parts of the OS and between different programs. 它们的价值观并非在操作系统的不同部分之间以及不同程序之间共享。

and what happens when application changes the segment register value it self? 当应用程序自行更改段寄存器值时会发生什么? I know that only CS can not be changed because it has CPL of current CPU. 我知道只有CS才能更改,因为它具有当前CPU的CPL。 but other registers(SS, DS...) can be changed. 但是其他寄存器(SS,DS ......)可以改变。

What happens? 怎么了? It either changes it successfully or causes an exception (typically, #GP) and then happens whatever the exception handler does or, if there's none or it's buggy, a triple fault, a CPU reset and probably a reboot of the entire computer. 它要么成功地更改它,要么导致异常(通常是#GP)然后发生异常处理程序所做的事情,或者如果没有或它有错误,三重故障,CPU重置以及可能重启整个计算机。

You can change any segment register if you somehow know what else can be loaded into it at the current privilege level. 如果您知道在当前权限级别可以加载哪些其他段,则可以更改任何段寄存器。 If your program is at level 3 and there are two code segments with DPL=3 set up for it by the OS, the program can use either of them for the CS register. 如果您的程序处于第3级并且操作系统为其设置了DPL = 3的两个代码段,则程序可以将它们中的任何一个用于CS寄存器。 If you don't know that, you're more likely to just crash the program. 如果你不知道,你更有可能只是崩溃程序。

I want to know details of x86 segment registers. 我想知道x86段寄存器的细节。

Get yourself a copy of and read: 给自己一份副本并阅读:

Intel® 64 and IA-32 Architectures Software Developer's Manual Combined Volumes: 1, 2A, 2B, 3A and 3B. 英特尔®64和IA-32架构软件开发人员手册合并卷:1,2A,2B,3A和3B。

You can either go by the relevant chapters (memory management, interrupt/exception handling, task switching) or search for specific registers (eg CS or SS or DS) or look at the description of and pseudo-code for specific instructions. 您可以查看相关章节(内存管理,中断/异常处理,任务切换)或搜索特定寄存器(例如CS或SS或DS),或查看特定指令的伪代码说明。

You're not going to get any more precise answers to the questions this vague. 你不会对这些模糊的问题得到任何更准确的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM