I have a sample code run in kernel(2.6.30 x86_64) mode(r0),trying to simulate a iret.I push variables under intel manual’s guide.but it turns out a runtime fault right in the pos of iret instruction:
general protection fault:fffc[#] SMP
asm volatile(
"mov %%ss,%%ax \n\t"
"push %%rax \n\t"/*ss*/
"push %%rsp \n\t"/*rsp*/
"pushfq \n\t"/*rflags*/
"mov %%cs,%%ax \n\t"
"push %%rax \n\t"/*cs*/
"mov $._restart_code,%%rax \n\t"
"push %%rax \n\t"/*rip*/
"iret \n\t"/*here is the fault rip!!!!!!*/
"._restart_code:"
"nop" :);
the bug is that rsp is changed after push.
so,save the rsp before all push instructions. and that correct code is:
Thanks!!!