Here's the code segment which calls the C function:
Code: Select all
welcome db "Welcome!",10,"This is a test", 0
extern entry_in_c
global userspace_entry
userspace_entry:
mov eax, 0
mov ebx, welcome
int 0x80
xchg bx, bx
call entry_in_c
jmp $
Code: Select all
void entry_in_c(void) {
asm("xchg %bx, %bx;\
mov $5, %eax;\
int $0x80;");
}
Code: Select all
isr_syscall:
cli
sti
iret
At the beginning of the C function, the correct return address is at the top of the stack (happens to be 0x100755). So here, the stack looks like this:
- (mem addr: value)
0x104ffb: 0x100755
- 0x104ff4: 0x0
0x104ffb: 0x100755
- 0x104fec: 0x100764
0x104ff0: 0x1b
0x104ff4: 0x202
0x104ff8: 0x104ff4 <- this is equal to ebp... why?
...
When it returns to the C function it has popped the top two things from the stack, so the top now looks like this:
- 0x104ff4: 0x202
0x104ff8: 0x104ff4
So, any idea what's going on here? I'm not so familiar with using C functions with assembly, and have quite likely made a beginner's mistake here.
Thanks a lot