461 lines
24 KiB
Plaintext
461 lines
24 KiB
Plaintext
1 ; asmfuncs.asm
|
|
2 ; Josh Holtrop
|
|
3 ; Created: 10/23/03
|
|
4 ; Modified: 12/25/03
|
|
5
|
|
6 [extern _putc]
|
|
7 [extern _console_memory]
|
|
8 [extern _cursorPosition]
|
|
9 [extern _video_drawConsole]
|
|
10 [extern _videoMode]
|
|
11
|
|
12 %macro jzfar 1
|
|
13 jnz %%skip
|
|
14 jmp %1
|
|
15 %%skip:
|
|
16
|
|
17 %endmacro
|
|
18
|
|
19 ;stores the parameter to the CR0 register
|
|
20 ;extern dword write_cr0(dword cr0);
|
|
21 [global _write_cr0]
|
|
22 _write_cr0:
|
|
23 00000000 55 push ebp
|
|
24 00000001 89E5 mov ebp, esp
|
|
25 00000003 8B4508 mov eax, [ebp+8]
|
|
26 00000006 0F22C0 mov cr0, eax
|
|
27 00000009 5D pop ebp
|
|
28 0000000A C3 ret
|
|
29
|
|
30 ;returns the value in the CR0 register
|
|
31 ;extern dword read_cr0();
|
|
32 [global _read_cr0]
|
|
33 _read_cr0:
|
|
34 0000000B 0F20C0 mov eax, cr0;
|
|
35 0000000E C3 ret
|
|
36
|
|
37 ;stores the parameter to the CR3 register
|
|
38 ;extern dword write_cr3(dword cr3);
|
|
39 [global _write_cr3]
|
|
40 _write_cr3:
|
|
41 0000000F 55 push ebp
|
|
42 00000010 89E5 mov ebp, esp
|
|
43 00000012 8B4508 mov eax, [ebp+8]
|
|
44 00000015 0F22D8 mov cr3, eax
|
|
45 00000018 5D pop ebp
|
|
46 00000019 C3 ret
|
|
47
|
|
48 ;returns the value in the CR3 register
|
|
49 ;extern dword read_cr3();
|
|
50 [global _read_cr3]
|
|
51 _read_cr3:
|
|
52 0000001A 0F20D8 mov eax, cr3;
|
|
53 0000001D C3 ret
|
|
54
|
|
55 ;compares one string to another
|
|
56 ;returns 0 if the strings are different
|
|
57 ;extern dword strcmp(char *str1, char *str2);
|
|
58 [global _strcmp]
|
|
59 _strcmp:
|
|
60 0000001E 55 push ebp
|
|
61 0000001F 89E5 mov ebp, esp
|
|
62 00000021 56 push esi
|
|
63 00000022 57 push edi
|
|
64
|
|
65 00000023 8B7508 mov esi, [ebp+8]
|
|
66 00000026 8B7D0C mov edi, [ebp+12]
|
|
67 strcmp_loop1:
|
|
68 00000029 AC lodsb
|
|
69 0000002A 8A27 mov ah, [edi]
|
|
70 0000002C 47 inc edi
|
|
71 0000002D 38C4 cmp ah, al
|
|
72 0000002F 750D jnz strcmp_ne
|
|
73 00000031 08C0 or al, al
|
|
74 00000033 7402 jz strcmp_e
|
|
75 00000035 EBF2 jmp strcmp_loop1
|
|
76 strcmp_e:
|
|
77 00000037 B801000000 mov eax, 1
|
|
78 0000003C EB02 jmp short strcmp_done
|
|
79 strcmp_ne:
|
|
80 0000003E 31C0 xor eax, eax
|
|
81 strcmp_done:
|
|
82
|
|
83 00000040 5F pop edi
|
|
84 00000041 5E pop esi
|
|
85 00000042 5D pop ebp
|
|
86 00000043 C3 ret
|
|
87
|
|
88 ;copies a string from the source to the destination parameter
|
|
89 ;extern void strcpy(char *dest, char *src);
|
|
90 [global _strcpy]
|
|
91 _strcpy:
|
|
92 00000044 55 push ebp
|
|
93 00000045 89E5 mov ebp, esp
|
|
94 00000047 56 push esi
|
|
95 00000048 57 push edi
|
|
96 00000049 8B7D08 mov edi, [ebp+8]
|
|
97 0000004C 8B750C mov esi, [ebp+12]
|
|
98 strcpyloop:
|
|
99 0000004F AC lodsb
|
|
100 00000050 AA stosb
|
|
101 00000051 08C0 or al, al
|
|
102 00000053 75FA jnz strcpyloop
|
|
103 00000055 5F pop edi
|
|
104 00000056 5E pop esi
|
|
105 00000057 5D pop ebp
|
|
106 00000058 C3 ret
|
|
107
|
|
108 ;copies memory of n bytes from src to destination
|
|
109 ;extern void memcpy(dword dest, dword src, dword n);
|
|
110 [global _memcpy]
|
|
111 _memcpy:
|
|
112 00000059 55 push ebp
|
|
113 0000005A 89E5 mov ebp, esp
|
|
114 0000005C 56 push esi
|
|
115 0000005D 57 push edi
|
|
116 0000005E 51 push ecx
|
|
117 0000005F 8B7D08 mov edi, [ebp+8]
|
|
118 00000062 8B750C mov esi, [ebp+12]
|
|
119 00000065 8B4D10 mov ecx, [ebp+16]
|
|
120
|
|
121 00000068 F3A4 rep movsb
|
|
122
|
|
123 0000006A 59 pop ecx
|
|
124 0000006B 5F pop edi
|
|
125 0000006C 5E pop esi
|
|
126 0000006D 5D pop ebp
|
|
127 0000006E C3 ret
|
|
128
|
|
129 ;returns the number of characters in a string
|
|
130 ;extern dword strlen(char *str);
|
|
131 [global _strlen]
|
|
132 _strlen:
|
|
133 0000006F 55 push ebp
|
|
134 00000070 89E5 mov ebp, esp
|
|
135 00000072 56 push esi
|
|
136 00000073 53 push ebx
|
|
137 00000074 8B7508 mov esi, [ebp+8]
|
|
138 00000077 31DB xor ebx, ebx
|
|
139 strlenloop:
|
|
140 00000079 AC lodsb
|
|
141 0000007A 08C0 or al, al
|
|
142 0000007C 7403 jz strlendone
|
|
143 0000007E 43 inc ebx
|
|
144 0000007F EBF8 jmp strlenloop
|
|
145 strlendone:
|
|
146 00000081 89D8 mov eax, ebx
|
|
147 00000083 5B pop ebx
|
|
148 00000084 5E pop esi
|
|
149 00000085 5D pop ebp
|
|
150 00000086 C3 ret
|
|
151
|
|
152 ;this function invalidates the page directory/table entry that
|
|
153 ; would be used to access the memory address given in the parameter
|
|
154 ;extern void invlpg(dword addr);
|
|
155 [global _invlpg]
|
|
156 _invlpg:
|
|
157 00000087 8B442404 mov eax, [esp+4]
|
|
158 0000008B 0F0138 invlpg [eax]
|
|
159 0000008E C3 ret
|
|
160
|
|
161
|
|
162 ;
|
|
163 ;void writeCursorPosition(word pos)
|
|
164 ;
|
|
165 [global _writeCursorPosition]
|
|
166 _writeCursorPosition:
|
|
167 0000008F 55 push ebp
|
|
168 00000090 89E5 mov ebp, esp
|
|
169
|
|
170 00000092 50 push eax
|
|
171 00000093 53 push ebx
|
|
172 00000094 52 push edx
|
|
173
|
|
174 00000095 8B4508 mov eax, [ebp+8] ;cursor position in ax
|
|
175
|
|
176 00000098 88C3 mov bl, al
|
|
177 0000009A 66BAD403 mov dx, 0x03D4
|
|
178 0000009E B00E mov al, 0x0E
|
|
179 000000A0 EE out dx, al
|
|
180
|
|
181 000000A1 6642 inc dx
|
|
182 000000A3 88E0 mov al, ah
|
|
183 000000A5 EE out dx, al
|
|
184
|
|
185 000000A6 664A dec dx
|
|
186 000000A8 B00F mov al, 0x0F
|
|
187 000000AA EE out dx, al
|
|
188
|
|
189 000000AB 6642 inc dx
|
|
190 000000AD 88D8 mov al, bl
|
|
191 000000AF EE out dx, al
|
|
192
|
|
193 000000B0 5A pop edx
|
|
194 000000B1 5B pop ebx
|
|
195 000000B2 58 pop eax
|
|
196 000000B3 5D pop ebp
|
|
197
|
|
198 000000B4 C3 ret
|
|
199
|
|
200
|
|
201 ;
|
|
202 ;word getCursorPosition()
|
|
203 ;
|
|
204 [global _getCursorPosition]
|
|
205 _getCursorPosition:
|
|
206 000000B5 53 push ebx
|
|
207 000000B6 52 push edx
|
|
208
|
|
209 000000B7 31C0 xor eax, eax
|
|
210 000000B9 66BAD403 mov dx, 0x03D4
|
|
211 000000BD B00E mov al, 0x0E
|
|
212 000000BF EE out dx, al
|
|
213
|
|
214 000000C0 6642 inc dx
|
|
215 000000C2 EC in al, dx
|
|
216 000000C3 88C3 mov bl, al
|
|
217
|
|
218 000000C5 664A dec dx
|
|
219 000000C7 B00F mov al, 0x0F
|
|
220 000000C9 EE out dx, al
|
|
221
|
|
222 000000CA 6642 inc dx
|
|
223 000000CC EC in al, dx
|
|
224 000000CD 88DC mov ah, bl
|
|
225
|
|
226 000000CF 5A pop edx
|
|
227 000000D0 5B pop ebx
|
|
228
|
|
229 000000D1 C3 ret
|
|
230
|
|
231
|
|
232 ;
|
|
233 ;void console_scroll()
|
|
234 ;
|
|
235 [global _console_scroll]
|
|
236 _console_scroll:
|
|
237 000000D2 60 pusha
|
|
238 000000D3 BE[A0000000] mov esi, _console_memory+160
|
|
239 000000D8 BF[00000000] mov edi, _console_memory
|
|
240 000000DD B9C0030000 mov ecx, 960 ;(2000-80)/2
|
|
241 000000E2 F3A5 rep movsd
|
|
242 000000E4 66B82007 mov ax, 0x0720
|
|
243 000000E8 B950000000 mov ecx, 80
|
|
244 000000ED F366AB rep stosw
|
|
245 000000F0 BE[00000000] mov esi, _console_memory
|
|
246 000000F5 BF00800BC0 mov edi, 0xC00B8000
|
|
247 000000FA B9E8030000 mov ecx, 1000
|
|
248 000000FF F3A5 rep movsd
|
|
249 00000101 A1[00000000] mov eax, [_videoMode]
|
|
250 00000106 3D00000000 cmp eax, 0
|
|
251 0000010B 7405 jz _console_scroll_end
|
|
252 0000010D E8(00000000) call _video_drawConsole
|
|
253 _console_scroll_end:
|
|
254 00000112 61 popa
|
|
255 00000113 C3 ret
|
|
256
|
|
257
|
|
258
|
|
259 ;
|
|
260 ;void console_cls()
|
|
261 ;
|
|
262 [global _console_cls]
|
|
263 _console_cls:
|
|
264 00000114 60 pusha
|
|
265 00000115 BF[00000000] mov edi, _console_memory
|
|
266 0000011A 66B82007 mov ax, 0x0720
|
|
267 0000011E B9D0070000 mov ecx, 2000
|
|
268 00000123 F366AB rep stosw
|
|
269 00000126 6800000000 push dword 0
|
|
270 0000012B E85FFFFFFF call _writeCursorPosition
|
|
271 00000130 81C404000000 add esp, 4
|
|
272 00000136 C705[00000000]0000- mov [_cursorPosition], dword 0
|
|
273 0000013E 0000
|
|
274 00000140 BE[00000000] mov esi, _console_memory
|
|
275 00000145 BF00800BC0 mov edi, 0xC00B8000
|
|
276 0000014A B9E8030000 mov ecx, 1000
|
|
277 0000014F F3A5 rep movsd
|
|
278 00000151 61 popa
|
|
279 00000152 C3 ret
|
|
280
|
|
281
|
|
282
|
|
283
|
|
284 ;
|
|
285 ;int puts(char *str)
|
|
286 ;
|
|
287 [global _puts]
|
|
288 _puts:
|
|
289 00000153 55 push ebp
|
|
290 00000154 89E5 mov ebp, esp
|
|
291 00000156 56 push esi
|
|
292 00000157 50 push eax
|
|
293 00000158 8B7508 mov esi, [ebp+8] ;esi = to string
|
|
294 puts_loop:
|
|
295 0000015B AC lodsb
|
|
296 0000015C 3C00 cmp al, 0
|
|
297 0000015E 740E jz puts_done
|
|
298 00000160 50 push eax
|
|
299 00000161 E8(00000000) call _putc
|
|
300 00000166 81C404000000 add esp, 4
|
|
301 0000016C EBED jmp puts_loop
|
|
302
|
|
303 puts_done:
|
|
304 0000016E 58 pop eax
|
|
305 0000016F 5E pop esi
|
|
306 00000170 5D pop ebp
|
|
307 00000171 C3 ret
|
|
308
|
|
309
|
|
310
|
|
311
|
|
312 [global _putDecu]
|
|
313 _putDecu:
|
|
314 00000172 55 push ebp
|
|
315 00000173 89E5 mov ebp, esp
|
|
316 00000175 81EC18000000 sub esp, 24
|
|
317 0000017B C745FC01000000 mov DWORD [ebp-4], 1
|
|
318 00000182 C645FB00 mov BYTE [ebp-5], 0
|
|
319 L2:
|
|
320 00000186 8B5508 mov edx, DWORD [ebp+8]
|
|
321 00000189 B8CDCCCCCC mov eax, -858993459
|
|
322 0000018E F7E2 mul edx
|
|
323 00000190 89D0 mov eax, edx
|
|
324 00000192 C1E803 shr eax, 3
|
|
325 00000195 3B45FC cmp eax, DWORD [ebp-4]
|
|
326 00000198 7305 jae L4
|
|
327 0000019A E912000000 jmp L3
|
|
328 L4:
|
|
329 0000019F 8B45FC mov eax, DWORD [ebp-4]
|
|
330 000001A2 89C2 mov edx, eax
|
|
331 000001A4 C1E202 sal edx, 2
|
|
332 000001A7 01C2 add edx, eax
|
|
333 000001A9 8D0412 lea eax, [edx+edx]
|
|
334 000001AC 8945FC mov DWORD [ebp-4], eax
|
|
335 000001AF EBD5 jmp L2
|
|
336 L3:
|
|
337 000001B1 90 nop
|
|
338 L5:
|
|
339 000001B2 817DFC01000000 cmp DWORD [ebp-4], 1
|
|
340 000001B9 7705 ja L7
|
|
341 000001BB E959000000 jmp L6
|
|
342 L7:
|
|
343 000001C0 8B5508 mov edx, DWORD [ebp+8]
|
|
344 000001C3 89D0 mov eax, edx
|
|
345 000001C5 BA00000000 mov edx, 0
|
|
346 000001CA F775FC div DWORD [ebp-4]
|
|
347 000001CD 8945F4 mov DWORD [ebp-12], eax
|
|
348 000001D0 8A45F4 mov al, BYTE [ebp-12]
|
|
349 000001D3 8845FB mov BYTE [ebp-5], al
|
|
350 000001D6 B800000000 mov eax, 0
|
|
351 000001DB 8A45FB mov al, BYTE [ebp-5]
|
|
352 000001DE 0FAF45FC imul eax, DWORD [ebp-4]
|
|
353 000001E2 294508 sub DWORD [ebp+8], eax
|
|
354 000001E5 8B55FC mov edx, DWORD [ebp-4]
|
|
355 000001E8 B8CDCCCCCC mov eax, -858993459
|
|
356 000001ED F7E2 mul edx
|
|
357 000001EF 89D0 mov eax, edx
|
|
358 000001F1 C1E803 shr eax, 3
|
|
359 000001F4 8945FC mov DWORD [ebp-4], eax
|
|
360 000001F7 8D45FB lea eax, [ebp-5]
|
|
361 000001FA 800030 add BYTE [eax], 48
|
|
362 000001FD 81EC0C000000 sub esp, 12
|
|
363 00000203 B800000000 mov eax, 0
|
|
364 00000208 8A45FB mov al, BYTE [ebp-5]
|
|
365 0000020B 50 push eax
|
|
366 0000020C E8(00000000) call _putc
|
|
367 00000211 81C410000000 add esp, 16
|
|
368 00000217 EB99 jmp L5
|
|
369 L6:
|
|
370 00000219 81EC0C000000 sub esp, 12
|
|
371 0000021F 8A4508 mov al, BYTE [ebp+8]
|
|
372 00000222 0530000000 add eax, 48
|
|
373 00000227 25FF000000 and eax, 255
|
|
374 0000022C 50 push eax
|
|
375 0000022D E8(00000000) call _putc
|
|
376 00000232 81C410000000 add esp, 16
|
|
377 00000238 C9 leave
|
|
378 00000239 C3 ret
|
|
379
|
|
380
|
|
381
|
|
382
|
|
383 [global _putDec]
|
|
384 _putDec:
|
|
385 0000023A 55 push ebp
|
|
386 0000023B 89E5 mov ebp, esp
|
|
387 0000023D 81EC18000000 sub esp, 24
|
|
388 00000243 817D0800000000 cmp DWORD [ebp+8], 0
|
|
389 0000024A 7919 jns L9
|
|
390 0000024C 81EC0C000000 sub esp, 12
|
|
391 00000252 682D000000 push 45
|
|
392 00000257 E8(00000000) call _putc
|
|
393 0000025C 81C410000000 add esp, 16
|
|
394 00000262 F75D08 neg DWORD [ebp+8]
|
|
395 L9:
|
|
396 00000265 C745FC01000000 mov DWORD [ebp-4], 1
|
|
397 0000026C C645FB00 mov BYTE [ebp-5], 0
|
|
398 L10:
|
|
399 00000270 8B4508 mov eax, DWORD [ebp+8]
|
|
400 00000273 3B45FC cmp eax, DWORD [ebp-4]
|
|
401 00000276 7305 jae L12
|
|
402 00000278 E912000000 jmp L11
|
|
403 L12:
|
|
404 0000027D 8B45FC mov eax, DWORD [ebp-4]
|
|
405 00000280 89C2 mov edx, eax
|
|
406 00000282 C1E202 sal edx, 2
|
|
407 00000285 01C2 add edx, eax
|
|
408 00000287 8D0412 lea eax, [edx+edx]
|
|
409 0000028A 8945FC mov DWORD [ebp-4], eax
|
|
410 0000028D EBE1 jmp L10
|
|
411 L11:
|
|
412 0000028F 8B55FC mov edx, DWORD [ebp-4]
|
|
413 00000292 B8CDCCCCCC mov eax, -858993459
|
|
414 00000297 F7E2 mul edx
|
|
415 00000299 89D0 mov eax, edx
|
|
416 0000029B C1E803 shr eax, 3
|
|
417 0000029E 8945FC mov DWORD [ebp-4], eax
|
|
418 L13:
|
|
419 000002A1 817DFC01000000 cmp DWORD [ebp-4], 1
|
|
420 000002A8 7705 ja L15
|
|
421 000002AA E959000000 jmp L14
|
|
422 L15:
|
|
423 000002AF 8B5508 mov edx, DWORD [ebp+8]
|
|
424 000002B2 89D0 mov eax, edx
|
|
425 000002B4 BA00000000 mov edx, 0
|
|
426 000002B9 F775FC div DWORD [ebp-4]
|
|
427 000002BC 8945F4 mov DWORD [ebp-12], eax
|
|
428 000002BF 8A45F4 mov al, BYTE [ebp-12]
|
|
429 000002C2 8845FB mov BYTE [ebp-5], al
|
|
430 000002C5 B800000000 mov eax, 0
|
|
431 000002CA 8A45FB mov al, BYTE [ebp-5]
|
|
432 000002CD 0FAF45FC imul eax, DWORD [ebp-4]
|
|
433 000002D1 294508 sub DWORD [ebp+8], eax
|
|
434 000002D4 8B55FC mov edx, DWORD [ebp-4]
|
|
435 000002D7 B8CDCCCCCC mov eax, -858993459
|
|
436 000002DC F7E2 mul edx
|
|
437 000002DE 89D0 mov eax, edx
|
|
438 000002E0 C1E803 shr eax, 3
|
|
439 000002E3 8945FC mov DWORD [ebp-4], eax
|
|
440 000002E6 8D45FB lea eax, [ebp-5]
|
|
441 000002E9 800030 add BYTE [eax], 48
|
|
442 000002EC 81EC0C000000 sub esp, 12
|
|
443 000002F2 B800000000 mov eax, 0
|
|
444 000002F7 8A45FB mov al, BYTE [ebp-5]
|
|
445 000002FA 50 push eax
|
|
446 000002FB E8(00000000) call _putc
|
|
447 00000300 81C410000000 add esp, 16
|
|
448 00000306 EB99 jmp L13
|
|
449 L14:
|
|
450 00000308 81EC0C000000 sub esp, 12
|
|
451 0000030E 8A4508 mov al, BYTE [ebp+8]
|
|
452 00000311 0530000000 add eax, 48
|
|
453 00000316 25FF000000 and eax, 255
|
|
454 0000031B 50 push eax
|
|
455 0000031C E8(00000000) call _putc
|
|
456 00000321 81C410000000 add esp, 16
|
|
457 00000327 C9 leave
|
|
458 00000328 C3 ret
|
|
459
|
|
460
|