Assembly 尝试调试程序集文件时出错
我正在尝试将32位汇编函数移植到64位。它的save_context和restore_restore。基本上是从i386移植到x86_64 这就是我的移植 32位版本:Assembly 尝试调试程序集文件时出错,assembly,x86-64,porting,cpu-registers,i386,Assembly,X86 64,Porting,Cpu Registers,I386,我正在尝试将32位汇编函数移植到64位。它的save_context和restore_restore。基本上是从i386移植到x86_64 这就是我的移植 32位版本: .align 4,0x90 .global save_context .type save_context,@function save_context: movl 4(%esp),%eax movl %ebx, 12(%eax) movl %esi, 16(%eax)
.align 4,0x90
.global save_context
.type save_context,@function
save_context:
movl 4(%esp),%eax
movl %ebx, 12(%eax)
movl %esi, 16(%eax)
movl %edi, 20(%eax)
movl %ebp, 24(%eax)
movl %esp, 28(%eax)
movl 0(%esp), %edx
movl %edx, 0(%eax)
xorl %eax,%eax
incl %eax
ret
在MAIN中调用函数:
u_int32_t context[10];
if (cpu_save_context(context) == TRUE) {
// do something
}
u_int64_t context[10]; // i have tried increasing 10->20 and 40//still save errors
if (cpu_save_context(context) == TRUE) {
// do something
}
gdb>>p上下文
$2 = {<some value>, 0, 0, <some value>, 0, 0, <some value>, <some value>, 0, 0}
$2 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
在MAIN中调用函数:
u_int32_t context[10];
if (cpu_save_context(context) == TRUE) {
// do something
}
u_int64_t context[10]; // i have tried increasing 10->20 and 40//still save errors
if (cpu_save_context(context) == TRUE) {
// do something
}
gdb>>p上下文
$2 = {<some value>, 0, 0, <some value>, 0, 0, <some value>, <some value>, 0, 0}
$2 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
因此,这些函数适用于32位版本,但对于64位版本则不适用。我已经发布了类似的问题,他们相信我移植的汇编代码是好的。
有人能帮你调试一下吗。IMHO你没有“移植”ABI(更具体的是调用约定)。在
x86
中,调用参数在堆栈上,但在x86-64
中,调用参数在寄存器中,根据操作系统的不同而不同。看看这里:对不起,我不明白。。你能给我举个例子说明一下吗。即使在阅读之后,我也没有看到移植错误?!?!另外,x86_64
还有几个寄存器需要保留…mov 8(%rsp),%rax做什么?堆栈上没有参数!context
的地址大概在RDI
中传递。我想知道为什么您没有出现分段错误。我已对新的64位移植进行了更改。你能核实一下吗。会很有帮助的!!!