Root/usbboot/xburst_stage2/main.c

1/*
2 * Copyright (C) 2009 Qi Hardware Inc.,
3 * Author: Xiangfu Liu <xiangfu@sharism.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 3 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA
18 */
19#include "usb_boot_defines.h"
20
21extern void usb_main();
22extern unsigned int UART_BASE;
23struct fw_args *fw_args;
24unsigned int start_addr,got_start,got_end;
25
26void c_main(void)
27{
28    volatile unsigned int addr,offset;
29    /* get absolute start address */
30    __asm__ __volatile__(
31        "move %0, $20\n\t"
32        : "=r"(start_addr)
33        :
34        );
35
36    /* get related GOT address */
37    __asm__ __volatile__(
38        "la $4, _GLOBAL_OFFSET_TABLE_\n\t"
39        "move %0, $4\n\t"
40        "la $5, _got_end\n\t"
41        "move %1, $5\n\t"
42        : "=r"(got_start),"=r"(got_end)
43        :
44        );
45
46    /* calculate offset and correct GOT*/
47    offset = start_addr - 0x80000000;
48     got_start += offset;
49    got_end += offset;
50    /* add offset to correct all GOT */
51    for(addr = got_start + 8; addr < got_end; addr += 4)
52        *((volatile unsigned int *)(addr)) += offset;
53    
54    /* get the fw args from memory */
55    fw_args = (struct fw_args *)(start_addr + 0x8);
56
57    extern struct hand Hand;
58    Hand.fw_args.cpu_id = fw_args->cpu_id;
59
60    UART_BASE = 0xB0030000 + fw_args->use_uart * 0x1000;
61
62    serial_puts("\n Stage2 start address is :\t");
63    serial_put_hex(start_addr);
64    serial_puts("\n Address offset is:\t");
65    serial_put_hex(offset);
66    serial_puts("\n GOT correct to :\t");
67    serial_put_hex(got_start);
68
69    usb_main();
70}
71

Archive Download this file



interactive