wok-next view linld/stuff/src/MEMCPY32.ASM @ rev 19667

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