Subversion Repositories Kolibri OS

Rev

Rev 2166 | Rev 2465 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2166 Rev 2434
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: 2166 $
8
$Revision: 2434 $
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 369... Line 359...
369
; Did we all that we have wanted to do?
359
; Did we all that we have wanted to do?
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
-
 
364
  @@:
374
  @@:   mov     eax, [esp+v86_regs.size+10h+18h]
365
        mov     eax, [esp+sizeof.v86_regs+10h+18h]
375
        cmp     word [esp+v86_regs.eip], ax
366
        cmp     word [esp+v86_regs.eip], ax
376
        jnz     @f
367
        jnz     @f
377
        shr     eax, 16
368
        shr     eax, 16
378
        cmp     word [esp+v86_regs.cs], ax
369
        cmp     word [esp+v86_regs.cs], ax
379
        jz      .done
370
        jz      .done
Line 441... Line 432...
441
        push    eax
432
        push    eax
442
        movzx   eax, word [esp+4+v86_regs.esp]
433
        movzx   eax, word [esp+4+v86_regs.esp]
443
        sub     eax, 6
434
        sub     eax, 6
444
        add     edx, eax
435
        add     edx, eax
445
        mov     eax, edx
436
        mov     eax, edx
446
        mov     esi, [esp+4+v86_regs.size+10h+4]
437
        mov     esi, [esp+4+sizeof.v86_regs+10h+4]
447
        call    v86_get_lin_addr
438
        call    v86_get_lin_addr
448
        cmp     eax, 0x1000
439
        cmp     eax, 0x1000
449
        jae     @f
440
        jae     @f
450
        mov     bl, 14          ; #PF exception
441
        mov     bl, 14          ; #PF exception
451
        jmp     .nogp
442
        jmp     .nogp
Line 489... Line 480...
489
        movzx   edx, word [esp+v86_regs.ss]
480
        movzx   edx, word [esp+v86_regs.ss]
490
        shl     edx, 4
481
        shl     edx, 4
491
        movzx   eax, word [esp+v86_regs.esp]
482
        movzx   eax, word [esp+v86_regs.esp]
492
        add     edx, eax
483
        add     edx, eax
493
        mov     eax, edx
484
        mov     eax, edx
494
        mov     esi, [esp+v86_regs.size+10h+4]
485
        mov     esi, [esp+sizeof.v86_regs+10h+4]
495
        call    v86_get_lin_addr
486
        call    v86_get_lin_addr
496
        cmp     eax, 0x1000
487
        cmp     eax, 0x1000
497
        jae     @f
488
        jae     @f
498
        mov     bl, 14
489
        mov     bl, 14
499
        jmp     .nogp
490
        jmp     .nogp
Line 525... Line 516...
525
        mov     eax, [esp+v86_regs.esp]
516
        mov     eax, [esp+v86_regs.esp]
526
        sub     eax, 2
517
        sub     eax, 2
527
        movzx   eax, ax
518
        movzx   eax, ax
528
        add     edx, eax
519
        add     edx, eax
529
        mov     eax, edx
520
        mov     eax, edx
530
        mov     esi, [esp+v86_regs.size+10h+4]
521
        mov     esi, [esp+sizeof.v86_regs+10h+4]
531
        call    v86_get_lin_addr
522
        call    v86_get_lin_addr
532
        cmp     eax, 0x1000
523
        cmp     eax, 0x1000
533
        jae     @f
524
        jae     @f
534
        mov     bl, 14          ; #PF exception
525
        mov     bl, 14          ; #PF exception
535
        jmp     .nogp
526
        jmp     .nogp
Line 557... Line 548...
557
        shl     edx, 4
548
        shl     edx, 4
558
        movzx   eax, word [esp+v86_regs.esp]
549
        movzx   eax, word [esp+v86_regs.esp]
559
        sub     eax, 4
550
        sub     eax, 4
560
        add     edx, eax
551
        add     edx, eax
561
        mov     eax, edx
552
        mov     eax, edx
562
        mov     esi, [esp+v86_regs.size+10h+4]
553
        mov     esi, [esp+sizeof.v86_regs+10h+4]
563
        call    v86_get_lin_addr
554
        call    v86_get_lin_addr
564
        cmp     eax, 0x1000
