wok-6.x view linld/stuff/src/MEMCPY32.ASM @ rev 23996

linld: add iso support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jan 08 20:15:35 2021 +0000 (2021-01-08)
parents 6e3d30b3031f
children 5c1ce90eb1d6
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 1000
6 %crefref
7 %noincl
8 %nomacs
9 ifdef NO386
10 p8086
11 else
12 p386
13 endif
15 group DGROUP _TEXT
16 assume cs:DGROUP,ds:DGROUP
18 macro lcr0 reg
19 mov cr0,reg
20 jmp short $+2 ;*Required*!
21 ;3+ NOPs also work fine (chkd on 386)
22 endm
24 segment _TEXT byte public use16 'CODE'
26 ;***************************************************************
27 ;void memcpy32(u32 dstofs,u16 srcseg,u32 srcofs,u32 size);
28 ;***************************************************************
29 ;****** Uses: Flags
30 ;***************************************************************
31 global memcpy32:near
32 proc memcpy32 near
34 arg dstofs :dword, \
35 srcseg :word, \
36 srcofs :dword, \
37 sz :dword = PARAM_SIZE
39 ;****** Init ***************************************************
41 ifndef NO386
43 enter 0,0
44 ;cld
45 pushf
46 push ds es
47 pushad ; struct declared in VCPI.ASM
48 mov cl,4
49 movzx esi,[srcseg]
50 shl esi,cl
51 add esi,[srcofs]
52 mov [srcofs],esi ; for memcpy_vcpi
53 mov edi,[dstofs]
55 ifndef pm_only
56 mov eax,esi
57 shr eax,cl
58 mov edx,edi
59 shr edx,cl
60 mov ecx,esi
61 or ecx,edi
62 shr ecx,20 ; >1mb ?
63 jnz @@pmcopy
64 @@movlp:
65 mov ds,ax
66 mov es,dx
67 inc ax
68 inc dx
69 mov cl,0Fh
70 and si,cx
71 and di,cx
72 inc cx
73 sub [sz],ecx
74 jae @@movpara
75 add ecx,[sz]
76 @@movpara:
77 rep movsb
78 ja @@movlp
79 jmp @@done
80 endif
81 @@pmcopy:
82 else
84 push bp
85 mov bp,sp
86 ;cld
87 pushf
88 push ds es
89 push si
90 xor bx,bx
91 xor si,si
92 mov ax,[srcseg]
93 extrn N_LXLSH@4:near
94 call near ptr N_LXLSH@4
95 add [word srcofs],ax
96 adc [word srcofs+2],dx
97 @@2flat:
98 les ax,[dword si+srcofs] ; srcofs, dstofs
99 mov dx,es
100 mov cl,4
101 @@loop:
102 shr dx,1
103 rcr ax,1
104 loop @@loop
105 or bx,dx ; >=1mb flag
106 push ax ; srcseg, dstseg
107 xor si,-6
108 jnz @@2flat
109 pop dx ; dstseg
110 pop ax ; srcseg
111 dec bx ; <1mb ?
112 jns @@pmcopy
113 push di
114 @@movlp:
115 mov ds,ax
116 mov es,dx
117 inc ax
118 inc dx
119 mov cl,0Fh
120 mov si,cx
121 mov di,cx
122 and si,[word srcofs]
123 and di,[word dstofs]
124 inc cx
125 sub [word sz],cx
126 ;jae @@movpara
127 sbb [word sz+2],0
128 jae @@movpara
129 add cx,[word sz]
130 ;stc
131 @@movpara:
132 rep movsb
133 jae @@movlp
134 dec cx ; set S
135 pop di
136 @@pmcopy:
137 pop si
138 js @@done16
139 p386
140 pushad ; struct declared in VCPI.ASM
141 mov esi,[srcofs]
142 mov edi,[dstofs]
144 endif
146 mov ecx,[sz]
147 jecxz @@done
149 smsw ax
150 and al,1 ;MSW_PE
151 jz @@real_mode
152 ; Note: bp points to std stack frame now. bp will be passed to
153 ; pm routine. This allows params to be passed on stack
154 extrn vcpi_pm_copy_routine:near
155 call near vcpi_pm_copy_routine ; Call pm copy routine via vcpi pm
156 jmp @@done
157 @@real_mode:
158 cmp esi,edi
159 jae @@do_copy
160 add esi,ecx ;src<dst: we must do
161 dec esi ; copy backwards to avoid
162 add edi,ecx ; overwrite bug
163 dec edi ;
164 std ;
165 @@do_copy:
166 cli
167 oldGDTR = (pword srcseg) ; don't need src seg/ofs anymore
168 sgdt [oldGDTR]
170 ;****** Load gdtr **********************************************
171 lgdt [GDTR]
173 ;****** Go into pm *********************************************
174 mov eax,cr0
175 inc ax ;CR0_PE on
176 lcr0 eax
177 ;****** Move data **********************************************
178 push 0008h
179 pop ds ;base=0, lim = 4gb
180 push ds ;
181 pop es ;
182 ;db 66h ;operand width override for ecx
183 db 67h ;address width override for esi/edi
184 rep movsb
185 ;cld
187 ;****** Return to rm *******************************************
188 dec ax ;CR0_PE off
189 lcr0 eax
190 ;****** Return *************************************************
191 lgdt [oldGDTR]
192 @@done:
193 popad
194 p8086
195 @@done16:
196 pop es ds
197 popf ; restore I & D
198 ifndef NO386
199 p386
200 leave
201 else
202 pop bp
203 endif
204 ret 14
206 ;****** Const data *********************************************
208 extrn gdt_memcpy
209 label GDTR pword
210 gdt_limit dw 0ffffh
211 global gdt_base_memcpy:word
212 gdt_base_memcpy dw offset gdt_memcpy,0
214 endp memcpy32
216 ends _TEXT
218 end
220 ;###### END OF FILE ############################################