pupa-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Weird behavior of nested functions


From: Marco Gerards
Subject: Weird behavior of nested functions
Date: 09 Nov 2003 23:16:57 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Hi,

Some of my test code that worked on pupa-emu didn't work for me on
real hardware.  I have included some code to demonstrate what the
problem is.

This test code is the same as the hello module code with some minor
modifications.  I have a function do_foo and a variable test in
pupa_foo.  If I access test from within pupa_foo it works perfectly,
but from within pupa_foo it doesn't work.

This only happens if do_foo has 3 or more arguments and as I said this
does not happen when running from GNU/Linux, etc.

This is the output when running this from PUPA:

pupa> foo
foo before: 2
foo: -65536
foo after: 2

I'm using gcc version 3.2.2 and binutils "2.13.90.0.18 20030121".  If
you need more information, please ask me.

I hope this is no stupid mistake from my side (I doubt this, but of
course this is possible).  Does someone have an idea what can cause
this weird behavior and how this can be fixed?

Thanks,
Marco

/* test.c - test module for dynamic loading */
/*
 *  PUPA  --  Preliminary Universal Programming Architecture for GRUB
 *  Copyright (C) 2003  NIIBE Yutaka <address@hidden>
 *  Copyright (C) 2003  Marco Gerards <address@hidden>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <pupa/types.h>
#include <pupa/misc.h>
#include <pupa/mm.h>
#include <pupa/err.h>
#include <pupa/dl.h>
#include <pupa/normal.h>

static int
pupa_foo (void)
{
  int test;

  int do_foo (int a, int b, int c)
    {
      pupa_printf ("Foo: %d\n", test);
      return 0;
    }

  test = 2;
  pupa_printf ("foo before: %d\n", test);
  do_foo (0, 0, 0);
  pupa_printf ("foo after: %d\n", test);

  return 0;
}

static int
pupa_cmd_foo (int argc, char *argv[])
{
  (void)argc;  (void)argv;      /* To stop warning. */
  pupa_foo ();

  return 0;
}

PUPA_MOD_INIT
{
  (void)mod;                    /* To stop warning. */
  pupa_register_command ("foo", pupa_cmd_foo, PUPA_COMMAND_FLAG_BOTH,
                         "foo", "Say foo");
}

PUPA_MOD_FINI
{
  pupa_unregister_command ("foo");
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]