> 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.


- Christian


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://reviews.gem5.org/r/1825/#review4240
-----------------------------------------------------------


On April 17, 2013, 5 a.m., Christian Menard wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://reviews.gem5.org/r/1825/
> -----------------------------------------------------------
> 
> (Updated April 17, 2013, 5 a.m.)
> 
> 
> Review request for Default.
> 
> 
> Description
> -------
> 
> x86: bugfix: lret instruction has to increment the stack pointer
> lret does not increment the stack pointer which results in misbehavior.
> I am not sure if this is the best way to fix this, but it works for me.
> 
> 
> Diffs
> -----
> 
>   src/arch/x86/isa/insts/general_purpose/control_transfer/xreturn.py 
> 531a176f863d4844af311df515d435b0bb06163c 
> 
> Diff: http://reviews.gem5.org/r/1825/diff/
> 
> 
> Testing
> -------
> 
> Tested with a custom kernel.
> 
> 
> Thanks,
> 
> Christian Menard
> 
>

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

Reply via email to