gpt4 book ai didi

c - 逐行分析 i386 汇编函数...

转载 作者:太空宇宙 更新时间:2023-11-04 07:28:36 26 4
gpt4 key购买 nike

您好,我是汇编和操作系统领域的新手。是的,这是我的作业,我陷入了 i386 手册的黑暗之中。请帮助我或给我一些提示.. 这是我必须逐行分析的代码。该函数是EOS(educational OS)的一部分,在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);
}

所以这些函数会确认和获取以及屏蔽和取消屏蔽中断请求。我被困在第一个。所以如果你足够仁慈,你能给我一些提示或答案来分析第一个函数吗?我会努力让其他人...我很抱歉又做了一个作业..(我的助教看起来不像电子邮件)

最佳答案

21 05 00 00 00 00(即and)实际上是一个and带内存操作数(即and[0],eax ) AT&T 语法模糊不清(但从技术上讲它确实这么说,请注意没有 $ 符号)。这样更有意义(0 的偏移量表明您在反汇编之前没有链接代码)。

mov $0xfffffffe, %eax 正在做它看起来正在做的事情(注意 0xfffffffe 是除最低位之外的所有 1),这意味着该函数已像这样实现:

_irq_pending &= rotate_left(0xFFFFFFFE, irq);

保存一个 not 操作。如果需要,必须在那里进行循环而不是移位,以便使低位为 1。

关于c - 逐行分析 i386 汇编函数...,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15996827/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com