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

linld: spare up to 30k more for zImage (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Nov 09 13:26:32 2019 +0100 (2019-11-09)
parents 04ffefac5707
children a946c1651082
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 1000
6 %crefref
7 %noincl
8 %nomacs
9 ifdef NO386
10 p8086
11 else
12 p386
13 endif
15 group DGROUP _TEXT
16 assume cs:DGROUP,ds:DGROUP
18 segment _TEXT byte public use16 'CODE'
20 ;***************************************************************
21 ;void memcpy32(u32 dstofs,u16 srcseg,u32 srcofs,u32 size);
22 ;***************************************************************
23 ;****** Uses: Flags
24 ;***************************************************************
25 global memcpy32:near
26 proc memcpy32 near
28 ; rm32,imm16 helper
29 macro addzx_e rm,i
30 db 66h
31 add rm,i
32 dw 0
33 endm
34 arg dstofs :dword, \
35 srcseg :word, \
36 srcofs :dword, \
37 sz :dword = PARAM_SIZE
39 local GDTR :pword, \
40 oldGDTR :pword = TEMP_SIZE
42 ;****** Init ***************************************************
44 ifndef NO386
46 enter TEMP_SIZE,0
47 ;cld
48 pushf
49 push ds es
50 pushad ; struct declared in VCPI.ASM
51 mov cl,4
52 movzx esi,[srcseg]
53 shl esi,cl
54 add esi,[srcofs]
55 mov [srcofs],esi ; for memcpy_vcpi
56 mov edi,[dstofs]
58 ifndef pm_only
59 mov eax,esi
60 shr eax,cl
61 mov edx,edi
62 shr edx,cl
63 mov ecx,esi
64 or ecx,edi
65 shr ecx,20 ; >1mb ?
66 jnz @@pmcopy
67 @@movlp:
68 mov ds,ax
69 mov es,dx
70 inc ax
71 inc dx
72 mov cl,0Fh
73 and si,cx
74 and di,cx
75 inc cx
76 sub [sz],ecx
77 jae @@movpara
78 add ecx,[sz]
79 @@movpara:
80 rep movsb
81 ja @@movlp
82 jmp @@done
83 endif
84 @@pmcopy:
85 else
87 push bp
88 mov bp,sp
89 sub sp,TEMP_SIZE
90 ;cld
91 pushf
92 push ds es
93 push si
94 xor bx,bx
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 ax,[dword si+srcofs] ; srcofs, dstofs
103 mov dx,es
104 mov cl,4
105 @@loop:
106 shr dx,1
107 rcr ax,1
108 loop @@loop
109 or bx,dx ; >=1mb flag
110 push ax ; srcseg, dstseg
111 xor si,-6
112 jnz @@2flat
113 pop dx ; dstseg
114 pop ax ; srcseg
115 dec bx ; <1mb ?
116 jns @@pmcopy
117 push di
118 @@movlp:
119 mov ds,ax
120 mov es,dx
121 inc ax
122 inc dx
123 mov cl,0Fh
124 mov si,cx
125 mov di,cx
126 and si,[word srcofs]
127 and di,[word dstofs]
128 inc cx
129 sub [word sz],cx
130 ;jae @@movpara
131 sbb [word sz+2],0
132 jae @@movpara
133 add cx,[word sz]
134 ;stc
135 @@movpara:
136 rep movsb
137 jae @@movlp
138 dec cx ; set S
139 pop di
140 @@pmcopy:
141 pop si
142 js @@done16
143 p386
144 pushad ; struct declared in VCPI.ASM
145 mov esi,[srcofs]
146 mov edi,[dstofs]
148 endif
150 mov ecx,[sz]
151 jecxz @@done
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 @@real_mode:
162 cmp esi,edi
163 jae @@do_copy
164 add esi,ecx ;src<dst: we must do
165 dec esi ; copy backwards to avoid
166 add edi,ecx ; overwrite bug
167 dec edi ;
168 std ;
169 @@do_copy:
170 cli
171 sgdt [oldGDTR]
173 ;****** Load gdtr **********************************************
174 mov eax,cs
175 shl eax,4
176 addzx_e ax,<offset GDT>
177 or [word GDTR],-1 ;GDT limit = 0FFFFh
178 mov [dword GDTR+2],eax ;GDT base
179 lgdt [GDTR]
181 ;****** Go into pm *********************************************
182 mov eax,cr0
183 inc ax ;CR0_PE on
184 mov cr0,eax
185 jmp short $+2 ;*Required*!
186 ;3+ NOPs also work fine (chkd on 386)
187 ;****** Move data **********************************************
188 push 0008h
189 pop ds ;base=0, lim = 4gb
190 push ds ;
191 pop es ;
192 ;db 66h ;operand width override for ecx
193 db 67h ;address width override for esi/edi
194 rep movsb
195 ;cld
197 ;****** Return to rm *******************************************
198 dec ax ;CR0_PE off
199 mov cr0,eax ;ds/es limits are *not* reset to 64kb
200 ; but who cares :-)
201 jmp short $+2
203 ;****** Return *************************************************
204 lgdt [oldGDTR]
205 @@done:
206 popad
207 p8086
208 @@done16:
209 pop es ds
210 popf ; restore I & D
211 ifndef NO386
212 p386
213 leave
214 else
215 mov sp,bp
216 pop bp
217 endif
218 ret 14
220 ;****** Const data *********************************************
221 org $-8 ;save 8 bytes - they are unused anyway
222 ;0000: unused
223 GDT dd ?,?
224 ;0008: Data seg [0,FFFFFFFF]
225 ; lim_lo base_lo
226 dw 1111111111111111b, 0000000000000000b
227 db 00000000b,10010010b,10001111b,00000000b
228 ; base_med P S D A G ??l_hi base_hi
229 ; Pl E W D
231 endp memcpy32
233 ends _TEXT
235 end
237 ;###### END OF FILE ############################################