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