Root/xbboot/target-echokernel/echo-kernel.c

1//
2// Authors: Wolfgang Spraul <wolfgang@qi-hardware.com>
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 <inttypes.h>
11#include "../target-common/jz4740.h"
12#include "../target-common/serial.h"
13
14void c_main();
15
16void pre_main(void)
17{
18    volatile unsigned int start_addr, got_start, got_end, addr, offset;
19
20    /* get absolute start address */
21    __asm__ __volatile__(
22        "move %0, $20\n\t"
23        : "=r"(start_addr)
24        :
25        );
26
27    /* get related GOT address */
28    __asm__ __volatile__(
29        "la $4, _GLOBAL_OFFSET_TABLE_\n\t"
30        "move %0, $4\n\t"
31        "la $5, _got_end\n\t"
32        "move %1, $5\n\t"
33        : "=r"(got_start),"=r"(got_end)
34        :
35        );
36
37    /* calculate offset and correct GOT*/
38    offset = start_addr - 0x80000000;
39     got_start += offset;
40    got_end += offset;
41
42    for ( addr = got_start + 8; addr < got_end; addr += 4 )
43        *((volatile unsigned int *)(addr)) += offset; // add offset to correct all GOT
44
45// fw_args = (struct fw_args *)(start_addr + 0x8); //get the fw args from memory
46    UART_BASE = 0xB0030000;
47    serial_puts("Start address is:");
48    serial_put_hex(start_addr);
49    serial_puts("Address offset is:");
50    serial_put_hex(start_addr - 0x80000000);
51    serial_puts("GOT corrected to:");
52    serial_put_hex(got_start);
53    c_main();
54}
55
56void c_main()
57{
58    // start infinite 'echo' kernel
59    while (1) {
60        if (serial_tstc()) {
61            int c = serial_getc();
62            serial_putc(c);
63            if (c == '\r')
64                serial_putc('\n');
65        }
66    }
67}
68

Archive Download this file



interactive