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

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

Remove unused base_addresses

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