cmd_boot.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2008-2011
  4. * Graeme Russ, <graeme.russ@gmail.com>
  5. *
  6. * (C) Copyright 2002
  7. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  8. *
  9. * (C) Copyright 2002
  10. * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
  11. *
  12. * (C) Copyright 2002
  13. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  14. * Marius Groeger <mgroeger@sysgo.de>
  15. */
  16. #include <common.h>
  17. #include <command.h>
  18. #include <malloc.h>
  19. #include <asm/u-boot-x86.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. unsigned long do_go_exec(ulong (*entry)(int, char * const []),
  22. int argc, char *const argv[])
  23. {
  24. unsigned long ret = 0;
  25. char **argv_tmp;
  26. /*
  27. * x86 does not use a dedicated register to pass the pointer to
  28. * the global_data, so it is instead passed as argv[-1]. By using
  29. * argv[-1], the called 'Application' can use the contents of
  30. * argv natively. However, to safely use argv[-1] a new copy of
  31. * argv is needed with the extra element
  32. */
  33. argv_tmp = malloc(sizeof(char *) * (argc + 1));
  34. if (argv_tmp) {
  35. argv_tmp[0] = (char *)gd;
  36. memcpy(&argv_tmp[1], argv, (size_t)(sizeof(char *) * argc));
  37. ret = (entry) (argc, &argv_tmp[1]);
  38. free(argv_tmp);
  39. }
  40. return ret;
  41. }