Rev 2288 | Rev 2455 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2288 | Rev 2384 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | ;; Copyright (C) KolibriOS team 2007-2008. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2007-2008. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 7... | Line 7... | ||
7 | 7 | ||
Line 8... | Line 8... | ||
8 | $Revision: 2288 $ |
8 | $Revision: 2384 $ |
9 | 9 | ||
Line 10... | Line 10... | ||
10 | ; Virtual-8086 mode manager |
10 | ; Virtual-8086 mode manager |
Line 11... | Line 11... | ||
11 | ; diamond, 2007, 2008 |
11 | ; diamond, 2007, 2008 |
12 | - | ||
13 | DEBUG_SHOW_IO = 0 |
12 | |
14 | 13 | DEBUG_SHOW_IO = 0 |
|
15 | struc V86_machine |
14 | |
16 | { |
15 | struct V86_machine |
17 | ; page directory |
16 | ; page directory |
18 | .pagedir dd ? |
17 | pagedir dd ? |
19 | ; translation table: V86 address -> flat linear address |
18 | ; translation table: V86 address -> flat linear address |
20 | .pages dd ? |
19 | pages dd ? |
21 | ; mutex to protect all data from writing by multiple threads at one time |
- | |
22 | .mutex dd ? |
- | |
23 | ; i/o permission map |
- | |
24 | .iopm dd ? |
- | |
25 | .size = $ |
20 | ; mutex to protect all data from writing by multiple threads at one time |
Line 26... | Line 21... | ||
26 | } |
21 | mutex dd ? |
27 | virtual at 0 |
22 | ; i/o permission map |
28 | V86_machine V86_machine |
23 | iopm dd ? |
29 | end virtual |
24 | ends |
30 | 25 | ||
31 | ; Create V86 machine |
26 | ; Create V86 machine |
32 | ; in: nothing |
27 | ; in: nothing |
33 | ; out: eax = handle (pointer to struc V86_machine) |
28 | ; out: eax = handle (pointer to struc V86_machine) |
34 | ; eax = NULL => failure |
29 | ; eax = NULL => failure |
35 | ; destroys: ebx, ecx, edx (due to malloc) |
30 | ; destroys: ebx, ecx, edx (due to malloc) |
36 | v86_create: |
31 | v86_create: |
37 | ; allocate V86_machine structure |
32 | ; allocate V86_machine structure |
38 | mov eax, V86_machine.size |
33 | mov eax, sizeof.V86_machine |
Line 243... | Line 238... | ||
243 | rep stosd |
238 | rep stosd |
244 | end if |
239 | end if |
245 | .ret: |
240 | .ret: |
246 | ret |
241 | ret |
Line 247... | Line 242... | ||
247 | 242 | ||
248 | struc v86_regs |
- | |
249 | { |
243 | struct v86_regs |
250 | ; don't change the order, it is important |
244 | ; don't change the order, it is important |
251 | .edi dd ? |
245 | edi dd ? |
252 | .esi dd ? |
246 | esi dd ? |
253 | .ebp dd ? |
247 | ebp dd ? |
254 | dd ? ; ignored |
248 | dd ? ; ignored |
255 | .ebx dd ? |
249 | ebx dd ? |
256 | .edx dd ? |
250 | edx dd ? |
257 | .ecx dd ? |
251 | ecx dd ? |
258 | .eax dd ? |
252 | eax dd ? |
259 | .eip dd ? |
253 | eip dd ? |
260 | .cs dd ? |
254 | cs dd ? |
261 | .eflags dd ? ; VM flag must be set! |
255 | eflags dd ? ; VM flag must be set! |
262 | .esp dd ? |
256 | esp dd ? |
263 | .ss dd ? |
257 | ss dd ? |
264 | .es dd ? |
258 | es dd ? |
265 | .ds dd ? |
259 | ds dd ? |
266 | .fs dd ? |
260 | fs dd ? |
267 | .gs dd ? |
- | |
268 | .size = $ |
- | |
269 | } |
- | |
270 | virtual at 0 |
- | |
271 | v86_regs v86_regs |
261 | gs dd ? |
Line 272... | Line 262... | ||
272 | end virtual |
262 | ends |
273 | 263 | ||
274 | ; Run V86 machine |
264 | ; Run V86 machine |
275 | ; in: ebx -> registers for V86 (two structures: in and out) |
265 | ; in: ebx -> registers for V86 (two structures: in and out) |
Line 317... | Line 307... | ||
317 | ; machine is running |
307 | ; machine is running |
318 | ; They will be enabled by IRET. |
308 | ; They will be enabled by IRET. |
319 | ; sti |
309 | ; sti |
Line 320... | Line 310... | ||
320 | 310 | ||
321 | mov eax, esi |
311 | mov eax, esi |
322 | sub esp, v86_regs.size |
312 | sub esp, sizeof.v86_regs |
323 | mov esi, ebx |
313 | mov esi, ebx |
324 | mov edi, esp |
314 | mov edi, esp |
325 | mov ecx, v86_regs.size/4 |
315 | mov ecx, sizeof.v86_regs/4 |
Line 326... | Line 316... | ||
326 | rep movsd |
316 | rep movsd |
327 | 317 | ||
328 | cmp edx, -1 |
318 | cmp edx, -1 |
Line 370... | Line 360... | ||
370 | cmp bl, 1 |
360 | cmp bl, 1 |
371 | jne @f |
361 | jne @f |
372 | xor eax, eax |
362 | xor eax, eax |
373 | mov dr6, eax |
363 | mov dr6, eax |
374 | @@: |
364 | @@: |
375 | mov eax, [esp+v86_regs.size+10h+18h] |
365 | mov eax, [esp+sizeof.v86_regs+10h+18h] |
376 | cmp word [esp+v86_regs.eip], ax |
366 | cmp word [esp+v86_regs.eip], ax |
377 | jnz @f |
367 | jnz @f |
378 | shr eax, 16 |
368 | shr eax, 16 |
379 | cmp word [esp+v86_regs.cs], ax |
369 | cmp word [esp+v86_regs.cs], ax |
380 | jz .done |
370 | jz .done |
Line 442... | Line 432... | ||
442 | push eax |
432 | push eax |
443 | movzx eax, word [esp+4+v86_regs.esp] |
433 | movzx eax, word [esp+4+v86_regs.esp] |
444 | sub eax, 6 |
434 | sub eax, 6 |
445 | add edx, eax |
435 | add edx, eax |
446 | mov eax, edx |
436 | mov eax, edx |
447 | mov esi, [esp+4+v86_regs.size+10h+4] |
437 | mov esi, [esp+4+sizeof.v86_regs+10h+4] |
448 | call v86_get_lin_addr |
438 | call v86_get_lin_addr |
449 | cmp eax, 0x1000 |
439 | cmp eax, 0x1000 |
450 | jae @f |
440 | jae @f |
451 | mov bl, 14 ; #PF exception |
441 | mov bl, 14 ; #PF exception |
452 | jmp .nogp |
442 | jmp .nogp |
Line 490... | Line 480... | ||
490 | movzx edx, word [esp+v86_regs.ss] |
480 | movzx edx, word [esp+v86_regs.ss] |
491 | shl edx, 4 |
481 | shl edx, 4 |
492 | movzx eax, word [esp+v86_regs.esp] |
482 | movzx eax, word [esp+v86_regs.esp] |
493 | add edx, eax |
483 | add edx, eax |
494 | mov eax, edx |
484 | mov eax, edx |
495 | mov esi, [esp+v86_regs.size+10h+4] |
485 | mov esi, [esp+sizeof.v86_regs+10h+4] |
496 | call v86_get_lin_addr |
486 | call v86_get_lin_addr |
497 | cmp eax, 0x1000 |
487 | cmp eax, 0x1000 |
498 | jae @f |
488 | jae @f |
499 | mov bl, 14 |
489 | mov bl, 14 |
500 | jmp .nogp |
490 | jmp .nogp |
Line 526... | Line 516... | ||
526 | mov eax, [esp+v86_regs.esp] |
516 | mov eax, [esp+v86_regs.esp] |
527 | sub eax, 2 |
517 | sub eax, 2 |
528 | movzx eax, ax |
518 | movzx eax, ax |
529 | add edx, eax |
519 | add edx, eax |
530 | mov eax, edx |
520 | mov eax, edx |
531 | mov esi, [esp+v86_regs.size+10h+4] |
521 | mov esi, [esp+sizeof.v86_regs+10h+4] |
532 | call v86_get_lin_addr |
522 | call v86_get_lin_addr |
533 | cmp eax, 0x1000 |
523 | cmp eax, 0x1000 |
534 | jae @f |
524 | jae @f |
535 | mov bl, 14 ; #PF exception |
525 | mov bl, 14 ; #PF exception |
536 | jmp .nogp |
526 | jmp .nogp |
Line 558... | Line 548... | ||
558 | shl edx, 4 |
548 | shl edx, 4 |
559 | movzx eax, word [esp+v86_regs.esp] |
549 | movzx eax, word [esp+v86_regs.esp] |
560 | sub eax, 4 |
550 | sub eax, 4 |
561 | add edx, eax |
551 | add edx, eax |
562 | mov eax, edx |
552 | mov eax, edx |
563 | mov esi, [esp+v86_regs.size+10h+4] |
553 | mov esi, [esp+sizeof.v86_regs+10h+4] |
564 | call v86_get_lin_addr |
554 | call v86_get_lin_addr |
565 | cmp eax, 0x1000 |
555 | cmp eax, 0x1000 |
566 | jae @f |
556 | jae @f |
567 | mov bl, 14 ; #PF exception |
557 | mov bl, 14 ; #PF exception |
568 | jmp .nogp |
558 | jmp .nogp |
Line 589... | Line 579... | ||
589 | movzx edx, word [esp+v86_regs.ss] |
579 | movzx edx, word [esp+v86_regs.ss] |
590 | shl edx, 4 |
580 | shl edx, 4 |
591 | movzx eax, word [esp+v86_regs.esp] |
581 | movzx eax, word [esp+v86_regs.esp] |
592 | add edx, eax |
582 | add edx, eax |
593 | mov eax, edx |
583 | mov eax, edx |
594 | mov esi, [esp+v86_regs.size+10h+4] |
584 | mov esi, [esp+sizeof.v86_regs+10h+4] |
595 | call v86_get_lin_addr |
585 | call v86_get_lin_addr |
596 | cmp eax, 0x1000 |
586 | cmp eax, 0x1000 |
597 | jae @f |
587 | jae @f |
598 | mov bl, 14 ; #PF exception |
588 | mov bl, 14 ; #PF exception |
599 | jmp .nogp |
589 | jmp .nogp |
Line 620... | Line 610... | ||
620 | movzx edx, word [esp+v86_regs.ss] |
610 | movzx edx, word [esp+v86_regs.ss] |
621 | shl edx, 4 |
611 | shl edx, 4 |
622 | movzx eax, word [esp+v86_regs.esp] |
612 | movzx eax, word [esp+v86_regs.esp] |
623 | add edx, eax |
613 | add edx, eax |
624 | mov eax, edx |
614 | mov eax, edx |
625 | mov esi, [esp+v86_regs.size+10h+4] |
615 | mov esi, [esp+sizeof.v86_regs+10h+4] |
626 | call v86_get_lin_addr |
616 | call v86_get_lin_addr |
627 | cmp eax, 0x1000 |
617 | cmp eax, 0x1000 |
628 | jae @f |
618 | jae @f |
629 | mov bl, 14 |
619 | mov bl, 14 |
630 | jmp .nogp |
620 | jmp .nogp |
Line 746... | Line 736... | ||
746 | mov ecx, 8 |
736 | mov ecx, 8 |
747 | movzx edx, word [esp+32+4] |
737 | movzx edx, word [esp+32+4] |
748 | shl edx, 4 |
738 | shl edx, 4 |
749 | add edx, [esp+32] |
739 | add edx, [esp+32] |
750 | @@: |
740 | @@: |
751 | mov esi, [esp+v86_regs.size+10h+4] |
741 | mov esi, [esp+sizeof.v86_regs+10h+4] |
752 | mov eax, edx |
742 | mov eax, edx |
753 | call v86_get_lin_addr |
743 | call v86_get_lin_addr |
754 | cmp eax, 0x1000 |
744 | cmp eax, 0x1000 |
755 | jb .nopage |
745 | jb .nopage |
756 | mov esi, v86_exc_str3-2 |
746 | mov esi, v86_exc_str3-2 |
Line 771... | Line 761... | ||
771 | 761 | ||
772 | .done: |
762 | .done: |
Line 773... | Line 763... | ||
773 | xor eax, eax |
763 | xor eax, eax |
774 | 764 | ||
775 | .exit: |
765 | .exit: |
Line 776... | Line 766... | ||
776 | mov [esp+v86_regs.size+10h+1Ch], eax |
766 | mov [esp+sizeof.v86_regs+10h+1Ch], eax |
777 | mov [esp+v86_regs.size+10h+18h], ebx |
767 | mov [esp+sizeof.v86_regs+10h+18h], ebx |
778 | 768 | ||
779 | mov edx, [esp+v86_regs.size+10h+14h] |
769 | mov edx, [esp+sizeof.v86_regs+10h+14h] |
780 | cmp edx, -1 |
770 | cmp edx, -1 |
781 | jz @f |
771 | jz @f |
782 | dec [v86_irqhooks+edx*8+4] |
772 | dec [v86_irqhooks+edx*8+4] |
Line 783... | Line 773... | ||
783 | jnz @f |
773 | jnz @f |
784 | and [v86_irqhooks+edx*8], 0 |
774 | and [v86_irqhooks+edx*8], 0 |
785 | @@: |
775 | @@: |
786 | 776 | ||
787 | mov esi, esp |
777 | mov esi, esp |
788 | mov edi, [esi+v86_regs.size+10h+10h] |
778 | mov edi, [esi+sizeof.v86_regs+10h+10h] |
Line 789... | Line 779... | ||
789 | add edi, v86_regs.size |
779 | add edi, sizeof.v86_regs |
790 | mov ecx, v86_regs.size/4 |
780 | mov ecx, sizeof.v86_regs/4 |
Line 872... | Line 862... | ||
872 | .scan: |
862 | .scan: |
873 | cmp [ebx+APPDATA.dir_table], eax |
863 | cmp [ebx+APPDATA.dir_table], eax |
874 | jnz .cont |
864 | jnz .cont |
875 | push ecx |
865 | push ecx |
876 | mov ecx, [ebx+APPDATA.saved_esp0] |
866 | mov ecx, [ebx+APPDATA.saved_esp0] |
877 | cmp word [ecx-v86_regs.size+v86_regs.esp], 6 |
867 | cmp word [ecx-sizeof.v86_regs+v86_regs.esp], 6 |
878 | jb .cont2 |
868 | jb .cont2 |
879 | movzx edx, word [ecx-v86_regs.size+v86_regs.ss] |
869 | movzx edx, word [ecx-sizeof.v86_regs+v86_regs.ss] |
880 | shl edx, 4 |
870 | shl edx, 4 |
881 | push eax |
871 | push eax |
882 | movzx eax, word [ecx-v86_regs.size+v86_regs.esp] |
872 | movzx eax, word [ecx-sizeof.v86_regs+v86_regs.esp] |
883 | sub eax, 6 |
873 | sub eax, 6 |
884 | add edx, eax |
874 | add edx, eax |
885 | mov eax, edx |
875 | mov eax, edx |
886 | call v86_get_lin_addr |
876 | call v86_get_lin_addr |
887 | cmp eax, 0x1000 |
877 | cmp eax, 0x1000 |
Line 903... | Line 893... | ||
903 | call irq_eoi |
893 | call irq_eoi |
904 | popad |
894 | popad |
905 | iretd |
895 | iretd |
906 | .found: |
896 | .found: |
907 | mov cr3, eax |
897 | mov cr3, eax |
908 | sub word [esi-v86_regs.size+v86_regs.esp], 6 |
898 | sub word [esi-sizeof.v86_regs+v86_regs.esp], 6 |
909 | mov ecx, [esi-v86_regs.size+v86_regs.eip] |
899 | mov ecx, [esi-sizeof.v86_regs+v86_regs.eip] |
910 | mov word [edx], cx |
900 | mov word [edx], cx |
911 | mov ecx, [esi-v86_regs.size+v86_regs.cs] |
901 | mov ecx, [esi-sizeof.v86_regs+v86_regs.cs] |
912 | mov word [edx+2], cx |
902 | mov word [edx+2], cx |
913 | mov ecx, [esi-v86_regs.size+v86_regs.eflags] |
903 | mov ecx, [esi-sizeof.v86_regs+v86_regs.eflags] |
914 | mov word [edx+4], cx |
904 | mov word [edx+4], cx |
915 | lea eax, [edi+8] |
905 | lea eax, [edi+8] |
916 | cmp al, 10h |
906 | cmp al, 10h |
917 | jb @f |
907 | jb @f |
918 | add al, 60h |
908 | add al, 60h |
919 | @@: |
909 | @@: |
920 | mov cx, [eax*4] |
910 | mov cx, [eax*4] |
921 | mov word [esi-v86_regs.size+v86_regs.eip], cx |
911 | mov word [esi-sizeof.v86_regs+v86_regs.eip], cx |
922 | mov cx, [eax*4+2] |
912 | mov cx, [eax*4+2] |
923 | mov word [esi-v86_regs.size+v86_regs.cs], cx |
913 | mov word [esi-sizeof.v86_regs+v86_regs.cs], cx |
924 | and byte [esi-v86_regs.size+v86_regs.eflags+1], not 3 |
914 | and byte [esi-sizeof.v86_regs+v86_regs.eflags+1], not 3 |
925 | call update_counters |
915 | call update_counters |
926 | lea edi, [ebx + 0x100000000 - SLOT_BASE] |
916 | lea edi, [ebx + 0x100000000 - SLOT_BASE] |
927 | shr edi, 3 |
917 | shr edi, 3 |
928 | add edi, TASK_DATA |
918 | add edi, TASK_DATA |
929 | call find_next_task.found |
919 | call find_next_task.found |