wok view linld/stuff/src/MEMCPY32.ASM @ rev 20454

Up zstd (1.3.6)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Oct 06 15:17:20 2018 +0200 (2018-10-06)
parents 485b1db348fd
children 2e46d946d7a8
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %crefref
6 %noincl
7 %nomacs
8 ifdef NO386
9 p8086
10 else
11 p386
12 endif
14 group DGROUP _TEXT,_DATA,_BSS
15 assume cs:DGROUP,ds:DGROUP
17 segment _DATA byte public use16 'DATA'
18 ends _DATA
20 segment _BSS byte public use16 'BSS'
21 global sssp:dword
22 sssp dd ?
23 ends _BSS
25 segment _TEXT byte public use16 'CODE'
27 ;***************************************************************
28 ;void dos_shutdown()
29 ;***************************************************************
30 global dos_shutdown:near
31 proc dos_shutdown near
33 dos_shutdown:
34 ifndef NO386
35 ;pusha
36 else
37 ;push bp si di
38 endif
39 xor bx,bx
40 mov ds,bx
41 ifndef NO386
42 push [dword bx+4] ; save step
43 mov [word bx+4],offset step19
44 else
45 mov ax,offset step19
46 xchg ax,[word bx+4]
47 push [word bx+6]
48 push ax ; save step
49 endif
50 mov [word sssp],sp
51 mov [word sssp+2],ss
52 ;cmp [byte bx+7],0F0h
53 ;jnc notdos
54 mov [bx+6],cs
55 pushf
56 pop ax
57 inc ah ; set TF
58 push ax
59 popf
60 jmp [dword bx+4*19h]
61 doiret:
62 iret
63 step19:
64 push bx
65 push ds
66 mov bx,sp
67 lds bx,[dword ss:bx+4] ; read cs:ip
68 cmp [word bx],19CDh ; int 19h ?
69 pop ds
70 pop bx
71 jne doiret
72 notdos:
73 ifndef NO386
74 lss sp,[dword cs:sssp]
75 else
76 lds ax,[dword cs:sssp]
77 push ds
78 pop ss
79 xchg ax,sp
80 endif
81 xor bx,bx
82 mov ds,bx
83 ifndef NO386
84 pop [dword bx+4] ; restore step
85 ;popa
86 else
87 pop [word bx+4] ; restore step
88 pop [word bx+6]
89 ;pop di si bp
90 endif
91 push cs
92 pop ds
93 ret
95 endp dos_shutdown
98 ;***************************************************************
99 ;void memcpy32(u32 dstofs,u16 srcseg,u32 srcofs,u32 size);
100 ;***************************************************************
101 ;****** Uses: Flags
102 ;***************************************************************
103 global _memcpy32:near
104 proc _memcpy32 near
106 ; rm32,imm16 helper
107 macro addzx_e rm,i
108 db 66h
109 add rm,i
110 dw 0
111 endm
112 arg dstofs :dword, \
113 srcseg :word, \
114 srcofs :dword, \
115 sz :dword = PARAM_SIZE
117 local GDTR :pword, \
118 oldGDTR :pword = TEMP_SIZE
120 ;****** Init ***************************************************
122 ifndef NO386
124 enter TEMP_SIZE,0
125 ;cld
126 pushf
127 push ds es
128 pushad
129 mov cl,4
130 movzx esi,[srcseg]
131 shl esi,cl
132 add esi,[srcofs]
133 mov [srcofs],esi ; for memcpy_vcpi
134 mov edi,[dstofs]
136 ifndef pm_only
137 mov eax,esi
138 shr eax,cl
139 mov edx,edi
140 shr edx,cl
141 mov ecx,esi
142 or ecx,edi
143 shr ecx,20 ; >1mb ?
144 jnz @@pmcopy
145 @@movlp:
146 mov ds,ax
147 mov es,dx
148 inc ax
149 inc dx
150 mov cl,0Fh
151 and si,cx
152 and di,cx
153 inc cx
154 sub [sz],ecx
155 rep movsb
156 ja @@movlp
157 jmp @@done
158 endif
159 @@pmcopy:
160 else
162 push bp
163 mov bp,sp
164 sub sp,TEMP_SIZE
165 ;cld
166 pushf
167 push ds es
168 push si
169 xor bx,bx
170 xor dx,dx
171 xor si,si
172 mov ax,[srcseg]
173 mov cl,4
174 extrn N_LXLSH@:near
175 call near N_LXLSH@
176 add [word srcofs],ax
177 adc [word srcofs+2],dx
178 @@2flat:
179 mov ax,[word si+srcofs] ; srcofs, dstofs lo
180 mov dx,[word si+srcofs+2] ; srcofs, dstofs hi
181 extrn N_LXURSH@4:near
182 call near N_LXURSH@4
183 or bx,dx ; >=1mb flag
184 push ax ; srcseg, dstseg
185 xor si,-6
186 jnz @@2flat
187 pop dx ; dstseg
188 pop ax ; srcseg
189 dec bx ; <1mb ?
190 jns @@pmcopy
191 push di
192 @@movlp:
193 mov ds,ax
194 mov es,dx
195 inc ax
196 inc dx
197 mov cl,0Fh
198 mov si,cx
199 mov di,cx
200 and si,[word srcofs]
201 and di,[word dstofs]
202 inc cx
203 sub [word sz],cx
204 rep movsb
205 ja @@movlp
206 dec [word sz+2]
207 jns @@movlp ; mov 1-16 more bytes...
208 pop di
209 @@pmcopy:
210 pop si
211 js @@done16
212 p386
213 pushad
214 mov esi,[srcofs]
215 mov edi,[dstofs]
217 endif
219 mov ecx,[sz]
220 jecxz @@done
222 smsw ax
223 and al,1 ;MSW_PE
224 jz @@real_mode
225 ; Note: bp points to std stack frame now. bp will be passed to
226 ; pm routine. This allows params to be passed on stack
227 extrn do_memcpy_vcpi:near
228 push offset do_memcpy_vcpi
229 extrn call_pm_routine:near
230 call near call_pm_routine ; Call pm copy routine via vcpi pm
231 pop ax
232 jmp @@done
233 @@real_mode:
234 cmp esi,edi
235 jae @@do_copy
236 add esi,ecx ;src<dst: we must do
237 dec esi ; copy backwards to avoid
238 add edi,ecx ; overwrite bug
239 dec edi ;
240 std ;
241 @@do_copy:
242 cli
243 sgdt [oldGDTR]
245 ;****** Load gdtr **********************************************
246 mov eax,cs
247 shl eax,4
248 addzx_e ax,<offset GDT>
249 or [word GDTR],-1 ;GDT limit = 0FFFFh
250 mov [dword GDTR+2],eax ;GDT base
251 lgdt [GDTR]
253 ;****** Go into pm *********************************************
254 mov eax,cr0
255 inc ax ;CR0_PE on
256 mov cr0,eax
257 jmp short $+2 ;*Required*!
258 ;3+ NOPs also work fine (chkd on 386)
259 ;****** Move data **********************************************
260 push 0008h
261 pop ds ;base=0, lim = 4gb
262 push ds ;
263 pop es ;
264 ;db 66h ;operand width override for ecx
265 db 67h ;address width override for esi/edi
266 rep movsb
267 ;cld
269 ;****** Return to rm *******************************************
270 dec ax ;CR0_PE off
271 mov cr0,eax ;ds/es limits are *not* reset to 64kb
272 ; but who cares :-)
273 jmp short $+2
275 ;****** Return *************************************************
276 lgdt [oldGDTR]
277 @@done:
278 popad
279 p8086
280 @@done16:
281 pop es ds
282 popf
283 ifndef NO386
284 p386
285 leave
286 else
287 mov sp,bp
288 pop bp
289 endif
290 ret
292 ;****** Const data *********************************************
293 org $-8 ;save 8 bytes - they are unused anyway
294 ;0000: unused
295 GDT dd ?,?
296 ;0008: Data seg [0,FFFFFFFF]
297 ; lim_lo base_lo
298 dw 1111111111111111b, 0000000000000000b
299 db 00000000b,10010010b,10001111b,00000000b
300 ; base_med P S D A G ??l_hi base_hi
301 ; Pl E W D
303 endp _memcpy32
305 ends _TEXT
307 end
309 ;###### END OF FILE ############################################