了解cpu寄存器 [英] Understanding cpu registers

查看:84
本文介绍了了解cpu寄存器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是汇编语言的初学者,试图了解它们的工作原理。我的问题似乎很愚蠢,但无论如何,对我来说还不太清楚。

I'm very beginner in assembly language and trying to understand how these all work. My question may seem very dumb but anyway, it's not quite clear to me.

请考虑以下简单程序:

section .text
    global _start

_start:

    mov eax, [text]
    mov [val], eax
    mov ecx, val
    mov eax, 4
    mov edx, 7
    mov ebx, 1
    int 0x80

    mov eax, 1
    int 0x80

segment .bss
    val resb 2

segment .data
    text db "Th"
    len equ $- text

在这里,我们更新寄存器中的值并通过系统调用将其打印出来。但是我想知道 OS (我正在使用Ubuntu 16.04)在同一内核上安排一些进程会怎样?这意味着进程以自己的方式更新CPU寄存器。 OS linux如何处理它?我的意思是每个进程都有自己一致的寄存器值,并且不受其他进程的影响?

Here we update values in registers and print it out with system call. But I'm wondering what if OS (I'm using Ubuntu 16.04) schedules some process on the same core. It means the process updates CPU registers in its own way. How does OS linux handle it? I mean each process has its own consistent registers value and not affected by some another process?

推荐答案

当内核运行时,它将当前任务的寄存器内容保存在某个地方(在内核内存中)(在许多处理器上,可能会有一些机器指令或硬件机制来帮助完成此任务。)

When the kernel is running, it keeps somewhere (in kernel memory) a backup of the register contents of the current task (on many processors, there might be some machine instruction or hardware mechanism to help that).

当内核运行调度程序,并且它选择运行某些任务时,即注册状态恢复。请注意,Linux具有抢占调度。阅读有关上下文切换中断 CPU模式。在终端中尝试几次 cat / proc / interrupts 。有关 proc(5)。 > / proc / 。了解有关 x86-64 的更多信息。

When the kernel runs the scheduler and it choose to run some task, that register state is restored. Notice that Linux has preemptive scheduling. Read about context switching and interrupts and CPU modes. Try several times cat /proc/interrupts in a terminal. See proc(5) for more about /proc/. Read more about x86-64.

当该任务要求(例如,通过某些系统调用)运行时,内核将通过备份寄存器内容开始。

When that task asks (e.g. via some system call) to run, the kernel starts by backing up the register contents.

读取 操作系统:三篇简单文章 (可免费下载)。

Read Operating Systems : Three Easy Pieces (freely downloadable book).

每个流程用户空间代码的视图,其注册内容,其文件描述符集,其虚拟地址空间等(而内核,包括其调度程序,正在管理所有这些)。对于多线程进程,每个线程都有其寄存器内容(但它们共享
处于某种状态-尤其是虚拟地址空间,文件描述符等-与同一进程中的其他线程)。

Each process has, from the point of view of user-space code, its register content, its set of file descriptors, its virtual address space etc... (and the kernel, including its scheduler, is managing all that). For multi-threaded processes, every thread has its register content (but they share some state - notably virtual address space, file descriptors, etc... - with other threads in the same process).

这篇关于了解cpu寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