* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / linux86-0.16.17 / libc / msdos / i86.c
blob3cab105e0e95f711b87f8ec93263852a065706de
1 /* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
2 * This file is part of the Linux-8086 C library and is distributed
3 * under the GNU Library General Public License.
4 */
5 /*
6 * These functions will not normally be useful for Linux-8086. But they
7 * can be used and may be useful in the kernel.
8 */
10 #ifdef __AS386_16__
12 #ifdef L___seg_regs
13 unsigned int
14 __get_cs()
16 #asm
17 mov ax,cs
18 #endasm
21 unsigned int
22 __get_ds()
24 #asm
25 mov ax,ds
26 #endasm
29 unsigned int
30 __get_es()
32 #asm
33 mov ax,es
34 #endasm
37 void
38 __set_es(seg)
40 #asm
41 #if __FIRST_ARG_IN_AX__
42 mov es,ax
43 #else
44 mov bx,sp
45 mov es,[bx+2]
46 #endif
47 #endasm
49 #endif
51 #ifdef L___peek_es
52 int
53 __peek_es(off)
54 unsigned int off;
56 #asm
57 #if __FIRST_ARG_IN_AX__
58 mov bx,ax
59 #else
60 mov bx,sp
61 mov bx,[bx+2]
62 #endif
63 seg es
64 mov al,[bx]
65 xor ah,ah
66 #endasm
68 #endif
70 #ifdef L___poke_es
71 int
72 __poke_es(off, value)
73 unsigned int off;
74 int value;
76 #asm
77 #if __FIRST_ARG_IN_AX__
78 mov bx,sp
79 mov bx,[bx+2]
80 xchg ax,bx
81 #else
82 mov bx,sp
83 mov ax,[bx+4]
84 mov bx,[bx+2]
85 #endif
86 seg es
87 mov [bx],al
88 xor ah,ah
89 #endasm
91 #endif
93 #ifdef L___deek_es
94 int
95 __deek_es(off)
96 unsigned int off;
98 #asm
99 #if __FIRST_ARG_IN_AX__
100 mov bx,ax
101 #else
102 mov bx,sp
103 mov bx,[bx+2]
104 #endif
105 seg es
106 mov ax,[bx]
107 #endasm
109 #endif
111 #ifdef L___doke_es
113 __doke_es(off, value)
114 unsigned int off;
115 int value;
117 #asm
118 #if __FIRST_ARG_IN_AX__
119 mov bx,sp
120 mov bx,[bx+2]
121 xchg ax,bx
122 #else
123 mov bx,sp
124 mov ax,[bx+4]
125 mov bx,[bx+2]
126 #endif
127 seg es
128 mov [bx],ax
129 #endasm
131 #endif
133 #ifdef L___strchr_es
134 char *
135 __strchr_es(s, c)
136 char * s;
137 int c;
139 #asm
140 mov bx,sp
141 push si
142 #if __FIRST_ARG_IN_AX__
143 mov bx,[bx+2]
144 mov si,ax
145 #else
146 mov si,[bx+2]
147 mov bx,[bx+4]
148 #endif
149 xor ax,ax
151 #ifdef PARANOID
153 #endif
154 push ds
155 push es
156 pop ds
158 in_loop:
159 lodsb
160 cmp al,bl
161 jz got_it
162 or al,al
163 jnz in_loop
164 pop ds
165 pop si
167 got_it:
168 lea ax,[si-1]
169 pop ds
170 pop si
172 #endasm
174 #endif
176 #ifdef L___strnget_es
177 char *
178 __strnget_es(d, s, c)
179 char *d;
180 char *s;
181 register int c;
183 register int i = __strlen_es(s);
184 if(i < c) c = i+1;
185 /* else s[--c] = 0; ?? */
186 /* else return -E2BIG; ?? */
188 __movedata(__get_es(), s, __get_ds(), d, c);
190 #endif
192 #ifdef L___strlen_es
193 int __strlen_es(str)
194 char * str;
196 #asm
197 #if !__FIRST_ARG_IN_AX__
198 mov bx,sp
199 #endif
200 push di
203 #if __FIRST_ARG_IN_AX__
204 mov di,ax
205 #else
206 mov di,[bx+2]
207 #endif
208 mov cx,#-1
209 xor ax,ax
210 repne
211 scasb ! Scans [ES:DI]
212 not cx
213 dec cx
214 mov ax,cx
216 pop di
217 #endasm
219 #endif
221 #ifdef L_int86
223 int86(intr, in_regs, out_regs)
224 int intr;
225 union REGS* in_regs;
226 union REGS* out_regs;
228 #asm
229 push bp
230 mov bp,sp
231 push ds ! save ds
232 ! es too ?
233 push bp ! same for new bp
235 pushf ! iret flags
236 mov ax,[bp-6] ! flags for simulated int
237 push cs ! iret address segment
238 mov bx,#ret_addr ! iret address offset
239 push bx
240 and ah,#$0C ! simulate interrupt flags
241 push ax ! flags are pushed first
243 xor bx,bx
244 mov es,bx ! interrupt vectors in seg 0
245 mov bl,[bp+4]
246 shl bx,#1
247 shl bx,#1 ! intr*4 => interrupt vector address
248 seg es
249 push [bx+2] ! fetch interrupt segment
250 seg es
251 push [bx] ! fetch interrupt offset
252 mov bx,[bp+6] ! input union REGS*
254 mov ax,[bx]
255 mov cx,[bx+4]
256 mov dx,[bx+6]
257 mov si,[bx+8]
258 mov di,[bx+10]
259 mov bx,[bx+2]
260 ! Ignore cflag/flags ?
262 iret ! simulate interrupt.
263 ! But won't be nice for protected mode ...
264 ret_addr:
265 ! Int $25/6 would need resetting sp:ss too ... should I ?
267 pop bp ! unzapped versions
268 pop ds ! paranoia
270 pushf ! save interrupt flags
271 push bx ! save pointer register
272 mov bx,[bp+8] ! output union REGS*
274 mov [bx],ax
275 pop [bx+2]
276 mov [bx+4],cx
277 mov [bx+6],dx
278 mov [bx+8],si
279 mov [bx+10],di
280 mov word [bx+12],#0 ! cflag
281 jnc no_carry
282 mov byte [bx+12],#1
283 no_carry:
284 pop [bx+14] ! flags
286 pop bp
287 #endasm
290 #endif
292 #ifdef L_int86x
294 int86x(intr, in_regs, out_regs, segr)
295 int intr;
296 union REGS* in_regs;
297 union REGS* out_regs;
298 struct SREGS * segr;
300 #asm
301 push bp
302 mov bp,sp
303 push ds ! save ds
304 ! es too ?
305 push bp ! same for new bp
307 pushf ! iret flags
308 mov ax,[bp-6] ! flags for simulated int
309 push cs ! iret address segment
310 mov bx,#ret_addr ! iret address offset
311 push bx
312 and ah,#$0C ! simulate interrupt flags
313 push ax ! flags are pushed first
315 xor bx,bx
316 mov es,bx ! interrupt vectors in seg 0
317 mov bl,[bp+4]
318 shl bx,1
319 shl bx,1 ! intr*4 => interrupt vector address
320 seg es
321 push word [bx+2] ! fetch interrupt segment
322 seg es
323 push word [bx] ! fetch interrupt offset
325 mov bx,[bp+10] ! struct SREGS*
326 mov es,[bx]
327 push [bx+6] ! ds
329 mov bx,[bp+6] ! input union REGS*
331 mov ax,[bx]
332 mov cx,[bx+4]
333 mov dx,[bx+6]
334 mov si,[bx+8]
335 mov di,[bx+10]
336 mov bx,[bx+2]
337 ! Ignore cflag/flags ?
339 pop ds
341 iret ! simulate interrupt
342 ! But won't be nice for protected mode ...
344 ret_addr:
345 ! Int $25/6 would need resetting sp:ss too ... should I ?
347 pop bp ! in case it was zapped
349 pushf ! save interrupt flags
351 push cx ! save work register
352 mov cx,ds
353 push bx ! save pointer register
355 mov ds,word [bp-2] ! restore original ds
356 mov bx,[bp+10] ! struct SREGS*
357 mov [bx],es
358 mov [bx+6],cx
360 mov bx,[bp+8] ! output union REGS*
361 mov [bx],ax
362 pop [bx+2] ! bx
363 pop [bx+4] ! cx
364 mov [bx+6],dx
365 mov [bx+8],si
366 mov [bx+10],di
367 mov word [bx+12],#0 ! cflag
368 jnc no_carry
369 mov byte [bx+12],#1
370 no_carry:
371 pop [bx+14] ! flags
373 pop ds
374 pop bp
375 #endasm
377 #endif
379 #ifdef L_segread
380 segread(segp)
381 struct SREGS * segp;
383 #asm
384 #if __FIRST_ARG_IN_AX__
385 mov bx,ax
386 #else
387 mov bx,sp
388 mov bx,[bx+2]
389 #endif
390 mov [bx],es
391 mov [bx+2],cs
392 mov [bx+4],ss
393 mov [bx+6],ds
394 #endasm
396 #endif
398 #endif /* __AS386_16__ */