source: trunk/softs/tsar_boot/src/boot_tty.c @ 348

Last change on this file since 348 was 348, checked in by cfuguet, 11 years ago

Adding the boot_putc and the boot_getc in the functions
pointer table defined at the beginning of the reset code

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