[586] | 1 | #include <reset_tty.h> |
---|
| 2 | #include <io.h> |
---|
[292] | 3 | #include <defs.h> |
---|
| 4 | |
---|
[586] | 5 | /////////////////////// |
---|
| 6 | int reset_getc(char *c) |
---|
[292] | 7 | { |
---|
[586] | 8 | unsigned int* tty_address = (unsigned int*) TTY_PADDR_BASE; |
---|
[348] | 9 | if (ioread32(&tty_address[TTY_STATUS]) == 0) |
---|
| 10 | return 0; |
---|
[292] | 11 | |
---|
[348] | 12 | *c = ioread32(&tty_address[TTY_READ]); |
---|
| 13 | return 1; |
---|
[292] | 14 | } |
---|
| 15 | |
---|
[586] | 16 | ///////////////////////////// |
---|
| 17 | void reset_putc(const char c) |
---|
[292] | 18 | { |
---|
[586] | 19 | unsigned int* tty_address = (unsigned int*) TTY_PADDR_BASE; |
---|
[368] | 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 | } |
---|
[292] | 26 | } |
---|
| 27 | |
---|
[586] | 28 | /////////////////////////////////// |
---|
| 29 | void reset_puts(const char *buffer) |
---|
[292] | 30 | { |
---|
| 31 | unsigned int n; |
---|
| 32 | |
---|
| 33 | for ( n=0; n<100; n++) |
---|
| 34 | { |
---|
| 35 | if (buffer[n] == 0) break; |
---|
[368] | 36 | |
---|
[586] | 37 | reset_putc(buffer[n]); |
---|
[292] | 38 | } |
---|
| 39 | } |
---|
| 40 | |
---|
[586] | 41 | ///////////////////////////////// |
---|
| 42 | void reset_putx(unsigned int val) |
---|
[292] | 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 | } |
---|
[586] | 57 | reset_puts(buf); |
---|
[292] | 58 | } |
---|
| 59 | |
---|
[586] | 60 | ///////////////////////////////// |
---|
| 61 | void reset_putd(unsigned int val) |
---|
[292] | 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 | } |
---|
[586] | 83 | reset_puts( &buf[first] ); |
---|
[292] | 84 | } |
---|
| 85 | |
---|
[586] | 86 | ///////////////// |
---|
| 87 | void reset_exit() |
---|
[292] | 88 | { |
---|
| 89 | register int pid; |
---|
| 90 | asm volatile( "mfc0 %0, $15, 1": "=r"(pid) ); |
---|
| 91 | |
---|
[586] | 92 | reset_puts("\n!!! Exit Processor "); |
---|
| 93 | reset_putx(pid); |
---|
| 94 | reset_puts(" !!!\n"); |
---|
[292] | 95 | |
---|
| 96 | while(1) asm volatile("nop"); // infinite loop... |
---|
| 97 | } |
---|
| 98 | |
---|
[586] | 99 | |
---|
| 100 | |
---|