can't read bottom of stack (esp), causes 'ret' to fail
Posted: Thu Nov 22, 2007 12:28 am
I have a function, called "flush_gdt" (ok, actually memmgr::_flush_gdt()) that loads gdtr, ds, es, and ss, does a far jump to load cs (to a label on the next line), and then returns. the ret instruction causes a triple-fault (because I don't have an IDT working yet), and it's because when the 'leave' instruction pops into %ebp, %ebp ends up being 0. What's weird is that gdb things that the value in the location contained in %esp is not 0.
Here's my code:
I tried inserting a couple of lines like this:
but %edi gets a zero also. doing a
on the value in %esp shows it not to be 0.
Here's my code:
Code: Select all
void
memmgr::_flush_gdt(gdtdesc& gdtr)
{
int *p=reinterpret_cast<int*>(&gdtr);
asm("lgdt %0" : : "m"(*p));
asm("movw %0, %%ds\n\t"
"movw %1, %%es\n\t"
"movw %2, %%ss"
: /* no output */
: "r"(ds), "r"(es), "r"(ss)
);
asm("ljmp $0x8, $1f\n"
"1:\n"
: : "r"(cs)
);
}
Code: Select all
movl (%esp), %edi
movl %edi, %ebp
Code: Select all
(gdb) x /1wx