| 1 | #include <reset_tty.h> |
|---|
| 2 | #include <io.h> |
|---|
| 3 | #include <defs.h> |
|---|
| 4 | |
|---|
| 5 | /////////////////////// |
|---|
| 6 | int reset_getc(char *c) |
|---|
| 7 | { |
|---|
| 8 | unsigned int* tty_address = (unsigned int*) TTY_PADDR_BASE; |
|---|
| 9 | if (ioread32(&tty_address[TTY_STATUS]) == 0) |
|---|
| 10 | return 0; |
|---|
| 11 | |
|---|
| 12 | *c = ioread32(&tty_address[TTY_READ]); |
|---|
| 13 | return 1; |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | ///////////////////////////// |
|---|
| 17 | void reset_putc(const char c) |
|---|
| 18 | { |
|---|
| 19 | unsigned int* tty_address = (unsigned int*) TTY_PADDR_BASE; |
|---|
| 20 | iowrite32(&tty_address[TTY_WRITE], (unsigned int)c); |
|---|
| 21 | |
|---|
| 22 | if (c == '\n') |
|---|
| 23 | { |
|---|
| 24 | iowrite32(&tty_address[TTY_WRITE], (unsigned int)'\r'); |
|---|
| 25 | } |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | /////////////////////////////////// |
|---|
| 29 | void reset_puts(const char *buffer) |
|---|
| 30 | { |
|---|
| 31 | unsigned int n; |
|---|
| 32 | |
|---|
| 33 | for ( n=0; n<100; n++) |
|---|
| 34 | { |
|---|
| 35 | if (buffer[n] == 0) break; |
|---|
| 36 | |
|---|
| 37 | reset_putc(buffer[n]); |
|---|
| 38 | } |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | ///////////////////////////////// |
|---|
| 42 | void reset_putx(unsigned int val) |
|---|
| 43 | { |
|---|
| 44 | static const char HexaTab[] = "0123456789ABCDEF"; |
|---|
| 45 | char buf[11]; |
|---|
| 46 | unsigned int c; |
|---|
| 47 | |
|---|
| 48 | buf[0] = '0'; |
|---|
| 49 | buf[1] = 'x'; |
|---|
| 50 | buf[10] = 0; |
|---|
| 51 | |
|---|
| 52 | for ( c = 0 ; c < 8 ; c++ ) |
|---|
| 53 | { |
|---|
| 54 | buf[9-c] = HexaTab[val&0xF]; |
|---|
| 55 | val = val >> 4; |
|---|
| 56 | } |
|---|
| 57 | reset_puts(buf); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | ///////////////////////////////// |
|---|
| 61 | void reset_putd(unsigned int val) |
|---|
| 62 | { |
|---|
| 63 | static const char DecTab[] = "0123456789"; |
|---|
| 64 | char buf[11]; |
|---|
| 65 | unsigned int i; |
|---|
| 66 | unsigned int first = 0; |
|---|
| 67 | |
|---|
| 68 | buf[10] = 0; |
|---|
| 69 | |
|---|
| 70 | for ( i = 0 ; i < 10 ; i++ ) |
|---|
| 71 | { |
|---|
| 72 | if ((val != 0) || (i == 0)) |
|---|
| 73 | { |
|---|
| 74 | buf[9-i] = DecTab[val % 10]; |
|---|
| 75 | first = 9-i; |
|---|
| 76 | } |
|---|
| 77 | else |
|---|
| 78 | { |
|---|
| 79 | break; |
|---|
| 80 | } |
|---|
| 81 | val /= 10; |
|---|
| 82 | } |
|---|
| 83 | reset_puts( &buf[first] ); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | ///////////////// |
|---|
| 87 | void reset_exit() |
|---|
| 88 | { |
|---|
| 89 | register int pid; |
|---|
| 90 | asm volatile( "mfc0 %0, $15, 1": "=r"(pid) ); |
|---|
| 91 | |
|---|
| 92 | reset_puts("\n!!! Exit Processor "); |
|---|
| 93 | reset_putx(pid); |
|---|
| 94 | reset_puts(" !!!\n"); |
|---|
| 95 | |
|---|
| 96 | while(1) asm volatile("nop"); // infinite loop... |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|