NanoPayload

Annotated stage2/stage2.c

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