views:

27

answers:

1

I want to move the value of the variable "userstack" inside the ESP register and then do an absolute jump to the memory address contained in the variable "location". This is what I've got:

// These are the two variables that contains memory addresses
 uint32_t location = current_running->LOCATION;
 uint32_t userstack = current_running->user_stack;

 // And then something like this
 __asm__ volatile ("movl userstack, %esp");
 __asm__ volatile ("ljmp $0x0000, location");

However when I try to compile I get the errors: "Error: suffix or operands invalid for ljmp" and "undefined reference to `userstack'".

Any help would be very much appreciated.

A: 

Take a look at the manual.

I think you'd need something like this:

asm volatile ("movl %0, %esp" : "g" (userstack));
asm volatile ("ljmp $0x0000, %0" : "g" (location));

Basically GCC needs know what and where userstack and location may be (registers, memory operands, floating, restricted subset of registers, etc.) and that is specified by "g", in this case meaning a general operand.

Laurynas Biveinis