source: trunk/softs/tsar_boot/boot_tty.c @ 276

Last change on this file since 276 was 276, checked in by bouyer, 11 years ago

A boot loader to be stored in ROM of a TSAR platform.
Based on Cesar FUGUET's work.
Platform-specific files are in a subdirectory, e.g. platform_fpga_de2-115,
so the same code can be targetted to different platforms.
The platform is selected with the PLATFORM_DIR environnement variable.
The supported variant are soclib and fpga, the later being the default
and the former selected by defining the SOCLIB environnement variable.
The boot loader embeds a binary device tree describing the platform,
to be used by the loaded software.

File size: 2.0 KB
Line 
1#include <boot_tty.h>
2#include <defs.h>
3
4#define in_reset         __attribute__((section (".reset")))
5#define in_reset_data     __attribute__((section (".reset_data")))
6
7struct base_addresses;
8extern struct base_addresses seg_tty_base;
9
10in_reset int boot_getc(int *c)
11{
12        unsigned int* tty_address = (unsigned int*) TTY_BASE;
13        if (ioread32(tty_address[TTY_STATUS]) == 0)
14                return 0;
15        *c = ioread32(&tty_address[TTY_READ]);
16        return 1;
17}
18
19in_reset void boot_putc(const char c)
20{
21        unsigned int* tty_address = (unsigned int*) TTY_BASE;
22        iowrite32(&tty_address[TTY_WRITE], (unsigned int)c);
23}
24
25in_reset void boot_puts(const char *buffer) 
26{
27    unsigned int n;
28
29    for ( n=0; n<100; n++)
30    {
31        if (buffer[n] == 0) break;
32        boot_putc(buffer[n]);
33    }
34} 
35
36in_reset void boot_putx(unsigned int val)
37{
38    in_reset_data static const char HexaTab[] = "0123456789ABCDEF";
39    char                buf[11];
40    unsigned int        c;
41
42    buf[0]  = '0';
43    buf[1]  = 'x';
44    buf[10] = 0;
45
46    for ( c = 0 ; c < 8 ; c++ )
47    { 
48        buf[9-c] = HexaTab[val&0xF];
49        val = val >> 4;
50    }
51    boot_puts(buf);
52}
53
54in_reset void boot_putd(unsigned int val)
55{
56    in_reset_data static const char DecTab[]  = "0123456789";
57    char                buf[11];
58    unsigned int        i;
59    unsigned int        first = 0;
60
61    buf[10] = 0;
62
63    for ( i = 0 ; i < 10 ; i++ )
64    {
65        if ((val != 0) || (i == 0))
66        {
67            buf[9-i] = DecTab[val % 10];
68            first    = 9-i;
69        }
70        else
71        {
72            break;
73        }
74        val /= 10;
75    }
76    boot_puts( &buf[first] );
77}
78
79in_reset void boot_exit()
80{
81    in_reset_data static const char exit_str[] = "\n\r!!! Exit Processor ";
82    in_reset_data static const char eol_str[] = " !!!\n\r";
83
84    register int pid;
85    asm volatile( "mfc0 %0, $15, 1": "=r"(pid) );
86
87    boot_puts(exit_str);
88    boot_putx(pid);
89    boot_puts(eol_str);
90
91    while(1) asm volatile("nop");   // infinite loop...
92}
93
Note: See TracBrowser for help on using the repository browser.