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