4

in do_IRQ you can find the following code!

#ifdef CONFIG_DEBUG_STACKOVERFLOW
   /* Debugging check for stack overflow: is there less than 1KB free? */
    {
       long esp;

        __asm__ __volatile__("andl %%esp,%0" :
                "=r" (esp) : "0" (THREAD_SIZE - 1));
       if (unlikely(esp < (sizeof(struct thread_info) + STACK_WARN))) {
           printk("do_IRQ: stack overflow: %ld\n",
                esp - sizeof(struct thread_info));
            dump_stack();
        }
    }
#endif

i did't understand the meaning of this asm assembly
asm _volatile_("andl %%esp,%0" : "=r" (esp) : "0" (THREAD_SIZE - 1)); THREAD_SIZE - 1 means what? I remeber the symbol in the parenthesis should be the C variable like the esp in the output part, but in the input part it looks like a integer but not a C symbol, can some noe help

Adambynes
  • 197
  • 1
  • 10

1 Answers1

3

The "0" constraint means: use the same constraints as the 0th operands (http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#ss6.1, and 6.1.3 Matching(Digit) constraints).

Basically, this snippet takes THREAD_SIZE - 1 as an input register, and output an anded value in the same register. This register is referenced as the esp variable in the source code.

Benny
  • 4,095
  • 1
  • 26
  • 27
  • 1
    "... the same constraints ..." in this context means ... the same register. I.e. here, this says "pass `(THREAD_SIZE - 1)` (as a constant / as input) in the same register that you return `esp` in". One could have written `long esp = (THREAD_SIZE - 1); __asm__("andl %%esp,%0" : "+r"(esp));` instead. – FrankH. Feb 20 '14 at 11:02
  • I was wondering if we could replace this code by the `"+r"` constraint; and you confirmed that, thanks! – Benny Feb 20 '14 at 11:05
  • 1
    thanks for the answer, I think the THREAD_SIZE-1 is used for the init of the esp value, thanks again for the help – Adambynes Feb 21 '14 at 04:25