Tools for working with Cidco Mailstations

Add basic Linux support

+51 -56
+1 -13
util/recvdump.c
··· 16 16 #include <unistd.h> 17 17 #include <sys/types.h> 18 18 #include <sys/limits.h> 19 - #include <machine/sysarch.h> 20 19 21 20 #include "tribble.h" 22 21 ··· 83 82 } else 84 83 usage(); 85 84 86 - if (geteuid() != 0) 87 - errx(1, "must be run as root"); 88 - 89 - #ifdef __OpenBSD__ 90 - #ifdef __amd64__ 91 - if (amd64_iopl(1) != 0) 92 - errx(1, "amd64_iopl failed (is machdep.allowaperture=1?)"); 93 - #elif defined(__i386__) 94 - if (i386_iopl(1) != 0) 95 - errx(1, "i386_iopl failed (is machdep.allowaperture=1?)"); 96 - #endif 97 - #endif 85 + checkio(); 98 86 99 87 pFile = fopen(fn, "wb"); 100 88 if (!pFile) {
+1 -14
util/sendload.c
··· 15 15 #include <unistd.h> 16 16 #include <sys/types.h> 17 17 #include <sys/stat.h> 18 - #include <machine/sysarch.h> 19 - #include <machine/pio.h> 20 18 21 19 #include "tribble.h" 22 20 ··· 60 58 if (argc != 1) 61 59 usage(); 62 60 63 - if (geteuid() != 0) 64 - errx(1, "must be run as root"); 65 - 66 - #ifdef __OpenBSD__ 67 - #ifdef __amd64__ 68 - if (amd64_iopl(1) != 0) 69 - errx(1, "amd64_iopl failed (is machdep.allowaperture=1?)"); 70 - #elif defined(__i386__) 71 - if (i386_iopl(1) != 0) 72 - errx(1, "i386_iopl failed (is machdep.allowaperture=1?)"); 73 - #endif 74 - #endif 61 + checkio(); 75 62 76 63 fn = argv[0]; 77 64 pFile = fopen(fn, "rb");
+47 -15
util/tribble.c
··· 1 1 #include <stdio.h> 2 + #include <err.h> 3 + #include <unistd.h> 2 4 #include <sys/types.h> 5 + 6 + #define INB inb 7 + 8 + #ifdef __OpenBSD__ 9 + #include <machine/sysarch.h> 3 10 #include <machine/pio.h> 11 + #define OUTB outb 12 + 13 + #elif defined(__linux__) 14 + #include <sys/io.h> 15 + #define OUTB(port, byte) outb(byte, port) 16 + #endif 4 17 5 18 #include "tribble.h" 6 19 ··· 8 21 9 22 int tribble_debug = 0; 10 23 24 + void 25 + checkio(void) 26 + { 27 + if (geteuid() != 0) 28 + errx(1, "must be run as root"); 29 + 30 + #ifdef __OpenBSD__ 31 + #ifdef __amd64__ 32 + if (amd64_iopl(1) != 0) 33 + errx(1, "amd64_iopl failed (is machdep.allowaperture=1?)"); 34 + #elif defined(__i386__) 35 + if (i386_iopl(1) != 0) 36 + errx(1, "i386_iopl failed (is machdep.allowaperture=1?)"); 37 + #endif 38 + #elif defined(__linux__) 39 + iopl(3); 40 + #endif 41 + } 42 + 11 43 unsigned int 12 44 havetribble(void) 13 45 { 14 46 int tries; 15 47 16 48 /* drop busy */ 17 - outb(tribble_port + DATA, 0); 49 + OUTB(tribble_port + DATA, 0); 18 50 19 51 /* wait for (inverted) strobe */ 20 52 for (tries = 0; tries < 1024; tries++) ··· 26 58 return 1; 27 59 28 60 /* re-raise busy */ 29 - outb(tribble_port + DATA, bsyout); 61 + OUTB(tribble_port + DATA, bsyout); 30 62 31 63 return 0; 32 64 } ··· 38 70 unsigned int tries; 39 71 40 72 /* drop busy */ 41 - outb(tribble_port + DATA, 0); 73 + OUTB(tribble_port + DATA, 0); 42 74 43 75 /* wait for (inverted) strobe */ 44 76 tries = 0; 45 - while ((inb(tribble_port + STATUS) & stbin) != 0) { 77 + while ((INB(tribble_port + STATUS) & stbin) != 0) { 46 78 if (++tries >= 500000) { 47 79 /* raise busy/ack */ 48 - outb(DATA,bsyout); 80 + OUTB(tribble_port + DATA, bsyout); 49 81 return -1; 50 82 } 51 83 } 52 84 53 85 /* grab tribble */ 54 - b = (inb(tribble_port + STATUS) >> 3) & tribmask; 86 + b = (INB(tribble_port + STATUS) >> 3) & tribmask; 55 87 56 88 /* raise busy/ack */ 57 - outb(tribble_port + DATA, bsyout); 89 + OUTB(tribble_port + DATA, bsyout); 58 90 59 91 /* wait for (inverted) UNstrobe */ 60 92 tries = 0; 61 - while ((inb(tribble_port + STATUS) & stbin) == 0) { 93 + while ((INB(tribble_port + STATUS) & stbin) == 0) { 62 94 if (++tries >= 500000) 63 95 return -1; 64 96 } ··· 93 125 int ret = 0; 94 126 95 127 /* raise busy */ 96 - outb(tribble_port + DATA, bsyout); 128 + OUTB(tribble_port + DATA, bsyout); 97 129 98 130 /* wait for mailstation to drop busy */ 99 131 tries = 0; 100 - while ((inb(tribble_port + STATUS) & bsyin) != 0) { 132 + while ((INB(tribble_port + STATUS) & bsyin) != 0) { 101 133 if (++tries >= 500000) { 102 134 ret = 1; 103 135 goto sendtribble_out; ··· 105 137 } 106 138 107 139 /* send tribble */ 108 - outb(tribble_port + DATA, b & tribmask); 140 + OUTB(tribble_port + DATA, b & tribmask); 109 141 110 142 /* strobe */ 111 - outb(tribble_port + DATA, (b & tribmask) | stbout); 143 + OUTB(tribble_port + DATA, (b & tribmask) | stbout); 112 144 113 145 /* wait for ack */ 114 146 tries = 0; 115 - while ((inb(tribble_port + STATUS) & bsyin) == 0) { 147 + while ((INB(tribble_port + STATUS) & bsyin) == 0) { 116 148 if (++tries >= 500000) { 117 149 ret = 1; 118 150 goto sendtribble_out; ··· 120 152 } 121 153 122 154 /* unstrobe */ 123 - outb(tribble_port + DATA, 0); 155 + OUTB(tribble_port + DATA, 0); 124 156 125 157 sendtribble_out: 126 158 /* raise busy/ack */ 127 - outb(tribble_port + DATA, bsyout); 159 + OUTB(tribble_port + DATA, bsyout); 128 160 129 161 return ret; 130 162 }
+1
util/tribble.h
··· 12 12 #define tribmask 0x07 13 13 #define dibmask 0x03 14 14 15 + void checkio(void); 15 16 unsigned int havetribble(void); 16 17 int recvtribble(void); 17 18 int recvbyte(void);
+1 -14
util/tribble_getty.c
··· 19 19 #include <util.h> 20 20 #include <sys/types.h> 21 21 #include <sys/stat.h> 22 - #include <machine/sysarch.h> 23 - #include <machine/pio.h> 24 22 25 23 #include "tribble.h" 26 24 ··· 61 59 if (argc != 0) 62 60 usage(); 63 61 64 - if (geteuid() != 0) 65 - errx(1, "must be run as root"); 66 - 67 - #ifdef __OpenBSD__ 68 - #ifdef __amd64__ 69 - if (amd64_iopl(1) != 0) 70 - errx(1, "amd64_iopl failed (is machdep.allowaperture=1?)"); 71 - #elif defined(__i386__) 72 - if (i386_iopl(1) != 0) 73 - errx(1, "i386_iopl failed (is machdep.allowaperture=1?)"); 74 - #endif 75 - #endif 62 + checkio(); 76 63 77 64 printf("[port 0x%x]\n", tribble_port); 78 65