555
        cmp     eax, 0x1000
565
        jae     @f
556
        jae     @f
566
        mov     bl, 14          ; #PF exception
557
        mov     bl, 14          ; #PF exception
567
        jmp     .nogp
558
        jmp     .nogp
Line 588... Line 579...
588
        movzx   edx, word [esp+v86_regs.ss]
579
        movzx   edx, word [esp+v86_regs.ss]
589
        shl     edx, 4
580
        shl     edx, 4
590
        movzx   eax, word [esp+v86_regs.esp]
581
        movzx   eax, word [esp+v86_regs.esp]
591
        add     edx, eax
582
        add     edx, eax
592
        mov     eax, edx
583
        mov     eax, edx
593
        mov     esi, [esp+v86_regs.size+10h+4]
584
        mov     esi, [esp+sizeof.v86_regs+10h+4]
594
        call    v86_get_lin_addr
585
        call    v86_get_lin_addr
595
        cmp     eax, 0x1000
586
        cmp     eax, 0x1000
596
        jae     @f
587
        jae     @f
597
        mov     bl, 14          ; #PF exception
588
        mov     bl, 14          ; #PF exception
598
        jmp     .nogp
589
        jmp     .nogp
Line 619... Line 610...
619
        movzx   edx, word [esp+v86_regs.ss]
610
        movzx   edx, word [esp+v86_regs.ss]
620
        shl     edx, 4
611
        shl     edx, 4
621
        movzx   eax, word [esp+v86_regs.esp]
612
        movzx   eax, word [esp+v86_regs.esp]
622
        add     edx, eax
613
        add     edx, eax
623
        mov     eax, edx
614
        mov     eax, edx
624
        mov     esi, [esp+v86_regs.size+10h+4]
615
        mov     esi, [esp+sizeof.v86_regs+10h+4]
625
        call    v86_get_lin_addr
616
        call    v86_get_lin_addr
626
        cmp     eax, 0x1000
617
        cmp     eax, 0x1000
627
        jae     @f
618
        jae     @f
628
        mov     bl, 14
619
        mov     bl, 14
629
        jmp     .nogp
620
        jmp     .nogp
Line 745... Line 736...
745
        mov     ecx, 8
736
        mov     ecx, 8
746
        movzx   edx, word [esp+32+4]
737
        movzx   edx, word [esp+32+4]
747
        shl     edx, 4
738
        shl     edx, 4
748
        add     edx, [esp+32]
739
        add     edx, [esp+32]
749
@@:
740
@@:
750
        mov     esi, [esp+v86_regs.size+10h+4]
741
        mov     esi, [esp+sizeof.v86_regs+10h+4]
751
        mov     eax, edx
742
        mov     eax, edx
752
        call    v86_get_lin_addr
743
        call    v86_get_lin_addr
753
        cmp     eax, 0x1000
744
        cmp     eax, 0x1000
754
        jb      .nopage
745
        jb      .nopage
755
        mov     esi, v86_exc_str3-2
746
        mov     esi, v86_exc_str3-2
Line 770... Line 761...
770
 
761
 
771
.done:
762
.done:
Line 772... Line 763...
772
        xor     eax, eax
763
        xor     eax, eax
773
 
764
 
774
.exit:
765
.exit:
Line 775... Line 766...
775
        mov     [esp+v86_regs.size+10h+1Ch], eax
766
        mov     [esp+sizeof.v86_regs+10h+1Ch], eax
776
        mov     [esp+v86_regs.size+10h+18h], ebx
767
        mov     [esp+sizeof.v86_regs+10h+18h], ebx
777
 
768
 
778
        mov     edx, [esp+v86_regs.size+10h+14h]
769
        mov     edx, [esp+sizeof.v86_regs+10h+14h]
779
        cmp     edx, -1
770
        cmp     edx, -1
780
        jz      @f
771
        jz      @f
781
        dec     [v86_irqhooks+edx*8+4]
772
        dec     [v86_irqhooks+edx*8+4]
Line 782... Line 773...
782
        jnz     @f
773
        jnz     @f
783
        and     [v86_irqhooks+edx*8], 0
774
        and     [v86_irqhooks+edx*8], 0
784
@@:
775
@@:
785
 
776
 
786
        mov     esi, esp
