blob: a24d3f013432cef783636b786037c24f492879f5 [file] [log] [blame]
Graeme Russd13640b2011-12-23 10:16:11 +11001/*
2 * (C) Copyright 2008-2011
3 * Graeme Russ, <graeme.russ@gmail.com>
4 *
5 * (C) Copyright 2002
6 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
7 *
8 * (C) Copyright 2002
9 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
10 *
11 * (C) Copyright 2002
12 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
13 * Marius Groeger <mgroeger@sysgo.de>
14 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020015 * SPDX-License-Identifier: GPL-2.0+
Graeme Russd13640b2011-12-23 10:16:11 +110016 */
17
18#include <common.h>
19#include <command.h>
20#include <malloc.h>
21#include <asm/u-boot-x86.h>
22
Simon Glass7282d832013-04-17 16:13:33 +000023DECLARE_GLOBAL_DATA_PTR;
24
Graeme Russd13640b2011-12-23 10:16:11 +110025unsigned long do_go_exec(ulong (*entry)(int, char * const []),
26 int argc, char * const argv[])
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}