1 #include <syscall.h> 2 #include <stdio.h> 3 #include <errno.h> 4 #include <sys/stat.h> 5 6 extern int _hardware; 7 /* _cpu_config==0 => Abel 8 * _cpu_config==1 => Zeta 9 * _cpu_config==2 => Phi 10 */ 11 extern int _cpu_config; 12 static volatile int *UART; 13 static volatile int *TIMER; 14 volatile int *MHZ; 15 16 17 18 /* 19 * Wait indefinitely for input byte 20 */ 21 22 inbyte()23int __attribute__ ((weak)) inbyte() 24 { 25 int val; 26 for (;;) 27 { 28 val=UART[1]; 29 if ((val&0x100)!=0) 30 { 31 return val&0xff; 32 } 33 } 34 } 35 36 37 38 /* 39 * Output one character to the serial port 40 * 41 * 42 */ outbyte(int c)43void __attribute__ ((weak)) outbyte(int c) 44 { 45 /* Wait for space in FIFO */ 46 while ((UART[0]&0x100)==0); 47 UART[0]=c; 48 } 49 50 static const int mhz=64; 51 _initIO(void)52void __attribute__ ((weak)) _initIO(void) 53 { 54 if (_hardware) 55 { 56 if (_cpu_config==2) 57 { 58 /* Phi board addresses */ 59 UART=(volatile int *)0x080a000c; 60 TIMER=(volatile int *)0x080a0014; 61 MHZ=(volatile int *)&mhz; 62 } else 63 { 64 /* Abel board */ 65 UART=(volatile int *)0xc000; 66 TIMER=(volatile int *)0x9000; 67 MHZ=(volatile int *)0x8800; 68 } 69 } else 70 { 71 UART=(volatile int *)0x80000024; 72 TIMER=(volatile int *)0x80000100; 73 MHZ=(volatile int *)0x80000200; 74 } 75 } 76 77 78 _readCycles()79long long __attribute__ ((weak)) _readCycles() 80 { 81 long long clock; 82 unsigned int i; 83 84 TIMER[0]=0x2; /* sample timer */ 85 clock=0; 86 for (i=0; i<2; i++) 87 { 88 clock|=((long long )(TIMER[i]))<<(i*32); 89 } 90 return clock; 91 } 92