QEMU fails to execute lea 0x1(%rax),%rax
Posted: Tue Dec 29, 2020 12:08 am
Hi all,
I'm attempting to port my OS to x86_64, but it has been a horrible experience so far. Currently, I'm stuck at getting strlen to work.
First, let me paste this:
Here, qemu is at the lea and once it executes, I expect rax to become 0x2000, however, as you can see, it just stays `0x1fff` and keeps looping forever. Also, it steps to 0x12f4, which doesn't exist in the disassembly.
This is how I run qemu:
i386-loader just sets up paging and jumps to a 64-bit function that attempts to write something to the screen, but it just gets stuck in this strlen.
I've been fighting this for a few days now and wanted to reach out to see if anyone has any idea...
I'm attempting to port my OS to x86_64, but it has been a horrible experience so far. Currently, I'm stuck at getting strlen to work.
First, let me paste this:
Code: Select all
(gdb) disas
Dump of assembler code for function strlen:
0x00000000000012eb <+0>: lea -0x1(%rdi),%rax
0x00000000000012ef <+4>: cmpb $0x0,0x1(%rax)
=> 0x00000000000012f3 <+8>: lea 0x1(%rax),%rax
0x00000000000012f7 <+12>: jne 0x12ef <strlen+4>
0x00000000000012f9 <+14>: sub %rdi,%rax
0x00000000000012fc <+17>: retq
End of assembler dump.
(gdb) i r rax
rax 0x1fff 8191
(gdb) si
0x00000000000012f4 95 while (*str)
(gdb) si
0x00000000000012f7 95 while (*str)
(gdb) i r rax
rax 0x1fff 8191
This is how I run qemu:
Code: Select all
qemu-system-x86_64-m 256m -cpu qemu64 -serial mon:stdio -kernel .\bin\i386-loader -s
I've been fighting this for a few days now and wanted to reach out to see if anyone has any idea...