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

Up glza (0.11.4)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat May 21 21:38:29 2022 +0000 (2022-05-21)
parents 217c02cbbe8d
children
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 255
6 %crefref
7 %noincl
8 %nomacs
10 include "common.inc"
12 ifdef NO386
13 p8086
14 else
15 p386
16 endif
18 group DGROUP _TEXT
19 assume cs:DGROUP,ds:DGROUP
21 macro lcr0 reg
22 mov cr0,reg
23 jmp short $+2 ;*Required*!
24 ;3+ NOPs also work fine (chkd on 386)
25 endm
27 macro addzx_e rm,i
28 db 66h
29 add rm,i
30 dw 0
31 endm
33 segment _TEXT byte public use16 'CODE'
35 ;***************************************************************
36 ;void memcpy32(u32 dstofs,u16 srcseg,u32 srcofs,u32 size);
37 ;***************************************************************
38 ;****** Uses: Flags
39 ;***************************************************************
40 global memcpy32:near
41 proc memcpy32 near
43 arg dstofs :dword, \
44 srcseg :word, \
45 srcofs :dword, \
46 sz :dword = PARAM_SIZE
48 ;****** Init ***************************************************
50 push bp
51 mov bp,sp
52 ;cld
53 pushf
54 push ds
56 ifndef NO386
58 pushad ; struct declared in VCPI.ASM
59 mov cl,4
60 movzx esi,[srcseg]
61 shl esi,cl
62 add esi,[srcofs]
63 mov edi,[dstofs]
65 ifndef pm_only
66 mov eax,esi
67 shr eax,cl
68 mov edx,edi
69 shr edx,cl
70 lea ecx,[eax+edx]
71 shr ecx,16 ; >1mb ?
72 jnz @@pmcopy
73 @@movlp:
74 mov ds,ax
75 mov es,dx
76 inc ax
77 inc dx
78 mov cl,0Fh
79 and si,cx
80 and di,cx
81 inc cx
82 sub [sz],ecx
83 jae @@movpara
84 add ecx,[sz]
85 @@movpara:
86 rep movsb
87 ja @@movlp
88 jmp @@done
89 endif
90 @@pmcopy:
91 else
93 push si
94 push di
95 xor si,si
96 mov ax,[srcseg]
97 extrn N_LXLSH@4:near
98 call near ptr N_LXLSH@4
99 add [word srcofs],ax
100 adc [word srcofs+2],dx
101 @@2flat:
102 les dx,[dword si+srcofs] ; srcofs, dstofs
103 mov di,dx ; dstofs
104 mov ax,es
105 mov cl,4
106 @@loop:
107 shr ax,1 ; high
108 rcr dx,1 ; low
109 loop @@loop
110 push dx ; srcseg, dstseg
111 xchg ax,bx ; save/restore high srcreg
112 xor si,-6
113 jnz @@2flat
114 or bx,ax ; srcseg & dstseg < 1mb ? clear C
115 pop dx ; dstseg
116 pop ax ; srcseg
117 jnz @@pmcopy
118 @@movlp: ; bx=cx=0
119 mov ds,ax
120 mov es,dx
121 inc ax
122 inc dx
123 mov cl,0Fh
124 mov si,cx
125 and di,cx
126 and si,[word srcofs]
127 inc cx
128 sub [word sz],cx
129 ;jae @@movpara
130 sbb [word sz+2],bx
131 jae @@movpara
132 add cx,[word sz]
133 ;stc
134 @@movpara:
135 rep movsb
136 jae @@movlp
137 @@pmcopy:
138 pop di
139 pop si
140 jc @@done16
141 p386
142 pushad ; struct declared in VCPI.ASM
143 mov esi,[srcofs]
144 mov edi,[dstofs]
146 endif
148 mov ecx,[sz]
149 jecxz @@done
150 cli
152 ifdef VCPI
153 smsw ax
154 and al,1 ;MSW_PE
155 jz @@real_mode
156 ; Note: bp points to std stack frame now. bp will be passed to
157 ; pm routine. This allows params to be passed on stack
158 extrn vcpi_pm_copy_routine:near
159 call near vcpi_pm_copy_routine ; Call pm copy routine via vcpi pm
160 jmp @@done
161 endif
162 @@real_mode:
163 oldGDTR = (pword srcseg) ; don't need src seg/ofs anymore
164 sgdt [oldGDTR]
166 ;****** Load gdtr **********************************************
167 ifdef LARGE_ZIMAGE
168 local rflags: word, rds: word, \
169 reax: dword, recx: dword, redx: dword, rebx: dword, \
170 resp: dword, rebp: dword, resi: dword, redi: dword, \
171 GDTR: pword = LOCAL_SIZE
172 mov eax,cs
173 shl eax,4
174 addzx_e ax,<offset gdt_memcpy>
175 push eax ; gdt_base_memcpy
176 push -1 ; gdt_limit
177 endif
179 lgdt [GDTR]
181 ;****** Go into pm *********************************************
182 mov eax,cr0
183 inc ax ;CR0_PE on
184 lcr0 eax
185 ;****** Move data **********************************************
186 push 0008h
187 pop ds ;base=0, lim = 4gb
188 push ds ;
189 pop es ;
190 cmp esi,edi
191 jae @@do_copy
192 add esi,ecx ;src<dst: we must do
193 add edi,ecx ; copy backwards to avoid
194 std ; overwrite bug
195 db 67h ;address width override for esi/edi
196 cmpsb ; dec esi/edi
197 @@do_copy:
198 ;db 66h ;operand width override for ecx
199 db 67h ;address width override for esi/edi
200 rep movsb
201 ;cld
203 ;****** Return to rm *******************************************
204 dec ax ;CR0_PE off
205 lcr0 eax
206 ;****** Return *************************************************
207 lgdt [oldGDTR]
208 ifdef LARGE_ZIMAGE
209 add sp,6
210 endif
211 @@done:
212 popad
213 p8086
214 @@done16:
215 pop ds
216 popf ; restore I & D
217 pop bp
218 ret 14
220 ;****** Const data *********************************************
222 ifdef VCPI
223 extrn gdt_memcpy
224 else
225 org $-8 ;save 8 bytes
226 ;0000: unused
227 gdt_memcpy dd ?,?
228 ;0008: Data seg [0,FFFFFFFF]
229 ; lim_lo base_lo
230 dw 1111111111111111b, 0000000000000000b
231 db 00000000b,10010010b,10001111b,00000000b
232 ; base_med P S D A G ??l_hi base_hi
233 ; Pl E W D
234 endif
235 ifndef LARGE_ZIMAGE
236 label GDTR pword
237 gdt_limit dw 0ffffh
238 global gdt_base_memcpy:word
239 gdt_base_memcpy dw offset gdt_memcpy,0
240 endif
242 endp memcpy32
244 ends _TEXT
246 end
248 ;###### END OF FILE ############################################