Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Graeme Russ | d13640b | 2011-12-23 10:16:11 +1100 | [diff] [blame] | 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> |
Graeme Russ | d13640b | 2011-12-23 10:16:11 +1100 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <common.h> |
| 18 | #include <command.h> |
| 19 | #include <malloc.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Graeme Russ | d13640b | 2011-12-23 10:16:11 +1100 | [diff] [blame] | 21 | #include <asm/u-boot-x86.h> |
| 22 | |
Simon Glass | 7282d83 | 2013-04-17 16:13:33 +0000 | [diff] [blame] | 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Graeme Russ | d13640b | 2011-12-23 10:16:11 +1100 | [diff] [blame] | 25 | unsigned long do_go_exec(ulong (*entry)(int, char * const []), |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 26 | int argc, char *const argv[]) |
Graeme Russ | d13640b | 2011-12-23 10:16:11 +1100 | [diff] [blame] | 27 | { |
| 28 | unsigned long ret = 0; |
| 29 | char **argv_tmp; |
| 30 | |
| 31 | /* |
| 32 | * x86 does not use a dedicated register to pass the pointer to |
| 33 | * the global_data, so it is instead passed as argv[-1]. By using |
| 34 | * argv[-1], the called 'Application' can use the contents of |
| 35 | * argv natively. However, to safely use argv[-1] a new copy of |
| 36 | * argv is needed with the extra element |
| 37 | */ |
| 38 | argv_tmp = malloc(sizeof(char *) * (argc + 1)); |
| 39 | |
| 40 | if (argv_tmp) { |
| 41 | argv_tmp[0] = (char *)gd; |
| 42 | |
| 43 | memcpy(&argv_tmp[1], argv, (size_t)(sizeof(char *) * argc)); |
| 44 | |
| 45 | ret = (entry) (argc, &argv_tmp[1]); |
| 46 | free(argv_tmp); |
| 47 | } |
| 48 | |
| 49 | return ret; |
| 50 | } |