1 /* 2 * Ben NanoNote stage 2 payload test. 3 * 4 * Copyright (C) Wolfgang Spraul <wolfgang@sharism.cc> 5 * Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk> 6 * 7 * This program is free software; you can redistribute it and/or modify it under 8 * the terms of the GNU General Public License as published by the Free Software 9 * Foundation; either version 3 of the License, or (at your option) any later 10 * version. 11 * 12 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 * details. 16 * 17 * You should have received a copy of the GNU General Public License along with 18 * this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #include "board-nanonote.h" 22 #include "lcd.h" 23 24 void c_main(void) 25 { 26 /* Relocate object locations. */ 27 28 volatile unsigned int start_addr, got_start, got_end, addr, offset; 29 30 /* get absolute start address */ 31 __asm__ __volatile__( 32 "move %0, $20\n\t" 33 : "=r"(start_addr) 34 : 35 ); 36 37 /* get related GOT address */ 38 __asm__ __volatile__( 39 "la $4, _GLOBAL_OFFSET_TABLE_\n\t" 40 "move %0, $4\n\t" 41 "la $5, _got_end\n\t" 42 "move %1, $5\n\t" 43 : "=r"(got_start),"=r"(got_end) 44 : 45 ); 46 47 /* calculate offset and correct GOT*/ 48 offset = start_addr - 0x80000000; 49 got_start += offset; 50 got_end += offset; 51 52 for ( addr = got_start + 8; addr < got_end; addr += 4 ) 53 *((volatile unsigned int *)(addr)) += offset; // add offset to correct all GOT 54 55 /* The actual work. */ 56 57 gpio_init2(); 58 cpm_init(); 59 rtc_init(); 60 timer_init(); 61 lcd_init(); 62 }