Update the changelog
[opencv] / apps / Hawk / CVEiCL / EiC / src / ppc403 / io.c
1 /* Collection of various routines needed by the GCC when no OS is present \r
2 \r
3   Works for the PowerPC 403 series currently\r
4 \r
5   Released under the GNU Public License 4/98 with no guarantee or statement\r
6   for fitness of purpose for any application\r
7 \r
8 Larry Battraw\r
9 (battraw@cicddal.com)\r
10 */\r
11 \r
12 #include <stdio.h>\r
13 #include <stdlib.h>\r
14 #include <sys/timeb.h>\r
15 #include <sys/times.h>\r
16 #include <sys/time.h>\r
17 #include <unistd.h>\r
18 \r
19 \r
20 void outbyte(int byte);\r
21 int inbyte(void);\r
22 \r
23 \r
24 #define spbase 0x40000000\r
25 #define _spls   0\r
26 #define _sphs   2\r
27 #define _brdh   4\r
28 #define _brdl   5\r
29 #define _spctl  6\r
30 #define _sprc   7\r
31 #define _sptc   8\r
32 #define _sprb   9\r
33 #define _sptb   9\r
34 \r
35 \r
36 #define SPLS (*(volatile unsigned char*) (spbase+_spls))\r
37 #define SPHS (*(volatile unsigned char*) (spbase+_sphs))\r
38 #define SPBRDH (*(volatile unsigned char*) (spbase+_spbrdh))\r
39 #define SPBRDL (*(volatile unsigned char*) (spbase+_spbrdl))\r
40 #define SPCTL (*(volatile unsigned char*) (spbase+_spctl))\r
41 #define SPRC (*(volatile unsigned char*) (spbase+_sprc))\r
42 #define SPTC (*(volatile unsigned char*) (spbase+_sptc))\r
43 #define SPRB (*(volatile unsigned char*) (spbase+_sprb))\r
44 #define SPTB (*(volatile unsigned char*) (spbase+_sptb))\r
45 #define SPRB (*(volatile unsigned char*) (spbase+_sprb))\r
46 \r
47 \r
48 #define sgr     0x03b9\r
49 #define iccr    0x3fb\r
50 #define br0     0x80\r
51 #define br1     0x81\r
52 #define br2     0x82\r
53 #define iocr    0xa0\r
54 #define lr      0x008\r
55 \r
56  void _start(void)\r
57 {\r
58         asm("\r
59         addis 1,0,0x7fe8\r
60         subi  1,1,0x1000        \r
61         mr    2,1\r
62         addi  3,0,0x1000\r
63         mtmsr 3\r
64         b main\r
65         ");\r
66\r
67 \r
68 \r
69 int inbyte(void)\r
70 {\r
71         while((SPLS&128)==0 && (SPLS&0x78)==0) \r
72         {\r
73           if((SPLS&0x78)!=0) SPLS=0x78;\r
74           if((SPHS&0xc0)!=0) SPHS=0xc0;\r
75         }\r
76           \r
77         return(SPRB);\r
78 }\r
79 \r
80 void outbyte(int byte)\r
81 {\r
82         while((SPLS&4)!=4) ;\r
83         SPTB=byte;\r
84 }\r
85 \r
86 void byteout(unsigned char val, unsigned long addr)\r
87 {\r
88         asm("stb  3,0(4)");\r
89 }\r
90 int bytein(unsigned long addr)\r
91 {\r
92         asm("lbz 3,0(3)");\r
93 }\r
94 \r
95 \r
96 /* returns -1 if character waiting, 0 if not */\r
97 int getchq(void)\r
98 {\r
99         if((SPLS&128)==0) return(0);\r
100         else return(-1);\r
101 }\r
102 \r
103 \r
104 int __srget(FILE *stream)\r
105 {\r
106 return(inbyte());\r
107 }\r
108 \r
109 int rget(FILE *stream)\r
110 {\r
111 return(inbyte());\r
112 }\r
113 \r
114 \r
115 int link(const char *oldpath, const char *newpath) { return(-1); }\r
116 \r
117 int *__errno(void)\r
118 {\r
119 static int _errorno_;\r
120 return(&_errorno_);\r
121 }\r
122 \r
123 \r
124 void prs(char *str)\r
125 {\r
126 int i;\r
127 for(i=0; i<99999; i++)\r
128  {\r
129         if(str[i]==0) break;\r
130         outbyte(str[i]);\r
131         if(str[i]=='\n') outbyte('\r');\r
132         if(str[i]=='\r') outbyte('\n');\r
133  }\r
134 }\r
135 \r
136 \r
137 void abort(void)\r
138 {\r
139 prs("<abort>-- exit to OS\n");\r
140 asm("   lis     3,0x7ff0\r
141         mtlr    3\r
142         blr");\r
143         while(1) ;\r
144 }\r
145 \r
146 \r
147 \r
148 void _exit(int _status ) \r
149 {\r
150 prs("<normal exit>-- returning to OS\n");\r
151 asm("   lis     3,0x7ff0\r
152         mtlr    3\r
153         blr");\r
154         while(1);\r
155 }\r
156 \r
157 int gettimeofday(struct timeval *tv, struct timezone *tz)\r
158 {\r
159 return(0);\r
160 }\r
161 clock_t times(struct tms *buf)\r
162 {\r
163 return(1);\r
164 }\r
165 int ftime(struct timeb *tp)\r
166 {\r
167 return(0);\r
168 }\r
169 \r
170 \r
171 \r