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

bluez: add /usr/bin/bluepin
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Apr 03 17:30:48 2017 +0200 (2017-04-03)
parents a7fbb1c5c71a
children df6498976257
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,_DATA
15 assume cs:DGROUP,ds:DGROUP
17 segment _DATA byte public use16 'DATA'
18 ends _DATA
20 segment _TEXT byte public use16 'CODE'
22 ;***************************************************************
23 ;void dos_shutdown()
24 ;***************************************************************
25 global dos_shutdown:near
26 proc dos_shutdown near
28 dos_shutdown:
29 ifndef NO386
30 ;pusha
31 else
32 ;push bp si di
33 endif
34 xor bx,bx
35 mov ds,bx
36 ifndef NO386
37 push [dword bx+4] ; save step
38 mov ax,sp
39 push ss
40 push ax
41 pop [dword cs:sssp]
42 else
43 push [word bx+6]
44 push [word bx+4] ; save step
45 mov [word cs:sssp],sp
46 mov [word cs:sssp+2],ss
47 endif
48 ;cmp [byte bx+7],0F0h
49 ;jnc notdos
50 mov [word bx+4],offset step19
51 mov [bx+6],cs
52 pushf
53 pop ax
54 inc ah ; set TF
55 push ax
56 popf
57 jmp [dword bx+4*19h]
58 doiret:
59 iret
60 sssp:
61 dd 0
62 step19:
63 push bx
64 push ds
65 mov bx,sp
66 lds bx,[dword ss:bx+4] ; read cs:ip
67 cmp [word bx],19CDh ; int 19h ?
68 pop ds
69 pop bx
70 jne doiret
71 notdos:
72 ifndef NO386
73 lss sp,[dword cs:sssp]
74 else
75 lds bx,[dword cs:sssp]
76 push ds
77 pop ss
78 mov sp,bx
79 endif
80 xor bx,bx
81 mov ds,bx
82 ifndef NO386
83 pop [dword bx+4] ; restore step
84 ;popa
85 else
86 pop [word bx+4] ; restore step
87 pop [word bx+6]
88 ;pop di si bp
89 endif
90 push cs
91 pop ds
92 ret
94 endp dos_shutdown
97 ;***************************************************************
98 ;void memcpy32(u32 dstofs,u16 srcseg,u32 srcofs,u32 size);
99 ;***************************************************************
100 ;****** Uses: Flags
101 ;***************************************************************
102 global _memcpy32:near
103 proc _memcpy32 near
105 ; rm32,imm16 helper
106 macro addzx_e rm,i
107 db 66h
108 add rm,i
109 dw 0
110 endm
111 arg dstofs :dword, \
112 srcseg :word, \
113 srcofs :dword, \
114 sz :dword = PARAM_SIZE
116 local GDTR :pword, \
117 oldGDTR :pword = TEMP_SIZE
119 ;****** Init ***************************************************
121 ifndef NO386
123 enter TEMP_SIZE,0
124 ;cld
125 pushf
126 push ds es
127 pushad
128 mov cl,4
129 movzx esi,[srcseg]
130 shl esi,cl
131 add esi,[srcofs]
132 mov [srcofs],esi ; for memcpy_vcpi
133 mov edi,[dstofs]
135 ifndef pm_only
136 mov eax,esi
137 shr eax,cl
138 mov edx,edi
139 shr edx,cl
140 mov ecx,esi
141 or ecx,edi
142 shr ecx,20 ; >1mb ?
143 jnz @@pmcopy
144 @@movlp:
145 mov ds,ax
146 mov es,dx
147 inc ax
148 inc dx
149 mov cl,0Fh
150 and si,cx
151 and di,cx
152 inc cx
153 sub [sz],ecx
154 rep movsb
155 ja @@movlp
156 jmp @@done
157 endif
158 @@pmcopy:
159 else
161 push bp
162 mov bp,sp
163 sub sp,TEMP_SIZE
164 ;cld
165 pushf
166 push ds es
167 push si
168 xor bx,bx
169 xor dx,dx
170 xor si,si
171 mov ax,[bp+8] ; srcseg
172 mov cl,4
173 extrn N_LXLSH@:near
174 call near N_LXLSH@
175 add [bp+10],ax ; srcofs lo
176 adc [bp+10+2],dx ; srcofs hi
177 @@2flat:
178 mov ax,[bp+si+10] ; srcofs, dstofs lo
179 mov dx,[bp+si+10+2] ; srcofs, dstofs hi
180 extrn N_LXURSH@4:near
181 call near N_LXURSH@4
182 or bx,dx ; >=1mb flag
183 push ax ; srcseg, dstseg
184 xor si,-6
185 jnz @@2flat
186 pop dx ; dstseg
187 pop ax ; srcseg
188 test bx,bx ; <1mb ? (clear C)
189 jnz @@pmcopy
190 push di
191 @@movlp:
192 mov ds,ax
193 mov es,dx
194 inc ax
195 inc dx
196 mov cl,0Fh
197 mov si,cx
198 mov di,cx
199 and si,[word srcofs]
200 and di,[word dstofs]
201 inc cx
202 sub [word sz],cx
203 rep movsb
204 ja @@movlp
205 dec [word sz+2]
206 jns @@movlp ; mov 1-16 more bytes...
207 pop di
208 @@pmcopy:
209 pop si
210 js @@done16
211 p386
212 pushad
213 mov esi,[srcofs]
214 mov edi,[dstofs]
216 endif
218 mov ecx,[sz]
219 jecxz @@done
221 smsw ax
222 test al,1
223 jz @@real_mode
224 ; Note: bp points to std stack frame now. bp will be passed to
225 ; pm routine. This allows params to be passed on stack
226 extrn do_memcpy_vcpi:near
227 push offset do_memcpy_vcpi
228 extrn call_pm_routine:near
229 call near call_pm_routine ; Call pm copy routine via vcpi pm
230 pop ax
231 jmp @@done
232 @@real_mode:
233 cmp esi,edi
234 jae @@do_copy
235 add esi,ecx ;src<dst: we must do
236 dec esi ; copy backwards to avoid
237 add edi,ecx ; overwrite bug
238 dec edi ;
239 std ;
240 @@do_copy:
241 cli
242 sgdt [oldGDTR]
244 ;****** Load gdtr **********************************************
245 mov eax,cs
246 shl eax,4
247 addzx_e ax,<offset GDT>
248 or [word GDTR],-1 ;GDT limit = 0FFFFh
249 mov [dword GDTR+2],eax ;GDT base
250 lgdt [GDTR]
252 ;****** Go into pm *********************************************
253 mov eax,cr0
254 inc ax ;CR0_PE on
255 mov cr0,eax
256 jmp short $+2 ;*Required*!
257 ;3+ NOPs also work fine (chkd on 386)
258 ;****** Move data **********************************************
259 push 0008h
260 pop ds ;base=0, lim = 4gb
261 push ds ;
262 pop es ;
263 ;db 66h ;operand width override for ecx
264 db 67h ;address width override for esi/edi
265 rep movsb
266 ;cld
268 ;****** Return to rm *******************************************
269 dec ax ;CR0_PE off
270 mov cr0,eax ;ds/es limits are *not* reset to 64kb
271 ; but who cares :-)
272 jmp short $+2
274 ;****** Return *************************************************
275 lgdt [oldGDTR]
276 @@done:
277 popad
278 p8086
279 @@done16:
280 pop es ds
281 popf
282 ifndef NO386
283 p386
284 leave
285 else
286 mov sp,bp
287 pop bp
288 endif
289 ret
291 ;****** Const data *********************************************
292 org $-8 ;save 8 bytes - they are unused anyway
293 ;0000: unused
294 GDT dd ?,?
295 ;0008: Data seg [0,FFFFFFFF]
296 ; lim_lo base_lo
297 dw 1111111111111111b, 0000000000000000b
298 db 00000000b,10010010b,10001111b,00000000b
299 ; base_med P S D A G ??l_hi base_hi
300 ; Pl E W D
302 endp _memcpy32
304 ends _TEXT
306 end
308 ;###### END OF FILE ############################################