0

how to jump in GCC inline asm without passing the value to a register?

this code

__asm__("jmp %0"::"r"(&_start))

generates:

mov    eax,0x1011
jmp    eax

but instead i want

jmp 0x1011

or just jmp +0x11,

  • tried using "m" instead of "r" and produces: memory input 0 is not directly addressable.

how can i just obtain a jump instruction without the overhead of using a register? Is this even possible with GCC inline asm?

Jester
  • 56,577
  • 4
  • 81
  • 125
Raffaello
  • 1,641
  • 15
  • 29
  • Is `jmp .+0x11` what you want? Or maybe `"m" (_start)` without the `&`? What is `_start`? – Jester Feb 03 '23 at 01:00
  • 1
    https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#GenericOperandmodifiers - `jmp %l0` with an `"i"(_start)` constraint probably works. Something like that. – Peter Cordes Feb 03 '23 at 03:25
  • 1
    Or `%p0` for a raw symbol name (or numeric address) from an `"i"(_start)` constraint. Or `&_start` I guess if it's not something that is an address if you use the bare name, like a function declaration or `extern char _start[]` – Peter Cordes Feb 03 '23 at 05:29
  • @Jester _start is a function., that is a function entry point to call _start, it has no return, so no reason to use call and i have information on register to pass on _start, this jmp function is just an experiment to hijack and override the stack pointer before starting a kernel – Raffaello Feb 03 '23 at 09:17
  • @PeterCordes yes with the `i` i achieved what i wanted. – Raffaello Feb 03 '23 at 09:21
  • Not really sure if this can be that duplicate question though as this is using `jmp`. Ok conceptually the `i` part is the same, but it won't appear in searches, infact i didn't find at all that question. – Raffaello Feb 03 '23 at 09:21
  • 1
    It's a duplicate because the non-trivial part is getting GCC to print the symbol name in the asm template, rather than a register name. This question is a signpost for people looking for it with `jmp` instead of `call`. That's the point of the duplicate system on stack overflow, why it's a closure reason not a deletion. – Peter Cordes Feb 03 '23 at 16:01

0 Answers0