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

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