777
        mov     esi, esp
787
        mov     edi, [esi+v86_regs.size+10h+10h]
778
        mov     edi, [esi+sizeof.v86_regs+10h+10h]
Line 788... Line 779...
788
        add     edi, v86_regs.size
779
        add     edi, sizeof.v86_regs
789
        mov     ecx, v86_regs.size/4
780
        mov     ecx, sizeof.v86_regs/4
Line 871... Line 862...
871
.scan:
862
.scan:
872
        cmp     [ebx+APPDATA.dir_table], eax
863
        cmp     [ebx+APPDATA.dir_table], eax
873
        jnz     .cont
864
        jnz     .cont
874
        push    ecx
865
        push    ecx
875
        mov     ecx, [ebx+APPDATA.saved_esp0]
866
        mov     ecx, [ebx+APPDATA.saved_esp0]
876
        cmp     word [ecx-v86_regs.size+v86_regs.esp], 6
867
        cmp     word [ecx-sizeof.v86_regs+v86_regs.esp], 6
877
        jb      .cont2
868
        jb      .cont2
878
        movzx   edx, word [ecx-v86_regs.size+v86_regs.ss]
869
        movzx   edx, word [ecx-sizeof.v86_regs+v86_regs.ss]
879
        shl     edx, 4
870
        shl     edx, 4
880
        push    eax
871
        push    eax
881
        movzx   eax, word [ecx-v86_regs.size+v86_regs.esp]
872
        movzx   eax, word [ecx-sizeof.v86_regs+v86_regs.esp]
882
        sub     eax, 6
873
        sub     eax, 6
883
        add     edx, eax
874
        add     edx, eax
884
        mov     eax, edx
875
        mov     eax, edx
885
        call    v86_get_lin_addr
876
        call    v86_get_lin_addr
886
        cmp     eax, 0x1000
877
        cmp     eax, 0x1000
Line 902... Line 893...
902
        call    irq_eoi
893
        call    irq_eoi
903
        popad
894
        popad
904
        iretd
895
        iretd
905
.found:
896
.found:
906
        mov     cr3, eax
897
        mov     cr3, eax
907
        sub     word [esi-v86_regs.size+v86_regs.esp], 6
898
        sub     word [esi-sizeof.v86_regs+v86_regs.esp], 6
908
        mov     ecx, [esi-v86_regs.size+v86_regs.eip]
899
        mov     ecx, [esi-sizeof.v86_regs+v86_regs.eip]
909
        mov     word [edx], cx
900
        mov     word [edx], cx
910
        mov     ecx, [esi-v86_regs.size+v86_regs.cs]
901
        mov     ecx, [esi-sizeof.v86_regs+v86_regs.cs]
911
        mov     word [edx+2], cx
902
        mov     word [edx+2], cx
912
        mov     ecx, [esi-v86_regs.size+v86_regs.eflags]
903
        mov     ecx, [esi-sizeof.v86_regs+v86_regs.eflags]
913
        mov     word [edx+4], cx
904
        mov     word [edx+4], cx
914
        lea     eax, [edi+8]
905
        lea     eax, [edi+8]
915
        cmp     al, 10h
906
        cmp     al, 10h
916
        jb      @f
907
        jb      @f
917
        add     al, 60h
908
        add     al, 60h
918
@@:
909
@@:
919
        mov     cx, [eax*4]
910
        mov     cx, [eax*4]
920
        mov     word [esi-v86_regs.size+v86_regs.eip], cx
911
        mov     word [esi-sizeof.v86_regs+v86_regs.eip], cx
921
        mov     cx, [eax*4+2]
912
        mov     cx, [eax*4+2]
922
        mov     word [esi-v86_regs.size+v86_regs.cs], cx
913
        mov     word [esi-sizeof.v86_regs+v86_regs.cs], cx
923
        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
924
        call    update_counters
915
        call    update_counters
925
        lea     edi, [ebx + 0x100000000 - SLOT_BASE]
916
        lea     edi, [ebx + 0x100000000 - SLOT_BASE]
926
        shr     edi, 3
917
        shr     edi, 3
927
        add     edi, TASK_DATA
918
        add     edi, TASK_DATA
928
        call    find_next_task.found
919
        call    find_next_task.found