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