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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
|
{
}
// this is generally go32 unit from go32v2 target.
// maybe these units should be merged into one ( uses dpmi ? )
// not yet finished
unit watcom;
{$S-,R-,I-,Q-} {no stack check, used by DPMIEXCP !! }
interface
const
{ contants for the run modes returned by get_run_mode }
rm_unknown = 0;
rm_raw = 1; { raw (without HIMEM) }
rm_xms = 2; { XMS (for example with HIMEM, without EMM386) }
rm_vcpi = 3; { VCPI (for example HIMEM and EMM386) }
rm_dpmi = 4; { DPMI (for example DOS box or 386Max) }
{ flags }
carryflag = $001;
parityflag = $004;
auxcarryflag = $010;
zeroflag = $040;
signflag = $080;
trapflag = $100;
interruptflag = $200;
directionflag = $400;
overflowflag = $800;
type
tmeminfo = record
available_memory,
available_pages,
available_lockable_pages,
linear_space,
unlocked_pages,
available_physical_pages,
total_physical_pages,
free_linear_space,
max_pages_in_paging_file,
reserved0,
reserved1,
reserved2 : longint;
end;
tseginfo = record
offset : pointer;
segment : word;
end;
trealregs = record
case integer of
1: { 32-bit } (EDI, ESI, EBP, Res, EBX, EDX, ECX, EAX: longint;
Flags, ES, DS, FS, GS, IP, CS, SP, SS: word);
2: { 16-bit } (DI, DI2, SI, SI2, BP, BP2, R1, R2: word;
BX, BX2, DX, DX2, CX, CX2, AX, AX2: word);
3: { 8-bit } (stuff: array[1..4] of longint;
BL, BH, BL2, BH2, DL, DH, DL2, DH2,
CL, CH, CL2, CH2, AL, AH, AL2, AH2: byte);
4: { Compat } (RealEDI, RealESI, RealEBP, RealRES,
RealEBX, RealEDX, RealECX, RealEAX: longint;
RealFlags,
RealES, RealDS, RealFS, RealGS,
RealIP, RealCS, RealSP, RealSS: word);
end;
registers = trealregs;
{ this works only with real DPMI }
function allocate_ldt_descriptors(count : word) : word;
function free_ldt_descriptor(d : word) : boolean;
function segment_to_descriptor(seg : word) : word;
function get_next_selector_increment_value : word;
function get_segment_base_address(d : word) : longint;
function set_segment_base_address(d : word;s : longint) : boolean;
function set_segment_limit(d : word;s : longint) : boolean;
function set_descriptor_access_right(d : word;w : word) : longint;
function create_code_segment_alias_descriptor(seg : word) : word;
function get_linear_addr(phys_addr : longint;size : longint) : longint;
function get_segment_limit(d : word) : longint;
function get_descriptor_access_right(d : word) : longint;
function get_page_size:longint;
function map_device_in_memory_block(handle,offset,pagecount,device:longint):boolean;
function realintr(intnr : word;var regs : trealregs) : boolean;
{ is needed for functions which need a real mode buffer }
function global_dos_alloc(bytes : longint) : longint;
function global_dos_free(selector : word) : boolean;
var
{ selector for the DOS memory (only usable if in DPMI mode) }
dosmemselector : word;
{ result of dpmi call }
int31error : word;
{ this procedure copies data where the source and destination }
{ are specified by 48 bit pointers }
{ Note: the procedure checks only for overlapping if }
{ source selector=destination selector }
procedure seg_move(sseg : word;source : longint;dseg : word;dest : longint;count : longint);
{ fills a memory area specified by a 48 bit pointer with c }
procedure seg_fillchar(seg : word;ofs : longint;count : longint;c : char);
procedure seg_fillword(seg : word;ofs : longint;count : longint;w : word);
{************************************}
{ this works with all PM interfaces: }
{************************************}
function get_meminfo(var meminfo : tmeminfo) : boolean;
function get_pm_interrupt(vector : byte;var intaddr : tseginfo) : boolean;
function set_pm_interrupt(vector : byte;const intaddr : tseginfo) : boolean;
function get_rm_interrupt(vector : byte;var intaddr : tseginfo) : boolean;
function set_rm_interrupt(vector : byte;const intaddr : tseginfo) : boolean;
function get_exception_handler(e : byte;var intaddr : tseginfo) : boolean;
function set_exception_handler(e : byte;const intaddr : tseginfo) : boolean;
function get_pm_exception_handler(e : byte;var intaddr : tseginfo) : boolean;
function set_pm_exception_handler(e : byte;const intaddr : tseginfo) : boolean;
function free_rm_callback(var intaddr : tseginfo) : boolean;
function get_rm_callback(pm_func : pointer;const reg : trealregs;var rmcb : tseginfo) : boolean;
function get_cs : word;
function get_ds : word;
function get_ss : word;
{ locking functions }
function allocate_memory_block(size:longint):longint;
function free_memory_block(blockhandle : longint) : boolean;
function request_linear_region(linearaddr, size : longint;
var blockhandle : longint) : boolean;
function lock_linear_region(linearaddr, size : longint) : boolean;
function lock_data(var data;size : longint) : boolean;
function lock_code(functionaddr : pointer;size : longint) : boolean;
function unlock_linear_region(linearaddr, size : longint) : boolean;
function unlock_data(var data;size : longint) : boolean;
function unlock_code(functionaddr : pointer;size : longint) : boolean;
{ disables and enables interrupts }
procedure disable;
procedure enable;
function inportb(port : word) : byte;
function inportw(port : word) : word;
function inportl(port : word) : longint;
procedure outportb(port : word;data : byte);
procedure outportw(port : word;data : word);
procedure outportl(port : word;data : longint);
function get_run_mode : word;
procedure copytodos(var addr; len : longint);
procedure copyfromdos(var addr; len : longint);
procedure dpmi_dosmemput(seg : word;ofs : word;var data;count : longint);
procedure dpmi_dosmemget(seg : word;ofs : word;var data;count : longint);
procedure dpmi_dosmemmove(sseg,sofs,dseg,dofs : word;count : longint);
procedure dpmi_dosmemfillchar(seg,ofs : word;count : longint;c : char);
procedure dpmi_dosmemfillword(seg,ofs : word;count : longint;w : word);
const
{ this procedures are assigned to the procedure which are needed }
{ for the current mode to access DOS memory }
{ It's strongly recommended to use this procedures! }
dosmemput : procedure(seg : word;ofs : word;var data;count : longint)=@dpmi_dosmemput;
dosmemget : procedure(seg : word;ofs : word;var data;count : longint)=@dpmi_dosmemget;
dosmemmove : procedure(sseg,sofs,dseg,dofs : word;count : longint)=@dpmi_dosmemmove;
dosmemfillchar : procedure(seg,ofs : word;count : longint;c : char)=@dpmi_dosmemfillchar;
dosmemfillword : procedure(seg,ofs : word;count : longint;w : word)=@dpmi_dosmemfillword;
implementation
{$asmmode ATT}
{ the following procedures copy from and to DOS memory using DPMI }
procedure dpmi_dosmemput(seg : word;ofs : word;var data;count : longint);
begin
seg_move(get_ds,longint(@data),dosmemselector,seg*16+ofs,count);
end;
procedure dpmi_dosmemget(seg : word;ofs : word;var data;count : longint);
begin
seg_move(dosmemselector,seg*16+ofs,get_ds,longint(@data),count);
end;
procedure dpmi_dosmemmove(sseg,sofs,dseg,dofs : word;count : longint);
begin
seg_move(dosmemselector,sseg*16+sofs,dosmemselector,dseg*16+dofs,count);
end;
procedure dpmi_dosmemfillchar(seg,ofs : word;count : longint;c : char);
begin
seg_fillchar(dosmemselector,seg*16+ofs,count,c);
end;
procedure dpmi_dosmemfillword(seg,ofs : word;count : longint;w : word);
begin
seg_fillword(dosmemselector,seg*16+ofs,count,w);
end;
procedure test_int31(flag : longint); stdcall; { flag is pushed on stack }
begin
asm
pushl %ebx
movw $0,INT31ERROR
movl flag,%ebx
testb $1,%bl
jz .Lti31_1
movw %ax,INT31ERROR
xorl %eax,%eax
jmp .Lti31_2
.Lti31_1:
movl $1,%eax
.Lti31_2:
popl %ebx
end;
end;
function global_dos_alloc(bytes : longint) : longint;
begin
asm
pushl %ebx
movl bytes,%ebx
addl $0xf,%ebx // round up
shrl $0x4,%ebx // convert to Paragraphs
movl $0x100,%eax // function 0x100
int $0x31
jnc .LDos_OK
movw %ax,INT31ERROR
xorl %eax,%eax
jmp .LDos_end
.LDos_OK:
shll $0x10,%eax // return Segment in hi(Result)
movw %dx,%ax // return Selector in lo(Result)
.LDos_end:
movl %eax,__result
popl %ebx
end;
end;
function global_dos_free(selector : word) : boolean;
begin
asm
movw Selector,%dx
movl $0x101,%eax
int $0x31
setnc %al
movb %al,__RESULT
end;
end;
function realintr(intnr : word;var regs : trealregs) : boolean;
begin
regs.realsp:=0;
regs.realss:=0;
asm
pushl %ebx
pushl %edi
{ save all used registers to avoid crash under NTVDM }
{ when spawning a 32-bit DPMI application }
pushw %fs
movw intnr,%bx
xorl %ecx,%ecx
movl regs,%edi
{ es is always equal ds }
movl $0x300,%eax
int $0x31
popw %fs
setnc %al
movb %al,__RESULT
popl %edi
popl %ebx
end;
end;
procedure seg_fillchar(seg : word;ofs : longint;count : longint;c : char);
begin
asm
pushl %edi
movl ofs,%edi
movl count,%ecx
movb c,%dl
{ load es with selector }
pushw %es
movw seg,%ax
movw %ax,%es
{ fill eax with duplicated c }
{ so we can use stosl }
movb %dl,%dh
movw %dx,%ax
shll $16,%eax
movw %dx,%ax
movl %ecx,%edx
shrl $2,%ecx
cld
rep
stosl
movl %edx,%ecx
andl $3,%ecx
rep
stosb
popw %es
popl %edi
end;
end;
procedure seg_fillword(seg : word;ofs : longint;count : longint;w : word);
begin
asm
pushl %edi
movl ofs,%edi
movl count,%ecx
movw w,%dx
{ load segment }
pushw %es
movw seg,%ax
movw %ax,%es
{ fill eax }
movw %dx,%ax
shll $16,%eax
movw %dx,%ax
movl %ecx,%edx
shrl $1,%ecx
cld
rep
stosl
movl %edx,%ecx
andl $1,%ecx
rep
stosw
popw %es
popl %edi
end;
end;
procedure seg_move(sseg : word;source : longint;dseg : word;dest : longint;count : longint);
begin
if count=0 then
exit;
if (sseg<>dseg) or ((sseg=dseg) and (source>dest)) then
asm
pushl %edi
pushl %esi
pushw %es
pushw %ds
cld
movl count,%ecx
movl source,%esi
movl dest,%edi
movw dseg,%ax
movw %ax,%es
movw sseg,%ax
movw %ax,%ds
movl %ecx,%eax
shrl $2,%ecx
rep
movsl
movl %eax,%ecx
andl $3,%ecx
rep
movsb
popw %ds
popw %es
popl %esi
popl %edi
end
else if (source<dest) then
{ copy backward for overlapping }
asm
pushl %edi
pushl %esi
pushw %es
pushw %ds
std
movl count,%ecx
movl source,%esi
movl dest,%edi
movw dseg,%ax
movw %ax,%es
movw sseg,%ax
movw %ax,%ds
addl %ecx,%esi
addl %ecx,%edi
movl %ecx,%eax
andl $3,%ecx
orl %ecx,%ecx
jz .LSEG_MOVE1
{ calculate esi and edi}
decl %esi
decl %edi
rep
movsb
incl %esi
incl %edi
.LSEG_MOVE1:
subl $4,%esi
subl $4,%edi
movl %eax,%ecx
shrl $2,%ecx
rep
movsl
cld
popw %ds
popw %es
popl %esi
popl %edi
end;
end;
procedure outportb(port : word;data : byte);
begin
asm
movw port,%dx
movb data,%al
outb %al,%dx
end ['EAX','EDX'];
end;
procedure outportw(port : word;data : word);
begin
asm
movw port,%dx
movw data,%ax
outw %ax,%dx
end ['EAX','EDX'];
end;
procedure outportl(port : word;data : longint);
begin
asm
movw port,%dx
movl data,%eax
outl %eax,%dx
end ['EAX','EDX'];
end;
function inportb(port : word) : byte;
begin
asm
movw port,%dx
inb %dx,%al
movb %al,__RESULT
end ['EAX','EDX'];
end;
function inportw(port : word) : word;
begin
asm
movw port,%dx
inw %dx,%ax
movw %ax,__RESULT
end ['EAX','EDX'];
end;
function inportl(port : word) : longint;
begin
asm
movw port,%dx
inl %dx,%eax
movl %eax,__RESULT
end ['EAX','EDX'];
end;
function get_cs : word;assembler;
asm
movw %cs,%ax
end;
function get_ss : word;assembler;
asm
movw %ss,%ax
end;
function get_ds : word;assembler;
asm
movw %ds,%ax
end;
function set_pm_interrupt(vector : byte;const intaddr : tseginfo) : boolean;
begin
asm
pushl %ebx
movl intaddr,%eax
movl (%eax),%edx
movw 4(%eax),%cx
movl $0x205,%eax
movb vector,%bl
int $0x31
pushf
call test_int31
movb %al,__RESULT
popl %ebx
end;
end;
function set_rm_interrupt(vector : byte;const intaddr : tseginfo) : boolean;
begin
asm
pushl %ebx
movl intaddr,%eax
movw (%eax),%dx
movw 4(%eax),%cx
movl $0x201,%eax
movb vector,%bl
int $0x31
pushf
call test_int31
movb %al,__RESULT
popl %ebx
end;
end;
function set_pm_exception_handler(e : byte;const intaddr : tseginfo) : boolean;
begin
asm
pushl %ebx
movl intaddr,%eax
movl (%eax),%edx
movw 4(%eax),%cx
movl $0x212,%eax
movb e,%bl
int $0x31
pushf
call test_int31
movb %al,__RESULT
popl %ebx
end;
end;
function set_exception_handler(e : byte;const intaddr : tseginfo) : boolean;
begin
asm
pushl %ebx
movl intaddr,%eax
movl (%eax),%edx
movw 4(%eax),%cx
movl $0x203,%eax
movb e,%bl
int $0x31
pushf
call test_int31
movb %al,__RESULT
popl %ebx
end;
end;
function get_pm_exception_handler(e : byte;var intaddr : tseginfo) : boolean;
begin
asm
pushl %ebx
movl $0x210,%eax
movb e,%bl
int $0x31
pushf
call test_int31
movb %al,__RESULT
movl intaddr,%eax
movl %edx,(%eax)
movw %cx,4(%eax)
popl %ebx
end;
end;
function get_exception_handler(e : byte;var intaddr : tseginfo) : boolean;
begin
asm
pushl %ebx
movl $0x202,%eax
movb e,%bl
int $0x31
pushf
call test_int31
movb %al,__RESULT
movl intaddr,%eax
movl %edx,(%eax)
movw %cx,4(%eax)
popl %ebx
end;
end;
function get_pm_interrupt(vector : byte;var intaddr : tseginfo) : boolean;
begin
asm
pushl %ebx
movb vector,%bl
movl $0x204,%eax
int $0x31
pushf
call test_int31
movb %al,__RESULT
movl intaddr,%eax
movl %edx,(%eax)
movw %cx,4(%eax)
popl %ebx
end;
end;
function get_rm_interrupt(vector : byte;var intaddr : tseginfo) : boolean;
begin
asm
pushl %ebx
movb vector,%bl
movl $0x200,%eax
int $0x31
pushf
call test_int31
movb %al,__RESULT
movl intaddr,%eax
movzwl %dx,%edx
movl %edx,(%eax)
movw %cx,4(%eax)
popl %ebx
end;
end;
function free_rm_callback(var intaddr : tseginfo) : boolean;
begin
asm
movl intaddr,%eax
movw (%eax),%dx
movw 4(%eax),%cx
movl $0x304,%eax
int $0x31
pushf
call test_int31
movb %al,__RESULT
end;
end;
{ here we must use ___v2prt0_ds_alias instead of from v2prt0.s
because the exception processor sets the ds limit to $fff
at hardware exceptions }
//!!!! var
//!!!! ___v2prt0_ds_alias : word; external name '___v2prt0_ds_alias';
var ___v2prt0_ds_alias : word;
function get_rm_callback(pm_func : pointer;const reg : trealregs;var rmcb : tseginfo) : boolean;
begin
asm
pushl %esi
pushl %edi
movl pm_func,%esi
movl reg,%edi
pushw %es
movw ___v2prt0_ds_alias,%ax
movw %ax,%es
pushw %ds
movw %cs,%ax
movw %ax,%ds
movl $0x303,%eax
int $0x31
popw %ds
popw %es
pushf
call test_int31
movb %al,__RESULT
movl rmcb,%eax
movzwl %dx,%edx
movl %edx,(%eax)
movw %cx,4(%eax)
popl %edi
popl %esi
end;
end;
function allocate_ldt_descriptors(count : word) : word;
begin
asm
movw count,%cx
xorl %eax,%eax
int $0x31
movw %ax,__RESULT
end;
end;
function free_ldt_descriptor(d : word) : boolean;
begin
asm
pushl %ebx
movw d,%bx
movl $1,%eax
int $0x31
pushf
call test_int31
movb %al,__RESULT
popl %ebx
end;
end;
function segment_to_descriptor(seg : word) : word;
begin
asm
pushl %ebx
movw seg,%bx
movl $2,%eax
int $0x31
movw %ax,__RESULT
popl %ebx
end;
end;
function get_next_selector_increment_value : word;
begin
asm
movl $3,%eax
int $0x31
movw %ax,__RESULT
end;
end;
function get_segment_base_address(d : word) : longint;
begin
asm
pushl %ebx
movw d,%bx
movl $6,%eax
int $0x31
xorl %eax,%eax
movw %dx,%ax
shll $16,%ecx
orl %ecx,%eax
movl %eax,__RESULT
popl %ebx
end;
end;
function get_page_size:longint;
begin
asm
pushl %ebx
movl $0x604,%eax
int $0x31
shll $16,%ebx
movw %cx,%bx
movl %ebx,__RESULT
popl %ebx
end;
end;
function request_linear_region(linearaddr, size : longint;
var blockhandle : longint) : boolean;
var
pageofs : longint;
begin
pageofs:=linearaddr and $3ff;
linearaddr:=linearaddr-pageofs;
size:=size+pageofs;
asm
pushl %esi
pushl %ebx
movl $0x504,%eax
movl linearaddr,%ebx
movl size,%ecx
movl $1,%edx
xorl %esi,%esi
int $0x31
pushf
call test_int31
movb %al,__RESULT
movl blockhandle,%eax
movl %esi,(%eax)
movl %ebx,pageofs
popl %ebx
popl %esi
end;
if pageofs<>linearaddr then
request_linear_region:=false;
end;
function allocate_memory_block(size:longint):longint;
begin
asm
pushl %esi
pushl %edi
pushl %ebx
movl $0x501,%eax
movl size,%ecx
movl %ecx,%ebx
shrl $16,%ebx
andl $65535,%ecx
int $0x31
jnc .Lallocate_mem_block_err
xorl %ebx,%ebx
xorl %ecx,%ecx
.Lallocate_mem_block_err:
shll $16,%ebx
movw %cx,%bx
shll $16,%esi
movw %di,%si
movl %ebx,__RESULT
popl %ebx
popl %edi
popl %esi
end;
end;
function free_memory_block(blockhandle : longint) : boolean;
begin
asm
pushl %esi
pushl %edi
movl blockhandle,%esi
movl %esi,%edi
shll $16,%esi
movl $0x502,%eax
int $0x31
pushf
call test_int31
movb %al,__RESULT
popl %edi
popl %esi
end;
end;
function lock_linear_region(linearaddr, size : longint) : boolean;
begin
asm
pushl %esi
pushl %edi
pushl %ebx
movl $0x600,%eax
movl linearaddr,%ecx
movl %ecx,%ebx
shrl $16,%ebx
movl size,%esi
movl %esi,%edi
shrl $16,%esi
int $0x31
pushf
call test_int31
movb %al,__RESULT
popl %ebx
popl %edi
popl %esi
end;
end;
function lock_data(var data;size : longint) : boolean;
var
linearaddr : longint;
begin
if get_run_mode<>rm_dpmi then
exit;
linearaddr:=longint(@data)+get_segment_base_address(get_ds);
lock_data:=lock_linear_region(linearaddr,size);
end;
function lock_code(functionaddr : pointer;size : longint) : boolean;
var
linearaddr : longint;
begin
if get_run_mode<>rm_dpmi then
exit;
linearaddr:=longint(functionaddr)+get_segment_base_address(get_cs);
lock_code:=lock_linear_region(linearaddr,size);
end;
function unlock_linear_region(linearaddr,size : longint) : boolean;
begin
asm
pushl %esi
pushl %edi
pushl %ebx
movl $0x601,%eax
movl linearaddr,%ecx
movl %ecx,%ebx
shrl $16,%ebx
movl size,%esi
movl %esi,%edi
shrl $16,%esi
int $0x31
pushf
call test_int31
movb %al,__RESULT
popl %ebx
popl %edi
popl %esi
end;
end;
function unlock_data(var data;size : longint) : boolean;
var
linearaddr : longint;
begin
if get_run_mode<>rm_dpmi then
exit;
linearaddr:=longint(@data)+get_segment_base_address(get_ds);
unlock_data:=unlock_linear_region(linearaddr,size);
end;
function unlock_code(functionaddr : pointer;size : longint) : boolean;
var
linearaddr : longint;
begin
if get_run_mode<>rm_dpmi then
exit;
linearaddr:=longint(functionaddr)+get_segment_base_address(get_cs);
unlock_code:=unlock_linear_region(linearaddr,size);
end;
function set_segment_base_address(d : word;s : longint) : boolean;
begin
asm
pushl %ebx
movw d,%bx
leal s,%eax
movw (%eax),%dx
movw 2(%eax),%cx
movl $7,%eax
int $0x31
pushf
call test_int31
movb %al,__RESULT
popl %ebx
end;
end;
function set_descriptor_access_right(d : word;w : word) : longint;
begin
asm
pushl %ebx
movw d,%bx
movw w,%cx
movl $9,%eax
int $0x31
pushf
call test_int31
movw %ax,__RESULT
popl %ebx
end;
end;
function set_segment_limit(d : word;s : longint) : boolean;
begin
asm
pushl %ebx
movw d,%bx
leal s,%eax
movw (%eax),%dx
movw 2(%eax),%cx
movl $8,%eax
int $0x31
pushf
call test_int31
movb %al,__RESULT
popl %ebx
end;
end;
function get_descriptor_access_right(d : word) : longint;
begin
asm
movzwl d,%eax
lar %eax,%eax
jz .L_ok
xorl %eax,%eax
.L_ok:
movl %eax,__RESULT
end;
end;
function get_segment_limit(d : word) : longint;
begin
asm
movzwl d,%eax
lsl %eax,%eax
jz .L_ok2
xorl %eax,%eax
.L_ok2:
movl %eax,__RESULT
end;
end;
function create_code_segment_alias_descriptor(seg : word) : word;
begin
asm
pushl %ebx
movw seg,%bx
movl $0xa,%eax
int $0x31
pushf
call test_int31
movw %ax,__RESULT
popl %ebx
end;
end;
function get_meminfo(var meminfo : tmeminfo) : boolean;
begin
asm
pushl %edi
movl meminfo,%edi
movl $0x500,%eax
int $0x31
pushf
movb %al,__RESULT
call test_int31
popl %edi
end;
end;
function get_linear_addr(phys_addr : longint;size : longint) : longint;
begin
asm
pushl %esi
pushl %edi
pushl %ebx
movl phys_addr,%ebx
movl %ebx,%ecx
shrl $16,%ebx
movl size,%esi
movl %esi,%edi
shrl $16,%esi
movl $0x800,%eax
int $0x31
pushf
call test_int31
shll $16,%ebx
movw %cx,%bx
movl %ebx,__RESULT
popl %ebx
popl %edi
popl %esi
end;
end;
procedure disable;assembler;
asm
cli
end;
procedure enable;assembler;
asm
sti
end;
// var
// _run_mode : word;external name '_run_mode';
function get_run_mode : word;
begin
// get_run_mode:=_run_mode; !!!!!!!!!!
get_run_mode:=rm_unknown;
end;
function map_device_in_memory_block(handle,offset,pagecount,device:longint):boolean;
begin
asm
pushl %esi
pushl %edi
pushl %ebx
movl device,%edx
movl handle,%esi
movl offset,%ebx
movl pagecount,%ecx
movl $0x0508,%eax
int $0x31
pushf
setnc %al
movb %al,__RESULT
call test_int31
popl %ebx
popl %edi
popl %esi
end;
end;
{*****************************************************************************
Transfer Buffer
*****************************************************************************}
procedure copytodos(var addr; len : longint);
begin
if len>tb_size then
runerror(217);
seg_move(get_ds,longint(@addr),dosmemselector,tb,len);
end;
procedure copyfromdos(var addr; len : longint);
begin
if len>tb_size then
runerror(217);
seg_move(dosmemselector,tb,get_ds,longint(@addr),len);
end;
begin
int31error:=0;
dosmemselector:=get_ds;
end.
|