* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / linux86-0.16.17 / doselks / coroutine.c
blobfa72becf13eca44c665aca8634aa1b664c6d23fb
2 #include "doselks.h"
4 int in_process = 0;
5 int intr_pending = 0;
6 unsigned int current_ds, current_stack;
7 struct process * proc;
9 /***************************************************************************
10 * These two routines to make doselks and the user program into co-routines.
12 * The Server calls run_cpu which runs the client.
13 * The client then does an int $80 which calls elks_int.
14 * Elks_int then returns to the caller of run_cpu.
16 * The return value is the value of AX when the int $80 occured.
17 * On return ES is set to the DS of the client program.
19 * The instruction times are for the 286
21 * If we were using a 486 then using mov's would be faster on the 286 they
22 * are the same speed but push/pop is smaller.
25 #asm
26 .data
27 bx_temp: ! Tempoary storage for BX.
28 .word 0
29 .text ! The is where we store the current_ds in the _TEXT_ segment
30 cs_current_ds: ! for the elks_int routine
31 .word 0
32 #endasm
34 unsigned int run_cpu()
36 #asm
37 mov ax,ds ; 2
38 seg cs ! Store ds for return
39 mov [cs_current_ds],ax ; 5
41 cli ! We`re messing! ; 3
42 test [_intr_pending],#$FFFF ! Last chance ...
43 jz skp
44 sti
45 xor ax,ax
46 ret
47 skp:
48 push bp ; 3
49 push si ; 3
50 push di ; 3
51 mov [_current_stack],sp ; 5
52 mov ax,#1 ; 2
53 mov [_in_process],ax ; 5
54 mov sp,[_proc] ; 5
55 pop ax ! pppop ; 5
56 pop [bx_temp] ; 5
57 pop cx ; 5
58 pop dx ; 5
59 pop di ; 5
60 pop si ; 5
61 pop bp ; 5
62 pop es ; 5
63 mov bx,sp ! Switch to client stack ; 2
64 mov ss,[bx+8] ! SS ; 5
65 mov sp,[bx+10] ! SP ; 5
66 push [bx+6] ! flags ; 5
67 push [bx+4] ! CS ; 5
68 push [bx+2] ! PC ; 5
69 push [bx+0] ! DS ; 5
70 mov bx,[bx_temp] ; 5
71 pop ds ; 5
72 iret ; 17
73 #endasm
76 unsigned int elks_int()
78 #asm
79 .text
80 cli ; 3
81 push ds ; 3
82 push cs ; 3
83 pop ds ; 5
84 mov ds,[cs_current_ds] ; 5
85 mov [bx_temp],bx ; 3
86 mov bx,[_proc] ; 5
87 add bx,#16 ; 2
88 pop [bx+0] ! DS ; 5
89 pop [bx+2] ! PC ; 5
90 pop [bx+4] ! CS ; 5
91 pop [bx+6] ! flags ; 5
92 mov [bx+8],ss ! SS ; 3
93 mov [bx+10],sp ! SP ; 3
95 mov sp,bx ! Ready for pppppush ; 2
96 mov bx,ds ; 2
97 mov ss,bx ; 2
99 push es ! wheeee ; 3
100 push bp ; 3
101 push si ; 3
102 push di ; 3
103 push dx ; 3
104 push cx ; 3
105 push [bx_temp] ; 5
106 push ax ! This is the return value, handy ; 3
108 mov sp,[_current_stack] ; 5
109 mov bx,#1 ; 2
110 mov [_in_process],bx ; 5
111 sti ! Finished F**** around with the stack ; 2
113 mov bx,[_proc] ; 5
114 mov es,[bx+16] ! Set ES to the client`s DS ; 5
115 pop di ; 5
116 pop si ; 5
117 pop bp ; 5
118 #endasm