source: vendor/emx/current/src/os2/doscall.c

Last change on this file was 18, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 8.2 KB
Line 
1/* doscall.c -- DOS-compatible system calls
2 Copyright (c) 1994-1995 by Eberhard Mattes
3
4This file is part of emx.
5
6emx is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11emx is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with emx; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA.
20
21As special exception, emx.dll can be distributed without source code
22unless it has been changed. If you modify emx.dll, this exception
23no longer applies and you must remove this paragraph from all source
24files for emx.dll. */
25
26
27#define INCL_DOSMISC
28#define INCL_KBD
29#include <os2emx.h>
30#include <sys/errno.h>
31#include "emxdll.h"
32#include "clib.h"
33
34static void bad_func (syscall_frame *f);
35static void do_get_date (syscall_frame *f);
36static void do_get_time (syscall_frame *f);
37static void do_get_version (syscall_frame *f);
38
39
40void dos_call (syscall_frame *f)
41{
42 int err_no, i;
43
44 if (debug_flags & DEBUG_SYSCALL)
45 oprintf ("%u: syscall %.2x\r\n", my_pid, (unsigned)f->b.ah);
46
47 f->e.eflags &= ~(FLAG_C | FLAG_Z);
48
49 switch (f->b.ah)
50 {
51 case 0x01:
52
53 /* Read keyboard with echo. */
54
55 kbd_input (&f->b.al, FALSE, TRUE, TRUE, FALSE);
56 break;
57
58 case 0x02:
59
60 /* Display character. */
61
62 conout (f->b.dl);
63 break;
64
65 case 0x06:
66
67 /* Direct console I/O. */
68
69 if (f->b.dl != 0xff)
70 conout (f->b.dl);
71 else
72 {
73 if (!kbd_input (&f->b.al, TRUE, FALSE, FALSE, FALSE))
74 f->e.eflags |= FLAG_Z;
75 }
76 break;
77
78 case 0x07:
79
80 /* Direct console input. */
81
82 kbd_input (&f->b.al, TRUE, FALSE, TRUE, FALSE);
83 break;
84
85 case 0x08:
86
87 /* Read keyboard. */
88
89 kbd_input (&f->b.al, FALSE, FALSE, TRUE, FALSE);
90 break;
91
92 case 0x0a:
93
94 /* Buffered keyboard input. */
95
96 conin_string ((char *)f->e.edx);
97 break;
98
99 case 0x0b:
100
101 /* Check keyboard status. */
102
103 f->b.al = kbd_input (NULL, FALSE, FALSE, FALSE, TRUE);
104 break;
105
106 case 0x0d:
107
108 /* Reset disk. */
109
110 break;
111
112 case 0x0e:
113
114 /* Select disk. */
115
116 do_selectdisk (f->b.dl);
117 f->b.al = 0;
118 break;
119
120 case 0x19:
121
122 /* Get current disk. */
123
124 f->b.al = do_getdrive ();
125 break;
126
127 case 0x2a:
128
129 /* Get date. */
130
131 do_get_date (f);
132 break;
133
134 case 0x2c:
135
136 /* Get time. */
137
138 do_get_time (f);
139 break;
140
141 case 0x30:
142
143 /* Get version number. */
144
145 do_get_version (f);
146 break;
147
148 case 0x37:
149
150 /* Get or set the switch character. */
151
152 f->b.al = 0xff; /* No switch character defined. */
153 break;
154
155 case 0x39:
156
157 /* Create directory. */
158
159 f->e.eax = do_mkdir ((const char *)f->e.edx);
160 if (f->e.eax != 0)
161 f->e.eflags |= FLAG_C;
162 break;
163
164 case 0x3a:
165
166 /* Remove directory. */
167
168 f->e.eax = do_rmdir ((const char *)f->e.edx);
169 if (f->e.eax != 0)
170 f->e.eflags |= FLAG_C;
171 break;
172
173 case 0x3b:
174
175 /* Change current directory. */
176
177 f->e.eax = do_chdir ((const char *)f->e.edx);
178 if (f->e.eax != 0)
179 f->e.eflags |= FLAG_C;
180 break;
181
182 case 0x3c:
183
184 /* Create handle. */
185
186 i = old_creat ((const char *)f->e.edx, f->e.ecx, &err_no);
187 if (i != -1)
188 f->e.eax = i;
189 else
190 {
191 f->e.eax = err_no;
192 f->e.eflags |= FLAG_C;
193 }
194 break;
195
196 case 0x3d:
197
198 /* Open handle. */
199
200 i = old_open ((const char *)f->e.edx, f->b.al, &err_no);
201 if (i != -1)
202 f->e.eax = i;
203 else
204 {
205 f->e.eax = err_no;
206 f->e.eflags |= FLAG_C;
207 }
208 break;
209
210 case 0x3e:
211
212 /* Close handle. */
213
214 f->e.eax = do_close (f->e.ebx);
215 if (f->e.eax != 0)
216 f->e.eflags |= FLAG_C;
217 break;
218
219 case 0x3f:
220
221 /* Read handle. */
222
223 f->e.eax = do_read (f->e.ebx, (void *)f->e.edx, f->e.ecx, &err_no);
224 if (err_no != 0)
225 {
226 f->e.eax = err_no;
227 f->e.eflags |= FLAG_C;
228 }
229 break;
230
231 case 0x40:
232
233 /* Write handle. */
234
235 f->e.eax = do_write (f->e.ebx, (void *)f->e.edx, f->e.ecx, &err_no);
236 if (err_no != 0)
237 {
238 f->e.eax = err_no;
239 f->e.eflags |= FLAG_C;
240 }
241 break;
242
243 case 0x41:
244
245 /* Delete directory entry. */
246
247 f->e.eax = do_delete ((const char *)f->e.edx);
248 if (f->e.eax != 0)
249 f->e.eflags |= FLAG_C;
250 break;
251
252 case 0x42:
253
254 /* Move file pointer. */
255
256 f->e.eax = do_seek (f->e.ebx, f->b.al, f->e.edx, &err_no);
257 if (err_no != 0)
258 {
259 f->e.eax = err_no;
260 f->e.eflags |= FLAG_C;
261 }
262 break;
263
264 case 0x43:
265
266 /* Get/set file attributes. */
267
268 if (f->b.al == 0)
269 {
270 f->e.ecx = get_attr ((const char *)f->e.edx, &err_no);
271 f->e.eax = err_no;
272 if (err_no != 0)
273 f->e.eflags |= FLAG_C;
274 }
275 else if (f->b.al == 1)
276 {
277 f->e.eax = set_attr ((const char *)f->e.edx, f->e.ecx);
278 if (f->e.eax != 0)
279 f->e.eflags |= FLAG_C;
280 }
281 else
282 bad_func (f);
283 break;
284
285 case 0x44:
286
287 /* IOCTL */
288
289 if (f->b.al != 0)
290 bad_func (f);
291 f->e.edx = do_ioctl1 (f->e.ebx, (int *)&f->e.eax);
292 if (f->e.eax != 0)
293 f->e.eflags |= FLAG_C;
294 break;
295
296 case 0x45:
297
298 /* Duplicate file handle. */
299
300 f->e.eax = do_dup (f->e.ebx, (ULONG)(-1), &err_no);
301 if (err_no != 0)
302 {
303 f->e.eax = err_no;
304 f->e.eflags |= FLAG_C;
305 }
306 break;
307
308 case 0x46:
309
310 /* Force duplicate file handle. */
311
312 f->e.eax = do_dup (f->e.ebx, f->e.ecx, &err_no);
313 if (err_no != 0)
314 {
315 f->e.eax = err_no;
316 f->e.eflags |= FLAG_C;
317 }
318 break;
319
320 case 0x47:
321
322 /* Get current directory. */
323
324 f->e.eax = do_getcwd ((char *)f->e.esi, f->b.dl);
325 if (f->e.eax != 0)
326 f->e.eflags |= FLAG_C;
327 break;
328
329 case 0x4c:
330
331 /* End process. */
332
333 quit (f->b.al);
334 break;
335
336 case 0x4e:
337
338 f->e.eax = do_find_first ((const char *)f->e.edx, f->e.ecx & 0x37,
339 (struct _find *)f->e.esi);
340 if (f->e.eax != 0)
341 f->e.eflags |= FLAG_C;
342 break;
343
344 case 0x4f:
345
346 f->e.eax = do_find_next ((struct _find *)f->e.esi);
347 if (f->e.eax != 0)
348 f->e.eflags |= FLAG_C;
349 break;
350
351 case 0x56:
352
353 /* Change directory entry. */
354
355 f->e.eax = do_rename ((const char *)f->e.edx, (const char *)f->e.edi);
356 if (f->e.eax != 0)
357 f->e.eflags |= FLAG_C;
358 break;
359
360 case 0x57:
361
362 /* Get/set time/date of file. */
363
364 if (f->b.al == 0)
365 {
366 f->e.eax = do_get_timestamp (f->e.ebx, &f->e.ecx, &f->e.edx);
367 if (f->e.eax != 0)
368 f->e.eflags |= FLAG_C;
369 }
370 else if (f->b.al == 1)
371 {
372 f->e.eax = do_set_timestamp (f->e.ebx, f->e.ecx, f->e.edx);
373 if (f->e.eax != 0)
374 f->e.eflags |= FLAG_C;
375 }
376 else
377 {
378 f->e.eax = EINVAL;
379 f->e.eflags |= FLAG_C;
380 }
381 break;
382
383 default:
384 bad_func (f);
385 }
386}
387
388
389static void bad_func (syscall_frame *f)
390{
391 oprintf ("Invalid syscall function code: %.2x\r\n", (unsigned)f->b.ah);
392 quit (255);
393}
394
395
396/* Get date. */
397
398static void do_get_date (syscall_frame *f)
399{
400 DATETIME dt;
401
402 DosGetDateTime (&dt);
403 f->x.cx = dt.year;
404 f->b.dh = dt.month;
405 f->b.dl = dt.day;
406 f->b.al = dt.weekday;
407}
408
409
410/* Get time. */
411
412static void do_get_time (syscall_frame *f)
413{
414 DATETIME dt;
415
416 DosGetDateTime (&dt);
417 f->b.ch = dt.hours;
418 f->b.cl = dt.minutes;
419 f->b.dh = dt.seconds;
420 f->b.dl = dt.hundredths;
421}
422
423
424/* Get version number. */
425
426static void do_get_version (syscall_frame *f)
427{
428 f->e.eax = ((version_major & 0xff) | ((version_minor & 0xff) << 8)
429 | 0x6d650000);
430 f->x.bx = 0;
431 f->x.cx = 0;
432}
Note: See TracBrowser for help on using the repository browser.