-
Notifications
You must be signed in to change notification settings - Fork 2
/
386c.bas
6995 lines (6859 loc) · 372 KB
/
386c.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Sub exec386(ByVal cycs As Integer)
Dim As ULongInt temp64=Any
'Dim As LongInt temp64i
Dim As UByte temp=Any,temp2=any
Dim As UShort tempw=any,tempw2=any,tempw3=any,tempw4=Any
Dim As Byte offset =Any
Dim As Byte temps=Any
Dim As Short temps16=Any ' SOLO se usa en "IDIV AX,w", y solo una vez.
Dim As long tempws=any,tempws2=Any
Dim As ULong templ=any,templ2=any,templ3=any,addr=Any
Dim As Integer c=any,cycdiff=Any
Dim As Integer oldcyc=Any
Dim As integer tempi=Any
Dim As integer trap =any
cycles+=cycs
while (cycles>0)
cycdiff=0
oldcyc=cycles
While (cycdiff<100)
oldcs=CS1
oldpc=pc
oldcpl=CPL
op32=use32
' GOTO
opcodestart:
fetchdat=fastreadl(cs0+pc)
If abrt Then GoTo opcodeend ' se va hasta el final
tempc=flags And C_FLAG
trap =flags And T_FLAG
' instruccion principal
opcode=fetchdat And &hFF
' segunda instruccion
fetchdat=(fetchdat shr 8) 'And &hffff
''if (deb=4) Then
' If ((opcode<>&hF2 And opcode<>&hF3) Or (firstrepcycle>0)) Then
' If ( skipnextprint=0) Then
' Print #1,Hex(CS1,4);"(";hex(cs0,6);"):";hex(pc,4);" : ";hex(EAX,8);" ";hex(EBX,8);" ";hex(ECX,8);" ";hex(EDX,8);" ";hex(CS1,4);" ";hex(DS1,4);" ";hex(ES1,4);"(";Hex(es0,8);") ";
' Print #1,Hex(FS1,4);" ";hex(GS1,4);" ";hex(SS1,4);"(";hex(ss0,8);") ";hex(EDI,8);" ";hex(ESI,8);" ";hex(EBP,8);" SP=";hex(SS1,4);":";hex(ESP,8);" ";Hex(opcode,2);" ";hex(flags,4);'" ";
' Print #1,ins;" ";hex(writelookup2,8);" ";hex(ldt.base0,8);CPL;stack32;" ";hex(pic.pend,2);" ";hex(pic.mask,2);" ";hex(pic.mask2,2);" ";hex(pic2.pend,2);" ";hex(pic2.mask,2);" ";hex(readmode,2)
' EndIf
' skipnextprint=0
' EndIf
'EndIf
'If EAX=&H001FA000 And EBX=&H0000A8FE And ECX=&H00004000 And EDX=&H00000000 Then deb=2'Print #5,"hola":sleep
' depuracion
printdebug()
pc+=1
inhlt=0
Select Case As Const ((opcode Or op32) And &h3FF)
Case &h00, &h100, &h200, &h300 /'ADD 8,reg'/
fetchea32() : if abrt Then exit Select
if modo=3 Then
temp = getr8(rm)
temp2 = getr8(reg)
setadd8(temp, temp2)
setr8(rm, temp + temp2)
cycles -= timing_rr
else
temp = geteab(): if abrt Then exit Select
temp2 = getr8(reg)
seteab(temp + temp2): if abrt then exit Select
setadd8(temp, temp2)
cycles -= timing_mr
EndIf
Exit Select
case &h01, &h201 /'ADD 16,reg'/
fetchea32() : if abrt Then exit Select
if modo=3 Then
setadd16(regs(rm).w, regs(reg).w)
regs(rm).w += regs(reg).w
cycles -= timing_rr
else
tempw = geteaw(): if abrt Then exit Select
seteaw(tempw + regs(reg).w): if abrt then exit Select
setadd16(tempw, regs(reg).w)
cycles -= timing_mr
EndIf
Exit Select
case &h101, &h301 /'ADD 32,reg'/
fetchea32() : if abrt Then exit Select
if modo=3 Then
setadd32(regs(rm).l, regs(reg).l)
regs(rm).l += regs(reg).l
cycles -= timing_rr
else
templ = geteal(): if abrt Then exit Select
seteal(templ + regs(reg).l): if abrt then exit Select
setadd32(templ, regs(reg).l)
cycles -= timing_mrl
EndIf
Exit Select
case &h02, &h102, &h202, &h302 /'ADD reg,8'/
fetchea32() : if abrt Then exit Select
temp=geteab(): if abrt Then exit Select
setadd8(getr8(reg),temp)
setr8(reg,getr8(reg)+temp)
cycles -= IIf((modo = 3) , timing_rr , timing_rm)
Exit Select
case &h03, &h203 /'ADD reg,16'/
fetchea32() : if abrt Then exit Select
tempw=geteaw(): if abrt Then exit Select
setadd16(regs(reg).w,tempw)
regs(reg).w+=tempw
cycles -= IIf((modo = 3) , timing_rr , timing_rm)
Exit Select
case &h103, &h303 /'ADD reg,32'/
fetchea32() : if abrt Then exit Select
templ=geteal(): if abrt Then exit Select
setadd32(regs(reg).l,templ)
regs(reg).l+=templ
cycles -= IIf((modo = 3) , timing_rr , timing_rml)
Exit Select
case &h04, &h104, &h204, &h304 /'ADD AL,#8'/
temp=getbytef()
setadd8(AL,temp)
AL+=temp
cycles -= timing_rr
Exit Select
case &h05, &h205 /'ADD AX,#16'/
tempw=getwordf()
setadd16(AX,tempw)
AX+=tempw
cycles -= timing_rr
Exit Select
case &h105, &h305 /'ADD EAX,#32'/
templ=getlong(): if abrt then exit Select
setadd32(EAX,templ)
EAX+=templ
cycles -= timing_rr
Exit Select
'''''''''''''''''''''''''''
case &h06, &h206 /'PUSH ES'/
if ssegs Then ss0=oldss
if stack32 Then
writememw_386(ss0,ESP-2,ES1): if abrt Then exit Select
ESP-=2
else
writememw_386(ss0,((SP-2) And &hFFFF),ES1): if abrt then exit Select
SP-=2
EndIf
cycles-=2
Exit Select
case &h106, &h306 /'PUSH ES'/
if ssegs Then ss0=oldss
if stack32 Then
writememl_386(ss0,ESP-4,ES1): if abrt Then exit Select
ESP-=4
else
writememl_386(ss0,((SP-4) And &hFFFF),ES1): if abrt then exit Select
SP-=4
EndIf
cycles-=2
Exit Select
case &h07, &h207 /'POP ES'/
if ssegs Then ss0=oldss
if stack32 Then
tempw=readmemw_386(ss0,ESP): if abrt Then exit Select
loadseg(tempw, _es): if abrt then exit Select
ESP+=2
else
tempw=readmemw_386(ss0,SP): if abrt Then exit Select
loadseg(tempw, _es): if abrt then exit Select
SP+=2
EndIf
cycles-=3
Exit Select
case &h107, &h307 /'POP ES'/
if ssegs Then ss0=oldss
if stack32 Then
tempw=readmeml_386(ss0,ESP) And &hFFFF: if abrt then exit Select
loadseg(tempw, _es): if abrt then exit Select
ESP+=4
else
tempw=readmemw_386(ss0,SP): if abrt Then exit Select
loadseg(tempw, _es): if abrt then exit Select
SP+=4
EndIf
cycles-=3
Exit Select
'''''''''''''''''''''''
case &h08, &h108, &h208, &h308 /'OR 8,reg'/
fetchea32() : if abrt Then exit Select
if modo=3 Then
temp = getr8(rm) Or getr8(reg)
setr8(rm, temp)
setznp8(temp)
cycles -= timing_rr
else
temp = geteab(): if abrt Then exit Select
temp2 = getr8(reg)
seteab(temp Or temp2): if abrt Then exit Select
setznp8(temp Or temp2)
cycles -= timing_mr
EndIf
Exit Select
case &h09, &h209 /'OR 16,reg'/
fetchea32() : if abrt Then exit Select
if modo=3 Then
regs(rm).w =regs(rm).w or regs(reg).w
setznp16(regs(rm).w)
cycles -= timing_rr
else
tempw = geteaw() Or regs(reg).w: if abrt then exit Select
seteaw(tempw): if abrt Then exit Select
setznp16(tempw)
cycles -= timing_mr
EndIf
Exit Select
case &h109, &h309 /'OR 32,reg'/
fetchea32() : if abrt Then exit Select
if modo=3 Then
regs(rm).l = regs(rm).l Or regs(reg).l
setznp32(regs(rm).l)
cycles -= timing_rr
else
templ = geteal() Or regs(reg).l: if abrt then exit Select
seteal(templ): if abrt Then exit Select
setznp32(templ)
cycles -= timing_mrl
EndIf
Exit Select
case &h0A, &h10A, &h20A, &h30A /'OR reg,8'/
fetchea32() : if abrt Then exit Select
temp=geteab(): if abrt Then exit Select
temp = temp Or getr8(reg)
setznp8(temp)
setr8(reg,temp)
cycles -= iif((modo = 3) , timing_rr , timing_rm )
Exit Select
case &h0B, &h20B /'OR reg,16'/
fetchea32() : if abrt Then exit Select
tempw=geteaw(): if abrt Then exit Select
tempw = tempw Or regs(reg).w
setznp16(tempw)
regs(reg).w=tempw
cycles -= IIf((modo = 3 ) , timing_rr , timing_rm )
Exit Select
case &h10B, &h30B /'OR reg,32'/
fetchea32() : if abrt Then exit Select
templ=geteal(): if abrt Then exit Select
templ = templ Or regs(reg).l
setznp32(templ)
regs(reg).l=templ
cycles -= iif((modo = 3) , timing_rr , timing_rml)
Exit Select
case &h0C, &h10C, &h20C, &h30C /'OR AL,#8'/
AL = AL Or getbytef()
setznp8(AL)
cycles -= timing_rr
Exit Select
case &h0D, &h20D /'OR AX,#16'/
AX = AX Or getwordf()
setznp16(AX)
cycles -= timing_rr
Exit Select
Case &h10D, &h30D /'OR AX,#32'/
templ=getlong(): if abrt then exit Select
EAX = EAX Or templ
setznp32(EAX)
cycles -= timing_rr
Exit Select
case &h0E, &h20E /'PUSH CS'/
if ssegs Then ss0=oldss
if stack32 Then
writememw_386(ss0,ESP-2,CS1): if abrt Then exit Select
ESP-=2
else
writememw_386(ss0,((SP-2) And &hFFFF),CS1): if abrt Then exit Select
SP-=2
EndIf
cycles-=2
Exit Select
case &h10E, &h30E /'PUSH CS'/
if ssegs Then ss0=oldss
if stack32 Then
writememl_386(ss0,ESP-4,CS1): if abrt Then exit Select
ESP-=4
else
writememl_386(ss0,((SP-4) And &hFFFF),CS1): if abrt Then exit select
SP-=4
EndIf
cycles-=2
Exit Select
case &h0F, &h20F
temp=fetchdat And &hFF: pc+=1
opcode2=temp
Select Case As Const (temp)
Case 0
if ((cr0 And 1)=0) Or (eflags And VM_FLAG) Then goto inv16
fetchea2() : if abrt then exit Select
Select Case As Const (rmdat And &h38)
Case &h00 /'SLDT'/
if NOTRM() then exit Select
seteaw(ldt.seg)
cycles-=4
Exit Select
case &h08 /'STR'/
if NOTRM() then exit Select
seteaw(tr.seg)
cycles-=4
Exit Select
case &h10 /'LLDT'/
if ((CPL<>0) Or ((eflags And VM_FLAG)<>0)) And ((cr0 And 1)<>0) Then
'if deb=3 then print #5,"Invalid LLDT"
x86gpf(0)
Exit Select
EndIf
if NOTRM() then exit Select
ldt.seg=geteaw()
templ=(ldt.seg And inv(7))+gdt.base0
templ3=readmemw_386(0,templ)+((readmemb_386(0,templ+6) And &hF) Shl 16)
templ2=(readmemw_386(0,templ+2)) Or (readmemb_386(0,templ+4) Shl 16) Or (readmemb_386(0,templ+7) Shl 24)
if abrt Then exit Select
ldt.limit=templ3
ldt.access0=readmemb_386(0,templ+6)
if (readmemb_386(0,templ+6) And &h80) Then
ldt.limit = ldt.limit Shl 12
ldt.limit = ldt.limit Or &hFFF
EndIf
ldt.base0=templ2
cycles-=20
Exit Select
case &h18 /'LTR'/
if ((CPL<>0) Or ((eflags And VM_FLAG)<>0)) And ((cr0 And 1)<>0) Then
'if deb=3 then print #5,"Invalid LTR"
x86gpf(0)
Exit Select
EndIf
if NOTRM() then exit Select
tr.seg=geteaw()
templ=(tr.seg And inv(7))+gdt.base0
templ3=readmemw_386(0,templ)+((readmemb_386(0,templ+6) And &hF) Shl 16)
templ2=(readmemw_386(0,templ+2)) Or (readmemb_386(0,templ+4) Shl 16) Or (readmemb_386(0,templ+7) Shl 24)
temp=readmemb_386(0,templ+5)
if abrt Then exit Select
tr.limit=templ3
tr.access0=readmemb_386(0,templ+6)
if (readmemb_386(0,templ+6) And &h80) Then
tr.limit = tr.limit Shl 12
tr.limit = tr.limit Or &hFFF
EndIf
tr.base0=templ2
tr.access0=temp
cycles-=20
Exit Select
case &h20 /'VERR'/
if NOTRM() then exit Select
tempw=geteaw(): if abrt then exit Select
flags = flags And inv(Z_FLAG)
if (tempw And &hFFFC)=0 then exit Select: /'NULO selector'/
cpl_override=1
tempi=(tempw And inv(7))<IIf((tempw And 4),ldt.limit,gdt.limit)
tempw2=readmemw_386(0,iif((tempw And 4),ldt.base0,gdt.base0)+(tempw And inv(7))+4)
cpl_override=0
if abrt Then exit Select
if (tempw2 And &h1000)=0 Then tempi=0
if (tempw2 And &hC00)<>&hC00 Then
/'Exclude conforming code segments'/
tempw3=(tempw2 Shr 13) And 3: /'Check permissions'/
if (tempw3<CPL) Or (tempw3<(tempw And 3)) Then tempi=0
EndIf
if (tempw2 And &h0800) And ((tempw2 And &h0200)=0) Then tempi=0: /'Non-readable code'/
if (tempi) Then flags = flags Or Z_FLAG
cycles-=20
Exit Select
case &h28 /'VERW'/
if NOTRM() then exit Select
tempw=geteaw(): if abrt then exit Select
flags = flags And inv(Z_FLAG)
if (tempw And &hFFFC)=0 then exit Select: /'NULO selector'/
cpl_override=1
tempi=(tempw And inv(7))<IIf((tempw And 4),ldt.limit,gdt.limit)
tempw2=readmemw_386(0,iif((tempw And 4),ldt.base0,gdt.base0)+(tempw And inv(7))+4)
cpl_override=0
if abrt Then exit Select
if (tempw2 And &h1000)=0 Then tempi=0
tempw3=(tempw2 Shr 13) And 3: /'Check permissions'/
if (tempw3<CPL) Or (tempw3<(tempw And 3)) Then tempi=0
if (tempw2 And &h0800) Then tempi=0 /'Code'/
If (tempw2 And &h0200)=0 Then tempi=0 /'Read-only data'/
if (tempi) Then flags = flags Or Z_FLAG
cycles-=20
Exit Select
case Else
'if deb=3 then print #5,"Bad 0F 00 opcode ",hex(rmdat and &h38,2)
pc-=3
x86illegal()
Exit Select
End Select
Exit Select
case 1
fetchea2() : if abrt then exit Select
Select Case As Const (rmdat And &h38)
case &h00 /'SGDT'/
seteaw(gdt.limit)
writememw_386(easeg,eaaddr+2,gdt.base0)
writememw_386(easeg,eaaddr+4,(gdt.base0 Shr 16) And &hFF)
cycles-=7: ''less seteaw time
Exit Select
case &h08 /'SIDT'/
seteaw(idt.limit)
writememw_386(easeg,eaaddr+2,idt.base0)
writememw_386(easeg,eaaddr+4,(idt.base0 Shr 16) And &hFF)
cycles-=7
Exit Select
case &h10 /'LGDT'/
if ((CPL<>0) Or ((eflags And VM_FLAG)<>0)) And ((cr0 and 1)<>0) Then
'if deb=3 then print #5,"Invalid LGDT"
x86gpf(0)
Exit Select
EndIf
tempw=geteaw()
templ=readmeml_386(0,easeg+eaaddr+2) And &hFFFFFF
if abrt Then exit Select
gdt.limit=tempw
gdt.base0=templ
cycles-=11
Exit Select
case &h18 /'LIDT'/
if ((CPL<>0) Or ((eflags And VM_FLAG)<>0)) And ((cr0 and 1)<>0) Then
'if deb=3 then print #5,"Invalid LIDT"
x86gpf(0)
Exit Select
EndIf
tempw=geteaw()
templ=readmeml_386(0,easeg+eaaddr+2) And &hFFFFFF
if abrt Then exit Select
idt.limit=tempw
idt.base0=templ
cycles-=11
Exit Select
case &h20 /'SMSW'/
seteaw(msw)
cycles-=2
Exit Select
case &h30 /'LMSW'/
if ((CPL<>0) Or ((eflags And VM_FLAG)<>0)) And (modoprotegido=1) Then
'if deb=3 then print #5,"LMSW - ring not zero"
x86gpf(0)
Exit Select
EndIf
tempw=geteaw(): if abrt then exit Select
if modoprotegido Then tempw = tempw Or 1
msw=tempw
Exit Select
case Else
'if deb=3 then print #5,"Bad 0F 01 opcode ",hex(rmdat and &h38,2)
pc-=3
x86illegal()
Exit Select
End Select
Exit Select
case 2 /'LAR'/
if NOTRM() then exit Select
fetchea2() : if abrt then exit Select
tempw=geteaw(): if abrt then exit Select
if ((tempw And &hFFFC)=0) Then
flags = flags And inv(Z_FLAG): Exit Select
EndIf /'NULO selector'/
tempi=(tempw And inv(7))<IIf((tempw And 4),ldt.limit,gdt.limit)
if (tempi) Then
cpl_override=1
tempw2=readmemw_386(0,IIf((tempw And 4),ldt.base0,gdt.base0)+(tempw And inv(7))+4)
cpl_override=0
if abrt Then exit Select
EndIf
flags = flags And inv(Z_FLAG)
if ((tempw2 And &h1F00)=&h000) Then tempi=0
if ((tempw2 And &h1F00)=&h800) Then tempi=0
if ((tempw2 And &h1F00)=&hA00) Then tempi=0
if ((tempw2 And &h1F00)=&hD00) Then tempi=0
if ((tempw2 And &h1C00)<&h1C00) Then
/'Exclude conforming code segments'/
tempw3=(tempw2 Shr 13) And 3
if (tempw3<CPL) Or (tempw3<(tempw And 3)) Then tempi=0
EndIf
if (tempi) Then
flags = flags Or Z_FLAG
cpl_override=1
regs(reg).w=readmemb_386(0,IIf((tempw And 4),ldt.base0,gdt.base0)+(tempw And inv(7))+5) Shl 8
cpl_override=0
EndIf
cycles-=11
Exit Select
case 3 /'LSL'/
if NOTRM() then exit Select
fetchea2() : if abrt then exit Select
tempw=geteaw(): if abrt then exit Select
flags = flags And inv(Z_FLAG)
if ((tempw And &hFFFC)=0) then exit Select: /'NULO selector'/
tempi=(tempw And inv(7))<IIf((tempw And 4),ldt.limit,gdt.limit)
cpl_override=1
if (tempi) Then
tempw2=readmemw_386(0,iif((tempw And 4),ldt.base0,gdt.base0)+(tempw And inv(7))+4)
EndIf
cpl_override=0
if abrt Then exit Select
if ((tempw2 And &h1400)=&h400) Then tempi=0 /'Interrupt or trap or call gate'/
if ((tempw2 And &h1F00)=&h000) Then tempi=0 /'Invalid'/
if ((tempw2 And &h1F00)=&hA00) Then tempi=0 /'Invalid'/
if ((tempw2 And &h1C00)<>&h1C00) Then
/'Exclude conforming code segments'/
tempw3=(tempw2 Shr 13) And 3
if (tempw3<CPL) Or (tempw3<(tempw And 3)) Then tempi=0
EndIf
if (tempi) Then
flags = flags Or Z_FLAG
cpl_override=1
regs(reg).w=readmemw_386(0,iif((tempw And 4),ldt.base0,gdt.base0)+(tempw And inv(7)))
cpl_override=0
EndIf
cycles-=10
Exit Select
case 5 /'LOADALL'/
flags=(readmemw_386(0,&h818) And &hFFD5) Or 2
'
pc=readmemw_386(0,&h81A)
'
DS1=readmemw_386(0,&h81E)
SS1=readmemw_386(0,&h820)
CS1=readmemw_386(0,&h822)
ES1=readmemw_386(0,&h824)
'
DI=readmemw_386(0,&h826)
SI=readmemw_386(0,&h828)
BP=readmemw_386(0,&h82A)
SP=readmemw_386(0,&h82C)
BX=readmemw_386(0,&h82E)
DX=readmemw_386(0,&h830)
CX=readmemw_386(0,&h832)
AX=readmemw_386(0,&h834)
'
es0=readmemw_386(0,&h836) Or (readmemb_386(0,&h838) Shl 16)
cs0=readmemw_386(0,&h83C) Or (readmemb_386(0,&h83E) Shl 16)
ss0=readmemw_386(0,&h842) Or (readmemb_386(0,&h844) Shl 16)
ds0=readmemw_386(0,&h848) Or (readmemb_386(0,&h84A) Shl 16)
'
cycles-=195
Exit Select
case 6 /'CLTS'/
if ((CPL<>0) Or ((eflags And VM_FLAG)<>0)) And ((cr0 and 1)<>0) Then
'if deb=3 then print #5,"Can't CLTS"
x86gpf(0)
Exit Select
EndIf
cr0 = cr0 And inv(8)
cycles-=5
Exit Select
case 8 /'INVD'/
'if ( is486=0) Then goto inv16
cycles-=1000
Exit Select
case 9 /'WBINVD'/
'if (is486=0) Then goto inv16
cycles-=10000
Exit Select
case &h20 /'MOV reg32,CRx'/
if ((CPL<>0) Or ((eflags And VM_FLAG)<>0)) And ((cr0 and 1)<>0) Then
'if deb=3 then print #5,"Can't load from CRx"
x86gpf(0)
Exit Select
EndIf
fetchea2() : if abrt then exit Select
Select Case As Const (reg)
Case 0
regs(rm).l=cr0
regs(rm).l = regs(rm).l Or &h10 /'ET hardwired on 486'/
Exit Select
Case 2
regs(rm).l=cr2
Exit Select
Case 3
regs(rm).l=cr3
Exit Select
case Else
'if deb=3 then print #5,"Bad read of CR ",rmdat And 7,reg
pc=oldpc
x86illegal()
Exit Select
End Select
cycles-=6
Exit Select
case &h21 /'MOV reg32,DRx'/
if ((CPL<>0) Or ((eflags And VM_FLAG)<>0)) And ((cr0 and 1)<>0) Then
'if deb=3 then print #5,"Can't load from DRx"
x86gpf(0)
Exit Select
EndIf
fetchea2() : if abrt then exit Select
regs(rm).l=0
cycles-=6
Exit Select
case &h22 /'MOV CRx,reg32'/
if ((CPL<>0) Or ((eflags And VM_FLAG)<>0)) And ((cr0 and 1)<>0) Then
'if deb=3 then print #5,"Can't load CRx"
x86gpf(0)
Exit Select
EndIf
fetchea2() : if abrt then Exit Select
Select Case As Const (reg)
case 0 ' EAX
if ((regs(rm).l Xor cr0) And &h80000001) Then flushmmucache()
cr0=regs(rm).l:''&~2;
'if (cpu_16bitbus) Then cr0 = cr0 Or &h10
if (cr0 And &h80000000)=0 Then
mmu_perm=4
EndIf
Exit Select
case 2 ' ECX
cr2=regs(rm).l
Exit Select
case 3 ' EDX
cr3=regs(rm).l And inv(&hFFF)
flushmmucache()
Exit Select
case Else
'if deb=3 then print #5,"Bad load CR ",reg
pc=oldpc
x86illegal()
Exit Select
End Select
cycles-=10
Exit Select
case &h23 /'MOV DRx,reg32'/
if ((CPL<>0) Or ((eflags And VM_FLAG)<>0)) And ((cr0 and 1)<>0) Then
'if deb=3 then print #5,"Can't load DRx"
x86gpf(0)
Exit Select
EndIf
fetchea2() : if abrt then exit Select
cycles-=6
Exit Select
case &h24 /'MOV reg32,TRx'/
if ((CPL<>0) Or ((eflags And VM_FLAG)<>0)) And ((cr0 and 1)<>0) Then
'if deb=3 then print #5,"Can't load from TRx"
x86gpf(0)
Exit Select
EndIf
fetchea2() : if abrt then exit Select
regs(rm).l=0
cycles-=6
Exit Select
case &h26 /'MOV TRx,reg32'/
if ((CPL<>0) Or ((eflags And VM_FLAG)<>0)) And ((cr0 and 1)<>0) Then
'if deb=3 then print #5,"Can't load TRx"
x86gpf(0)
Exit Select
EndIf
fetchea2() : if abrt then exit Select
cycles-=6
Exit Select
case &h32
x86illegal()
Exit Select
case &h80 /'JO'/
tempw=getword2f()
if (flags And V_FLAG) Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h81 /'JNO'/
tempw=getword2f()
if (flags And V_FLAG)=0 Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h82 /'JB'/
tempw=getword2f()
if (flags And C_FLAG) Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h83 /'JNB'/
tempw=getword2f()
if (flags And C_FLAG)=0 Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h84 /'JE'/
tempw=getword2f()
if (flags And Z_FLAG) Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h85 /'JNE'/
tempw=getword2f()
if (flags And Z_FLAG)=0 Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h86 /'JBE'/
tempw=getword2f()
if (flags And (C_FLAG Or Z_FLAG)) Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h87 /'JNBE'/
tempw=getword2f()
if (flags And (C_FLAG Or Z_FLAG))=0 Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h88 /'JS'/
tempw=getword2f()
if (flags And N_FLAG) Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h89 /'JNS'/
tempw=getword2f()
if (flags And N_FLAG)=0 Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h8A /'JP'/
tempw=getword2f()
if (flags And P_FLAG) Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h8B /'JNP'/
tempw=getword2f()
if (flags And P_FLAG)=0 Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h8C /'JL'/
tempw=getword2f()
temp=IIf((flags And N_FLAG),1,0)
temp2=IIf((flags And V_FLAG),1,0 )
if (temp<>temp2) Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h8D /'JNL'/
tempw=getword2f()
temp=IIf((flags And N_FLAG),1,0)
temp2=IIf((flags And V_FLAG),1,0 )
if (temp=temp2) Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h8E /'JLE'/
tempw=getword2f()
temp=IIf((flags And N_FLAG),1,0 )
temp2=IIf((flags And V_FLAG),1,0 )
if ((flags And Z_FLAG)<>0) Or (temp<>temp2) Then
pc+=CShort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h8F /'JNLE'/
tempw=getword2f()
temp=IIf((flags And N_FLAG),1,0 )
temp2=IIf((flags And V_FLAG),1,0 )
if ( ((flags And Z_FLAG)<>0) Or (temp<>temp2) )=0 Then
pc+=cshort(tempw): cycles-=timing_bt
EndIf
cycles -= timing_bnt
Exit Select
case &h90 /'SETO'/
fetchea2() : if abrt then exit Select
seteab(IIf((flags And V_FLAG),1,0) )
cycles-=4
Exit Select
case &h91 /'SETNO'/
fetchea2() : if abrt then exit Select
seteab(IIf((flags And V_FLAG),0,1) )
cycles-=4
Exit Select
case &h92 /'SETC'/
fetchea2() : if abrt then exit Select
seteab(IIf((flags And C_FLAG),1,0))
cycles-=4
Exit Select
case &h93 /'SETAE'/
fetchea2() : if abrt then exit Select
seteab(IIf((flags And C_FLAG),0,1) )
cycles-=4
Exit Select
case &h94 /'SETZ'/
fetchea2() : if abrt then exit Select
seteab(IIf((flags And Z_FLAG),1,0))
cycles-=4
Exit Select
case &h95 /'SETNZ'/
fetchea2() : if abrt then exit Select
seteab(IIf((flags And Z_FLAG),0,1))
cycles-=4
Exit Select
case &h96 /'SETBE'/
fetchea2() : if abrt then exit Select
seteab(IIf((flags And (C_FLAG Or Z_FLAG)),1,0))
cycles-=4
Exit Select
case &h97 /'SETNBE'/
fetchea2() : if abrt then exit Select
seteab(IIf((flags And (C_FLAG Or Z_FLAG)),0,1))
cycles-=4
Exit Select
case &h98 /'SETS'/
fetchea2() : if abrt then exit Select
seteab(IIf((flags And N_FLAG),1,0))
cycles-=4
Exit Select
case &h99 /'SETNS'/
fetchea2() : if abrt then exit Select
seteab(IIf((flags And N_FLAG),0,1))
cycles-=4
Exit Select
case &h9A /'SETP'/
fetchea2() : if abrt then exit Select
seteab(IIf((flags And P_FLAG),1,0))
cycles-=4
Exit Select
case &h9B /'SETNP'/
fetchea2() : if abrt then exit Select
seteab(IIf((flags And P_FLAG),0,1))
cycles-=4
Exit Select
case &h9C /'SETL'/
fetchea2() : if abrt then exit Select
temp=IIf((flags And N_FLAG),1,0)
temp2=IIf((flags And V_FLAG),1,0)
seteab(temp Xor temp2)
cycles-=4
Exit Select
case &h9D /'SETGE'/
fetchea2() : if abrt then exit Select
temp=IIf((flags And N_FLAG),1,0)
temp2=IIf((flags And V_FLAG),1,0)
seteab(IIf((temp Xor temp2),0,1))
cycles-=4
Exit Select
case &h9E /'SETLE'/
fetchea2() : if abrt then exit Select
temp=IIf((flags And N_FLAG),1,0 )
temp2=IIf((flags And V_FLAG),1,0 )
seteab(IIf(((temp Xor temp2) Or (flags And Z_FLAG)),1,0))
cycles-=4
Exit Select
case &h9F /'SETNLE'/
fetchea2() : if abrt then exit Select
temp=IIf((flags And N_FLAG),1,0 )
temp2=IIf((flags And V_FLAG),1,0)
seteab(IIf(((temp Xor temp2) Or (flags And Z_FLAG)),0,1))
cycles-=4
Exit Select
case &hA0 /'PUSH FS'/
if ssegs Then ss0=oldss
if stack32 Then
writememw_386(ss0,ESP-2,FS1): if abrt then exit Select
ESP-=2
else
writememw_386(ss0,((SP-2) And &hFFFF),FS1): if abrt then exit Select
SP-=2
EndIf
cycles-=2
Exit Select
case &hA1 /'POP FS'/
if ssegs Then ss0=oldss
if stack32 Then
tempw=readmemw_386(ss0,ESP): if abrt Then exit Select
loadseg(tempw, _fs): if abrt then exit Select
ESP+=2
else
tempw=readmemw_386(ss0,SP): if abrt Then exit Select
loadseg(tempw, _fs): if abrt then exit Select
SP+=2
EndIf
cycles-=3
Exit Select
case &hA3 /'BT r16'/
fetchea2() : if abrt then exit Select
eaaddr+=((regs(reg).w \ 16)*2): eal_r = 0
tempw=geteaw(): if abrt then exit Select
if ((tempw And (1 Shl (regs(reg).w And 15)))) Then
flags = flags Or C_FLAG
else
flags = flags And inv(C_FLAG)
EndIf
cycles-=3
Exit Select
case &hA4 /'SHLD imm'/
fetchea2() : if abrt then exit Select
temp=readmemb_386(cs0,pc) And 31: pc+=1
if (temp) Then
tempw=geteaw(): if abrt then exit Select
tempc=IIf(((tempw Shl (temp-1)) And &h8000),1,0)
templ=(tempw Shl 16) Or regs(reg).w
if (temp<=16) Then
tempw=templ Shr (16-temp)
else
tempw=(templ Shl temp) Shr 16
EndIf
seteaw(tempw): if abrt then exit Select
setznp16(tempw)
if tempc Then flags = flags Or C_FLAG
EndIf
cycles-=3
Exit Select
case &hA5 /'SHLD CL'/
fetchea2() : if abrt then exit Select
temp=CL And 31
if (temp) Then
tempw=geteaw(): if abrt then exit Select
tempc=IIf(((tempw Shl (temp-1)) And &h8000),1,0)
templ=(tempw Shl 16) Or regs(reg).w
if (temp<=16) Then
tempw=templ Shr (16-temp)
else
tempw=(templ Shl temp) Shr 16
EndIf
seteaw(tempw): if abrt then exit Select
setznp16(tempw)
if tempc Then flags = flags Or C_FLAG
EndIf
cycles-=3
Exit Select
case &hA8 /'PUSH GS'/
if ssegs Then ss0=oldss
if stack32 Then
writememw_386(ss0,ESP-2,GS1): if abrt then exit Select
ESP-=2
else
writememw_386(ss0,((SP-2) And &hFFFF),GS1): if abrt then exit Select
SP-=2
EndIf
cycles-=2
Exit Select
case &hA9 /'POP GS'/
if ssegs Then ss0=oldss
if stack32 Then
tempw=readmemw_386(ss0,ESP): if abrt Then exit Select
loadseg(tempw, _gs): if abrt then exit Select
ESP+=2
else
tempw=readmemw_386(ss0,SP): if abrt Then exit Select
loadseg(tempw, _gs): if abrt then exit Select
SP+=2
EndIf
cycles-=3
Exit Select
case &hAB /'BTS r16'/
fetchea2() : if abrt then exit Select
eaaddr+=((regs(reg).w \ 16)*2)
eal_r = 0
eal_w = 0
tempw=geteaw(): if abrt then exit Select
tempc=IIf((tempw And (1 Shl (regs(reg).w And 15))),1,0)
tempw = tempw Or (1 Shl (regs(reg).w And 15))
seteaw(tempw): if abrt then exit Select
if tempc Then
flags = flags Or C_FLAG
else
flags = flags And inv(C_FLAG)
EndIf
cycles-=6
Exit Select
case &hAC /'SHRD imm'/
fetchea2() : if abrt then exit Select
temp=readmemb_386(cs0,pc) And 31: pc+=1
if (temp) Then
tempw=geteaw(): if abrt then exit Select