blob: baaf3d13ad4bf473749ae28e7f4d051c0e09a1bc [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Graeme Russac52e472011-12-23 10:16:11 +11002/*
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 Russac52e472011-12-23 10:16:11 +110015 */
16
17#include <common.h>
18#include <command.h>
19#include <malloc.h>
20#include <asm/u-boot-x86.h>
21
Simon Glassbb6306c2013-04-17 16:13:33 +000022DECLARE_GLOBAL_DATA_PTR;
23
Graeme Russac52e472011-12-23 10:16:11 +110024unsigned long do_go_exec(ulong (*entry)(int, char * const []),
Simon Glassed38aef2020-05-10 11:40:03 -060025 int argc, char *const argv[])
Graeme Russac52e472011-12-23 10:16:11 +110026{
27 unsigned long ret = 0;
28 char **argv_tmp;
29
30 /*
31 * x86 does not use a dedicated register to pass the pointer to
32 * the global_data, so it is instead passed as argv[-1]. By using
33 * argv[-1], the called 'Application' can use the contents of
34 * argv natively. However, to safely use argv[-1] a new copy of
35 * argv is needed with the extra element
36 */
37 argv_tmp = malloc(sizeof(char *) * (argc + 1));
38
39 if (argv_tmp) {
40 argv_tmp[0] = (char *)gd;
41
42 memcpy(&argv_tmp[1], argv, (size_t)(sizeof(char *) * argc));
43
44 ret = (entry) (argc, &argv_tmp[1]);
45 free(argv_tmp);
46 }
47
48 return ret;
49}