]> pd.if.org Git - mmurtl/blob - ossource/svccode.asm
autocommit for file dated 2003-12-29 17:36:54
[mmurtl] / ossource / svccode.asm
1 ;   MMURTL Operating System Source Code\r
2 ;   Copyright 1991,1992,1993, Richard A. Burgess\r
3 ;   ALL RIGHTS RESERVED\r
4 ;   Version x0.8\r
5 \r
6 .DATA\r
7 .INCLUDE MOSEDF.INC\r
8 \r
9 ;=============================================================================\r
10 .CODE\r
11 ;=============================================================================\r
12 ;\r
13 ; GetExchange\r
14 ;\r
15 ; This returns the exchange associated with a service name pointed to in EAX.\r
16 ; It scans the array of servce names and finds a match. ESI pts to the\r
17 ; SvcDesc if found and EAX has ercOk, else EAX has error code and ESI\r
18 ; is undefined.\r
19 ;\r
20 ; INPUT  - EAX = Pointer to the Service Name (8 bytes long)\r
21 ; OUTPUT - EAX = result code\r
22 ;                  ESI = exchange\r
23 ; USED   - EAX, EBX, ESI, EDX, EFlags\r
24 ;\r
25 ;=============================================================================\r
26 \r
27 PUBLIC GetExchange:\r
28                 MOV EDX,[EAX]                   ; First DWORD of the SvcName in EDX\r
29                 MOV EBX,[EAX+4]                 ; Second DWORD of the SvcName in EBX\r
30                 MOV ESI,OFFSET rgSVC    ; Get the address of rgSVC\r
31                 MOV ECX,nSVC                    ; Get the number of Service Descriptors\r
32 GE0000:\r
33                 CMP EDX, [ESI]                  ; Compare first 4 bytes\r
34                 JNE SHORT GE0001                ; Not equal.. JUMP\r
35                 CMP EBX, [ESI+4]                ; Compare first 4 bytes\r
36                 JNE SHORT GE0001                ; Not equal.. JUMP\r
37                 MOV ESI,[ESI+8]                 ; Get the Exchange in ESI\r
38                 MOV EAX,ercOk                   ; Set EAX to ercOk\r
39                 RETN                                    ; return\r
40 GE0001:\r
41                 ADD ESI,sSVC                    ; Move Dest Ptr to Next rgSvc Element\r
42                 LOOP GE0000                             ; Loop until ECX = 0\r
43                 MOV EAX,ErcNoSuchSvc    ; set result code\r
44                 RETN                                    ; Get out\r
45 \r
46 ;=============================================================================\r
47 \r
48 FindEmptySVC:\r
49 ;\r
50 ; INPUT : NONE\r
51 ; OUTPUT : EAX,ESI\r
52 ; REGISTERS : ECX\r
53 ; MODIFIES : NOTHING\r
54 ;\r
55 ; Searches the list of Service Descriptors and returns a ptr to an empty\r
56 ; Service Descriptor in ESI with ercOk in EAX.\r
57 ; If an empty Svc Desc in not found, an Error is returned in EAX\r
58 ; and ESI is undefined. Used by RegisterSvc (below)\r
59 ;\r
60                 MOV ESI, OFFSET rgSVC   ; Get address of the Service Descriptor Array\r
61                 MOV ECX,nSVC            ; Get number of Service Descriptors\r
62                 CLI\r
63 FELOOP:\r
64         CMP DWORD PTR [ESI],0   ; Is the lower dword empty?\r
65                 JNE SHORT FENEXT        ; NO\r
66                 CMP DWORD PTR [ESI+4],0 ; Is the upper dword empty?\r
67                 JNE SHORT FENEXT        ; NO\r
68                 XOR EAX,EAX             ; No Error\r
69                 STI\r
70                 RETN                    ;\r
71 FENEXT:\r
72         ADD ESI,sSVC            ;\r
73                 LOOP FELOOP             ;\r
74                 MOV EAX,ErcOutOfSvcDesc ;\r
75 FEEXIT:\r
76         STI\r
77                 RETN\r
78 \r
79 ;==============================\r
80 \r
81 FindMatchSVC:\r
82 ;\r
83 ; INPUT : EDX:EBX  contains name of service to search for\r
84 ; OUTPUT : EAX,ESI\r
85 ; REGISTERS : ECX\r
86 ; MODIFIES : NOTHING\r
87 ;\r
88 ; Searches the list of Service Descriptors and returns a ptr to the match\r
89 ; in ESI with ercOk in EAX.\r
90 ; If not found an Error is returned in EAX and ESI is undefined.\r
91 ; Used by RegisterSvc (below)\r
92 ;\r
93                 MOV ESI, OFFSET rgSVC       ; Get address of the Service Desc Array\r
94                 MOV ECX,nSVC                ; Get number of Service Descriptors\r
95                 CLI\r
96 FMLOOP:\r
97         CMP [ESI],EDX                           ; lower dword match?\r
98                 JNE SHORT FMNEXT            ; NO\r
99                 CMP [ESI+4],EBX                 ; upper dword match?\r
100                 JNE SHORT FMNEXT            ; NO\r
101                 XOR EAX,EAX                 ; No Error\r
102                 STI\r
103                 RETN                        ;\r
104 FMNEXT:\r
105         ADD ESI,sSVC                ;\r
106                 LOOP FMLOOP                 ;\r
107                 MOV EAX, ErcNoSuchSvc       ;\r
108 FMEXIT:\r
109         STI\r
110                 RETN\r
111 \r
112 ;=============================================================================\r
113 ;\r
114 ; RegisterSvc - The kernel system service name registery. This procedure will\r
115 ; identify a particular system service name with a particular exchange.\r
116 ; The name is an 8 byte (null padded) CASE SENSITIVE string. The name is\r
117 ; registered with the operating system along with a service exchange. Together\r
118 ; the information allows the OS to direct requests for system services without\r
119 ; the originator having to know where the actual exchange is located or on\r
120 ; what machine the request is being serviced.\r
121 ;\r
122 ; A result code in returned in the EAX register.\r
123 ;\r
124 ; Procedural Interface :\r
125 ;\r
126 ;   RegisterName(pName,exch):ercType\r
127 ;\r
128 ;           pName is a POINTER to the new Service Name\r
129 \r
130 ;           exch is a DWORD (4 BYTES) containing the exchange where the\r
131 ;           service will accept messages.\r
132 ;\r
133 pSVCName       EQU [EBP+16]\r
134 SVCExchange    EQU [EBP+12]\r
135 \r
136 PUBLIC __RegisterSvc:\r
137                 PUSH EBP                ;\r
138                 MOV EBP,ESP             ;\r
139                 MOV EAX,pSVCName        ; in EAX\r
140                 MOV EDX,[EAX]           ; Get the Name into EDX:EBX for Find call\r
141                 MOV EBX,[EAX+4]         ;\r
142                 CALL FindMatchSVC       ; Is it already there? (if so, overwrite)\r
143                 CMP EAX,ercOk           ; ercOk if it is\r
144                 JNE SHORT RSNew         ; No, go get an empty one\r
145                 JMP SHORT RSFill        ; Yes, Overwrite it\r
146 RSNew:\r
147         CALL FindEmptySVC       ;\r
148                 CMP EAX,ercOk           ;\r
149                 JNE SHORT RSDone        ;\r
150 RSFill:\r
151                 MOV EAX,pSVCName        ; pSVCName in EAX\r
152                 MOV EDX, [EAX]                  ; Low DWORD of name into EDX\r
153                 MOV [ESI], EDX          ; Now into Svc Descriptor\r
154                 MOV EBX,[EAX+4]         ; Low DWORD of name into EBX\r
155                 MOV [ESI+4], EBX        ; Now into Svc Descriptor\r
156         MOV ECX,SVCExchange     ;\r
157                 MOV [ESI+SvcExch],ECX   ;\r
158                 XOR EAX,EAX             ;\r
159 RSDone:\r
160                 MOV ESP,EBP             ;\r
161                 POP EBP                 ;\r
162                 RETF 8                                  ;\r
163 \r
164 ;=============================================================================\r
165 ;\r
166 ; UnRegisterSvc -  This removes the service name from the name\r
167 ; name registry. The name must be an exact match for the one\r
168 ; supplied to RegisterSvc.\r
169 ; The name is an 8 byte (null padded) CASE SENSITIVE string.\r
170 ;\r
171 ; A result code in returned in the EAX register.\r
172 ;\r
173 ; Procedural Interface :\r
174 ;\r
175 ;   UnRegisterName(pName):ercType\r
176 ;\r
177 ;           pName is a POINTER to the existing Service Name\r
178 \r
179 ;           exch is a DWORD (4 BYTES) containing the exchange where the\r
180 ;           service will accept messages.\r
181 ;\r
182 pOldSVCName       EQU [EBP+12]\r
183 \r
184 PUBLIC __UnRegisterSvc:\r
185                 PUSH EBP                ;\r
186                 MOV EBP,ESP             ;\r
187                 MOV EAX,pOldSVCName     ; in EAX\r
188                 MOV EDX,[EAX]           ; Get the Name into EDX:EBX for Find call\r
189                 MOV EBX,[EAX+4]         ;\r
190                 CALL FindMatchSVC       ; Is it already there? (if so, overwrite)\r
191                 OR EAX, EAX                             ; ErcOK?\r
192                 JZ  SHORT URSKill       ; Found it, go kill it\r
193                 JMP SHORT URSDone       ; ErcNoSuchSvc already in EAX\r
194 URSKill:\r
195                 XOR EAX, EAX                    ; Low DWORD of name into EDX\r
196                 MOV [ESI], EAX          ; Now into Svc Descriptor\r
197                 MOV [ESI+4], EAX        ; (EAX already zero for ErcOK)\r
198 URSDone:\r
199                 MOV ESP,EBP             ;\r
200                 POP EBP                 ;\r
201                 RETF 4                                  ;\r
202 \r
203 ;=========== End of Module ===================\r