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 * 15d13640b7SGraeme Russ * See file CREDITS for list of people who contributed to this 16d13640b7SGraeme Russ * project. 17d13640b7SGraeme Russ * 18d13640b7SGraeme Russ * This program is free software; you can redistribute it and/or 19d13640b7SGraeme Russ * modify it under the terms of the GNU General Public License as 20d13640b7SGraeme Russ * published by the Free Software Foundation; either version 2 of 21d13640b7SGraeme Russ * the License, or (at your option) any later version. 22d13640b7SGraeme Russ * 23d13640b7SGraeme Russ * This program is distributed in the hope that it will be useful, 24d13640b7SGraeme Russ * but WITHOUT ANY WARRANTY; without even the implied warranty of 25d13640b7SGraeme Russ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26d13640b7SGraeme Russ * GNU General Public License for more details. 27d13640b7SGraeme Russ * 28d13640b7SGraeme Russ * You should have received a copy of the GNU General Public License 29d13640b7SGraeme Russ * along with this program; if not, write to the Free Software 30d13640b7SGraeme Russ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 31d13640b7SGraeme Russ * MA 02111-1307 USA 32d13640b7SGraeme Russ */ 33d13640b7SGraeme Russ 34d13640b7SGraeme Russ #include <common.h> 35d13640b7SGraeme Russ #include <command.h> 36d13640b7SGraeme Russ #include <malloc.h> 37d13640b7SGraeme Russ #include <asm/u-boot-x86.h> 38d13640b7SGraeme Russ 39*7282d834SSimon Glass DECLARE_GLOBAL_DATA_PTR; 40*7282d834SSimon Glass 41d13640b7SGraeme Russ unsigned long do_go_exec(ulong (*entry)(int, char * const []), 42d13640b7SGraeme Russ int argc, char * const argv[]) 43d13640b7SGraeme Russ { 44d13640b7SGraeme Russ unsigned long ret = 0; 45d13640b7SGraeme Russ char **argv_tmp; 46d13640b7SGraeme Russ 47d13640b7SGraeme Russ /* 48d13640b7SGraeme Russ * x86 does not use a dedicated register to pass the pointer to 49d13640b7SGraeme Russ * the global_data, so it is instead passed as argv[-1]. By using 50d13640b7SGraeme Russ * argv[-1], the called 'Application' can use the contents of 51d13640b7SGraeme Russ * argv natively. However, to safely use argv[-1] a new copy of 52d13640b7SGraeme Russ * argv is needed with the extra element 53d13640b7SGraeme Russ */ 54d13640b7SGraeme Russ argv_tmp = malloc(sizeof(char *) * (argc + 1)); 55d13640b7SGraeme Russ 56d13640b7SGraeme Russ if (argv_tmp) { 57d13640b7SGraeme Russ argv_tmp[0] = (char *)gd; 58d13640b7SGraeme Russ 59d13640b7SGraeme Russ memcpy(&argv_tmp[1], argv, (size_t)(sizeof(char *) * argc)); 60d13640b7SGraeme Russ 61d13640b7SGraeme Russ ret = (entry) (argc, &argv_tmp[1]); 62d13640b7SGraeme Russ free(argv_tmp); 63d13640b7SGraeme Russ } 64d13640b7SGraeme Russ 65d13640b7SGraeme Russ return ret; 66d13640b7SGraeme Russ } 67