| 1 | // |
| 2 | // Authors: Wolfgang Spraul <wolfgang@sharism.cc> |
| 3 | // |
| 4 | // This program is free software; you can redistribute it and/or |
| 5 | // modify it under the terms of the GNU General Public License |
| 6 | // as published by the Free Software Foundation; either version |
| 7 | // 3 of the License, or (at your option) any later version. |
| 8 | // |
| 9 | |
| 10 | #include "../target-common/serial.h" |
| 11 | #include "../target-common/common.h" |
| 12 | |
| 13 | void pre_main(void) |
| 14 | { |
| 15 | volatile unsigned int start_addr, got_start, got_end, addr, offset; |
| 16 | |
| 17 | /* get absolute start address */ |
| 18 | __asm__ __volatile__( |
| 19 | "move %0, $20\n\t" |
| 20 | : "=r"(start_addr) |
| 21 | : |
| 22 | ); |
| 23 | |
| 24 | /* get related GOT address */ |
| 25 | __asm__ __volatile__( |
| 26 | "la $4, _GLOBAL_OFFSET_TABLE_\n\t" |
| 27 | "move %0, $4\n\t" |
| 28 | "la $5, _got_end\n\t" |
| 29 | "move %1, $5\n\t" |
| 30 | : "=r"(got_start),"=r"(got_end) |
| 31 | : |
| 32 | ); |
| 33 | |
| 34 | /* calculate offset and correct GOT*/ |
| 35 | offset = start_addr - 0x80000000; |
| 36 | got_start += offset; |
| 37 | got_end += offset; |
| 38 | |
| 39 | for ( addr = got_start + 8; addr < got_end; addr += 4 ) |
| 40 | *((volatile unsigned int *)(addr)) += offset; // add offset to correct all GOT |
| 41 | |
| 42 | // fw_args = (struct fw_args *)(start_addr + 0x8); //get the fw args from memory |
| 43 | UART_BASE = 0xB0030000 + 0x1000; |
| 44 | serial_puts("Start address is:"); |
| 45 | serial_put_hex(start_addr); |
| 46 | serial_puts("Address offset is:"); |
| 47 | serial_put_hex(start_addr - 0x80000000); |
| 48 | serial_puts("GOT corrected to:"); |
| 49 | serial_put_hex(got_start); |
| 50 | c_main(); |
| 51 | } |
| 52 | |
| 53 | void c_main() |
| 54 | { |
| 55 | // start infinite 'echo' kernel |
| 56 | while (1) { |
| 57 | if (serial_tstc()) { |
| 58 | int c = serial_getc(); |
| 59 | serial_putc(c); |
| 60 | if (c == '\r') |
| 61 | serial_putc('\n'); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |