cmd_boot.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * (C) Copyright 2008-2011
  3. * Graeme Russ, <graeme.russ@gmail.com>
  4. *
  5. * (C) Copyright 2002
  6. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  7. *
  8. * (C) Copyright 2002
  9. * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
  10. *
  11. * (C) Copyright 2002
  12. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  13. * Marius Groeger <mgroeger@sysgo.de>
  14. *
  15. * See file CREDITS for list of people who contributed to this
  16. * project.
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License as
  20. * published by the Free Software Foundation; either version 2 of
  21. * the License, or (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program; if not, write to the Free Software
  30. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  31. * MA 02111-1307 USA
  32. */
  33. #include <common.h>
  34. #include <command.h>
  35. #include <malloc.h>
  36. #include <asm/u-boot-x86.h>
  37. unsigned long do_go_exec(ulong (*entry)(int, char * const []),
  38. int argc, char * const argv[])
  39. {
  40. unsigned long ret = 0;
  41. char **argv_tmp;
  42. /*
  43. * x86 does not use a dedicated register to pass the pointer to
  44. * the global_data, so it is instead passed as argv[-1]. By using
  45. * argv[-1], the called 'Application' can use the contents of
  46. * argv natively. However, to safely use argv[-1] a new copy of
  47. * argv is needed with the extra element
  48. */
  49. argv_tmp = malloc(sizeof(char *) * (argc + 1));
  50. if (argv_tmp) {
  51. argv_tmp[0] = (char *)gd;
  52. memcpy(&argv_tmp[1], argv, (size_t)(sizeof(char *) * argc));
  53. ret = (entry) (argc, &argv_tmp[1]);
  54. free(argv_tmp);
  55. }
  56. return ret;
  57. }