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

linld: more ram for zImage (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun May 26 12:07:54 2019 +0200 (2019-05-26)
parents f0d71e920c5a
children 04ffefac5707
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 ; struct declared in VCPI.ASM
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 jae @@movpara
77 add ecx,[sz]
78 @@movpara:
79 rep movsb
80 ja @@movlp
81 jmp @@done
82 endif
83 @@pmcopy:
84 else
86 push bp
87 mov bp,sp
88 sub sp,TEMP_SIZE
89 ;cld
90 pushf
91 push ds es
92 push si
93 xor bx,bx
94 xor si,si
95 mov ax,[srcseg]
96 xor dx,dx
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 mov ax,[word si+srcofs] ; srcofs, dstofs lo
103 mov dx,[word si+srcofs+2] ; srcofs, dstofs hi
104 extrn N_LXURSH@4:near
105 call near N_LXURSH@4
106 or bx,dx ; >=1mb flag
107 push ax ; srcseg, dstseg
108 xor si,-6
109 jnz @@2flat
110 pop dx ; dstseg
111 pop ax ; srcseg
112 dec bx ; <1mb ?
113 jns @@pmcopy
114 push di
115 @@movlp:
116 mov ds,ax
117 mov es,dx
118 inc ax
119 inc dx
120 mov cl,0Fh
121 mov si,cx
122 mov di,cx
123 and si,[word srcofs]
124 and di,[word dstofs]
125 inc cx
126 sub [word sz],cx
127 ;jae @@movpara
128 sbb [word sz+2],0
129 jae @@movpara
130 add cx,[word sz]
131 ;stc
132 @@movpara:
133 rep movsb
134 jae @@movlp
135 dec cx ; set S
136 pop di
137 @@pmcopy:
138 pop si
139 js @@done16
140 p386
141 pushad ; struct declared in VCPI.ASM
142 mov esi,[srcofs]
143 mov edi,[dstofs]
145 endif
147 mov ecx,[sz]
148 jecxz @@done
150 smsw ax
151 and al,1 ;MSW_PE
152 jz @@real_mode
153 ; Note: bp points to std stack frame now. bp will be passed to
154 ; pm routine. This allows params to be passed on stack
155 extrn vcpi_pm_copy_routine:near
156 call near vcpi_pm_copy_routine ; Call pm copy routine via vcpi pm
157 jmp @@done
158 @@real_mode:
159 cmp esi,edi
160 jae @@do_copy
161 add esi,ecx ;src<dst: we must do
162 dec esi ; copy backwards to avoid
163 add edi,ecx ; overwrite bug
164 dec edi ;
165 std ;
166 @@do_copy:
167 cli
168 sgdt [oldGDTR]
170 ;****** Load gdtr **********************************************
171 mov eax,cs
172 shl eax,4
173 addzx_e ax,<offset GDT>
174 or [word GDTR],-1 ;GDT limit = 0FFFFh
175 mov [dword GDTR+2],eax ;GDT base
176 lgdt [GDTR]
178 ;****** Go into pm *********************************************
179 mov eax,cr0
180 inc ax ;CR0_PE on
181 mov cr0,eax
182 jmp short $+2 ;*Required*!
183 ;3+ NOPs also work fine (chkd on 386)
184 ;****** Move data **********************************************
185 push 0008h
186 pop ds ;base=0, lim = 4gb
187 push ds ;
188 pop es ;
189 ;db 66h ;operand width override for ecx
190 db 67h ;address width override for esi/edi
191 rep movsb
192 ;cld
194 ;****** Return to rm *******************************************
195 dec ax ;CR0_PE off
196 mov cr0,eax ;ds/es limits are *not* reset to 64kb
197 ; but who cares :-)
198 jmp short $+2
200 ;****** Return *************************************************
201 lgdt [oldGDTR]
202 @@done:
203 popad
204 p8086
205 @@done16:
206 pop es ds
207 popf ; restore I & D
208 ifndef NO386
209 p386
210 leave
211 else
212 mov sp,bp
213 pop bp
214 endif
215 ret 14
217 ;****** Const data *********************************************
218 org $-8 ;save 8 bytes - they are unused anyway
219 ;0000: unused
220 GDT dd ?,?
221 ;0008: Data seg [0,FFFFFFFF]
222 ; lim_lo base_lo
223 dw 1111111111111111b, 0000000000000000b
224 db 00000000b,10010010b,10001111b,00000000b
225 ; base_med P S D A G ??l_hi base_hi
226 ; Pl E W D
228 endp memcpy32
230 ends _TEXT
232 end
234 ;###### END OF FILE ############################################