进程中断时如何保存寄存器? [英] how do the registers get saved when a process gets interrupted?

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

问题描述

这整天困扰着我。当程序设置为在收到某个中断时调用函数时,我知道程序中断时寄存器会被压入堆栈,但是我不知道的是:寄存器如何从堆栈中退出。堆栈?我知道编译器不知道该函数是否为中断处理程序,也不知道该中断为该函数提供了多少个参数。

this has been bugging me all day. When a program sets itself up to call a function when it receives a certain interrupt, I know that the registers are pushed onto the stack when the program is interrupted, but what I can't figure out is: how do the registers get off the stack? I know that the compiler doesn't know if the function is an interrupt handler, and it can't know how many arguments the interrupt gave to the function. So how on earth does it get the registers off?

推荐答案

这取决于编译器,操作系统和CPU。

It depends on the compiler, the OS and the CPU.

对于低级嵌入式内容,可以直接响应中断而调用ISR,编译器通常会扩展标记该语言的语言(通常为C或C ++)给定的例程作为ISR,寄存器将在该例程的开始和结束时保存和恢复。 [1]

For low level embedded stuff, where an ISR may be called directly in response to an interrupt, the compiler will typically have some extension to the language (usually C or C++) that flags a given routine as an ISR, and registers will be saved and restored at the beginning and end of such a routine. [1]

对于常见的台式机/服务器操作系统,尽管中断和用户代码之间通常存在一定程度的抽象-中断通常在传递之前先由某些内核代码处理到用户例程,在这种情况下,内核代码负责保存和恢复寄存器,并且用户提供的ISR没有特殊

For common desktop/server OSs though there is normally a level of abstraction between interrupts and user code - interrupts are normally handled first by some kernel code before being passed to a user routine, in which case the kernel code takes care of saving and restoring registers, and there is nothing special about the user-supplied ISR.

[1]例如Keil 8051 C编译器:

[1] E.g. Keil 8051 C compiler:

void Some_ISR(void) interrupt 0 // this routine will get called in response to interrupt 0
{
    // compiler generates preamble to save registers

    // ISR code goes here

    // compiler generates code to restore registers and
    // do any other special end-of-ISR stuff
}

这篇关于进程中断时如何保存寄存器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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