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

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