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