From: Gordon Matzigkeit <[EMAIL PROTECTED]>
Subject: Re: cleanups and /sbin/grub GUI works
Date: 15 Mar 1999 08:03:48 -0600

> I realize this, and have checked to make sure that asmstub.c is
> entirely self-contained (i.e. the critical section in grub_stage2
> doesn't contain any references to the old stack).  What I am having
> problems with is getting GCC not to clobber the stack with its
> optimizations.

  As long as I know, if you don't use any variable on a stack in the
function where the stack pointer is changed, that's safe. For example,
this below works correctly:

#include <stdio.h>
#include <string.h>

static volatile int foo;
static void *new_stack;
static void *old_stack;

int
main (int argc, char *argv[])
{
  new_stack = malloc (1024);
  foo = argc;
  asm volatile ("movl %%esp, %0\n\tmovl %1, %%esp\n"
                : "=r" (old_stack) : "r" (new_stack));
  printf ("argc = %d\n", foo);
  asm volatile ("movl %0, %%esp\n"
                : : "r" (old_stack));
  free (new_stack);
  return 0;
}

----------------------------------------------------------------------
OKUJI Yoshinori  <[EMAIL PROTECTED]>           ^o-o^
http://duff.kuicr.kyoto-u.ac.jp/~okuji (in English)     m /

Reply via email to