|
|
1.1 root 1: /*
2:
3: Copyright 1990,1991,1992 Eric R. Smith. All rights reserved.
4:
5: */
6:
7:
8:
9: /*
10:
11: * XBIOS replacement routines
12:
13: */
14:
15:
16:
17: #include "mint.h"
18:
19:
20:
21: extern int tosvers; /* from main.c */
22:
23:
24:
25: #define XBIOS_MAX 0x80
26:
27:
28:
29: Func xbios_tab[XBIOS_MAX]; /* initially all zeros */
30:
31: short xbios_max = XBIOS_MAX;
32:
33:
34:
35: /* NOTE: has_bconmap is initialized in main.c */
36:
37:
38:
39: int has_bconmap; /* flag: set if running under a version
40:
41: * of TOS which supports Bconmap
42:
43: */
44:
45:
46:
47: /*
48:
49: * Supexec() presents a lot of problems for us: for example, the user
50:
51: * may be calling the kernel, or may be changing interrupt vectors
52:
53: * unexpectedly. So we play some dirty tricks here: the function
54:
55: * call is treated like a signal handler, and we take advantage
56:
57: * of the fact that no context switches will take place while
58:
59: * in supervisor mode. ASSUMPTION: the user will not choose to
60:
61: * switch back to user mode, or if s/he does it will be as part
62:
63: * of a longjmp().
64:
65: *
66:
67: * BUG: if the user function switches to user mode, then back to
68:
69: * supervisor mode and returns, then the returned value may be
70:
71: * inaccurate (this happens if two programs make Supexec calls
72:
73: * at the same time).
74:
75: */
76:
77:
78:
79: static long (*usrcall) P_((long,long,long,long,long));
80:
81: static long usrret;
82:
83: static long usrarg1, usrarg2, usrarg3, usrarg4, usrarg5;
84:
85:
86:
87: static void do_usrcall P_((void));
88:
89:
90:
91: static void
92:
93: do_usrcall()
94:
95: {
96:
97: usrret = (*usrcall)(usrarg1, usrarg2, usrarg3, usrarg4, usrarg5);
98:
99: }
100:
101:
102:
103: long
104:
105: supexec(funcptr, arg1, arg2, arg3, arg4, arg5)
106:
107: Func funcptr;
108:
109: long arg1, arg2, arg3, arg4, arg5;
110:
111: {
112:
113: short savesr;
114:
115: CONTEXT *syscall = &curproc->ctxt[SYSCALL];
116:
117:
118:
119: /* set things up so that "signal 0" will be handled by calling the user's
120:
121: * function.
122:
123: */
124:
125:
126:
127: usrcall = funcptr;
128:
129: usrarg1 = arg1;
130:
131: usrarg2 = arg2;
132:
133: usrarg3 = arg3;
134:
135: usrarg4 = arg4;
136:
137: usrarg5 = arg5;
138:
139: curproc->sighandle[0] = (long)do_usrcall;
140:
141: savesr = syscall->sr; /* save old super/user mode flag */
142:
143: syscall->sr |= 0x2000; /* set supervisor mode */
144:
145: handle_sig(0); /* actually call out to the user function */
146:
147: syscall->sr = savesr;
148:
149:
150:
151: /* do_usrcall saves the user's return value in usrret */
152:
153: return usrret;
154:
155: }
156:
157:
158:
159:
160:
161: /*
162:
163: * midiws: we have to replace this, because it's possible that the process'
164:
165: * view of what the MIDI port is has been changed by Fforce or Fmidipipe
166:
167: */
168:
169:
170:
171: long
172:
173: midiws(cnt, buf)
174:
175: int cnt;
176:
177: const char *buf;
178:
179: {
180:
181: FILEPTR *f;
182:
183: long towrite = cnt+1;
184:
185:
186:
187: f = curproc->handle[-5]; /* MIDI output handle */
188:
189: if (!f) return EIHNDL;
190:
191:
192:
193: if (is_terminal(f)) {
194:
195: while (cnt >= 0) {
196:
197: tty_putchar(f, (long)*buf, RAW);
198:
199: buf++; cnt--;
200:
201: }
202:
203: return towrite;
204:
205: }
206:
207: return (*f->dev->write)(f, buf, towrite);
208:
209: }
210:
211:
212:
213: /*
214:
215: * Modem control things: these are replaced because we handle
216:
217: * Bconmap ourselves
218:
219: */
220:
221:
222:
223: /* mapin: utility routine, does a Bconmap and keeps track
224:
225: * so we call the kernel only when necessary; call this
226:
227: * only if has_bconmap is "true".
228:
229: * Returns: 0 on failure, 1 on success.
230:
231: */
232:
233: int curbconmap;
234:
235:
236:
237: int
238:
239: mapin(dev)
240:
241: int dev;
242:
243: {
244:
245: int r;
246:
247:
248:
249: if (dev == curbconmap)
250:
251: return 1;
252:
253: r = Bconmap(dev);
254:
255: if (r) {
256:
257: curbconmap = dev;
258:
259: return 1;
260:
261: }
262:
263: return 0;
264:
265: }
266:
267:
268:
269: long
270:
271: uiorec(dev)
272:
273: int dev;
274:
275: {
276:
277: TRACE("Iorec(%d)", dev);
278:
279: if (dev == 0 && has_bconmap)
280:
281: mapin(curproc->bconmap);
282:
283: return (long)Iorec(dev);
284:
285: }
286:
287:
288:
289: long
290:
291: rsconf(baud, flow, uc, rs, ts, sc)
292:
293: int baud, flow, uc, rs, ts, sc;
294:
295: {
296:
297: TRACE("Rsconf(%d,%d,%d,%d,%d,%d)", baud, flow,
298:
299: uc, rs, ts, sc);
300:
301:
302:
303: if (has_bconmap)
304:
305: mapin(curproc->bconmap);
306:
307: return Rsconf(baud, flow, uc, rs, ts, sc);
308:
309: }
310:
311:
312:
313: long
314:
315: bconmap(dev)
316:
317: int dev;
318:
319: {
320:
321: int old = curproc->bconmap;
322:
323:
324:
325: TRACE("Bconmap(%d)", dev);
326:
327:
328:
329: if (has_bconmap) {
330:
331: if (dev == -1) return old;
332:
333: if (dev == -2) return Bconmap(-2);
334:
335: if (mapin(dev) == 0) {
336:
337: DEBUG("Bconmap: mapin failed");
338:
339: return 0;
340:
341: }
342:
343: if (set_auxhandle(curproc, dev) == 0) {
344:
345: DEBUG("Bconmap: Couldn't change AUX:");
346:
347: return 0;
348:
349: }
350:
351: curproc->bconmap = dev;
352:
353: return old;
354:
355: }
356:
357: return EINVFN; /* no Bconmap available */
358:
359: }
360:
361:
362:
363: void
364:
365: init_xbios()
366:
367: {
368:
369: curbconmap = (has_bconmap) ? Bconmap(-1) : 1;
370:
371:
372:
373: xbios_tab[0x0c] = midiws;
374:
375: xbios_tab[0x0e] = uiorec;
376:
377: xbios_tab[0x0f] = rsconf;
378:
379: xbios_tab[0x26] = supexec;
380:
381: xbios_tab[0x2c] = bconmap;
382:
383: }
384:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.