blob: 0b26c831338e80083d7bbbcfbbb9a7af5622405a [file] [log] [blame]
wdenk2262cfe2002-11-18 00:14:45 +00001/*
2 * (C) Copyright 2002
Graeme Russ9963a822011-02-12 15:11:26 +11003 * Daniel Engström, Omicron Ceti AB, daniel@omicron.se
wdenk8bde7f72003-06-27 21:31:46 +00004 *
wdenk2262cfe2002-11-18 00:14:45 +00005 * (C) Copyright 2002
6 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk8bde7f72003-06-27 21:31:46 +00007 *
wdenk2262cfe2002-11-18 00:14:45 +00008 * (C) Copyright 2002
9 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
10 * Marius Groeger <mgroeger@sysgo.de>
11 *
12 * See file CREDITS for list of people who contributed to this
13 * project.
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
29 */
30
31#include <common.h>
32#include <watchdog.h>
33#include <command.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020034#include <stdio_dev.h>
Peter Tyser561858e2008-11-03 09:30:59 -060035#include <timestamp.h>
wdenk2262cfe2002-11-18 00:14:45 +000036#include <version.h>
37#include <malloc.h>
wdenk2262cfe2002-11-18 00:14:45 +000038#include <net.h>
39#include <ide.h>
Graeme Russbf165002010-04-24 00:05:47 +100040#include <serial.h>
wdenk7a8e9bed2003-05-31 18:35:21 +000041#include <asm/u-boot-i386.h>
Graeme Russ1c409bc2009-11-24 20:04:21 +110042#include <elf.h>
wdenk2262cfe2002-11-18 00:14:45 +000043
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +020044#ifdef CONFIG_BITBANGMII
45#include <miiphy.h>
46#endif
47
Graeme Russ2e2613d2011-02-12 15:11:50 +110048/*
49 * Pointer to initial global data area
50 *
51 * Here we initialize it.
52 */
53#undef XTRN_DECLARE_GLOBAL_DATA_PTR
54#define XTRN_DECLARE_GLOBAL_DATA_PTR /* empty = allocate here */
55DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CONFIG_SYS_INIT_GD_ADDR);
56
Wolfgang Denkd87080b2006-03-31 18:32:53 +020057
Graeme Russ1c409bc2009-11-24 20:04:21 +110058/* Exports from the Linker Script */
Graeme Russ067f9b12010-10-07 20:03:31 +110059extern ulong __text_start;
Graeme Russ22191422010-10-07 20:03:32 +110060extern ulong __data_end;
Graeme Russ067f9b12010-10-07 20:03:31 +110061extern ulong __rel_dyn_start;
62extern ulong __rel_dyn_end;
63extern ulong __bss_start;
Graeme Russf2ff75c2010-10-07 20:03:33 +110064extern ulong __bss_end;
Graeme Russ2fb1bc42010-04-24 00:05:44 +100065
wdenk2262cfe2002-11-18 00:14:45 +000066const char version_string[] =
Peter Tyser561858e2008-11-03 09:30:59 -060067 U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")";
wdenk2262cfe2002-11-18 00:14:45 +000068
wdenk2262cfe2002-11-18 00:14:45 +000069/************************************************************************
70 * Init Utilities *
71 ************************************************************************
72 * Some of this code should be moved into the core functions,
73 * or dropped completely,
74 * but let's get it working (again) first...
75 */
wdenk2262cfe2002-11-18 00:14:45 +000076static int init_baudrate (void)
77{
wdenk7a8e9bed2003-05-31 18:35:21 +000078 char tmp[64]; /* long enough for environment variables */
Wolfgang Denkcdb74972010-07-24 21:55:43 +020079 int i = getenv_f("baudrate", tmp, 64);
wdenk2262cfe2002-11-18 00:14:45 +000080
wdenk7a8e9bed2003-05-31 18:35:21 +000081 gd->baudrate = (i != 0)
wdenk2262cfe2002-11-18 00:14:45 +000082 ? (int) simple_strtoul (tmp, NULL, 10)
83 : CONFIG_BAUDRATE;
84
85 return (0);
86}
87
88static int display_banner (void)
89{
90
91 printf ("\n\n%s\n\n", version_string);
Graeme Russ1c409bc2009-11-24 20:04:21 +110092/*
wdenk2262cfe2002-11-18 00:14:45 +000093 printf ("U-Boot code: %08lX -> %08lX data: %08lX -> %08lX\n"
94 " BSS: %08lX -> %08lX stack: %08lX -> %08lX\n",
95 i386boot_start, i386boot_romdata_start-1,
96 i386boot_romdata_dest, i386boot_romdata_dest+i386boot_romdata_size-1,
97 i386boot_bss_start, i386boot_bss_start+i386boot_bss_size-1,
wdenk8bde7f72003-06-27 21:31:46 +000098 i386boot_bss_start+i386boot_bss_size,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020099 i386boot_bss_start+i386boot_bss_size+CONFIG_SYS_STACK_SIZE-1);
wdenk8bde7f72003-06-27 21:31:46 +0000100
Graeme Russ1c409bc2009-11-24 20:04:21 +1100101*/
wdenk2262cfe2002-11-18 00:14:45 +0000102
103 return (0);
104}
105
106/*
107 * WARNING: this code looks "cleaner" than the PowerPC version, but
108 * has the disadvantage that you either get nothing, or everything.
109 * On PowerPC, you might see "DRAM: " before the system hangs - which
110 * gives a simple yet clear indication which part of the
111 * initialization if failing.
112 */
113static int display_dram_config (void)
114{
wdenk2262cfe2002-11-18 00:14:45 +0000115 int i;
116
117 puts ("DRAM Configuration:\n");
118
119 for (i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
120 printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
121 print_size (gd->bd->bi_dram[i].size, "\n");
122 }
wdenk8bde7f72003-06-27 21:31:46 +0000123
wdenk2262cfe2002-11-18 00:14:45 +0000124 return (0);
125}
126
127static void display_flash_config (ulong size)
128{
129 puts ("Flash: ");
130 print_size (size, "\n");
131}
132
wdenk2262cfe2002-11-18 00:14:45 +0000133/*
134 * Breath some life into the board...
135 *
136 * Initialize an SMC for serial comms, and carry out some hardware
137 * tests.
138 *
139 * The first part of initialization is running from Flash memory;
140 * its main purpose is to initialize the RAM so that we
141 * can relocate the monitor code to RAM.
142 */
143
Graeme Russ1c409bc2009-11-24 20:04:21 +1100144
wdenk2262cfe2002-11-18 00:14:45 +0000145/*
146 * All attempts to come up with a "common" initialization sequence
147 * that works for all boards and architectures failed: some of the
148 * requirements are just _too_ different. To get rid of the resulting
149 * mess of board dependend #ifdef'ed code we now make the whole
150 * initialization sequence configurable to the user.
151 *
152 * The requirements for any new initalization function is simple: it
153 * receives a pointer to the "global data" structure as it's only
154 * argument, and returns an integer return code, where 0 means
155 * "continue" and != 0 means "fatal error, hang the system".
156 */
157typedef int (init_fnc_t) (void);
158
159init_fnc_t *init_sequence[] = {
Graeme Russ1c409bc2009-11-24 20:04:21 +1100160 cpu_init_r, /* basic cpu dependent setup */
161 board_early_init_r, /* basic board dependent setup */
wdenk2262cfe2002-11-18 00:14:45 +0000162 dram_init, /* configure available RAM banks */
wdenk2262cfe2002-11-18 00:14:45 +0000163 interrupt_init, /* set up exceptions */
wdenk8bde7f72003-06-27 21:31:46 +0000164 timer_init,
wdenk2262cfe2002-11-18 00:14:45 +0000165 env_init, /* initialize environment */
166 init_baudrate, /* initialze baudrate settings */
167 serial_init, /* serial communications setup */
168 display_banner,
169 display_dram_config,
170
171 NULL,
172};
173
Graeme Russ3ef96de2008-09-07 07:08:42 +1000174gd_t *gd;
wdenk2262cfe2002-11-18 00:14:45 +0000175
Graeme Russ1c409bc2009-11-24 20:04:21 +1100176/*
177 * Load U-Boot into RAM, initialize BSS, perform relocation adjustments
178 */
Graeme Russ96cd6642011-02-12 15:11:54 +1100179void board_init_f(ulong boot_flags)
Graeme Russ1c409bc2009-11-24 20:04:21 +1100180{
Graeme Russ067f9b12010-10-07 20:03:31 +1100181 void *text_start = &__text_start;
Graeme Russ22191422010-10-07 20:03:32 +1100182 void *data_end = &__data_end;
Graeme Russf2ff75c2010-10-07 20:03:33 +1100183 void *rel_dyn_start = &__rel_dyn_start;
184 void *rel_dyn_end = &__rel_dyn_end;
Graeme Russ067f9b12010-10-07 20:03:31 +1100185 void *bss_start = &__bss_start;
Graeme Russf2ff75c2010-10-07 20:03:33 +1100186 void *bss_end = &__bss_end;
Graeme Russ1c409bc2009-11-24 20:04:21 +1100187
Graeme Russf2ff75c2010-10-07 20:03:33 +1100188 ulong *dst_addr;
189 ulong *src_addr;
190 ulong *end_addr;
191
Graeme Russfb002902011-02-12 15:11:58 +1100192 void *addr_sp;
Graeme Russ2fb1bc42010-04-24 00:05:44 +1000193 void *dest_addr;
Graeme Russ1c409bc2009-11-24 20:04:21 +1100194 ulong rel_offset;
Graeme Russf2ff75c2010-10-07 20:03:33 +1100195 Elf32_Rel *re_src;
196 Elf32_Rel *re_end;
Graeme Russ1c409bc2009-11-24 20:04:21 +1100197
Graeme Russ96cd6642011-02-12 15:11:54 +1100198 gd->flags = boot_flags;
199
Graeme Russc869e2a2011-02-12 15:11:59 +1100200 if (dram_init_f() != 0)
201 hang();
202
Graeme Russf2ff75c2010-10-07 20:03:33 +1100203 /* Calculate destination RAM Address and relocation offset */
Graeme Russ96cd6642011-02-12 15:11:54 +1100204 dest_addr = (void *)gd->ram_size;
Graeme Russfb002902011-02-12 15:11:58 +1100205 addr_sp = dest_addr;
Graeme Russ96cd6642011-02-12 15:11:54 +1100206 dest_addr -= CONFIG_SYS_STACK_SIZE;
207 dest_addr -= (bss_end - text_start);
Graeme Russ2fb1bc42010-04-24 00:05:44 +1000208 rel_offset = text_start - dest_addr;
Graeme Russ1c409bc2009-11-24 20:04:21 +1100209
Graeme Russc868af32010-10-07 20:03:33 +1100210 /* Perform low-level initialization only when cold booted */
Graeme Russ2e2613d2011-02-12 15:11:50 +1100211 if (gd->flags & GD_FLG_COLD_BOOT) {
Graeme Russc868af32010-10-07 20:03:33 +1100212 /* First stage CPU initialization */
213 if (cpu_init_f() != 0)
214 hang();
Graeme Russ1c409bc2009-11-24 20:04:21 +1100215
Graeme Russc868af32010-10-07 20:03:33 +1100216 /* First stage Board initialization */
217 if (board_early_init_f() != 0)
218 hang();
219 }
Graeme Russ1c409bc2009-11-24 20:04:21 +1100220
221 /* Copy U-Boot into RAM */
Graeme Russf2ff75c2010-10-07 20:03:33 +1100222 dst_addr = (ulong *)dest_addr;
Graeme Russ2e2613d2011-02-12 15:11:50 +1100223 src_addr = (ulong *)(text_start + gd->load_off);
224 end_addr = (ulong *)(data_end + gd->load_off);
Graeme Russf2ff75c2010-10-07 20:03:33 +1100225
226 while (src_addr < end_addr)
227 *dst_addr++ = *src_addr++;
Graeme Russ1c409bc2009-11-24 20:04:21 +1100228
229 /* Clear BSS */
Graeme Russf2ff75c2010-10-07 20:03:33 +1100230 dst_addr = (ulong *)(bss_start - rel_offset);
231 end_addr = (ulong *)(bss_end - rel_offset);
232
233 while (dst_addr < end_addr)
234 *dst_addr++ = 0x00000000;
Graeme Russ1c409bc2009-11-24 20:04:21 +1100235
236 /* Perform relocation adjustments */
Graeme Russ2e2613d2011-02-12 15:11:50 +1100237 re_src = (Elf32_Rel *)(rel_dyn_start + gd->load_off);
238 re_end = (Elf32_Rel *)(rel_dyn_end + gd->load_off);
Graeme Russf2ff75c2010-10-07 20:03:33 +1100239
240 do {
Wolfgang Denk14d0a022010-10-07 21:51:12 +0200241 if (re_src->r_offset >= CONFIG_SYS_TEXT_BASE)
242 if (*(Elf32_Addr *)(re_src->r_offset - rel_offset) >= CONFIG_SYS_TEXT_BASE)
Graeme Russf2ff75c2010-10-07 20:03:33 +1100243 *(Elf32_Addr *)(re_src->r_offset - rel_offset) -= rel_offset;
244 } while (re_src++ < re_end);
Graeme Russ1c409bc2009-11-24 20:04:21 +1100245
Graeme Russ2e2613d2011-02-12 15:11:50 +1100246 gd->reloc_off = rel_offset;
247 gd->flags |= GD_FLG_RELOC;
Graeme Russ161b3582010-10-07 20:03:29 +1100248
Graeme Russ2fb1bc42010-04-24 00:05:44 +1000249 /* Enter the relocated U-Boot! */
Graeme Russfb002902011-02-12 15:11:58 +1100250 relocate_code((ulong)addr_sp, gd, (ulong)dest_addr);
Graeme Russ161b3582010-10-07 20:03:29 +1100251
Graeme Russfb002902011-02-12 15:11:58 +1100252 /* NOTREACHED - relocate_code() does not return */
Graeme Russ1c409bc2009-11-24 20:04:21 +1100253 while(1);
254}
255
Graeme Russ2fb1bc42010-04-24 00:05:44 +1000256void board_init_r(gd_t *id, ulong dest_addr)
wdenk2262cfe2002-11-18 00:14:45 +0000257{
wdenk2262cfe2002-11-18 00:14:45 +0000258 char *s;
259 int i;
260 ulong size;
wdenk2262cfe2002-11-18 00:14:45 +0000261 static bd_t bd_data;
Graeme Russ2e2613d2011-02-12 15:11:50 +1100262 static gd_t gd_data;
wdenk2262cfe2002-11-18 00:14:45 +0000263 init_fnc_t **init_fnc_ptr;
wdenk8bde7f72003-06-27 21:31:46 +0000264
wdenk2262cfe2002-11-18 00:14:45 +0000265 show_boot_progress(0x21);
266
Graeme Russ2e2613d2011-02-12 15:11:50 +1100267 /* Global data pointer is now writable */
268 gd = &gd_data;
269 memcpy(gd, id, sizeof(gd_t));
270
wdenk93f6a672004-07-01 20:28:03 +0000271 /* compiler optimization barrier needed for GCC >= 3.4 */
272 __asm__ __volatile__("": : :"memory");
wdenk8bde7f72003-06-27 21:31:46 +0000273
wdenk2262cfe2002-11-18 00:14:45 +0000274 gd->bd = &bd_data;
275 memset (gd->bd, 0, sizeof (bd_t));
276 show_boot_progress(0x22);
277
wdenk7a8e9bed2003-05-31 18:35:21 +0000278 gd->baudrate = CONFIG_BAUDRATE;
wdenk8bde7f72003-06-27 21:31:46 +0000279
Graeme Russ2fb1bc42010-04-24 00:05:44 +1000280 mem_malloc_init((((ulong)dest_addr - CONFIG_SYS_MALLOC_LEN)+3)&~3,
Graeme Russ1c409bc2009-11-24 20:04:21 +1100281 CONFIG_SYS_MALLOC_LEN);
282
wdenk2262cfe2002-11-18 00:14:45 +0000283 for (init_fnc_ptr = init_sequence, i=0; *init_fnc_ptr; ++init_fnc_ptr, i++) {
284 show_boot_progress(0xa130|i);
285
286 if ((*init_fnc_ptr)() != 0) {
287 hang ();
288 }
289 }
290 show_boot_progress(0x23);
291
Graeme Russbf165002010-04-24 00:05:47 +1000292#ifdef CONFIG_SERIAL_MULTI
293 serial_initialize();
294#endif
wdenk2262cfe2002-11-18 00:14:45 +0000295 /* configure available FLASH banks */
296 size = flash_init();
297 display_flash_config(size);
298 show_boot_progress(0x24);
299
300 show_boot_progress(0x25);
301
302 /* initialize environment */
303 env_relocate ();
304 show_boot_progress(0x26);
305
306
Graeme Russ535ad2d2010-04-24 00:05:36 +1000307#ifdef CONFIG_CMD_NET
wdenk2262cfe2002-11-18 00:14:45 +0000308 /* IP Address */
309 bd_data.bi_ip_addr = getenv_IPaddr ("ipaddr");
Graeme Russ535ad2d2010-04-24 00:05:36 +1000310#endif
wdenk2262cfe2002-11-18 00:14:45 +0000311
wdenk2262cfe2002-11-18 00:14:45 +0000312#if defined(CONFIG_PCI)
313 /*
314 * Do pci configuration
315 */
316 pci_init();
317#endif
318
319 show_boot_progress(0x27);
320
321
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200322 stdio_init ();
wdenk2262cfe2002-11-18 00:14:45 +0000323
wdenk27b207f2003-07-24 23:38:38 +0000324 jumptable_init ();
wdenk8bde7f72003-06-27 21:31:46 +0000325
wdenk2262cfe2002-11-18 00:14:45 +0000326 /* Initialize the console (after the relocation and devices init) */
327 console_init_r();
wdenk2262cfe2002-11-18 00:14:45 +0000328
329#ifdef CONFIG_MISC_INIT_R
330 /* miscellaneous platform dependent initialisations */
331 misc_init_r();
332#endif
333
Jon Loeliger67350562007-07-09 18:05:38 -0500334#if defined(CONFIG_CMD_PCMCIA) && !defined(CONFIG_CMD_IDE)
wdenk2262cfe2002-11-18 00:14:45 +0000335 WATCHDOG_RESET();
336 puts ("PCMCIA:");
337 pcmcia_init();
338#endif
339
Jon Loeliger67350562007-07-09 18:05:38 -0500340#if defined(CONFIG_CMD_KGDB)
wdenk2262cfe2002-11-18 00:14:45 +0000341 WATCHDOG_RESET();
342 puts("KGDB: ");
343 kgdb_init();
344#endif
345
346 /* enable exceptions */
wdenk7a8e9bed2003-05-31 18:35:21 +0000347 enable_interrupts();
wdenk2262cfe2002-11-18 00:14:45 +0000348 show_boot_progress(0x28);
349
wdenk2262cfe2002-11-18 00:14:45 +0000350#ifdef CONFIG_STATUS_LED
351 status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
352#endif
353
wdenk7a8e9bed2003-05-31 18:35:21 +0000354 udelay(20);
wdenk2262cfe2002-11-18 00:14:45 +0000355
356 set_timer (0);
357
358 /* Initialize from environment */
359 if ((s = getenv ("loadaddr")) != NULL) {
360 load_addr = simple_strtoul (s, NULL, 16);
361 }
Jon Loeliger67350562007-07-09 18:05:38 -0500362#if defined(CONFIG_CMD_NET)
wdenk2262cfe2002-11-18 00:14:45 +0000363 if ((s = getenv ("bootfile")) != NULL) {
364 copy_filename (BootFile, s, sizeof (BootFile));
365 }
Jon Loeligerb3aff0c2007-07-10 11:19:50 -0500366#endif
wdenk2262cfe2002-11-18 00:14:45 +0000367
368 WATCHDOG_RESET();
369
Jon Loeliger67350562007-07-09 18:05:38 -0500370#if defined(CONFIG_CMD_IDE)
wdenk2262cfe2002-11-18 00:14:45 +0000371 WATCHDOG_RESET();
372 puts("IDE: ");
373 ide_init();
Jon Loeligerb3aff0c2007-07-10 11:19:50 -0500374#endif
wdenk2262cfe2002-11-18 00:14:45 +0000375
Jon Loeliger67350562007-07-09 18:05:38 -0500376#if defined(CONFIG_CMD_SCSI)
wdenk2262cfe2002-11-18 00:14:45 +0000377 WATCHDOG_RESET();
378 puts("SCSI: ");
379 scsi_init();
380#endif
381
Jon Loeliger67350562007-07-09 18:05:38 -0500382#if defined(CONFIG_CMD_DOC)
wdenk2262cfe2002-11-18 00:14:45 +0000383 WATCHDOG_RESET();
wdenk7a8e9bed2003-05-31 18:35:21 +0000384 puts("DOC: ");
wdenk2262cfe2002-11-18 00:14:45 +0000385 doc_init();
386#endif
387
Luigi 'Comio' Mantellini310cecb2009-10-10 12:42:21 +0200388#ifdef CONFIG_BITBANGMII
389 bb_miiphy_init();
390#endif
Jon Loeliger67350562007-07-09 18:05:38 -0500391#if defined(CONFIG_CMD_NET)
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200392#if defined(CONFIG_NET_MULTI)
wdenk2262cfe2002-11-18 00:14:45 +0000393 WATCHDOG_RESET();
394 puts("Net: ");
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200395#endif
wdenk2262cfe2002-11-18 00:14:45 +0000396 eth_initialize(gd->bd);
397#endif
398
Jon Loeliger67350562007-07-09 18:05:38 -0500399#if ( defined(CONFIG_CMD_NET)) && (0)
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200400 WATCHDOG_RESET();
401# ifdef DEBUG
402 puts ("Reset Ethernet PHY\n");
403# endif
404 reset_phy();
405#endif
406
wdenk2262cfe2002-11-18 00:14:45 +0000407#ifdef CONFIG_LAST_STAGE_INIT
408 WATCHDOG_RESET();
409 /*
410 * Some parts can be only initialized if all others (like
411 * Interrupts) are up and running (i.e. the PC-style ISA
412 * keyboard).
413 */
414 last_stage_init();
415#endif
416
417
wdenk2262cfe2002-11-18 00:14:45 +0000418#ifdef CONFIG_POST
419 post_run (NULL, POST_RAM | post_bootmode_get(0));
wdenk2262cfe2002-11-18 00:14:45 +0000420#endif
wdenk8bde7f72003-06-27 21:31:46 +0000421
422
wdenk2262cfe2002-11-18 00:14:45 +0000423 show_boot_progress(0x29);
wdenk8bde7f72003-06-27 21:31:46 +0000424
wdenk2262cfe2002-11-18 00:14:45 +0000425 /* main_loop() can return to retry autoboot, if so just run it again. */
426 for (;;) {
wdenk7a8e9bed2003-05-31 18:35:21 +0000427 main_loop();
wdenk2262cfe2002-11-18 00:14:45 +0000428 }
429
430 /* NOTREACHED - no way out of command loop except booting */
431}
432
433void hang (void)
434{
435 puts ("### ERROR ### Please RESET the board ###\n");
436 for (;;);
437}
Mike Frysingera4986452008-04-13 19:42:19 -0400438
Graeme Russe69c0cb2010-08-22 16:25:58 +1000439unsigned long do_go_exec (ulong (*entry)(int, char * const []), int argc, char * const argv[])
Mike Frysingera4986452008-04-13 19:42:19 -0400440{
Graeme Russe69c0cb2010-08-22 16:25:58 +1000441 unsigned long ret = 0;
442 char **argv_tmp;
Graeme Russ9e08efc2010-04-24 00:05:39 +1000443
Graeme Russe69c0cb2010-08-22 16:25:58 +1000444 /*
445 * x86 does not use a dedicated register to pass the pointer to
446 * the global_data, so it is instead passed as argv[-1]. By using
447 * argv[-1], the called 'Application' can use the contents of
448 * argv natively. However, to safely use argv[-1] a new copy of
449 * argv is needed with the extra element
450 */
451 argv_tmp = malloc(sizeof(char *) * (argc + 1));
452
453 if (argv_tmp) {
454 argv_tmp[0] = (char *)gd;
455
456 memcpy(&argv_tmp[1], argv, (size_t)(sizeof(char *) * argc));
457
458 ret = (entry) (argc, &argv_tmp[1]);
459 free(argv_tmp);
460 }
461
462 return ret;
Mike Frysingera4986452008-04-13 19:42:19 -0400463}
Graeme Russ79ea6b82010-04-24 00:05:48 +1000464
465void setup_pcat_compatibility(void)
466 __attribute__((weak, alias("__setup_pcat_compatibility")));
467
468void __setup_pcat_compatibility(void)
469{
470}