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

linld: pascal convention calls
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Nov 09 16:37:55 2018 +0100 (2018-11-09)
parents 17c0ad41f5bf
children af959ebf1305
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 si,si
92 mov ax,[srcseg]
93 xor dx,dx
94 extrn N_LXLSH@4:near
95 call near ptr N_LXLSH@4
96 add [word srcofs],ax
97 adc [word srcofs+2],dx
98 @@2flat:
99 mov ax,[word si+srcofs] ; srcofs, dstofs lo
100 mov dx,[word si+srcofs+2] ; srcofs, dstofs hi
101 extrn N_LXURSH@4:near
102 call near N_LXURSH@4
103 or bx,dx ; >=1mb flag
104 push ax ; srcseg, dstseg
105 xor si,-6
106 jnz @@2flat
107 pop dx ; dstseg
108 pop ax ; srcseg
109 dec bx ; <1mb ?
110 jns @@pmcopy
111 push di
112 @@movlp:
113 mov ds,ax
114 mov es,dx
115 inc ax
116 inc dx
117 mov cl,0Fh
118 mov si,cx
119 mov di,cx
120 and si,[word srcofs]
121 and di,[word dstofs]
122 inc cx
123 sub [word sz],cx
124 ;jae @@movpara
125 sbb [word sz+2],0
126 jae @@movpara
127 add cx,[word sz]
128 ;stc
129 @@movpara:
130 rep movsb
131 jae @@movlp
132 dec cx ; set S
133 pop di
134 @@pmcopy:
135 pop si
136 js @@done16
137 p386
138 pushad
139 mov esi,[srcofs]
140 mov edi,[dstofs]
142 endif
144 mov ecx,[sz]
145 jecxz @@done
147 smsw ax
148 and al,1 ;MSW_PE
149 jz @@real_mode
150 ; Note: bp points to std stack frame now. bp will be passed to
151 ; pm routine. This allows params to be passed on stack
152 extrn do_memcpy_vcpi:near
153 push offset do_memcpy_vcpi
154 extrn call_pm_routine:near
155 call near call_pm_routine ; Call pm copy routine via vcpi pm
156 pop ax
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
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 ############################################