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

Add openct
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Apr 03 15:12:17 2017 +0200 (2017-04-03)
parents 76087975885f
children 69faca221dde
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 mov cl,4
173 extrn N_LXLSH@:near
174 call near N_LXLSH@
175 add [bp+10],ax ; srcofs lo
176 adc [bp+10+2],dx ; srcofs hi
177 @@2flat:
178 mov ax,[bp+si+10] ; srcofs, dstofs lo
179 mov dx,[bp+si+10+2] ; srcofs, dstofs hi
180 call near N_LXURSH@4
181 or bx,dx ; >=1mb flag
182 push ax ; srcseg, dstseg
183 xor si,-6
184 jnz @@2flat
185 pop dx ; dstseg
186 pop ax ; srcseg
187 test bx,bx ; <1mb ? (clear C)
188 jnz @@pmcopy
189 push di
190 @@movlp:
191 mov ds,ax
192 mov es,dx
193 inc ax
194 inc dx
195 mov cl,0Fh
196 mov si,cx
197 mov di,cx
198 and si,[word srcofs]
199 and di,[word dstofs]
200 inc cx
201 sub [word sz],cx
202 rep movsb
203 ja @@movlp
204 dec [word sz+2]
205 jns @@movlp ; mov 1-16 more bytes...
206 pop di
207 @@pmcopy:
208 pop si
209 js @@done16
210 p386
211 pushad
212 mov esi,[srcofs]
213 mov edi,[dstofs]
215 endif
217 mov ecx,[sz]
218 jecxz @@done
220 smsw ax
221 test al,1
222 jz @@real_mode
223 ; Note: bp points to std stack frame now. bp will be passed to
224 ; pm routine. This allows params to be passed on stack
225 extrn do_memcpy_vcpi:near
226 push offset do_memcpy_vcpi
227 extrn call_pm_routine:near
228 call near call_pm_routine ; Call pm copy routine via vcpi pm
229 pop ax
230 jmp @@done
231 @@real_mode:
232 cmp esi,edi
233 jae @@do_copy
234 add esi,ecx ;src<dst: we must do
235 dec esi ; copy backwards to avoid
236 add edi,ecx ; overwrite bug
237 dec edi ;
238 std ;
239 @@do_copy:
240 cli
241 sgdt [oldGDTR]
243 ;****** Load gdtr **********************************************
244 mov eax,cs
245 shl eax,4
246 addzx_e ax,<offset GDT>
247 or [word GDTR],-1 ;GDT limit = 0FFFFh
248 mov [dword GDTR+2],eax ;GDT base
249 lgdt [GDTR]
251 ;****** Go into pm *********************************************
252 mov eax,cr0
253 inc ax ;CR0_PE on
254 mov cr0,eax
255 jmp short $+2 ;*Required*!
256 ;3+ NOPs also work fine (chkd on 386)
257 ;****** Move data **********************************************
258 push 0008h
259 pop ds ;base=0, lim = 4gb
260 push ds ;
261 pop es ;
262 ;db 66h ;operand width override for ecx
263 db 67h ;address width override for esi/edi
264 rep movsb
265 ;cld
267 ;****** Return to rm *******************************************
268 dec ax ;CR0_PE off
269 mov cr0,eax ;ds/es limits are *not* reset to 64kb
270 ; but who cares :-)
271 jmp short $+2
273 ;****** Return *************************************************
274 lgdt [oldGDTR]
275 @@done:
276 popad
277 p8086
278 @@done16:
279 pop es ds
280 popf
281 ifndef NO386
282 p386
283 leave
284 else
285 mov sp,bp
286 pop bp
287 endif
288 ret
290 ;****** Const data *********************************************
291 org $-8 ;save 8 bytes - they are unused anyway
292 ;0000: unused
293 GDT dd ?,?
294 ;0008: Data seg [0,FFFFFFFF]
295 ; lim_lo base_lo
296 dw 1111111111111111b, 0000000000000000b
297 db 00000000b,10010010b,10001111b,00000000b
298 ; base_med P S D A G ??l_hi base_hi
299 ; Pl E W D
301 endp _memcpy32
303 ifdef NO386
304 global N_LXURSH@:near
305 global N_LXURSH@4:near
306 proc N_LXURSH@4 near
308 mov cl,4
309 N_LXURSH@:
310 mov ch,0
311 @@loop:
312 shr dx,1
313 rcr ax,1
314 loop @@loop
315 ret
317 endp N_LXURSH@4
319 endif
321 ends _TEXT
323 end
325 ;###### END OF FILE ############################################