| 1 | /* |
| 2 | * Copyright (C) 2009 Qi Hardware Inc., |
| 3 | * Author: Xiangfu Liu <xiangfu@qi-hardware.com> |
| 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 | |
| 21 | extern void usb_main(); |
| 22 | unsigned int start_addr,got_start,got_end; |
| 23 | extern unsigned int UART_BASE; |
| 24 | struct fw_args *fw_args; |
| 25 | |
| 26 | void 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 | |
| 51 | for ( addr = got_start + 8; addr < got_end; addr += 4 ) |
| 52 | { |
| 53 | *((volatile unsigned int *)(addr)) += offset; //add offset to correct all GOT |
| 54 | } |
| 55 | |
| 56 | fw_args = (struct fw_args *)(start_addr + 0x8); //get the fw args from memory |
| 57 | if ( fw_args->use_uart > 3 ) fw_args->use_uart = 0; |
| 58 | UART_BASE = 0xB0030000 + fw_args->use_uart * 0x1000; |
| 59 | |
| 60 | serial_puts("Start address is :"); |
| 61 | serial_put_hex(start_addr); |
| 62 | serial_puts("Address offset is:"); |
| 63 | serial_put_hex(offset); |
| 64 | serial_puts("GOT correct to :"); |
| 65 | serial_put_hex(got_start); |
| 66 | |
| 67 | usb_main(); |
| 68 | } |
| 69 | |