返回到 Eip 寄存器中存储的下一条指令 [英] Returning to the next instruction following the one stored in Eip register

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

问题描述

我编写了一个处理中断的汇编函数.我想回到导致中断的指令之后的指令.这是我的代码,

I have written a assembly function that handles an interrupt. I want to return to the instruction following the one that caused the interrupt. Here is my code,

    pushl   %ebp
    movl    %esp,%ebp
    pushal
    movl    %esp, %eax
    pushl   %eax
    pushl   $0
    call    divzero

    addl    $8, %esp        /* add 8 to the stack pointer to skip the two variables*/ 
    popal   
    popl    %ebp            /* restore %ebp */
    popl    %eax            /* pop return address from stack and store in eax */
    add     $4, %eax    /* add 4 to value of eax to get the address of next instruction */
    jmp     %eax  

我正在编码的平台是 x86 32 位.我已经根据我对堆栈如何工作的理解写了评论,但我收到了无效的操作码中断.这是堆栈跟踪.

The platform I am coding on is x86 32 bits. I have written comments from my understanding of how the stack works but I am getting invalid opcode interrupt. Here is the stack trace.

exception 6 (invalid opcode) currpid 3 (Main process)
CS EFC0008 eip 1028D4
eflags 10297
register dump:
eax 001028CC (1059020)
ecx 0EFC8FFC (251432956)
edx 00000000 (0)
ebx 00121000 (1183744)
esp 0EFC8FB8 (251432888)
ebp 0EFC8FB8 (251432888)
esi 00000000 (0)
edi 00000000 (0)

作为参考,我在这里添加我的主要功能:

For reference I am adding my main function here:

process main(void)
{
    
        asm("int $0");
        kprintf("hello\n");
        int i = 4 / 0; <- Casue of interrupt
        kprintf("hello again\n"); -< The place I want to return to.

}

推荐答案

这对我有用:

    pushl   %ebp
    movl    %esp,%ebp
    pushal
    movl    %esp, %eax
    pushl   %eax
    pushl   $0
    call    divzero

    addl    $8, %esp        /* add 8 to the stack pointer to skip the two variables*/ 
    popal                   /* resotre the flags */
    addl    $4, 4(%ebp)     /* add 4 to the return address */
    popl    %ebp            /* restore %ebp */
    iret                    /* return from the function */ 

这篇关于返回到 Eip 寄存器中存储的下一条指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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