On Thu, April 18, 2013 9:36 am, Christian Menard wrote:
>
>
>> On April 17, 2013, 12:37 p.m., Nilay Vaish wrote:
>> > I am guessing you read some x86 instruction manual to figure this out.
>> Can you mention the manual you read? After reading a code snippet that
>> appears in "AMD64 Architecture Programmer’s Manual Volume 3:
>> General-Purpose and System Instructions", it appears to me that the
>> suggested change may not be required in all the cases that 'ret'
>> instruction needs to handle.
>
> Just to clarify, I'm talking about 'lret' not the normal 'ret'
> instruction. I'm new to x86 and I don't know if this is required in all
> cases, but I think it's required in most. I got my information from
> http://docs.oracle.com/cd/E19620-01/805-4693/instructionset-68/index.html
> but I think the book you mentioned is more specific.
>
> Here is a more detailed description of my problem:
>
> asm volatile (
>   "movabsq    $1f, %%rax      \n"
>   "pushq      %%rbx           \n"
>   "pushq      %%rax           \n"
>   "lretq                      \n"
>   "1:                                 \n"
>     :
>     : "b" (KERNEL_CS_64)
>     : "rax", "memory");
>
> The code above is causing the problem. What it is supposed to do is to
> reload the code segment register. Therefor the address of the gdt is
> pushed as segment selector and the address of the instruction directly
> following the 'lret' is pushed as return address. The 'lret' instruction
> then reloads CS and jumps just to the next instruction. This works
> perfectly fine in qemu but causes trouble in gem5. This is because the
> segment selector and the return address are still on the stack. The 'ret'
> of the function this code is part of then returns to the segment selector
> which results in a crash because it just contains data.
>
>

I went through the manual again and I think you are right. I'll run this
patch through our regression tests so as to make sure nothing break,
though it is surprising that no one experienced this problem before. This
might also mean that our regression tests do not actually make use of this
instruction. Can you provide more details about where you found this code
snippet?

--
Nilay

_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to