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

Up acl-dev (2.2.53)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Oct 31 15:13:42 2018 +0100 (2018-10-31)
parents cd2def637347
children d7919052f62f
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
15 assume cs:DGROUP,ds:DGROUP
17 segment _TEXT byte public use16 'CODE'
19 ;***************************************************************
20 ;void memcpy32(u32 dstofs,u16 srcseg,u32 srcofs,u32 size);
21 ;***************************************************************
22 ;****** Uses: Flags
23 ;***************************************************************
24 global _memcpy32:near
25 proc _memcpy32 near
27 ; rm32,imm16 helper
28 macro addzx_e rm,i
29 db 66h
30 add rm,i
31 dw 0
32 endm
33 arg dstofs :dword, \
34 srcseg :word, \
35 srcofs :dword, \
36 sz :dword = PARAM_SIZE
38 local GDTR :pword, \
39 oldGDTR :pword = TEMP_SIZE
41 ;****** Init ***************************************************
43 ifndef NO386
45 enter TEMP_SIZE,0
46 ;cld
47 pushf
48 push ds es
49 pushad
50 mov cl,4
51 movzx esi,[srcseg]
52 shl esi,cl
53 add esi,[srcofs]
54 mov [srcofs],esi ; for memcpy_vcpi
55 mov edi,[dstofs]
57 ifndef pm_only
58 mov eax,esi
59 shr eax,cl
60 mov edx,edi
61 shr edx,cl
62 mov ecx,esi
63 or ecx,edi
64 shr ecx,20 ; >1mb ?
65 jnz @@pmcopy
66 @@movlp:
67 mov ds,ax
68 mov es,dx
69 inc ax
70 inc dx
71 mov cl,0Fh
72 and si,cx
73 and di,cx
74 inc cx
75 sub [sz],ecx
76 rep movsb
77 ja @@movlp
78 jmp @@done
79 endif
80 @@pmcopy:
81 else
83 push bp
84 mov bp,sp
85 sub sp,TEMP_SIZE
86 ;cld
87 pushf
88 push ds es
89 push si
90 xor bx,bx
91 xor dx,dx
92 xor si,si
93 mov ax,[srcseg]
94 mov cl,4
95 extrn N_LXLSH@:near
96 call near N_LXLSH@
97 add [word srcofs],ax
98 adc [word srcofs+2],dx
99 @@2flat:
100 mov ax,[word si+srcofs] ; srcofs, dstofs lo
101 mov dx,[word si+srcofs+2] ; srcofs, dstofs hi
102 extrn N_LXURSH@4:near
103 call near N_LXURSH@4
104 or bx,dx ; >=1mb flag
105 push ax ; srcseg, dstseg
106 xor si,-6
107 jnz @@2flat
108 pop dx ; dstseg
109 pop ax ; srcseg
110 dec bx ; <1mb ?
111 jns @@pmcopy
112 push di
113 @@movlp:
114 mov ds,ax
115 mov es,dx
116 inc ax
117 inc dx
118 mov cl,0Fh
119 mov si,cx
120 mov di,cx
121 and si,[word srcofs]
122 and di,[word dstofs]
123 inc cx
124 sub [word sz],cx
125 rep movsb
126 jae @@movlp
127 dec [word sz+2]
128 jns @@movlp ; mov 1-16 more bytes...
129 pop di
130 @@pmcopy:
131 pop si
132 js @@done16
133 p386
134 pushad
135 mov esi,[srcofs]
136 mov edi,[dstofs]
138 endif
140 mov ecx,[sz]
141 jecxz @@done
143 smsw ax
144 and al,1 ;MSW_PE
145 jz @@real_mode
146 ; Note: bp points to std stack frame now. bp will be passed to
147 ; pm routine. This allows params to be passed on stack
148 extrn do_memcpy_vcpi:near
149 push offset do_memcpy_vcpi
150 extrn call_pm_routine:near
151 call near call_pm_routine ; Call pm copy routine via vcpi pm
152 pop ax
153 jmp @@done
154 @@real_mode:
155 cmp esi,edi
156 jae @@do_copy
157 add esi,ecx ;src<dst: we must do
158 dec esi ; copy backwards to avoid
159 add edi,ecx ; overwrite bug
160 dec edi ;
161 std ;
162 @@do_copy:
163 cli
164 sgdt [oldGDTR]
166 ;****** Load gdtr **********************************************
167 mov eax,cs
168 shl eax,4
169 addzx_e ax,<offset GDT>
170 or [word GDTR],-1 ;GDT limit = 0FFFFh
171 mov [dword GDTR+2],eax ;GDT base
172 lgdt [GDTR]
174 ;****** Go into pm *********************************************
175 mov eax,cr0
176 inc ax ;CR0_PE on
177 mov cr0,eax
178 jmp short $+2 ;*Required*!
179 ;3+ NOPs also work fine (chkd on 386)
180 ;****** Move data **********************************************
181 push 0008h
182 pop ds ;base=0, lim = 4gb
183 push ds ;
184 pop es ;
185 ;db 66h ;operand width override for ecx
186 db 67h ;address width override for esi/edi
187 rep movsb
188 ;cld
190 ;****** Return to rm *******************************************
191 dec ax ;CR0_PE off
192 mov cr0,eax ;ds/es limits are *not* reset to 64kb
193 ; but who cares :-)
194 jmp short $+2
196 ;****** Return *************************************************
197 lgdt [oldGDTR]
198 @@done:
199 popad
200 p8086
201 @@done16:
202 pop es ds
203 popf
204 ifndef NO386
205 p386
206 leave
207 else
208 mov sp,bp
209 pop bp
210 endif
211 ret
213 ;****** Const data *********************************************
214 org $-8 ;save 8 bytes - they are unused anyway
215 ;0000: unused
216 GDT dd ?,?
217 ;0008: Data seg [0,FFFFFFFF]
218 ; lim_lo base_lo
219 dw 1111111111111111b, 0000000000000000b
220 db 00000000b,10010010b,10001111b,00000000b
221 ; base_med P S D A G ??l_hi base_hi
222 ; Pl E W D
224 endp _memcpy32
226 ends _TEXT
228 end
230 ;###### END OF FILE ############################################