分析i386组装功能......逐行分析

时间:2013-04-14 07:40:20

标签: c assembly

嗨,我是组装和OS界的新手。是的,这是我的作业,我在i386手册深陷黑暗中。请帮助我或给我一些提示..这里的代码我必须逐行分析。此功能是EOS(教育操作系统)的一部分,在hal(硬件抽象层)中执行中断请求。我做了“objdump -d interrupt.o”并获得了这个汇编代码。当然是在i386。

00000000 <eos_ack_irq>:
   0:   55                      push   %ebp  ; push %ebp to stack to save stack before
   1:   b8 fe ff ff ff          mov    $0xfffffffe,%eax  ; what is this??
   6:   89 e5                   mov    %esp,%ebp   ; couple with "push %ebp". known as prolog assembly function.   
   8:   8b 4d 08                mov    0x8(%ebp),%ecx ; set %ecx as value of (%ebp+8)...and what is this do??
   b:   5d                      pop    %ebp ; pop the top of stack to %ebp. i know this is for getting back to callee..
   c:   d3 c0                   rol    %cl,%eax  ; ????? what is this for???
   e:   21 05 00 00 00 00       and    %eax,0x0  ; make %eax as 0. for what??
  14:   c3                      ret    ; return what register??

00000015 <eos_get_irq>:
  15:   8b 15 00 00 00 00       mov    0x0,%edx
  1b:   b8 1f 00 00 00          mov    $0x1f,%eax
  20:   55                      push   %ebp
  21:   89 e5                   mov    %esp,%ebp
  23:   56                      push   %esi
  24:   53                      push   %ebx
  25:   bb 01 00 00 00          mov    $0x1,%ebx
  2a:   89 de                   mov    %ebx,%esi
  2c:   88 c1                   mov    %al,%cl
  2e:   d3 e6                   shl    %cl,%esi
  30:   85 d6                   test   %edx,%esi
  32:   75 06                   jne    3a <eos_get_irq+0x25>
  34:   48                      dec    %eax
  35:   83 f8 ff                cmp    $0xffffffff,%eax
  38:   75 f0                   jne    2a <eos_get_irq+0x15>
  3a:   5b                      pop    %ebx
  3b:   5e                      pop    %esi
  3c:   5d                      pop    %ebp
  3d:   c3                      ret    

0000003e <eos_disable_irq_line>:
  3e:   55                      push   %ebp
  3f:   b8 01 00 00 00          mov    $0x1,%eax
  44:   89 e5                   mov    %esp,%ebp
  46:   8b 4d 08                mov    0x8(%ebp),%ecx
  49:   5d                      pop    %ebp
  4a:   d3 e0                   shl    %cl,%eax
  4c:   09 05 00 00 00 00       or     %eax,0x0
  52:   c3                      ret    

00000053 <eos_enable_irq_line>:
  53:   55                      push   %ebp
  54:   b8 fe ff ff ff          mov    $0xfffffffe,%eax
  59:   89 e5                   mov    %esp,%ebp
  5b:   8b 4d 08                mov    0x8(%ebp),%ecx
  5e:   5d                      pop    %ebp
  5f:   d3 c0                   rol    %cl,%eax
  61:   21 05 00 00 00 00       and    %eax,0x0
  67:   c3                      ret    

这里是预先组装的C代码

/* ack the specified irq */
void eos_ack_irq(int32u_t irq) {
    /* clear the corresponding bit in _irq_pending register */
    _irq_pending &= ~(0x1<<irq);
}

/* get the irq number */
int32s_t eos_get_irq() {
    /* get the highest bit position in the _irq_pending register */
    int i = 31;
    for(; i>=0; i--) {
        if (_irq_pending & (0x1<<i)) {
            return i;
        }
    }
    return -1;
}

/* mask an irq */
void eos_disable_irq_line(int32u_t irq) {
    /* turn on the corresponding bit */
    _irq_mask |= (0x1<<irq);
}

/* unmask an irq */
void eos_enable_irq_line(int32u_t irq) {
    /* turn off the corresponding bit */
    _irq_mask &= ~(0x1<<irq);
}

因此这些函数执行ack并获取并屏蔽和取消屏蔽中断请求。我被困在第一个。所以,如果你足够怜悯,请你给我一些提示或答案来分析第一个功能?我会试着去找别人......而且我很抱歉还有另外的作业......(我的TA不看电子邮件)

1 个答案:

答案 0 :(得分:3)

21 05 00 00 00 00and)实际上是一个并且有一个内存操作数(即and [0], eax)AT&amp; T语法模糊不清(但从技术上来说它确实说明了,请注意缺席一个$符号)。这种方式更有意义(0的偏移表明你在拆卸之前没有链接代码)。

mov $0xfffffffe, %eax正在做它看起来正在做的事情(注意0xfffffffe除了最低位之外都是其中的一个),这意味着该函数已经实现如下:

_irq_pending &= rotate_left(0xFFFFFFFE, irq);

保存not操作。它必须是旋转而不是移位,以便在必要时使低位1。