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